From b8e821d0dd663b4db6e80768473dfb4232710e50 Mon Sep 17 00:00:00 2001 From: Janez Date: Wed, 18 Mar 2020 21:15:33 +0100 Subject: [PATCH] Add CO_NMT_UNKNOWN state for Heartbeat consumer. --- 301/CO_HBconsumer.c | 16 ++++++++-------- 301/CO_NMT_Heartbeat.h | 1 + socketCAN/CO_error_msgs.h | 2 +- socketCAN/CO_main_basic.c | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/301/CO_HBconsumer.c b/301/CO_HBconsumer.c index 2a34c34..ebcc386 100644 --- a/301/CO_HBconsumer.c +++ b/301/CO_HBconsumer.c @@ -119,7 +119,7 @@ CO_ReturnError_t CO_HBconsumer_init( HBcons->monitoredNodes = monitoredNodes; HBcons->numberOfMonitoredNodes = numberOfMonitoredNodes; HBcons->allMonitoredActive = false; - HBcons->allMonitoredOperational = CO_NMT_INITIALIZING; + HBcons->allMonitoredOperational = CO_NMT_UNKNOWN; HBcons->NMTisPreOrOperationalPrev = false; HBcons->CANdevRx = CANdevRx; HBcons->CANdevRxIdxStart = CANdevRxIdxStart; @@ -182,9 +182,9 @@ CO_ReturnError_t CO_HBconsumer_initEntry( CO_HBconsNode_t * monitoredNode = &HBcons->monitoredNodes[idx]; monitoredNode->nodeId = nodeId; monitoredNode->time_us = (int32_t)consumerTime_ms * 1000; - monitoredNode->NMTstate = CO_NMT_INITIALIZING; + monitoredNode->NMTstate = CO_NMT_UNKNOWN; #if CO_CONFIG_HB_CONS & CO_CONFIG_HB_CONS_CHANGE_CALLBACK - monitoredNode->NMTstatePrev = CO_NMT_INITIALIZING; + monitoredNode->NMTstatePrev = CO_NMT_UNKNOWN; #endif CO_FLAG_CLEAR(monitoredNode->CANrxNew); @@ -382,7 +382,7 @@ void CO_HBconsumer_process( #endif CO_errorReport(HBcons->em, CO_EM_HEARTBEAT_CONSUMER, CO_EMC_HEARTBEAT, i); - monitoredNode->NMTstate = CO_NMT_INITIALIZING; + monitoredNode->NMTstate = CO_NMT_UNKNOWN; monitoredNode->HBstate = CO_HBconsumer_TIMEOUT; } @@ -400,7 +400,7 @@ void CO_HBconsumer_process( allMonitoredActiveCurrent = false; } if (monitoredNode->NMTstate != CO_NMT_OPERATIONAL) { - allMonitoredOperationalCurrent = CO_NMT_INITIALIZING; + allMonitoredOperationalCurrent = CO_NMT_UNKNOWN; } #if CO_CONFIG_HB_CONS & CO_CONFIG_HB_CONS_CHANGE_CALLBACK /* Verify, if NMT state of monitored node changed */ @@ -419,9 +419,9 @@ void CO_HBconsumer_process( else if (NMTisPreOrOperational || HBcons->NMTisPreOrOperationalPrev) { /* (pre)operational state changed, clear variables */ for(i=0; inumberOfMonitoredNodes; i++) { - monitoredNode->NMTstate = CO_NMT_INITIALIZING; + monitoredNode->NMTstate = CO_NMT_UNKNOWN; #if CO_CONFIG_HB_CONS & CO_CONFIG_HB_CONS_CHANGE_CALLBACK - monitoredNode->NMTstatePrev = CO_NMT_INITIALIZING; + monitoredNode->NMTstatePrev = CO_NMT_UNKNOWN; #endif CO_FLAG_CLEAR(monitoredNode->CANrxNew); if (monitoredNode->HBstate != CO_HBconsumer_UNCONFIGURED) { @@ -430,7 +430,7 @@ void CO_HBconsumer_process( monitoredNode++; } allMonitoredActiveCurrent = false; - allMonitoredOperationalCurrent = CO_NMT_INITIALIZING; + allMonitoredOperationalCurrent = CO_NMT_UNKNOWN; } /* Clear emergencies when all monitored nodes becomes active. diff --git a/301/CO_NMT_Heartbeat.h b/301/CO_NMT_Heartbeat.h index 98fd8f8..3ea9ac5 100644 --- a/301/CO_NMT_Heartbeat.h +++ b/301/CO_NMT_Heartbeat.h @@ -93,6 +93,7 @@ extern "C" { * Internal network state of the CANopen node */ typedef enum{ + CO_NMT_UNKNOWN = -1, /**< Device state is unknown (for heartbeat consumer) */ CO_NMT_INITIALIZING = 0, /**< Device is initializing */ CO_NMT_PRE_OPERATIONAL = 127, /**< Device is in pre-operational state */ CO_NMT_OPERATIONAL = 5, /**< Device is in operational state */ diff --git a/socketCAN/CO_error_msgs.h b/socketCAN/CO_error_msgs.h index c5852ff..2008dc4 100644 --- a/socketCAN/CO_error_msgs.h +++ b/socketCAN/CO_error_msgs.h @@ -87,7 +87,7 @@ extern "C" { #define DBG_NO_CAN_DEVICE "(%s) Can't find CAN device \"%s\"", __func__ #define DBG_OBJECT_DICTIONARY "(%s) Error in Object Dictionary \"%s\"", __func__ #define DBG_CAN_OPEN "(%s) CANopen error in %s, err=%d", __func__ -#define DBG_CAN_OPEN_INFO "(%s) CANopen device, Node ID = %d(0x%02X), %s", __func__ +#define DBG_CAN_OPEN_INFO "(%s) CANopen device, Node ID = 0x%02X, %s", __func__ #define DBG_COMMAND_LOCAL_INFO "(%s) Command interface on socket \"%s\" started", __func__ #define DBG_COMMAND_TCP_INFO "(%s) Command interface on tcp port \"%hu\" started", __func__ diff --git a/socketCAN/CO_main_basic.c b/socketCAN/CO_main_basic.c index f0cab2d..78afdc9 100644 --- a/socketCAN/CO_main_basic.c +++ b/socketCAN/CO_main_basic.c @@ -263,7 +263,7 @@ int main (int argc, char *argv[]) { } - log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, CO_ownNodeId, "starting"); + log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, "starting"); /* Allocate memory for CANopen objects */ @@ -308,7 +308,7 @@ int main (int argc, char *argv[]) { while(reset != CO_RESET_APP && reset != CO_RESET_QUIT && CO_endProgram == 0) { /* CANopen communication reset - initialize CANopen objects *******************/ - log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, CO_ownNodeId, "communication reset"); + log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, "communication reset"); #if CO_CONFIG_309 > 0 @@ -439,7 +439,7 @@ int main (int argc, char *argv[]) { reset = CO_RESET_NOT; - log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, CO_ownNodeId, "running ..."); + log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, "running ..."); while(reset == CO_RESET_NOT && CO_endProgram == 0) { @@ -493,7 +493,7 @@ int main (int argc, char *argv[]) { threadMainWait_close(); CO_delete((void *)CANdevice0Index); - log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, CO_ownNodeId, "finished"); + log_printf(LOG_INFO, DBG_CAN_OPEN_INFO, CO_ownNodeId, "finished"); /* Flush all buffers (and reboot) */ if(rebootEnable && reset == CO_RESET_APP) {