OpenThread_app
Loading...
Searching...
No Matches
main API for OpenThread hardware application

Main API for OpenThread hardware application device driver. More...

Classes

struct  ot_app_drv_nvs_t
 NVS Non-Volatile Storage functions. More...
struct  ot_app_drv_pair_t
struct  ot_app_drv_devName_t
struct  ot_app_drv_coap_t
struct  ot_app_devDrvAPI_t
struct  ot_app_devDrv_t

Typedefs

typedef struct ot_app_drv_nvs_t ot_app_drv_nvs_t
 NVS Non-Volatile Storage functions.
typedef struct ot_app_drv_pair_t ot_app_drv_pair_t
typedef struct ot_app_drv_devName_t ot_app_drv_devName_t
typedef struct ot_app_drv_coap_t ot_app_drv_coap_t
typedef struct ot_app_devDrvAPI_t ot_app_devDrvAPI_t
typedef uint8_t ot_app_size_t
typedef otapp_pair_rule_t *(* pairRuleGet_callback_t) (void)
typedef otapp_coap_uri_t *(* uriGet_callback_t) (void)
typedef void(* subscribedUris_callback_t) (oac_uri_dataPacket_t *dataPacket)
typedef void(* mainTask_callback_t) (void)
typedef struct ot_app_devDrv_t ot_app_devDrv_t

Functions

ot_app_devDrv_tot_app_drv_getInstance (void)
void ot_app_drv_task (void)

Variables

int8_t(* ot_app_drv_nvs_t::saveString )(const char *inData, const uint8_t keyId)
 save data into NVS partition
int8_t(* ot_app_drv_nvs_t::readString )(char *outBuff, uint8_t outBuffSize, const uint8_t keyId)
 read data from NVS partition
int8_t(* ot_app_drv_nvs_t::init )(void)
 NVS init function.
otapp_pair_DeviceList_t *(* ot_app_drv_pair_t::getHandle )(void)
 get ptr of otapp_pair_DeviceList_t handle
int8_t(* ot_app_drv_pair_t::uriStateSet )(otapp_pair_DeviceList_t *pairDeviceList, const oacu_token_t *token, const uint32_t *uriState)
 set uri state on the pair device list. Max data per uri = uint32_t
int8_t(* ot_app_drv_pair_t::uriGetIdList )(otapp_pair_Device_t *deviceHandle, otapp_deviceType_t uriDevType)
 looking for ID of urisList in urisList
int8_t(* ot_app_drv_devName_t::devNameFullToEUI )(const char *deviceNameFull, uint8_t stringLength, char **outEuiChrPtr)
 decode EUI from deviceNameFull
int8_t(* ot_app_drv_devName_t::devNameEuiIsSame )(const char *deviceNameFull, const char *eui)
 compare EUI from deviceNameFull with given EUI
void(* ot_app_drv_coap_t::sendBytePut )(const otIp6Address *peer_addr, const char *aUriPath, const uint8_t *payloadMsg, const uint16_t payloadMsgSize, otCoapResponseHandler responseHandler, void *aContext)
 send coap message bytes using the PUT method
void(* ot_app_drv_coap_t::sendByteGet )(const otIp6Address *peer_addr, const char *aUriPath, otCoapResponseHandler responseHandler, void *aContext)
 send coap request using the GET method. Response will contain bytes
void(* ot_app_drv_coap_t::sendResponse )(otMessage *requestMessage, const otMessageInfo *aMessageInfo, const uint8_t *responceContent, uint16_t responceLength)
 send coap response to device
int8_t(* ot_app_drv_coap_t::readPayload )(otMessage *aMessage, uint8_t *bufferOut, uint16_t bufferSize, uint16_t *readBytesOut)
 read incoming message and save them to in buffer
int8_t(* ot_app_drv_coap_t::processUriRequest )(otMessage *aMessage, const otMessageInfo *aMessageInfo, oacu_uriIndex_t uriId, uint8_t *bufOut, uint16_t bufSize)
 main function for HARDWARE DEVICE URIS. This function processing incoming request. Request can be concern adding device to subscribe list or general uri request to next processing. If it is general uri request, then the given bufOut contains data to processing.
