|
OpenThread_app
|
Manages the list of discovered devices, pairing logic, and URI resource parsing. More...
Classes | |
| struct | otapp_pair_resUrisParseData_t |
| Structure holding temporary parsed data from a URI resource. More... | |
| struct | otapp_pair_uris_t |
| Represents a single URI endpoint belonging to a paired device. More... | |
| struct | otapp_pair_Device_t |
| Represents a fully paired remote device. More... | |
| struct | otapp_pair_rule_t |
| Rules structure defining which device types are allowed to pair. More... | |
| struct | otapp_pair_queueItem_t |
| Structure for the pairing event queue. More... | |
Typedefs | |
| typedef uint8_t | otapp_pair_resUrisBuffer_t[OTAPP_PAIR_URI_RESOURCE_BUFFER_SIZE] |
| typedef struct otapp_pair_DeviceList_t | otapp_pair_DeviceList_t |
| Opaque handle for the device list. | |
| typedef void(* | otapp_pair_observerCallback_t) (otapp_pair_Device_t *newDevice) |
| Prototype for observer callback function. | |
Enumerations | |
| enum | otapp_pair_QueueDataType_t { OTAPP_PAIR_CHECK_AND_ADD_TO_DEV_LIST } |
| Queue event types. More... | |
Functions | |
| int8_t | otapp_pair_init (ot_app_devDrv_t *driver) |
| Initializes the pairing module. | |
| int8_t | otapp_pair_observerPairedDeviceRegisterCallback (otapp_pair_observerCallback_t callback) |
| Registers a callback to be notified when a new device is paired. | |
| int8_t | otapp_pair_DeviceAdd (otapp_pair_DeviceList_t *pairDeviceList, const char *deviceNameFull, otIp6Address *ipAddr) |
| Adds a new device to the pairing list. | |
| int8_t | otapp_pair_DeviceIndexGet (otapp_pair_DeviceList_t *pairDeviceList, const char *deviceNameFull) |
| Retrieves the index of a device in the list by its name. | |
| otapp_pair_Device_t * | otapp_pair_DeviceGet (otapp_pair_DeviceList_t *pairDeviceList, const char *deviceNameFull) |
| Retrieves a pointer to the device structure by name. | |
| char * | otapp_pair_DeviceNameGet (otapp_pair_DeviceList_t *pairDeviceList, uint8_t indexDevice) |
| Retrieves the full name of a device at a specific index. | |
| int8_t | otapp_pair_DeviceDelete (otapp_pair_DeviceList_t *pairDeviceList, const char *deviceNameFull) |
| Removes a device from the pairing list. | |
| int8_t | otapp_pair_DeviceDeleteAll (otapp_pair_DeviceList_t *pairDeviceList) |
| Clears all devices from the pairing list. | |
| otapp_pair_DeviceList_t * | otapp_pair_getHandle (void) |
| Gets the singleton handle to the global device list. | |
| otIp6Address * | otapp_pair_ipAddressGet (otapp_pair_DeviceList_t *pairDeviceList, uint8_t indexDevice) |
| Retrieves the IPv6 address of a device at a specific index. | |
| int8_t | otapp_pair_ipAddressIsSame (otapp_pair_DeviceList_t *pairDeviceList, uint8_t indexDevice, otIp6Address *ipAddr) |
| Checks if the stored IP address matches the provided one. | |
| int8_t | otapp_pair_ipAddressUpdate (otapp_pair_DeviceList_t *pairDeviceList, uint8_t indexDevice, otIp6Address *ipAddrNew) |
| Updates the IP address of a paired device if it has changed. | |
| void | otapp_pair_devicePrintData (otapp_pair_DeviceList_t *pairDeviceList, uint8_t indexDevice) |
| Prints debug information about a paired device to the log. | |
| int8_t | otapp_pair_addToQueue (otapp_pair_queueItem_t *queueItem) |
| Adds an item to the pairing processing queue. | |
| otapp_pair_resUrisParseData_t * | otapp_pair_uriParseMessage (uint8_t *inBuffer, uint16_t inBufferSize, int8_t *result, uint16_t *outParsedDataSize) |
| Parses the payload of a CoAP response containing URI resources. | |
| uint16_t | otapp_pair_uriParseMessageCalculateBufSize (uint16_t aMessagePayloadSize) |
| Calculates the required buffer size to hold a message with URI resources. | |
| int8_t | otapp_pair_uriAdd (otapp_pair_uris_t *deviceUrisList, const otapp_pair_resUrisParseData_t *uriData, const oacu_token_t *token) |
| Adds a parsed URI to a specific slot in a device's URI list. | |
| int8_t | otapp_pair_uriResourcesCreate (otapp_coap_uri_t *uri, uint8_t uriSize, uint8_t *bufferOut, uint16_t *bufferSizeInOut) |
| Serializes a list of device URI resources into a TLV-encoded byte buffer. | |
| uint16_t | otapp_pair_uriResourcesCalculateBufSize (otapp_coap_uri_t *uri, uint8_t uriSize) |
| Calculates the buffer size needed to serialize a list of URIs. | |
| int8_t | otapp_pair_uriStateSet (otapp_pair_DeviceList_t *pairDeviceList, const oacu_token_t *token, const uint32_t *uriState) |
| Sets the state (value) of a URI based on its token. | |
| int8_t | otapp_pair_subSendUpdateIP (otapp_pair_DeviceList_t *pairDeviceList) |
| Resends subscription updates to all paired devices (e.g. after IP change). | |
| otapp_pair_uris_t * | otapp_pair_tokenGetUriIteams (otapp_pair_DeviceList_t *pairDeviceList, const oacu_token_t *token) |
| Finds a URI item in the list by its token. | |
| int8_t | otapp_pair_uriGetIdList (otapp_pair_Device_t *deviceHandle, otapp_deviceType_t uriDevType) |
| Searches for a specific device function type within a device's URI list. | |
Comparison Results | |
| #define | OTAPP_PAIR_IS (1) |
| Objects are identical. | |
| #define | OTAPP_PAIR_IS_NOT (2) |
| Objects are different. | |
Return Codes | |
| #define | OTAPP_PAIR_OK (-1) |
| Operation successful. | |
| #define | OTAPP_PAIR_UPDATED (-2) |
| Device data was updated (e.g. new IP). | |
| #define | OTAPP_PAIR_NO_NEED_UPDATE (-3) |
| Device exists and data is current. | |
| #define | OTAPP_PAIR_ERROR (-4) |
| Generic error. | |
| #define | OTAPP_PAIR_NO_EXIST (-5) |
| Device not found in list. | |
| #define | OTAPP_PAIR_DEVICE_NAME_EXIST (-6) |
| Device name collision. | |
| #define | OTAPP_PAIR_DEVICE_NAME_TO_LONG (-7) |
| Name exceeds buffer size. | |
| #define | OTAPP_PAIR_DEVICE_NO_SPACE (-8) |
| Device list is full. | |
Buffer & Limits Configuration | |
| #define | OTAPP_PAIR_DEVICES_MAX OTAPP_PAIRED_DEVICES_MAX |
| Max number of paired devices (from ot_app.h). | |
| #define | OTAPP_PAIR_URI_MAX OTAPP_PAIRED_URI_MAX |
| Max number of URIs per device (from ot_app.h). | |
| #define | OTAPP_PAIR_URI_RESOURCE_BUFFER_SIZE (OTAPP_URI_MAX_NAME_LENGHT + sizeof(otapp_deviceType_t) + sizeof(uint8_t)) |
| #define | OTAPP_PAIR_URI_RESOURCE_BUFFER_MAX_SIZE (OTAPP_PAIR_URI_RESOURCE_BUFFER_SIZE * OTAPP_PAIR_URI_MAX) |
| #define | OTAPP_PAIR_URI_MAX_VAL OTAPP_URI_END_OF_INDEX |
| #define | OTAPP_PAIR_NAME_FULL_SIZE OTAPP_DEVICE_NAME_FULL_SIZE |
| #define | OTAPP_PAIR_NO_URI OTAPP_URI_NO_URI_INDEX |
| #define | OTAPP_PAIR_URI_INIT OTAPP_URI_END_OF_INDEX |
Task & Queue Configuration | |
| #define | OTAPP_PAIR_QUEUE_LENGTH 10 |
| Depth of the pairing event queue. | |
| #define | OTAPP_PAIR_TASK_STACK_DEPTH (128 * 17) |
| Stack size for the pairing RTOS task. | |
| #define | OTAPP_PAIR_TASK_PRIORITY 5 |
| Priority of the pairing RTOS task. | |
Pairing Rules Configuration | |
| #define | OTAPP_PAIR_RULES_ALLOWED_SIZE 10 |
| #define | OTAPP_PAIR_RULES_ALLOWED_ITEM_MAX_SIZE OTAPP_END_OF_DEVICE_TYPE |
| #define | OTAPP_PAIR_NO_RULES (OTAPP_END_OF_DEVICE_TYPE + 1) |
| #define | OTAPP_PAIR_NO_ALLOWED OTAPP_NO_DEVICE_TYPE |
| #define | OTAPP_PAIR_END_OF_RULES OTAPP_END_OF_DEVICE_TYPE |
| #define | OTAPP_PAIR_OBSERVER_PAIRE_DDEVICE_CALLBACK_SIZE 10 |
Manages the list of discovered devices, pairing logic, and URI resource parsing.
This module handles the core logic of the "Pairing" phase. It maintains a list of known devices (otapp_pair_DeviceList_t), handles the logic of adding/removing devices based on rules, and parses CoAP responses containing device capabilities (URIs). Key Features:
| #define OTAPP_PAIR_DEVICE_NAME_EXIST (-6) |
Device name collision.
| #define OTAPP_PAIR_DEVICE_NAME_TO_LONG (-7) |
Name exceeds buffer size.
| #define OTAPP_PAIR_DEVICE_NO_SPACE (-8) |
Device list is full.
| #define OTAPP_PAIR_DEVICES_MAX OTAPP_PAIRED_DEVICES_MAX |
Max number of paired devices (from ot_app.h).
| #define OTAPP_PAIR_END_OF_RULES OTAPP_END_OF_DEVICE_TYPE |
| #define OTAPP_PAIR_ERROR (-4) |
Generic error.
| #define OTAPP_PAIR_IS (1) |
Objects are identical.
| #define OTAPP_PAIR_IS_NOT (2) |
Objects are different.
| #define OTAPP_PAIR_NAME_FULL_SIZE OTAPP_DEVICE_NAME_FULL_SIZE |
| #define OTAPP_PAIR_NO_ALLOWED OTAPP_NO_DEVICE_TYPE |
| #define OTAPP_PAIR_NO_EXIST (-5) |
Device not found in list.
| #define OTAPP_PAIR_NO_NEED_UPDATE (-3) |
Device exists and data is current.
| #define OTAPP_PAIR_NO_RULES (OTAPP_END_OF_DEVICE_TYPE + 1) |
| #define OTAPP_PAIR_NO_URI OTAPP_URI_NO_URI_INDEX |
| #define OTAPP_PAIR_OBSERVER_PAIRE_DDEVICE_CALLBACK_SIZE 10 |
| #define OTAPP_PAIR_OK (-1) |
Operation successful.
| #define OTAPP_PAIR_QUEUE_LENGTH 10 |
Depth of the pairing event queue.
| #define OTAPP_PAIR_RULES_ALLOWED_ITEM_MAX_SIZE OTAPP_END_OF_DEVICE_TYPE |
| #define OTAPP_PAIR_RULES_ALLOWED_SIZE 10 |
| #define OTAPP_PAIR_TASK_PRIORITY 5 |
Priority of the pairing RTOS task.
| #define OTAPP_PAIR_TASK_STACK_DEPTH (128 * 17) |
Stack size for the pairing RTOS task.
| #define OTAPP_PAIR_UPDATED (-2) |
Device data was updated (e.g. new IP).
| #define OTAPP_PAIR_URI_INIT OTAPP_URI_END_OF_INDEX |
| #define OTAPP_PAIR_URI_MAX OTAPP_PAIRED_URI_MAX |
Max number of URIs per device (from ot_app.h).
| #define OTAPP_PAIR_URI_MAX_VAL OTAPP_URI_END_OF_INDEX |
| #define OTAPP_PAIR_URI_RESOURCE_BUFFER_MAX_SIZE (OTAPP_PAIR_URI_RESOURCE_BUFFER_SIZE * OTAPP_PAIR_URI_MAX) |
| #define OTAPP_PAIR_URI_RESOURCE_BUFFER_SIZE (OTAPP_URI_MAX_NAME_LENGHT + sizeof(otapp_deviceType_t) + sizeof(uint8_t)) |
| typedef struct otapp_pair_DeviceList_t otapp_pair_DeviceList_t |
Opaque handle for the device list.
The actual definition is hidden in the source file to encapsulate the list storage.
| typedef void(* otapp_pair_observerCallback_t) (otapp_pair_Device_t *newDevice) |
Prototype for observer callback function.
| [out] | newDevice | Pointer to the structure of the newly paired device. |
| typedef uint8_t otapp_pair_resUrisBuffer_t[OTAPP_PAIR_URI_RESOURCE_BUFFER_SIZE] |
| int8_t otapp_pair_addToQueue | ( | otapp_pair_queueItem_t * | queueItem | ) |
Adds an item to the pairing processing queue.
| queueItem | Pointer to the item to add. |
| int8_t otapp_pair_DeviceAdd | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| const char * | deviceNameFull, | ||
| otIp6Address * | ipAddr ) |
Adds a new device to the pairing list.
| pairDeviceList | [in] Handle to the device list (use otapp_pair_getHandle). |
| deviceNameFull | [in] Full device name string. |
| ipAddr | [in] Pointer to the device's IPv6 address. |
| int8_t otapp_pair_DeviceDelete | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| const char * | deviceNameFull ) |
Removes a device from the pairing list.
| pairDeviceList | Handle to the device list. |
| deviceNameFull | Full device name string. |
| int8_t otapp_pair_DeviceDeleteAll | ( | otapp_pair_DeviceList_t * | pairDeviceList | ) |
Clears all devices from the pairing list.
| pairDeviceList | Handle to the device list. |
| otapp_pair_Device_t * otapp_pair_DeviceGet | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| const char * | deviceNameFull ) |
Retrieves a pointer to the device structure by name.
| pairDeviceList | Handle to the device list. |
| deviceNameFull | Full device name string. |
| int8_t otapp_pair_DeviceIndexGet | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| const char * | deviceNameFull ) |
Retrieves the index of a device in the list by its name.
| pairDeviceList | [in] Handle to the device list. |
| deviceNameFull | [in] Full device name string. |
| char * otapp_pair_DeviceNameGet | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| uint8_t | indexDevice ) |
Retrieves the full name of a device at a specific index.
| pairDeviceList | Handle to the device list. |
| indexDevice | Index of the device. |
| void otapp_pair_devicePrintData | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| uint8_t | indexDevice ) |
Prints debug information about a paired device to the log.
| pairDeviceList | Handle to the device list. |
| indexDevice | Index of the device to print. |
| otapp_pair_DeviceList_t * otapp_pair_getHandle | ( | void | ) |
Gets the singleton handle to the global device list.
| int8_t otapp_pair_init | ( | ot_app_devDrv_t * | driver | ) |
Initializes the pairing module.
Creates the RTOS task and queue responsible for processing discovery events and managing the device list. Registers the initial observer callback.
| driver | Pointer to the main application driver instance. |
| otIp6Address * otapp_pair_ipAddressGet | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| uint8_t | indexDevice ) |
Retrieves the IPv6 address of a device at a specific index.
| pairDeviceList | Handle to the device list. |
| indexDevice | Index of the device. |
| int8_t otapp_pair_ipAddressIsSame | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| uint8_t | indexDevice, | ||
| otIp6Address * | ipAddr ) |
Checks if the stored IP address matches the provided one.
| pairDeviceList | Handle to the device list. |
| indexDevice | Index of the device. |
| ipAddr | Pointer to the IPv6 address to compare. |
| int8_t otapp_pair_ipAddressUpdate | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| uint8_t | indexDevice, | ||
| otIp6Address * | ipAddrNew ) |
Updates the IP address of a paired device if it has changed.
| pairDeviceList | Handle to the device list. |
| indexDevice | Index of the device. |
| ipAddrNew | Pointer to the new IPv6 address. |
| int8_t otapp_pair_observerPairedDeviceRegisterCallback | ( | otapp_pair_observerCallback_t | callback | ) |
Registers a callback to be notified when a new device is paired.
| callback | Function pointer to the handler. |
| int8_t otapp_pair_subSendUpdateIP | ( | otapp_pair_DeviceList_t * | pairDeviceList | ) |
Resends subscription updates to all paired devices (e.g. after IP change).
| pairDeviceList | Handle to the device list. |
| otapp_pair_uris_t * otapp_pair_tokenGetUriIteams | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| const oacu_token_t * | token ) |
Finds a URI item in the list by its token.
| pairDeviceList | Handle to the device list. |
| token | Token to search for. |
| int8_t otapp_pair_uriAdd | ( | otapp_pair_uris_t * | deviceUrisList, |
| const otapp_pair_resUrisParseData_t * | uriData, | ||
| const oacu_token_t * | token ) |
Adds a parsed URI to a specific slot in a device's URI list.
| deviceUrisList | Pointer to the destination slot in the device structure. |
| uriData | Pointer to the parsed source data. |
| token | Optional CoAP token if subscription is active. |
| int8_t otapp_pair_uriGetIdList | ( | otapp_pair_Device_t * | deviceHandle, |
| otapp_deviceType_t | uriDevType ) |
Searches for a specific device function type within a device's URI list.
| deviceHandle | [in] Pointer to the device structure. |
| uriDevType | [in] Function type to look for (e.g. LIGHTING_ON_OFF). |
| otapp_pair_resUrisParseData_t * otapp_pair_uriParseMessage | ( | uint8_t * | inBuffer, |
| uint16_t | inBufferSize, | ||
| int8_t * | result, | ||
| uint16_t * | outParsedDataSize ) |
Parses the payload of a CoAP response containing URI resources.
Extracts TLV data from the buffer and populates an array of otapp_pair_resUrisParseData_t.
| [in] | inBuffer | Pointer to the raw TLV buffer. |
| [in] | inBufferSize | Size of the buffer. |
| [out] | result | Operation result (OTAPP_PAIR_OK / ERROR). |
| [out] | outParsedDataSize | Number of URI items found. |
| uint16_t otapp_pair_uriParseMessageCalculateBufSize | ( | uint16_t | aMessagePayloadSize | ) |
Calculates the required buffer size to hold a message with URI resources.
| aMessagePayloadSize | Size of the raw payload. |
| uint16_t otapp_pair_uriResourcesCalculateBufSize | ( | otapp_coap_uri_t * | uri, |
| uint8_t | uriSize ) |
Calculates the buffer size needed to serialize a list of URIs.
| uri | Pointer to array of URIs. |
| uriSize | Number of URIs. |
| int8_t otapp_pair_uriResourcesCreate | ( | otapp_coap_uri_t * | uri, |
| uint8_t | uriSize, | ||
| uint8_t * | bufferOut, | ||
| uint16_t * | bufferSizeInOut ) |
Serializes a list of device URI resources into a TLV-encoded byte buffer.
This function takes an array of CoAP resources and packs them into a user-provided buffer using the TLV Message Buffer module. It is primarily used during the device discovery and pairing phase to inform other nodes about available endpoints. TLV Memory Layout:
Encoding Logic:
| [in] | uri | Pointer to the array of URI resource structures. |
| [in] | uriSize | Number of URIs to serialize (max OTAPP_PAIR_URI_MAX). |
| [out] | bufferOut | Pointer to the destination buffer (usually acquired via otapp_buf_getWriteOnly_ptr). |
| [in,out] | bufferSizeInOut | [in] Total capacity of the buffer; [out] Actual number of bytes written. |
bufferSizeInOut by calling otapp_msg_tlv_getBufferTotalUsedSpace at the end of the process. | int8_t otapp_pair_uriStateSet | ( | otapp_pair_DeviceList_t * | pairDeviceList, |
| const oacu_token_t * | token, | ||
| const uint32_t * | uriState ) |
Sets the state (value) of a URI based on its token.
| pairDeviceList | [in] Handle to Pair devices list. |
| token | [in] Token of the URI (from Observe notification). |
| uriState | [in] New state value (max uint32_t). |