Merge branch 'master' into development
Conflicts: libraries/MySensors/MyGateway.cpp libraries/MySensors/MySensor.cpp
This commit is contained in:
@@ -67,9 +67,11 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
|
|||||||
|
|
||||||
autoFindParent = _parentNodeId == AUTO;
|
autoFindParent = _parentNodeId == AUTO;
|
||||||
if (!autoFindParent) {
|
if (!autoFindParent) {
|
||||||
nc.parentNodeId = _parentNodeId;
|
if (_parentNodeId != nc.parentNodeId) {
|
||||||
// Save static parent id in eeprom (used by bootloader)
|
nc.parentNodeId = _parentNodeId;
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId);
|
// Save static parent id in eeprom (used by bootloader)
|
||||||
|
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, _parentNodeId);
|
||||||
|
}
|
||||||
// We don't actually know the distance to gw here. Let's pretend it is 1.
|
// We don't actually know the distance to gw here. Let's pretend it is 1.
|
||||||
// If the current node is also repeater, be aware of this.
|
// If the current node is also repeater, be aware of this.
|
||||||
nc.distance = 1;
|
nc.distance = 1;
|
||||||
@@ -293,21 +295,23 @@ boolean MySensor::process() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command == C_INTERNAL) {
|
if (command == C_INTERNAL) {
|
||||||
if (type == I_FIND_PARENT_RESPONSE && !isGateway) {
|
if (type == I_FIND_PARENT_RESPONSE) {
|
||||||
// We've received a reply to a FIND_PARENT message. Check if the distance is
|
if (autoFindParent) {
|
||||||
// shorter than we already have.
|
// We've received a reply to a FIND_PARENT message. Check if the distance is
|
||||||
uint8_t distance = msg.getByte();
|
// shorter than we already have.
|
||||||
if (isValidDistance(distance))
|
uint8_t distance = msg.getByte();
|
||||||
{
|
if (isValidDistance(distance))
|
||||||
// Distance to gateway is one more for us w.r.t. parent
|
{
|
||||||
distance++;
|
// Distance to gateway is one more for us w.r.t. parent
|
||||||
if (isValidDistance(distance) && (distance < nc.distance)) {
|
distance++;
|
||||||
// Found a neighbor closer to GW than previously found
|
if (isValidDistance(distance) && (distance < nc.distance)) {
|
||||||
nc.distance = distance;
|
// Found a neighbor closer to GW than previously found
|
||||||
nc.parentNodeId = msg.sender;
|
nc.distance = distance;
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
|
nc.parentNodeId = msg.sender;
|
||||||
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
|
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
|
||||||
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
|
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
|
||||||
|
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user