mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-21 12:07:34 +08:00
65 lines
1.4 KiB
C++
65 lines
1.4 KiB
C++
/*
|
|
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <uavcan/node/publisher.hpp>
|
|
#include <uavcan/node/subscriber.hpp>
|
|
#include <uavcan/util/method_binder.hpp>
|
|
#include <uavcan/util/lazy_constructor.hpp>
|
|
#include <uavcan/protocol/GlobalTimeSync.hpp>
|
|
|
|
namespace uavcan
|
|
{
|
|
/**
|
|
* Ref. M. Gergeleit, H. Streich - "Implementing a Distributed High-Resolution Real-Time Clock using the CAN-Bus"
|
|
* TODO: Enforce max one master per node
|
|
*/
|
|
class GlobalTimeSyncMaster : protected LoopbackFrameListenerBase
|
|
{
|
|
class IfaceMaster
|
|
{
|
|
Publisher<protocol::GlobalTimeSync> pub_;
|
|
MonotonicTime prev_pub_mono_;
|
|
UtcTime prev_tx_utc_;
|
|
const uint8_t iface_index_;
|
|
|
|
public:
|
|
IfaceMaster(INode& node, uint8_t iface_index)
|
|
: pub_(node)
|
|
, iface_index_(iface_index)
|
|
{
|
|
assert(iface_index < MaxCanIfaces);
|
|
}
|
|
|
|
int init();
|
|
|
|
void setTxTimestamp(UtcTime ts);
|
|
|
|
int publish();
|
|
};
|
|
|
|
INode& node_;
|
|
LazyConstructor<IfaceMaster> iface_masters_[MaxCanIfaces];
|
|
DataTypeID dtid_;
|
|
bool initialized_;
|
|
|
|
void handleLoopbackFrame(const RxFrame& frame);
|
|
|
|
public:
|
|
explicit GlobalTimeSyncMaster(INode& node)
|
|
: LoopbackFrameListenerBase(node.getDispatcher())
|
|
, node_(node)
|
|
, initialized_(false)
|
|
{ }
|
|
|
|
int init();
|
|
|
|
bool isInitialized() const { return initialized_; }
|
|
|
|
int publish();
|
|
};
|
|
|
|
}
|