ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
Transcoder

Library for encoding/decoding protobuf messages. More...

Functions

size_t EncodePowerMeasurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double voltage, double current, uint8_t *buffer)
 Encodes a power measurement.
 
size_t EncodePowerDeltaMeasurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, uint32_t voltage, uint32_t current, uint8_t *buffer)
 Encodes power delta measurements.
 
size_t EncodeTeros12Measurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double vwc_raw, double vwc_adj, double temp, uint32_t ec, uint8_t *buffer)
 Encodes a Teros12 measurement.
 
size_t EncodeTeros21Measurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double matric_pot, double temp, uint8_t *buffer)
 Encodes a Teros21 measurement.
 
size_t EncodePhytos31Measurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double voltage, double leaf_wetness, uint8_t *buffer)
 Encodes a Phytos31 measurement.
 
size_t EncodeBME280Measurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, uint32_t pressure, int32_t temperature, uint32_t humidity, uint8_t *buffer)
 Encodes a BME280 measurement.
 
size_t EncodeWaterPressMeasurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double voltage, double water_pressure, uint8_t *buffer)
 Encodes a Water Pressure measurement.
 
size_t EncodeSEN0308Measurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double voltage, double humidity, uint8_t *buffer)
 Encodes a Capacitive Soil Moisture measurement.
 
size_t EncodeWaterFlowMeasurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double water_flow, uint8_t *buffer)
 Encodes a Water Flow measurement.
 
size_t EncodePCAP02Measurement (uint32_t ts, uint32_t logger_id, uint32_t cell_id, double capacitance, uint8_t *buffer)
 Encodes a PCAP02 measurement.
 
int DecodeMeasurement (Measurement *meas, const uint8_t *buffer, const size_t len)
 Decodes a measurement.
 
Response_ResponseType DecodeResponse (const uint8_t *data, const size_t len)
 Decodes a response message.
 
Esp32Command DecodeEsp32Command (const uint8_t *data, const size_t len)
 Decodes an Esp32Command message.
 
size_t EncodePageCommand (PageCommand_RequestType req, int fd, size_t bs, size_t n, uint8_t *buffer, size_t size)
 Encodes a page command.
 
size_t EncodeTestCommand (TestCommand_ChangeState state, int32_t data, uint8_t *buffer, size_t size)
 Encodes a test command.
 
size_t EncodeMicroSDCommand (const MicroSDCommand *microsd_cmd, uint8_t *buffer, size_t size)
 Encodes a MicroSDCommand.
 
size_t EncodeWiFiCommand (const WiFiCommand *wifi_cmd, uint8_t *buffer, size_t size)
 Encodes a WiFiCommand.
 
size_t EncodeUserConfigCommand (UserConfigCommand_RequestType type, const UserConfiguration *config_data, uint8_t *buffer, size_t size)
 Encodes a UserConfigCommand into a protobuf message.
 
size_t EncodeIrrigationCommand (const IrrigationCommand *irrigation_cmd, uint8_t *buffer, size_t size)
 Encodes an IrrigationCommand.
 
size_t EncodePowerCommand (const PowerCommand *power_cmd, uint8_t *buffer, size_t size)
 Encodes a PowerCommand.
 
size_t EncodeUserConfiguration (const UserConfiguration *config, uint8_t *buffer)
 Encodes user configuration data.
 
int DecodeUserConfiguration (const uint8_t *data, const size_t len, UserConfiguration *config)
 Decodes user configuration data.
 

Detailed Description

Library for encoding/decoding protobuf messages.

Function Documentation

◆ DecodeEsp32Command()

Esp32Command DecodeEsp32Command ( const uint8_t *  data,
const size_t  len 
)

Decodes an Esp32Command message.

The type of command and the data from the command will need to be manually extracted,

See also
soil_power_sensor.ph.h.
Returns
Esp32Command data

Definition at line 246 of file transcoder.c.

References data.

Referenced by ControllerMicroSDLog(), ControllerMicroSDSave(), ControllerMicroSDUserConfig(), ControllerUserConfigRequest(), IrrigationCommandTransaction(), ModuleHandler::ModuleHandler::OnReceive(), PowerCommandTransaction(), and WiFiCommandTransaction().

◆ DecodeMeasurement()

int DecodeMeasurement ( Measurement *  meas,
const uint8_t *  buffer,
const size_t  len 
)

Decodes a measurement.

Use meas.which_measurement to determine the type of sensor data.

Parameters
measDestination Measurement struct
bufferSource buffer containing the serialized measurement to decode
lenNumber of bytes in buffer
Returns
0 on success, -1 on error

Definition at line 235 of file transcoder.c.

References buffer.

Referenced by ControllerMicroSDSave().

◆ DecodeResponse()

