Skip to content

Commit

Permalink
Merge pull request 107-systems#258 from Willmac16/main
Browse files Browse the repository at this point in the history
Add an optional CRC param to NodeInfo & allow access to TransferMetadata in ServiceServer Callback
  • Loading branch information
aentinger authored Sep 29, 2023
2 parents b3fb722 + fa86c2e commit 0895490
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ NodeInfo Node::create_node_info(uint8_t const protocol_major, uint8_t const prot
name);
}

NodeInfo Node::create_node_info(uint8_t const protocol_major, uint8_t const protocol_minor,
uint8_t const hardware_major, uint8_t const hardware_minor,
uint8_t const software_major, uint8_t const software_minor,
uint64_t const software_vcs_revision_id,
std::array<uint8_t, 16> const & unique_id,
std::string const & name,
uint64_t const image_crc)
{
return std::make_shared<impl::NodeInfo>(*this,
protocol_major, protocol_minor,
hardware_major, hardware_minor,
software_major, software_minor,
software_vcs_revision_id,
unique_id,
name, image_crc);
}

void Node::spinSome()
{
processPortList();
Expand Down
8 changes: 8 additions & 0 deletions src/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ class Node
std::array<uint8_t, 16> const & unique_id,
std::string const & name);

NodeInfo create_node_info(uint8_t const protocol_major, uint8_t const protocol_minor,
uint8_t const hardware_major, uint8_t const hardware_minor,
uint8_t const software_major, uint8_t const software_minor,
uint64_t const software_vcs_revision_id,
std::array<uint8_t, 16> const & unique_id,
std::string const & name,
uint64_t const image_crc);

/* Must be called from the application to process
* all received CAN frames.
*/
Expand Down
7 changes: 6 additions & 1 deletion src/ServiceServer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ bool ServiceServer<T_REQ, T_RSP, OnRequestCb>::onTransferReceived(CanardRxTransf
if (!req_rc) return false;

/* Invoke the service callback and obtain the desired response. */
T_RSP const rsp = _on_request_cb(req);
T_RSP rsp;
if constexpr (std::is_invocable_v<OnRequestCb, T_REQ, TransferMetadata>) {
rsp = _on_request_cb(req, fillMetadata(transfer));
} else {
rsp = _on_request_cb(req);
}

/* Serialize the response message. */
std::array<uint8_t, T_RSP::_traits_::SerializationBufferSizeBytes> rsp_buf;
Expand Down
23 changes: 23 additions & 0 deletions src/util/nodeinfo/NodeInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ namespace impl
class NodeInfo : public NodeInfoBase
{
public:
NodeInfo(Node & node_hdl,
uint8_t const protocol_major,
uint8_t const protocol_minor,
uint8_t const hardware_major,
uint8_t const hardware_minor,
uint8_t const software_major,
uint8_t const software_minor,
uint64_t const software_vcs_revision_id,
std::array<uint8_t, 16> const & unique_id,
std::string const & name,
std::uint64_t const software_image_crc)
: NodeInfo{node_hdl,
protocol_major, protocol_minor,
hardware_major, hardware_minor,
software_major, software_minor,
software_vcs_revision_id,
unique_id,
name}
{
std::array<std::uint64_t, 1> const crc = {software_image_crc};
std::copy(crc.cbegin(), crc.cend(), std::back_inserter(_node_info_rsp.software_image_crc));
}

NodeInfo(Node & node_hdl,
uint8_t const protocol_major,
uint8_t const protocol_minor,
Expand Down

0 comments on commit 0895490

Please sign in to comment.