Skip to content

Commit 85fe2d2

Browse files
author
Marcelo Aquino
committed
Merge from mysensors/Arduino
1 parent 3364c07 commit 85fe2d2

File tree

5 files changed

+166
-123
lines changed

5 files changed

+166
-123
lines changed

MyGateway.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
5050
#endif
5151
repeaterMode = true;
5252
isGateway = true;
53+
autoFindParent = false;
5354
setupRepeaterMode();
5455

5556
if (inDataCallback != NULL) {
@@ -60,6 +61,7 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
6061
}
6162

6263
nc.nodeId = 0;
64+
nc.parentNodeId = 0;
6365
nc.distance = 0;
6466
inclusionMode = 0;
6567
buttonTriggeredInclusion = false;

MyMessage.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ MyMessage::MyMessage(uint8_t _sensor, uint8_t _type) {
3434
type = _type;
3535
}
3636

37-
3837
bool MyMessage::isAck() const {
3938
return miGetAck();
4039
}
4140

42-
4341
/* Getters for payload converted to desired form */
4442
void* MyMessage::getCustom() const {
4543
return (void *)data;
@@ -63,16 +61,20 @@ char MyMessage::i2h(uint8_t i) const {
6361
return 'A' + k - 10;
6462
}
6563

64+
char* MyMessage::getCustomString(char *buffer) const {
65+
for (uint8_t i = 0; i < miGetLength(); i++)
66+
{
67+
buffer[i * 2] = i2h(data[i] >> 4);
68+
buffer[(i * 2) + 1] = i2h(data[i]);
69+
}
70+
buffer[miGetLength() * 2] = '\0';
71+
return buffer;
72+
}
73+
6674
char* MyMessage::getStream(char *buffer) const {
6775
uint8_t cmd = miGetCommand();
6876
if ((cmd == C_STREAM) && (buffer != NULL)) {
69-
for (uint8_t i = 0; i < miGetLength(); i++)
70-
{
71-
buffer[i * 2] = i2h(data[i] >> 4);
72-
buffer[(i * 2) + 1] = i2h(data[i]);
73-
}
74-
buffer[miGetLength() * 2] = '\0';
75-
return buffer;
77+
return getCustomString(buffer);
7678
} else {
7779
return NULL;
7880
}
@@ -94,12 +96,11 @@ char* MyMessage::getString(char *buffer) const {
9496
} else if (payloadType == P_LONG32) {
9597
ltoa(lValue, buffer, 10);
9698
} else if (payloadType == P_ULONG32) {
97-
9899
ultoa(ulValue, buffer, 10);
99100
} else if (payloadType == P_FLOAT32) {
100101
dtostrf(fValue,2,fPrecision,buffer);
101102
} else if (payloadType == P_CUSTOM) {
102-
return getStream(buffer);
103+
return getCustomString(buffer);
103104
}
104105
return buffer;
105106
} else {
@@ -172,7 +173,6 @@ unsigned int MyMessage::getUInt() const {
172173

173174
}
174175

175-
176176
MyMessage& MyMessage::setType(uint8_t _type) {
177177
type = _type;
178178
return *this;
@@ -196,12 +196,11 @@ MyMessage& MyMessage::set(void* value, uint8_t length) {
196196
return *this;
197197
}
198198

199-
200199
MyMessage& MyMessage::set(const char* value) {
201-
uint8_t length = strlen(value);
200+
uint8_t length = min(strlen(value), MAX_PAYLOAD);
202201
miSetLength(length);
203202
miSetPayloadType(P_STRING);
204-
strncpy(data, value, min(length, MAX_PAYLOAD));
203+
strncpy(data, value, length);
205204
return *this;
206205
}
207206

@@ -212,7 +211,6 @@ MyMessage& MyMessage::set(uint8_t value) {
212211
return *this;
213212
}
214213

215-
216214
MyMessage& MyMessage::set(float value, uint8_t decimals) {
217215
miSetLength(5); // 32 bit float + persi
218216
miSetPayloadType(P_FLOAT32);
@@ -436,6 +434,4 @@ char *ultoa(unsigned long num, char *str, int radix)
436434
return str;
437435
}
438436

439-
440437
#endif
441-

MyMessage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ typedef enum {
142142
#ifdef __cplusplus
143143
class MyMessage
144144
{
145+
private:
146+
char* getCustomString(char *buffer) const;
147+
145148
public:
146149
// Constructors
147150
MyMessage();

0 commit comments

Comments
 (0)