ot_app_drv_pair_t ot_app_devDrvAPI_t::pair
ot_app_drv_devName_t ot_app_devDrvAPI_t::devName
ot_app_drv_nvs_t ot_app_devDrvAPI_t::nvs
ot_app_drv_coap_t ot_app_devDrvAPI_t::coap
subscribedUris_callback_t ot_app_devDrv_t::obs_subscribedUri_clb
otapp_pair_observerCallback_t ot_app_devDrv_t::obs_pairedDevice_clb
 it will be called when new device has been properly paired. All data are saved in otapp_pair_DeviceList_t.
pairRuleGet_callback_t ot_app_devDrv_t::pairRuleGetList_clb
 Callback function to retrieve the list of pairing rules. *.
uriGet_callback_t ot_app_devDrv_t::uriGetList_clb
 Callback function to retrieve the list of URIs.
char * ot_app_devDrv_t::deviceName
 Device name group identifier for network pairing.
const otapp_deviceType_tot_app_devDrv_t::deviceType
 Pointer to the device type identifier.
ot_app_size_t ot_app_devDrv_t::uriGetListSize
 Number of URIs in the URI list.
mainTask_callback_t ot_app_devDrv_t::task
 Main task callback for periodic device processing.
ot_app_devDrvAPI_t ot_app_devDrv_t::api
 Application device driver API structure.

Detailed Description

Main API for OpenThread hardware application device driver.

Description

Main API for OpenThread hardware application device driver.

Provides unified interface for managing hardware devices in Thread networks:

  • Device Pairing through filtering rules and observer callbacks
  • URI/CoAP Handling for remote resource control
  • Device Grouping via name groups (deviceName)
  • Persistent Storage using NVS subsystem
  • IPv6/CoAP Network Communication with other Thread devices

Key Features:

Example Initialization:

// CRITICAL: Initialize NVS FIRST before any other operations
// **MUST call NVS init before otapp_init():**
if(drv->api.nvs.init == NULL) return; // Safety check
drv->api.nvs.init(); // Required before other operations
// Register device callbacks and properties
drv->pairRuleGetList_clb = myPairRulesCallback;
drv->uriGetList_clb = myUriListCallback;
drv->obs_pairedDevice_clb = myPairedCallback;
drv->obs_subscribedUri_clb = mySubscribedCallback;
drv->deviceName = myDeviceNameGroup;
drv->deviceType = &myDeviceType;
drv->task = myMainTask;
drv->uriGetListSize = myUriCount;
ot_app_devDrv_t * ot_app_drv_getInstance(void)
Definition ot_app_drv.c:73
#define NULL
Definition hro_utils.h:73
Definition ot_app_drv.h:242

Pairing Requirements:

  • Devices must share the same deviceName group
  • Target device must match pairRuleGetList_clb rules

Framework automatically calls registered callbacks during:

  • New device discovery (obs_pairedDevice_clb)
  • URI state updates (obs_subscribedUri_clb)
See also
ot_app_devDrv_t for complete driver structure
ot_app_drv_getInstance() for singleton access
ad_button_Init() for full example implementation
Version
0.1
Date
08-09-2025
Author
Jan Łukaszewicz (plhar.nosp@m.eo@g.nosp@m.mail..nosp@m.com)

Typedef Documentation

◆ mainTask_callback_t

typedef void(* mainTask_callback_t) (void)

◆ ot_app_devDrv_t

typedef struct ot_app_devDrv_t ot_app_devDrv_t

◆ ot_app_devDrvAPI_t

typedef struct ot_app_devDrvAPI_t ot_app_devDrvAPI_t

◆ ot_app_drv_coap_t

typedef struct ot_app_drv_coap_t ot_app_drv_coap_t

◆ ot_app_drv_devName_t

typedef struct ot_app_drv_devName_t ot_app_drv_devName_t

◆ ot_app_drv_nvs_t

typedef struct ot_app_drv_nvs_t ot_app_drv_nvs_t

NVS Non-Volatile Storage functions.

◆ ot_app_drv_pair_t

typedef struct ot_app_drv_pair_t ot_app_drv_pair_t

◆ ot_app_size_t

typedef uint8_t ot_app_size_t

◆ pairRuleGet_callback_t

typedef otapp_pair_rule_t *(* pairRuleGet_callback_t) (void)

◆ subscribedUris_callback_t

typedef void(* subscribedUris_callback_t) (oac_uri_dataPacket_t *dataPacket)

◆ uriGet_callback_t

typedef otapp_coap_uri_t *(* uriGet_callback_t) (void)

