Skip to content

Commit 2cb01e7

Browse files
committed
added payload_size field
1 parent aaecd15 commit 2cb01e7

File tree

14 files changed

+129
-113
lines changed

14 files changed

+129
-113
lines changed

src/common/dsdl/ocvsmd/common/ipc/Route.1.0.dsdl renamed to src/common/dsdl/ocvsmd/common/ipc/Route.0.1.dsdl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
uavcan.primitive.Empty.1.0 empty
44
RouteConnect.0.1 connect
5-
RouteChannelMsg.1.0 channel_msg
6-
RouteChannelEnd.1.0 channel_end
5+
RouteChannelMsg.0.1 channel_msg
6+
RouteChannelEnd.0.1 channel_end
77

88
@sealed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
uint64 tag
2+
int32 error_code
3+
4+
@extent 32 * 8

src/common/dsdl/ocvsmd/common/ipc/RouteChannelEnd.1.0.dsdl

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
uint64 tag
2+
uint64 sequence
3+
uint64 service_id
4+
uint64 payload_size
5+
6+
@extent 64 * 8

src/common/dsdl/ocvsmd/common/ipc/RouteChannelMsg.1.0.dsdl

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/common/dsdl/ocvsmd/common/node_command/ExecCmd.1.0.dsdl renamed to src/common/dsdl/ocvsmd/common/node_command/ExecCmd.0.1.dsdl

File renamed without changes.

src/common/ipc/client_router.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#include "ipc_types.hpp"
1111
#include "pipe/client_pipe.hpp"
1212

13-
#include "ocvsmd/common/ipc/RouteChannelEnd_1_0.hpp"
14-
#include "ocvsmd/common/ipc/RouteChannelMsg_1_0.hpp"
13+
#include "ocvsmd/common/ipc/RouteChannelEnd_0_1.hpp"
14+
#include "ocvsmd/common/ipc/RouteChannelMsg_0_1.hpp"
1515
#include "ocvsmd/common/ipc/RouteConnect_0_1.hpp"
16-
#include "ocvsmd/common/ipc/Route_1_0.hpp"
16+
#include "ocvsmd/common/ipc/Route_0_1.hpp"
1717
#include "uavcan/primitive/Empty_1_0.hpp"
1818

1919
#include <cetl/cetl.hpp>
@@ -138,12 +138,13 @@ class ClientRouterImpl final : public ClientRouter
138138
return static_cast<int>(ErrorCode::Shutdown);
139139
}
140140

141-
Route_1_0 route{&router_.memory_};
141+
Route_0_1 route{&router_.memory_};
142142

143-
auto& channel_msg = route.set_channel_msg();
144-
channel_msg.tag = endpoint_.tag;
145-
channel_msg.sequence = next_sequence_++;
146-
channel_msg.service_id = service_id;
143+
auto& channel_msg = route.set_channel_msg();
144+
channel_msg.tag = endpoint_.tag;
145+
channel_msg.sequence = next_sequence_++;
146+
channel_msg.service_id = service_id;
147+
channel_msg.payload_size = payload.size();
147148