Response_ResponseType DecodeResponse ( const uint8_t *  data,
const size_t  len 
)

Decodes a response message.

Take bytes in data withy length len and decodes into a response type. Neither data or len are modified. A return value of -1 indicates an error in decoding. See soil_power_sensor.proto for a full list of response types.

Parameters
dataProtobuf serialized data
lenNumber of bytes in data
Returns
Response type

Definition at line 207 of file transcoder.c.

References data.

◆ DecodeUserConfiguration()

int DecodeUserConfiguration ( const uint8_t *  data,
const size_t  len,
UserConfiguration *  config 
)

Decodes user configuration data.

This function deserializes a user configuration protobuf message from a buffer. The message length is specified, and a return value of -1 indicates a decoding error.

Parameters
dataSerialized data buffer
lenLength of data buffer
configDecoded user configuration output
Returns
0 on success, -1 on error

Definition at line 376 of file transcoder.c.

References data.

Referenced by setConfig(), and UserConfigLoadBytes().

◆ EncodeBME280Measurement()

size_t EncodeBME280Measurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
uint32_t  pressure,
int32_t  temperature,
uint32_t  humidity,
uint8_t *  buffer 
)

Encodes a BME280 measurement.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Below shows the relation between raw measurements taken from the device in relation to real-world or si units.

Raw values

pressure: 98473 temperature: 2275 humidity: 43600

SI unit values

pressure: 9847.3 hPa temperature: 22.75 C humidity: 43.600 %

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
pressureAir pressure in hPa
temperatureAir temperature in celsius (C)
humidityRelative humidity in percent (%)
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 99 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodeIrrigationCommand()

size_t EncodeIrrigationCommand ( const IrrigationCommand *  irrigation_cmd,
uint8_t *  buffer,
size_t  size 
)

Encodes an IrrigationCommand.

Parameters
irrigation_cmdCommand containing the data
bufferBuffer to store serialized measurement
sizeSize of buffer
Returns
Number of bytes in buffer

Definition at line 322 of file transcoder.c.

References buffer, and EncodeEsp32Command().

Referenced by IrrigationCommandTransaction().

◆ EncodeMicroSDCommand()

size_t EncodeMicroSDCommand ( const MicroSDCommand *  microsd_cmd,
uint8_t *  buffer,
size_t  size 
)

Encodes a MicroSDCommand.

Parameters
microsd_cmdCommand containing the data
bufferBuffer to store serialized command
sizeSize of buffer
Returns
Number of bytes in buffer

Definition at line 278 of file transcoder.c.

References buffer, and EncodeEsp32Command().

Referenced by ControllerMicroSDLog(), ControllerMicroSDSave(), and ControllerMicroSDUserConfig().

◆ EncodePageCommand()

size_t EncodePageCommand ( PageCommand_RequestType  req,
int  fd,
size_t  bs,
size_t  n,
uint8_t *  buffer,
size_t  size 
)

Encodes a page command.

Parameters
reqRequest type
fdFile descriptor
bsBlock size
nNumber of bytes
bufferBuffer to store serialized command
sizeSize of buffer
Returns
Number of bytes in buffer

Definition at line 255 of file transcoder.c.

References buffer, and EncodeEsp32Command().

◆ EncodePCAP02Measurement()

size_t EncodePCAP02Measurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  capacitance,
uint8_t *  buffer 
)

Encodes a PCAP02 measurement.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
voltageRaw voltage reading
capacitanceCapacitance
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 190 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodePhytos31Measurement()

size_t EncodePhytos31Measurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  voltage,
double  leaf_wetness,
uint8_t *  buffer 
)

Encodes a Phytos31 measurement.

Currently only the voltage measurement is used. Leaf wetness will be implemented once more is known about the sensor.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
voltageRaw voltage reading
leaf_wetnessCalibrated leaf wetness
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 81 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodePowerCommand()

size_t EncodePowerCommand ( const PowerCommand *  power_cmd,
uint8_t *  buffer,
size_t  size 
)

Encodes a PowerCommand.

Parameters
power_cmdCommand containing the data
bufferBuffer to store serialized measurement
sizeSize of buffer
Returns
Number of bytes in buffer

Definition at line 335 of file transcoder.c.

References buffer, and EncodeEsp32Command().

Referenced by PowerCommandTransaction().

◆ EncodePowerDeltaMeasurement()

size_t EncodePowerDeltaMeasurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
uint32_t  voltage,
uint32_t  current,
uint8_t *  buffer 
)

Encodes power delta measurements.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsUnix epochs
logger_idLogger Id
cell_idCell Id
voltageVoltage measured in mV
currentCurrent measured in uA
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

◆ EncodePowerMeasurement()

