TuyaOS SDK for Linux

Last Updated on : 2022-11-24 09:19:59download

Using the networking capabilities of smart devices, TuyaOS SDK serves as the software middleware to build communication links with Tuya Cloud and Tuya’s apps and perform Tuya standard data transmission. This topic describes the TuyaOS SDK for Linux.

Prerequisites

  • Currently, TuyaOS SDK for Linux only applies to devices with screens. You can bind and activate devices by scanning the QR code.
  • Before development, you need to register an account on the Tuya IoT Platform to get the required information for device development, including the product ID, authorization code, and more. For more information about specific operations, see related documentation in Docs Center.

SDK download

The TuyaOS SDK for Linux is provided in the form of a dynamic-link library (.so) or static library (.a) in C. Therefore, you need to use a cross-compilation toolchain to generate an SDK.

The TuyaOS SDK for Linux will be regularly uploaded to GitHub. If the compiled product already contains your cross-compilation toolchain, you can download and use it directly.

Directory structure

For the description of the directory structure and usage, see the README.md file included in the package.

├── build_App.sh ├── CHANGELOG.md ├── Apps ├── platforms └── sdk ├── include └── lib ├── libtuya_iot.a

SDK initialization

Device authentication

  • The one-key-per-device authentication mechanism is used. The device is programmed with the unique UUID and authKey.

  • The UUID and authKey are in pairs, and each device must have its unique UUID and authKey. If you need multiple sets of UUID and authKey for debugging, you can submit a ticket for asking support.

  • The device authentication information is set through the interface of tuya_iot_set_gw_prod_info.

    Note: The PID, UUID, and authKey in the demo are only used for testing, not for physical products. Otherwise, physical products will be unavailable. You need to apply for a PID in the IoT Platform. Each device must have a unique UUID and authKey.

Interface initialization description

Initialization process

TuyaOS SDK for Linux

tuya_iot_init

  • Function prototype

    OPERATE_RET tuya_iot_init(IN CONST CHAR_T *fs_storge_path)
    
  • Summary

    It is used to initialize the Tuya IoT system and must be called first.

  • Parameters

    Parameter name Description
    fs_storge_path Assign a read and write path for the SDK. The path length cannot be greater than 110 bytes.
  • Return values

    Return values Description
    OPRT_OK Success
    Error codes Error codes returned when execution failed.

tuya_iot_get_sdk_info

  • Function prototype

    CHAR_T *tuya_iot_get_sdk_info(VOID);
    
  • Summary

    Get the SDK version information.

  • Parameters

    Parameter name Description
    VOID Empty
  • Return values

    Return values Description
    SDK information string Include compilation time, platform, version number, and functionalities.

TY_IOT_CBS_S

  • Function prototype

    typedef struct { GW_STATUS_CHANGED_CB gw_status_cb; GW_UG_INFORM_CB gw_ug_cb; GW_RESET_IFM_CB gw_reset_cb; DEV_OBJ_DP_CMD_CB dev_obj_dp_cb; DEV_RAW_DP_CMD_CB dev_raw_dp_cb; DEV_DP_QUERY_CB dev_dp_query_cb; ACTIVE_SHORTURL_CB active_shorturl; }TY_IOT_CBS_S;
  • Summary

    SDK user callback interface.

  • Member description

    Member name Description
    gw_status_cb It is called when the internal status of the SDK changes. For more information, see gw_status_cb.
    gw_ug_cb It is called when the SDK detects upgrades. For more information, see gw_ug_cb.
    gw_reset_cb It is called when the SDK is used to reset devices. For more information, see gw_reset_cb.
    dev_obj_dp_cb It is called when the SDK receives the data point (DP). For more information, see dev_obj_dp_cb.
    dev_raw_dp_cb It is called when the SDK receives the RAW DP. For more information, see dev_raw_dp_cb.
    dev_dp_query_cb It is called when the SDK receives DP query commands. For more information, see dev_dp_query_cb.
    active_shorturl It is called when the SDK receives QR code links. For more information, see active_shourturl_cb.
