mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-25 16:30:34 +08:00
Fixed Linux driver: SocketCan driver adds time offset from the provided clock instance, which fixes time synchronization in PerDriverPrivate clock adjustment mode
This commit is contained in:
@@ -32,8 +32,16 @@ static void testSocketRxTx(const std::string& iface_name)
|
||||
const int sock2 = uavcan_linux::SocketCanIface::openSocket(iface_name);
|
||||
ENFORCE(sock1 >= 0 && sock2 >= 0);
|
||||
|
||||
uavcan_linux::SocketCanIface if1(sock1);
|
||||
uavcan_linux::SocketCanIface if2(sock2);
|
||||
/*
|
||||
* Clocks will have some offset from the true system time
|
||||
* SocketCAN driver must handle this correctly
|
||||
*/
|
||||
uavcan_linux::SystemClock clock_impl(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate);
|
||||
clock_impl.adjustUtc(uavcan::UtcDuration::fromMSec(100000));
|
||||
const uavcan_linux::SystemClock& clock = clock_impl;
|
||||
|
||||
uavcan_linux::SocketCanIface if1(clock, sock1);
|
||||
uavcan_linux::SocketCanIface if2(clock, sock2);
|
||||
|
||||
/*
|
||||
* Sending two frames, one of which must be returned back
|
||||
@@ -69,8 +77,6 @@ static void testSocketRxTx(const std::string& iface_name)
|
||||
uavcan::UtcTime ts_utc;
|
||||
uavcan::CanIOFlags flags = 0;
|
||||
|
||||
const uavcan_linux::SystemClock clock(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate);
|
||||
|
||||
/*
|
||||
* Read first
|
||||
*/
|
||||
@@ -132,8 +138,16 @@ static void testSocketFilters(const std::string& iface_name)
|
||||
const int sock2 = uavcan_linux::SocketCanIface::openSocket(iface_name);
|
||||
ENFORCE(sock1 >= 0 && sock2 >= 0);
|
||||
|
||||
uavcan_linux::SocketCanIface if1(sock1);
|
||||
uavcan_linux::SocketCanIface if2(sock2);
|
||||
/*
|
||||
* Clocks will have some offset from the true system time
|
||||
* SocketCAN driver must handle this correctly
|
||||
*/
|
||||
uavcan_linux::SystemClock clock_impl(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate);
|
||||
clock_impl.adjustUtc(uavcan::UtcDuration::fromMSec(-1000));
|
||||
const uavcan_linux::SystemClock& clock = clock_impl;
|
||||
|
||||
uavcan_linux::SocketCanIface if1(clock, sock1);
|
||||
uavcan_linux::SocketCanIface if2(clock, sock2);
|
||||
|
||||
/*
|
||||
* Configuring filters
|
||||
@@ -199,7 +213,15 @@ static void testSocketFilters(const std::string& iface_name)
|
||||
|
||||
static void testDriver(const std::vector<std::string>& iface_names)
|
||||
{
|
||||
uavcan_linux::SocketCanDriver driver;
|
||||
/*
|
||||
* Clocks will have some offset from the true system time
|
||||
* SocketCAN driver must handle this correctly
|
||||
*/
|
||||
uavcan_linux::SystemClock clock_impl(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate);
|
||||
clock_impl.adjustUtc(uavcan::UtcDuration::fromMSec(9000000));
|
||||
const uavcan_linux::SystemClock& clock = clock_impl;
|
||||
|
||||
uavcan_linux::SocketCanDriver driver(clock);
|
||||
for (auto ifn : iface_names)
|
||||
{
|
||||
std::cout << "Adding iface " << ifn << std::endl;
|
||||
@@ -254,7 +276,6 @@ static void testDriver(const std::vector<std::string>& iface_names)
|
||||
/*
|
||||
* Receive loopback
|
||||
*/
|
||||
const uavcan_linux::SystemClock clock(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate);
|
||||
for (int i = 0; i < driver.getNumIfaces(); i++)
|
||||
{
|
||||
uavcan::CanFrame frame;
|
||||
|
||||
Reference in New Issue
Block a user