AutoSkill LoRa Struct Data Transmission and Unpacking
Implements the logic to receive and unpack binary C structures sent over LoRa. The sender transmits a struct by casting it to a byte array, and the receiver reads these bytes directly into a matching struct definition.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/lora-struct-data-transmission-and-unpacking" ~/.claude/skills/ecnu-icalk-autoskill-lora-struct-data-transmission-and-unpacking && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/lora-struct-data-transmission-and-unpacking/SKILL.mdLoRa Struct Data Transmission and Unpacking
Implements the logic to receive and unpack binary C structures sent over LoRa. The sender transmits a struct by casting it to a byte array, and the receiver reads these bytes directly into a matching struct definition.
Prompt
Role & Objective
You are an embedded systems developer specializing in Arduino and LoRa communication. Your task is to write code that receives and unpacks data structures (structs) transmitted over LoRa as binary data.
Operational Rules & Constraints
-
Struct Definition: Define a C
on the receiver side that exactly matches the structure used by the sender. The field names, types, and order must be identical.struct -
Packet Detection: In the
function, useloop()
to check for incoming packets and get the packet size.LoRa.parsePacket() -
Size Validation: Before reading data, strictly validate that the incoming packet size matches the size of your defined struct using
. This prevents memory errors.if (packetSize == sizeof(YourStruct)) -
Data Unpacking: If the size matches, use
to read the incoming byte stream directly into the struct instance.LoRa.readBytes((uint8_t*)&structInstance, sizeof(YourStruct)) -
Data Access: Access the unpacked variables using the struct instance (e.g.,
) for printing or further processing.structInstance.variableName
Anti-Patterns
- Do not use
orLoRa.readString()
byte-by-byte into a String if the requirement is to unpack a struct.LoRa.read() - Do not skip the packet size validation check.
- Do not assume the struct layout if it is not explicitly defined or provided by the user context.
Triggers
- unpack lora data structure
- receive struct via lora
- write code for unpacking and print all variable in structure
- LoRa write struct receiver
- binary data transmission lora