@@ -13,12 +13,10 @@ MyMessage::MyMessage(uint8_t _sensor, uint8_t _type) {
13
13
type = _type;
14
14
}
15
15
16
-
17
16
bool MyMessage::isAck () const {
18
17
return miGetAck ();
19
18
}
20
19
21
-
22
20
/* Getters for payload converted to desired form */
23
21
void * MyMessage::getCustom () const {
24
22
return (void *)data;
@@ -42,16 +40,20 @@ char MyMessage::i2h(uint8_t i) const {
42
40
return ' A' + k - 10 ;
43
41
}
44
42
43
+ char * MyMessage::getCustomString (char *buffer) const {
44
+ for (uint8_t i = 0 ; i < miGetLength (); i++)
45
+ {
46
+ buffer[i * 2 ] = i2h (data[i] >> 4 );
47
+ buffer[(i * 2 ) + 1 ] = i2h (data[i]);
48
+ }
49
+ buffer[miGetLength () * 2 ] = ' \0 ' ;
50
+ return buffer;
51
+ }
52
+
45
53
char * MyMessage::getStream (char *buffer) const {
46
54
uint8_t cmd = miGetCommand ();
47
55
if ((cmd == C_STREAM) && (buffer != NULL )) {
48
- for (uint8_t i = 0 ; i < miGetLength (); i++)
49
- {
50
- buffer[i * 2 ] = i2h (data[i] >> 4 );
51
- buffer[(i * 2 ) + 1 ] = i2h (data[i]);
52
- }
53
- buffer[miGetLength () * 2 ] = ' \0 ' ;
54
- return buffer;
56
+ return getCustomString (buffer);
55
57
} else {
56
58
return NULL ;
57
59
}
@@ -73,12 +75,11 @@ char* MyMessage::getString(char *buffer) const {
73
75
} else if (payloadType == P_LONG32) {
74
76
ltoa (lValue, buffer, 10 );
75
77
} else if (payloadType == P_ULONG32) {
76
-
77
78
ultoa (ulValue, buffer, 10 );
78
79
} else if (payloadType == P_FLOAT32) {
79
80
dtostrf (fValue ,2 ,fPrecision ,buffer);
80
81
} else if (payloadType == P_CUSTOM) {
81
- return getStream (buffer);
82
+ return getCustomString (buffer);
82
83
}
83
84
return buffer;
84
85
} else {
@@ -151,7 +152,6 @@ unsigned int MyMessage::getUInt() const {
151
152
152
153
}
153
154
154
-
155
155
MyMessage& MyMessage::setType (uint8_t _type) {
156
156
type = _type;
157
157
return *this ;
@@ -175,7 +175,6 @@ MyMessage& MyMessage::set(void* value, uint8_t length) {
175
175
return *this ;
176
176
}
177
177
178
-
179
178
MyMessage& MyMessage::set (const char * value) {
180
179
uint8_t length = min (strlen (value), MAX_PAYLOAD);
181
180
miSetLength (length);
@@ -191,7 +190,6 @@ MyMessage& MyMessage::set(uint8_t value) {
191
190
return *this ;
192
191
}
193
192
194
-
195
193
MyMessage& MyMessage::set (float value, uint8_t decimals) {
196
194
miSetLength (5 ); // 32 bit float + persi
197
195
miSetPayloadType (P_FLOAT32);
@@ -227,5 +225,3 @@ MyMessage& MyMessage::set(int value) {
227
225
iValue = value;
228
226
return *this ;
229
227
}
230
-
231
-
0 commit comments