Skip to content

Commit

Permalink
Harden against accidentally setting node address to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Aug 23, 2013
1 parent 7d4b5b1 commit a9961f2
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions examples/sensornet/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const eeprom_info_t& nodeconfig_read(void)
{
eeprom_info.clear();

printf_P(PSTR("*** No valid address found. Send node address via serial of the form 011<cr>\n\r"));
printf_P(PSTR("*** No valid address found. Send node address via serial of the form 011N\n\r"));
while(1)
{
nodeconfig_listen();
Expand Down Expand Up @@ -99,7 +99,7 @@ void nodeconfig_listen(void)
if ( ! eeprom_info.isValid() )
printf_P(PSTR("Please assign an address\r\n"));
}
else if ( c == 13 )
else if ( c == 'n' )
{
// Convert to octal
char *pc = serialdata;
Expand All @@ -110,13 +110,20 @@ void nodeconfig_listen(void)
address |= (*pc++ - '0');
}

// It is our address
eeprom_info.address = address;
eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info));
if ( address > 0 )
{
// It is our address
eeprom_info.address = address;
eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info));

// And we are done right now (no easy way to soft reset)
printf_P(PSTR("\n\rManually set to address 0%o\n\rPress RESET to continue!"),address);
while(1);
// And we are done right now (no easy way to soft reset)
printf_P(PSTR("\n\rManually set to address 0%o\n\rPress RESET to continue!"),address);
while(1);
}
else
{
printf_P(PSTR("\n\rERROR: This sketch cannot run on node 00\r\n"));
}
}
}
}
Expand Down

0 comments on commit a9961f2

Please sign in to comment.