Embedded System Design 2 - Project
lpp.c File Reference

Basic Low Power Payload (LPP) functionality. More...

#include <em_device.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "lpp.h"
#include "datatypes.h"
#include "debug_dbprint.h"

Go to the source code of this file.

Macros

#define LPP_DIGITAL_INPUT   0x00
 
#define LPP_ANALOG_INPUT   0x02
 
#define LPP_TEMPERATURE   0x67
 
#define LPP_HUMIDITY   0x68
 
#define LPP_ACCELEROMETER   0x71
 
#define LPP_PRESSURE   0x73
 
#define LPP_DIGITAL_INPUT_SIZE   0x03
 
#define LPP_ANALOG_INPUT_SIZE   0x04
 
#define LPP_TEMPERATURE_SIZE   0x04
 
#define LPP_HUMIDITY_SIZE   0x03
 
#define LPP_ACCELEROMETER_SIZE   0x08
 
#define LPP_PRESSURE_SIZE   0x04
 
#define LPP_DIGITAL_INPUT_CHANNEL   0x01
 
#define LPP_ANALOG_INPUT_CHANNEL   0x02
 
#define LPP_TEMPERATURE_CHANNEL   0x03
 
#define LPP_HUMIDITY_CHANNEL   0x04
 
#define LPP_ACCELEROMETER_CHANNEL   0x05
 
#define LPP_PRESSURE_CHANNEL   0x06
 
#define LPP_VBAT_CHANNEL   0x10 /* 16 */
 
#define LPP_TEMPERATURE_CHANNEL_INT   0x11 /* 17 */
 
#define LPP_TEMPERATURE_CHANNEL_EXT   0x12 /* 18 */
 
#define LPP_STORM_CHANNEL   0x13 /* 19 */
 
#define LPP_CABLE_BROKEN_CHANNEL   0x14 /* 20 */
 
#define LPP_STATUS_CHANNEL   0x15 /* 21 */
 

Functions

bool LPP_InitBuffer (LPP_Buffer_t *b, uint8_t size)
 
void LPP_ClearBuffer (LPP_Buffer_t *b)
 
void LPP_FreeBuffer (LPP_Buffer_t *b)
 
bool LPP_AddMeasurements (LPP_Buffer_t *b, MeasurementData_t data)
 Add measurement data to the LPP packet following the custom message convention to save bytes to send. More...
 
bool LPP_AddStormDetected (LPP_Buffer_t *b, uint8_t stormDetected)
 Add a value to indicate that a storm has been detected to the LPP packet following the custom message convention. More...
 
bool LPP_AddCableBroken (LPP_Buffer_t *b, uint8_t cableBroken)
 Add a value to indicate that the cable has been broken to the LPP packet following the custom message convention. More...
 
bool LPP_AddStatus (LPP_Buffer_t *b, uint8_t status)
 Add a value to indicate a program status to the LPP packet following the custom message convention. More...
 
bool LPP_deprecated_AddVBAT (LPP_Buffer_t *b, int16_t vbat)
 Add a battery voltage measurement to the LPP packet, disguised as an Analog Input packet (2 bytes). The channel is defined by LPP_VBAT_CHANNEL and is 0x10. More...
 
bool LPP_deprecated_AddIntTemp (LPP_Buffer_t *b, int16_t intTemp)
 Add an internal temperature measurement (2 bytes) to the LPP packet. The channel is defined by LPP_TEMPERATURE_CHANNEL_INT and is 0x11. More...
 
bool LPP_deprecated_AddExtTemp (LPP_Buffer_t *b, int16_t extTemp)
 Add an external temperature measurement (2 bytes) to the LPP packet. The channel is defined by LPP_TEMPERATURE_CHANNEL_EXT and is 0x12. More...
 
bool LPP_deprecated_AddStormDetected (LPP_Buffer_t *b, uint8_t stormDetected)
 Add a storm value to the LPP packet, disguised as a Digital Input packet (1 byte). The channel is defined by LPP_STORM_CHANNEL and is 0x13. More...
 
bool LPP_deprecated_AddCableBroken (LPP_Buffer_t *b, uint8_t cableBroken)
 Add a cable break value to the LPP packet, disguised as a Digital Input packet (1 byte). The channel is defined by LPP_CABLE_BROKEN_CHANNEL and is 0x14. More...
 
bool LPP_deprecated_AddStatus (LPP_Buffer_t *b, uint8_t status)
 Add a status value to the LPP packet, disguised as a Digital Input packet (1 byte). The channel is defined by LPP_STATUS_CHANNEL and is 0x15. More...
 
bool LPP_AddDigital (LPP_Buffer_t *b, uint8_t data)
 
bool LPP_AddAnalog (LPP_Buffer_t *b, int16_t data)
 
