mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-14 03:43:33 +08:00
Run-time checks: Enforcing valid monotonic timestamp for all received frames
This commit is contained in:
@@ -211,7 +211,14 @@ std::string Frame::toString() const
|
||||
bool RxFrame::parse(const CanRxFrame& can_frame)
|
||||
{
|
||||
if (!Frame::parse(can_frame))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (can_frame.ts_mono.isZero()) // Monotonic timestamps are mandatory.
|
||||
{
|
||||
assert(0); // If it is not set, it's a driver failure.
|
||||
return false;
|
||||
}
|
||||
ts_mono_ = can_frame.ts_mono;
|
||||
ts_utc_ = can_frame.ts_utc;
|
||||
iface_index_ = can_frame.iface_index;
|
||||
|
||||
@@ -178,6 +178,7 @@ TEST(Frame, RxFrameParse)
|
||||
ASSERT_FALSE(rx_frame.parse(can_rx_frame));
|
||||
|
||||
// Valid
|
||||
can_rx_frame.ts_mono = uavcan::MonotonicTime::fromUSec(1); // Zero is not allowed
|
||||
can_rx_frame.id = CanFrame::FlagEFF |
|
||||
(2 << 0) | // Transfer ID
|
||||
(1 << 3) | // Last Frame
|
||||
@@ -187,7 +188,7 @@ TEST(Frame, RxFrameParse)
|
||||
(456 << 19); // Data Type ID
|
||||
|
||||
ASSERT_TRUE(rx_frame.parse(can_rx_frame));
|
||||
ASSERT_EQ(0, rx_frame.getMonotonicTimestamp().toUSec());
|
||||
ASSERT_EQ(1, rx_frame.getMonotonicTimestamp().toUSec());
|
||||
ASSERT_EQ(0, rx_frame.getIfaceIndex());
|
||||
|
||||
can_rx_frame.ts_mono = tsMono(123);
|
||||
|
||||
Reference in New Issue
Block a user