6 #include <satcat5/coap_client.h>
8 #include <satcat5/coap_writer.h>
10 #include <satcat5/udp_dispatch.h>
26 if (!m_prefer)
return false;
34 if (!wr.
ready())
return false;
35 wr.
write_header(satcat5::coap::TYPE_CON, code, m_msg_id, m_msg_id);
46 const char* uri,
const char* data, u16 fmt)
49 return request(code, uri, &rd, fmt);
55 #if SATCAT5_CBOR_ENABLE
95 satcat5::coap::SimpleClientSpp::SimpleClientSpp(
104 satcat5::coap::SimpleClientUdp::SimpleClientUdp(
108 , m_connection(this, iface)
Creates an ephemeral writer for the Concise Binary Object Representation (CBOR, IETF RFC8949),...
satcat5::io::Readable * get_buffer()
Get encoded data as a Readable, useful if no dst was given.
Implemention of "net::Dispatch" API for CCSDS-SPP packets.
CoAP request/response handling for a single client-server connection.
satcat5::io::Writeable * open_request()
If able, send a request to the current remote server.
CoAP endpoint (i.e., client, server, or combined client+server).
void set_connection(satcat5::coap::Connection *obj)
Set the preferred connection for outgoing requests.
Connection manager for CoAP endpoints using CCSDS-SPP.
Wrapper for coap::ReadOptions that automatically parses options, rejecting any message with unrecogni...
Base-class for parsing CoAP message headers and options.
satcat5::util::optional< u16 > format() const
Accessors for parsed options.
Simplified CoAP client that writes responses to a PacketBuffer.
satcat5::io::Readable * response_data()
Read the contents of the next CoAP response.
bool request(satcat5::coap::Code code, const char *uri, const char *data, u16 fmt=satcat5::coap::FORMAT_TEXT)
Create and send a CoAP request, with optional data.
bool response_discard()
Discard the contents of the next CoAP response.
satcat5::io::Readable * response_all()
Read full header and contents of the next CoAP response.
void coap_response(satcat5::coap::Connection *obj, satcat5::coap::Reader *msg) override
Save the incoming response message.
Message formatting for the Constrained Applications Protocol (CoAP).
bool write_uri(u16 id, const char *str)
Convert a URI to consecutive Uri-Path options.
bool ready() const
Is this object ready for writing? Note: This is the only safe method if m_dst is null.
bool write_finalize()
After the last option, finish with an empty message.
bool write_option(u16 id, unsigned len, const void *data)
Write option(s) one at a time, in various formats.
satcat5::io::Writeable * write_data()
After the last option, start writing message data.
bool write_header(u8 type, Code code, u16 msg_id, u64 token=0, u8 tkl=0)
Always start by writing the header, with optional token.
Ephemeral Readable interface for a simple array.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
void write_abort() override
If possible, abort the current partially-written packet.
void read_finalize() override
Consume any remaining bytes in this frame, if applicable.
Abstract API for reading byte-streams and packets.
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
unsigned copy_to(satcat5::io::Writeable *dst)
Copy data to a Writeable object, without finalizing.
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Dispatcher sorts incoming UDP messages by port index.
constexpr u16 FORMAT_CBOR
application/cbor (RFC8949)
constexpr u16 OPTION_URI_PATH
Option: Uri-Path.
constexpr u16 OPTION_FORMAT
Option: Content-Format.
Message parsing for the Constrained Applications Protocol (CoAP)
CBOR (IETF RFC8949) Readable/Writeable interface.
CoAP message header CODE field (Section 12.1).
T value() const
Fetch the inner value.