|
ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
|
Library for encoding and decoding sensor measurements. More...
Typedefs | |
| typedef enum _SensorStatus | SensorStatus |
Enumerations | |
| enum | _SensorStatus { SENSOR_OK = 0 , SENSOR_ERROR = -1 , SENSOR_OUT_OF_BOUNDS = -2 , SENSOR_REUPLOAD = -3 , SENSOR_FORMAT = -4 } |
Functions | |
| SensorStatus | EncodeSensorMeasurement (const SensorMeasurement *meas, uint8_t *buffer, size_t *size) |
| Encodes a single sensor measurement into a buffer. | |
| SensorStatus | EncodeRepeatedSensorMeasurements (Metadata meta, const SensorMeasurement meas[], size_t count, uint8_t *buffer, size_t size, size_t *length) |
| Encodes multiple sensor measurements into a buffer. | |
| SensorStatus | EncodeUint32Measurement (Metadata meta, uint32_t value, SensorType type, uint8_t *buffer, size_t *size) |
| Encodes a uint64_t sensor measurement into a buffer. | |
| SensorStatus | EncodeInt32Measurement (Metadata meta, int32_t value, SensorType type, uint8_t *buffer, size_t *size) |
| Encodes an int64_t sensor measurement into a buffer. | |
| SensorStatus | EncodeDoubleMeasurement (Metadata meta, double value, SensorType type, uint8_t *buffer, size_t *size) |
| Encodes a double sensor measurement into a buffer. | |
| SensorStatus | DecodeSensorMeasurement (const uint8_t *data, const size_t len, SensorMeasurement *meas) |
| Decodes a sensor measurement from a buffer. | |
| SensorStatus | RepeatedSensorMeasurementsSize (Metadata meta, const SensorMeasurement meas[], size_t count, size_t *size) |
| Gets the size of multiple repeated sensor measurements when encoded. | |
| SensorStatus | DecodeRepeatedSensorMeasurements (const uint8_t *data, const size_t len, RepeatedSensorMeasurements *meas) |
| Decodes multiple sensor measurements from a buffer. | |
| SensorStatus | EncodeRepeatedSensorResponses (const RepeatedSensorResponses responses, uint8_t *buffer, size_t *size) |
| Encodes multiple sensor responses into a buffer. | |
| SensorStatus | DecodeRepeatedSensorReponses (const uint8_t *data, const size_t len, RepeatedSensorResponses *resp) |
| Decodes multiple sensor responses from a buffer. | |
| SensorStatus | CheckSensorResponse (const SensorResponse *resp) |
| Checks a single sensor response for errors. | |
| void | PrintSensorMeasurement (const SensorMeasurement *m) |
| void | PrintRepeatedSensorMeasurements (const RepeatedSensorMeasurements *msg) |
Library for encoding and decoding sensor measurements.
Where sensors measurements are taken EncodeUint64Measurement, EncodeInt64Measurement, EncodeDoubleMeasurement, and EncodeTextMeasurement are used.
When formatting multiple measurements, single measurements may have to be decoded first with DecodeSensorMeasurement and placed in the SensorMeasurement struct before re-encoding Re-encoding into a RepeatedSensorMeasurement struct can be done with EncodeRepeatedSensorMeasurements.
| typedef enum _SensorStatus SensorStatus |
| enum _SensorStatus |
| SensorStatus CheckSensorResponse | ( | const SensorResponse * | resp | ) |
Checks a single sensor response for errors.
If the index of the response is 0 and error is not OK, this indicates an overall error in protobuf for the repeated measurement message. The upload should be retried. In this case, SENSOR_REUPLOAD is returned.
Otherwise, if there is an issue with the measurement information, ie. a cell or logger is not found or a measurement is not supported. The measurement should be discarded. A SENSOR_FORMAT is returned in this case.
Other errors that could possibly result from handling a data buffer or in the communication link should be re-uploaded. In this case, SENSOR_REUPLOAD is returned.
| resp | Pointer to the SensorResponse to check. |
Definition at line 306 of file sensor.c.
References SENSOR_FORMAT, SENSOR_OK, and SENSOR_REUPLOAD.
Referenced by TestCheckSensorResponse().
| SensorStatus DecodeRepeatedSensorMeasurements | ( | const uint8_t * | data, |
| const size_t | len, | ||
| RepeatedSensorMeasurements * | meas | ||
| ) |
Decodes multiple sensor measurements from a buffer.
| data | Pointer to the input buffer. |
| len | Length of the input buffer. |
| meas | Pointer to the RepeatedSensorMeasurements to populate. |
Definition at line 270 of file sensor.c.
References data, Parse(), and SENSOR_ERROR.
Referenced by TestRepeatedSensorMeasurementsOptimize(), and TestTranscodeRepeatedSensorMeasurements().
| SensorStatus DecodeRepeatedSensorReponses | ( | const uint8_t * | data, |
| const size_t | len, | ||
| RepeatedSensorResponses * | resp | ||
| ) |
Decodes multiple sensor responses from a buffer.
| data | Pointer to the input buffer. |
| len | Length of the input buffer. |
| meas | Pointer to the RepeatedSensorResponses to populate. |
Definition at line 295 of file sensor.c.
References data, SENSOR_ERROR, and SENSOR_OK.
Referenced by TestRepeatedSensorResponses().
| SensorStatus DecodeSensorMeasurement | ( | const uint8_t * | data, |
| const size_t | len, | ||
| SensorMeasurement * | meas | ||
| ) |
Decodes a sensor measurement from a buffer.
| data | Pointer to the input buffer. |
| len | Length of the input buffer. |
| meas | Pointer to the SensorMeasurement to populate. |
Definition at line 259 of file sensor.c.
References data, SENSOR_ERROR, and SENSOR_OK.
Referenced by TestTranscodeSensorMeasurement().
| SensorStatus EncodeDoubleMeasurement | ( | Metadata | meta, |
| double | value, | ||
| SensorType | type, | ||
| uint8_t * | buffer, | ||
| size_t * | size | ||
| ) |
Encodes a double sensor measurement into a buffer.
| meta | Metadata for the measurement. |
| value | The double measurement value. |
| type | The SensorType of the measurement. |
| buffer | Pointer to the output buffer. |
| size | Pointer to the size of the output buffer. On success, updated to the number of bytes written. |
Definition at line 244 of file sensor.c.
References buffer, and EncodeSensorMeasurement().
Referenced by ads1219_sensor_current(), ads1219_sensor_voltage(), BME280MeasureHumidity(), BME280MeasurePressure(), BME280MeasureTemperature(), and TestEncodeDoubleMeasurement().
| SensorStatus EncodeInt32Measurement | ( | Metadata | meta, |
| int32_t | value, | ||
| SensorType | type, | ||
| uint8_t * | buffer, | ||
| size_t * | size | ||
| ) |
Encodes an int64_t sensor measurement into a buffer.
| meta | Metadata for the measurement. |
| value | The int64_t measurement value. |
| type | The SensorType of the measurement. |
| buffer | Pointer to the output buffer. |
| size | Pointer to the size of the output buffer. On success, updated to the number of bytes written. |
Definition at line 229 of file sensor.c.
References buffer, and EncodeSensorMeasurement().
Referenced by TestEncodeInt32Measurement().
| SensorStatus EncodeRepeatedSensorMeasurements | ( | Metadata | meta, |
| const SensorMeasurement | meas[], | ||
| size_t | count, | ||
| uint8_t * | buffer, | ||
| size_t | size, | ||
| size_t * | length | ||
| ) |
Encodes multiple sensor measurements into a buffer.
No checking is done to ensure there are not duplicates in the metadata. This is left up to the user implementation.
| meta | Metadata for the measurements. |
| meas | Array of SensorMeasurements to encode. |
| count | Number of measurements in the array. |
| buffer | Pointer to the output buffer. |
| size | Size of buffer. |
| length | Pointer to the length of the output buffer. |
Definition at line 166 of file sensor.c.
References buffer, FormatRepeatedSensorMeasurements(), SENSOR_ERROR, and SENSOR_OK.
Referenced by TestRepeatedSensorMeasurementsOptimize(), and TestTranscodeRepeatedSensorMeasurements().
| SensorStatus EncodeRepeatedSensorResponses | ( | const RepeatedSensorResponses | responses, |
| uint8_t * | buffer, | ||
| size_t * | size | ||
| ) |
Encodes multiple sensor responses into a buffer.
This function is mainly here for test purposes as only the server will be sending responses back to the device.
| responses | Array of SensorResponses to encode. |
| buffer | Pointer to the output buffer. |
| size | Pointer to the size of the output buffer. On success, updated to the number of bytes written. |
Definition at line 283 of file sensor.c.
References buffer, SENSOR_ERROR, and SENSOR_OK.
Referenced by TestRepeatedSensorResponses().
| SensorStatus EncodeSensorMeasurement | ( | const SensorMeasurement * | meas, |
| uint8_t * | buffer, | ||
| size_t * | size | ||
| ) |
Encodes a single sensor measurement into a buffer.
The metadata is embedded within the SensorMeasurement structure.
| meas | Pointer to the SensorMeasurement to encode. |
| buffer | Pointer to the output buffer. |
| size | Pointer to the size of the output buffer. On success, updated to the number of bytes written. |
Definition at line 151 of file sensor.c.
References buffer, SENSOR_ERROR, and SENSOR_OK.
Referenced by EncodeDoubleMeasurement(), EncodeInt32Measurement(), EncodeUint32Measurement(), and TestTranscodeSensorMeasurement().
| SensorStatus EncodeUint32Measurement | ( | Metadata | meta, |
| uint32_t | value, | ||
| SensorType | type, | ||
| uint8_t * | buffer, | ||
| size_t * | size | ||
| ) |
Encodes a uint64_t sensor measurement into a buffer.
| meta | Metadata for the measurement. |
| value | The uint64_t measurement value. |
| type | The SensorType of the measurement. |
| buffer | Pointer to the output buffer. |
| size | Pointer to the size of the output buffer. On success, updated to the number of bytes written. |
Definition at line 213 of file sensor.c.
References buffer, and EncodeSensorMeasurement().
Referenced by TestEncodeUint32Measurement().
| void PrintRepeatedSensorMeasurements | ( | const RepeatedSensorMeasurements * | msg | ) |
Definition at line 369 of file sensor.c.
References i, PrintMetadata(), and PrintSensorMeasurement().
| void PrintSensorMeasurement | ( | const SensorMeasurement * | m | ) |
Definition at line 338 of file sensor.c.
References PrintMetadata().
Referenced by PrintRepeatedSensorMeasurements().
| SensorStatus RepeatedSensorMeasurementsSize | ( | Metadata | meta, |
| const SensorMeasurement | meas[], | ||
| size_t | count, | ||
| size_t * | size | ||
| ) |
Gets the size of multiple repeated sensor measurements when encoded.
| meta | Metadata for the measurements. |
| meas | Array of SensorMeasurements to encode. |
| count | Number of measurements in the array. |
| size | Pointer to the size variable to populate. |
Definition at line 191 of file sensor.c.
References FormatRepeatedSensorMeasurements(), SENSOR_ERROR, and SENSOR_OK.
Referenced by TestRepeatedSensorMeasurementsSize().