ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
wisun.h File Reference

Wi-SUN FAN border-router connector (PROTOCORE_ENABLE_WISUN). More...

#include "protocore_config.h"
#include "shared/ip/ip.h"

Go to the source code of this file.

Classes

struct  WisunNode
 One FAN mesh node behind the border router. More...
 
struct  WisunFan
 The FAN connector state over a caller-owned node table. More...
 
struct  WisunNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Macros

#define WISUN_COAP_CON   0
 CoAP message type + method codes (RFC 7252) used by the connector.
 
#define WISUN_COAP_NON   1
 Non-confirmable.
 
#define WISUN_COAP_GET   1
 method code 0.01.
 
#define WISUN_COAP_PUT   3
 method code 0.03.
 

Functions

 PROTOCORE_NS_LAYOUT (WisunNs, build_coap, init, node_register, node_find, joined_count, nodes_json)
 
size_t protocore_wisun_build_coap (uint8_t *work, uint8_t type, uint8_t code, uint16_t msg_id, const uint8_t *token, uint8_t tkl, const char *uri_path, const uint8_t *payload, size_t plen, uint8_t *out, size_t cap)
 Build a CoAP client request: header + Uri-Path options (one per / .
 
void protocore_wisun_init (uint8_t *work, WisunFan *fan, const protocore_ip *border_router, WisunNode *storage, size_t cap)
 Initialize the connector over caller storage.
 
int protocore_wisun_node_register (uint8_t *work, WisunFan *fan, const protocore_ip *addr, uint32_t now)
 Register (or refresh) a node by address; sets joined + last_seen.
 
proto_bool protocore_wisun_node_find (uint8_t *work, const WisunFan *fan, const protocore_ip *addr, size_t *idx)
 Find a node by address. idx (may be null) receives the index. found.
 
size_t protocore_wisun_joined_count (uint8_t *work, const WisunFan *fan)
 Number of joined nodes.
 
size_t protocore_wisun_nodes_json (uint8_t *work, const WisunFan *fan, char *out, size_t cap)
 Serialize the node table as [{"addr":"..","joined":bool},...] for .
 

Variables

PROTOCORE_NS WisunNs Wisun PROTOCORE_UNUSED
 Module namespace.
 

Detailed Description

Wi-SUN FAN border-router connector (PROTOCORE_ENABLE_WISUN).

Wi-SUN FAN is an IPv6 / UDP / CoAP mesh, not a byte-level radio the ESP32 drives - the FAN radio is terminated by a border router / devboard and each mesh node is reached as an ordinary IPv6 CoAP endpoint. So the connector rides the existing IP stack: it keeps a table of the FAN nodes (their IPv6 protocore_ip addresses + join state) behind the border router, and builds the CoAP client requests to their resources (the CoAP service ships a server, so the client-request builder is here). The app sends the built PDU to the node's address over protocore_udp; the specific devboard only sets which border router you point at, not this code.

Pure: protocore_wisun_build_coap frames an RFC 7252 request (header + Uri-Path options + payload), the node registry tracks the mesh, and protocore_wisun_nodes_json exposes it to the web. No heap, no stdlib, host-testable.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Definition in file wisun.h.

Macro Definition Documentation

◆ WISUN_COAP_CON

#define WISUN_COAP_CON   0

CoAP message type + method codes (RFC 7252) used by the connector.

Confirmable.

Definition at line 38 of file wisun.h.

◆ WISUN_COAP_NON

#define WISUN_COAP_NON   1

Non-confirmable.

Definition at line 39 of file wisun.h.

◆ WISUN_COAP_GET

#define WISUN_COAP_GET   1

method code 0.01.

Definition at line 40 of file wisun.h.

◆ WISUN_COAP_PUT

#define WISUN_COAP_PUT   3

method code 0.03.

Definition at line 41 of file wisun.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( WisunNs  ,
build_coap  ,
init  ,
node_register  ,
node_find  ,
joined_count  ,
nodes_json   
)

◆ protocore_wisun_build_coap()

size_t protocore_wisun_build_coap ( uint8_t *  work,
uint8_t  type,
uint8_t  code,
uint16_t  msg_id,
const uint8_t *  token,
uint8_t  tkl,
const char *  uri_path,
const uint8_t *  payload,
size_t  plen,
uint8_t *  out,
size_t  cap 
)

Build a CoAP client request: header + Uri-Path options (one per / .

Parameters
workPROTOCORE_WISUN_BORROW bytes the caller took. Not held past the call.
typeWISUN_COAP_CON / WISUN_COAP_NON
codemethod code (WISUN_COAP_GET / WISUN_COAP_PUT)
msg_idthe 16-bit message id (echoed in the ACK)
tokencorrelation token (0..8 bytes; may be null if tkl == 0)
tkltoken length
uri_pathresource path, e.g. "sensors/temp" (leading / optional)
payloadrequest body (may be null if plen == 0)
plenpayload length
outOut
capCap
Returns
The size_t.

◆ protocore_wisun_init()

void protocore_wisun_init ( uint8_t *  work,
WisunFan *  fan,
const protocore_ip *  border_router,
WisunNode *  storage,
size_t  cap 
)

Initialize the connector over caller storage.

Parameters
workPROTOCORE_WISUN_BORROW bytes the caller took. Not held past the call.
fanFan
border_routerBorder router
storageStorage
capCap

◆ protocore_wisun_node_register()

int protocore_wisun_node_register ( uint8_t *  work,
WisunFan *  fan,
const protocore_ip *  addr,
uint32_t  now 
)

Register (or refresh) a node by address; sets joined + last_seen.

Parameters
workPROTOCORE_WISUN_BORROW bytes the caller took. Not held past the call.
fanFan
addrAddr
nowNow
Returns
The int.

◆ protocore_wisun_node_find()

proto_bool protocore_wisun_node_find ( uint8_t *  work,
const WisunFan *  fan,
const protocore_ip *  addr,
size_t *  idx 
)

Find a node by address. idx (may be null) receives the index. found.

Parameters
workPROTOCORE_WISUN_BORROW bytes the caller took. Not held past the call.
fanFan
addrAddr
idxIdx
Returns
PROTO_TRUE on success.

◆ protocore_wisun_joined_count()

size_t protocore_wisun_joined_count ( uint8_t *  work,
const WisunFan *  fan 
)

Number of joined nodes.

Parameters
workPROTOCORE_WISUN_BORROW bytes the caller took. Not held past the call.
fanFan
Returns
The size_t.

◆ protocore_wisun_nodes_json()

size_t protocore_wisun_nodes_json ( uint8_t *  work,
const WisunFan *  fan,
char *  out,
size_t  cap 
)

Serialize the node table as [{"addr":"..","joined":bool},...] for .

Parameters
workPROTOCORE_WISUN_BORROW bytes the caller took. Not held past the call.
fanFan
outOut
capCap
Returns
The size_t.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS WisunNs Wisun PROTOCORE_UNUSED
Initial value:
= {.build_coap = protocore_wisun_build_coap,
proto_bool protocore_wisun_node_find(uint8_t *work, const WisunFan *fan, const protocore_ip *addr, size_t *idx)
Find a node by address. idx (may be null) receives the index. found.
void protocore_wisun_init(uint8_t *work, WisunFan *fan, const protocore_ip *border_router, WisunNode *storage, size_t cap)
Initialize the connector over caller storage.
int protocore_wisun_node_register(uint8_t *work, WisunFan *fan, const protocore_ip *addr, uint32_t now)
Register (or refresh) a node by address; sets joined + last_seen.
size_t protocore_wisun_joined_count(uint8_t *work, const WisunFan *fan)
Number of joined nodes.
size_t protocore_wisun_nodes_json(uint8_t *work, const WisunFan *fan, char *out, size_t cap)
Serialize the node table as [{"addr":"..","joined":bool},...] for .
size_t protocore_wisun_build_coap(uint8_t *work, uint8_t type, uint8_t code, uint16_t msg_id, const uint8_t *token, uint8_t tkl, const char *uri_path, const uint8_t *payload, size_t plen, uint8_t *out, size_t cap)
Build a CoAP client request: header + Uri-Path options (one per / .

Module namespace.

Definition at line 139 of file wisun.h.