Function Documentation

◆ ot_app_drv_getInstance()

ot_app_devDrv_t * ot_app_drv_getInstance ( void )

◆ ot_app_drv_task()

void ot_app_drv_task ( void )

Variable Documentation

◆ api

ot_app_devDrvAPI_t ot_app_devDrv_t::api

Application device driver API structure.

This structure contains function pointers that define the full API for interacting with the OpenThread device driver. It provides organized access to key subsystems:

  • Pairing API (api.pair)
  • Device Name API (api.devName)
  • Non-Volatile Storage API (api.nvs)
  • CoAP API (api.coap)

This centralized API structure aids modular and flexible device driver design, allowing easy interaction with all key OpenThread application features.

Internal callbacks such as obs_pairedDevice_clb, obs_subscribedUri_clb, and pairing rules callback pairRuleGetList_clb are maintained here alongside device properties (deviceName, deviceType), URI management, and main task pointer.

The instance is statically allocated and accessed via ot_app_drv_getInstance().

Note
Functions must be properly initialized to avoid NULL pointer dereferences.
This API encapsulates both synchronous and asynchronous device behaviors.
See also
ot_app_drv_getInstance() for singleton access.

◆ coap

ot_app_drv_coap_t ot_app_devDrvAPI_t::coap

◆ deviceName

char* ot_app_devDrv_t::deviceName

Device name group identifier for network pairing.

Pointer to the device name group string used for network pairing.

This string identifies the device on the OpenThread network and filters pairing – only devices with a matching name group can pair together.

Enables logical grouping of devices (e.g., by room or function).

Buffer Properties:

  • Size: OTAPP_DEVICENAME_SIZE (10 bytes)
  • Maximum string length: 9 characters + null terminator

The buffer for this pointer is allocated and initialized by the application. In the reference implementation, it is set in the ad_button_Init() function, which copies the provided group name into an internal static buffer and assigns its address to this field (example initialization).

Note
Content should be set once during initialization.
Length must not exceed OTAPP_DEVICENAME_SIZE - 1 characters.
See also
ad_button_Init() for example initialization.
OTAPP_DEVICENAME_SIZE for buffer size definition.

◆ deviceType

const otapp_deviceType_t* ot_app_devDrv_t::deviceType

Pointer to the device type identifier.

Points to a constant device type identifier used to classify the device. This type typically indicates the device category or role within the OpenThread network, such as switch, light, sensor, etc.

The device type helps the pairing rules and other network management logic determine the kind of device and apply appropriate filters or actions.

The pointer refers to a static, application-defined constant, for example, OTAPP_SWITCH for a button or switch device.

The type otapp_deviceType_t represents the full supported list of device types recognized by the framework, allowing classification across all supported device categories.

Note
The pointed-to data should remain constant and valid for the entire lifetime of the device.
See also
OTAPP_SWITCH device type example in reference implementation.
otapp_deviceType_t for full supported list of device types.

◆ devName

ot_app_drv_devName_t ot_app_devDrvAPI_t::devName

◆ devNameEuiIsSame

int8_t(* ot_app_drv_devName_t::devNameEuiIsSame) (const char *deviceNameFull, const char *eui)

compare EUI from deviceNameFull with given EUI

Parameters
deviceNameFull[in] string ptr to device name full
eui[in] ptr to EUI
Returns
int8_t [out] OTAPP_DEVICENAME_IS OTAPP_DEVICENAME_IS_NOT OTAPP_DEVICENAME_ERROR

◆ devNameFullToEUI

int8_t(* ot_app_drv_devName_t::devNameFullToEUI) (const char *deviceNameFull, uint8_t stringLength, char **outEuiChrPtr)

decode EUI from deviceNameFull

Parameters
deviceNameFull[in] string ptr to device name full
stringLength[in] string lenght
outEuiChrPtr[out] ptr to EUI from string. It looks for EUI string from deviceNameFull and return ptr to first element of EUI string.
Returns
int8_t [out] OTAPP_DEVICENAME_OK or OTAPP_DEVICENAME_ERROR

◆ getHandle

otapp_pair_DeviceList_t *(* ot_app_drv_pair_t::getHandle) (void)

get ptr of otapp_pair_DeviceList_t handle

Returns
otapp_pair_DeviceList_t* [out] ptr of otapp_pair_DeviceList_t handle

◆ init

