File syn_coap.c¶
FileList > net > syn_coap.c
Go to the source code of this file
CoAP message serialization, parsing, and cooperative client task implementation.
#include "../port/syn_port_system.h"#include "../util/syn_assert.h"#include "../util/syn_pack.h"#include "syn_coap.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_coap_parse (SYN_CoapMsg * msg, SYN_CoapOption * options, size_t max_options, size_t * option_count, const uint8_t * buf, size_t buf_len) Parse a raw CoAP packet into a message structure. |
| void | syn_coap_request_init (SYN_CoapRequest * r, const SYN_SockAddr * server_addr, const SYN_CoapMsg * msg, uint32_t timeout_ms, uint8_t retries) Initialize a CoAP request context. |
| SYN_PT_Status | syn_coap_request_task (SYN_PT * pt, SYN_Task * task) Cooperative protothread task to execute a CoAP client request. |
| size_t | syn_coap_serialize (const SYN_CoapMsg * msg, const SYN_CoapOption * options, size_t option_count, uint8_t * buf, size_t max_buf_len) Serialize a CoAP message into a byte buffer. |
Public Functions Documentation¶
function syn_coap_parse¶
Parse a raw CoAP packet into a message structure.
SYN_Status syn_coap_parse (
SYN_CoapMsg * msg,
SYN_CoapOption * options,
size_t max_options,
size_t * option_count,
const uint8_t * buf,
size_t buf_len
)
Parameters:
msg[out] Parsed message header.options[out] Array to receive parsed options.max_optionsCapacity of the options array.option_count[out] Number of options actually parsed.bufRaw packet buffer.buf_lenLength of the raw packet in bytes.
Returns:
SYN_OK on success, SYN_ERROR on malformed input.
function syn_coap_request_init¶
Initialize a CoAP request context.
void syn_coap_request_init (
SYN_CoapRequest * r,
const SYN_SockAddr * server_addr,
const SYN_CoapMsg * msg,
uint32_t timeout_ms,
uint8_t retries
)
Parameters:
rRequest context.server_addrTarget server address.msgRequest header/token/payload.timeout_msInitial retransmit timeout (ms).retriesMaximum number of retransmissions.
function syn_coap_request_task¶
Cooperative protothread task to execute a CoAP client request.
Parameters:
ptProtothread state.taskScheduler task (user_data must point to a SYN_CoapRequest).
Returns:
Protothread status.
function syn_coap_serialize¶
Serialize a CoAP message into a byte buffer.
size_t syn_coap_serialize (
const SYN_CoapMsg * msg,
const SYN_CoapOption * options,
size_t option_count,
uint8_t * buf,
size_t max_buf_len
)
Parameters:
msgMessage header to serialize.optionsOptions array (will be sorted by option number).option_countNumber of options.buf[out] Destination buffer.max_buf_lenCapacity of the destination buffer.
Returns:
Number of bytes written, or 0 on error (buffer too small).
The documentation for this class was generated from the following file src/syntropic/net/syn_coap.c