Documentation

Documentation

Includes

tuya_cloud_types.h

#include "tuya_cloud_types.h"
#include "tuya_cloud_types.h"

uni_pointer.h

#include "uni_pointer.h"
#include "uni_pointer.h"

sys_timer.h

#include "sys_timer.h"
#include "sys_timer.h"

tuya_hal_system.h

#include "tuya_hal_system.h"
#include "tuya_hal_system.h"

Macros

Marco _UNI_MSG_QUEUE_H

#define _UNI_MSG_QUEUE_H


      

Marco USE_SEM_COUNTING

#define USE_SEM_COUNTING 1


      

Marco PROC_MSG_DELAY

#define PROC_MSG_DELAY 100


      

Marco UNVALUED_MSGID

#define UNVALUED_MSGID 65535 // invalid message id

      

Functions

Func CreateMsgQueAndInit

OPERATE_RET CreateMsgQueAndInit(OUT MSG_QUE_HANDLE *pMsgQueHandle);
/**
 * @brief Create and init the message queue
 *
 * @param[in] pMsgQueHandle: the handle of message queue
 *
 * @note This API is used for initializing the message queue
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func AddMsgNodeToQueue

OPERATE_RET AddMsgNodeToQueue(IN CONST MSG_QUE_HANDLE msgQueHandle,\
                                    IN CONST MSG_ID msgID, IN CONST P_MSG_DATA pMsgData,\
                                    IN CONST MSG_DATA_LEN msgDataLen,\
                                    IN CONST MSG_TYPE msgType);
/**
 * @brief Add message to queue
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] msgID: message id
 * @param[in] pMsgData: message data
 * @param[in] pMsgData: message data lenth
 * @param[in] msgType: message type
 *
 * @note This API is used for adding a timer to the queue
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func GetMsgNodeFromQueue

OPERATE_RET GetMsgNodeFromQueue(IN CONST MSG_QUE_HANDLE msgQueHandle,\
                                       IN CONST MSG_ID msgID, OUT P_MSG_LIST *ppMsgListNode);
/**
 * @brief Get message node from queue
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] msgID: message id
 * @param[out] ppMsgListNode: message node
 *
 * @note This API is used for getting message node from the queue
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func GetFirstMsgFromQueue

OPERATE_RET GetFirstMsgFromQueue(IN CONST MSG_QUE_HANDLE msgQueHandle,\
                                        OUT P_MSG_LIST *ppMsgListNode);
/**
 * @brief Get the first message node from queue
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[out] ppMsgListNode: message node
 *
 * @note This API is used for getting the first message node from queue
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func GetMsgNodeNum

OPERATE_RET GetMsgNodeNum(IN CONST MSG_QUE_HANDLE msgQueHandle, OUT PINT_T pMsgNodeNum);
/**
 * @brief Get the count of message node from queue
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[out] pMsgNodeNum: the count of message node
 *
 * @note This API is used for getting the first message node from queue
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func DelAndFreeMsgNodeFromQueue

OPERATE_RET DelAndFreeMsgNodeFromQueue(IN CONST MSG_QUE_HANDLE msgQueHandle, IN CONST P_MSG_LIST pMsgListNode);
/**
 * @brief Delete and free the message node from queue
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] pMsgListNode: the message node
 *
 * @note This API is used to delete and free the message node from queue
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func ReleaseMsgQue

OPERATE_RET ReleaseMsgQue(IN CONST MSG_QUE_HANDLE msgQueHandle);
/**
 * @brief Release the message queue
 *
 * @param[in] msgQueHandle: the handle of the message queue
 *
 * @note This API is used releasing the message queue
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func PostMessage

OPERATE_RET PostMessage(IN CONST MSG_QUE_HANDLE msgQueHandle,\
                           IN CONST MSG_ID msgID,\
                           IN CONST P_MSG_DATA pMsgData,\
                           IN CONST MSG_DATA_LEN msgDataLen);
/**
 * @brief Post a message.
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] msgID: message id
 * @param[in] pMsgData: message data
 * @param[in] msgDataLen: message data len
 *
 * @note This API is used for posting a message
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func PostInstancyMsg

OPERATE_RET PostInstancyMsg(IN CONST MSG_QUE_HANDLE msgQueHandle,\
                                 IN CONST MSG_ID msgID,\
                                 IN CONST P_MSG_DATA pMsgData,\
                                 IN CONST MSG_DATA_LEN msgDataLen);
/**
 * @brief Post a message instantly
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] msgID: message id
 * @param[in] pMsgData: message data
 * @param[in] msgDataLen: message data len
 *
 * @note This API is used for posting a message instantly
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func WaitMessage

OPERATE_RET WaitMessage(IN CONST MSG_QUE_HANDLE msgQueHandle, OUT P_MSG_LIST *ppMsgListNode);
/**
 * @brief Wait a message.
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[out] ppMsgListNode: message node
 *
 * @note This API is used for waiting a message
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func RegisterMsgCb

OPERATE_RET RegisterMsgCb(IN CONST MSG_QUE_HANDLE msgQueHandle,\
                              IN CONST MSG_CALLBACK msg_cb, OUT MSG_ID *msg_id);
/**
 * @brief Regist callback function for message.
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] msg_cb: message callback function
 * @param[out] msg_id: message id
 *
 * @note This API is used for registing message's callback function.
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func UnregisterMsgCb

OPERATE_RET UnregisterMsgCb(IN CONST MSG_QUE_HANDLE msgQueHandle,IN CONST MSG_ID msgID);
/**
 * @brief Unregist callback function for message.
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] msgID: message id
 *
 * @note This API is used for unRegisting message's callback function.
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func MessageLoop

VOID MessageLoop(IN CONST MSG_QUE_HANDLE msgQueHandle);
/**
 * @brief Message loop processing.
 *
 * @param[in] msgQueHandle: the handle of the message queue
 *
 * @note This API is used for Message loop processing.
 *
 * @return VOID
 */

