Project:HUGnet Packet Structure
From HUG Wiki
The packet structure is what allows the computer and the HUGnet units to communicate amongst themselves. It tells where a set of data is from, where it is going, and has some safeguards to make sure the data gets there intact.
Contents |
Breakdown
- Preamble 2-3 bytes
- Command 1 Byte
- To 3 Bytes
- From 3 Bytes
- Length 1 Byte
- Data 0-256 Bytes
- Checksum 1 Byte
Preamble
0x5A repeated 2-3 times. 3 are sent. At least 2 must be received.
Command
Command sent to the endpoint. Can not be 0x5A because then it would meld with the preamble. See HUGnet Packet Commands for more information.
To
DeviceID (Least Significant 3 bytes of the serial number) of the unit the packet is for. Endpoints will disregard this packet if the To field does not match their DeviceID.
From
DeviceID (Least Significant 3 bytes of the serial number) of the unit the packet is from.
Length
length of the data section
Data
The packet structure maximum length is 256 bytes based on the size of the Length field. Very few devices can actually receive packets this size. Most could send them.
The maximum packet length is limited by:
- The buffer in the endpoint
- The buffer in the controller
- The timeout of the controller (larger packets may take too long)
See Project:HUGnet Endpoint for more information on specific endpoints.
Checksum
xor of all the bytes except the preamble. When receiving a packet if you xor all bytes including the checksum you should get 0.
Example
A power up packet from device 0000AA might look like:
5A5A5A5E0000000000AA0A00000000AA0039280142XX
The XX is the checksum, as I am too lazy to calculate it tonight (Prices 21:35, 5 December 2006 (CST))

