43 #include <em_device.h> 53 #define LPP_DIGITAL_INPUT 0x00 54 #define LPP_ANALOG_INPUT 0x02 55 #define LPP_TEMPERATURE 0x67 56 #define LPP_HUMIDITY 0x68 57 #define LPP_ACCELEROMETER 0x71 58 #define LPP_PRESSURE 0x73 61 #define LPP_DIGITAL_INPUT_SIZE 0x03 62 #define LPP_ANALOG_INPUT_SIZE 0x04 63 #define LPP_TEMPERATURE_SIZE 0x04 64 #define LPP_HUMIDITY_SIZE 0x03 65 #define LPP_ACCELEROMETER_SIZE 0x08 66 #define LPP_PRESSURE_SIZE 0x04 69 #define LPP_DIGITAL_INPUT_CHANNEL 0x01 70 #define LPP_ANALOG_INPUT_CHANNEL 0x02 71 #define LPP_TEMPERATURE_CHANNEL 0x03 72 #define LPP_HUMIDITY_CHANNEL 0x04 73 #define LPP_ACCELEROMETER_CHANNEL 0x05 74 #define LPP_PRESSURE_CHANNEL 0x06 77 #define LPP_VBAT_CHANNEL 0x10 78 #define LPP_TEMPERATURE_CHANNEL_INT 0x11 79 #define LPP_TEMPERATURE_CHANNEL_EXT 0x12 80 #define LPP_STORM_CHANNEL 0x13 81 #define LPP_CABLE_BROKEN_CHANNEL 0x14 82 #define LPP_STATUS_CHANNEL 0x15 87 #if DEBUG_DBPRINT == 1 88 dbinfo(
"Started initializing LPP buffer...");
93 b->
buffer = (uint8_t *) malloc(
sizeof(uint8_t) * size);
95 #if DEBUG_DBPRINT == 1 96 dbinfo(
"> Memory allocated.");
104 #if DEBUG_DBPRINT == 1 105 dbinfo(
"LPP Buffer initialized (returned true).");
111 #if DEBUG_DBPRINT == 1 112 dbwarn(
"LPP Buffer initialized (returned false).");
123 #if DEBUG_DBPRINT == 1 124 dbinfo(
"> LPP buffer cleared.");
133 #if DEBUG_DBPRINT == 1 134 dbinfo(
"> LPP buffer freed.");
184 #if DEBUG_DBPRINT == 1 185 dbinfo(
"Started adding measurements...");
192 uint8_t necessarySpace = 1;
196 necessarySpace += 3*(2+(2*(data.
index)));
199 if (space < necessarySpace)
return (
false);
208 for (uint8_t i = 0; i < data.
index; i++)
211 int16_t batteryLPP = (int16_t)(round((
float)data.
voltage[i]/10));
213 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & batteryLPP) >> 8);
214 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & batteryLPP);
221 for (uint8_t i = 0; i < data.
index; i++)
224 int16_t intTempLPP = (int16_t)(round((
float)data.
intTemp[i]/100));
226 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & intTempLPP) >> 8);
227 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & intTempLPP);
234 for (uint8_t i = 0; i < data.
index; i++)
237 int16_t extTempLPP = (int16_t)(round((
float)data.
extTemp[i]/100));
239 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & extTempLPP) >> 8);
240 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & extTempLPP);
243 #if DEBUG_DBPRINT == 1 244 dbinfo(
"Measurements successfully added.");
407 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & vbat) >> 8);
408 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & vbat);
440 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & intTemp) >> 8);
441 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & intTemp);
473 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & extTemp) >> 8);
474 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & extTemp);
595 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & data) >> 8);
596 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & data);
610 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & data) >> 8);
611 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & data);
639 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & x) >> 8);
641 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & y) >> 8);
643 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & z) >> 8);
658 b->
buffer[b->
fill++] = (uint8_t)((0xFF00 & data) >> 8);
659 b->
buffer[b->
fill++] = (uint8_t)(0x00FF & data);
#define LPP_STATUS_CHANNEL
bool LPP_AddDigital(LPP_Buffer_t *b, uint8_t data)
#define LPP_ACCELEROMETER_CHANNEL
bool LPP_InitBuffer(LPP_Buffer_t *b, uint8_t size)
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...
#define LPP_DIGITAL_INPUT_SIZE
#define LPP_PRESSURE_CHANNEL
Basic Low Power Payload (LPP) functionality.
bool LPP_AddPressure(LPP_Buffer_t *b, uint16_t data)
Definitions of the custom data-types used.
bool LPP_AddHumidity(LPP_Buffer_t *b, uint8_t data)
void dbwarn(char *message)
Print a warning string (char array) in yellow to USARTx and go to the next line.
bool LPP_AddTemperature(LPP_Buffer_t *b, int16_t data)
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
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)...
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.
#define LPP_ANALOG_INPUT_CHANNEL
#define LPP_CABLE_BROKEN_CHANNEL
#define LPP_HUMIDITY_CHANNEL
#define LPP_TEMPERATURE_CHANNEL
void LPP_ClearBuffer(LPP_Buffer_t *b)
#define LPP_DIGITAL_INPUT
#define LPP_STORM_CHANNEL
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...
void LPP_FreeBuffer(LPP_Buffer_t *b)
Enable or disable printing to UART with dbprint.
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)...
#define LPP_HUMIDITY_SIZE
bool LPP_AddAccelerometer(LPP_Buffer_t *b, int16_t x, int16_t y, int16_t z)
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...
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_TE...
#define LPP_DIGITAL_INPUT_CHANNEL
#define LPP_ACCELEROMETER
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...
#define LPP_ANALOG_INPUT_SIZE
#define LPP_TEMPERATURE_CHANNEL_INT
bool LPP_AddAnalog(LPP_Buffer_t *b, int16_t data)
#define LPP_TEMPERATURE_SIZE
#define LPP_PRESSURE_SIZE
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.
#define LPP_TEMPERATURE_CHANNEL_EXT
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_TE...
#define LPP_ACCELEROMETER_SIZE