KNX IoT
KNX IoT Point API stack implementation
|
Group of server support functions. More...
Functions | |
bool | oc_add_resource (oc_resource_t *resource) |
Add a resource to the stack. More... | |
void | oc_delayed_delete_resource (oc_resource_t *resource) |
Schedule a callback to remove a resource. More... | |
bool | oc_delete_resource (oc_resource_t *resource) |
Remove a resource from the stack and delete the resource. More... | |
bool | oc_get_diagnostic_message (oc_client_response_t *response, const char **msg, size_t *size) |
retrieve the diagnostic payload from a response More... | |
int | oc_get_query_value (oc_request_t *request, const char *key, char **value) |
Get a pointer to the start of the value in a URL query parameter key=value pair. More... | |
bool | oc_get_request_payload_raw (oc_request_t *request, const uint8_t **payload, size_t *size, oc_content_format_t *content_format) |
retrieve the payload from the request, no processing More... | |
bool | oc_get_response_payload_raw (oc_client_response_t *response, const uint8_t **payload, size_t *size, oc_content_format_t *content_format) |
retrieve the response payload, without processing More... | |
void | oc_ignore_request (oc_request_t *request) |
Ignore the request. More... | |
void | oc_indicate_separate_response (oc_request_t *request, oc_separate_response_t *response) |
Respond to an incoming request asynchronously. More... | |
void | oc_init_query_iterator (void) |
This resets the query iterator to the start of the URI query parameter. More... | |
int | oc_iterate_query (oc_request_t *request, char **key, size_t *key_len, char **value, size_t *value_len) |
Iterate through the URI query parameters and get each key=value pair. More... | |
bool | oc_iterate_query_get_values (oc_request_t *request, const char *key, char **value, int *value_len) |
Iterate though the URI query parameters for a specific key. More... | |
oc_resource_t * | oc_new_resource (const char *name, const char *uri, uint8_t num_resource_types, size_t device) |
Allocate and populate a new oc_resource_t. More... | |
int | oc_notify_observers (const oc_resource_t *resource) |
Notify all observers of a change to a given resource's property. More... | |
int | oc_query_value_exists (oc_request_t *request, const char *key) |
Checks if a query parameter 'key' exist in the URL query parameter. More... | |
bool | oc_query_values_available (oc_request_t *request) |
Checks if a query parameter are available. More... | |
void | oc_resource_bind_content_type (oc_resource_t *resource, oc_content_format_t content_type) |
set the content type on the resource More... | |
void | oc_resource_bind_dpt (oc_resource_t *resource, const char *dpt) |
Add a Data Point Type "dpt" property to the resource. More... | |
void | oc_resource_bind_resource_interface (oc_resource_t *resource, oc_interface_mask_t iface_mask) |
Add the supported interface(s) to the resource. More... | |
void | oc_resource_bind_resource_type (oc_resource_t *resource, const char *type) |
Add a Resource Type "rt" property to the resource. More... | |
void | oc_resource_make_public (oc_resource_t *resource) |
Expose unsecured coap:// endpoints (in addition to secured coaps:// endpoints) for this resource in /well-known/core. More... | |
void | oc_resource_set_discoverable (oc_resource_t *resource, bool state) |
Specify if a resource can be found using .well-known/core discover mechanisms. More... | |
void | oc_resource_set_function_block_instance (oc_resource_t *resource, uint8_t instance) |
set a resource to a specific function block instance default is instance 0, if there is just 1 instance of the function block this function does not have to be called. More... | |
void | oc_resource_set_observable (oc_resource_t *resource, bool state) |
Specify that a resource should notify clients when a property has been modified. More... | |
void | oc_resource_set_periodic_observable (oc_resource_t *resource, uint16_t seconds) |
The resource will periodically notify observing clients of is property values. More... | |
void | oc_resource_set_properties_cbs (oc_resource_t *resource, oc_get_properties_cb_t get_properties, void *get_props_user_data, oc_set_properties_cb_t set_properties, void *set_props_user_data) |
sets the callback properties for set properties and get properties More... | |
void | oc_resource_set_request_handler (oc_resource_t *resource, oc_method_t method, oc_request_callback_t callback, void *user_data) |
Specify a request_callback for GET, PUT, POST, and DELETE methods. More... | |
void | oc_send_cbor_response (oc_request_t *request, oc_status_t response_code) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed. More... | |
void | oc_send_cbor_response_with_payload_size (oc_request_t *request, oc_status_t response_code, size_t payload_size) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed. More... | |
void | oc_send_diagnostic_message (oc_request_t *request, const char *msg, size_t msg_len, oc_status_t response_code) |
send a diagnostic payload More... | |
void | oc_send_empty_separate_response (oc_separate_response_t *handle, oc_status_t response_code) |
Called to send the deferred response to a GET, PUT, POST or DELETE request, with an empty payload. More... | |
void | oc_send_json_response (oc_request_t *request, oc_status_t response_code) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed. More... | |
void | oc_send_linkformat_response (oc_request_t *request, oc_status_t response_code, size_t response_length) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed. More... | |
void | oc_send_response (oc_request_t *request, oc_status_t response_code) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed, will respond with CBOR. More... | |
void | oc_send_response_no_format (oc_request_t *request, oc_status_t response_code) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed. More... | |
void | oc_send_response_raw (oc_request_t *request, const uint8_t *payload, size_t size, oc_content_format_t content_format, oc_status_t response_code) |
send the request, no processing More... | |
void | oc_send_separate_response (oc_separate_response_t *handle, oc_status_t response_code) |
Called to send the deferred response to a GET, PUT, POST or DELETE request. More... | |
void | oc_set_separate_response_buffer (oc_separate_response_t *handle) |
Set a response buffer for holding the response payload. More... | |
Group of server support functions.
The standardized functions are implemented. The following groups are implemented:
all functions generate the core-link or CBOR formatted responses.
Applications have to define the functions (GET and PUT) for the application level data points. Applications have to define for each instance these functions. The functions are registered with the device and will be called when the other devices are interacting with it.
see for more details the examples.
bool oc_add_resource | ( | oc_resource_t * | resource | ) |
Add a resource to the stack.
The resource will be validated then added to the stack.
[in] | resource | the resource to add to the stack |
void oc_delayed_delete_resource | ( | oc_resource_t * | resource | ) |
Schedule a callback to remove a resource.
[in] | resource | the resource to delete |
bool oc_delete_resource | ( | oc_resource_t * | resource | ) |
Remove a resource from the stack and delete the resource.
Any resource observers will automatically be removed.
This will free the memory associated with the resource.
[in] | resource | the resource to delete |
bool oc_get_diagnostic_message | ( | oc_client_response_t * | response, |
const char ** | msg, | ||
size_t * | size | ||
) |
retrieve the diagnostic payload from a response
response | the response to get the diagnostic payload from |
msg | the diagnostic payload |
size | the size of the diagnostic payload |
int oc_get_query_value | ( | oc_request_t * | request, |
const char * | key, | ||
char ** | value | ||
) |
Get a pointer to the start of the value in a URL query parameter key=value pair.
[in] | request | the oc_request_t that contains the query parameters |
[in] | key | the key being searched for |
[out] | value | pointer to the value string assigned to the key |
-1
if there are no additional query parameters bool oc_get_request_payload_raw | ( | oc_request_t * | request, |
const uint8_t ** | payload, | ||
size_t * | size, | ||
oc_content_format_t * | content_format | ||
) |
retrieve the payload from the request, no processing
request | the request |
payload | the payload of the request |
size | the size in bytes of the payload |
content_format | the content format of the payload |
bool oc_get_response_payload_raw | ( | oc_client_response_t * | response, |
const uint8_t ** | payload, | ||
size_t * | size, | ||
oc_content_format_t * | content_format | ||
) |
retrieve the response payload, without processing
response | the response |
payload | the payload of the response |
size | the size of the payload |
content_format | the content format of the payload |
void oc_ignore_request | ( | oc_request_t * | request | ) |
Ignore the request.
The GET, PUT, POST or DELETE requests can be ignored. For example a oc_request_callback_t may only want to respond to multi-cast requests. Thus any request that is not over multi-cast endpoint could be ignored.
Using oc_ignore(request)
is preferred over oc_send_response(request, OC_IGNORE)
since it does not attempt to fill the response buffer before sending the response.
[in] | request | the request being responded to |
void oc_indicate_separate_response | ( | oc_request_t * | request, |
oc_separate_response_t * | response | ||
) |
Respond to an incoming request asynchronously.
If for some reason the response to a request would take a long time or is not immediately available, then this function may be used defer responding to the request.
Example:
[in] | request | the request that will be responded to as a separate response |
[in] | response | instance of an internal struct that is used to track the state of the separate response. |
void oc_init_query_iterator | ( | void | ) |
This resets the query iterator to the start of the URI query parameter.
This is used together with oc_iterate_query_get_values() or oc_iterate_query() to iterate through query parameter of a URI that are part of an oc_request_t
int oc_iterate_query | ( | oc_request_t * | request, |
char ** | key, | ||
size_t * | key_len, | ||
char ** | value, | ||
size_t * | value_len | ||
) |
Iterate through the URI query parameters and get each key=value pair.
Before calling oc_iterate_query() the first time oc_init_query_iterator() must be called to reset the query iterator to the first query parameter.
Example:
[in] | request | the oc_request_t that contains the query parameters |
[out] | key | pointer to the location of the key of the key=value pair |
[out] | key_len | the length of the key string |
[out] | value | pointer the location of the value string assigned to the key=value pair |
[out] | value_len | the length of the value string |
-1
if there are no additional query parameters bool oc_iterate_query_get_values | ( | oc_request_t * | request, |
const char * | key, | ||
char ** | value, | ||
int * | value_len | ||
) |
Iterate though the URI query parameters for a specific key.
Before calling oc_iterate_query_get_values() the first time oc_init_query_iterator() must be called to reset the query iterator to the first query parameter.
Example:
[in] | request | the oc_request_t that contains the query parameters |
[in] | key | the key being searched for |
[out] | value | pointer to the value string for to the key=value pair |
[out] | value_len | the length of the value string |
oc_resource_t* oc_new_resource | ( | const char * | name, |
const char * | uri, | ||
uint8_t | num_resource_types, | ||
size_t | device | ||
) |
Allocate and populate a new oc_resource_t.
Resources are the primary interface between code and real world devices.
Each resource has a Uniform Resource Identifier (URI) that identifies it. All resources must specify one or more Resource Types to be considered a valid resource. The number of Resource Types is specified by the num_resource_types
the actual Resource Types are added later using the oc_resource_bind_resource_type() function.
Many properties associated with a resource are set or modified after the new resource has been created.
The resource is not added to the device till oc_add_resource() is called.
Example:
[in] | name | the name of the new resource this will set the property n |
[in] | uri | the Uniform Resource Identifier for the resource |
[in] | num_resource_types | the number of Resource Types that will be added/bound to the resource |
[in] | device | index of the logical device the resource will be added to |
int oc_notify_observers | ( | const oc_resource_t * | resource | ) |
Notify all observers of a change to a given resource's property.
[in] | resource | the oc_resource_t that has a modified property |
0
on failure could also mean no registered observers int oc_query_value_exists | ( | oc_request_t * | request, |
const char * | key | ||
) |
Checks if a query parameter 'key' exist in the URL query parameter.
[in] | request | the oc_request_t that contains the query parameters |
[in] | key | the key being searched for |
bool oc_query_values_available | ( | oc_request_t * | request | ) |
Checks if a query parameter are available.
[in] | request | the oc_request_t that contains the query parameters |
void oc_resource_bind_content_type | ( | oc_resource_t * | resource, |
oc_content_format_t | content_type | ||
) |
set the content type on the resource
resource | the resource |
content_type | the content type |
void oc_resource_bind_dpt | ( | oc_resource_t * | resource, |
const char * | dpt | ||
) |
Add a Data Point Type "dpt" property to the resource.
[in] | resource | the resource that the Data Point Type will be set on |
[in] | dpt | the Data Point Type to add to the Data Point Type "dpt" property |
void oc_resource_bind_resource_interface | ( | oc_resource_t * | resource, |
oc_interface_mask_t | iface_mask | ||
) |
Add the supported interface(s) to the resource.
Resource interfaces specify how the code is able to interact with the resource
The iface_mask
is bitwise OR of the interfaces
[in] | resource | the resource that the interface(s) will be added to |
[in] | iface_mask | a bitwise ORed list of all interfaces supported by the resource. |
void oc_resource_bind_resource_type | ( | oc_resource_t * | resource, |
const char * | type | ||
) |
Add a Resource Type "rt" property to the resource.
All resources require at least one Resource Type. The number of Resource Types the resource contains is declared when the resource it created using oc_new_resource() function.
Multi-value "rt" Resource means a resource with multiple Resource Types. i.e. oc_resource_bind_resource_type() is called multiple times for a single resource. When using a Multi-value Resource the different resources properties must not conflict.
[in] | resource | the resource that the Resource Type will be set on |
[in] | type | the Resource Type to add to the Resource Type "rt" property |
void oc_resource_make_public | ( | oc_resource_t * | resource | ) |
Expose unsecured coap:// endpoints (in addition to secured coaps:// endpoints) for this resource in /well-known/core.
[in] | resource | the resource to make public |
void oc_resource_set_discoverable | ( | oc_resource_t * | resource, |
bool | state | ||
) |
Specify if a resource can be found using .well-known/core discover mechanisms.
[in] | resource | to specify as discoverable or non-discoverable |
[in] | state | if true the resource will be discoverable if false the resource will be non-discoverable |
void oc_resource_set_function_block_instance | ( | oc_resource_t * | resource, |
uint8_t | instance | ||
) |
set a resource to a specific function block instance default is instance 0, if there is just 1 instance of the function block this function does not have to be called.
resource | the resource |
instance | the instance id. |
void oc_resource_set_observable | ( | oc_resource_t * | resource, |
bool | state | ||
) |
Specify that a resource should notify clients when a property has been modified.
[in] | resource | the resource to specify the observability |
[in] | state | true to make resource observable, false to make resource unobservable |
void oc_resource_set_periodic_observable | ( | oc_resource_t * | resource, |
uint16_t | seconds | ||
) |
The resource will periodically notify observing clients of is property values.
The oc_resource_set_observable() function can be used to turn off a periodic observable resource.
Setting a seconds
frequency of zero 0
is invalid and will result in an invalid resource.
[in] | resource | the resource to specify the periodic observability |
[in] | seconds | the frequency in seconds that the resource will send out an notification of is property values. |
void oc_resource_set_properties_cbs | ( | oc_resource_t * | resource, |
oc_get_properties_cb_t | get_properties, | ||
void * | get_props_user_data, | ||
oc_set_properties_cb_t | set_properties, | ||
void * | set_props_user_data | ||
) |
sets the callback properties for set properties and get properties
resource | the resource for the callback data |
get_properties | callback function for retrieving the properties |
get_props_user_data | the user data for the get_properties callback function |
set_properties | callback function for setting the properties |
set_props_user_data | the user data for the set_properties callback function |
void oc_resource_set_request_handler | ( | oc_resource_t * | resource, |
oc_method_t | method, | ||
oc_request_callback_t | callback, | ||
void * | user_data | ||
) |
Specify a request_callback for GET, PUT, POST, and DELETE methods.
All resources must provide at least one request handler to be a valid resource.
method types:
OC_GET
the oc_request_callback_t
is responsible for returning the current value of all of the resource properties.OC_PUT
the oc_request_callback_t
is responsible for updating one or more of the resource properties.OC_POST
the oc_request_callback_t
is responsible for updating one or more of the resource properties. The callback may also be responsible for creating new resources.OC_DELETE
the oc_request_callback_t
is responsible for deleting a resource[in] | resource | the resource the callback handler will be registered to |
[in] | method | specify if type method the callback is responsible for handling |
[in] | callback | the callback handler that will be invoked when a the method is called on the resource. |
[in] | user_data | context pointer that is passed to the oc_request_callback_t. The pointer must remain valid as long as the resource exists. |
void oc_send_cbor_response | ( | oc_request_t * | request, |
oc_status_t | response_code | ||
) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
will respond with CBOR as content type.
The function oc_send_response is called at the end of a oc_request_callback_t to inform the caller about the status of the requested action.
Note that OC_STATUS_BAD_REQUEST for multicast will not send a response (e.g. threated as OC_IGNORE)
request | the request being responded to |
response_code | the status of the response |
void oc_send_cbor_response_with_payload_size | ( | oc_request_t * | request, |
oc_status_t | response_code, | ||
size_t | payload_size | ||
) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
will respond with CBOR.
The function oc_send_response is called at the end of a oc_request_callback_t to inform the caller about the status of the requested action.
Note that OC_STATUS_BAD_REQUEST for multicast will not send a response (e.g. threated as OC_IGNORE)
request | the request being responded to |
response_code | the status of the response |
payload_size | the payload size of the response |
void oc_send_diagnostic_message | ( | oc_request_t * | request, |
const char * | msg, | ||
size_t | msg_len, | ||
oc_status_t | response_code | ||
) |
send a diagnostic payload
request | the request |
msg | the message in ASCII |
msg_len | the length of the message |
response_code | the CoAP response code |
void oc_send_empty_separate_response | ( | oc_separate_response_t * | handle, |
oc_status_t | response_code | ||
) |
Called to send the deferred response to a GET, PUT, POST or DELETE request, with an empty payload.
The function oc_send_empty_separate_response is called to initiate transfer of the response.
[in] | handle | instance of the internal struct that was passed to oc_indicate_separate_response() |
[in] | response_code | the status of the response |
void oc_send_json_response | ( | oc_request_t * | request, |
oc_status_t | response_code | ||
) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
will respond with JSON.
The function oc_send_response is called at the end of a oc_request_callback_t to inform the caller about the status of the requested action.
Note that OC_STATUS_BAD_REQUEST for multicast will not send a response (e.g. threated as OC_IGNORE)
request | the request being responded to |
response_code | the request being responded to |
void oc_send_linkformat_response | ( | oc_request_t * | request, |
oc_status_t | response_code, | ||
size_t | response_length | ||
) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
will respond with LINK-FORMAT.
Note that OC_STATUS_BAD_REQUEST for multicast will not send a response (e.g. threated as OC_IGNORE)
request | the request being responded to |
response_code | the request being responded to |
response_length | the framed response length |
void oc_send_response | ( | oc_request_t * | request, |
oc_status_t | response_code | ||
) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed, will respond with CBOR.
The function oc_send_response is called at the end of a oc_request_callback_t to inform the caller about the status of the requested action.
[in] | request | the request being responded to |
[in] | response_code | the status of the response |
void oc_send_response_no_format | ( | oc_request_t * | request, |
oc_status_t | response_code | ||
) |
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
will respond without setting the content format.
Example usecase: When the response has empty payload.
request | the request being responded to |
response_code | the request being responded to |
void oc_send_response_raw | ( | oc_request_t * | request, |
const uint8_t * | payload, | ||
size_t | size, | ||
oc_content_format_t | content_format, | ||
oc_status_t | response_code | ||
) |
send the request, no processing
request | the request to send |
payload | the payload for the request |
size | the payload size |
content_format | the content format |
response_code | the response code to send |
void oc_send_separate_response | ( | oc_separate_response_t * | handle, |
oc_status_t | response_code | ||
) |
Called to send the deferred response to a GET, PUT, POST or DELETE request.
The function oc_send_separate_response is called to initiate transfer of the response.
[in] | handle | instance of the internal struct that was passed to oc_indicate_separate_response() |
[in] | response_code | the status of the response |
void oc_set_separate_response_buffer | ( | oc_separate_response_t * | handle | ) |
Set a response buffer for holding the response payload.
When a deferred response is ready, pass in the same oc_separate_response_t
that was handed to oc_indicate_separate_response() for delaying the initial response.
[in] | handle | instance of the oc_separate_response_t that was passed to the oc_indicate_separate_response() function |