Merge pull request #62 from mapnull/hotfix-autoFindParent_response

Accept a new parent only when autoFindParent is 1
This commit is contained in:
Henrik Ekblad
2015-02-12 22:23:13 +01:00
2 changed files with 14 additions and 11 deletions
+1
View File
@@ -37,6 +37,7 @@ void MyGateway::begin(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e da
Serial.begin(BAUD_RATE);
repeaterMode = true;
isGateway = true;
autoFindParent = false;
setupRepeaterMode();
if (inDataCallback != NULL) {
+13 -11
View File
@@ -303,17 +303,19 @@ boolean MySensor::process() {
}
if (command == C_INTERNAL) {
if (type == I_FIND_PARENT_RESPONSE && !isGateway) {
// We've received a reply to a FIND_PARENT message. Check if the distance is
// shorter than we already have.
uint8_t distance = msg.getByte();
if (distance<nc.distance-1) {
// Found a neighbor closer to GW than previously found
nc.distance = distance + 1;
nc.parentNodeId = msg.sender;
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
if (type == I_FIND_PARENT_RESPONSE) {
if (autoFindParent) {
// We've received a reply to a FIND_PARENT message. Check if the distance is
// shorter than we already have.
uint8_t distance = msg.getByte();
if (distance<nc.distance-1) {
// Found a neighbor closer to GW than previously found
nc.distance = distance + 1;
nc.parentNodeId = msg.sender;
eeprom_write_byte((uint8_t*)EEPROM_PARENT_NODE_ID_ADDRESS, nc.parentNodeId);
eeprom_write_byte((uint8_t*)EEPROM_DISTANCE_ADDRESS, nc.distance);
debug(PSTR("new parent=%d, d=%d\n"), nc.parentNodeId, nc.distance);
}
}
return false;
} else if (sender == GATEWAY_ADDRESS) {