Skip to content

Commit 13ea23a

Browse files
hendjoshsr71Lokesh-Carbonix
authored andcommitted
AP_UAVCAN_DNA: add CANH health logging message
Co-authored-by: Lokesh-Carbonix <[email protected]>
1 parent 3fbe99e commit 13ea23a

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

libraries/AP_UAVCAN/AP_UAVCAN.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const AP_Param::GroupInfo AP_UAVCAN::var_info[] = {
122122
// @Param: OPTION
123123
// @DisplayName: UAVCAN options
124124
// @Description: Option flags
125-
// @Bitmask: 0:ClearDNADatabase,1:IgnoreDNANodeConflicts,2:EnableCanfd
125+
// @Bitmask: 0:ClearDNADatabase,1:IgnoreDNANodeConflicts,2:EnableCanfd,3:LogNodeStatus
126126
// @User: Advanced
127127
AP_GROUPINFO("OPTION", 5, AP_UAVCAN, _options, 0),
128128

libraries/AP_UAVCAN/AP_UAVCAN.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class AP_UAVCAN : public AP_CANDriver, public AP_ESC_Telem_Backend {
200200
DNA_CLEAR_DATABASE = (1U<<0),
201201
DNA_IGNORE_DUPLICATE_NODE = (1U<<1),
202202
CANFD_ENABLED = (1U<<2),
203+
LOG_NODE_STATUS = (1U<<3),
203204
};
204205

205206
// check if a option is set

libraries/AP_UAVCAN/AP_UAVCAN_DNA_Server.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ void AP_UAVCAN_DNA_Server::handleNodeStatus(uint8_t node_id, const NodeStatusCb
484484
return;
485485
}
486486
WITH_SEMAPHORE(sem);
487+
488+
if (_ap_uavcan->option_is_set(AP_UAVCAN::Options::LOG_NODE_STATUS)) {
489+
log_NodeStatus(node_id, cb.msg->uptime_sec, cb.msg->health, cb.msg->mode);
490+
}
491+
487492
if (!isNodeIDVerified(node_id)) {
488493
//immediately begin verification of the node_id
489494
for (uint8_t i = 0; i < HAL_MAX_CAN_PROTOCOL_DRIVERS; i++) {
@@ -580,6 +585,29 @@ void AP_UAVCAN_DNA_Server::handleNodeInfo(uint8_t node_id, uint8_t unique_id[],
580585
}
581586
}
582587

588+
/*
589+
optionally log NodeStatus packets
590+
*/
591+
void AP_UAVCAN_DNA_Server::log_NodeStatus(uint8_t node_id, uint32_t uptime_sec, uint8_t healthy, uint8_t mode)
592+
{
593+
if (node_id > MAX_NODE_ID) {
594+
return;
595+
}
596+
597+
// @LoggerMessage: CANH
598+
// @Description: CAN Health Status
599+
// @Field: TimeUS: Time since system startup
600+
// @Field: NodeID: Node ID
601+
// @Field: Healthy: zero when node healthy
602+
// @Field: UpTime: time since boot in seconds
603+
AP::logger().WriteStreaming("CANH",
604+
"TimeUS," "NodeID," "Healthy," "UpTime", // labels
605+
"s" "#" "-" "-", // units
606+
"F" "-" "-" "-", // multipliers
607+
"Q" "B" "B" "I", // types
608+
AP_HAL::micros64(), node_id, healthy, uptime_sec);
609+
}
610+
583611
//Trampoline call for handleNodeInfo member call
584612
void trampoline_handleNodeInfo(const uavcan::ServiceCallResult<uavcan::protocol::GetNodeInfo>& resp)
585613
{

libraries/AP_UAVCAN/AP_UAVCAN_DNA_Server.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class AP_UAVCAN_DNA_Server
124124

125125
//Run through the list of seen node ids for verification
126126
void verify_nodes(AP_UAVCAN *ap_uavcan);
127+
128+
// Log NodeInfo
129+
void log_NodeStatus(uint8_t node_id, uint32_t uptime_sec, uint8_t healthy, uint8_t mode);
127130
};
128131

129132
namespace AP

0 commit comments

Comments
 (0)