From 451598fa9ce4e57a00c9312c04839e0b3dcdf320 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 26 Nov 2019 16:18:41 +0100 Subject: Integrate the J1939 features : address claiming and write. This commit allows to write J1939 messages and add the management of the address claiming. Bug-AGL: SPEC-2386 Bug-AGL: SPEC-2976 Signed-off-by: Arthur Guyader Change-Id: I1bb95a7ba6f6ebe463319c3972d9d46897181d51 Signed-off-by: Romain Forlot --- low-can-binding/can/message/j1939-message.cpp | 63 +++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 8 deletions(-) (limited to 'low-can-binding/can/message/j1939-message.cpp') diff --git a/low-can-binding/can/message/j1939-message.cpp b/low-can-binding/can/message/j1939-message.cpp index 08fc1302..0d2320dc 100644 --- a/low-can-binding/can/message/j1939-message.cpp +++ b/low-can-binding/can/message/j1939-message.cpp @@ -184,16 +184,63 @@ uint32_t j1939_message_t::get_id() const return get_pgn(); } - -struct bcm_msg j1939_message_t::get_bcm_msg() +/** + * @brief Return the sockname of the message + * + * @return struct sockaddr_can The sockname of the message + */ +struct sockaddr_can j1939_message_t::get_sockname() { - AFB_WARNING("Not implemented"); - struct bcm_msg bcm_msg; - ::memset(&bcm_msg, 0, sizeof(struct bcm_msg)); - return bcm_msg; + return sockname_; } -void j1939_message_t::set_bcm_msg(struct bcm_msg bcm_msg) +/** + * @brief Allows to set a sockname at a message to send it after + * + * @param sockname The sockname of the message + */ +void j1939_message_t::set_sockname(struct sockaddr_can sockname) { - AFB_WARNING("Not implemented"); + sockname_ = sockname; } + +/** + * @brief Allows to generate a sockname for the message + * + * @param pgn The pgn for the sockname + * @param name The name for the sockname + * @param addr The address for the sockname + */ +void j1939_message_t::set_sockname(pgn_t pgn, name_t name, uint8_t addr) +{ + memset(&sockname_, 0, sizeof(sockname_)); + sockname_.can_family = AF_CAN; + sockname_.can_ifindex = 0; + + if(addr <= 0 || addr >= UINT8_MAX ) + { + sockname_.can_addr.j1939.addr = J1939_NO_ADDR; + } + else + { + sockname_.can_addr.j1939.addr = addr; + } + + if(name <= 0 || name >= UINT64_MAX ) + { + sockname_.can_addr.j1939.name = J1939_NO_NAME; + } + else + { + sockname_.can_addr.j1939.name = name; + } + + if(pgn <= 0 || pgn > J1939_PGN_MAX) + { + sockname_.can_addr.j1939.pgn = J1939_NO_PGN; + } + else + { + sockname_.can_addr.j1939.pgn = pgn; + } +} \ No newline at end of file -- cgit 1.2.3-korg