int8_t(* ot_app_drv_nvs_t::init) (void)

NVS init function.

Warning
it has to be inicjalized befor otapp_init() and first using.

◆ nvs

ot_app_drv_nvs_t ot_app_devDrvAPI_t::nvs

◆ obs_pairedDevice_clb

otapp_pair_observerCallback_t ot_app_devDrv_t::obs_pairedDevice_clb

it will be called when new device has been properly paired. All data are saved in otapp_pair_DeviceList_t.

Parameters
[out]newDeviceptr to data struct otapp_pair_Device_t

◆ obs_subscribedUri_clb

subscribedUris_callback_t ot_app_devDrv_t::obs_subscribedUri_clb

◆ pair

ot_app_drv_pair_t ot_app_devDrvAPI_t::pair

◆ pairRuleGetList_clb

pairRuleGet_callback_t ot_app_devDrv_t::pairRuleGetList_clb

Callback function to retrieve the list of pairing rules. *.

This callback is used by the OpenThread device driver to obtain the current set of pairing rules that determine which devices are allowed to pair.

When invoked, the callback returns a pointer to an array of pairing rules (otapp_pair_rule_t) specifying device types allowed or disallowed for pairing.

The application should assign this callback to provide dynamic or static pairing rules depending on the system's pairing policy.

Configuration:

  • OTAPP_PAIR_NO_RULES: Special flag indicating no filtering
  • OTAPP_PAIR_NO_ALLOWED: Special flag blocking all pairing attempts
  • OTAPP_PAIR_END_OF_RULES: Terminator for rule array
Note
OTAPP_PAIR_RULES_ALLOWED_SIZE = 10 (maximum rules per set)
Returns
Pointer to the pairing rule list (array of otapp_pair_rule_t).

◆ processUriRequest

int8_t(* ot_app_drv_coap_t::processUriRequest) (otMessage *aMessage, const otMessageInfo *aMessageInfo, oacu_uriIndex_t uriId, uint8_t *bufOut, uint16_t bufSize)

main function for HARDWARE DEVICE URIS. This function processing incoming request. Request can be concern adding device to subscribe list or general uri request to next processing. If it is general uri request, then the given bufOut contains data to processing.

Parameters
aMessage[in] ptr to incoming message
aMessageInfo[in] ptr to message info
uriId[in] specific HARDWARE DEVICE URI ID that was passed in uriGetListSize callback
bufOut[out] ptr to buffer. Incomming data will be saved there.
bufSize[in] size of bufOut
Returns
int8_t [out] OTAPP_COAP_OK when same data was saved in buffer, OAC_URI_OBS_ADDED_NEW_DEVICE or OAC_URI_OBS_NO_NEED_UPDATE when observer function processed, OTAPP_COAP_ERROR

◆ readPayload

int8_t(* ot_app_drv_coap_t::readPayload) (otMessage *aMessage, uint8_t *bufferOut, uint16_t bufferSize, uint16_t *readBytesOut)

read incoming message and save them to in buffer

Parameters
aMessage[in] ptr to incoming message
bufferOut[out] ptr to out buffer
bufferSize[in] size of bufferOut
readBytesOut[out] ptr to the uint16_t variable, where the size of the read bytes will be saved
Returns
int8_t [out] OTAPP_COAP_OK or OTAPP_COAP_ERROR

◆ readString

int8_t(* ot_app_drv_nvs_t::readString) (char *outBuff, uint8_t outBuffSize, const uint8_t keyId)

read data from NVS partition

Parameters
outData[out] ptr to data
outDataSize[out] ptr to the size of the data that was read
keyId[in] it is id for saved data. It will be necessary for update or read data
Returns
int8_t OT_APP_NVS_ERROR or OT_APP_NVS_OK

◆ saveString

int8_t(* ot_app_drv_nvs_t::saveString) (const char *inData, const uint8_t keyId)

save data into NVS partition

Parameters
inData[in] ptr to data
keyId[in] it is id for saved data. It will be necessary for update or read data
Returns
int8_t OT_APP_NVS_ERROR or OT_APP_NVS_OK

◆ sendByteGet

void(* ot_app_drv_coap_t::sendByteGet) (const otIp6Address *peer_addr, const char *aUriPath, otCoapResponseHandler responseHandler, void *aContext)

send coap request using the GET method. Response will contain bytes

