SatCat5
ptp_measurement.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.
7 
8 #pragma once
9 
10 #include <satcat5/ptp_header.h>
11 #include <satcat5/ptp_time.h>
12 
13 // Cache-size parameter sets the maximum number of two-way
14 // PTP handshakes that can be in-flight at a given time.
15 #ifndef SATCAT5_PTP_CACHE_SIZE
16 #define SATCAT5_PTP_CACHE_SIZE 4
17 #endif
18 
19 namespace satcat5 {
20  namespace ptp {
37  struct Measurement {
45 
46  // Explicitly declare default constructor and assignment methods.
47  Measurement() = default;
48  Measurement(const Measurement& t) = default;
49  Measurement& operator=(const Measurement& t) = default;
50 
52  bool done() const;
53 
55  void log_to(satcat5::log::LogBuffer& wr) const;
56 
59  bool match(
60  const satcat5::ptp::Header& hdr,
61  const satcat5::ptp::PortId& port) const;
62 
71 
75  void reset(const satcat5::ptp::Header& hdr);
76  };
77 
80 
86  public:
88  constexpr MeasurementCache()
89  : m_next_wr(0), m_buff{} {}
90 
94  const satcat5::ptp::Header& hdr,
95  const satcat5::ptp::PortId& port);
96 
99  const satcat5::ptp::Header& hdr)
100  { return find(hdr, hdr.src_port); }
101 
105  const satcat5::ptp::Header& hdr);
106 
107  protected:
108  unsigned m_next_wr;
109  satcat5::ptp::Measurement m_buff[SATCAT5_PTP_CACHE_SIZE];
110  };
111  }
112 }
Internal buffer used by the Log class.
Definition: log.h:134
Searchable cache of recent Measurement objects.
satcat5::ptp::Measurement * find(const satcat5::ptp::Header &hdr, const satcat5::ptp::PortId &port)
Find the first matching measurement in the cache.
satcat5::ptp::Measurement * find(const satcat5::ptp::Header &hdr)
Shortcut for searches where port = hdr.src_port.
satcat5::ptp::Measurement * push(const satcat5::ptp::Header &hdr)
Create a new measurement, overwriting the oldest.
constexpr MeasurementCache()
Create an empty cache.
High-precision timestamp for use with PTP / IEEE1588.
Definition: ptp_time.h:41
constexpr satcat5::ptp::Measurement MEASUREMENT_NULL
Placeholder for an empty Measurement.
High-precision "Time" object for use with PTP / IEEE1588.
Struct representing the PTP header used for all message types.
Definition: ptp_header.h:46
satcat5::ptp::PortId src_port
sourcePortIdentity
Definition: ptp_header.h:56
Timestamps and metadata for a two-way time-transfer handshake.
satcat5::ptp::Time t1
Timestamp T1 (A to B / Tx)
bool match(const satcat5::ptp::Header &hdr, const satcat5::ptp::PortId &port) const
Check if an incoming message matches this exchange.
void log_to(satcat5::log::LogBuffer &wr) const
Write all four timestamps to the log.
void reset(const satcat5::ptp::Header &hdr)
Reset this data structure for immediate reuse.
bool done() const
Is this measurement completed? (i.e., T1/T2/T3/T4 all known)
satcat5::ptp::Time mean_link_delay() const
Calculate PTP "meanLinkDelay".
satcat5::ptp::Header ref
Reference header is copied from the initiating PTP message (i.e., SYNC or PDELAY_REQ) and used to mat...
satcat5::ptp::Time mean_path_delay() const
Calculate PTP "meanPathDelay".
satcat5::ptp::Time t2
Timestamp T2 (A to B / Rx)
satcat5::ptp::Time t4
Timestamp T4 (B to A / Rx)
satcat5::ptp::Time t3
Timestamp T3 (B to A / Tx)
satcat5::ptp::Time offset_from_master() const
Calculate PTP "offsetFromMaster".
Struct used for sourcePortIdentity and requestingPortIdentity.
Definition: ptp_header.h:17