uc_service_client.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
6 
7 namespace uavcan
8 {
9 /*
10  * ServiceClientBase::CallState
11  */
13 {
14  UAVCAN_TRACE("ServiceClient::CallState", "Timeout from nid=%d, tid=%d, dtname=%s",
15  int(id_.server_node_id.get()), int(id_.transfer_id.get()),
17  /*
18  * What we're doing here is relaying execution from this call stack to a different one.
19  * We need it because call registry cannot release memory from this callback, because this will destroy the
20  * object method of which we're executing now.
21  */
22  UAVCAN_ASSERT(timed_out_ == false);
23  timed_out_ = true;
25  UAVCAN_TRACE("ServiceClient::CallState", "Relaying execution to the owner's handler via timer callback");
26 }
27 
28 /*
29  * ServiceClientBase
30  */
32  const char* dtname,
33  NodeID server_node_id,
34  ServiceCallID& out_call_id)
35 {
36  /*
37  * Making sure we're not going to get transport error because of invalid input data
38  */
39  if (!server_node_id.isUnicast() || (server_node_id == node.getNodeID()))
40  {
41  UAVCAN_TRACE("ServiceClient", "Invalid Server Node ID");
42  return -ErrInvalidParam;
43  }
44  out_call_id.server_node_id = server_node_id;
45 
46  /*
47  * Determining the Data Type ID
48  */
50  {
54  {
55  UAVCAN_TRACE("ServiceClient", "Type [%s] is not registered", dtname);
56  return -ErrUnknownDataType;
57  }
58  UAVCAN_TRACE("ServiceClient", "Data type descriptor inited: %s", data_type_descriptor_->toString().c_str());
59  }
61 
62  /*
63  * Determining the Transfer ID
64  */
66  TransferTypeServiceRequest, server_node_id);
68  TransferID* const otr_tid =
69  node.getDispatcher().getOutgoingTransferRegistry().accessOrCreate(otr_key, otr_deadline);
70  if (!otr_tid)
71  {
72  UAVCAN_TRACE("ServiceClient", "OTR access failure, dtd=%s", data_type_descriptor_->toString().c_str());
73  return -ErrMemory;
74  }
75  out_call_id.transfer_id = *otr_tid;
76  otr_tid->increment();
77 
78  return 0;
79 }
80 
81 }
Dispatcher & getDispatcher()
bool isUnicast() const
Definition: transfer.hpp:136
const DataTypeDescriptor * find(const char *name) const
const char * getFullName() const
Definition: data_type.hpp:161
void generateDeadlineImmediately()
Definition: scheduler.hpp:35
const DataTypeDescriptor * data_type_descriptor_
This will be initialized at the time of first call.
uint8_t get() const
Definition: transfer.hpp:132
NodeID getNodeID() const
uint8_t get() const
Definition: transfer.hpp:99
DataTypeID getID() const
Definition: data_type.hpp:159
static GlobalDataTypeRegistry & instance()
int prepareToCall(INode &node, const char *dtname, NodeID server_node_id, ServiceCallID &out_call_id)
TransferID * accessOrCreate(const OutgoingTransferRegistryKey &key, MonotonicTime new_deadline)
virtual void handleDeadline(MonotonicTime)
static MonotonicDuration getDefaultMaxTransferInterval()
MonotonicTime getMonotonicTime() const
OutgoingTransferRegistry & getOutgoingTransferRegistry()
Definition: dispatcher.hpp:204


uavcan_communicator
Author(s):
autogenerated on Wed Jan 11 2023 03:59:40