SatCat5
ptp_tlv.h
Go to the documentation of this file.
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
44 
45 #pragma once
46 
47 #include <satcat5/list.h>
48 #include <satcat5/types.h>
49 
50 namespace satcat5 {
51  namespace ptp {
55  constexpr u16
56  TLVTYPE_NONE = 0x0000,
58  TLVTYPE_ORG_EXT = 0x0003,
60  TLVTYPE_DOPPLER = 0x20AE, // Experimental / SatCat5 only
63  TLVTYPE_PAD = 0x8008,
64  TLVTYPE_AUTH = 0x8009;
66 
70  struct TlvHeader {
74  u16 type; // (All) tlvType
75  u16 length; // (All) Length of dataField or valueField
76  u32 org_id; // (Org) organizationId (zero = disabled)
77  u32 org_sub; // (Org) organizationSubType (zero = disabled)
78 
79  // Explicitly declare default constructor and assignment methods.
80  TlvHeader() = default;
81  TlvHeader(const TlvHeader& t) = default;
82  TlvHeader& operator=(const TlvHeader& t) = default;
83 
85  bool match(const satcat5::ptp::TlvHeader& other) const;
86 
90  bool propagate() const;
91 
94  inline constexpr unsigned len_header() const
95  {return (org_id || org_sub) ? 10 : 4;}
96  inline constexpr unsigned len_total() const
97  {return len_header() + length;}
98 
102  void write_to(satcat5::io::Writeable* wr) const;
105  };
106 
107  constexpr satcat5::ptp::TlvHeader TLV_HEADER_NONE = {0, 0, 0, 0};
108 
111  class TlvHandler {
112  public:
117  virtual bool tlv_rcvd(
118  const satcat5::ptp::Header& hdr, // Received message header
119  const satcat5::ptp::TlvHeader& tlv, // Received TLV header
120  satcat5::io::LimitedRead& rd); // Received TLV data
121 
126  virtual unsigned tlv_send(
127  const satcat5::ptp::Header& hdr, // Received message header
129 
133  virtual void tlv_meas(satcat5::ptp::Measurement& meas);
134 
135  protected:
137  explicit TlvHandler(satcat5::ptp::Client* client);
138  ~TlvHandler();
139 
142 
143  private:
144  // Linked list pointer to the next registered TlvHandler.
146  satcat5::ptp::TlvHandler* m_next;
147  };
148  }
149 }
Limited read of next N bytes.
Definition: io_readable.h:255
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
Client for the IEEE 1588-2019 Precision Time Protocol (PTP)
Definition: ptp_client.h:67
Users should derive custom TLV objects from this base class.
Definition: ptp_tlv.h:111
satcat5::ptp::Client *const m_client
Pointer to the associated PTP client.
Definition: ptp_tlv.h:141
virtual unsigned tlv_send(const satcat5::ptp::Header &hdr, satcat5::io::Writeable *wr)
Child class SHOULD override this method to append outgoing TLV(s).
Definition: ptp_tlv.cc:87
virtual bool tlv_rcvd(const satcat5::ptp::Header &hdr, const satcat5::ptp::TlvHeader &tlv, satcat5::io::LimitedRead &rd)
Child class SHOULD override this method to read incoming TLV(s).
Definition: ptp_tlv.cc:78
TlvHandler(satcat5::ptp::Client *client)
Only children should create or destroy the base class.
Definition: ptp_tlv.cc:66
virtual void tlv_meas(satcat5::ptp::Measurement &meas)
Child class MAY override this method to read or modify each complete two-way handshake event.
Definition: ptp_tlv.cc:95
Helper functions for manipulating singly-linked lists.
Definition: list.h:52
Templated functions for manipulating singly-linked lists.
constexpr u16 TLVTYPE_NONE
Define some key tlvType values.
Definition: ptp_tlv.h:56
constexpr u16 TLVTYPE_PAD
Define some key tlvType values.
Definition: ptp_tlv.h:63
constexpr u16 TLVTYPE_ORG_EXT
Define some key tlvType values.
Definition: ptp_tlv.h:58
constexpr u16 TLVTYPE_AUTH
Define some key tlvType values.
Definition: ptp_tlv.h:64
constexpr u16 TLVTYPE_ORG_EXT_P
Define some key tlvType values.
Definition: ptp_tlv.h:61
constexpr u16 TLVTYPE_ORG_EXT_NP
Define some key tlvType values.
Definition: ptp_tlv.h:62
constexpr u16 TLVTYPE_PATH_TRACE
Define some key tlvType values.
Definition: ptp_tlv.h:59
constexpr u16 TLVTYPE_MANAGEMENT
Define some key tlvType values.
Definition: ptp_tlv.h:57
constexpr u16 TLVTYPE_DOPPLER
Define some key tlvType values.
Definition: ptp_tlv.h:60
Struct representing the PTP header used for all message types.
Definition: ptp_header.h:46
Timestamps and metadata for a two-way time-transfer handshake.
Data structure for identifying TLV headers.
Definition: ptp_tlv.h:70
bool propagate() const
When attached to ANNOUNCE messages, certain TLVs are required to propagate across boundary clocks,...
Definition: ptp_tlv.cc:20
void write_to(satcat5::io::Writeable *wr) const
I/O functions read or write the TLV header only.
Definition: ptp_tlv.cc:30
u16 type
Access to the raw header fields Note: This "length" field always reflects the user data length,...
Definition: ptp_tlv.h:74
bool match(const satcat5::ptp::TlvHeader &other) const
Does this TLV match the designated type and/or subtype?
Definition: ptp_tlv.cc:13
bool read_from(satcat5::io::Readable *rd)
I/O functions read or write the TLV header only.
Definition: ptp_tlv.cc:42
constexpr unsigned len_header() const
Total length of TLV header, or header plus associated data.
Definition: ptp_tlv.h:94
Basic type aliases and prototypes used throughout SatCat5.