Hi, obviously a lot of work gone into NodeManager thanks, I'm quite new to MySensors but have started working on.a few sensors around my home.
I was just looking through the code (NodeManager.cpp) and an apparent issue jumped out at me (I write C++ for a living on very large boxes but still worry about performance!)
The two functions NodeManager::_saveConfig and NodeManager::_loadConfig are used to save the _sleep_time value to EEPROM. The code splits the long value into 3 parts by dividing by successively 255 . On loading the value is reconstructed by multiplying by 255.
I'm pretty sure that you meant to use 256 to split the long value into three independent bytes to store.
Dividing or multiplying by 255 is potentially expensive whereas dividing or multiplying by 256 is much faster simply requiring shifts.
The normal code for splitting a long value into individual bytes would be something like
uint8_t byte0 = _sleep_time & 0xff; // compiler should generate a simple byte load
uint8_t byte1 = (_sleep_time >> 8 ) & 0xff; // compiler should still generate a simple byte load from the second byte of _sleep_time
uint8_t byte2 = (_sleep_time >> 16) & 0xff; // as before should still be a byte load.
I'm not sure how good the gcc optimiser is for the AVR code but, putting the shift&mask operations directly into the calls of saveSave(...) may avoid having to allocate local variables as in
// save the 3 bits
saveState(EEPROM_SLEEP_SAVED,1);
saveState(EEPROM_SLEEP_1,_sleep_time & 0xff);
saveState(EEPROM_SLEEP_2,(_sleep_time >> 8 ) & 0xff);
saveState(EEPROM_SLEEP_3, (_sleep_time >> 16) & 0xff);
I am not an expert in in the AVR architecture or instruction set so maybe there is a good reason why you are using 255 instead of 256 - it just seems strange!
Regards
Graham