gw_status_cb
  • Function prototype

    VOID gw_status_cb(IN CONST GW_STATUS_E status);
    
    /* tuya sdk gateway status info */
    typedef BYTE_T GW_STATUS_E;
    #define GW_RESET            0 // gw reset
    #define GW_ACTIVED          1 // gw actived
    #define GW_FIRST_START      2 // start tuya-sdk in the first time.
    #define GW_NORMAL           3 // tuya-sdk is actived and started
    
  • Member description

    Member name Description
    GW_RESET It is called when resetting devices locally and removing devices from the app.
    GW_ACTIVED It is a one-time callback triggered only as successful activation.
    GW_FIRST_START It is called each time the device is restarted.
    GW_NORMAL It is called each time the device is restarted only if the device is successfully activated.

tuya_iot_soc_init

  • Function prototype

    OPERATE_RET tuya_iot_soc_init(IN CONST TY_IOT_CBS_S *cbs, IN CONST CHAR_T *product_key, IN CONST CHAR_T *sw_ver);
  • Functional description

    Initialize interfaces of the network module SoC.

  • Parameter description

    Name Description Type Required Setting method
    cbs The array of callback functions. You can implement your own functions by the callback functions. TY_IOT_CBS_S* Yes View the usage from examples.
    product_key The product key that is got from Tuya IoT Platform. String Yes The string cannot exceed 16 bytes.
    sw_ver: Software version No. String Yes Firmware version No. of the device. The valid format is “xx.xx.xx” (0 ≤ x ≤ 9).
  • Return value

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

tuya_iot_set_gw_prod_info

  • Function prototype

    OPERATE_RET tuya_iot_set_gw_prod_info(IN CONST GW_PROD_INFO_S *prod_info);

    Set the authorization information of the network module. The authorization information must be got from Tuya. Otherwise, the device cannot be used properly.

    typedef struct { CHAR_T *uuid; CHAR_T *auth_key; } GW_PROD_INFO_S;
  • Member description

    Member name Description
    uuid UUID string. It must not be NULL.
    auth_key auth_key string. It must not be NULL.
  • Parameters

    Parameter name Description
    prod_info Product information. see GW_PROD_INFO_S.
  • Return values

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

tuya_iot_reg_get_wf_nw_stat_cb

  • Function prototype

    OPERATE_RET tuya_iot_reg_get_wf_nw_stat_cb(IN CONST GET_WF_NW_STAT_CB nw_stat_cb);
  • Summary

    From the registered callback functions, you can get the current network status according to the parameters of callback functions.

  • Parameters

    Parameter name Description
    nw_stat_cb The callback function of registering the network status.

    The parameters of the callback function nw_stat_cb are of type GW_WIFI_NW_STAT_E, which are defined as follows:

    /* tuya sdk definition of wired-net status */
    typedef uint8_t GW_BASE_NW_STAT_T;
    
    /* offline in LAN.  user wired callback <tuya_hal_wired_station_conn> return <false> */
    #define GB_STAT_LAN_UNCONN 0
    
    /* online in LAN, offline in WAN.
     user wired callback <tuya_hal_wired_station_conn> return <true> but mqtt is offline
    */
    #define GB_STAT_LAN_CONN 1
    
    /* online in WAN.
     user wired callback <tuya_hal_wired_station_conn> return <true> and mqtt is online
    */
    #define GB_STAT_CLOUD_CONN 2
    
  • Return values

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

Device activation methods

QR code scanning

You can activate and bind devices by scanning the QR code with the Tuya Smart app.

Callback description

active_shourturl_cb

  • Function prototype

    VOID active_shourturl_cb(OUT CONST CHAR_T *shorturl);
    
  • Functional description

    The callback of getting QR code link.

  • Parameter description

    Name Description Type Required Setting method
    shorturl The format is {“shorturl”: “qrcode link”}. You need to convert the QR code link to a QR code. If the link cannot be got, NULL will be returned. CONST CHAR_T * Yes -
  • Return value. None.

Reset device

Use app to reset

You can reset devices from the app.

gw_reset_cb

Function prototype

