aboutsummaryrefslogtreecommitdiffstats
path: root/CAN-binder/low-can-binding/utils
diff options
context:
space:
mode:
Diffstat (limited to 'CAN-binder/low-can-binding/utils')
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan-bcm.cpp7
-rw-r--r--CAN-binder/low-can-binding/utils/socketcan-raw.cpp5
-rw-r--r--CAN-binder/low-can-binding/utils/timer.cpp10
-rw-r--r--CAN-binder/low-can-binding/utils/timer.hpp7
4 files changed, 22 insertions, 7 deletions
diff --git a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
index 7323565c..38f48522 100644
--- a/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
+++ b/CAN-binder/low-can-binding/utils/socketcan-bcm.cpp
@@ -84,7 +84,12 @@ namespace utils
DEBUG(binder_interface, "read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", ifr.ifr_name, msg.msg_head.can_id, msg.frames.can_dlc,
msg.frames.data[0], msg.frames.data[1], msg.frames.data[2], msg.frames.data[3], msg.frames.data[4], msg.frames.data[5], msg.frames.data[6], msg.frames.data[7]);
- cm = ::can_message_t::convert_from_frame(msg.frames , nbytes-sizeof(struct bcm_msg_head));
+ struct timeval tv;
+ ioctl(s.socket(), SIOCGSTAMP, &tv);
+ uint64_t timestamp = 1000000 * tv.tv_sec + tv.tv_usec;
+ cm = ::can_message_t::convert_from_frame(msg.frames ,
+ nbytes-sizeof(struct bcm_msg_head),
+ timestamp);
return s;
}
diff --git a/CAN-binder/low-can-binding/utils/socketcan-raw.cpp b/CAN-binder/low-can-binding/utils/socketcan-raw.cpp
index d8cd906f..a35a99d4 100644
--- a/CAN-binder/low-can-binding/utils/socketcan-raw.cpp
+++ b/CAN-binder/low-can-binding/utils/socketcan-raw.cpp
@@ -78,7 +78,10 @@ namespace utils
DEBUG(binder_interface, "read: Found on bus %s:\n id: %X, length: %X, data %02X%02X%02X%02X%02X%02X%02X%02X", ifr.ifr_name, frame.can_id, frame.len,
frame.data[0], frame.data[1], frame.data[2], frame.data[3], frame.data[4], frame.data[5], frame.data[6], frame.data[7]);
- cm = ::can_message_t::convert_from_frame(frame , nbytes);
+ struct timeval tv;
+ ioctl(s.socket(), SIOCGSTAMP, &tv);
+ uint64_t timestamp = 1000000 * tv.tv_sec + tv.tv_usec;
+ cm = ::can_message_t::convert_from_frame(frame , nbytes, timestamp);
return s;
}
diff --git a/CAN-binder/low-can-binding/utils/timer.cpp b/CAN-binder/low-can-binding/utils/timer.cpp
index 3d90a007..9c22bd0d 100644
--- a/CAN-binder/low-can-binding/utils/timer.cpp
+++ b/CAN-binder/low-can-binding/utils/timer.cpp
@@ -62,6 +62,12 @@ frequency_clock_t::frequency_clock_t(float frequency)
frequency_ = 1;
}
+frequency_clock_t::frequency_clock_t(float frequency, uint64_t last_tick, time_function_t time_function)
+ : unit_{1000000}, frequency_{frequency}, last_tick_{0}, time_function_{nullptr}
+{
+ if(frequency_ <= 0)
+ frequency_ = 1;
+}
/// @brief Return the period in ms given the frequency in hertz.
/// @param[in] frequency - Frequency to convert, in hertz
float frequency_clock_t::frequency_to_period() const
@@ -109,7 +115,7 @@ float frequency_clock_t::get_frequency() const
/// @brief Force the clock to tick, regardless of it its time has actually
/// elapsed.
-void frequency_clock_t::tick()
+void frequency_clock_t::tick(uint64_t timestamp)
{
- last_tick_ = get_time_function()();
+ last_tick_ = timestamp;
} \ No newline at end of file
diff --git a/CAN-binder/low-can-binding/utils/timer.hpp b/CAN-binder/low-can-binding/utils/timer.hpp
index 8ea74768..432d513d 100644
--- a/CAN-binder/low-can-binding/utils/timer.hpp
+++ b/CAN-binder/low-can-binding/utils/timer.hpp
@@ -18,6 +18,7 @@
#pragma once
#include <sys/time.h>
+#include <stdint.h>
/// @brief return epoch in milliseconds
///
@@ -36,13 +37,13 @@ class frequency_clock_t
private:
float unit_; ///< unit_ - multiplicator to make operation to be in the right unit (milli, micro, nano, etc)
float frequency_; ///< the clock frequency in Hz.
- unsigned long last_tick_; ///< the last time (in milliseconds since startup) that the clock ticked.
+ uint64_t last_tick_; ///< the last time (in microseconds since startup) that the clock ticked.
time_function_t time_function_; ///< a function returning current time
public:
frequency_clock_t();
frequency_clock_t(float frequency);
- frequency_clock_t(float frequency, unsigned long last_tick, time_function_t time_function);
+ frequency_clock_t(float frequency, uint64_t last_tick, time_function_t time_function);
float get_frequency() const;
const struct timeval get_timeval_from_period() const;
@@ -52,5 +53,5 @@ public:
time_function_t get_time_function();
bool elapsed(bool stagger);
- void tick();
+ void tick(uint64_t timestamp);
}; \ No newline at end of file