Skip to content

Commit 9f48f09

Browse files
committed
Rename PING to the more suitable FIND_PARENT
1 parent 6112253 commit 9f48f09

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

libraries/MySensors/MyMessage.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef enum {
4444
// Type of internal messages (for internal messages)
4545
typedef enum {
4646
I_BATTERY_LEVEL, I_TIME, I_VERSION, I_ID_REQUEST, I_ID_RESPONSE,
47-
I_INCLUSION_MODE, I_CONFIG, I_PING, I_PING_ACK,
47+
I_INCLUSION_MODE, I_CONFIG, I_FIND_PARENT, I_FIND_PARENT_RESPONSE,
4848
I_LOG_MESSAGE, I_CHILDREN, I_SKETCH_NAME, I_SKETCH_VERSION,
4949
I_REBOOT
5050
} internal;
@@ -185,17 +185,21 @@ struct
185185

186186
// Each message can transfer a payload. We add one extra byte for string
187187
// terminator \0 to be "printable" this is not transferred OTA
188-
// This union is used to simplify the construction of the binary transferred int/long values.
188+
// This union is used to simplify the construction of the binary data types transferred.
189189
union {
190190
uint8_t bValue;
191191
unsigned long ulValue;
192192
long lValue;
193193
unsigned int uiValue;
194194
int iValue;
195-
struct {
195+
struct { // Float messages
196196
float fValue;
197197
uint8_t fPrecision; // Number of decimals when serializing
198198
};
199+
struct { // Presentation messages
200+
uint8_t version; // Library version
201+
uint8_t sensorType; // Sensor type hint for controller, see table above
202+
};
199203
char data[MAX_PAYLOAD + 1];
200204
} __attribute__((packed));
201205
#ifdef __cplusplus

libraries/MySensors/MySensor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void MySensor::setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_
112112
RF24::setCRCLength(RF24_CRC_16);
113113
RF24::enableDynamicPayloads();
114114

115-
// All nodes listen to broadcast pipe (for PING-ACK messages)
115+
// All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages)
116116
RF24::openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));
117117
}
118118

@@ -145,7 +145,7 @@ void MySensor::findParentNode() {
145145
nc.distance = 255;
146146

147147
// Send ping message to BROADCAST_ADDRESS (to which all relaying nodes and gateway listens and should reply to)
148-
build(msg, nc.nodeId, BROADCAST_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_PING, false).set("");
148+
build(msg, nc.nodeId, BROADCAST_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT, false).set("");
149149
sendWrite(BROADCAST_ADDRESS, msg, true);
150150

151151
// Wait for ping response.
@@ -285,12 +285,12 @@ boolean MySensor::process() {
285285
uint8_t last = msg.last;
286286
uint8_t destination = msg.destination;
287287

288-
if (repeaterMode && command == C_INTERNAL && type == I_PING) {
288+
if (repeaterMode && command == C_INTERNAL && type == I_FIND_PARENT) {
289289
// Relaying nodes should always answer ping messages
290290
// Wait a random delay of 0-2 seconds to minimize collision
291291
// between ping ack messages from other relaying nodes
292292
delay(millis() & 0x3ff);
293-
sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_PING_ACK, false).set(nc.distance), true);
293+
sendWrite(sender, build(msg, nc.nodeId, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false).set(nc.distance), true);
294294
return false;
295295
} else if (destination == nc.nodeId) {
296296
// Check if sender requests an ack back.
@@ -311,8 +311,8 @@ boolean MySensor::process() {
311311
}
312312

313313
if (command == C_INTERNAL) {
314-
if (type == I_PING_ACK && !isGateway) {
315-
// We've received a reply to a PING message. Check if the distance is
314+
if (type == I_FIND_PARENT_RESPONSE && !isGateway) {
315+
// We've received a reply to a FIND_PARENT message. Check if the distance is
316316
// shorter than we already have.
317317
uint8_t distance = msg.getByte();
318318
if (distance<nc.distance-1) {

0 commit comments

Comments
 (0)