7 #include <satcat5/eth_dispatch.h>
9 #include <satcat5/udp_dispatch.h>
12 #if SATCAT5_CBOR_ENABLE
13 #include <qcbor/qcbor_decode.h>
14 #include <qcbor/qcbor_encode.h>
20 #ifndef SATCAT5_QCBOR_BUFFER
21 #define SATCAT5_QCBOR_BUFFER 1500
27 : satcat5::net::Protocol(filter)
34 #if SATCAT5_ALLOW_DELETION
35 FromCbor::~FromCbor() {
41 inline bool int_or_null(
const QCBORItem& item) {
42 return item.uDataType == QCBOR_TYPE_NULL
43 || item.uDataType == QCBOR_TYPE_INT64;
49 QCBORDecodeContext cbor;
60 QCBORDecode_Init(&cbor, {buff, plen}, QCBOR_DECODE_MODE_NORMAL);
64 errcode = QCBORDecode_GetNext(&cbor, &item);
65 if (errcode || item.uDataType != QCBOR_TYPE_ARRAY)
return;
69 errcode = QCBORDecode_GetNext(&cbor, &item);
70 if (errcode || !int_or_null(item))
return;
71 errcode = QCBORDecode_GetNext(&cbor, &item);
72 if (errcode || !int_or_null(item))
return;
73 errcode = QCBORDecode_GetNext(&cbor, &item);
74 if (errcode || item.uDataType != QCBOR_TYPE_INT64)
return;
75 errcode = QCBOR_Int64ToInt8(item.val.int64, &priority);
77 if (errcode || priority < m_min_priority)
return;
78 errcode = QCBORDecode_GetNext(&cbor, &item);
79 if (errcode || item.uDataType != QCBOR_TYPE_TEXT_STRING)
return;
82 log_event(priority, item.val.string.len, (
const char*)item.val.string.ptr);
98 if (priority < m_min_priority)
return;
104 QCBOREncodeContext cbor;
105 QCBOREncode_Init(&cbor, UsefulBuf_FROM_BYTE_ARRAY(buff));
106 QCBOREncode_OpenArray(&cbor);
107 QCBOREncode_AddNULL(&cbor);
108 auto now = satcat5::datetime::clock.
gps();
109 QCBOREncode_AddInt64(&cbor, now.tow);
110 QCBOREncode_AddInt64(&cbor, priority);
111 QCBOREncode_AddText(&cbor, {msg, nbytes});
112 QCBOREncode_CloseArray(&cbor);
116 QCBORError error = QCBOREncode_Finish(&cbor, &encoded);
135 , satcat5::log::
ToCbor(&m_addr)
138 connect(satcat5::eth::MACADDR_BROADCAST, typ);
153 , satcat5::log::
ToCbor(&m_addr)
156 connect(satcat5::ip::ADDR_BROADCAST, dstport);
satcat5::datetime::GpsTime gps() const
Current time as GPS week number and time-of-week.
Inheritable container for a eth::Address.
Implemention of "net::Dispatch" for Ethernet frames.
LogFromCbor(satcat5::eth::Dispatch *iface, const satcat5::eth::MacType &typ)
Constructor binds to a specific interface and EtherType.
void connect(const satcat5::eth::MacAddr &addr, const satcat5::eth::MacType &type)
Set the destination address.
LogToCbor(satcat5::eth::Dispatch *eth, const satcat5::eth::MacType &typ)
Constructor binds to a specific interface and EtherType.
Limited read of next N bytes.
bool read_bytes(unsigned nbytes, void *dst) override
Read 0 or more bytes into a buffer.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
Read CBOR-formatted network messages and copy to the local log.
virtual void log_event(s8 priority, unsigned nbytes, const char *msg)
Event handler for validated messages.
satcat5::net::Dispatch *const m_src
Pointer to the interface object.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Event handler for incoming messages.
The Log class creates and formats one log message.
Write local logs to a CBOR-formatted network message.
ToCbor(satcat5::net::Address *dst)
Only children can safely access constructor/destructor.
void log_event(s8 priority, unsigned nbytes, const char *msg) override
Callback for each formatted Log message.
Defines a generic API for sending data to a specific destination, such as a MAC address,...
bool write_packet(unsigned nbytes, const void *data)
All-in-one call that writes an entire packet.
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
void add(satcat5::net::Protocol *proto)
Register a Protocol object.
void remove(satcat5::net::Protocol *proto)
Unregister a Protocol object.
Inheritable container for a udp::Address.
Dispatcher sorts incoming UDP messages by port index.
LogFromCbor(satcat5::udp::Dispatch *iface, const satcat5::udp::Port &port)
Constructor binds to a specific incoming UDP port.
void connect(const satcat5::udp::Addr &dstaddr, const satcat5::udp::Port &dstport)
Set the destination address.
LogToCbor(satcat5::udp::Dispatch *udp, const satcat5::udp::Port &dstport)
Constructor binds to a specific interface and port number.
Real-time clock conversion functions.
#define SATCAT5_QCBOR_BUFFER
Set the default size for the QCBOR buffer.
CBOR-encoded network logging.
EtherType field (uint16) is used a protocol-ID [1536..65535].
UDP and TCP ports are both 16-bit unsigned integers.
Multipurpose filter for matching fields in network packets.