ProsecCoAP 🥂
 
Loading...
Searching...
No Matches
Definitions.h
Go to the documentation of this file.
1#ifndef TYPES_H_INCLUDED
2#define TYPES_H_INCLUDED
3
4// Explicitly include Arduino header for IPAddress definition.
5#include <Arduino.h>
6
7// Include Arduino UDP library.
8#include "Udp.h"
9
10// SECTION Constants.
25#ifndef COAP_MAX_MESSAGE_SIZE
46#define COAP_MAX_MESSAGE_SIZE 128U
47#endif
48#ifndef COAP_MAX_CALLBACKS
54#define COAP_MAX_CALLBACKS 10U
55#endif
56#ifndef COAP_MAX_OBSERVERS
60#define COAP_MAX_OBSERVERS 4U
61#endif
62#ifndef COAP_OBSERVER_LEASE_MS
63#define COAP_OBSERVER_LEASE_MS 60000UL
64#endif
65#ifndef COAP_ACK_MIN_TIMEOUT_MS
72#define COAP_ACK_MIN_TIMEOUT_MS 2000UL
73#endif
74#ifndef COAP_ACK_RANDOM_FACTOR
80#define COAP_ACK_RANDOM_FACTOR 1.5f
81#endif
85#define COAP_ACK_MAX_TIMEOUT_MS (unsigned long)(COAP_ACK_MIN_TIMEOUT_MS * COAP_ACK_RANDOM_FACTOR)
86#ifndef COAP_MAX_RETRANSMIT
92#define COAP_MAX_RETRANSMIT 4U
93#endif
94#ifndef COAP_CONFIRMABLE_MESSAGE_QUEUE_SIZE
104#define COAP_CONFIRMABLE_MESSAGE_QUEUE_SIZE 2U
105#endif
106 // End of "Configurable constants" group
107
124constexpr uint8_t COAP_VERSION = 0x01;
128constexpr uint8_t COAP_HEADER_SIZE = 4;
132constexpr uint8_t COAP_PAYLOAD_MARKER = 0xFF;
139constexpr uint16_t COAP_DEFAULT_PORT = 5683;
143constexpr uint8_t COAP_CODE_ENCODE(uint8_t class_, uint8_t detail) { return (class_ << 5) | (detail); }
149constexpr uint8_t COAP_MAX_TOKEN_LENGTH = 8;
150 // End of "Non configurable constants" group
151
152// !SECTION End of all constants.
153
154namespace Coap
155{
156 // SECTION Enums.
163 enum class MessageType : uint8_t
164 {
166 CON = 0,
168 NON = 1,
170 ACK = 2,
172 RST = 3
173 };
174
185 enum class MessageCode : uint8_t
186 {
188 EMPTY = COAP_CODE_ENCODE(0, 0),
189
190 // SECTION 0.xx Request MessageCodes
191 GET = COAP_CODE_ENCODE(0, 1),
192 POST = COAP_CODE_ENCODE(0, 2),
193 PUT = COAP_CODE_ENCODE(0, 3),
194 DELETE = COAP_CODE_ENCODE(0, 4),
195 // !SECTION End of 0.xx Request MessageCodes
196
197 // SECTION 2.xx Success response codes
203 VALID = COAP_CODE_ENCODE(2, 3),
208 // !SECTION End of 2.xx Success response codes
209
210 // SECTION 4.xx Client Error response codes
231 // !SECTION End of 4.xx Client Error response codes
232
233 // SECTION 5.xx Server Error response codes
246 // !SECTION End of 5.xx Server Error response codes
247 };
248
254 enum class OptionNumber : uint16_t
255 {
256 IF_MATCH = 1,
257 URI_HOST = 3,
258 E_TAG = 4,
259 IF_NONE_MATCH = 5,
260 OBSERVE = 6,
261 URI_PORT = 7,
262 LOCATION_PATH = 8,
263 URI_PATH = 11,
264 CONTENT_FORMAT = 12,
265 MAX_AGE = 14,
266 URI_QUERY = 15,
267 ACCEPT = 17,
268 LOCATION_QUERY = 20,
269 PROXY_URI = 35,
270 PROXY_SCHEME = 39,
271 SIZE1 = 60
272 };
273
285 enum class ContentFormat : uint16_t
286 {
287 TEXT_PLAIN = 0,
289 APPLICATION_XML = 41,
291 APPLICATION_EXI = 47,
292 APPLICATION_JSON = 50,
294 };
295
307 enum class ObserveValue : uint8_t
308 {
310 REGISTER = 0,
312 DEREGISTER = 1
313 };
314
320 enum class ErrorCode : int8_t
321 {
323 OK = 0,
325 NOT_FOUND = -1,
335 INVALID_ARGUMENT = -4,
337 NOT_SUPPORTED = -5,
339 NETWORK = -6,
341 UNEXPECTED = -99
342 };
343
344 // !SECTION End of Enums.
345
346 class Message; // Forward declaration.
347
355 typedef void (*Callback)(Message &message, IPAddress ip, uint16_t port);
356}
357
358#endif // TYPES_H_INCLUDED
A CoAP message.
Definition ProsecCoAP.h:161
constexpr uint8_t COAP_VERSION
The CoAP version.
Definition Definitions.h:124
constexpr uint8_t COAP_HEADER_SIZE
The size of the CoAP header in bytes.
Definition Definitions.h:128
constexpr uint8_t COAP_PAYLOAD_MARKER
The payload marker byte.
Definition Definitions.h:132
constexpr uint16_t COAP_DEFAULT_PORT
The default CoAP port number.
Definition Definitions.h:139
constexpr uint8_t COAP_MAX_TOKEN_LENGTH
The maximum length of a CoAP token.
Definition Definitions.h:149
constexpr uint8_t COAP_CODE_ENCODE(uint8_t class_, uint8_t detail)
Helper to encode class and detail into a 8-bit response code as defined in RFC 7252.
Definition Definitions.h:143
Namespace for the library.
Definition Definitions.h:155
void(* Callback)(Message &message, IPAddress ip, uint16_t port)
Callback function type for handling incoming messages.
Definition Definitions.h:355
ErrorCode
Error codes used in the library.
Definition Definitions.h:321
MessageType
The CoAP message type.
Definition Definitions.h:164
OptionNumber
Definition Definitions.h:255
MessageCode
The CoAP code.
Definition Definitions.h:186
ContentFormat
The CoAP content format.
Definition Definitions.h:286
ObserveValue
Represents possible Observe option values.
Definition Definitions.h:308
IPAddress ip(192, 168, 0, DEVICE_ID)