11 #include <satcat5/udp_core.h>
15 #ifndef SATCAT5_COAP_BUFFSIZE
16 #define SATCAT5_COAP_BUFFSIZE 1152
22 #ifndef SATCAT5_COAP_HISTORY
23 #define SATCAT5_COAP_HISTORY 4
68 {
return m_state == State::IDLE && m_allow_reuse; }
75 {
return m_state == State::WAIT_RESPONSE_U
76 || m_state == State::WAIT_RESPONSE_M
77 || m_state == State::RESPONSE_SEP1;}
79 {
return m_state == State::CONNECT_IDLE
80 || m_state == State::CONNECT_BUSY; }
82 {
return m_state == State::REQUEST_CON
83 || m_state == State::REQUEST_NON
84 || m_state == State::REQUEST_SEP; }
86 {
return m_state == State::RESPONSE_CACHE
87 || m_state == State::RESPONSE_DEFER
88 || m_state == State::RESPONSE_SEP1
89 || m_state == State::RESPONSE_SEP2; }
91 {
return m_state == State::RESPONSE_SEP1
92 || m_state == State::RESPONSE_SEP2; }
94 {
return m_msgid[m_meta_idx]; }
96 {
return m_token[m_meta_idx]; }
98 {
return m_flags[m_meta_idx] & 0x0F; }
116 {
return m_proxy_token; }
123 { m_proxy_token =
token; }
180 bool deliver(satcat5::coap::
Reader* msg);
181 void frame_rcvd(satcat5::io::LimitedRead& src) override;
186 bool connected(
bool allow_reuse);
188 int match_history(const satcat5::coap::
ReadHeader* msg) const;
189 void push_history(const satcat5::coap::
ReadHeader* msg);
193 bool send_empty(u8 typ, u16
id);
195 void timer_rand(u32 base_msec);
220 u8 m_flags[SATCAT5_COAP_HISTORY];
221 u16 m_msgid[SATCAT5_COAP_HISTORY];
222 u64 m_token[SATCAT5_COAP_HISTORY];
272 bool allow_reuse =
false);
284 template <
unsigned SIZE>
293 for (
unsigned a = 0 ; a < SIZE ; ++a) {
294 m_array[a].
init(endpoint, iface);
300 {
return m_array[idx]; }
CCSDS Space Packet Protocol.
Implemention of "net::Address" API for CCSDS-SPP packets.
Implemention of "net::Dispatch" API for CCSDS-SPP packets.
CoAP request/response handling for a single client-server connection.
bool is_separate() const
< Awaiting separate response?
bool is_match_reuse() const
Idle or continue same connection.
bool write_finalize() override
Mark end of frame and release temporary working data.
bool open_separate(const satcat5::coap::ReadHeader *msg)
If able, send the first half of a separated response.
bool is_connecting() const
< Connection in progress?
u8 tkl() const
< Most recent token length
bool is_match_addr() const
< Match reply endpoint?
u64 token() const
< Most recent message token
bool ready() const
Ready to send a request?
satcat5::io::Writeable * open_response_auto()
Automatically call open_response() or continue_separate().
u8 response_type() const
Determine the expected response type for an incoming request.
bool is_request() const
< Any request state?
void timer_event() override
Child class MUST override this method.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
satcat5::io::Writeable * continue_separate()
If able, send the second half of a separated response.
bool is_response() const
< Any response state?
bool test_inject(unsigned len, const void *data)
Test only: Send a message using the active connection.
bool ping(u16 msg_id)
If able, send a ping request to the remote client.
u16 msg_id() const
< Most recent message ID
bool is_idle() const
< Idle and ready for use?
bool error_response(satcat5::coap::Code code, const char *why=0)
If able, return an error in response to an incoming request from a remote client.
satcat5::io::Writeable * open_response()
If able, accept an incoming request from a remote client.
bool is_match_coap(const satcat5::coap::ReadHeader *msg) const
Connection(satcat5::coap::Endpoint *endpoint, satcat5::net::Address *addr)
Constructor is only accessible to child classes.
bool is_await() const
< Awaiting initial response?
satcat5::io::Writeable * open_request()
If able, send a request to the current remote server.
void set_proxy_token(u32 token)
Set identifier for matching incoming proxy responses.
u32 get_proxy_token() const
Query the most recent proxy token.
void init(satcat5::coap::Endpoint *endpoint)
Deferred initialization of the upstream interface.
void close()
Close any open connections and reset state.
Variant of coap::Connection for CCSDS-SPP connections.
satcat5::ccsds_spp::Address m_spp
Connection to a specific APID.
bool connect(u16 apid)
Set remote APID for later calls to open_request().
ConnectionSpp(satcat5::coap::Endpoint *endpoint, satcat5::ccsds_spp::Dispatch *iface)
Create cache object and link it to the designated endpoint.
Statically-allocated array of ConnectionUdp objects.
ConnectionUdpArray(satcat5::coap::Endpoint *endpoint, satcat5::udp::Dispatch *iface)
Link each ConnectionUdp object to the specified interfaces.
ConnectionUdp & operator[](unsigned idx)
Access an internal connection object by index.
Variant of coap::Connection for UDP connections.
void init(satcat5::coap::Endpoint *endpoint, satcat5::udp::Dispatch *iface)
Deferred initialization of the upstream interface.
bool connect(const satcat5::udp::Addr &dstaddr, const satcat5::udp::Port &dstport=satcat5::udp::PORT_COAP, const satcat5::udp::Port &srcport=satcat5::udp::PORT_NONE, bool allow_reuse=false)
Set remote endpoint for later calls to open_request().
ConnectionUdp(satcat5::coap::Endpoint *endpoint, satcat5::udp::Dispatch *iface)
Create cache object and link it to the designated endpoint.
ConnectionUdp()
Default constructor must subsequently call init().
satcat5::udp::Address m_udp
Connection to a specific IP address and UDP port.
CoAP endpoint (i.e., client, server, or combined client+server).
Base-class for parsing CoAP message headers and options.
Thin wrapper for ArrayWrite with a built-in buffer.
Abstract API for writing byte-streams and packets.
Defines a generic API for sending data to a specific destination, such as a MAC address,...
virtual bool matches_reply_address() const =0
Does this Address object match the parent interface's current reply address? Multicast destinations s...
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Timer objects are polled after a fixed delay or at a regular interval.
Implementation of "net::Address" for UDP Dispatch.
Dispatcher sorts incoming UDP messages by port index.
Helper functions for manipulating singly-linked lists.
Constants relating to the Constrained Applications Protocol (CoAP)
CoAP message header CODE field (Section 12.1).
IPv4 address is a 32-bit unsigned integer.
UDP and TCP ports are both 16-bit unsigned integers.