|
| 1 | +/** |
| 2 | + * This software is distributed under the terms of the MIT License. |
| 3 | + * Copyright (c) 2020 LXRobotics. |
| 4 | + * Author: Alexander Entinger <[email protected]> |
| 5 | + * Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. |
| 6 | + */ |
| 7 | + |
| 8 | +/************************************************************************************** |
| 9 | + * INCLUDES |
| 10 | + **************************************************************************************/ |
| 11 | + |
| 12 | +#include "NodeInfo.h" |
| 13 | + |
| 14 | +/************************************************************************************** |
| 15 | + * CTOR/DTOR |
| 16 | + **************************************************************************************/ |
| 17 | + |
| 18 | +NodeInfo::NodeInfo(uint8_t const protocol_major, uint8_t const protocol_minor, |
| 19 | + uint8_t const hardware_major, uint8_t const hardware_minor, |
| 20 | + uint8_t const software_major, uint8_t const software_minor, |
| 21 | + uint64_t const software_vcs_revision_id, |
| 22 | + UniqueId16Array const unique_id, |
| 23 | + std::string const & name) |
| 24 | +{ |
| 25 | + _node_info.protocol_version.major = protocol_major; |
| 26 | + _node_info.protocol_version.minor = protocol_minor; |
| 27 | + |
| 28 | + _node_info.hardware_version.major = hardware_major; |
| 29 | + _node_info.hardware_version.minor = hardware_minor; |
| 30 | + |
| 31 | + _node_info.software_version.major = software_major; |
| 32 | + _node_info.software_version.minor = software_minor; |
| 33 | + |
| 34 | + _node_info.software_vcs_revision_id = software_vcs_revision_id; |
| 35 | + |
| 36 | + memcpy(_node_info.unique_id, unique_id.data(), sizeof(_node_info.unique_id)); |
| 37 | + |
| 38 | + _node_info.name.count = std::min(name.length(), uavcan_node_GetInfo_Response_1_0_name_ARRAY_CAPACITY_); |
| 39 | + memcpy(_node_info.name.elements, name.c_str(), _node_info.name.count); |
| 40 | +} |
| 41 | + |
| 42 | +/************************************************************************************** |
| 43 | + * PUBLIC MEMBER FUNCTIONS |
| 44 | + **************************************************************************************/ |
| 45 | + |
| 46 | +void NodeInfo::subscribe(Node & node_hdl) |
| 47 | +{ |
| 48 | + node_hdl.subscribe<uavcan::node::GetInfo_1_0::Request<>> |
| 49 | + ([this](CanardRxTransfer const & transfer, Node & node_hdl) { this->onGetInfo_1_0_Request_Received(transfer, node_hdl); }); |
| 50 | +} |
| 51 | + |
| 52 | +/************************************************************************************** |
| 53 | + * PRIVATE MEMBER FUNCTIONS |
| 54 | + **************************************************************************************/ |
| 55 | + |
| 56 | +void NodeInfo::onGetInfo_1_0_Request_Received(CanardRxTransfer const & transfer, Node & node_hdl) |
| 57 | +{ |
| 58 | + uavcan::node::GetInfo_1_0::Response<> rsp = uavcan::node::GetInfo_1_0::Response<>(); |
| 59 | + memcpy(&rsp.data, &_node_info, sizeof(uavcan_node_GetInfo_Response_1_0)); |
| 60 | + node_hdl.respond(rsp, transfer.metadata.remote_node_id, transfer.metadata.transfer_id); |
| 61 | +} |
0 commit comments