Skip to content

Commit

Permalink
Add support for I_DEBUG messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tekka007 committed Jun 1, 2016
1 parent a74a2d5 commit cb4254d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
11 changes: 10 additions & 1 deletion libraries/MySensors/MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@
* Serial and debug options
***********************************/

// Enables this in sketch to show debug prints. This option will add a lot to the size of the
// Enable MY_DEBUG in sketch to show debug prints. This option will add a lot to the size of the
// final sketch but is helpful to see what is actually is happening during development
//#define MY_DEBUG

// Enable MY_SPECIAL_DEBUG in sketch to activate I_DEBUG messages if MY_DEBUG is disabled.
// I_DEBUG requests are:
// R: routing info (only repeaters): received msg XXYY (as stream), where XX is the node and YY the routing node
// V: CPU voltage
// F: CPU frequency
// M: free memory
// E: clear MySensors EEPROM area and reboot (i.e. "factory" reset)
//#define MY_SPECIAL_DEBUG

// Enable MY_DEBUG_VERBOSE_SIGNING flag for verbose debug prints related to signing.
// Requires DEBUG to be enabled.
// This will add even more to the size of the final sketch!
Expand Down
69 changes: 51 additions & 18 deletions libraries/MySensors/core/MySensorCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,58 @@ void _processInternalMessages() {
// Deliver time to callback
if (receiveTime)
receiveTime(_msg.getULong());
}
#if defined(MY_REPEATER_FEATURE)
if (type == I_CHILDREN) {
if (_msg.getString()[0] == 'C') {
// Clears child relay data for this node
debug(PSTR("clear routing table\n"));
uint8_t i = 255;
do {
hwWriteConfig(EEPROM_ROUTES_ADDRESS+i, BROADCAST_ADDRESS);
} while (i--);
// Clear parent node id & distance to gw
hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, AUTO);
hwWriteConfig(EEPROM_DISTANCE_ADDRESS, DISTANCE_INVALID);
// Find parent node
transportFindParentNode();
_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set(""));
} else if (type == I_CHILDREN) {
#if defined(MY_REPEATER_FEATURE)
if (_msg.data[0] == 'C') {
// Clears child relay data for this node
debug(PSTR("clear routing table\n"));
uint8_t i = 255;
do {
hwWriteConfig(EEPROM_ROUTES_ADDRESS+i, BROADCAST_ADDRESS);
} while (i--);
// Clear parent node id & distance to gw
hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, AUTO);
hwWriteConfig(EEPROM_DISTANCE_ADDRESS, DISTANCE_INVALID);
// Find parent node
transportFindParentNode();
_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set("ok"));
}
#endif
} else if (type == I_DEBUG) {
#if defined(MY_DEBUG) || defined(MY_SPECIAL_DEBUG)
char debug_msg = _msg.data[0];
if(debug_msg == 'R'){
#if defined(MY_REPEATER_FEATURE)
// routing table
for(uint8_t cnt=0; cnt!=255;cnt++){
uint8_t route = hwReadConfig(EEPROM_ROUTES_ADDRESS+cnt);
if (route!=BROADCAST_ADDRESS){
debug(PSTR("ID: %d via %d\n"),cnt,route);
uint8_t OutBuf[2] = {cnt,route};
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(OutBuf,2));
wait(100);
}
}
#endif
} else if(debug_msg == 'V'){
// CPU voltage
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(hwCPUVoltage()));
} else if (debug_msg == 'F') {
// CPU frequency in 1/10Mhz
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(hwCPUFrequency()));
} else if (debug_msg == 'M') {
// free memory
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(hwFreeMem()));
} else if (debug_msg == 'E') {
// clear MySensors eeprom area and reboot
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set("ok"));
for (int i=EEPROM_START;i<EEPROM_LOCAL_CONFIG_ADDRESS;i++) {
hwWriteConfig(i,0xFF);
}
hwReboot();
}
}
#endif
#endif
}
}


Expand Down
1 change: 1 addition & 0 deletions libraries/MySensors/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ smartSleep KEYWORD2
#######################################
AUTO LITERAL1
MY_DEBUG LITERAL1
MY_SPECIAL_DEBUG LITERAL1
MY_CORE_ONLY LITERAL1
MY_DEBUG_VERBOSE LITERAL1
MY_DEBUG_VERBOSE_RF24 LITERAL1
Expand Down

0 comments on commit cb4254d

Please sign in to comment.