@@ -13,12 +13,10 @@ MyMessage::MyMessage(uint8_t _sensor, uint8_t _type) {
1313 type = _type;
1414}
1515
16-
1716bool MyMessage::isAck () const {
1817 return miGetAck ();
1918}
2019
21-
2220/* Getters for payload converted to desired form */
2321void * MyMessage::getCustom () const {
2422 return (void *)data;
@@ -42,16 +40,20 @@ char MyMessage::i2h(uint8_t i) const {
4240 return ' A' + k - 10 ;
4341}
4442
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+
4553char * MyMessage::getStream (char *buffer) const {
4654 uint8_t cmd = miGetCommand ();
4755 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);
5557 } else {
5658 return NULL ;
5759 }
@@ -73,12 +75,11 @@ char* MyMessage::getString(char *buffer) const {
7375 } else if (payloadType == P_LONG32) {
7476 ltoa (lValue, buffer, 10 );
7577 } else if (payloadType == P_ULONG32) {
76-
7778 ultoa (ulValue, buffer, 10 );
7879 } else if (payloadType == P_FLOAT32) {
7980 dtostrf (fValue ,2 ,fPrecision ,buffer);
8081 } else if (payloadType == P_CUSTOM) {
81- return getStream (buffer);
82+ return getCustomString (buffer);
8283 }
8384 return buffer;
8485 } else {
@@ -151,7 +152,6 @@ unsigned int MyMessage::getUInt() const {
151152
152153}
153154
154-
155155MyMessage& MyMessage::setType (uint8_t _type) {
156156 type = _type;
157157 return *this ;
@@ -175,7 +175,6 @@ MyMessage& MyMessage::set(void* value, uint8_t length) {
175175 return *this ;
176176}
177177
178-
179178MyMessage& MyMessage::set (const char * value) {
180179 uint8_t length = min (strlen (value), MAX_PAYLOAD);
181180 miSetLength (length);
@@ -191,7 +190,6 @@ MyMessage& MyMessage::set(uint8_t value) {
191190 return *this ;
192191}
193192
194-
195193MyMessage& MyMessage::set (float value, uint8_t decimals) {
196194 miSetLength (5 ); // 32 bit float + persi
197195 miSetPayloadType (P_FLOAT32);
@@ -227,5 +225,3 @@ MyMessage& MyMessage::set(int value) {
227225 iValue = value;
228226 return *this ;
229227}
230-
231-
0 commit comments