libs
libuavcan
libuavcan
src
node
uc_service_client.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3
*/
4
5
#include <
uavcan/node/service_client.hpp
>
6
7
namespace
uavcan
8
{
9
/*
10
* ServiceClientBase::CallState
11
*/
12
void
ServiceClientBase::CallState::handleDeadline
(
MonotonicTime
)
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
()),
16
(
owner_
.
data_type_descriptor_
==
UAVCAN_NULLPTR
) ?
"???"
:
owner_
.
data_type_descriptor_
->
getFullName
());
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
;
24
owner_
.
generateDeadlineImmediately
();
25
UAVCAN_TRACE
(
"ServiceClient::CallState"
,
"Relaying execution to the owner's handler via timer callback"
);
26
}
27
28
/*
29
* ServiceClientBase
30
*/
31
int
ServiceClientBase::prepareToCall
(
INode
&
node
,
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
*/
49
if
(
data_type_descriptor_
==
UAVCAN_NULLPTR
)
50
{
51
GlobalDataTypeRegistry::instance
().
freeze
();
52
data_type_descriptor_
=
GlobalDataTypeRegistry::instance
().
find
(
DataTypeKindService
, dtname);
53
if
(
data_type_descriptor_
==
UAVCAN_NULLPTR
)
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
}
60
UAVCAN_ASSERT
(
data_type_descriptor_
!=
UAVCAN_NULLPTR
);
61
62
/*
63
* Determining the Transfer ID
64
*/
65
const
OutgoingTransferRegistryKey
otr_key(
data_type_descriptor_
->
getID
(),
66
TransferTypeServiceRequest
, server_node_id);
67
const
MonotonicTime
otr_deadline =
node
.getMonotonicTime() +
TransferSender::getDefaultMaxTransferInterval
();
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
}
uavcan::DataTypeDescriptor::getFullName
const char * getFullName() const
Definition:
data_type.hpp:161
UAVCAN_NULLPTR
#define UAVCAN_NULLPTR
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:51
uavcan::ServiceClientBase::CallState::id_
const ServiceCallID id_
Definition:
service_client.hpp:126
uavcan::ServiceClientBase::prepareToCall
int prepareToCall(INode &node, const char *dtname, NodeID server_node_id, ServiceCallID &out_call_id)
Definition:
uc_service_client.cpp:31
uavcan::DataTypeKindService
@ DataTypeKindService
Definition:
data_type.hpp:21
uavcan::NodeID::get
uint8_t get() const
Definition:
transfer.hpp:132
uavcan::NodeID
Definition:
transfer.hpp:112
uavcan::OutgoingTransferRegistryKey
Definition:
outgoing_transfer_registry.hpp:19
uavcan::ServiceClientBase::CallState::timed_out_
bool timed_out_
Definition:
service_client.hpp:127
service_client.hpp
uavcan::ServiceClientBase::CallState::handleDeadline
virtual void handleDeadline(MonotonicTime)
Definition:
uc_service_client.cpp:12
UAVCAN_TRACE
#define UAVCAN_TRACE(...)
Definition:
libuavcan/libuavcan/include/uavcan/debug.hpp:31
uavcan::TransferTypeServiceRequest
@ TransferTypeServiceRequest
Definition:
transfer.hpp:21
uavcan::TransferID::get
uint8_t get() const
Definition:
transfer.hpp:99
uavcan::DeadlineHandler::generateDeadlineImmediately
void generateDeadlineImmediately()
Definition:
scheduler.hpp:35
uavcan::GlobalDataTypeRegistry::find
const DataTypeDescriptor * find(const char *name) const
Definition:
uc_global_data_type_registry.cpp:144
uavcan::TransferID
Definition:
transfer.hpp:71
uavcan::ServiceCallID::server_node_id
NodeID server_node_id
Definition:
service_client.hpp:29
uavcan::NodeID::isUnicast
bool isUnicast() const
Definition:
transfer.hpp:136
uavcan::INode
Definition:
abstract_node.hpp:19
uavcan::ServiceClientBase::data_type_descriptor_
const DataTypeDescriptor * data_type_descriptor_
This will be initialized at the time of first call.
Definition:
service_client.hpp:120
uavcan::ServiceClientBase::CallState::owner_
ServiceClientBase & owner_
Definition:
service_client.hpp:125
uavcan::ServiceCallID
Definition:
service_client.hpp:27
uavcan::DataTypeDescriptor::getID
DataTypeID getID() const
Definition:
data_type.hpp:159
uavcan::ServiceCallID::transfer_id
TransferID transfer_id
Definition:
service_client.hpp:30
uavcan::TransferSender::getDefaultMaxTransferInterval
static MonotonicDuration getDefaultMaxTransferInterval()
Definition:
transfer_sender.hpp:38
pyuavcan_v0.introspect.node
node
Definition:
introspect.py:398
uavcan::MonotonicTime
Definition:
time.hpp:184
uavcan::GlobalDataTypeRegistry::instance
static GlobalDataTypeRegistry & instance()
Definition:
uc_global_data_type_registry.cpp:128
uavcan
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:204
uavcan::GlobalDataTypeRegistry::freeze
void freeze()
Definition:
uc_global_data_type_registry.cpp:134
uavcan::TransferID::increment
void increment()
Definition:
transfer.hpp:94
UAVCAN_ASSERT
#define UAVCAN_ASSERT(x)
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:184
uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03