32
32
33
33
LoraEncoder::LoraEncoder (byte *buffer) {
34
34
_buffer = buffer;
35
+ _offset = 0 ;
35
36
}
36
37
37
38
void LoraEncoder::_intToBytes (byte *buf, int32_t i, uint8_t byteSize) {
@@ -41,38 +42,39 @@ void LoraEncoder::_intToBytes(byte *buf, int32_t i, uint8_t byteSize) {
41
42
}
42
43
43
44
void LoraEncoder::writeUnixtime (uint32_t unixtime) {
44
- _intToBytes (_buffer, unixtime, 4 );
45
- _buffer += 4 ;
45
+ _intToBytes (_buffer + _offset , unixtime, 4 );
46
+ _offset += 4 ;
46
47
}
47
48
48
49
void LoraEncoder::writeLatLng (double latitude, double longitude) {
49
50
int32_t lat = latitude * 1e6 ;
50
51
int32_t lng = longitude * 1e6 ;
51
52
52
- _intToBytes (_buffer, lat, 4 );
53
- _intToBytes (_buffer + 4 , lng, 4 );
54
- _buffer += 8 ;
53
+ _intToBytes (_buffer + _offset, lat, 4 );
54
+ _offset += 4 ;
55
+ _intToBytes (_buffer + _offset, lng, 4 );
56
+ _offset += 4 ;
55
57
}
56
58
57
59
void LoraEncoder::writeUint32 (uint32_t i) {
58
- _intToBytes (_buffer, i, 4 );
59
- _buffer += 4 ;
60
+ _intToBytes (_buffer + _offset , i, 4 );
61
+ _offset += 4 ;
60
62
}
61
63
62
64
void LoraEncoder::writeUint16 (uint16_t i) {
63
- _intToBytes (_buffer, i, 2 );
64
- _buffer += 2 ;
65
+ _intToBytes (_buffer + _offset , i, 2 );
66
+ _offset += 2 ;
65
67
}
66
68
67
69
void LoraEncoder::writeUint8 (uint8_t i) {
68
- _intToBytes (_buffer, i, 1 );
69
- _buffer += 1 ;
70
+ _intToBytes (_buffer + _offset , i, 1 );
71
+ _offset += 1 ;
70
72
}
71
73
72
74
void LoraEncoder::writeHumidity (float humidity) {
73
75
int16_t h = (int16_t ) (humidity * 100 );
74
- _intToBytes (_buffer, h, 2 );
75
- _buffer += 2 ;
76
+ _intToBytes (_buffer + _offset , h, 2 );
77
+ _offset += 2 ;
76
78
}
77
79
78
80
/* *
@@ -85,9 +87,9 @@ void LoraEncoder::writeTemperature(float temperature) {
85
87
t = ~-t;
86
88
t = t + 1 ;
87
89
}
88
- _buffer[0 ] = (byte) ((t >> 8 ) & 0xFF );
89
- _buffer[1 ] = (byte) t & 0xFF ;
90
- _buffer += 2 ;
90
+ _buffer[_offset ] = (byte) ((t >> 8 ) & 0xFF );
91
+ _buffer[_offset+ 1 ] = (byte) t & 0xFF ;
92
+ _offset += 2 ;
91
93
}
92
94
93
95
void LoraEncoder::writeBitmap (bool a, bool b, bool c, bool d, bool e, bool f, bool g, bool h) {
@@ -106,6 +108,10 @@ void LoraEncoder::writeBitmap(bool a, bool b, bool c, bool d, bool e, bool f, bo
106
108
107
109
void LoraEncoder::writeRawFloat (float value) {
108
110
uint32_t asbytes=*(reinterpret_cast <uint32_t *>(&value));
109
- _intToBytes (_buffer, asbytes, 4 );
110
- _buffer += 4 ;
111
+ _intToBytes (_buffer + _offset, asbytes, 4 );
112
+ _offset += 4 ;
113
+ }
114
+
115
+ int LoraEncoder::getLength (void ) {
116
+ return _offset;
111
117
}
0 commit comments