-
Notifications
You must be signed in to change notification settings - Fork 1
/
sigfoxMessage.cpp
48 lines (38 loc) · 1008 Bytes
/
sigfoxMessage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "sigfoxMessage.h"
#include <cstring>
void SigfoxMessage::writeLongitude(Longitude longitude)
{
memcpy(&_message[0], &longitude, sizeof(longitude));
}
void SigfoxMessage::writeLatitude(Latitude latitude)
{
memcpy(&_message[4], &latitude, sizeof(latitude));
}
void SigfoxMessage::writeTemperature(CentiCelsius temperature)
{
memcpy(&_message[8], &temperature, sizeof(temperature));
}
void SigfoxMessage::writeHumidity(Humidity humidity)
{
memcpy(&_message[10], &humidity, sizeof(humidity));
}
void SigfoxMessage::writeFreefall(bool freefall)
{
char value = _message[11] & 0xFE;
value |= (freefall ? 0x01 : 0x00);
memcpy(&_message[11], &value, sizeof(value));
}
void SigfoxMessage::writeOpened(bool opened)
{
char value = _message[11] & 0xFD;
value |= (opened ? 0x02 : 0x00);
memcpy(&_message[11], &value, sizeof(value));
}
const char* SigfoxMessage::message() const
{
return _message;
}
void SigfoxMessage::reset()
{
memset(_message, 0, sizeof(_message));
}