Prvni ulozeni z chegewara githubu

This commit is contained in:
2023-02-25 16:13:53 +01:00
commit 01eb80dfe2
3279 changed files with 638407 additions and 0 deletions

View File

@@ -0,0 +1,171 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <esp_err.h>
#include <esp_event.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* Super Admin User Flag*/
#define ESP_RMAKER_USER_ROLE_SUPER_ADMIN (1 << 0)
/** Primary User Flag */
#define ESP_RMAKER_USER_ROLE_PRIMARY_USER (1 << 1)
/** Secondary User Flag */
#define ESP_RMAKER_USER_ROLE_SECONDARY_USER (1 << 2)
/** RainMaker Command Response TLV8 Types */
typedef enum {
/** Request Id : Variable length string, max 32 characters*/
ESP_RMAKER_TLV_TYPE_REQ_ID = 1,
/** User Role : 1 byte */
ESP_RMAKER_TLV_TYPE_USER_ROLE,
/** Status : 1 byte */
ESP_RMAKER_TLV_TYPE_STATUS,
/** Timestamp : TBD */
ESP_RMAKER_TLV_TYPE_TIMESTAMP,
/** Command : 2 bytes*/
ESP_RMAKER_TLV_TYPE_CMD,
/** Data : Variable length */
ESP_RMAKER_TLV_TYPE_DATA
} esp_rmaker_tlv_type_t;
/* RainMaker Command Response Status */
typedef enum {
/** Success */
ESP_RMAKER_CMD_STATUS_SUCCESS = 0,
/** Generic Failure */
ESP_RMAKER_CMD_STATUS_FAILED,
/** Invalid Command */
ESP_RMAKER_CMD_STATUS_CMD_INVALID,
/** Authentication Failed */
ESP_RMAKER_CMD_STATUS_AUTH_FAIL,
/** Command not found */
ESP_RMAKER_CMD_STATUS_NOT_FOUND,
/** Last status value */
ESP_RMAKER_CMD_STATUS_MAX,
} esp_rmaker_cmd_status_t;
#define REQ_ID_LEN 32
typedef struct {
/** Command id */
uint16_t cmd;
/** Request id */
char req_id[REQ_ID_LEN];
/** User Role */
uint8_t user_role;
} esp_rmaker_cmd_ctx_t;
typedef enum {
/** Standard command: Set Parameters */
ESP_RMAKER_CMD_TYPE_SET_PARAMS = 1,
/** Last Standard command */
ESP_RMAKER_CMD_STANDARD_LAST = 0xfff,
/** Custom commands can start from here */
ESP_RMAKER_CMD_CUSTOM_START = 0x1000
} esp_rmaker_cmd_t;
/** Command Response Handler
*
* If any command data is received from any of the supported transports (which are outside the scope of this core framework),
* this function should be called to handle it and fill in the response.
*
* @param[in] input Pointer to input data.
* @param[in] input_len data len.
* @param[in] output Pointer to output data which should be set by the handler.
* @param[out] output_len Length of output generated.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_cmd_response_handler(const void *input, size_t input_len, void **output, size_t *output_len);
/** Prototype for Command Handler
*
* The handler to be invoked when a given command is received.
*
* @param[in] in_data Pointer to input data.
* @param[in] in_len data len.
* @param[in] out_data Pointer to output data which should be set by the handler.
* @param[out] out_len Length of output generated.
* @param[in] ctx Command Context.
* @param[in] priv Private data, if specified while registering command.
*
* @return ESP_OK on success.
* @return error on failure.
*/
typedef esp_err_t (*esp_rmaker_cmd_handler_t)(const void *in_data, size_t in_len, void **out_data, size_t *out_len, esp_rmaker_cmd_ctx_t *ctx, void *priv);
/** Register a new command
*
* @param[in] cmd Command Identifier. Custom commands should start beyond ESP_RMAKER_CMD_STANDARD_LAST
* @param[in] access User Access for the command. Can be an OR of the various user role flags like ESP_RMAKER_USER_ROLE_SUPER_ADMIN,
* ESP_RMAKER_USER_ROLE_PRIMARY_USER and ESP_RMAKER_USER_ROLE_SECONDARY_USER
* @param[in] handler The handler to be invoked when the given command is received.
* @param[in] free_on_return Flag to indicate of the framework should free the output after it has been sent as response.
* @paramp[in] priv Optional private data to be passed to the handler.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_cmd_register(uint16_t cmd, uint8_t access, esp_rmaker_cmd_handler_t handler, bool free_on_return, void *priv);
/** De-register a command
*
* @param[in] cmd Command Identifier. Custom commands should start beyond ESP_RMAKER_CMD_STANDARD_LAST
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_cmd_deregister(uint16_t cmd);
/** Prototype for Command sending function (TESTING only)
*
* @param[in] data Pointer to the data to be sent.
* @param[in[ data_len Size of data to be sent.
* @param[in] priv Private data, if applicable.
*
* @return ESP_OK on success.
* @return error on failure.
*/
typedef esp_err_t (*esp_rmaker_cmd_send_t)(const void *data, size_t data_len, void *priv);
/** Send Test command (TESTING only)
*
* @param[in] req_id NULL terminated request id of max 32 characters.
* @param[in] role User Role flag.
* @param[in] cmd Command Identifier.
* @param[in] data Pointer to data for the command.
* @param[in] data_size Size of the data.
* @param[in] cmd_send Transport specific function to send the command data.
* @param[in] priv Private data (if any) to be sent to cmd_send.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_cmd_resp_test_send(const char *req_id, uint8_t role, uint16_t cmd, const void *data, size_t data_size, esp_rmaker_cmd_send_t cmd_send, void *priv);
/** Parse response (TESTING only)
*
* @param[in] response Pointer to the response received
* @param[in] response_len Length of the response
* @param[in] priv Private data, if any. Can be NULL.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_cmd_resp_parse_response(const void *response, size_t response_len, void *priv);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,60 @@
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <esp_event.h>
#ifdef __cplusplus
extern "C"
{
#endif
/** ESP RainMaker Common Event Base */
ESP_EVENT_DECLARE_BASE(RMAKER_COMMON_EVENT);
typedef enum {
/** Node reboot has been triggered. The associated event data is the time in seconds
* (type: uint8_t) after which the node will reboot. Note that this time may not be
* accurate as the events are received asynchronously.*/
RMAKER_EVENT_REBOOT,
/** Wi-Fi credentials reset. Triggered after calling esp_rmaker_wifi_reset() */
RMAKER_EVENT_WIFI_RESET,
/** Node reset to factory defaults. Triggered after calling esp_rmaker_factory_reset() */
RMAKER_EVENT_FACTORY_RESET,
/** Connected to MQTT Broker */
RMAKER_MQTT_EVENT_CONNECTED,
/** Disconnected from MQTT Broker */
RMAKER_MQTT_EVENT_DISCONNECTED,
/** MQTT message published successfully.
* Event data will contain the message ID (integer) of published message.
*/
RMAKER_MQTT_EVENT_PUBLISHED,
/** POSIX Timezone Changed. Associated data would be NULL terminated POSIX Timezone
* Eg. "PST8PDT,M3.2.0,M11.1.0" */
RMAKER_EVENT_TZ_POSIX_CHANGED,
/** Timezone Changed. Associated data would be NULL terminated Timezone.
* Eg. "America/Los_Angeles"
* Note that whenever this event is received, the RMAKER_EVENT_TZ_POSIX_CHANGED event
* will also be received, but not necessarily vice versa.
*/
RMAKER_EVENT_TZ_CHANGED,
/**
* MQTT message deleted from the outbox if the message couldn't have been sent and acknowledged.
* Event data will contain the message ID (integer) of deleted message.
* Valid only if CONFIG_MQTT_REPORT_DELETED_MESSAGES is enabled.
*/
RMAKER_MQTT_EVENT_MSG_DELETED,
} esp_rmaker_common_event_t;
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,61 @@
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <esp_err.h>
#include <esp_event.h>
#ifdef __cplusplus
extern "C"
{
#endif
/** Initialize Factory NVS
*
* This initializes the Factory NVS partition which will store data
* that should not be cleared even after a reset to factory.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_factory_init(void);
/** Get value from factory NVS
*
* This will search for the specified key in the Factory NVS partition,
* allocate the required memory to hold it, copy the value and return
* the pointer to it. It is responsibility of the caller to free the
* memory when the value is no more required.
*
* @param[in] key The key of the value to be read from factory NVS.
*
* @return pointer to the value on success.
* @return NULL on failure.
*/
void *esp_rmaker_factory_get(const char *key);
/** Set a value in factory NVS
*
* This will write the value for the specified key into factory NVS.
*
* @param[in] key The key for the value to be set in factory NVS.
* @param[in] data Pointer to the value.
* @param[in] len Length of the value.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_factory_set(const char *key, void *value, size_t len);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,169 @@
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <esp_err.h>
#include <esp_event.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define RMAKER_MQTT_QOS0 0
#define RMAKER_MQTT_QOS1 1
/** MQTT Connection parameters */
typedef struct {
/** MQTT Host */
char *mqtt_host;
/** Client ID */
char *client_id;
/** Client Certificate in NULL terminated PEM format */
char *client_cert;
/** Client Key in NULL terminated PEM format */
char *client_key;
/** Server Certificate in NULL terminated PEM format */
char *server_cert;
} esp_rmaker_mqtt_conn_params_t;
/** MQTT Get Connection Parameters function prototype
*
* @return Pointer to \ref esp_rmaker_mqtt_conn_params_t on success.
* @return NULL on failure.
*/
typedef esp_rmaker_mqtt_conn_params_t *(*esp_rmaker_mqtt_get_conn_params_t)(void);
/** MQTT Subscribe callback prototype
*
* @param[in] topic Topic on which the message was received
* @param[in] payload Data received in the message
* @param[in] payload_len Length of the data
* @param[in] priv_data The private data passed during subscription
*/
typedef void (*esp_rmaker_mqtt_subscribe_cb_t)(const char *topic, void *payload, size_t payload_len, void *priv_data);
/** MQTT Init function prototype
*
* @param[in] conn_params The MQTT connection parameters. If NULL is passed, it should internally use the
* \ref esp_rmaker_mqtt_get_conn_params call if registered.
*
* @return ESP_OK on success.
* @return error in case of any error.
*/
typedef esp_err_t (*esp_rmaker_mqtt_init_t)(esp_rmaker_mqtt_conn_params_t *conn_params);
/** MQTT Deinit function prototype
*
* Call this function after MQTT has disconnected.
*/
typedef void (*esp_rmaker_mqtt_deinit_t)(void);
/** MQTT Connect function prototype
*
* Starts the connection attempts to the MQTT broker.
* This should ideally be called after successful network connection.
*
* @return ESP_OK on success.
* @return error in case of any error.
*/
typedef esp_err_t (*esp_rmaker_mqtt_connect_t)(void);
/** MQTT Disconnect function prototype
*
* Disconnects from the MQTT broker.
*
* @return ESP_OK on success.
* @return error in case of any error.
*/
typedef esp_err_t (*esp_rmaker_mqtt_disconnect_t)(void);
/** MQTT Publish Message function prototype
*
* @param[in] topic The MQTT topic on which the message should be published.
* @param[in] data Data to be published.
* @param[in] data_len Length of the data.
* @param[in] qos Quality of service for the message.
* @param[out] msg_id If a non NULL pointer is passed, the id of the published message will be returned in this.
*
* @return ESP_OK on success.
* @return error in case of any error.
*/
typedef esp_err_t (*esp_rmaker_mqtt_publish_t)(const char *topic, void *data, size_t data_len, uint8_t qos, int *msg_id);
/** MQTT Subscribe function prototype
*
* @param[in] topic The topic to be subscribed to.
* @param[in] cb The callback to be invoked when a message is received on the given topic.
* @param[in] qos Quality of service for the subscription.
* @param[in] priv_data Optional private data to be passed to the callback.
*
* @return ESP_OK on success.
* @return error in case of any error.
*/
typedef esp_err_t (*esp_rmaker_mqtt_subscribe_t)(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, uint8_t qos, void *priv_data);
/** MQTT Unsubscribe function prototype
*
* @param[in] topic Topic from which to unsubscribe.
*
* @return ESP_OK on success.
* @return error in case of any error.
*/
typedef esp_err_t (*esp_rmaker_mqtt_unsubscribe_t)(const char *topic);
/** MQTT configuration */
typedef struct {
/** Flag to indicate if the MQTT config setup is done */
bool setup_done;
/** Pointer to the Get MQTT params function. */
esp_rmaker_mqtt_get_conn_params_t get_conn_params;
/** Pointer to MQTT Init function. */
esp_rmaker_mqtt_init_t init;
/** Pointer to MQTT Deinit function. */
esp_rmaker_mqtt_deinit_t deinit;
/** Pointer to MQTT Connect function. */
esp_rmaker_mqtt_connect_t connect;
/** Pointer to MQTQ Disconnect function */
esp_rmaker_mqtt_disconnect_t disconnect;
/** Pointer to MQTT Publish function */
esp_rmaker_mqtt_publish_t publish;
/** Pointer to MQTT Subscribe function */
esp_rmaker_mqtt_subscribe_t subscribe;
/** Pointer to MQTT Unsubscribe function */
esp_rmaker_mqtt_unsubscribe_t unsubscribe;
} esp_rmaker_mqtt_config_t;
/** Setup MQTT Glue
*
* This function initializes MQTT glue layer with all the default functions.
*
* @param[out] mqtt_config Pointer to an allocated MQTT configuration structure.
*
* @return ESP_OK on success.
* @return error in case of any error.
*/
esp_err_t esp_rmaker_mqtt_glue_setup(esp_rmaker_mqtt_config_t *mqtt_config);
/* Get the ESP AWS PPI String
*
* @return pointer to a NULL terminated PPI string on success.
* @return NULL in case of any error.
*/
const char *esp_get_aws_ppi(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,205 @@
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <sntp.h>
#include <esp_err.h>
#include <esp_heap_caps.h>
#include <sdkconfig.h>
#ifdef __cplusplus
extern "C"
{
#endif
#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC))
#define MEM_ALLOC_EXTRAM(size) heap_caps_malloc(size, MALLOC_CAP_SPIRAM)
#define MEM_CALLOC_EXTRAM(num, size) heap_caps_calloc(num, size, MALLOC_CAP_SPIRAM)
#define MEM_REALLOC_EXTRAM(ptr, size) heap_caps_realloc(ptr, size, MALLOC_CAP_SPIRAM)
#else
#define MEM_ALLOC_EXTRAM(size) malloc(size)
#define MEM_CALLOC_EXTRAM(num, size) calloc(num, size)
#define MEM_REALLOC_EXTRAM(ptr, size) realloc(ptr, size)
#endif
typedef struct esp_rmaker_time_config {
/** If not specified, then 'CONFIG_ESP_RMAKER_SNTP_SERVER_NAME' is used as the SNTP server. */
char *sntp_server_name;
/** Optional callback to invoke, whenever time is synchronised. This will be called
* periodically as per the SNTP polling interval (which is 60min by default).
* If kept NULL, the default callback will be invoked, which will just print the
* current local time.
*/
sntp_sync_time_cb_t sync_time_cb;
} esp_rmaker_time_config_t;
/** Reboot the device after a delay
*
* This API just starts a reboot timer and returns immediately.
* The actual reboot is trigerred asynchronously in the timer callback.
* This is useful if you want to reboot after a delay, to allow other tasks to finish
* their operations (Eg. MQTT publish to indicate OTA success). The \ref RMAKER_EVENT_REBOOT
* event is triggered when the reboot timer is started.
*
* @param[in] seconds Time in seconds after which the device should reboot.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_reboot(int8_t seconds);
/** Reset Wi-Fi credentials and (optionally) reboot
*
* This will reset just the Wi-Fi credentials and (optionally) trigger a reboot.
* This is useful when you want to keep all the entries in NVS memory
* intact, but just change the Wi-Fi credentials. The \ref RMAKER_EVENT_WIFI_RESET
* event is triggered when this API is called. The actual reset will happen after a
* delay if reset_seconds is not zero.
*
* @note This reset and reboot operations will happen asynchronously depending
* on the values passed to the API.
*
* @param[in] reset_seconds Time in seconds after which the reset should get triggered.
* This will help other modules take some actions before the device actually resets.
* If set to zero, the operation would be performed immediately.
* @param[in] reboot_seconds Time in seconds after which the device should reboot. If set
* to negative value, the device will not reboot at all.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_wifi_reset(int8_t reset_seconds, int8_t reboot_seconds);
/** Reset to factory defaults and reboot
*
* This will clear entire NVS partition and (optionally) trigger a reboot.
* The \ref RMAKER_EVENT_FACTORY_RESET event is triggered when this API is called.
* The actual reset will happen after a delay if reset_seconds is not zero.
*
* @note This reset and reboot operations will happen asynchronously depending
* on the values passed to the API.
*
* @param[in] reset_seconds Time in seconds after which the reset should get triggered.
* This will help other modules take some actions before the device actually resets.
* If set to zero, the operation would be performed immediately.
* @param[in] reboot_seconds Time in seconds after which the device should reboot. If set
* to negative value, the device will not reboot at all.
*
* @return ESP_OK on success.
* @return error on failure.
*/
esp_err_t esp_rmaker_factory_reset(int8_t reset_seconds, int8_t reboot_seconds);
/** Initialize time synchronization
*
* This API initializes SNTP for time synchronization.
*
* @param[in] config Configuration to be used for SNTP time synchronization. The default configuration is used if NULL is passed.
*
* @return ESP_OK on success
* @return error on failure
*/
esp_err_t esp_rmaker_time_sync_init(esp_rmaker_time_config_t *config);
/** Check if current time is updated
*
* This API checks if the current system time is updated against the reference time of 1-Jan-2019.
*
* @return true if time is updated
* @return false if time is not updated
*/
bool esp_rmaker_time_check(void);
/** Wait for time synchronization
*
* This API waits for the system time to be updated against the reference time of 1-Jan-2019.
* This is a blocking call.
*
* @param[in] ticks_to_wait Number of ticks to wait for time synchronization. Accepted values: 0 to portMAX_DELAY.
*
* @return ESP_OK on success
* @return error on failure
*/
esp_err_t esp_rmaker_time_wait_for_sync(uint32_t ticks_to_wait);
/** Set POSIX timezone
*
* Set the timezone (TZ environment variable) as per the POSIX format
* specified in the [GNU libc documentation](https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html).
* Eg. For China: "CST-8"
* For US Pacific Time (including daylight saving information): "PST8PDT,M3.2.0,M11.1.0"
*
* @param[in] tz_posix NULL terminated TZ POSIX string
*
* @return ESP_OK on success
* @return error on failure
*/
esp_err_t esp_rmaker_time_set_timezone_posix(const char *tz_posix);
/** Set timezone location string
*
* Set the timezone as a user friendly location string.
* Check [here](https://rainmaker.espressif.com/docs/time-service.html) for a list of valid values.
*
* Eg. For China: "Asia/Shanghai"
* For US Pacific Time: "America/Los_Angeles"
*
* @note Setting timezone using this API internally also sets the POSIX timezone string.
*
* @param[in] tz NULL terminated Timezone location string
*
* @return ESP_OK on success
* @return error on failure
*/
esp_err_t esp_rmaker_time_set_timezone(const char *tz);
/** Get the current POSIX timezone
*
* This fetches the current timezone in POSIX format, read from NVS.
*
* @return Pointer to a NULL terminated POSIX timezone string on success.
* Freeing this is the responsibility of the caller.
* @return NULL on failure.
*/
char *esp_rmaker_time_get_timezone_posix(void);
/** Get the current timezone
*
* This fetches the current timezone in POSIX format, read from NVS.
*
* @return Pointer to a NULL terminated timezone string on success.
* Freeing this is the responsibility of the caller.
* @return NULL on failure.
*/
char *esp_rmaker_time_get_timezone(void);
/** Get printable local time string
*
* Get a printable local time string, with information of timezone and Daylight Saving.
* Eg. "Tue Sep 1 09:04:38 2020 -0400[EDT], DST: Yes"
* "Tue Sep 1 21:04:04 2020 +0800[CST], DST: No"
*
*
* @param[out] buf Pointer to a pre-allocated buffer into which the time string will
* be populated.
* @param[in] buf_len Length of the above buffer.
*
* @return ESP_OK on success
* @return error on failure
*/
esp_err_t esp_rmaker_get_local_time_str(char *buf, size_t buf_len);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,82 @@
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <esp_err.h>
#include <esp_event.h>
#ifdef __cplusplus
extern "C"
{
#endif
/** Prototype for ESP RainMaker Work Queue Function
*
* @param[in] priv_data The private data associated with the work function.
*/
typedef void (*esp_rmaker_work_fn_t)(void *priv_data);
/** Initializes the Work Queue
*
* This initializes the work queue, which is basically a mechanism to run
* tasks in the context of a dedicated thread. You can start queueing tasks
* after this, but they will get executed only after calling
* esp_rmaker_work_queue_start().
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t esp_rmaker_work_queue_init(void);
/** De-initialize the Work Queue
*
* This de-initializes the work queue. Note that the work queue needs to
* be stopped using esp_rmaker_work_queue_stop() before calling this.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t esp_rmaker_work_queue_deinit(void);
/** Start the Work Queue
*
* This starts the Work Queue thread which then starts executing the tasks queued.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t esp_rmaker_work_queue_start(void);
/** Stop the Work Queue
*
* This stops a running Work Queue.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t esp_rmaker_work_queue_stop(void);
/** Queue execution of a function in the Work Queue's context
*
* This API queues a work function for execution in the Work Queue Task's context.
*
* @param[in] work_fn The Work function to be queued.
* @param[in] priv_data Private data to be passed to the work function.
*
* @return ESP_OK on success.
* @return error in case of failure.
*/
esp_err_t esp_rmaker_work_queue_add_task(esp_rmaker_work_fn_t work_fn, void *priv_data);
#ifdef __cplusplus
}
#endif