Go to the documentation of this file.
5 #ifndef UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_ALLOCATION_REQUEST_MANAGER_HPP_INCLUDED
6 #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_ALLOCATION_REQUEST_MANAGER_HPP_INCLUDED
16 #include <uavcan/protocol/dynamic_node_id/Allocation.hpp>
20 namespace dynamic_node_id_server
69 const uint8_t max_bytes_per_request = Allocation::MAX_LENGTH_OF_UNIQUE_ID_IN_REQUEST;
71 if ((msg.unique_id.size() != max_bytes_per_request) &&
72 (msg.unique_id.size() != (msg.unique_id.capacity() - max_bytes_per_request * 2U)) &&
73 (msg.unique_id.size() != msg.unique_id.capacity()))
77 if (msg.first_part_of_unique_id)
81 if (msg.unique_id.size() == Allocation::MAX_LENGTH_OF_UNIQUE_ID_IN_REQUEST)
85 if (msg.unique_id.size() < Allocation::MAX_LENGTH_OF_UNIQUE_ID_IN_REQUEST)
113 UAVCAN_ASSERT(msg.unique_id.size() < msg.unique_id.capacity());
115 UAVCAN_TRACE(
"AllocationRequestManager",
"Intermediate response with %u bytes of unique ID",
116 unsigned(msg.unique_id.size()));
143 UAVCAN_TRACE(
"AllocationRequestManager",
"Stage timeout, reset");
165 if (request_stage != expected_stage)
171 const uint8_t max_expected_bytes =
174 if (msg.unique_id.size() > max_expected_bytes)
183 for (
uint8_t i = 0; i < msg.unique_id.size(); i++)
196 UAVCAN_TRACE(
"AllocationRequestManager",
"Allocation request received; preferred node ID: %d",
205 for (
uint8_t i = 0; i < 8; i++)
207 event_agrument |=
static_cast<uint64_t>(unique_id[i]) << (56U - i * 8U);
265 msg.unique_id.resize(msg.unique_id.capacity());
266 copy(unique_id.begin(), unique_id.end(), msg.unique_id.begin());
268 msg.node_id = allocated_node_id.
get();
286 #endif // Include guard
static uint8_t detectRequestStage(const Allocation &msg)
MonotonicTime getMonotonicTime() const
Subscriber< Allocation, AllocationCallback > allocation_sub_
void publishFollowupAllocationResponse()
TraceAllocationFollowupDenied
MonotonicTime last_activity_timestamp_
void setTxTimeout(MonotonicDuration tx_timeout)
Allocation::FieldTypes::unique_id current_unique_id_
virtual void handleAllocationRequest(const UniqueID &unique_id, NodeID preferred_node_id)=0
static MonotonicDuration fromMSec(int64_t ms)
int broadcastAllocationResponse(const UniqueID &unique_id, NodeID allocated_node_id)
TraceAllocationUnexpectedStage
int init(const TransferPriority priority)
virtual bool canPublishFollowupAllocationResponse() const =0
Publisher< Allocation > allocation_pub_
void handleAllocation(const ReceivedDataStructure< Allocation > &msg)
void trace(TraceCode code, int64_t argument)
#define UAVCAN_TRACE(...)
uint8_t getExpectedStage() const
virtual void registerInternalFailure(const char *msg)=0
const MonotonicDuration stage_timeout_
MonotonicTime last_message_timestamp_
TraceAllocationBadRequest
virtual void onEvent(TraceCode event_code, int64_t event_argument)=0
TraceAllocationFollowupResponse
MethodBinder< AllocationRequestManager *, void(AllocationRequestManager::*)(const ReceivedDataStructure< Allocation > &)> AllocationCallback
TraceAllocationRequestAccepted
MonotonicTime getTimeOfLastAllocationActivity() const
virtual ~IAllocationRequestHandler()
MonotonicTime getMonotonicTimestamp() const
int broadcast(const DataType &message)
IAllocationRequestHandler & handler_
NodeID getSrcNodeID() const
UAVCAN_EXPORT OutputIt copy(InputIt first, InputIt last, OutputIt result)
protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id UniqueID
TraceAllocationExchangeComplete
AllocationRequestManager(INode &node, IEventTracer &tracer, IAllocationRequestHandler &handler)
bool isAnonymousTransfer() const
TraceAllocationFollowupTimeout