SatCat5
coap_client.h
1 // Copyright 2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Simplified CoAP client implementation.
6 
7 #pragma once
8 #include <satcat5/coap_endpoint.h>
9 #include <satcat5/pkt_buffer.h>
10 
11 namespace satcat5 {
12  namespace coap {
18  public:
20  inline u16 msg_id() const
21  { return m_msg_id; }
22 
25  { m_rcvd.set_callback(obj); }
26 
30  bool request(satcat5::coap::Code code,
31  const char* uri, const char* data,
32  u16 fmt = satcat5::coap::FORMAT_TEXT);
33  bool request(satcat5::coap::Code code,
34  const char* uri, satcat5::io::Readable* data = 0,
35  u16 fmt = satcat5::coap::FORMAT_BYTES);
36  bool request(satcat5::coap::Code code,
37  const char* uri, satcat5::cbor::CborWriter& cbor);
39 
42 
45 
47  bool response_discard();
48 
49  protected:
53 
55  void coap_response(
57  satcat5::coap::Reader* msg) override;
58 
59  // Other internal variables.
61  u16 m_msg_id;
62  };
63 
67  , public satcat5::coap::ManageSpp {
68  public:
70  };
71 
75  , public satcat5::coap::ManageUdp {
76  public:
78 
79  protected:
80  satcat5::coap::ConnectionUdp m_connection;
81  };
82  }
83 };
Creates an ephemeral writer for the Concise Binary Object Representation (CBOR, IETF RFC8949),...
Definition: io_cbor.h:91
Implemention of "net::Dispatch" API for CCSDS-SPP packets.
Definition: ccsds_spp.h:199
CoAP request/response handling for a single client-server connection.
Variant of coap::Connection for UDP connections.
CoAP endpoint (i.e., client, server, or combined client+server).
Definition: coap_endpoint.h:41
satcat5::net::Dispatch * iface() const
Fetch the associated network interface.
Definition: coap_endpoint.h:44
Connection manager for CoAP endpoints using CCSDS-SPP.
Connection manager for CoAP endpoints using UDP.
Base-class for parsing CoAP message headers and options.
Definition: coap_reader.h:162
Simplified CoAP client that writes responses to a PacketBuffer.
Definition: coap_client.h:17
satcat5::io::Readable * response_data()
Read the contents of the next CoAP response.
Definition: coap_client.cc:68
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.
Definition: coap_client.cc:45
void set_callback(satcat5::io::EventListener *obj)
Request notifications for incoming responses.
Definition: coap_client.h:24
SimpleClient(satcat5::net::Dispatch *iface)
Constructor attaches to a network interface.
Definition: coap_client.cc:14
bool response_discard()
Discard the contents of the next CoAP response.
Definition: coap_client.cc:74
u16 msg_id() const
Message-ID and token for the most recent request.
Definition: coap_client.h:20
satcat5::io::Readable * response_all()
Read full header and contents of the next CoAP response.
Definition: coap_client.cc:63
void coap_response(satcat5::coap::Connection *obj, satcat5::coap::Reader *msg) override
Save the incoming response message.
Definition: coap_client.cc:80
Variant of SimpleClient using a single outgoing SPP connection.
Definition: coap_client.h:67
Variant of SimpleClient using a single outgoing UDP connection.
Definition: coap_client.h:75
Event-handler interface for newly received data.
Definition: io_readable.h:43
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
Definition: io_readable.cc:39
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
CoAP message header CODE field (Section 12.1).