The Sequence Identifier (SID) is used to link different Parameter Group Numbers (PGNs) that were sampled or calculated at the same time. This allows receiving devices to synchronize data from multiple PGNs for more accurate calculations (e.g., linking GPS position, speed, and heading data).
Implementation Guidelines
- Range: Use values between
0 and 252. - Reserved Values:
253 and 254 are reserved. 255 (0xff) indicates that data is not available. - Sending: If you do not need synchronization, you can simply use
0xff for the SID. - Synchronization Logic: To use SID effectively, increment the value in synchronization with your sampling cycle. If you sample faster than you transmit, increment the SID only after all related messages for a specific sample have been sent.
Thread Safety and Multitasking
When using a multitasking system, you must lock your data during both the sampling and sending phases to prevent data from changing mid-task. This ensures the SID and the sensor values remain consistent across all related PGNs.
// Incrementing SID logic
SensorSID++;
if (SensorSID > 252) SensorSID = 0;
// Example Sampling Task with Locking
SampleSensors(Sensor1, Sensor2);
LockSend();
Sensor1Out = Sensor1;
Sensor2Out = Sensor2;
SensorsSID++;
if (SensorsSID > 252) SensorsSID = 0;
ReleaseSend();
// Example Sending Task with Locking
LockSend();
double S1 = Sensor1Out;
double S2 = Sensor2Out;
SID = SensorsSID;
ReleaseSend();
SendSensorsData(SID, S1, S2);