VOID gw_reset_cb(GW_RESET_TYPE_E type);
  • Summary

    The callback function gw_reset_cb of registering TY_IOT_CBS_S.

  • Parameters

    Parameter name Description
    type Empty

    GW_RESET_TYPE_E definition:

    typedef enum { GW_LOCAL_RESET_FACTORY = 0, GW_REMOTE_UNACTIVE, GW_LOCAL_UNACTIVE, GW_REMOTE_RESET_FACTORY, GW_RESET_DATA_FACTORY, //need clear local data when active }GW_RESET_TYPE_E;

    Currently, the reset types of GW_REMOTE_RESET_FACTORY and GW_RESET_DATA_FACTORY are processed during the callback. After reset, the app shall be restarted.

  • Return values

    Return value Description
    VOID Empty

Locally reset

The SDK is capable of locally resetting the gateway. You can reset the gateway locally with the reset button.

tuya_iot_gw_unactive
  • Function prototype

    OPERATE_RET tuya_iot_gw_unactive(VOID);
  • Summary

    Reset devices and unbind the gateway from the app. Then, the gateway will be waiting for pairing (inactive status).

    Note: This function is asynchronous, and the callback gw_reset_cb will be triggered after execution. You only need to restart the process during this callback.

  • Parameters

    Parameter name Description
    VOID Empty
  • Return values

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

Data points of device

Process description

Tuya provides the MQTT-based network application protocol to implement device control and status reporting. MQTT is a lightweight publish-subscribe mode messaging protocol that is designed for IoT applications in low-bandwidth and unstable network environments.

TuyaOS SDK encapsulates the implementation of the MQTT protocol layer, which is abstracted as the data point (hereinafter referred to as DP). DP supports types of numeric, Boolean, enumeration, string, fault, and raw data, as simple as defining a C variable.

You need to create data points based on device functions in the Tuya IoT Platform. For more information about DP creation, see Custom Functions.

Features

  • Currently, up to 35 DPs can be created for each product. You need to use raw data to implement complex functions.
  • For Obj types, including Boolean (bool), numeric (value), string (string), enumeration (enum), and fault (bitmap), TuyaOS SDK filters continuously reported values and does not upload the identical values.

Interface description

dev_obj_dp_cb

  • Function prototype

    VOID dev_obj_dp_cb(IN CONST TY_RECV_OBJ_DP_S *dp);
    
  • Functional description

    The callback of OBJ DP information commands.

  • Parameter description

    Name Description Type Required Setting method
    dp TY_RECV_OBJ_DP_S includes:
    • Types of DP commands.
    • Device ID controlled by DPs.
    • Group ID.
      Note: The group ID mb_id is returned only if dtt_tp is multicast.
    • The length of DP struct array.
    • The DP struct array. See tuya_cloud_com_defs.h.
    TY_RECV_OBJ_DP_S* Yes See the DP definitions in the IoT Platform.
  • Return value

    Return value Description
    None No value is returned.
    Error codes Error codes returned when execution failed.

dev_raw_dp_cb

  • Function prototype

    VOID dev_raw_dp_cb(IN CONST TY_RECV_RAW_DP_S *dp);
    
  • Functional description

    The callback of raw DP information command.

  • Parameter description

    Name Description Type Required Setting method
    dp The struct includes:
    • Types of DP commands.
    • Device ID controlled by DPs.
    • Group ID.
      Note: The group ID mb_id is returned only if dtt_tp is multicast.
    • The length of DP struct array.
    • Raw data. See tuya_cloud_com_defs.h.
    TY_RECV_RAW_DP_S* Yes None
  • Return value

    None.

dev_dp_query_cb

  • Function prototype

    VOID dev_dp_query_cb(IN CONST TY_DP_QUERY_S *dp_qry);
    
  • Functional description

    Entry of querying specific device data. Optional implementation.

  • Parameter description

    Name Description Type Required Setting method
    dp_qry TY_DP_QUERY_S* Yes
  • Return value. None.

dev_report_dp_json_async

  • Function prototype

    OPERATE_RET dev_report_dp_json_async(IN CONST CHAR_T *dev_id, IN CONST TY_OBJ_DP_S *dp_data,IN CONST UINT_T cnt);
    
  • Functional description

    Report DP information in an asynchronous manner.

  • Parameter description

    Name Description Type Required Setting method
    dev_id Device ID String Yes Set according to device types:
    • Sub-device: ID of sub-devices.
    • Gateway or MCU: NULL.
    dp_data DP data struct Pointer of the struct array TY_OBJ_DP_S. Yes
    cnt The number of struct arrays dp_data. UINT_T Yes
  • Return value

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

dev_report_dp_raw_sync

  • Function prototype

    OPERATE_RET dev_report_dp_raw_sync (IN CONST CHAR_T *dev_id, IN CONST BYTE_T dpid, IN CONST 
    BYTE_T *data,IN CONST UINT_T len, 
                                      IN CONST UINT_T timeout);
    
  • Functional description

    The interface of synchronously reporting raw data. The caller guarantees the reliability of data reporting.

  • Parameter description

    Name Description Type Required Setting method
    dev_id Device ID String Yes Set according to device types:
    • Sub-device: ID of sub-devices.
    • Gateway or MCU: NULL.
    dpid DP ID UINT_T Yes
    data Data BYTE_T * Yes
    len Data length UINT_T Yes
    timeout Timeout interval for blocked functions UINT_T Yes In seconds.
  • Return value

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

dev_report_dp_stat_sync

  • Function prototype

    OPERATE_RET dev_report_dp_stat_sync (IN CONST CHAR_T *dev_id, IN CONST     TY_OBJ_DP_S *dp_data, IN CONST UINT_T cnt, IN CONST UINT_T timeout);
    
  • Functional description

    The interface of synchronously reporting struct data, which usually applies to reporting statistics data. The caller guarantees the reliability of data reporting.

  • Parameter description

    Name Description Type Required Setting method
    dev_id Device ID String Yes Set according to device types:
    • Sub-device: ID of sub-devices.
    • Gateway or MCU: NULL.
    dp_data DP information struct array TY_OBJ_DP_S * Yes
    cnt Length of DP status array UINT_T Yes
    timeout Timeout interval for blocked functions UINT_T Yes In seconds.
  • Return value

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

Firmware upgrades

Process description

Configuration description of firmware package

  • After the gateway or sub-device is successfully paired, the virtual ID in the device information from the app can be added to the whitelist for firmware upgrades.
  • Compile the firmware package to be upgraded. The firmware version must be greater than that running on the device.
  • Log in to the IoT Platform, find corresponding created products, and upload the configuration firmware package.
  • Operating instruction.

Start upgrades

After the device firmware is uploaded to the cloud, the device will not receive the upgrades message immediately. Currently, the following upgrade methods are available:

  • Notification upgrade: When opening the device panel for the first time, you will receive an upgrade prompt. You choose to upgrade or not.
  • Hardware silent upgrade: The device goes through a silent upgrade. After the device is restarted, it will send a request for a silent upgrade task to the cloud. If there is a task, the upgrade will be executed directly. Meanwhile, the progress bar is displayed in the device panel, and the device cannot be operated.
  • Forced upgrade: When opening the device panel for the first time, you will receive an upgrade prompt. You must choose to upgrade. Otherwise, the device cannot be operated.
  • Manual detection upgrade: You click the device panel and then click the top right corner to enter the device information to check for updates.

Firmware upgrade interaction process

TuyaOS SDK for Linux

Interface description

gw_ug_cb

  • Function prototype

    VOID gw_ug_cb(IN CONST FW_UG_S *fw);
  • Summary

    The callback function gw_ug_cb of registering TY_IOT_CBS_S.

  • Parameters

    Parameter name Description
    fw Firmware upgrade information

    FW_UG_S definition:

    /* tuya sdk ota firmware info */ typedef struct { DEV_TYPE_T tp; // firmware type UPGRADE_TYPE_T type; CHAR_T fw_url[FW_URL_LEN+1]; // firmware download url CHAR_T sw_ver[SW_VER_LEN+1]; // firmware version UINT_T file_size; // firmware size in BYTE CHAR_T fw_hmac[FW_HMAC_LEN+1]; // firmware hmac }FW_UG_S;

tuya_iot_upgrade_gw_notify

  • Function prototype

    OPERATE_RET tuya_iot_upgrade_gw(IN CONST FW_UG_S *fw, 
      							IN CONST GET_FILE_DATA_CB get_file_cb, 
      							IN CONST UPGRADE_NOTIFY_CB upgrd_nofity_cb, 
      							IN CONST PVOID_T pri_data, 
      							BOOL_T notify, 
      							UINT_T download_buf_size);
    
  • Functional description

    The interface of processing firmware upgrade for network modules.

  • Parameter description

    Name Description Type Required Remark
    fw Firmware information Pointer of FW_UG_S struct Yes
    get_file_cb Store downloaded files Callback function Yes
    upgrd_nofity_cb Notification of upgrade status Callback function Yes
    pri_data Parameters passed to get_file_cb and upgrd_nofity_cb Pointer No If no parameter is passed, it is set to NULL.
    notify Choose whether to report the upgrade progress by the SDK Boolean Yes TRUE means reporting by the SDK, and FALSE means reporting by the application layer.
    download_buf_size The maximum download cache in bytes UINT_T No If 0 is passed in, the maximum download cache is the SDK’s default cache size.
  • Return value

    Return value Description
    OPRT_OK Success
    Error codes Error codes returned when execution failed.

tuya_iot_dev_upgd_progress_rept

  • Function prototype

    OPERATE_RET tuya_iot_dev_upgd_progress_rept(IN CONST UINT_T percent, IN CONST CHAR_T *devid, IN CONST DEV_TYPE_T tp);
    
  • Functional description

    Report the upgrade progress.

  • Parameter description

    Name Description Type Required Remark
    percent Upgrade progress value UINT_T Yes 0–99
    devid Set according to device types:
    • Sub-device: ID of sub-devices.
    • Gateway: NULL.
    CHAR_T * Yes See demo
    tp Device type DEV_TYPE_T Yes See demo
  • Return value

    Return value Description
    OPRT_OK Success
    Error codes Error codes returned when execution failed.

Log management

TuyaOS log management supports log output and redirection. By default, logs of TuyaOS SDK are output to the standard output terminal. It also supports redirection, such as output to a file or the cloud.

AddOutputTerm

  • Function prototype

    OPERATE_RET AddOutputTerm(IN CONST CHAR_T *name,IN CONST LOG_OUTPUT term);
    
  • Functional description

    Added an output callback to the TuyaOS SDK log to write the log to a file.

  • Parameter description

    Name Description Type Required Setting method
    name The name of the log callback. String Yes It can be used for DelOutputTerm to cancel corresponding callbacks.
    term LOG_OUTPUT Callback Yes None
  • Return value

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

DelOutputTerm

  • Function prototype

    VOID DelOutputTerm(IN CONST CHAR_T *name);
    
  • Functional description

    Cancel the log callback registered by the interface AddOutputTerm.

  • Parameter description

    Name Description Type Required Setting method
    name The name of the log callback String Yes Cancel the log callback registered by the interface AddOutputTerm.
  • Return value. VOID

SetLogManageAttr

  • Function prototype

    OPERATE_RET SetLogManageAttr(IN CONST LOG_LEVEL curLogLevel);
    
  • Functional description

    Set the log level.

  • Parameter description

    Name Description Type Required Setting method
    curLogLevel Log level UINT Yes See the description of uni_log.h.
  • Return value

    Return value Description
    OPRT_OK Operation succeeded.
    Error codes Error codes returned when execution failed.

Timer

Add a system timer

  • Function prototype

    OPERATE_RET sys_add_timer(IN CONST P_TIMER_FUNC pTimerFunc,
    IN CONST PVOID pTimerArg, OUT TIMER_ID *p_timerID);
    
  • Functional description

    Add a system timer.

  • Parameter description

    Name Description Type Required Setting method
    pTimerFunc Function of timer processing P_TIMER_FUNC Yes The pointer of the callback function called by the timer aging.
    pTimerArg Parameter of timer processing PVOID Yes Timer related parameters. The specific type is determined by the inside of a callback function.
    p_timerID Timer ID No. TIMER_ID * Yes Output parameter. timer id is returned if a timer is added successfully.
  • Return value

    Return value Description
    OPERATE_RET Error code

sys_stop_timer

  • Function prototype

    OPERATE_RET sys_stop_timer(IN CONST TIMER_ID timerID));
    
  • Functional description

    Stop a timer.

  • Parameter description

    Name Description Type Required Setting method
    timerID Timer ID No. TIMER_ID * Yes Timer’s timer id that needs to be stopped.
  • Return value

    Return value Description
    OPERATE_RET Error code

IsThisSysTimerRun

  • Function prototype

    BOOL IsThisSysTimerRun(IN CONST TIMER_ID timerID);
    
  • Functional description

    Determine whether a timer is running.

  • Parameter description

    Name Description Type Required Setting method
    timerID Timer ID No. TIMER_ID * Yes Timer’s timer id that you shall determine whether it is running.
  • Return value

    Return value Description
    BOOL Whether the timer is running.

sys_start_timer

  • Function prototype

    OPERATE_RET sys_start_timer(IN CONST TIMER_ID timerID, IN CONST TIME_MS  timeCycle, IN CONST TIMER_TYPE timer_type);
    
  • Functional description

    Start a timer.

  • Parameter description

    Name Description Type Required Setting method
    timerID Timer ID No. TIMER_ID * Yes Timer’s timer id that you shall determine whether it is running.
    timeCycle Timer cycle TIME_MS Yes Timing cycle in milliseconds.
    timer_type Timer type TIMER_TYPE Yes
    • TIMER_ONCE: one-time execution.
    • TIMER_CYCLE: looping execution.
  • Return value

    Return value Description
    BOOL Whether the timer is running.

Message queuing

CreateMsgQueAndInit

  • Function prototype

    OPERATE_RET CreateMsgQueAndInit(OUT MSG_QUE_HANDLE *pMsgQueHandle);
    
  • Functional description

    Create message queuing.

  • Parameter description

    Name Description Type Required Setting method
    pMsgQueHandle Struct handle of message management. MSG_QUE_HANDLE Yes Output parameters. The message queue is successfully created, and the handle is returned.
  • Return value

    Return value Description
    OPERATE_RET Error code

AddMsgNodeToQueue

  • Function prototype

    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);
    
  • Functional description

    Create message queuing.

  • Parameter description

    Name Description Type Required Setting method
    pMsgQueHandle Struct handle of message management. MSG_QUE_HANDLE Yes The returned handle on successful creation.
    msgID Message ID MSG_ID Yes
    pMsgData Message data P_MSG_DATA Yes
    msgDataLen Message data length MSG_DATA_LEN Yes
    msgType Message type MSG_TYPE Yes
  • Return value

    Return value Description
    OPERATE_RET Error code