Func create_tm_msg_hand

OPERATE_RET create_tm_msg_hand(IN CONST MSG_QUE_HANDLE msgQueHandle,IN CONST VOID *data,\
                                     IN CONST TM_MSG_CB cb,OUT TM_MSG_S **tm_msg);
/**
 * @brief Create timer message handle.
 *
 * @param[in] msgQueHandle: the handle of the message queue
 * @param[in] data: message data
 * @param[in] cb: callback function
 * @param[out] tm_msg: timer message info
 *
 * @note This API is used for creating a timer message handle
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func start_tm_msg

OPERATE_RET start_tm_msg(IN CONST TM_MSG_S *tm_msg,IN CONST TIME_MS timeCycle,\
                             IN CONST TIMER_TYPE timer_type);
/**
 * @brief Start the timer message.
 *
 * @param[in] tm_msg: timer message info
 * @param[in] timeCycle: cycle time of the timer
 * @param[in] timer_type: timer type, cycle or once
 *
 * @note This API is used for starting the timer message
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func stop_tm_msg

OPERATE_RET stop_tm_msg(IN CONST TM_MSG_S *tm_msg);
/**
 * @brief Stop the timer message.
 *
 * @param[in] tm_msg: timer message info
 *
 * @note This API is used for stopping the timer message
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Func release_tm_msg_hand

VOID release_tm_msg_hand(IN CONST TM_MSG_S *tm_msg);
/**
 * @brief Release the timer message.
 *
 * @param[in] tm_msg: timer message info
 *
 * @note This API is used for releasing the timer message
 *
 * @return VOID
 */

Vars

Variable s_tm_msg

struct s_tm_msg;

      

Consts

Types

Typedefs

Typedef MSG_QUE_HANDLE

typedef PVOID_T MSG_QUE_HANDLE; // message queue handle


      

Typedef MSG_ID

typedef USHORT_T MSG_ID;         // message id


      

Typedef P_MSG_DATA

typedef PVOID_T P_MSG_DATA;      // message data


      

Typedef MSG_DATA_LEN

typedef UINT_T MSG_DATA_LEN;     // message data lenth


      

Typedef MSG_TYPE

typedef UINT_T MSG_TYPE; 
#define INSTANCY_MESSAGE 0 // instant message type
#define NORMAL_MESSAGE 1   // normal message type

/**
 * @brief Definition of message type
 */

Typedef MESSAGE,*P_MESSAGE;

typedef struct
{
   MSG_ID msgID;           // message id
   P_MSG_DATA pMsgData;    // message data
   MSG_DATA_LEN msgDataLen; // message data len
}MESSAGE,*P_MESSAGE;
/**
 * @brief Init param of message
 */

Typedef MSG_LIST,*P_MSG_LIST;

typedef struct
{
   LIST_HEAD listHead; // list head
   MESSAGE msg;        // message info
}MSG_LIST,*P_MSG_LIST;
/**
 * @brief message list
 */

Typedef MSG_CALLBACK

typedef VOID(*MSG_CALLBACK)(MESSAGE *msg);
// message processing callback

Typedef TM_MSG_CB

typedef VOID(* TM_MSG_CB)(struct s_tm_msg *tm_msg); // timer message callback


      

Typedef TM_MSG_S;

typedef struct s_tm_msg {
   TIMER_ID timer;             // timer id
   MSG_QUE_HANDLE msgQueHandle; // timer queue handle
   TM_MSG_CB cb;               // timer callback function
   MSG_ID msgID;               // message id
   VOID *data;                 // message data
}TM_MSG_S;
/**
 * @brief timer message definition
 */

Typedef MSG_ENTRY_S;

typedef struct {
   MSG_ID *mid;        // message id
   MSG_CALLBACK msg_cb; // message callback
}MSG_ENTRY_S;
/**
 * @brief message entry definition
 */

Typedef TM_MSG_ENTRY_S;

typedef struct {
   TM_MSG_S **tm_msg;   //timer message info
   TM_MSG_CB tmm_msg_cb; //timer message callback
}TM_MSG_ENTRY_S;
/**
 * @brief timer message entry definition
 */