ProsecCoAP 🥂
 
Loading...
Searching...
No Matches
Definitions.h
Go to the documentation of this file.
1
5#ifndef TYPES_H_INCLUDED
6#define TYPES_H_INCLUDED
7
8// Explicitly include Arduino header for IPAddress definition.
9#include <Arduino.h>
10
11// Include Arduino UDP library.
12#include "Udp.h"
13
14// SECTION Constants.
29#ifndef COAP_MAX_MESSAGE_SIZE
52#define COAP_MAX_MESSAGE_SIZE 128U
53#endif
54#ifndef COAP_MAX_CALLBACKS
60#define COAP_MAX_CALLBACKS 10U
61#endif
62#ifndef COAP_MAX_OBSERVERS
66#define COAP_MAX_OBSERVERS 4U
67#endif
68#ifndef COAP_OBSERVER_LEASE_MS
69#define COAP_OBSERVER_LEASE_MS 60000UL
70#endif
71#ifndef COAP_ACK_MIN_TIMEOUT_MS
78#define COAP_ACK_MIN_TIMEOUT_MS 2000UL
79#endif
80#ifndef COAP_ACK_RANDOM_FACTOR
86#define COAP_ACK_RANDOM_FACTOR 1.5f
87#endif
91#define COAP_ACK_MAX_TIMEOUT_MS (unsigned long)(COAP_ACK_MIN_TIMEOUT_MS * COAP_ACK_RANDOM_FACTOR)
92#ifndef COAP_MAX_RETRANSMIT
98#define COAP_MAX_RETRANSMIT 4U
99#endif
100#ifndef COAP_CONFIRMABLE_MESSAGE_QUEUE_SIZE
110#define COAP_CONFIRMABLE_MESSAGE_QUEUE_SIZE 2U
111#endif
112 // End of "Configurable constants" group
113
130constexpr uint8_t COAP_VERSION = 0x01;
134constexpr uint8_t COAP_HEADER_SIZE = 4;
138constexpr uint8_t COAP_PAYLOAD_MARKER = 0xFF;
145constexpr uint16_t COAP_DEFAULT_PORT = 5683;
149constexpr uint8_t COAP_CODE_ENCODE(uint8_t class_, uint8_t detail) { return (class_ << 5) | (detail); }
155constexpr uint8_t COAP_MAX_TOKEN_LENGTH = 8;
156 // End of "Non configurable constants" group
157
158// !SECTION End of all constants.
159
160namespace Coap
161{
162 // SECTION Enums.
169 enum class MessageType : uint8_t
170 {
172 CON = 0,
174 NON = 1,
176 ACK = 2,
178 RST = 3
179 };
180
191 enum class MessageCode : uint8_t
192 {
194 EMPTY = COAP_CODE_ENCODE(0, 0),
195
196 // SECTION 0.xx Request MessageCodes
197 GET = COAP_CODE_ENCODE(0, 1),
198 POST = COAP_CODE_ENCODE(0, 2),
199 PUT = COAP_CODE_ENCODE(0, 3),
200 DELETE = COAP_CODE_ENCODE(0, 4),
201 // !SECTION End of 0.xx Request MessageCodes
202
203 // SECTION 2.xx Success response codes
209 VALID = COAP_CODE_ENCODE(2, 3),
214 // !SECTION End of 2.xx Success response codes
215
216 // SECTION 4.xx Client Error response codes
237 // !SECTION End of 4.xx Client Error response codes
238
239 // SECTION 5.xx Server Error response codes
252 // !SECTION End of 5.xx Server Error response codes
253 };
254
260 enum class OptionNumber : uint16_t
261 {
262 IF_MATCH = 1,
263 URI_HOST = 3,
264 E_TAG = 4,
265 IF_NONE_MATCH = 5,
266 OBSERVE = 6,
267 URI_PORT = 7,
268 LOCATION_PATH = 8,
269 URI_PATH = 11,
270 CONTENT_FORMAT = 12,
271 MAX_AGE = 14,
272 URI_QUERY = 15,
273 ACCEPT = 17,
274 LOCATION_QUERY = 20,
275 PROXY_URI = 35,
276 PROXY_SCHEME = 39,
277 SIZE1 = 60
278 };
279
291 enum class ContentFormat : uint16_t
292 {
293 TEXT_PLAIN = 0,
295 APPLICATION_XML = 41,
297 APPLICATION_EXI = 47,
298 APPLICATION_JSON = 50,
300 };
301
313 enum class ObserveValue : uint8_t
314 {
316 REGISTER = 0,
318 DEREGISTER = 1
319 };
320
326 enum class ErrorCode : int8_t
327 {
329 OK = 0,
331 NOT_FOUND = -1,
341 INVALID_ARGUMENT = -4,
343 NOT_SUPPORTED = -5,
345 NETWORK = -6,
347 UNEXPECTED = -99
348 };
349
350 // !SECTION End of Enums.
351
352 class Message; // Forward declaration.
353
361 typedef void (*Callback)(Message &message, IPAddress ip, uint16_t port);
362}
363
364#endif // TYPES_H_INCLUDED
A CoAP message.
Definition ProsecCoAP.h:164
constexpr uint8_t COAP_VERSION
The CoAP version.
Definition Definitions.h:130
constexpr uint8_t COAP_HEADER_SIZE
The size of the CoAP header in bytes.
Definition Definitions.h:134
constexpr uint8_t COAP_PAYLOAD_MARKER
The payload marker byte.
Definition Definitions.h:138
constexpr uint16_t COAP_DEFAULT_PORT
The default CoAP port number.
Definition Definitions.h:145
constexpr uint8_t COAP_MAX_TOKEN_LENGTH
The maximum length of a CoAP token.
Definition Definitions.h:155
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:149
Namespace for the library.
Definition Definitions.h:161
void(* Callback)(Message &message, IPAddress ip, uint16_t port)
Callback function type for handling incoming messages.
Definition Definitions.h:361
ErrorCode
Error codes used in the library.
Definition Definitions.h:327
MessageType
The CoAP message type.
Definition Definitions.h:170
OptionNumber
Definition Definitions.h:261
MessageCode
The CoAP code.
Definition Definitions.h:192
ContentFormat
The CoAP content format.
Definition Definitions.h:292
ObserveValue
Represents possible Observe option values.
Definition Definitions.h:314
IPAddress ip(192, 168, 0, DEVICE_ID)