148149
return tryPerformOnSerialized(route, [this, payload](const auto prefix) {
149150
//
@@ -248,7 +249,7 @@ class ClientRouterImpl final : public ClientRouter
248249
//
249250
if (was_registered && send_ch_end && isConnected(endpoint))
250251
{
251-
Route_1_0 route{&memory_};
252+
Route_0_1 route{&memory_};
252253
auto& channel_end = route.set_channel_end();
253254
channel_end.tag = endpoint.tag;
254255
channel_end.error_code = 0; // No error b/c it's a normal channel completion.
@@ -269,7 +270,7 @@ class ClientRouterImpl final : public ClientRouter
269270
// It's not enough to consider the server route connected by the pipe event.
270271
// We gonna initiate `RouteConnect` negotiation (see `handleRouteConnect`).
271272
//
272-
Route_1_0 route{&memory_};
273+
Route_0_1 route{&memory_};
273274
auto& route_conn = route.set_connect();
274275
route_conn.version.major = VERSION_MAJOR;
275276
route_conn.version.minor = VERSION_MINOR;
@@ -282,17 +283,14 @@ class ClientRouterImpl final : public ClientRouter
282283

283284
CETL_NODISCARD int handlePipeEvent(const pipe::ClientPipe::Event::Message& msg)
284285
{
285-
Route_1_0 route_msg{&memory_};
286+
Route_0_1 route_msg{&memory_};
286287
const auto result_size = tryDeserializePayload(msg.payload, route_msg);
287288
if (!result_size.has_value())
288289
{
289290
// Invalid message payload.
290291
return EINVAL;
291292
}
292293

293-
// Cut routing stuff from the payload - remaining is the actual message payload.
294-
const auto msg_payload = msg.payload.subspan(result_size.value());
295-
296294
return cetl::visit( //
297295
cetl::make_overloaded( //
298296
[this](const uavcan::primitive::Empty_1_0&) {
@@ -305,11 +303,11 @@ class ClientRouterImpl final : public ClientRouter
305303
//
306304
return handleRouteConnect(route_conn);
307305
},
308-
[this, msg_payload](const RouteChannelMsg_1_0& route_ch_msg) {
306+
[this, &msg](const RouteChannelMsg_0_1& route_ch_msg) {
309307
//
310-
return handleRouteChannelMsg(route_ch_msg, msg_payload);
308+
return handleRouteChannelMsg(route_ch_msg, msg.payload);
311309
},
312-
[this](const RouteChannelEnd_1_0& route_ch_end) {
310+
[this](const RouteChannelEnd_0_1& route_ch_end) {
313311
//
314312
return handleRouteChannelEnd(route_ch_end);
315313
}),
@@ -367,24 +365,27 @@ class ClientRouterImpl final : public ClientRouter
367365
return 0;
368366
}
369367

370-
CETL_NODISCARD int handleRouteChannelMsg(const RouteChannelMsg_1_0& route_ch_msg, const Payload payload)
368+
CETL_NODISCARD int handleRouteChannelMsg(const RouteChannelMsg_0_1& route_ch_msg, const Payload payload)
371369
{
370+
// Cut routing stuff from the payload - remaining is the real message payload.
371+
const auto msg_real_payload = payload.subspan(payload.size() - route_ch_msg.payload_size);
372+
372373
const Endpoint endpoint{route_ch_msg.tag};
373374

374375
const auto tag_to_gw = map_of_gateways_.find(endpoint.tag);
375376
if (tag_to_gw != map_of_gateways_.end())
376377
{
377378
if (const auto gateway = tag_to_gw->second.lock())
378379
{
379-
return gateway->event(detail::Gateway::Event::Message{route_ch_msg.sequence, payload});
380+
return gateway->event(detail::Gateway::Event::Message{route_ch_msg.sequence, msg_real_payload});
380381
}
381382
}
382383

383384
// Nothing to do here with unsolicited messages - just ignore them.
384385
return 0;
385386
}
386387

387-
CETL_NODISCARD int handleRouteChannelEnd(const RouteChannelEnd_1_0& route_ch_end)
388+
CETL_NODISCARD int handleRouteChannelEnd(const RouteChannelEnd_0_1& route_ch_end)
388389
{
389390
::syslog(LOG_DEBUG, "Route Ch End (tag=%zu, err=%d).", route_ch_end.tag, route_ch_end.error_code); // NOLINT
390391

src/common/ipc/server_router.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "ipc_types.hpp"
1111
#include "pipe/server_pipe.hpp"
1212

13-
#include "ocvsmd/common/ipc/RouteChannelMsg_1_0.hpp"
13+
#include "ocvsmd/common/ipc/RouteChannelMsg_0_1.hpp"
1414
#include "ocvsmd/common/ipc/RouteConnect_0_1.hpp"
15-
#include "ocvsmd/common/ipc/Route_1_0.hpp"
15+
#include "ocvsmd/common/ipc/Route_0_1.hpp"
1616
#include "uavcan/primitive/Empty_1_0.hpp"
1717

1818
#include <cetl/cetl.hpp>
@@ -130,12 +130,13 @@ class ServerRouterImpl final : public ServerRouter
130130
return static_cast<int>(ErrorCode::Shutdown);
131131
}
132132

133-
Route_1_0 route{&router_.memory_};
133+
Route_0_1 route{&router_.memory_};
134134

135-
auto& channel_msg = route.set_channel_msg();
136-
channel_msg.tag = endpoint_.tag;
137-
channel_msg.sequence = next_sequence_++;
138-
channel_msg.service_id = service_id;
135+
auto& channel_msg = route.set_channel_msg();
136+
channel_msg.tag = endpoint_.tag;
137+
channel_msg.sequence = next_sequence_++;
138+
channel_msg.service_id = service_id;
139+
channel_msg.payload_size = payload.size();
139140

140141
return tryPerformOnSerialized(route, [this, payload](const auto prefix) {
141142
//
@@ -237,7 +238,7 @@ class ServerRouterImpl final : public ServerRouter
237238
//
238239
if (was_registered && isConnected(endpoint))
239240
{
240-
Route_1_0 route{&memory_};
241+
Route_0_1 route{&memory_};
241242
auto& channel_end = route.set_channel_end();
242243
channel_end.tag = endpoint.tag;
243244
channel_end.error_code = 0; // No error b/c it's a normal channel completion.
@@ -264,17 +265,14 @@ class ServerRouterImpl final : public ServerRouter
264265

265266
CETL_NODISCARD int handlePipeEvent(const pipe::ServerPipe::Event::Message& msg)
266267
{
267-
Route_1_0 route_msg{&memory_};
268+
Route_0_1 route_msg{&memory_};
268269
const auto result_size = tryDeserializePayload(msg.payload, route_msg);
269270
if (!result_size.has_value())
270271
{
271272
// Invalid message payload.
272273
return EINVAL;
273274
}
274275

275-
// Cut routing stuff from the payload - remaining is the actual message payload.
276-
const auto msg_payload = msg.payload.subspan(result_size.value());
277-
278276
return cetl::visit( //
279277
cetl::make_overloaded( //
280278
[this](const uavcan::primitive::Empty_1_0&) {
@@ -287,11 +285,11 @@ class ServerRouterImpl final : public ServerRouter
287285
//
288286
return handleRouteConnect(msg.client_id, route_conn);
289287
},
290-
[this, &msg, msg_payload](const RouteChannelMsg_1_0& route_ch_msg) {
288+
[this, &msg](const RouteChannelMsg_0_1& route_ch_msg) {
291289
//
292-
return handleRouteChannelMsg(msg.client_id, route_ch_msg, msg_payload);
290+
return handleRouteChannelMsg(msg.client_id, route_ch_msg, msg.payload);
293291
},
294-
[this, &msg](const RouteChannelEnd_1_0& route_ch_end) {
292+
[this, &msg](const RouteChannelEnd_0_1& route_ch_end) {
295293
//
296294
return handleRouteChannelEnd(msg.client_id, route_ch_end);
297295
}),
@@ -333,7 +331,7 @@ class ServerRouterImpl final : public ServerRouter
333331
static_cast<int>(rt_conn.version.minor),
334332
static_cast<int>(rt_conn.error_code));
335333

336-
Route_1_0 route{&memory_};
334+
Route_0_1 route{&memory_};
337335
auto& route_conn = route.set_connect();
338336
route_conn.version.major = VERSION_MAJOR;
339337
route_conn.version.minor = VERSION_MINOR;
@@ -353,9 +351,12 @@ class ServerRouterImpl final : public ServerRouter
353351
}
354352

355353
CETL_NODISCARD int handleRouteChannelMsg(const pipe::ServerPipe::ClientId client_id,
356-
const RouteChannelMsg_1_0& route_ch_msg,
357-
const Payload msg_payload)
354+
const RouteChannelMsg_0_1& route_ch_msg,
355+
const Payload payload)
358356
{
357+
// Cut routing stuff from the payload - remaining is the real message payload.
358+
const auto msg_real_payload = payload.subspan(payload.size() - route_ch_msg.payload_size);
359+
359360
const auto cl_to_gws = client_id_to_map_of_gateways_.find(client_id);
360361
if (cl_to_gws != client_id_to_map_of_gateways_.end())
361362
{
@@ -366,7 +367,7 @@ class ServerRouterImpl final : public ServerRouter
366367
{
367368
if (auto gateway = tag_to_gw->second.lock())
368369
{
369-
return gateway->event(detail::Gateway::Event::Message{route_ch_msg.sequence, msg_payload});
370+
return gateway->event(detail::Gateway::Event::Message{route_ch_msg.sequence, msg_real_payload});
370371
}
371372
}
372373

@@ -381,7 +382,7 @@ class ServerRouterImpl final : public ServerRouter
381382
auto gateway = GatewayImpl::create(*this, endpoint);
382383
map_of_gws[route_ch_msg.tag] = gateway;
383384

384-
si_to_ch_factory->second(gateway, msg_payload);
385+
si_to_ch_factory->second(gateway, msg_real_payload);
385386
}
386387
}
387388
}
@@ -391,7 +392,7 @@ class ServerRouterImpl final : public ServerRouter
391392
}
392393

393394
CETL_NODISCARD int handleRouteChannelEnd(const pipe::ServerPipe::ClientId client_id,
394-
const RouteChannelEnd_1_0& route_ch_end)
395+
const RouteChannelEnd_0_1& route_ch_end)
395396
{
396397
::syslog(LOG_DEBUG, "Route Ch End (tag=%zu, err=%d).", route_ch_end.tag, route_ch_end.error_code); // NOLINT
397398

src/daemon/engine/application.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ cetl::optional<std::string> Application::init()
6969
ipc_router_ = common::ipc::ServerRouter::make(memory_, std::move(server_pipe));
7070

7171
using Ch = ExecCmdChannel;
72-
ipc_router_->registerChannel<ExecCmdChannel>("daemon", [this](ExecCmdChannel&& ch, const auto&) {
72+
ipc_router_->registerChannel<ExecCmdChannel>("daemon", [this](ExecCmdChannel&& ch, const auto& request) {
7373
//
74-
::syslog(LOG_DEBUG, "D << 🆕 Ch created."); // NOLINT
75-
::syslog(LOG_DEBUG, "D << 🔵 Ch ininital msg."); // NOLINT
74+
::syslog(LOG_DEBUG, "D << 🆕 Ch created."); // NOLINT
75+
::syslog(LOG_DEBUG, "D << 🔵 Ch ininital Msg='%s'.", request.some_stuff.data()); // NOLINT
7676

7777
ipc_exec_cmd_ch_ = std::move(ch);
7878
ipc_exec_cmd_ch_->subscribe([this](const auto& event_var) {
@@ -83,16 +83,19 @@ cetl::optional<std::string> Application::init()
8383
//
8484
::syslog(LOG_DEBUG, "D << 🟢 Ch connected."); // NOLINT
8585

86-
::syslog(LOG_DEBUG, "D >> 🔵 Ch Msg."); // NOLINT
87-
const ExecCmd cmd{&memory_};
88-
const int result = ipc_exec_cmd_ch_->send(cmd);
86+
::syslog(LOG_DEBUG, "D >> 🔵 Ch 'SR' msg."); // NOLINT
87+
ExecCmd cmd{&memory_};
88+
cmd.some_stuff.push_back('S');
89+
cmd.some_stuff.push_back('R');
90+
cmd.some_stuff.push_back('\0');
91+
const int result = ipc_exec_cmd_ch_->send(cmd);
8992
(void) result;
9093
},
9194
[this](const ExecCmdChannel::Input& input) {
9295
//
93-
::syslog(LOG_DEBUG, "D << 🔵 Ch Msg."); // NOLINT
96+
::syslog(LOG_DEBUG, "D << 🔵 Ch Msg='%s'.", input.some_stuff.data()); // NOLINT
9497

95-
::syslog(LOG_DEBUG, "D >> 🔵 Ch Msg."); // NOLINT
98+
::syslog(LOG_DEBUG, "D >> 🔵 Ch '%s' msg.", input.some_stuff.data()); // NOLINT
9699
const int result = ipc_exec_cmd_ch_->send(input);
97100
(void) result;
98101
},

src/daemon/engine/application.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "cyphal/udp_transport_bag.hpp"
1010
#include "ocvsmd/platform/defines.hpp"
1111

12-
#include "ocvsmd/common/node_command/ExecCmd_1_0.hpp"
12+
#include "ocvsmd/common/node_command/ExecCmd_0_1.hpp"
1313

1414
#include <ipc/channel.hpp>
1515
#include <ipc/server_router.hpp>
@@ -39,7 +39,7 @@ class Application
3939

4040
private:
4141
// TODO: temp stuff
42-
using ExecCmd = common::node_command::ExecCmd_1_0;
42+
using ExecCmd = common::node_command::ExecCmd_0_1;
4343
using ExecCmdChannel = common::ipc::Channel<ExecCmd, ExecCmd>;
4444
cetl::optional<ExecCmdChannel> ipc_exec_cmd_ch_;
4545

0 commit comments

Comments
 (0)