Skip to content

Commit bc7e246

Browse files
committed
Merge pull request #457 from tekka007/DebugMessages
Add support for I_DEBUG messages
2 parents a74a2d5 + cb4254d commit bc7e246

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

libraries/MySensors/MyConfig.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,19 @@
3131
* Serial and debug options
3232
***********************************/
3333

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

38+
// Enable MY_SPECIAL_DEBUG in sketch to activate I_DEBUG messages if MY_DEBUG is disabled.
39+
// I_DEBUG requests are:
40+
// R: routing info (only repeaters): received msg XXYY (as stream), where XX is the node and YY the routing node
41+
// V: CPU voltage
42+
// F: CPU frequency
43+
// M: free memory
44+
// E: clear MySensors EEPROM area and reboot (i.e. "factory" reset)
45+
//#define MY_SPECIAL_DEBUG
46+
3847
// Enable MY_DEBUG_VERBOSE_SIGNING flag for verbose debug prints related to signing.
3948
// Requires DEBUG to be enabled.
4049
// This will add even more to the size of the final sketch!

libraries/MySensors/core/MySensorCore.cpp

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -306,25 +306,58 @@ void _processInternalMessages() {
306306
// Deliver time to callback
307307
if (receiveTime)
308308
receiveTime(_msg.getULong());
309-
}
310-
#if defined(MY_REPEATER_FEATURE)
311-
if (type == I_CHILDREN) {
312-
if (_msg.getString()[0] == 'C') {
313-
// Clears child relay data for this node
314-
debug(PSTR("clear routing table\n"));
315-
uint8_t i = 255;
316-
do {
317-
hwWriteConfig(EEPROM_ROUTES_ADDRESS+i, BROADCAST_ADDRESS);
318-
} while (i--);
319-
// Clear parent node id & distance to gw
320-
hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, AUTO);
321-
hwWriteConfig(EEPROM_DISTANCE_ADDRESS, DISTANCE_INVALID);
322-
// Find parent node
323-
transportFindParentNode();
324-
_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set(""));
309+
} else if (type == I_CHILDREN) {
310+
#if defined(MY_REPEATER_FEATURE)
311+
if (_msg.data[0] == 'C') {
312+
// Clears child relay data for this node
313+
debug(PSTR("clear routing table\n"));
314+
uint8_t i = 255;
315+
do {
316+
hwWriteConfig(EEPROM_ROUTES_ADDRESS+i, BROADCAST_ADDRESS);
317+
} while (i--);
318+
// Clear parent node id & distance to gw
319+
hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, AUTO);
320+
hwWriteConfig(EEPROM_DISTANCE_ADDRESS, DISTANCE_INVALID);
321+
// Find parent node
322+
transportFindParentNode();
323+
_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set("ok"));
324+
}
325+
#endif
326+
} else if (type == I_DEBUG) {
327+
#if defined(MY_DEBUG) || defined(MY_SPECIAL_DEBUG)
328+
char debug_msg = _msg.data[0];
329+
if(debug_msg == 'R'){
330+
#if defined(MY_REPEATER_FEATURE)
331+
// routing table
332+
for(uint8_t cnt=0; cnt!=255;cnt++){
333+
uint8_t route = hwReadConfig(EEPROM_ROUTES_ADDRESS+cnt);
334+
if (route!=BROADCAST_ADDRESS){
335+
debug(PSTR("ID: %d via %d\n"),cnt,route);
336+
uint8_t OutBuf[2] = {cnt,route};
337+
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(OutBuf,2));
338+
wait(100);
339+
}
340+
}
341+
#endif
342+
} else if(debug_msg == 'V'){
343+
// CPU voltage
344+
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(hwCPUVoltage()));
345+
} else if (debug_msg == 'F') {
346+
// CPU frequency in 1/10Mhz
347+
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(hwCPUFrequency()));
348+
} else if (debug_msg == 'M') {
349+
// free memory
350+
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_DEBUG,false).set(hwFreeMem()));
351+
} else if (debug_msg == 'E') {
352+
// clear MySensors eeprom area and reboot
353+
_sendRoute(build(_msgTmp, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set("ok"));
354+
for (int i=EEPROM_START;i<EEPROM_LOCAL_CONFIG_ADDRESS;i++) {
355+
hwWriteConfig(i,0xFF);
356+
}
357+
hwReboot();
325358
}
326-
}
327-
#endif
359+
#endif
360+
}
328361
}
329362

330363

libraries/MySensors/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ smartSleep KEYWORD2
3232
#######################################
3333
AUTO LITERAL1
3434
MY_DEBUG LITERAL1
35+
MY_SPECIAL_DEBUG LITERAL1
3536
MY_CORE_ONLY LITERAL1
3637
MY_DEBUG_VERBOSE LITERAL1
3738
MY_DEBUG_VERBOSE_RF24 LITERAL1

0 commit comments

Comments
 (0)