Serial Sensor Protocol

Serial Sensor Protocol is a protocol for serial communications between sensors and base stations on a meshed sensor network.

THIS IS A DRAFT

Terminology

 * CAN and MAY both mean that it is allowed but not required.
 * SHOULD means that it generally should be a certain way but legitimate exceptions may arise; in this case care must be taken not to break compatibility with other aspects of the protocol.
 * MUST means that there are no acceptable exceptions to this rule.

Negations both in the form of CAN NOT and CAN'T should be understood canonically.

Transaction block
The basic unit of communications is a transaction block, which consists of:


 * Recipient ID (1 byte)
 * Sender ID (1 byte)
 * Command code (1 byte)
 * Payload length in bytes (1 byte)
 * (optional) Payload (maximum 255 bytes)

Identification codes
Each sensor MUST have an ID code. These ID codes SHOULD be unique, as ID collisions will render two sensors indistinguishable, but of course there MAY arise situations where this is beneficial; to all other extents there should be no ill effects of collisions.

ID codes 0x00 and 0xFF are reserved.
 * 0x00 is a multicast address, which ALL sensors MUST respond to.
 * 0xFF is the master address, which is not considered a sensor.

Sensors SHOULD in general address messages to the master unless they have specific reason not to. Sensors SHOULD never use multicast addressing.

@UTS
4 byte UNIX time stamp

@memstruct
This contains the measurement data.


 * 1 byte			signifying number of bytes per structural element.
 * 2 bytes			number of elements (same as command 0x03).
 * repeats:
 * 2 bytes		time offset
 * n bytes		structural elements
 * 2 bytes			checksum (same as command 0x02)

@sensorstruct
This contains information about the sensors, and also provides information about how to parse measurement data.


 * 1 byte			number of sensors attached
 * repeats:
 * 1 byte		sensor class (@sensorclasses)
 * 1 byte		status code
 * 1 byte		memstruct element length in bytes
 * 1 byte		reserved

@sensorclasses
A table of sensor types, enumerated from 0x00 to 0xFF


 * 0x01	Light sensor, IR
 * 0x02	Light sensor, visible light
 * 0x03	Light sensor, UV
 * 0x04	Thermal sensor
 * 0x05	Barmoeter
 * 0x06	Force sensor
 * 0x07	Scales
 * 0x10	Accelerometer
 * 0x11	Odometer
 * 0x12	Tachometer
 * 0x20	Button
 * 0x21	Switch
 * 0xFF	Hybrid sensor

@statuscodes
one byte status codes


 * 0xE1	OK
 * 0xE2	CRC error
 * 0xFF	Not implemented