mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
STM32 test: Time sync slave
This commit is contained in:
parent
befd18de6d
commit
0edeff9e4d
@ -5,6 +5,7 @@
|
||||
#include <unistd.h>
|
||||
#include <crdr_chibios/sys/sys.h>
|
||||
#include <uavcan_stm32/uavcan_stm32.hpp>
|
||||
#include <uavcan/protocol/global_time_sync_slave.hpp>
|
||||
|
||||
namespace app
|
||||
{
|
||||
@ -93,6 +94,18 @@ public:
|
||||
::sleep(3);
|
||||
}
|
||||
|
||||
/*
|
||||
* Time synchronizer
|
||||
*/
|
||||
static uavcan::GlobalTimeSyncSlave time_sync_slave(node);
|
||||
{
|
||||
const int res = time_sync_slave.start();
|
||||
if (res < 0)
|
||||
{
|
||||
die(res);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Main loop
|
||||
*/
|
||||
@ -100,11 +113,12 @@ public:
|
||||
node.setStatusOk();
|
||||
while (true)
|
||||
{
|
||||
const int spin_res = node.spin(uavcan::MonotonicDuration::fromMSec(100));
|
||||
const int spin_res = node.spin(uavcan::MonotonicDuration::fromMSec(5000));
|
||||
if (spin_res < 0)
|
||||
{
|
||||
lowsyslog("Spin failure: %i\n", spin_res);
|
||||
}
|
||||
lowsyslog("Time sync master: %u\n", unsigned(time_sync_slave.getMasterNodeID().get()));
|
||||
}
|
||||
return msg_t();
|
||||
}
|
||||
@ -130,5 +144,11 @@ int main()
|
||||
sleep(1);
|
||||
app::ledSet(true);
|
||||
sleep(1);
|
||||
|
||||
const uavcan::UtcTime utc = uavcan_stm32::clock::getUtc();
|
||||
lowsyslog("UTC %lu sec, %li corr, %lu jumps\n",
|
||||
static_cast<unsigned long>(utc.toMSec() / 1000),
|
||||
uavcan_stm32::clock::getUtcSpeedCorrectionPPM(),
|
||||
uavcan_stm32::clock::getUtcAjdustmentJumpCount());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user