Skip to content

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_options Capacity of the options array.
  • option_count [out] Number of options actually parsed.
  • buf Raw packet buffer.
  • buf_len Length 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:

  • r Request context.
  • server_addr Target server address.
  • msg Request header/token/payload.
  • timeout_ms Initial retransmit timeout (ms).
  • retries Maximum number of retransmissions.

function syn_coap_request_task

Cooperative protothread task to execute a CoAP client request.

SYN_PT_Status syn_coap_request_task (
    SYN_PT * pt,
    SYN_Task * task
) 

Parameters:

  • pt Protothread state.
  • task Scheduler 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:

  • msg Message header to serialize.
  • options Options array (will be sorted by option number).
  • option_count Number of options.
  • buf [out] Destination buffer.
  • max_buf_len Capacity 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