-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from 107-systems/subject-id-list
Add feature to allow publishing of port ID list.
- Loading branch information
Showing
9 changed files
with
203 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* This software is distributed under the terms of the MIT License. | ||
* Copyright (c) 2020-2023 LXRobotics. | ||
* Author: Alexander Entinger <[email protected]> | ||
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. | ||
*/ | ||
|
||
#ifndef INC_107_ARDUINO_CYPHAL_LIST_HPP | ||
#define INC_107_ARDUINO_CYPHAL_LIST_HPP | ||
|
||
/************************************************************************************** | ||
* INCLUDES | ||
**************************************************************************************/ | ||
|
||
#include "PortListPublisherBase.hpp" | ||
|
||
#include "../../Node.hpp" | ||
#include "../../DSDL_Types.h" | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
namespace impl | ||
{ | ||
|
||
/************************************************************************************** | ||
* CLASS DECLARATION | ||
**************************************************************************************/ | ||
|
||
class PortListPublisher final : public PortListPublisherBase | ||
{ | ||
public: | ||
PortListPublisher(Node & node_hdl, Node::MicrosFunc const micros_func) | ||
: _pub{node_hdl.create_publisher<uavcan::node::port::List_1_0>(1*1000*1000UL /* = 1 sec in usecs. */)} | ||
, _micros_func{micros_func} | ||
, _prev_pub{0} | ||
, _list_msg{} | ||
{ | ||
_list_msg.publishers.set_sparse_list(); | ||
_list_msg.subscribers.set_sparse_list(); | ||
|
||
/* This one won't be able automatically, as the object does not exist yet when | ||
* this objects publisher is created. | ||
*/ | ||
add_publisher(uavcan::node::port::List_1_0::_traits_::FixedPortId); | ||
} | ||
virtual ~PortListPublisher() { } | ||
|
||
virtual void update() override | ||
{ | ||
static CanardMicrosecond const MAX_PUBLICATION_PERIOD_us = uavcan::node::port::List_1_0::MAX_PUBLICATION_PERIOD * 1000 * 1000UL; | ||
auto const now = _micros_func(); | ||
if ((now - _prev_pub) > MAX_PUBLICATION_PERIOD_us) | ||
{ | ||
_prev_pub = now; | ||
_pub->publish(_list_msg); | ||
} | ||
} | ||
|
||
virtual void add_publisher(CanardPortID const port_id) override | ||
{ | ||
auto sparse_list = _list_msg.publishers.get_sparse_list(); | ||
sparse_list.push_back(uavcan::node::port::SubjectID_1_0{port_id}); | ||
_list_msg.publishers.set_sparse_list(sparse_list); | ||
} | ||
|
||
virtual void add_subscriber(CanardPortID const port_id) override | ||
{ | ||
auto sparse_list = _list_msg.subscribers.get_sparse_list(); | ||
sparse_list.push_back(uavcan::node::port::SubjectID_1_0{port_id}); | ||
_list_msg.subscribers.set_sparse_list(sparse_list); | ||
} | ||
|
||
virtual void add_service_server(CanardPortID const request_port_id) override | ||
{ | ||
_list_msg.servers.mask.set(request_port_id); | ||
} | ||
|
||
virtual void add_service_client(CanardPortID const response_port_id) override | ||
{ | ||
_list_msg.clients.mask.set(response_port_id); | ||
} | ||
|
||
private: | ||
::Publisher<uavcan::node::port::List_1_0> _pub; | ||
Node::MicrosFunc const _micros_func; | ||
CanardMicrosecond _prev_pub; | ||
uavcan::node::port::List_1_0 _list_msg; | ||
}; | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
} /* impl */ | ||
|
||
#endif /* INC_107_ARDUINO_CYPHAL_LIST_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* This software is distributed under the terms of the MIT License. | ||
* Copyright (c) 2020-2023 LXRobotics. | ||
* Author: Alexander Entinger <[email protected]> | ||
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. | ||
*/ | ||
|
||
#ifndef INC_107_ARDUINO_CYPHAL_LIST_BASE_HPP | ||
#define INC_107_ARDUINO_CYPHAL_LIST_BASE_HPP | ||
|
||
/************************************************************************************** | ||
* INCLUDES | ||
**************************************************************************************/ | ||
|
||
#include <memory> | ||
|
||
#include <libcanard/canard.h> | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
namespace impl | ||
{ | ||
|
||
/************************************************************************************** | ||
* CLASS DECLARATION | ||
**************************************************************************************/ | ||
|
||
class PortListPublisherBase | ||
{ | ||
public: | ||
PortListPublisherBase() = default; | ||
virtual ~PortListPublisherBase() { } | ||
PortListPublisherBase(PortListPublisherBase const &) = delete; | ||
PortListPublisherBase(PortListPublisherBase &&) = delete; | ||
PortListPublisherBase &operator=(PortListPublisherBase const &) = delete; | ||
PortListPublisherBase &operator=(PortListPublisherBase &&) = delete; | ||
|
||
virtual void update() = 0; | ||
virtual void add_publisher(CanardPortID const port_id) = 0; | ||
virtual void add_subscriber(CanardPortID const port_id) = 0; | ||
virtual void add_service_server(CanardPortID const request_port_id) = 0; | ||
virtual void add_service_client(CanardPortID const response_port_id) = 0; | ||
}; | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
} /* impl */ | ||
|
||
/************************************************************************************** | ||
* TYPEDEF | ||
**************************************************************************************/ | ||
|
||
using PortListPublisher = std::shared_ptr<impl::PortListPublisherBase>; | ||
|
||
#endif /* INC_107_ARDUINO_CYPHAL_LIST_BASE_HPP */ |