This repository has been archived by the owner on Aug 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
SWAP Protocol Decoder Encoder
danbim edited this page Apr 26, 2011
·
7 revisions
The SWAP protocol provides an easy and lightweight alternative to service oriented application level protocols like the Constrained Application Protocol (CoAP). As packages may get larger than e.g., the MTU of 802.15.4, one usually runs the SWAP protocol on base of a fragmenting protocol such as the Remote UART protocol.
0: CMD_TYPE = 70
1: REQUEST_ID
2: REQUEST_TYPE
3: REQUEST_OPTIONS_LENGTH
4-n: REQUEST_OPTIONS
0: CMD_TYPE = 71
1: REQUEST_ID
2: RESPONSE_CODE
3: RESPONSE_PAYLOAD_LENGTH
4-n: RESPONSE_PAYLOAD
0: CMD_TYPE = 72
1: SUBSCRIPTION_ID
2: PAYLOAD_LENGTH
3-n: PAYLOAD
The following table shows the possible values for the various fields of request and response messages:
REQUEST_TYPE | REQUEST_OPTIONS | RESPONSE_PAYLOAD |
---|---|---|
0x00 GET_SENSORS | newline character-separated string of sensor names and associated key-value pairs, e.g., "temp=1\nhumid=2\nacc=3" | |
0x01 GET_SENSORNODE_META_DATA | key-value pairs, newline character-separated, e.g., "type=isense\nrevision=jennic85391" | |
0x02 GET_SENSOR_VALUE | 1 byte uint_8, identifying the sensor, e.g. "1", see GET_SENSORS | sensor-specific binary representation of a sensor value, see below |
0x03 GET_SENSOR_META_DATA | 1 byte uint_8, identifying the sensor, e.g. "1", see GET_SENSORS | key-value pairs, newline character-separated, e.g., "type=temperature\nunit=degreecelsius" |
0x04 SUBSCRIBE | key-value pairs, newline character-separated, e.g., "method=push\nduration=7200000" | 1 byte subscription ID |
0x05 UNSUBSCRIBE | 1 byte subscription ID | |
0x06 PUT_SENSOR_META_DATA | 1 byte identifying the sensor, e.g., "1", 1 byte string length, string with meta data as key-value pair, e.g., "type=temperature" | empty response with an appropriate response code |
The data representation of a push messages' PAYLOAD
field is defined below (sensor-specific binary representation of sensor values).
Sensor values are encoded as 3-tuples of the following form:
ENCODING_BYTE | DATA_LENGTH (in byte) | DATA |
UNKNOWN_ENCODING | 0xff |
BOOL | 0x01 |
UINT8 | 0x02 |
INT8 | 0x03 |
UINT16 | 0x04 |
INT16 | 0x05 |
UINT32 | 0x06 |
INT32 | 0x07 |
UINT64 | 0x08 |
INT64 | 0x09 |
STRING | 0x0a |
DOUBLE | 0x0b |
room = int
type = temp | occupation
unit = celsius/fahrenheit (bei temp) | bool (bei occupation)
position = gps