aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/can
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-19 12:15:07 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-19 16:19:08 +0200
commite4a50a3e96aa39346ad7212cae984524276973dd (patch)
tree8a8ba1e7c4db73c5c94d025e0364e1fef87c04c6 /CAN-binder/low-can-binding/can
parent7bde3f53dbbbf688506a32e89c27c8aa69a86a3f (diff)
Added timestamp to received CAN messages
and store into frequency_clock_t. Change-Id: If209070298bd9df49297fdcbed554770e1bc0e4a Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'CAN-binder/low-can-binding/can')
-rw-r--r--CAN-binder/low-can-binding/can/can-decoder.cpp1
-rw-r--r--CAN-binder/low-can-binding/can/can-message.cpp26
-rw-r--r--CAN-binder/low-can-binding/can/can-message.hpp9
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.cpp5
-rw-r--r--CAN-binder/low-can-binding/can/can-signals.hpp1
5 files changed, 32 insertions, 10 deletions
diff --git a/CAN-binder/low-can-binding/can/can-decoder.cpp b/CAN-binder/low-can-binding/can/can-decoder.cpp
index b0d7bb8..aa1f57e 100644
--- a/CAN-binder/low-can-binding/can/can-decoder.cpp
+++ b/CAN-binder/low-can-binding/can/can-decoder.cpp
@@ -172,6 +172,7 @@ openxc_DynamicField decoder_t::translateSignal(can_signal_t& signal, const can_m
*send = false;
}
signal.set_last_value(value);
+ signal.set_timestamp(message.get_timestamp());
signal.get_message()->set_last_value(message);
return decoded_value;
}
diff --git a/CAN-binder/low-can-binding/can/can-message.cpp b/CAN-binder/low-can-binding/can/can-message.cpp
index 66a4f4f..772734d 100644
--- a/CAN-binder/low-can-binding/can/can-message.cpp
+++ b/CAN-binder/low-can-binding/can/can-message.cpp
@@ -27,7 +27,7 @@
/// Constructor about can_message_t class.
///
can_message_t::can_message_t()
- : maxdlen_{0}, id_{0}, length_{0}, format_{can_message_format_t::INVALID}, rtr_flag_{false}, flags_{0}
+ : maxdlen_{0}, id_{0}, length_{0}, format_{can_message_format_t::INVALID}, rtr_flag_{false}, flags_{0}, timestamp_{0}
{}
can_message_t::can_message_t(uint8_t maxdlen,
@@ -36,14 +36,16 @@ can_message_t::can_message_t(uint8_t maxdlen,
can_message_format_t format,
bool rtr_flag,
uint8_t flags,
- std::vector<uint8_t> data)
+ std::vector<uint8_t> data,
+ uint64_t timestamp)
: maxdlen_{maxdlen},
id_{id},
length_{length},
format_{format},
rtr_flag_{rtr_flag},
flags_{flags},
- data_{data}
+ data_{data},
+ timestamp_{timestamp}
{}
///
@@ -119,6 +121,16 @@ uint8_t can_message_t::get_length() const
return length_;
}
+uint64_t can_message_t::get_timestamp() const
+{
+ return timestamp_;
+}
+
+void can_message_t::set_timestamp(uint64_t timestamp)
+{
+ timestamp_ = timestamp;
+}
+
///
/// @brief Control whether the object is correctly initialized
/// to be sent over the CAN bus
@@ -162,7 +174,7 @@ void can_message_t::set_format(const can_message_format_t new_format)
///
/// @return A can_message_t object fully initialized with canfd_frame values.
///
-can_message_t can_message_t::convert_from_frame(const struct canfd_frame& frame, size_t nbytes)
+can_message_t can_message_t::convert_from_frame(const struct canfd_frame& frame, size_t nbytes, uint64_t timestamp)
{
uint8_t maxdlen, length, flags = (uint8_t)NULL;
uint32_t id;
@@ -239,10 +251,10 @@ can_message_t can_message_t::convert_from_frame(const struct canfd_frame& frame,
id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
}
- return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data);
+ return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp);
}
-can_message_t can_message_t::convert_from_frame(const struct can_frame& frame, size_t nbytes)
+can_message_t can_message_t::convert_from_frame(const struct can_frame& frame, size_t nbytes, uint64_t timestamp)
{
uint8_t maxdlen, length, flags = (uint8_t)NULL;
uint32_t id;
@@ -310,7 +322,7 @@ can_message_t can_message_t::convert_from_frame(const struct can_frame& frame, s
// id, (uint8_t)format, length, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
}
- return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data);
+ return can_message_t(maxdlen, id, length, format, rtr_flag, flags, data, timestamp);
}
///
diff --git a/CAN-binder/low-can-binding/can/can-message.hpp b/CAN-binder/low-can-binding/can/can-message.hpp
index 3fde5f1..910b3e9 100644
--- a/CAN-binder/low-can-binding/can/can-message.hpp
+++ b/CAN-binder/low-can-binding/can/can-message.hpp
@@ -51,10 +51,11 @@ private:
bool rtr_flag_; /*!< rtr_flag_ - Telling if the frame has RTR flag positionned. Then frame hasn't data field*/
uint8_t flags_; /*!< flags_ - flags of a CAN FD frame. Needed if we catch FD frames.*/
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*/
public:
can_message_t();
- can_message_t(uint8_t maxdlen, uint32_t id, uint8_t length, can_message_format_t format, bool rtr_flag_, uint8_t flags, std::vector<uint8_t> data);
+ can_message_t(uint8_t maxdlen, uint32_t id, uint8_t length, can_message_format_t format, bool rtr_flag_, uint8_t flags, std::vector<uint8_t> data, uint64_t timestamp);
uint32_t get_id() const;
bool get_rtr_flag_() const;
@@ -63,13 +64,15 @@ public:
const uint8_t* get_data() const;
const std::vector<uint8_t> get_data_vector() const;
uint8_t get_length() const;
+ uint64_t get_timestamp() const;
+ void set_timestamp(uint64_t timestamp);
void set_format(const can_message_format_t new_format);
bool is_correct_to_send();
- static can_message_t convert_from_frame(const canfd_frame& frame, size_t nbytes);
- static can_message_t convert_from_frame(const can_frame& frame, size_t nbytes);
+ static can_message_t convert_from_frame(const canfd_frame& frame, size_t nbytes, uint64_t timestamp);
+ static can_message_t convert_from_frame(const can_frame& frame, size_t nbytes, uint64_t timestamp);
struct canfd_frame convert_to_canfd_frame();
struct can_frame convert_to_can_frame();
diff --git a/CAN-binder/low-can-binding/can/can-signals.cpp b/CAN-binder/low-can-binding/can/can-signals.cpp
index 024855c..9a87613 100644
--- a/CAN-binder/low-can-binding/can/can-signals.cpp
+++ b/CAN-binder/low-can-binding/can/can-signals.cpp
@@ -215,6 +215,11 @@ void can_signal_t::set_last_value(float val)
last_value_ = val;
}
+void can_signal_t::set_timestamp(uint64_t timestamp)
+{
+ frequency_.tick(timestamp);
+}
+
/// @brief Create a RX_SETUP receive job used by the BCM socket.
///
/// @return 0 if ok else -1
diff --git a/CAN-binder/low-can-binding/can/can-signals.hpp b/CAN-binder/low-can-binding/can/can-signals.hpp
index e4077c2..cc4b6da 100644
--- a/CAN-binder/low-can-binding/can/can-signals.hpp
+++ b/CAN-binder/low-can-binding/can/can-signals.hpp
@@ -154,6 +154,7 @@ public:
void set_prefix(std::string val);
void set_received(bool r);
void set_last_value(float val);
+ void set_timestamp(uint64_t timestamp);
int create_rx_filter();
};