Parameters
peer_addr[in] ptr to device IPv6 address
aUriPath[in] string ptr to uri
responseHandler[in] callback to response handler
aContext[in] content will be provided with responseHandler

◆ sendBytePut

void(* ot_app_drv_coap_t::sendBytePut) (const otIp6Address *peer_addr, const char *aUriPath, const uint8_t *payloadMsg, const uint16_t payloadMsgSize, otCoapResponseHandler responseHandler, void *aContext)

send coap message bytes using the PUT method

Parameters
peer_addr[in] ptr to device IPv6 address
aUriPath[in] string ptr to uri
payloadMsg[in] ptr to payload data
payloadMsgSize[in] payload size
responseHandler[in] callback to response handler
aContext[in] content will be provided with responseHandler

◆ sendResponse

void(* ot_app_drv_coap_t::sendResponse) (otMessage *requestMessage, const otMessageInfo *aMessageInfo, const uint8_t *responceContent, uint16_t responceLength)

send coap response to device

Parameters
requestMessage[in] ptr to request message
aMessageInfo[in] ptr to message info
responceContent[in] ptr to response data
responceLength[in] size of response data

◆ task

mainTask_callback_t ot_app_devDrv_t::task

Main task callback for periodic device processing.

Pointer to the main task function that should be called periodically from the main loop or RTOS task to process device events and state updates.

This callback handles non-blocking processing of:

  • Button events and user input
  • Internal state updates
  • Communication with paired devices
  • Any device-specific periodic maintenance

The framework calls this function regularly (e.g., every main loop iteration) to keep the device responsive and process pending work.

Example usage in reference implementation:

void ad_button_task(void)
{
ad_btn_task(); // Processes button events
}
void ad_button_task()
Main task function for button device.
Definition ad_button.c:275
void ad_btn_task(void)
Definition ad_btn_assign.c:96

Set during initialization: drv->task = ad_button_task; [file:1]

Note
Function must be non-blocking and return immediately
Should contain minimal processing to avoid delaying other tasks
See also
ad_button_task() for reference implementation example

◆ uriGetIdList

int8_t(* ot_app_drv_pair_t::uriGetIdList) (otapp_pair_Device_t *deviceHandle, otapp_deviceType_t uriDevType)

looking for ID of urisList in urisList

Parameters
deviceHandle[in] ptr to otapp_pair_Device_t
uriDevType[in] type of device, we will be looking for in the uriList
Returns
int8_t [out] index of urisList from otapp_pair_uris_t when uriDevType exist or OTAPP_PAIR_NO_EXIST

◆ uriGetList_clb

uriGet_callback_t ot_app_devDrv_t::uriGetList_clb

Callback function to retrieve the list of URIs.

This callback is used to obtain the list of supported URIs exposed by the device. The URIs typically represent accessible CoAP resource endpoints for network interaction.

When called, the callback returns a pointer to a list or array holding the URIs that the device registers or supports for remote access or commands.

This allows the framework or application to discover and interact with device capabilities dynamically.

Note
Maximum URIs: OTAPP_PAIRED_URI_MAX
Maximum URI name length: OTAPP_URI_MAX_NAME_LENGHT
Returns
Pointer to the URI list.

◆ uriGetListSize

ot_app_size_t ot_app_devDrv_t::uriGetListSize

Number of URIs in the URI list.

Returns the count of URIs supported by the device, corresponding to the size of the array returned by uriGetList_clb callback.

This value informs the framework how many CoAP resource endpoints the device exposes for network interaction and remote control.

Used during device registration and pairing to properly allocate resources for URI handling and subscription management.

Note
Maximum value limited by OTAPP_PAIRED_URI_MAX
Must match the actual size of URI list returned by uriGetList_clb
See also
uriGetList_clb for the URI list callback
OTAPP_PAIRED_URI_MAX for maximum URI count limit

◆ uriStateSet

int8_t(* ot_app_drv_pair_t::uriStateSet) (otapp_pair_DeviceList_t *pairDeviceList, const oacu_token_t *token, const uint32_t *uriState)

set uri state on the pair device list. Max data per uri = uint32_t

Parameters
pairDeviceList[in] ptr to Pair devices list.
See also
getHandle()
Parameters
token[in] ptr to token of uri
uriState[in] ptr to uri state. Max uint32_t
Returns
int8_t [out] OTAPP_PAIR_OK or OTAPP_PAIR_ERROR