Skip to content

Commit 7f4f765

Browse files
author
Marcelo Aquino
committed
get custom string from msg that isn't a stream type
1 parent ca6d79e commit 7f4f765

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

libraries/MySensors/MyMessage.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ MyMessage::MyMessage(uint8_t _sensor, uint8_t _type) {
1313
type = _type;
1414
}
1515

16-
1716
bool MyMessage::isAck() const {
1817
return miGetAck();
1918
}
2019

21-
2220
/* Getters for payload converted to desired form */
2321
void* 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+
4553
char* 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-
155155
MyMessage& 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-
179178
MyMessage& 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-
195193
MyMessage& 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-

libraries/MySensors/MyMessage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ typedef enum {
122122
#ifdef __cplusplus
123123
class MyMessage
124124
{
125+
private:
126+
char* getCustomString(char *buffer) const;
127+
125128
public:
126129
// Constructors
127130
MyMessage();

0 commit comments

Comments
 (0)