|
SatCat5
|
Client for the IEEE 1588-2019 Precision Time Protocol (PTP)
This file implements a simple "Client" endpoint for the Precision Time Protocol, which may act as either master or slave depending on mode. It uses a single network port and acts as an "Ordinary Clock" as defined in IEEE 1588-2019 Section 9. Other modes such as boundary clocks may be added in a future release.
This client also supports Meta's proposed "Simple Precision Time Protocol" (SPTP) extention, which reduces overhead for unicast PTP exchanges. https://engineering.fb.com/2024/02/07/production-engineering/simple-precision-time-protocol-sptp-meta/ https://ieeexplore.ieee.org/document/10296989
Long-term feature wishlist:
Definition at line 64 of file ptp_client.h.
#include <ptp_client.h>
Public Member Functions | |
| Client (satcat5::ptp::Interface *ptp_iface, satcat5::ip::Dispatch *ip_dispatch, satcat5::ptp::ClientMode mode=ClientMode::DISABLED) | |
| Set the network interface for this client. | |
| void | set_clock (const satcat5::ptp::ClockInfo &clk) |
| Set clock information for outgoing ANNOUNCE messages. | |
| satcat5::ptp::ClockInfo | get_clock () const |
| Get local clock information. | |
| satcat5::ptp::ClockInfo | get_remote () const |
| Get grandmaster clock information. | |
| satcat5::ptp::Time | get_time_now () |
| Read the current time from the network interface. | |
| s16 | get_utc_offset () const |
| Query the current UTC vs. More... | |
| void | set_utc_offset (s16 offset) |
| Immediately adjust the UTC vs. More... | |
| void | set_announce_rate (int rate) |
| Set the ANNOUNCE message rate to 2^N / sec. More... | |
| void | set_sync_rate (int rate) |
| Set the SYNC message rate to 2^N / sec. More... | |
| void | set_pdelay_rate (int rate) |
| Set the pdelay message rate to 0.9 x 2^N / sec. More... | |
| bool | send_sync_unicast (const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip=satcat5::ip::ADDR_NONE, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE) |
| Send a unicast SYNC message to the designated address. More... | |
| void | ptp_rcvd (satcat5::io::LimitedRead &rd) |
| Dispatch calls this method for each incoming packet. | |
| void | timer_once (unsigned msec) |
| Configure a one-time notification after X milliseconds. | |
| void | timer_every (unsigned msec) |
| Configure a repeating notification every X milliseconds. | |
| void | timer_stop () |
| Stop all future notifications. | |
| unsigned | timer_interval () const |
| Accessor for recurring timer interval, if one is set. | |
| unsigned | timer_remaining () const |
| Accessor for time to next event, if one is set. | |
| void | add_callback (satcat5::ptp::Callback *callback) |
| void | remove_callback (satcat5::ptp::Callback *callback) |
| void | set_mode (satcat5::ptp::ClientMode mode) |
| Mode and state accessors. | |
| satcat5::ip::Dispatch * | get_iface () const |
| Mode and state accessors. | |
| satcat5::ptp::ClientMode | get_mode () const |
| Mode and state accessors. | |
| satcat5::ptp::ClientState | get_state () const |
| Mode and state accessors. | |
| satcat5::ptp::PortId | get_source () const |
| Mode and state accessors. | |
Static Public Member Functions | |
| static unsigned | count_timer () |
| Count all objects of this type, including idle timers. | |
Protected Member Functions | |
| void | timer_event () override |
| Child class MUST override this method. | |
| void | timer_reset () |
| void | cache_miss () |
| void | client_timeout () |
| unsigned | tlv_send (const satcat5::ptp::Header &hdr, satcat5::io::Writeable *wr) |
| void | notify_if_complete (const satcat5::ptp::Measurement *meas) |
| void | rcvd_announce (const satcat5::ptp::Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_delay_req (const satcat5::ptp::Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_pdelay_req (const Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_delay_resp (const satcat5::ptp::Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_pdelay_resp (const satcat5::ptp::Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_follow_up (const satcat5::ptp::Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_pdelay_follow_up (const satcat5::ptp::Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_sync (const satcat5::ptp::Header &hdr, satcat5::io::ArrayRead &rd) |
| void | rcvd_unexpected (const satcat5::ptp::Header &hdr) |
| satcat5::ptp::Header | make_header (u8 type, u16 seq_id) |
| bool | send_announce () |
| bool | send_sync (satcat5::ptp::DispatchTo addr, u16 seq_id, u16 flags=0, u64 tref=0) |
| bool | send_sync_bcast () |
| bool | send_follow_up (satcat5::ptp::DispatchTo addr, u16 seq_id, u16 flags=0, u64 tref=0) |
| void | send_delay_req_sptp () |
| bool | send_delay_req (u16 seq_id, u16 flags=0) |
| bool | send_delay_resp (const satcat5::ptp::Header &ref) |
| bool | send_pdelay_req () |
| bool | send_pdelay_resp (const satcat5::ptp::Header &ref) |
| bool | send_pdelay_follow_up (const satcat5::ptp::Header &ref) |
| void | notify_callbacks (const satcat5::ptp::Measurement &meas) |
| Notify all Callback objects of a new Measurement. | |
Protected Attributes | |
| satcat5::ptp::Dispatch | m_iface |
| satcat5::igmp::Address | m_mcast_primary |
| satcat5::igmp::Address | m_mcast_pdelay |
| satcat5::util::List< satcat5::ptp::TlvHandler > | m_tlv_list |
| satcat5::ptp::ClientMode | m_mode |
| satcat5::ptp::ClientState | m_state |
| satcat5::ptp::MeasurementCache | m_cache |
| satcat5::ptp::ClockInfo | m_clock_local |
| satcat5::ptp::ClockInfo | m_clock_remote |
| satcat5::ptp::PortId | m_current_source |
| unsigned | m_announce_count |
| unsigned | m_announce_every |
| unsigned | m_sync_count |
| unsigned | m_sync_every |
| unsigned | m_cache_wdog |
| unsigned | m_request_wdog |
| int | m_announce_rate |
| int | m_sync_rate |
| int | m_pdelay_rate |
| u16 | m_announce_id |
| u16 | m_sync_id |
| u16 | m_pdelay_id |
| s16 | m_utc_offset |
| satcat5::util::List< satcat5::ptp::Callback > | m_callbacks |
| Linked list of registered callback objects. | |
Private Member Functions | |
| void | query (unsigned elapsed_msec) |
Private Attributes | |
| satcat5::poll::Timer * | m_next |
| unsigned | m_trem |
| unsigned | m_tnext |
|
inline |
Query the current UTC vs.
TAI offset (currentUtcOffset). This is the offset (TAI - UTC), equal to the cumulative number of UTC leap seconds, which is +37 as of 2017. See IEEE1588 Section 7.2.4 for details.
Definition at line 93 of file ptp_client.h.
| bool Client::send_sync_unicast | ( | const satcat5::eth::MacAddr & | mac, |
| const satcat5::ip::Addr & | ip = satcat5::ip::ADDR_NONE, |
||
| const satcat5::eth::VlanTag & | vtag = satcat5::eth::VTAG_NONE |
||
| ) |
Send a unicast SYNC message to the designated address.
Unicast allows higher message rates than broadcast mode, and ignores the rate parameter from set_sync_rate.
Definition at line 209 of file ptp_client.cc.
| void Client::set_announce_rate | ( | int | rate | ) |
Set the ANNOUNCE message rate to 2^N / sec.
Range -8 to +8. INT_MIN disables outgoing ANNOUNCE messages. This setting applies to master mode only.
Definition at line 187 of file ptp_client.cc.
| void Client::set_pdelay_rate | ( | int | rate | ) |
Set the pdelay message rate to 0.9 x 2^N / sec.
Range -8 to +8. INT_MIN disables outgoing PDELAY_REQ messages. This setting applies to passive mode only.
Definition at line 199 of file ptp_client.cc.
| void Client::set_sync_rate | ( | int | rate | ) |
Set the SYNC message rate to 2^N / sec.
Range -8 to +8. INT_MIN disables outgoing SYNC messages. This setting applies to master mode and to SPTP slaves.
Definition at line 193 of file ptp_client.cc.
|
inline |
Immediately adjust the UTC vs.
TAI offset (currentUtcOffset). This has no effect on the client itself, except to change the "currentUtcOffset" reported in each ANNOUNCE message. Changes take effect immediately, without setting the pending-change flags (i.e., "leap59" and "leap61"), which are not supported. See IEEE1588 Section 7.2.4 for details.
Definition at line 102 of file ptp_client.h.