GetMsgNodeFromQueue

  • Function prototype

    OPERATE_RET GetMsgNodeFromQueue(IN CONST MSG_QUE_HANDLE msgQueHandle, IN CONST MSG_ID msgID, OUT P_MSG_LIST *ppMsgListNode);
    
  • Functional description

    Get the message node of a specified ID.

  • Parameter description

    Name Description Type Required Setting method
    pMsgQueHandle Struct handle of message management. MSG_QUE_HANDLE Yes The returned handle on successful creation.
    msgID Message ID MSG_ID Yes
    pMsgListNode Message node P_MSG_LIST * Yes Output parameters. The obtained message nodes.
  • Return value

    Return value Description
    OPERATE_RET Error code

GetFirstMsgFromQueue

  • Function prototype

    OPERATE_RET GetFirstMsgFromQueue(IN CONST MSG_QUE_HANDLE msgQueHandle, OUT P_MSG_LIST *ppMsgListNode);
    
  • Functional description

    Get the message node of the first incoming link.

  • Parameter description

    Name Description Type Required Setting method
    pMsgQueHandle Struct handle of message management. MSG_QUE_HANDLE Yes The returned handle on successful creation.
    pMsgListNode Message node P_MSG_LIST * Yes Output parameters. The obtained message nodes.
  • Return value

    Return value Description
    OPERATE_RET Error code

