7 #include <satcat5/ptp_client.h>
8 #include <satcat5/ptp_doppler.h>
15 using satcat5::ptp::ClientMode;
27 #ifndef SATCAT5_SPTP_ENABLE
28 #define SATCAT5_SPTP_ENABLE 2
32 #ifndef SATCAT5_DOPPLER_TCOMP
33 #define SATCAT5_DOPPLER_TCOMP false
37 static constexpr
unsigned DEBUG_VERBOSE = 1;
46 , m_tref(SATCAT5_CLOCK->now())
47 , m_tcomp(SATCAT5_DOPPLER_TCOMP)
59 m_dstamp = rd.read_s48();
62 bool rcvd_sptp = SATCAT5_SPTP_ENABLE
65 bool rcvd_final = (hdr.
type == Header::TYPE_DELAY_RESP)
71 elapsed_usec = min_u32(1000000, elapsed_usec);
72 m_predict.
update(m_dstamp, elapsed_usec);
76 if (DEBUG_VERBOSE > 1) {
97 || (hdr.
type == Header::TYPE_DELAY_REQ)
98 || (hdr.
type == Header::TYPE_PDELAY_REQ)
99 || (hdr.
type == Header::TYPE_PDELAY_RESP)
100 || (hdr.
type == Header::TYPE_DELAY_RESP);
102 || (hdr.
type == Header::TYPE_PDELAY_REQ)
103 || (hdr.
type == Header::TYPE_DELAY_REQ && flag_sptp);
106 if (send_any && wr) {
108 wr->write_s48(send_first ? 0 : m_dstamp);
110 return send_any ? TLVHDR_DOPPLER.len_total() : 0;
119 s64 t = (meas.
t4 - meas.
t1).abs().delta_subns();
123 s64 a = m_predict.
predict(500000) - v;
127 s64 delta = s64((((aa * tt).div_round(s) + vv) * tt).div_round(s));
128 if (m_tcomp) meas.
t4 -=
Time(delta);
131 if (DEBUG_VERBOSE > 0) {
146 , m_ctrl(DEFAULT_TIME_CONSTANT)
Limited read of next N bytes.
Abstract API for writing byte-streams and packets.
void write_obj(const T &obj)
Templated wrapper for any object with the following method: void write_to(satcat5::io::Writeable* wr)...
The Log class creates and formats one log message.
Log & write10(s32 val)
Print integer as a decimal value with no leading zeros.
Log & write(const char *str)
Formatting methods for various data types.
Client for the IEEE 1588-2019 Precision Time Protocol (PTP)
satcat5::ptp::ClientMode get_mode() const
Mode and state accessors.
Streamlined variant of ptp::DopplerTlv, with a built-in filter chain that is adequate for most PTP ap...
TlvHandler for experimental Doppler-TLV tags.
void add_filter(satcat5::ptp::Filter *filter)
Add to the chain of processing filters.
bool tlv_rcvd(const satcat5::ptp::Header &hdr, const satcat5::ptp::TlvHeader &tlv, satcat5::io::LimitedRead &rd) override
Child class SHOULD override this method to read incoming TLV(s).
void tlv_meas(satcat5::ptp::Measurement &meas) override
Child class MAY override this method to read or modify each complete two-way handshake event.
unsigned tlv_send(const satcat5::ptp::Header &hdr, satcat5::io::Writeable *wr) override
Child class SHOULD override this method to append outgoing TLV(s).
s64 predict(u32 elapsed_usec) const
Extrapolate trendline relative to most recent update() event.
s64 update(s64 next, u32 elapsed_usec) override
Required API from ptp::Filter.
High-precision timestamp for use with PTP / IEEE1588.
Users should derive custom TLV objects from this base class.
satcat5::ptp::Client *const m_client
Pointer to the associated PTP client.
Diagnostic logging to UART and/or Ethernet ports.
Timekeeper timekeeper
There is a single global instance of the Timekeeper class.
Define the data structure for a two-way time transfer handshake.
constexpr s64 SUBNS_PER_SEC
Define commonly used scaling factors.
constexpr u16 TLVTYPE_DOPPLER
Define some key tlvType values.
Loop-filter coefficients for use with the "ControllerPI" class.
Timestamps and metadata for a two-way time-transfer handshake.
satcat5::ptp::Time t1
Timestamp T1 (A to B / Tx)
satcat5::ptp::Time t4
Timestamp T4 (B to A / Rx)
unsigned increment_usec()
Measure elapsed time in microseconds, then increment by the returned quantized value.
Miscellaneous mathematical utility functions.
constexpr u32 min_u32(u32 a, u32 b)
Min and max functions.