fix(ethercat): log CiA402 device state transitions

This commit is contained in:
linbo 2026-08-19 10:53:29 +08:00
parent 9d12f5d1d1
commit b9dffb66df

View File

@ -153,8 +153,11 @@ void Cia402StatusMonitor::reportStatuswordTransition_(
const StatusSample& previous, const StatusSample& previous,
const StatusSample& current) const const StatusSample& current) const
{ {
const bool status_changed = const bool device_state_changed =
!had_previous || !previous.read_ok || !had_previous || !previous.read_ok ||
(previous.statusword & 0x006F) != (current.statusword & 0x006F);
const bool status_changed =
device_state_changed ||
previous.status_problem != current.status_problem || previous.status_problem != current.status_problem ||
(previous.statusword & 0x0888) != (current.statusword & 0x0888); (previous.statusword & 0x0888) != (current.statusword & 0x0888);
if (current.status_problem && status_changed) { if (current.status_problem && status_changed) {
@ -178,9 +181,20 @@ void Cia402StatusMonitor::reportStatuswordTransition_(
previous.status_problem) { previous.status_problem) {
CMVR_LOG(INFO) << "[Cia402StatusMonitor] [statusword] recovered" CMVR_LOG(INFO) << "[Cia402StatusMonitor] [statusword] recovered"
<< ", node=" << static_cast<int>(node_id) << ", node=" << static_cast<int>(node_id)
<< ", current_statusword=0x" << std::hex << std::uppercase
<< std::setw(4) << std::setfill('0') << current.statusword
<< std::dec << std::nouppercase << std::setfill(' ')
<< ' ' << deviceStateName_(current.statusword)
<< ", previous_statusword=0x" << std::hex << std::uppercase << ", previous_statusword=0x" << std::hex << std::uppercase
<< std::setw(4) << std::setfill('0') << previous.statusword << std::setw(4) << std::setfill('0') << previous.statusword
<< std::dec << std::nouppercase << std::setfill(' '); << std::dec << std::nouppercase << std::setfill(' ');
} else if (device_state_changed) {
CMVR_LOG(INFO) << "[Cia402StatusMonitor] [statusword] 0x"
<< std::hex << std::uppercase << std::setw(4)
<< std::setfill('0') << current.statusword
<< std::dec << std::nouppercase << std::setfill(' ')
<< ' ' << deviceStateName_(current.statusword)
<< ", node=" << static_cast<int>(node_id);
} }
} }