GetMsgNodeNum

  • Function prototype

    OPERATE_RET GetMsgNodeNum(IN CONST MSG_QUE_HANDLE msgQueHandle,OUT PINT pMsgNodeNum);
    
  • Functional description

    Get the total number of message nodes in the linked list.

  • Parameter description

    Name Description Type Required Setting method
    pMsgQueHandle Struct handle of message management. MSG_QUE_HANDLE Yes The returned handle on successful creation.
    pMsgNodeNum The total number of message nodes. PINT Yes Output parameters. The total number of obtained message nodes.
  • Return value

    Return value Description
    OPERATE_RET Error code

DelAndFreeMsgNodeFromQueue

  • Function prototype

    OPERATE_RET DelAndFreeMsgNodeFromQueue(IN CONST MSG_QUE_HANDLE msgQueHandle, IN CONST P_MSG_LIST pMsgListNode);
    
  • Functional description

    Delete the message node from the linked list and release the memory of message nodes.

  • Parameter description

    Name Description Type Required Setting method
    pMsgQueHandle Struct handle of message management. MSG_QUE_HANDLE Yes The returned handle on successful creation.
    pMsgListNode The deleted message nodes. P_MSG_LIST Yes The deleted message nodes.
  • Return value

    Return value Description
    OPERATE_RET Error code