bool LPP_AddTemperature (LPP_Buffer_t *b, int16_t data)
 
bool LPP_AddHumidity (LPP_Buffer_t *b, uint8_t data)
 
bool LPP_AddAccelerometer (LPP_Buffer_t *b, int16_t x, int16_t y, int16_t z)
 
bool LPP_AddPressure (LPP_Buffer_t *b, uint16_t data)
 

Detailed Description

Basic Low Power Payload (LPP) functionality.

Version
2.3
Author
Geoffrey Ottoy
Modified by Brecht Van Eeckhoudt

Versions

  • v1.0: DRAMCO GitHub version (https://github.com/DRAMCO/EFM32-RN2483-LoRa-Node).
  • v1.1: Added custom methods to add specific data to the LPP packet.
  • v1.2: Merged methods to use less bytes when sending the data.
  • v1.3: Updated documentation.
  • v2.0: Updated version number.
  • v2.1: Added extra dbprint debugging statements.
  • v2.2: Fixed suboptimal buffer logic causing lockups after some runtime.
  • v2.3: Chanced logic to clear the buffer before going to sleep.

Definition in file lpp.c.

Macro Definition Documentation

◆ LPP_ACCELEROMETER

#define LPP_ACCELEROMETER   0x71

Definition at line 57 of file lpp.c.

◆ LPP_ACCELEROMETER_CHANNEL

#define LPP_ACCELEROMETER_CHANNEL   0x05

Definition at line 73 of file lpp.c.

◆ LPP_ACCELEROMETER_SIZE

#define LPP_ACCELEROMETER_SIZE   0x08

Definition at line 65 of file lpp.c.

◆ LPP_ANALOG_INPUT

#define LPP_ANALOG_INPUT   0x02

Definition at line 54 of file lpp.c.

◆ LPP_ANALOG_INPUT_CHANNEL

#define LPP_ANALOG_INPUT_CHANNEL   0x02

Definition at line 70 of file lpp.c.

◆ LPP_ANALOG_INPUT_SIZE

#define LPP_ANALOG_INPUT_SIZE   0x04

Definition at line 62 of file lpp.c.

◆ LPP_CABLE_BROKEN_CHANNEL

#define LPP_CABLE_BROKEN_CHANNEL   0x14 /* 20 */

Definition at line 81 of file lpp.c.

◆ LPP_DIGITAL_INPUT

#define LPP_DIGITAL_INPUT   0x00

Definition at line 53 of file lpp.c.

◆ LPP_DIGITAL_INPUT_CHANNEL

#define LPP_DIGITAL_INPUT_CHANNEL   0x01

Definition at line 69 of file lpp.c.

◆ LPP_DIGITAL_INPUT_SIZE

#define LPP_DIGITAL_INPUT_SIZE   0x03

Definition at line 61 of file lpp.c.

◆ LPP_HUMIDITY

#define LPP_HUMIDITY   0x68

Definition at line 56 of file lpp.c.

◆ LPP_HUMIDITY_CHANNEL

#define LPP_HUMIDITY_CHANNEL   0x04

Definition at line 72 of file lpp.c.

◆ LPP_HUMIDITY_SIZE

#define LPP_HUMIDITY_SIZE   0x03

Definition at line 64 of file lpp.c.

◆ LPP_PRESSURE

#define LPP_PRESSURE   0x73

Definition at line 58 of file lpp.c.

◆ LPP_PRESSURE_CHANNEL

#define LPP_PRESSURE_CHANNEL   0x06

Definition at line 74 of file lpp.c.

◆ LPP_PRESSURE_SIZE

#define LPP_PRESSURE_SIZE   0x04

Definition at line 66 of file lpp.c.

◆ LPP_STATUS_CHANNEL

#define LPP_STATUS_CHANNEL   0x15 /* 21 */

Definition at line 82 of file lpp.c.

◆ LPP_STORM_CHANNEL

#define LPP_STORM_CHANNEL   0x13 /* 19 */

Definition at line 80 of file lpp.c.

◆ LPP_TEMPERATURE

#define LPP_TEMPERATURE   0x67

Definition at line 55 of file lpp.c.

◆ LPP_TEMPERATURE_CHANNEL

#define LPP_TEMPERATURE_CHANNEL   0x03

Definition at line 71 of file lpp.c.

◆ LPP_TEMPERATURE_CHANNEL_EXT

#define LPP_TEMPERATURE_CHANNEL_EXT   0x12 /* 18 */

Definition at line 79 of file lpp.c.

◆ LPP_TEMPERATURE_CHANNEL_INT

#define LPP_TEMPERATURE_CHANNEL_INT   0x11 /* 17 */

Definition at line 78 of file lpp.c.

◆ LPP_TEMPERATURE_SIZE

#define LPP_TEMPERATURE_SIZE   0x04

Definition at line 63 of file lpp.c.

◆ LPP_VBAT_CHANNEL

#define LPP_VBAT_CHANNEL   0x10 /* 16 */

Definition at line 77 of file lpp.c.

Function Documentation

◆ LPP_AddAccelerometer()

bool LPP_AddAccelerometer ( LPP_Buffer_t b,
int16_t  x,
int16_t  y,
int16_t  z 
)

Definition at line 630 of file lpp.c.

631 {
632  uint8_t space = b->length - b->fill;
633  if(space < LPP_ACCELEROMETER_SIZE){
634  return (false);
635  }
636 
638  b->buffer[b->fill++] = LPP_ACCELEROMETER;
639  b->buffer[b->fill++] = (uint8_t)((0xFF00 & x) >> 8);
640  b->buffer[b->fill++] = (uint8_t)(0x00FF & x);
641  b->buffer[b->fill++] = (uint8_t)((0xFF00 & y) >> 8);
642  b->buffer[b->fill++] = (uint8_t)(0x00FF & y);
643  b->buffer[b->fill++] = (uint8_t)((0xFF00 & z) >> 8);
644  b->buffer[b->fill++] = (uint8_t)(0x00FF & z);
645 
646  return (true);
647 }
#define LPP_ACCELEROMETER_CHANNEL
Definition: lpp.c:73
uint8_t fill
Definition: lpp.h:41
uint8_t * buffer
Definition: lpp.h:40
#define LPP_ACCELEROMETER
Definition: lpp.c:57
uint8_t length
Definition: lpp.h:42
#define LPP_ACCELEROMETER_SIZE
Definition: lpp.c:65

◆ LPP_AddAnalog()

bool LPP_AddAnalog ( LPP_Buffer_t b,
int16_t  data 
)

Definition at line 586 of file lpp.c.

587 {
588  uint8_t space = b->length - b->fill;
589  if(space < LPP_ANALOG_INPUT_SIZE){
590  return (false);
591  }
592 
594  b->buffer[b->fill++] = LPP_ANALOG_INPUT;
595  b->buffer[b->fill++] = (uint8_t)((0xFF00 & data) >> 8);
596  b->buffer[b->fill++] = (uint8_t)(0x00FF & data);
597 
598  return (true);
599 }
uint8_t fill
Definition: lpp.h:41
MeasurementData_t data
Definition: main.c:189
#define LPP_ANALOG_INPUT_CHANNEL
Definition: lpp.c:70
uint8_t * buffer
Definition: lpp.h:40
#define LPP_ANALOG_INPUT_SIZE
Definition: lpp.c:62
uint8_t length
Definition: lpp.h:42
#define LPP_ANALOG_INPUT
Definition: lpp.c:54

◆ LPP_AddCableBroken()

bool LPP_AddCableBroken ( LPP_Buffer_t b,
uint8_t  cableBroken 
)

Add a value to indicate that the cable has been broken to the LPP packet following the custom message convention.

This is what each added byte represents:

  • byte 0: Amount of measurements (in this case always one)
  • byte 1: Cable broken channel (LPP_CABLE_BROKEN_CHANNEL = 0x14)
  • byte 2: LPP digital input type (LPP_DIGITAL_INPUT = 0x00)
  • byte 3: The cableBroken value

We always need 4 bytes.

Parameters
[in]bThe pointer to the LPP pointer.
[in]cableBrokenThe cable break value.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 317 of file lpp.c.

318 {
319  /* Calculate free space in the buffer */
320  uint8_t space = b->length - b->fill;
321 
322  /* Return `false` if we don't have the necessary space available */
323  if (space < LPP_DIGITAL_INPUT_SIZE + 1) return (false); /* "+1": One extra byte for the amount of measurements */
324 
325  /* Fill the first byte with the amount of measurements (in this case always one) */
326  b->buffer[b->fill++] = 0x01;
327 
328  /* Fill the next bytes following the default LPP packet convention */
330  b->buffer[b->fill++] = LPP_DIGITAL_INPUT;
331  b->buffer[b->fill++] = cableBroken;
332 
333  return (true);
334 }
uint8_t fill
Definition: lpp.h:41
#define LPP_DIGITAL_INPUT_SIZE
Definition: lpp.c:61
#define LPP_CABLE_BROKEN_CHANNEL
Definition: lpp.c:81
uint8_t * buffer
Definition: lpp.h:40
#define LPP_DIGITAL_INPUT
Definition: lpp.c:53
uint8_t length
Definition: lpp.h:42

◆ LPP_AddDigital()

bool LPP_AddDigital ( LPP_Buffer_t b,
uint8_t  data 
)

Definition at line 572 of file lpp.c.

573 {
574  uint8_t space = b->length - b->fill;
575  if(space < LPP_DIGITAL_INPUT_SIZE){
576  return (false);
577  }
578 
580  b->buffer[b->fill++] = LPP_DIGITAL_INPUT;
581  b->buffer[b->fill++] = data;
582 
583  return (true);
584 }
uint8_t fill
Definition: lpp.h:41
#define LPP_DIGITAL_INPUT_SIZE
Definition: lpp.c:61
MeasurementData_t data
Definition: main.c:189
uint8_t * buffer
Definition: lpp.h:40
#define LPP_DIGITAL_INPUT
Definition: lpp.c:53
#define LPP_DIGITAL_INPUT_CHANNEL
Definition: lpp.c:69
uint8_t length
Definition: lpp.h:42

◆ LPP_AddHumidity()

bool LPP_AddHumidity ( LPP_Buffer_t b,
uint8_t  data 
)

Definition at line 616 of file lpp.c.

617 {
618  uint8_t space = b->length - b->fill;
619  if(space < LPP_HUMIDITY_SIZE){
620  return (false);
621  }
622 
623  b->buffer[b->fill++] = LPP_HUMIDITY_CHANNEL;
624  b->buffer[b->fill++] = LPP_HUMIDITY;
625  b->buffer[b->fill++] = data;
626 
627  return (true);
628 }
#define LPP_HUMIDITY
Definition: lpp.c:56
uint8_t fill
Definition: lpp.h:41
MeasurementData_t data
Definition: main.c:189
#define LPP_HUMIDITY_CHANNEL
Definition: lpp.c:72
uint8_t * buffer
Definition: lpp.h:40
#define LPP_HUMIDITY_SIZE
Definition: lpp.c:64
uint8_t length
Definition: lpp.h:42

◆ LPP_AddMeasurements()

bool LPP_AddMeasurements ( LPP_Buffer_t b,
MeasurementData_t  data 
)

Add measurement data to the LPP packet following the custom message convention to save bytes to send.

This is what each added byte represents, in the case of 2 measurements:

  • byte 0: Amount of measurements
  • byte 1: Battery voltage channel (LPP_VBAT_CHANNEL = 0x10)
  • byte 2: LPP analog input type (LPP_ANALOG_INPUT = 0x02)
  • byte 3-4: A battery voltage measurement
  • byte 5-6: Another battery voltage measurement (in the case of 2 measurements)
  • ...
  • byte 7: Internal temperature channel (LPP_TEMPERATURE_CHANNEL_INT = 0x11)
  • byte 8: LPP temperature type (LPP_TEMPERATURE = 0x67)
  • byte 9-10: An internal temperature measurement
  • byte 11-12: Another internal temperature measurement (in the case of 2 measurements)
  • ...
  • byte 13: External temperature channel (LPP_TEMPERATURE_CHANNEL_EXT = 0x12)
  • byte 14: LPP temperature type (LPP_TEMPERATURE = 0x67)
  • byte 15-16: An external temperature measurement
  • byte 17-18: Another external temperature measurement (in the case of 2 measurements)
  • ...

If we have 6 measurements we need 43 bytes:

  • 1 byte to hold the amount of measurements
  • 2 bytes to hold the battery voltage channel and LPP analog input type
  • 6*2bytes to hold the battery voltage measurements
  • 2 bytes to hold the internal temperature channel and LPP temperature type
  • 6*2bytes to hold the internal temperature measurements
  • 2 bytes to hold the external temperature channel and LPP temperature type
  • 6*2bytes to hold the external temperature measurements
Parameters
[in]bThe pointer to the LPP pointer.
[in]dataThe struct which contains the measurements to send using LoRaWAN.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 182 of file lpp.c.

183 {
184 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
185  dbinfo("Started adding measurements...");
186 #endif /* DEBUG_DBPRINT */
187 
188  /* Calculate free space in the buffer */
189  uint8_t space = b->length - b->fill;
190 
191  /* Calculate necessary space, first byte holds the amount of measurements */
192  uint8_t necessarySpace = 1;
193 
194  /* Add space necessary for the battery voltage and internal and external temperature measurements.
195  * (1 byte for the channel ID, 1 byte for the data type, 2 bytes for each measurement) */
196  necessarySpace += 3*(2+(2*(data.index)));
197 
198  /* Return `false` if we don't have the necessary space available */
199  if (space < necessarySpace) return (false);
200 
201  /* Fill the first byte with the amount of measurements */
202  b->buffer[b->fill++] = data.index;
203 
204  /* Fill the next bytes with battery voltage measurements */
205  b->buffer[b->fill++] = LPP_VBAT_CHANNEL;
206  b->buffer[b->fill++] = LPP_ANALOG_INPUT;
207 
208  for (uint8_t i = 0; i < data.index; i++)
209  {
210  /* Convert battery voltage value (should represent 0.01 signed ) */
211  int16_t batteryLPP = (int16_t)(round((float)data.voltage[i]/10));
212 
213  b->buffer[b->fill++] = (uint8_t)((0xFF00 & batteryLPP) >> 8);
214  b->buffer[b->fill++] = (uint8_t)(0x00FF & batteryLPP);
215  }
216 
217  /* Fill the next bytes with internal temperature measurements */
219  b->buffer[b->fill++] = LPP_TEMPERATURE;
220 
221  for (uint8_t i = 0; i < data.index; i++)
222  {
223  /* Convert temperature sensor value (should represent 0.1 °C Signed MSB) */
224  int16_t intTempLPP = (int16_t)(round((float)data.intTemp[i]/100));
225 
226  b->buffer[b->fill++] = (uint8_t)((0xFF00 & intTempLPP) >> 8);
227  b->buffer[b->fill++] = (uint8_t)(0x00FF & intTempLPP);
228  }
229 
230  /* Fill the next bytes with external temperature measurements */
232  b->buffer[b->fill++] = LPP_TEMPERATURE;
233 
234  for (uint8_t i = 0; i < data.index; i++)
235  {
236  /* Convert temperature sensor value (should represent 0.1 °C Signed MSB) */
237  int16_t extTempLPP = (int16_t)(round((float)data.extTemp[i]/100));
238 
239  b->buffer[b->fill++] = (uint8_t)((0xFF00 & extTempLPP) >> 8);
240  b->buffer[b->fill++] = (uint8_t)(0x00FF & extTempLPP);
241  }
242 
243 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
244  dbinfo("Measurements successfully added.");
245 #endif /* DEBUG_DBPRINT */
246 
247  return (true);
248 }
uint8_t fill
Definition: lpp.h:41
#define LPP_TEMPERATURE
Definition: lpp.c:55
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
int32_t intTemp[6]
Definition: datatypes.h:73
uint8_t * buffer
Definition: lpp.h:40
#define LPP_VBAT_CHANNEL
Definition: lpp.c:77
int32_t extTemp[6]
Definition: datatypes.h:74
#define LPP_TEMPERATURE_CHANNEL_INT
Definition: lpp.c:78
uint8_t length
Definition: lpp.h:42
int32_t voltage[6]
Definition: datatypes.h:72
#define LPP_ANALOG_INPUT
Definition: lpp.c:54
#define LPP_TEMPERATURE_CHANNEL_EXT
Definition: lpp.c:79

◆ LPP_AddPressure()

bool LPP_AddPressure ( LPP_Buffer_t b,
uint16_t  data 
)

Definition at line 649 of file lpp.c.

650 {
651  uint8_t space = b->length - b->fill;
652  if(space < LPP_PRESSURE_SIZE){
653  return (false);
654  }
655 
656  b->buffer[b->fill++] = LPP_PRESSURE_CHANNEL;
657  b->buffer[b->fill++] = LPP_PRESSURE;
658  b->buffer[b->fill++] = (uint8_t)((0xFF00 & data) >> 8);
659  b->buffer[b->fill++] = (uint8_t)(0x00FF & data);
660 
661  return (true);
662 }
uint8_t fill
Definition: lpp.h:41
#define LPP_PRESSURE_CHANNEL
Definition: lpp.c:74
MeasurementData_t data
Definition: main.c:189
#define LPP_PRESSURE
Definition: lpp.c:58
uint8_t * buffer
Definition: lpp.h:40
uint8_t length
Definition: lpp.h:42
#define LPP_PRESSURE_SIZE
Definition: lpp.c:66

◆ LPP_AddStatus()

bool LPP_AddStatus ( LPP_Buffer_t b,
uint8_t  status 
)

Add a value to indicate a program status to the LPP packet following the custom message convention.

This is what each added byte represents:

  • byte 0: Amount of measurements (in this case always one)
  • byte 1: Status channel (LPP_STATUS_CHANNEL = 0x15)
  • byte 2: LPP digital input type (LPP_DIGITAL_INPUT = 0x00)
  • byte 3: The status value

We always need 4 bytes.

Parameters
[in]bThe pointer to the LPP pointer.
[in]statusThe status value.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 360 of file lpp.c.

361 {
362  /* Calculate free space in the buffer */
363  uint8_t space = b->length - b->fill;
364 
365  /* Return `false` if we don't have the necessary space available */
366  if (space < LPP_DIGITAL_INPUT_SIZE + 1) return (false); /* "+1": One extra byte for the amount of measurements */
367 
368  /* Fill the first byte with the amount of measurements (in this case always one) */
369  b->buffer[b->fill++] = 0x01;
370 
371  /* Fill the next bytes following the default LPP packet convention */
372  b->buffer[b->fill++] = LPP_STATUS_CHANNEL;
373  b->buffer[b->fill++] = LPP_DIGITAL_INPUT;
374  b->buffer[b->fill++] = status;
375 
376  return (true);
377 }
#define LPP_STATUS_CHANNEL
Definition: lpp.c:82
uint8_t fill
Definition: lpp.h:41
#define LPP_DIGITAL_INPUT_SIZE
Definition: lpp.c:61
uint8_t * buffer
Definition: lpp.h:40
#define LPP_DIGITAL_INPUT
Definition: lpp.c:53
uint8_t length
Definition: lpp.h:42

◆ LPP_AddStormDetected()

bool LPP_AddStormDetected ( LPP_Buffer_t b,
uint8_t  stormDetected 
)

Add a value to indicate that a storm has been detected to the LPP packet following the custom message convention.

This is what each added byte represents:

  • byte 0: Amount of measurements (in this case always one)
  • byte 1: Storm detected channel (LPP_STORM_CHANNEL = 0x13)
  • byte 2: LPP digital input type (LPP_DIGITAL_INPUT = 0x00)
  • byte 3: The stormDetected value

We always need 4 bytes.

Parameters
[in]bThe pointer to the LPP pointer.
[in]stormDetectedIf a storm is detected using the accelerometer or not.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 274 of file lpp.c.

275 {
276  /* Calculate free space in the buffer */
277  uint8_t space = b->length - b->fill;
278 
279  /* Return `false` if we don't have the necessary space available */
280  if (space < LPP_DIGITAL_INPUT_SIZE + 1) return (false); /* "+1": One extra byte for the amount of measurements */
281 
282  /* Fill the first byte with the amount of measurements (in this case always one) */
283  b->buffer[b->fill++] = 0x01;
284 
285  /* Fill the next bytes following the default LPP packet convention */
286  b->buffer[b->fill++] = LPP_STORM_CHANNEL;
287  b->buffer[b->fill++] = LPP_DIGITAL_INPUT;
288  b->buffer[b->fill++] = stormDetected;
289 
290  return (true);
291 }
uint8_t fill
Definition: lpp.h:41
#define LPP_DIGITAL_INPUT_SIZE
Definition: lpp.c:61
uint8_t * buffer
Definition: lpp.h:40
#define LPP_DIGITAL_INPUT
Definition: lpp.c:53
#define LPP_STORM_CHANNEL
Definition: lpp.c:80
uint8_t length
Definition: lpp.h:42

◆ LPP_AddTemperature()

bool LPP_AddTemperature ( LPP_Buffer_t b,
int16_t  data 
)

Definition at line 601 of file lpp.c.

602 {
603  uint8_t space = b->length - b->fill;
604  if(space < LPP_TEMPERATURE_SIZE){
605  return (false);
606  }
607 
609  b->buffer[b->fill++] = LPP_TEMPERATURE;
610  b->buffer[b->fill++] = (uint8_t)((0xFF00 & data) >> 8);
611  b->buffer[b->fill++] = (uint8_t)(0x00FF & data);
612 
613  return (true);
614 }
uint8_t fill
Definition: lpp.h:41
#define LPP_TEMPERATURE
Definition: lpp.c:55
MeasurementData_t data
Definition: main.c:189
uint8_t * buffer
Definition: lpp.h:40
#define LPP_TEMPERATURE_CHANNEL
Definition: lpp.c:71
uint8_t length
Definition: lpp.h:42
#define LPP_TEMPERATURE_SIZE
Definition: lpp.c:63

◆ LPP_ClearBuffer()

void LPP_ClearBuffer ( LPP_Buffer_t b)

Definition at line 118 of file lpp.c.

119 {
120  memset(b->buffer, 0, b->length);
121  b->fill = 0;
122 
123 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
124  dbinfo("> LPP buffer cleared.");
125 #endif /* DEBUG_DBPRINT */
126 
127 }
uint8_t fill
Definition: lpp.h:41
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
uint8_t * buffer
Definition: lpp.h:40
uint8_t length
Definition: lpp.h:42

◆ LPP_deprecated_AddCableBroken()

bool LPP_deprecated_AddCableBroken ( LPP_Buffer_t b,
uint8_t  cableBroken 
)

Add a cable break value to the LPP packet, disguised as a Digital Input packet (1 byte). The channel is defined by LPP_CABLE_BROKEN_CHANNEL and is 0x14.

Deprecated:
This is a deprecated method following the standard LPP format to add data to the LPP packet. The method is kept here just in case.
Parameters
[in]bThe pointer to the LPP pointer.
[in]cableBrokenThe cable break value.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 529 of file lpp.c.

530 {
531  uint8_t space = b->length - b->fill;
532  if (space < LPP_DIGITAL_INPUT_SIZE) return (false);
533 
535  b->buffer[b->fill++] = LPP_DIGITAL_INPUT;
536  b->buffer[b->fill++] = cableBroken;
537 
538  return (true);
539 }
uint8_t fill
Definition: lpp.h:41
#define LPP_DIGITAL_INPUT_SIZE
Definition: lpp.c:61
#define LPP_CABLE_BROKEN_CHANNEL
Definition: lpp.c:81
uint8_t * buffer
Definition: lpp.h:40
#define LPP_DIGITAL_INPUT
Definition: lpp.c:53
uint8_t length
Definition: lpp.h:42

◆ LPP_deprecated_AddExtTemp()

bool LPP_deprecated_AddExtTemp ( LPP_Buffer_t b,
int16_t  extTemp 
)

Add an external temperature measurement (2 bytes) to the LPP packet. The channel is defined by LPP_TEMPERATURE_CHANNEL_EXT and is 0x12.

Deprecated:
This is a deprecated method following the standard LPP format to add data to the LPP packet. In practice it uses too much bytes to send a lot of measurements at once. The method is kept here just in case.
Parameters
[in]bThe pointer to the LPP pointer.
[in]extTempThe measured external temperature.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 466 of file lpp.c.

467 {
468  uint8_t space = b->length - b->fill;
469  if (space < LPP_TEMPERATURE_SIZE) return (false);
470 
472  b->buffer[b->fill++] = LPP_TEMPERATURE;
473  b->buffer[b->fill++] = (uint8_t)((0xFF00 & extTemp) >> 8);
474  b->buffer[b->fill++] = (uint8_t)(0x00FF & extTemp);
475 
476  return (true);
477 }
uint8_t fill
Definition: lpp.h:41
#define LPP_TEMPERATURE
Definition: lpp.c:55
uint8_t * buffer
Definition: lpp.h:40
uint8_t length
Definition: lpp.h:42
#define LPP_TEMPERATURE_SIZE
Definition: lpp.c:63
#define LPP_TEMPERATURE_CHANNEL_EXT
Definition: lpp.c:79

◆ LPP_deprecated_AddIntTemp()

bool LPP_deprecated_AddIntTemp ( LPP_Buffer_t b,
int16_t  intTemp 
)

Add an internal temperature measurement (2 bytes) to the LPP packet. The channel is defined by LPP_TEMPERATURE_CHANNEL_INT and is 0x11.

Deprecated:
This is a deprecated method following the standard LPP format to add data to the LPP packet. In practice it uses too much bytes to send a lot of measurements at once. The method is kept here just in case.
Parameters
[in]bThe pointer to the LPP pointer.
[in]intTempThe measured internal temperature.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 433 of file lpp.c.

434 {
435  uint8_t space = b->length - b->fill;
436  if (space < LPP_TEMPERATURE_SIZE) return (false);
437 
439  b->buffer[b->fill++] = LPP_TEMPERATURE;
440  b->buffer[b->fill++] = (uint8_t)((0xFF00 & intTemp) >> 8);
441  b->buffer[b->fill++] = (uint8_t)(0x00FF & intTemp);
442 
443  return (true);
444 }
uint8_t fill
Definition: lpp.h:41
#define LPP_TEMPERATURE
Definition: lpp.c:55
uint8_t * buffer
Definition: lpp.h:40
#define LPP_TEMPERATURE_CHANNEL_INT
Definition: lpp.c:78
uint8_t length
Definition: lpp.h:42
#define LPP_TEMPERATURE_SIZE
Definition: lpp.c:63

◆ LPP_deprecated_AddStatus()

bool LPP_deprecated_AddStatus ( LPP_Buffer_t b,
uint8_t  status 
)

Add a status value to the LPP packet, disguised as a Digital Input packet (1 byte). The channel is defined by LPP_STATUS_CHANNEL and is 0x15.

Deprecated:
This is a deprecated method following the standard LPP format to add data to the LPP packet. The method is kept here just in case.
Parameters
[in]bThe pointer to the LPP pointer.
[in]statusThe status value.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 560 of file lpp.c.

561 {
562  uint8_t space = b->length - b->fill;
563  if (space < LPP_DIGITAL_INPUT_SIZE) return (false);
564 
565  b->buffer[b->fill++] = LPP_STATUS_CHANNEL;
566  b->buffer[b->fill++] = LPP_DIGITAL_INPUT;
567  b->buffer[b->fill++] = status;
568 
569  return (true);
570 }
#define LPP_STATUS_CHANNEL
Definition: lpp.c:82
uint8_t fill
Definition: lpp.h:41
#define LPP_DIGITAL_INPUT_SIZE
Definition: lpp.c:61
uint8_t * buffer
Definition: lpp.h:40
#define LPP_DIGITAL_INPUT
Definition: lpp.c:53
uint8_t length
Definition: lpp.h:42

◆ LPP_deprecated_AddStormDetected()

bool LPP_deprecated_AddStormDetected ( LPP_Buffer_t b,
uint8_t  stormDetected 
)

Add a storm value to the LPP packet, disguised as a Digital Input packet (1 byte). The channel is defined by LPP_STORM_CHANNEL and is 0x13.

Deprecated:
This is a deprecated method following the standard LPP format to add data to the LPP packet. The method is kept here just in case.
Parameters
[in]bThe pointer to the LPP pointer.
[in]stormDetectedIf a storm is detected using the accelerometer or not.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 498 of file lpp.c.

499 {
500  uint8_t space = b->length - b->fill;
501  if (space < LPP_DIGITAL_INPUT_SIZE) return (false);
502 
503  b->buffer[b->fill++] = LPP_STORM_CHANNEL;
504  b->buffer[b->fill++] = LPP_DIGITAL_INPUT;
505  b->buffer[b->fill++] = stormDetected;
506 
507  return (true);
508 }
uint8_t fill
Definition: lpp.h:41
#define LPP_DIGITAL_INPUT_SIZE
Definition: lpp.c:61
uint8_t * buffer
Definition: lpp.h:40
#define LPP_DIGITAL_INPUT
Definition: lpp.c:53
#define LPP_STORM_CHANNEL
Definition: lpp.c:80
uint8_t length
Definition: lpp.h:42

◆ LPP_deprecated_AddVBAT()

bool LPP_deprecated_AddVBAT ( LPP_Buffer_t b,
int16_t  vbat 
)

Add a battery voltage measurement to the LPP packet, disguised as an Analog Input packet (2 bytes). The channel is defined by LPP_VBAT_CHANNEL and is 0x10.

Deprecated:
This is a deprecated method following the standard LPP format to add data to the LPP packet. In practice it uses too much bytes to send a lot of measurements at once. The method is kept here just in case.
Parameters
[in]bThe pointer to the LPP pointer.
[in]vbatThe measured battery voltage.
Returns
  • true - Successfully added the data to the LoRaWAN packet.
  • false - Couldn't add the data to the LoRaWAN packet.

Definition at line 400 of file lpp.c.

401 {
402  uint8_t space = b->length - b->fill;
403  if (space < LPP_ANALOG_INPUT_SIZE) return (false);
404 
405  b->buffer[b->fill++] = LPP_VBAT_CHANNEL;
406  b->buffer[b->fill++] = LPP_ANALOG_INPUT;
407  b->buffer[b->fill++] = (uint8_t)((0xFF00 & vbat) >> 8);
408  b->buffer[b->fill++] = (uint8_t)(0x00FF & vbat);
409 
410  return (true);
411 }
uint8_t fill
Definition: lpp.h:41
uint8_t * buffer
Definition: lpp.h:40
#define LPP_VBAT_CHANNEL
Definition: lpp.c:77
#define LPP_ANALOG_INPUT_SIZE
Definition: lpp.c:62
uint8_t length
Definition: lpp.h:42
#define LPP_ANALOG_INPUT
Definition: lpp.c:54

◆ LPP_FreeBuffer()

void LPP_FreeBuffer ( LPP_Buffer_t b)

Definition at line 129 of file lpp.c.

130 {
131  if (b->buffer != NULL) free(b->buffer); /* This logic was previously in `LPP_ClearBuffer` */
132 
133 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
134  dbinfo("> LPP buffer freed.");
135 #endif /* DEBUG_DBPRINT */
136 
137 }
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
uint8_t * buffer
Definition: lpp.h:40

◆ LPP_InitBuffer()

bool LPP_InitBuffer ( LPP_Buffer_t b,
uint8_t  size 
)

Definition at line 84 of file lpp.c.

85 {
86 
87 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
88  dbinfo("Started initializing LPP buffer...");
89 #endif /* DEBUG_DBPRINT */
90 
91  // LPP_FreeBuffer(b); // Before: LPP_ClearBuffer(b);
92 
93  b->buffer = (uint8_t *) malloc(sizeof(uint8_t) * size);
94 
95 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
96  dbinfo("> Memory allocated.");
97 #endif /* DEBUG_DBPRINT */
98 
99  if(b->buffer != NULL)
100  {
101  b->fill = 0;
102  b->length = size;
103 
104 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
105  dbinfo("LPP Buffer initialized (returned true).");
106 #endif /* DEBUG_DBPRINT */
107 
108  return (true);
109  }
110 
111 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
112  dbwarn("LPP Buffer initialized (returned false).");
113 #endif /* DEBUG_DBPRINT */
114 
115  return (false);
116 }
uint8_t fill
Definition: lpp.h:41
void dbwarn(char *message)
Print a warning string (char array) in yellow to USARTx and go to the next line.
Definition: dbprint.c:521
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
uint8_t * buffer
Definition: lpp.h:40
uint8_t length
Definition: lpp.h:42