SatCat5
log_cbor.h
Go to the documentation of this file.
1 // Copyright 2023-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
22 
23 #pragma once
24 
25 #include <satcat5/ethernet.h>
26 #include <satcat5/log.h>
27 #include <satcat5/types.h>
28 #include <satcat5/udp_core.h>
29 
30 // Enable this feature? (See types.h)
31 #if SATCAT5_CBOR_ENABLE
32 
33 namespace satcat5 {
34  namespace log {
42  protected:
44  FromCbor(
45  satcat5::net::Dispatch* src, // Incoming message interface
46  satcat5::net::Type filter); // Incoming message type
47  ~FromCbor() SATCAT5_OPTIONAL_DTOR;
48 
51  void frame_rcvd(satcat5::io::LimitedRead& src) override;
52 
58  virtual void log_event(s8 priority, unsigned nbytes, const char* msg);
59 
62 
63  public:
68  void set_min_priority(s8 priority) {m_min_priority = priority;}
69 
70  private:
71  s8 m_min_priority = satcat5::log::DEBUG; // default to handle everything
72  };
73 
81  protected:
84  explicit ToCbor(satcat5::net::Address* dst);
85  ~ToCbor() {}
86 
87  // Implement the required "log_event" handler.
88  void log_event(s8 priority, unsigned nbytes, const char* msg) override;
89 
90  // Destination interface and address.
91  satcat5::net::Address* const m_dst;
92  public:
93  // Set the minimum level (priority). Messages below this level will be ignored.
94  void set_min_priority(s8 priority) {m_min_priority = priority;}
95  private:
96  s8 m_min_priority = satcat5::log::DEBUG; // default to handle everything
97  };
98  }
99 
100  namespace eth {
102  class LogFromCbor final
103  : public satcat5::log::FromCbor
104  {
105  public:
107  LogFromCbor(
108  satcat5::eth::Dispatch* iface, // Ethernet interface
109  const satcat5::eth::MacType& typ); // Incoming EtherType
110  ~LogFromCbor() {}
111  };
112 
114  class LogToCbor final
116  , public satcat5::log::ToCbor
117  {
118  public:
122  LogToCbor(
123  satcat5::eth::Dispatch* eth, // Ethernet interface
124  const satcat5::eth::MacType& typ); // Destination EtherType
125  ~LogToCbor() {}
126 
128  inline void connect(
129  const satcat5::eth::MacAddr& addr,
130  const satcat5::eth::MacType& type)
131  { m_addr.connect(addr, type); }
132 
134  inline void close()
135  { m_addr.close(); }
136  };
137  }
138 
139  namespace udp {
141  class LogFromCbor final
142  : public satcat5::log::FromCbor
143  {
144  public:
146  LogFromCbor(
147  satcat5::udp::Dispatch* iface, // UDP interface
148  const satcat5::udp::Port& port); // Incoming UDP port
149  ~LogFromCbor() {}
150  };
151 
153  class LogToCbor final
155  , public satcat5::log::ToCbor
156  {
157  public:
161  LogToCbor(
162  satcat5::udp::Dispatch* udp, // UDP interface
163  const satcat5::udp::Port& dstport); // Destination port
164  ~LogToCbor() {}
165 
167  inline void connect(
168  const satcat5::udp::Addr& dstaddr,
169  const satcat5::udp::Port& dstport)
170  { m_addr.connect(dstaddr, dstport, 0);}
171 
173  inline void close()
174  { m_addr.close(); }
175  };
176  }
177 }
178 
179 #endif // SATCAT5_CBOR_ENABLE
Inheritable container for a eth::Address.
Definition: eth_address.h:60
void close() override
Close any open connections and revert to idle.
Definition: eth_address.cc:37
void connect(const satcat5::eth::MacAddr &addr, const satcat5::eth::MacType &type, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Connect to the designated address.
Definition: eth_address.cc:19
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Specialization of satcat5::log::FromCbor for raw-Ethernet frames.
Definition: log_cbor.h:104
LogFromCbor(satcat5::eth::Dispatch *iface, const satcat5::eth::MacType &typ)
Constructor binds to a specific interface and EtherType.
Definition: log_cbor.cc:123
Specialization of satcat5::log::ToCbor for raw-Ethernet frames.
Definition: log_cbor.h:117
void connect(const satcat5::eth::MacAddr &addr, const satcat5::eth::MacType &type)
Set the destination address.
Definition: log_cbor.h:128
void close()
Stop message forwarding.
Definition: log_cbor.h:134
LogToCbor(satcat5::eth::Dispatch *eth, const satcat5::eth::MacType &typ)
Constructor binds to a specific interface and EtherType.
Definition: log_cbor.cc:131
Limited read of next N bytes.
Definition: io_readable.h:255
Defines the interface for accepting Log messages.
Definition: log.h:72
Read CBOR-formatted network messages and copy to the local log.
Definition: log_cbor.h:41
virtual void log_event(s8 priority, unsigned nbytes, const char *msg)
Event handler for validated messages.
Definition: log_cbor.cc:85
void set_min_priority(s8 priority)
Set the minimum priority for message forwarding.
Definition: log_cbor.h:68
satcat5::net::Dispatch *const m_src
Pointer to the interface object.
Definition: log_cbor.h:61
FromCbor(satcat5::net::Dispatch *src, satcat5::net::Type filter)
Only children can safely access constructor/destructor.
Definition: log_cbor.cc:24
void frame_rcvd(satcat5::io::LimitedRead &src) override
Event handler for incoming messages.
Definition: log_cbor.cc:46
Write local logs to a CBOR-formatted network message.
Definition: log_cbor.h:80
ToCbor(satcat5::net::Address *dst)
Only children can safely access constructor/destructor.
Definition: log_cbor.cc:90
void log_event(s8 priority, unsigned nbytes, const char *msg) override
Callback for each formatted Log message.
Definition: log_cbor.cc:96
Defines a generic API for sending data to a specific destination, such as a MAC address,...
Definition: net_address.h:30
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Definition: net_protocol.h:28
Inheritable container for a udp::Address.
Definition: udp_core.h:149
void connect(const satcat5::udp::Addr &dstaddr, const satcat5::eth::MacAddr &dstmac, const satcat5::udp::Port &dstport, const satcat5::udp::Port &srcport=satcat5::udp::PORT_NONE, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Manual address resolution (user supplies IP + MAC).
Definition: udp_core.cc:30
void close() override
Close any open connections and revert to idle.
Definition: udp_core.h:102
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
Specialization of satcat5::log::FromCbor for UDP datagrams.
Definition: log_cbor.h:143
LogFromCbor(satcat5::udp::Dispatch *iface, const satcat5::udp::Port &port)
Constructor binds to a specific incoming UDP port.
Definition: log_cbor.cc:141
Specialization of satcat5::log::ToCbor for UDP datagrams.
Definition: log_cbor.h:156
void connect(const satcat5::udp::Addr &dstaddr, const satcat5::udp::Port &dstport)
Set the destination address.
Definition: log_cbor.h:167
void close()
Stop message forwarding.
Definition: log_cbor.h:173
LogToCbor(satcat5::udp::Dispatch *udp, const satcat5::udp::Port &dstport)
Constructor binds to a specific interface and port number.
Definition: log_cbor.cc:149
Diagnostic logging to UART and/or Ethernet ports.
constexpr s8 DEBUG
Define basic priority codes for log messages.
Definition: log.h:109
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
EtherType field (uint16) is used a protocol-ID [1536..65535].
Definition: eth_header.h:96
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15
UDP and TCP ports are both 16-bit unsigned integers.
Definition: ip_core.h:119
Multipurpose filter for matching fields in network packets.
Definition: net_type.h:38
Basic type aliases and prototypes used throughout SatCat5.