ReleaseMsgQue

  • Function prototype

    OPERATE_RET ReleaseMsgQue(IN CONST MSG_QUE_HANDLE msgQueHandle);
    
  • Functional description

    Release the memory occupied by the message queue.

  • Parameter description

    Name Description Type Required Setting method
    pMsgQueHandle Struct handle of message management. MSG_QUE_HANDLE Yes The returned handle on successful creation.
  • Return value

    Return value Description
    OPERATE_RET Error code

PostMessage

  • Function prototype

    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);
    
  • Functional description

    Send a message to the module. It is a FIFO (First-In-First-Out) queue.

  • Parameter description

    Name Description Type Required Setting method
    msgQueHandle Handle of message processing MSG_QUE_HANDLE Yes The returned handle on successful creation.
    msgID Message ID MSG_ID Yes
    pMsgData Message data P_MSG_DATA Yes
    msgDataLen Message data length MSG_DATA_LEN Yes
  • Return value

    Return value Description
    OPERATE_RET Error code

PostInstancyMsg

  • Function prototype

    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);
    
  • Functional description

    Send urgent messages (the message will be executed immediately).

  • Parameter description

    Name Description Type Required Setting method
    msgQueHandle Handle of message processing MSG_QUE_HANDLE Yes The returned handle on successful creation.
    msgID Message ID MSG_ID Yes
    pMsgData Message data P_MSG_DATA Yes
    msgDataLen Message data length MSG_DATA_LEN Yes
  • Return value

    Return value Description
    OPERATE_RET Error code

