typedef union SensorWord_t {
unsigned char raw[2];
struct {
unsigned sensorType:3; //range:0-7
unsigned sensorID:3; //range:0-7
unsigned data:10; //range:0-1024
};
} SensorWord;
We have the 'raw' member for sending the SensorWord over serial, and the actual elements of the SensorWord: the 3bit sensor type, the 3bit sensor ID, and 10 bits of data. All sensor sections will use this data type for communicating information to the serial communications procedure.
Each sensor handler will submit data for sending over the serial line with via this method.
First and foremost, it would be best for each sensor to have its own buffer to hold its sensor word that it is preparing to send to serial. This way we can avoid memory leaks. It would also be a good idea to assign each type of sensor its own specific type, and each sensor its own ID. We will probably be tweaking the sizes of each field in the SensorWord type, but it will most likely stay at 2 bytes. RFC
Assuming we have at most 7 sensors per router, we could probably just use one byte per word (at 3 bits for the ID, and dump the type member). This would also hinge on whether we can fit enough useful information into the remaining 5 bytes. RFC
Here is the serial format for the identification byte so far. This will be the first byte transmitted. Then, immediately following will be the actual data. As of now, there will only be at maximum 8 bits of data transmitted for convenience sake. If there is need to send ten bits of data, this can be changed quickly. On the router end, check for the hexadecimal value when data is received from the microcontroller. These values can be found under the Hexadecimal Info Byte column.
| SensorType | Binary Form | Sensor ID | Binary Form | Hexadecimal Info Byte |
|---|---|---|---|---|
| Trip | 001 | IN1 | 001 | 0×24 |
| Trip | 001 | OUT1 | 010 | 0×28 |
| Trip | 001 | IN2 | 011 | 0x2C |
| Trip | 001 | OUT2 | 100 | 0×30 |
| Mic | 010 | micLevel1 | 001 | 0×44 |
| Mic | 010 | micDanger1 | 010 | 0×48 |
| Mic | 010 | micLevel2 | 011 | 0x4C |
| Mic | 010 | micDanger2 | 100 | 0×50 |