6 #include <satcat5/coap_endpoint.h>
8 #include <satcat5/coap_writer.h>
10 #include <satcat5/udp_dispatch.h>
20 namespace log = satcat5::log;
23 static const unsigned DEBUG_VERBOSE = 0;
26 : Protocol(satcat5::net::TYPE_NONE)
34 #if SATCAT5_ALLOW_DELETION
35 Endpoint::~Endpoint() {
43 item = m_list.
next(item);
50 while (item && !item->
is_idle()) {
51 item = m_list.
next(item);
57 if (DEBUG_VERBOSE > 0)
log::Log(log::DEBUG,
"CoAP: frame_rcvd");
64 item = m_list.
next(item);
71 reply(TYPE_RST, &msg);
return;
84 log::Log(log::WARNING,
"CoAP: All connections busy.");
88 bool Endpoint::reply(u8 type,
const ReadHeader* rcvd) {
91 if (DEBUG_VERBOSE > 0)
99 reply.write_header(type, CODE_EMPTY, rcvd->
msg_id());
100 reply.write_finalize();
111 : m_connection(coap, (satcat5::ccsds_spp::Dispatch*)coap->iface())
124 EndpointSppFwd::EndpointSppFwd(
128 , m_endpoint(backing_endpoint)
132 m_endpoint->m_aux_ep =
this;
163 if (
udp)
udp->connect(dstaddr, dstport, srcport);
Implemention of "net::Dispatch" API for CCSDS-SPP packets.
CoAP request/response handling for a single client-server connection.
bool is_match_addr() const
< Match reply endpoint?
bool is_idle() const
< Idle and ready for use?
u32 get_proxy_token() const
Query the most recent proxy token.
bool connect(u16 apid)
Set remote APID for later calls to open_request().
Variant of coap::Connection for UDP connections.
CoAP endpoint (i.e., client, server, or combined client+server).
void set_connection(satcat5::coap::Connection *obj)
Set the preferred connection for outgoing requests.
virtual void coap_request(Connection *obj, Reader *msg)
The Child class overrides these event-handlers:
satcat5::coap::Connection * get_idle_connection() const
Get the first idle connection, or null if all are busy.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
virtual void coap_error(Connection *obj)
The Child class overrides these event-handlers:
virtual void coap_ping(const Reader *msg)
The Child class overrides these event-handlers:
Connection * find_token(u32 token) const
Scan connections for a matching proxy-ID.
void set_filter(const satcat5::net::Type &filter)
Set network interface filter.
virtual void coap_response(Connection *obj, Reader *msg)
The Child class overrides these event-handlers:
EndpointSpp variant that forwards all requests to another Endpoint.
void coap_ping(const Reader *msg) override
The Child class overrides these event-handlers:
void coap_request(Connection *obj, Reader *msg) override
The Child class overrides these event-handlers:
void coap_error(Connection *obj) override
The Child class overrides these event-handlers:
void coap_response(Connection *obj, Reader *msg) override
The Child class overrides these event-handlers:
Variant of coap::Endpoint for a CCSDS-SPP client or server.
EndpointSpp(satcat5::ccsds_spp::Dispatch *iface, u16 apid)
Constructor and destructor should only be called by the child.
Variant for a UDP client or server with multiple active connections.
EndpointUdp(satcat5::udp::Dispatch *iface, satcat5::udp::Port req_port=satcat5::udp::PORT_NONE)
Constructor and destructor should only be called by the child.
Connection manager for CoAP endpoints using CCSDS-SPP.
satcat5::coap::ConnectionSpp m_connection
Point-to-point link, only one Connection is required.
ManageSpp(satcat5::coap::Endpoint *coap, u16 apid)
Constructor and destructor should only be called by the child.
Connection manager for CoAP endpoints using UDP.
satcat5::coap::ConnectionUdp * connect(const satcat5::udp::Addr &dstaddr, const satcat5::udp::Port &dstport=satcat5::udp::PORT_COAP, const satcat5::udp::Port &srcport=satcat5::udp::PORT_NONE)
Open a connection to the designated remote UDP endpoint.
ManageUdp(satcat5::coap::Endpoint *coap, satcat5::udp::Port req_port=satcat5::udp::PORT_NONE)
Constructor and destructor should only be called by the child.
satcat5::coap::Endpoint *const m_endpoint
Pointer to the associated Endpoint.
satcat5::udp::Dispatch * udp() const
Pointer to the parent's network interface.
void bind(satcat5::udp::Port req_port=satcat5::udp::PORT_COAP)
Begin accepting incoming requests on the designated UDP port.
Wrapper for coap::ReadOptions that automatically parses options, rejecting any message with unrecogni...
Base-class for parsing CoAP message headers and options.
Message formatting for the Constrained Applications Protocol (CoAP).
unsigned written_len() const
Report total length after write_finalize() is called.
const u8 * buffer() const
Read-only access to the working buffer.
Thin wrapper for ArrayWrite with a built-in buffer.
Limited read of next N bytes.
Abstract API for writing byte-streams and packets.
virtual void write_bytes(unsigned nbytes, const void *src)
Write 0 or more bytes from a buffer.
virtual bool write_finalize()
Mark end of frame and release temporary working data.
The Log class creates and formats one log message.
Log & write(const char *str)
Formatting methods for various data types.
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.
virtual satcat5::io::Writeable * open_reply(const satcat5::net::Type &type, unsigned len)=0
Open a reply to the sender of the most recent message by writing frame header(s) and returning a stre...
void remove(satcat5::net::Protocol *proto)
Unregister a Protocol object.
Dispatcher sorts incoming UDP messages by port index.
T * next(const T *item) const
Fetch pointer to the next item.
Message parsing for the Constrained Applications Protocol (CoAP)
Diagnostic logging to UART and/or Ethernet ports.
IPv4 address is a 32-bit unsigned integer.
UDP and TCP ports are both 16-bit unsigned integers.
u16 value
Raw access to the underlying representation.
Multipurpose filter for matching fields in network packets.