Tuesday, October 20, 2009

FYI for tinyos 2.x

Packet Format

A data packet in the TinyOS 2.x serial stack has the following format over the wire. Each protocol field is associated with a specific component:

   ____________________________________________   | | | | |                               |  | |   | | | | |                               |  | |   |_|_|_|_|_______________________________|__|_|    F P S D         Payload                 CR F  F       = Framing byte, denoting start of packet: HdlcTranslateC P       = Protocol byte: SerialP S       = Sequence number byte: SerialP D       = Packet format dispatch byte: SerialDispatcherC Payload = Data payload (stored in SerialDispatcherC): SerialDispatcherC CR      = Two-byte CRC over S to end of Payload: SerialP F       = Framing byte denoting end of packet: HdlcTranslateC 

Payload is a contiguous packet that SerialDispatcherC reads in. Note that any data bytes (P - CR) equal to 0x7e or 0x7d will be escaped to 0x7d 0x5e or 0x7d 0x5d accordingly. For example, a platform independent AM packet of type 6, group 0x7d, and length 5 to destination 0xbeef with a payload of 1 2 3 4 5 would look like this:

7e 40 09 00 be ef 05 7d 5d 06 01 02 03 04 05 7e

Note that the group 0x7d is escaped to 0x7d 0x5d. The protocol field (P) is 0x40 (64), corresponding to SERIAL_PROTO_ACK (in Serial.h).

1 comment: