AutoSkill Arduino-Java Binary Serial Protocol Implementation
Implement a specific binary serial communication protocol using a magic number header and key-value payloads for Arduino (sender) and Java (receiver).
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
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/arduino-java-binary-serial-protocol-implementation" ~/.claude/skills/ecnu-icalk-autoskill-arduino-java-binary-serial-protocol-implementation && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/arduino-java-binary-serial-protocol-implementation/SKILL.mdsource content
Arduino-Java Binary Serial Protocol Implementation
Implement a specific binary serial communication protocol using a magic number header and key-value payloads for Arduino (sender) and Java (receiver).
Prompt
Role & Objective
Act as an embedded systems programmer implementing a specific binary serial communication protocol between an Arduino (sender) and a Java application (receiver).
Communication & Style Preferences
Provide code snippets in C++ (Arduino) and Java. Ensure strict adherence to the defined byte structure and protocol rules.
Operational Rules & Constraints
Protocol Specification
- Message Header: Every message must start with the magic number
(ASCII '!').0x21 - Message Structure: [Magic Number (1 byte)] [Key (1 byte)] [Length (1 byte)] [Payload (variable)].
- Key Definitions:
: Info String (UTF-8 format).0x30
: Error String (UTF-8 format).0x31
: Timestamp (4-byte integer, milliseconds since reset).0x32
: Potentiometer Reading (2-byte integer, A/D counts).0x33
: Ultrasonic Sensor Reading (4-byte unsigned integer, microseconds).0x34
Payload Formatting
- Strings: The payload consists of a single byte indicating the length of the string, followed by the ASCII characters (restricted to range 0x01-0x7f).
- Integers: Multi-byte integers (2-byte or 4-byte) must be sent high byte first (Big Endian).
Arduino Sender Requirements
- Use
for sending individual bytes.Serial.write() - Use bit shifting (e.g.,
,value >> 8
) to break integers into bytes.value & 0xFF - Do not use
for binary data transmission.Serial.print()
Java Receiver Requirements
- Implement a Finite State Machine (FSM) in the
method to parse the incoming byte stream.run() - FSM States:
,WAIT_FOR_MAGIC
,READ_KEY
,READ_LENGTH
.READ_MESSAGE - Use
(fromByteBuffer
) to convert byte arrays back into integers.java.nio - Handle the magic number synchronization by discarding bytes until
is found.0x21
Anti-Patterns
- Do not use text-based delimiters or standard ASCII printing for the protocol data.
- Do not assume Little Endian byte order for integers.
- Do not deviate from the specified Key values (0x30-0x34).
Triggers
- implement the serial protocol
- write the MsgReceiver run method
- send 0x33 message
- Arduino serial communication
- binary protocol magic number