summaryrefslogtreecommitdiffstats
path: root/low-can-binding/can/message
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-11-26 16:19:35 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2019-11-28 16:11:47 +0100
commitfee3b49099fb39731e15f9e26ad5a873bc109f59 (patch)
treef925b8b2a744d9e94cedbd460e47ba533717c36c /low-can-binding/can/message
parenta8d5f5d3018da0b051dad4c143c6257b2fba9fac (diff)
Replace all enum types with masks
This commit allows to change all enum types by masks. Now to implement new protocol you don't need to add more attribute in class. All can be contained in the flags field. Bug-AGL : SPEC-2779 Bug-AGL: SPEC-2976 Change-Id: I814d0052139be5d5efefc9ff1b4b558f46b85e90 Signed-off-by: Arthur Guyader <arthur.guyader@iot.bzh> Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/can/message')
-rw-r--r--low-can-binding/can/message/can-message.cpp22
-rw-r--r--low-can-binding/can/message/can-message.hpp3
-rw-r--r--low-can-binding/can/message/j1939-message.cpp18
-rw-r--r--low-can-binding/can/message/j1939-message.hpp4
-rw-r--r--low-can-binding/can/message/message.cpp26
-rw-r--r--low-can-binding/can/message/message.hpp23
6 files changed, 36 insertions, 60 deletions
diff --git a/low-can-binding/can/message/can-message.cpp b/low-can-binding/can/message/can-message.cpp
index 8a04992e..0ef693c7 100644
--- a/low-can-binding/can/message/can-message.cpp
+++ b/low-can-binding/can/message/can-message.cpp
@@ -35,12 +35,11 @@ can_message_t::can_message_t()
can_message_t::can_message_t(uint32_t maxdlen,
uint32_t id,
uint32_t length,
- message_format_t format,
bool rtr_flag,
uint32_t flags,
std::vector<uint8_t>& data,
uint64_t timestamp)
- : message_t(maxdlen, length, format, data, timestamp, flags),
+ : message_t(maxdlen, length, flags, data, timestamp),
id_{id},
rtr_flag_{rtr_flag}
{}
@@ -62,7 +61,7 @@ uint32_t can_message_t::get_id() const
/// @return True if object correctly initialized and false if not.
bool can_message_t::is_correct_to_send()
{
- if (id_ != 0 && length_ != 0 && format_ != message_format_t::INVALID)
+ if (id_ != 0 && length_ != 0 && !(flags_&INVALID_FLAG))
{
int i;
for(i=0;i<length_;i++)
@@ -83,9 +82,8 @@ bool can_message_t::is_correct_to_send()
std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct canfd_frame& frame, size_t nbytes, uint64_t timestamp)
{
uint32_t maxdlen = 0, length = 0;
- uint8_t flags = 0;
+ uint32_t flags = 0;
uint32_t id;
- message_format_t format;
bool rtr_flag;
std::vector<uint8_t> data;
@@ -106,17 +104,17 @@ std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct ca
if (frame.can_id & CAN_ERR_FLAG)
{
- format = message_format_t::INVALID;
+ flags = flags|INVALID_FLAG;
id = frame.can_id & (CAN_ERR_MASK|CAN_ERR_FLAG);
}
else if (frame.can_id & CAN_EFF_FLAG)
{
- format = message_format_t::EXTENDED;
+ flags = flags|EXTENDED_ID;
id = frame.can_id & CAN_EFF_MASK;
}
else
{
- format = message_format_t::STANDARD;
+ flags = flags|STANDARD_ID;
id = frame.can_id & CAN_SFF_MASK;
}
@@ -140,8 +138,8 @@ std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct ca
length = (frame.len > maxdlen) ? maxdlen : frame.len;
/* Flags field only present for CAN FD frames*/
- if(maxdlen == CANFD_MAX_DLEN)
- flags = frame.flags & 0xF;
+ /*if(maxdlen == CANFD_MAX_DLEN)
+ flags = frame.flags & 0xF;*/
if (data.capacity() < maxdlen)
data.reserve(maxdlen);
@@ -155,10 +153,10 @@ std::shared_ptr<can_message_t> can_message_t::convert_from_frame(const struct ca
};
AFB_DEBUG("Found id: %X, format: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X",
- id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
+ id, (uint32_t)flags, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
}
- return std::make_shared<can_message_t>(can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp));
+ return std::make_shared<can_message_t>(can_message_t(maxdlen, id, length, rtr_flag, flags, data, timestamp));
}
/// @brief Take all initialized class members and build a
diff --git a/low-can-binding/can/message/can-message.hpp b/low-can-binding/can/message/can-message.hpp
index 75e65c67..769899ea 100644
--- a/low-can-binding/can/message/can-message.hpp
+++ b/low-can-binding/can/message/can-message.hpp
@@ -39,8 +39,7 @@ class can_message_t : public message_t {
public:
can_message_t();
- can_message_t(uint32_t maxdlen, uint32_t id, uint32_t length, message_format_t format, bool rtr_flag_, uint32_t flags, std::vector<uint8_t>& data, uint64_t timestamp);
-
+ can_message_t(uint32_t maxdlen, uint32_t id, uint32_t length, bool rtr_flag_, uint32_t flags, std::vector<uint8_t>& data, uint64_t timestamp);
uint32_t get_id() const;
static std::shared_ptr<can_message_t> convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp);
diff --git a/low-can-binding/can/message/j1939-message.cpp b/low-can-binding/can/message/j1939-message.cpp
index 2d600a1e..ec65cba4 100644
--- a/low-can-binding/can/message/j1939-message.cpp
+++ b/low-can-binding/can/message/j1939-message.cpp
@@ -45,13 +45,12 @@ j1939_message_t::j1939_message_t():
* @param addr The address of the message
*/
j1939_message_t::j1939_message_t(uint32_t length,
- message_format_t format,
std::vector<uint8_t>& data,
uint64_t timestamp,
name_t name,
pgn_t pgn,
uint8_t addr):
- message_t(J1939_MAX_DLEN,length, format, data, timestamp, 0),
+ message_t(J1939_MAX_DLEN, length, J1939_PROTOCOL, data, timestamp),
name_{name},
pgn_{pgn},
addr_{addr}
@@ -99,18 +98,13 @@ std::shared_ptr<j1939_message_t> j1939_message_t::convert_from_addr(struct socka
{
int i;
uint32_t length = 0;
- message_format_t format;
+ uint32_t flags;
std::vector<uint8_t> data_vector;
if(nbytes > J1939_MAX_DLEN)
{
AFB_DEBUG("Unsupported j1939 frame");
- format = message_format_t::INVALID;
- }
- else
- {
- //AFB_DEBUG("Got a j1939 frame");
- format = message_format_t::J1939;
+ return std::make_shared<j1939_message_t>(j1939_message_t());
}
length = (uint32_t) nbytes;
@@ -126,10 +120,10 @@ std::shared_ptr<j1939_message_t> j1939_message_t::convert_from_addr(struct socka
data_vector.push_back(data[i]);
};
- AFB_DEBUG("Found pgn: %X, format: %X, length: %X, data %s",
- addr.can_addr.j1939.pgn, (uint8_t)format, length, data_string.c_str());
+ AFB_DEBUG("Found pgn: %X, length: %X, data %s",
+ addr.can_addr.j1939.pgn, length, data_string.c_str());
- return std::make_shared<j1939_message_t>(j1939_message_t(J1939_MAX_DLEN,length, format, data_vector, timestamp,addr.can_addr.j1939.name,addr.can_addr.j1939.pgn,addr.can_addr.j1939.addr));
+ return std::make_shared<j1939_message_t>(j1939_message_t(length, data_vector, timestamp,addr.can_addr.j1939.name,addr.can_addr.j1939.pgn,addr.can_addr.j1939.addr));
}
/// @brief Test if members pgn_ and length are set.
diff --git a/low-can-binding/can/message/j1939-message.hpp b/low-can-binding/can/message/j1939-message.hpp
index 0d3736f1..9e9cea4a 100644
--- a/low-can-binding/can/message/j1939-message.hpp
+++ b/low-can-binding/can/message/j1939-message.hpp
@@ -67,7 +67,7 @@ class j1939_message_t : public message_t
public:
j1939_message_t();
- j1939_message_t(uint32_t maxdlen, uint32_t length, message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr);
+ j1939_message_t(uint32_t length, std::vector<uint8_t>& data, uint64_t timestamp, name_t name, pgn_t pgn, uint8_t addr);
uint64_t get_name() const;
uint32_t get_pgn() const;
uint8_t get_addr() const;
@@ -78,4 +78,4 @@ class j1939_message_t : public message_t
struct sockaddr_can get_sockname();
void set_sockname(struct sockaddr_can sockname);
void set_sockname(pgn_t pgn, name_t name, uint8_t addr);
-};
+}; \ No newline at end of file
diff --git a/low-can-binding/can/message/message.cpp b/low-can-binding/can/message/message.cpp
index 497304de..aaab99f5 100644
--- a/low-can-binding/can/message/message.cpp
+++ b/low-can-binding/can/message/message.cpp
@@ -28,10 +28,9 @@
message_t::message_t()
: maxdlen_{0},
length_{0},
- format_{message_format_t::INVALID},
+ flags_{INVALID_FLAG},
timestamp_{0},
- sub_id_{-1},
- flags_{0}
+ sub_id_{-1}
{}
/**
@@ -45,17 +44,15 @@ message_t::message_t()
*/
message_t::message_t(uint32_t maxdlen,
uint32_t length,
- message_format_t format,
+ uint32_t flags,
std::vector<uint8_t>& data,
- uint64_t timestamp,
- uint32_t flags)
+ uint64_t timestamp)
: maxdlen_{maxdlen},
length_{length},
- format_{format},
+ flags_{flags},
data_{data},
timestamp_{timestamp},
- sub_id_{-1},
- flags_{flags}
+ sub_id_{-1}
{}
/**
@@ -163,17 +160,6 @@ uint64_t message_t::get_timestamp() const
return timestamp_;
}
-/**
- * @brief Return the format of the message
- *
- * @return message_format_t The message format
- */
-message_format_t message_t::get_msg_format()
-{
- return format_;
-}
-
-
uint32_t message_t::get_flags()
{
return flags_;
diff --git a/low-can-binding/can/message/message.hpp b/low-can-binding/can/message/message.hpp
index 2182fe5b..6cef0185 100644
--- a/low-can-binding/can/message/message.hpp
+++ b/low-can-binding/can/message/message.hpp
@@ -32,16 +32,17 @@
/**
- * @enum message_format_t
- * @brief The ID format for a CAN message.
+ * FLAGS
*/
-enum class message_format_t {
- STANDARD, ///< STANDARD - standard 11-bit CAN arbitration ID. */
- EXTENDED, ///< EXTENDED - an extended frame, with a 29-bit arbitration ID. */
- J1939, ///< J1939 - Format for j1939 messages
- INVALID, ///< INVALID - INVALID code used at initialization to signify that it isn't usable'*/
-};
+#define INVALID_FLAG 0x0001
+#define STANDARD_ID 0x0002
+#define EXTENDED_ID 0x0004
+#define BCM_PROTOCOL 0x0008
+#define J1939_PROTOCOL 0x0010
+#define J1939_ADDR_CLAIM_PROTOCOL 0x0020
+#define ISOTP_PROTOCOL 0x0040
+#define FD_FRAME 0x0800
/// @class message_t
///
@@ -51,15 +52,14 @@ class message_t {
protected:
uint32_t maxdlen_; ///< maxdlen_ - Max data length deduce from number of bytes read from the socket.*/
uint32_t length_; ///< length_ - the length of the data array. */
- message_format_t format_; ///< format_ - the format of the message's ID.*/
+ uint32_t flags_; ///< format_ - the format mask of the message*/
std::vector<uint8_t> data_; ///< data_ - The message's data field with a size of 8 which is the standard about CAN bus messages.*/
uint64_t timestamp_; ///< timestamp_ - timestamp of the received message*/
int sub_id_; ///< sub_id_ - Subscription index. */
- uint32_t flags_; ///< flags_ - flags of a CAN FD frame. Needed if we catch FD frames.*/
public:
message_t();
- message_t(uint32_t maxdlen, uint32_t length, message_format_t format, std::vector<uint8_t>& data, uint64_t timestamp, uint32_t flags);
+ message_t(uint32_t maxdlen, uint32_t length, uint32_t flags, std::vector<uint8_t>& data, uint64_t timestamp);
virtual ~message_t() = default;
int get_sub_id() const;
@@ -72,7 +72,6 @@ public:
void set_data(std::vector<uint8_t> &data);
void set_sub_id(int sub_id);
void set_timestamp(uint64_t timestamp);
- message_format_t get_msg_format();
virtual bool is_set() = 0;
virtual std::string get_debug_message() = 0;
virtual uint32_t get_id() const = 0;