16 return NodeEventStrings::get_log_str(
static_cast<uint8_t
>(event), NodeEventStrings::LAST_INDEX);
19#ifdef USE_CANOPEN_NODE_MONITOR
21 if (this->
co_ !=
nullptr) {
22 ESP_LOGE(TAG,
"monitor_node(0x%02x) after setup, ignored", node_id);
26 ESP_LOGE(TAG,
"monitor_node(0x%02x): needs a CANopen node (node_id), ignored", node_id);
30 if (node_id == 0 || node_id > 127 || node_id == this->
node_id_ || timeout_ms == 0) {
31 ESP_LOGE(TAG,
"monitor_node(0x%02x, %u ms): needs another node's id (1-127) and a timeout, ignored", node_id,
37 if ((c >> 16) == node_id) {
49 int8_t idx = CO_HBconsumer_getIdxByNodeId(this->
co_->HBcons, node_id);
50 CO_NMT_internalState_t
state;
51 if (idx < 0 || CO_HBconsumer_getNmtState(this->
co_->HBcons, idx, &
state) != 0)
59 int8_t idx = CO_HBconsumer_getIdxByNodeId(this->
co_->HBcons, node_id);
60 return idx >= 0 && CO_HBconsumer_getState(this->
co_->HBcons, idx) == CO_HBconsumer_ACTIVE;
64#if ESPHOME_CANOPEN_HEARTBEAT_CLIENTS > 0
65 uint8_t n_cons = this->
hb_cons_.size();
75 uint8_t n_cons = this->
hb_cons_.size();
76 cfg.CNT_HB_CONS = n_cons ? 1 : 0;
77 cfg.CNT_ARR_1016 = n_cons;
78 cfg.ENTRY_H1016 = this->
od_.
find(0x1016);
82 CO_HBconsumer_t *hb = this->
co_->HBcons;
89 hb->NMTisPreOrOperationalPrev =
true;
90 for (uint8_t i = 0, n = this->
hb_cons_.size(); i < n; i++) {
91 CO_HBconsumer_initCallbackHeartbeatStarted(hb, i,
this,
on_hb_started);
93 CO_HBconsumer_initCallbackTimeout(hb, i,
this,
on_hb_timeout);
99 if (this->
co_->HBcons !=
nullptr)
100 CO_HBconsumer_process(this->
co_->HBcons,
true, dt_us,
nullptr);
105 ESP_LOGCONFIG(TAG,
" Heartbeat client: node 0x%02x, timeout %u ms", (
unsigned) (c >> 16), (
unsigned) (c & 0xFFFF));
112 ESP_LOGW(TAG,
"node 0x%02x offline (heartbeat timeout)", node_id);
114 ESP_LOGI(TAG,
"node 0x%02x %s, NMT state: %s", node_id, LOG_STR_ARG(
node_event_to_string(event)),
120#ifdef USE_CANOPEN_NODE_MONITOR
127 CO_NMT_internalState_t
state = self->
co_->HBcons->monitoredNodes[idx].NMTstate;
138 if (
state == CO_NMT_INITIALIZING)
154 this->pending_node_events_.clear();
void node_event_(uint8_t node_id, NodeEvent event, NMTState state)
static void on_hb_nmt_changed(uint8_t node_id, uint8_t idx, CO_NMT_internalState_t state, void *object)
void dump_node_monitor_config_()
LazyCallbackManager< void(uint8_t, NodeEvent, NMTState)> node_event_callback_
SlotList< uint32_t, ESPHOME_CANOPEN_HEARTBEAT_CLIENTS > hb_cons_
NMTState get_node_state(uint8_t node_id)
void add_node_monitor_od_()
static void on_hb_timeout(uint8_t node_id, uint8_t idx, void *object)
void init_node_monitor_()
void dispatch_node_events_()
static void push_node_event(void *object, uint8_t node_id, NodeEvent event, NMTState state)
void process_node_monitor_(uint32_t dt_us)
static void on_hb_started(uint8_t node_id, uint8_t idx, void *object)
void monitor_node_(uint8_t node_id, uint16_t timeout_ms)
bool is_client_only() const
StaticVector< PendingNodeEvent, 2 *ESPHOME_CANOPEN_HEARTBEAT_CLIENTS > pending_node_events_
bool is_node_online(uint8_t node_id)
static void on_hb_remote_reset(uint8_t node_id, uint8_t idx, void *object)
void config_node_monitor_(CO_config_t &cfg)
OD_entry_t * find(uint16_t index)
void add_array(uint16_t index, OD_attr_t attr, uint8_t *count, void *data, OD_size_t elem_len, uint8_t n, OD_attr_t count_attr=ODA_SDO_R)
PROGMEM_STRING_TABLE(NMTStateStrings, "bootup", "stopped", "operational", "pre-operational", "unknown")
ESPHOME_LOG_TAG(TAG, "canopen")
NMTState to_nmt_state(CO_NMT_internalState_t state)
const LogString * nmt_state_to_string(NMTState state)
const LogString * node_event_to_string(NodeEvent event)