SatCat5
ptp_interface.h
1 // Copyright 2023-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Generic API for network ports that support PTP
6 
7 #pragma once
8 
9 #include <satcat5/types.h>
10 
11 namespace satcat5 {
12  namespace ptp {
18  enum class PacketType {NON_PTP, PTP_L2, PTP_L3};
19 
27  class Interface {
28  public:
31  { m_ptp_callback = obj; }
32 
36 
41 
46 
50 
55 
59 
61  inline satcat5::ptp::PacketType ptp_rx_type() const
62  { return m_ptp_rx_type; }
63 
64  protected:
67  : m_ptp_callback(0)
68  , m_ptp_rx_type(PacketType::NON_PTP) {}
69 
74  bool ptp_dispatch(const u8* peek, unsigned length);
75 
77  inline void ptp_notify_now() {m_ptp_callback->poll_demand();}
78 
80  inline void ptp_notify_req() {m_ptp_callback->request_poll();}
81 
82  private:
83  satcat5::poll::OnDemand* m_ptp_callback;
84  satcat5::ptp::PacketType m_ptp_rx_type;
85  };
86  }
87 }
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
An "OnDemand" object is polled only on request.
Definition: polling.h:131
virtual void poll_demand()=0
Deferred event handler, called after request().
void request_poll()
Call this method to request polling at a later time.
Definition: polling.cc:208
Generic API for network ports that support PTP.
Definition: ptp_interface.h:27
virtual satcat5::ptp::Time ptp_rx_timestamp()=0
Return timestamp of the current incoming message.
Interface()
Constructor is not publicly accessible.
Definition: ptp_interface.h:66
virtual satcat5::ptp::Time ptp_tx_timestamp()=0
Return timestamp of the most recent outgoing message.
bool ptp_dispatch(const u8 *peek, unsigned length)
Determine if an incoming packet is a PTP message.
satcat5::ptp::PacketType ptp_rx_type() const
Return the packet type for the most recent message.
Definition: ptp_interface.h:61
virtual satcat5::io::Writeable * ptp_tx_write()=0
Return an object suitable for writing the next PTP frame.
virtual satcat5::ptp::Time ptp_time_now()=0
Return the best available estimate of the current time.
void ptp_notify_now()
Notify the PTP callback object in immediate mode.
Definition: ptp_interface.h:77
void ptp_callback(satcat5::poll::OnDemand *obj)
Set callback object for PTP-related packet handling.
Definition: ptp_interface.h:30
virtual satcat5::io::Readable * ptp_rx_read()=0
Return an object suitable for reading the next PTP frame.
virtual satcat5::ptp::Time ptp_tx_start()=0
Begin sending a timestamped message.
void ptp_notify_req()
Notify the PTP callback object in deferred mode.
Definition: ptp_interface.h:80
High-precision timestamp for use with PTP / IEEE1588.
Definition: ptp_time.h:41
Basic type aliases and prototypes used throughout SatCat5.