WaitMessage

  • Function prototype

    OPERATE_RET WaitMessage(IN CONST MSG_QUE_HANDLE msgQueHandle, OUT P_MSG_LIST *ppMsgListNode);
    
  • Functional description

    Send urgent messages (the message will be executed immediately). It is called when there is a new message. DelAndFreeMsgNodeFromQueue shall be called to release the message after the message is processed.

  • Parameter description

    Name Description Type Required Setting method
    msgQueHandle Handle of message processing MSG_QUE_HANDLE Yes The returned handle on successful creation.
    ppMsgListNode Message node P_MSG_LIST * Yes Output parameters. The received message nodes.
  • Return value

    Return value Description
    OPERATE_RET Error code

Task queue

CreateAndStart

  • Function prototype

    OPERATE_RET CreateAndStart(OUT THRD_HANDLE *pThrdHandle, IN CONST P_THRD_FUNC pThrdFunc,
    IN CONST PVOID pThrdFuncArg, IN CONST STACK_SIZE stack_size,IN CONST TRD_PRI pri,
    IN CONST CHAR *thrd_name);;
    
  • Functional description

    Task creation

  • Parameter description

    Name Description Type Required Setting method
    pThrdHandle Task handle of pThrdHandle MSG_QUE_HANDLE Yes The returned handle on successful creation.
    pThrdFunc Function of task processing P_THRD_FUNC Yes
    pThrdFuncArg Task parameters PVOID Yes
    stack_size Specify task stack size STACK_SIZE Yes
    pri Task priority TRD_PRI Yes
    thrd_name Task name CHAR * Yes
  • Return value

    Return value Description
    OPERATE_RET Error code

ThrdJoin

  • Function prototype

    OPERATE_RET ThrdJoin(IN CONST THRD_HANDLE thrdHandle, OUT VOID **ppThrdRet);;
    
  • Functional description

    Task creation

  • Parameter description

    Name Description Type Required Setting method
    thrdHandle Task handle of pThrdHandle MSG_QUE_HANDLE Yes The returned handle on successful creation.
    ppThrdRet Task exit code VOID * Yes
  • Return value

    Return value Description
    OPERATE_RET Error code