Legacy UART-RF-Protocol
The Demo-Software implemets an UART-to-Radio protocol. For an easy use the pakets to the uart have to be send as hex-values as ASCII, meaning 0x00 ia send as "00". Only '0'-'9' and 'A'-'F' are accepted letters. Additionaly there is an 'Magic Word' - the letter 'S'. The 'S' is used as sync byte to start a packet. The packets to the UART alway have a fixed sceme: File:packet uart-to-rf.png
- first letter is the 'S'
- followed by 2 bytes length of the packet (N + 1(type) +16(address))
- followed by 16 bytes IPv6 address of the destination, the IPv6 address ::1 is reserved for the Local Host. Packets to the ocal host are not sent over radio, but they are commands to the module.
- followed by 1 type-byte, that determines the type of the packet. When a module receives the packet, it decides with the type how to handle the packet data. There are several packet types pre-defined - as seen below.
- followed by N data bytes.
Example 1 - Packet to the UART: S0015FF0200000000000000000000000000010012345678 This commad sends an Broadcast data packet with 4 bytes of data =0x12345678.
- the length is 16Bytes(address) + 1Byte(type) + 4Bytes(data) = 21Bytes = 0x15
- the address FF020000000000000000000000000001 is the 6LowPAM broadcast address
- type 0x00 means that the packet is a data packet, see the pre-defined packet types below
- the data are 0x12 0x34 0x56 0x78
When the radio sends packets via UART, theese packets also have a fixed sceme:
- first letter is the 'S'
- followed by 2 bytes length of the packet (N + 1(type) +16(address))
- followed by 16 bytes IPv6 address of the destination, the IPv6 address ::1 is reserved for the Local Host. Packets to the ocal host are not sent over radio, but they are commands to the module.
- followed by 1 type-byte, that determines the type of the packet. When a module receives the packet, it decides with the type how to handle the packet data. There are several packet types pre-defined - as seen below.
- followed by N data bytes.
- additionally there is one byte for RSSI that is sent by the radio, but is not counted to the length of the packet!
S00110000000000000000000000000000000105 S - sync letter 0011 - length = 0x11 = 17 bytes 00000000000000000000000000000001 - address = ::1 (IPv6 Local Host) 05 - type is 0x05 = discover-network command
This is the commad 0x05 to the Local Host. It is the command to discover the network - see below for available commands. The module executes the stack-command for scanning the network.
void rf_CallbackDiscover( unsigned char hopCount, char rssi, unsigned char addrCount, ZWIR_IPv6Address_t* address ) { uint8_t data[2]; data[0] = hopCount; data[1] = rssi; packetHandler(SOURCE_RF, address, PACKET_TYPE_DISCOVER_NETWORK_REPLY, data, 2); }
When nodes are discovered, a callback routine is called. The packet handler then sends this packet via uart. The module sends to the uart a packet with PACKET_TYPE_DISCOVER_NETWORK_REPLY with the received address, the hop-count and the RSSI of the node that was discovered.
S0013FE0800000000000000000000000012340601DF
This reply means that the node FE080000000000000000000000001234 is 1 hopcounts away and is received with -33dBm signal strength.
Pre-defined packet types:
typedef enum { PACKET_TYPE_DATA = 0x00, PACKET_TYPE_BIND = 0x01, PACKET_TYPE_BINDACK = 0x02, PACKET_TYPE_UNBIND = 0x03, PACKET_TYPE_SETUP = 0x04, PACKET_TYPE_DISCOVER_NETWORK = 0x05, PACKET_TYPE_DISCOVER_NETWORK_REPLY = 0x06, PACKET_TYPE_LED_DATA = 0x07, PACKET_TYPE_BTN_DATA = 0x08, PACKET_TYPE_GET_LOCAL_ADDRESS = 0x09, PACKET_TYPE_GET_LOCAL_ADDRESS_REPLY = 0x0A, PACKET_TYPE_SET_MAC_ADDRESS = 0x0B, //special type for use with ICradioPlug PACKET_TYPE_CONFIGURE_AS_PLUG = 0xF0, } PACKET_TYPE_t;
Some special commands are also implemented and have to be sent via UART to the LOCAL-HOST (::1)
- scanning the network
S00110000000000000000000000000000000105
- getting the module's IPv6 address
S00110000000000000000000000000000000109
- setting the module's LED's
S001300000000000000000000000000000001070100 (set LED1=on, LED2=off) S001300000000000000000000000000000001070001 (set LED1=off, LED2=on)