size_t EncodePowerMeasurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  voltage,
double  current,
uint8_t *  buffer 
)

Encodes a power measurement.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsUnix epochs
logger_idLogger Id
cell_idCell Id
voltageVoltage measured in mV
currentCurrent measured in uA
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 43 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodeSEN0308Measurement()

size_t EncodeSEN0308Measurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  voltage,
double  humidity,
uint8_t *  buffer 
)

Encodes a Capacitive Soil Moisture measurement.

Currently only the voltage measurement is used. Sensor will be implemented once more is known about the sensor.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
voltageRaw voltage reading
soil_moisterCalibrated soil moister
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 137 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodeTeros12Measurement()

size_t EncodeTeros12Measurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  vwc_raw,
double  vwc_adj,
double  temp,
uint32_t  ec,
uint8_t *  buffer 
)

Encodes a Teros12 measurement.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
vwc_rawRaw volumetric water content
vwc_adjVolumetric water content converted to percentage
tempTemperature in celsius
ecElectrical conductivity
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 60 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodeTeros21Measurement()

size_t EncodeTeros21Measurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  matric_pot,
double  temp,
uint8_t *  buffer 
)

Encodes a Teros21 measurement.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
matric_potMatric potential
tempTemperature in celsius
Returns
Number of bytes in buffer

Definition at line 119 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodeTestCommand()

size_t EncodeTestCommand ( TestCommand_ChangeState  state,
int32_t  data,
uint8_t *  buffer,
size_t  size 
)

Encodes a test command.

Parameters
stateState to change to
dataData to encode
bufferBuffer to store serialized command
sizeSize of buffer
Returns
Number of bytes in buffer

Definition at line 268 of file transcoder.c.

References buffer, data, EncodeEsp32Command(), and state.

◆ EncodeUserConfigCommand()

size_t EncodeUserConfigCommand ( UserConfigCommand_RequestType  type,
const UserConfiguration *  config_data,
uint8_t *  buffer,
size_t  size 
)

Encodes a UserConfigCommand into a protobuf message.

Parameters
typeThe request type (REQUEST_CONFIG or RESPONSE_CONFIG)
config_dataPointer to UserConfiguration data
bufferOutput buffer for encoded data
sizeSize of output buffer
Returns
Number of bytes in buffer

Definition at line 302 of file transcoder.c.

References buffer, and EncodeEsp32Command().

Referenced by ControllerUserConfigRequest(), ControllerUserConfigSend(), and ControllerUserConfigStart().

◆ EncodeUserConfiguration()

size_t EncodeUserConfiguration ( const UserConfiguration *  config,
uint8_t *  buffer 
)

Encodes user configuration data.

This function serializes user configuration settings, including upload settings, measurement settings, and WiFi settings, using protobuf and stores the result in a buffer. The serialized data length is returned, or -1 if an encoding error occurred.

Parameters
configUser configuration to encode
bufferBuffer to store serialized data
Returns
Number of bytes in the buffer, or -1 on error

Definition at line 361 of file transcoder.c.

References buffer.

Referenced by setConfig(), and UserConfigSave().

◆ EncodeWaterFlowMeasurement()

size_t EncodeWaterFlowMeasurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  water_flow,
uint8_t *  buffer 
)

Encodes a Water Flow measurement.

Currently only the voltage measurement is used. Sensor will be implemented once more is known about the sensor.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
water_flowWater Flow
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 173 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodeWaterPressMeasurement()

size_t EncodeWaterPressMeasurement ( uint32_t  ts,
uint32_t  logger_id,
uint32_t  cell_id,
double  voltage,
double  water_pressure,
uint8_t *  buffer 
)

Encodes a Water Pressure measurement.

Currently only the voltage measurement is used. Sensor will be implemented once more is known about the sensor.

The timestamp is not able to encode timezones and is references from UTC+0. The serialized data is stored in buffer with the number of bytes written being returned by the function. A return value of -1 indicates an error in encoding.

Parameters
tsTimestamp
logger_idLogger Id
cell_idCell Id
voltageRaw voltage reading
water_pressureWater Pressure
bufferBuffer to store serialized measurement
Returns
Number of bytes in buffer

Definition at line 155 of file transcoder.c.

References buffer, and EncodeMeasurement().

◆ EncodeWiFiCommand()

size_t EncodeWiFiCommand ( const WiFiCommand *  wifi_cmd,
uint8_t *  buffer,
size_t  size 
)

Encodes a WiFiCommand.

Parameters
wifi_cmdCommand containing the data
bufferBuffer to store serialized measurement
sizeSize of buffer
Returns
Number of bytes in buffer

Definition at line 290 of file transcoder.c.

References buffer, and EncodeEsp32Command().

Referenced by WiFiCommandTransaction().