Gateway Extension SDK Production Test

Last Updated on : 2022-11-24 09:20:08download

Gateway production test SDK is used to carry out production tests on the platform and improve development efficiency. The SDK encapsulates the parameter details of data transmission and parsing data frames. You can focus on service development and implement relevant service interfaces.

Get the SDK

Get the gateway production test SDK tuya_gw_pts_sdk.git in GitHub. For SDK usage, see the README.md file and demo/demo.c file in the GitHub repository.

Directory structure

├── CHANGE_LOG.md
├── demo
│   └── demo.c
├── Makefile
├── README.md
└── sdk
    ├── include
    │   ├── tuya_prod_test.h
    │   └── tuya_testframe_handle.h
    └── lib
        ├── shared
        │   ├── libtuya_prodtest.so
        │   └── libtuya_prodtest.so.stripped
        └── static
            ├── libtuya_prodtest.a
            └── libtuya_prodtest.a.stripped

Production test library

Support static library, dynamic library, and strip library. The unstripped version of the static library is selected by default. The production test library is in the sdk/lib/ directory.

Compilation

  • Generate a demo:

    make
    
  • Clear:

    make clean
    
  • Product: The product is under the output/bin directory.

Supported test items

Command Functional specification
0x00 Enter production test mode.
0x01 Read the master firmware version information.
0x02 Read the slave firmware version information.
0x03 Write configuration information (such as authorization information).
0x04 Read configuration information.
0x05 Write the MAC address of the master firmware.
0x06 Read the MAC address of the master firmware.
0x07 Write the MAC address of the slave firmware.
0x08 Read the MAC address of the slave firmware.
0x0a Key test.
0x0b LED test.
0x0c Write BSN.
0x0d Read BSN.
0x0e Write SN.
0x0f Read SN.
0x11 Performance test of slave firmware.
0x15 Speaker test.
0x1c Write the country code.
0x1d Read the country code.
0x23 Specify slave firmware update for the update test.
0x1e Configure the update test.
0x1f Start the update test.
0x20 Receive data during update test.
0x21 Update test ends.
0x22 Reboot the device.
0x29 LTE test.
0x2a Detect the onboard flag.
0x2b Read the SIM card’s CCID.

Interface description

tuya_testframe_set_tcp_port

#include "tuya_testframe_handle.h"
void tuya_testframe_set_tcp_port(int tcp_port);

Functional specification

Set the TCP port number. Note that it shall be called before tuya_testframe_handle_init. Otherwise it will not take effect.

Parameter description

Parameter name Description
tcp_port Set the TCP port number. If this interface is not called, the default port is 12130.

Return value

VOID

tuya_testframe_handle_init

#include "tuya_testframe_handle.h"
int tuya_testframe_handle_init(TUYA_PRODTEST_MODE mode, 
                               int port, 
                               TYTEST_FRAME_CBS_S *cbs);

Functional specification

The test initialization function. It will start the test thread for data transmission during the test.

Parameter description

Parameter name Description
mode Test transmission mode. See the description of TUYA_PRODTEST_MODE struct.
port TCP port number for test, specified by you.
cbs The callback list that is implemented by you. See the description of TYTEST_FRAME_CBS_S struct.

Return value

Return value Description
0 Successful
-1 Failed

Note:

  • If the mode is illegal, TCP transmission is selected by default.
  • The port number shall not conflict with the existing program.

tuya_testframe_handle_deinit

#include "tuya_testframe_handle.h"
int tuya_testframe_handle_deinit();

Functional specification

Test exit function to exit the test mode.

Parameter description

VOID

Return value

Return value Description
0 Successful
-1 Failed

tuya_testframe_rep_key_event

#include "tuya_testframe_handle.h"
int tuya_testframe_rep_key_event(int index, unsigned int key_num);

Functional specification

The interface for asynchronous reporting of test keys. key_num is the number of qualified test keys.

Parameter description

Parameter name Description
index See the description of index.
key_num The number of qualified test keys.

Return value

Return value Description
0 Successful
-1 Failed

tuya_testframe_rep_zigbeeRf_event

#include "tuya_testframe_handle.h"
int tuya_testframe_rep_zigbeeRf_event(int index, unsigned int receive_num);

Functional specification

The interface for asynchronous reporting of Zigbee RF. receive_num is the number of messages received.

Parameter description

Parameter name Description
index See the description of index.
receive_num The number of messages received.

Return value

Return value Description
0 Successful
-1 Failed

Struct and interface description

TUYA_PRODTEST_MODE

// The method of data transmission. Currently, TCP is supported and can be extended. 
typedef enum
{
    TPM_TCP = 0,
    TPM_SERIAL,
    TPM_MAX
} TUYA_PRODTEST_MODE;

Struct description

Currently, only TCP transmission is supported. The serial port is reserved for extensions.

TYTEST_FRAME_CBS_S

typedef struct {    
 
   TYTEST_F_COMMON_HANDL enter_prodtest_frame_cb;          // 1. Enter the production test
   TYTEST_F_COMMON_HANDL exit_prodtest_frame_cb;           // 1. Exit the production test
   TYTEST_F_WR_HANDL master_firm_frame_cb;                 // 2. Master firmware
   TYTEST_F_WR_HANDL slave_firm_frame_cb;                  // 3. Slave firmware
   TYTEST_F_W_CFG_HANDL w_cfg_frame_cb;                    // 4. Write the configuration information
   TYTEST_F_R_CFG_HANDL r_cfg_frame_cb;                    // 5. Read the configuration information
   TYTEST_F_WR_HANDL w_master_mac_frame_cb;                // 6. Write the master MAC address
   TYTEST_F_WR_HANDL r_master_mac_frame_cb;                // 7. Read the master MAC address
   TYTEST_F_WR_SLAVEMAC_HANDL w_slave_mac_frame_cb;        // 8. Write the slave MAC address
   TYTEST_F_WR_SLAVEMAC_HANDL r_slave_mac_frame_cb;        // 9. Read the slave MAC address
   TYTEST_F_WR_HANDL w_bsn_frame_cb;                       // 10. Write BSN
   TYTEST_F_WR_HANDL r_bsn_frame_cb;                       // 11. Read BSN
   TYTEST_F_WR_HANDL w_sn_frame_cb;                        // 12. Write SN
   TYTEST_F_WR_HANDL r_sn_frame_cb;                        // 13. Read SN
   TYTEST_F_WR_HANDL w_country_frame_cb;                   // 14. Write the country code
   TYTEST_F_WR_HANDL r_country_frame_cb;                   // 15. Read the country code
   TYTEST_F_KEY_HANDL key_frame_cb;                        // 16. Key test
   TYTEST_F_LED_HANDL led_frame_cb;                        // 17. LED test
   TYTEST_F_ZIGBEE_RF_HANDL zigbee_rf_frame_cb;            // 18. Zigbee RF test
   TYTEST_F_WIFIBLE_RF_HANDL wifi_rf_frame_cb;    
   TYTEST_F_WIFIBLE_RF_HANDL ble_rf_frame_cb;
   TYTEST_F_UG_SLAVE_HANDL upgrade_slave_frame_cb;         // 19. Slave update
   TYTEST_F_UG_CFG_HANDL upgrade_cfg_frame_cb;             // 20. Update configuration
   TYTEST_F_COMMON_HANDL upgrade_start_frame_cb;           // 21. Start update
   TYTEST_F_UG_REV_HANDL upgrade_rev_packet_frame_cb;      // 22. Receive update     
   TYTEST_F_COMMON_HANDL upgrade_end_frame_cb;             // 23. Complete update   
   TYTEST_F_COMMON_VOID_HANDL reboot_frame_cb;             // 24. Reboot
   TYTEST_F_SPEAKER_HANDL speaker_frame_cb;                // 25. Speaker
   TYTEST_F_LTE_HANDL lte_test_frame_cb;                   // 26. LTE test
   TYTEST_F_R_CCID_HANDL r_ccid_frame_cb;                  // 27. Read the CCID
   TYTEST_F_R_FLAGTYPE_HANDL flag_dect_frame_cb;           // 28. Detect the flag
   TYTEST_F_CUSTOMIZE_HANDL customize_frame_cb;            // 29. Customize handle    
   TYTEST_F_KEY_ASYNC_HANDL key_async_frame_cb;            // 30. Key test
}TYTEST_FRAME_CBS_S;

Struct description

The interfaces to be implemented by you.

Functional specification

SDK callback interface.

Member description

Member name Description
enter_prodtest_frame_cb See enter_prodtest_frame_cb
exit_prodtest_frame_cb See exit_prodtest_frame_cb
master_firm_frame_cb See master_firm_frame_cb
slave_firm_frame_cb See slave_firm_frame_cb
w_cfg_frame_cb See w_cfg_frame_cb
r_cfg_frame_cb See r_cfg_frame_cb
w_master_mac_frame_cb See w_master_mac_frame_cb
r_master_mac_frame_cb See r_master_mac_frame_cb
w_bsn_frame_cb See w_bsn_frame_cb
r_bsn_frame_cb See r_bsn_frame_cb
w_sn_frame_cb See w_sn_frame_cb
r_sn_frame_cb See r_sn_frame_cb
w_country_frame_cb See w_country_frame_cb
r_country_frame_cb See r_country_frame_cb
key_frame_cb See key_frame_cb
led_frame_cb See led_frame_cb
zigbee_rf_frame_cb See zigbee_rf_frame_cb
wifi_rf_frame_cb See wifi_rf_frame_cb
ble_rf_frame_cb See ble_rf_frame_cb
upgrade_slave_frame_cb See upgrade_slave_frame_cb
upgrade_cfg_frame_cb See upgrade_cfg_frame_cb
upgrade_start_frame_cb See upgrade_start_frame_cb
upgrade_rev_packet_frame_cb See upgrade_rev_packet_frame_cb
upgrade_end_frame_cb See upgrade_end_frame_cb
reboot_frame_cb See reboot_frame_cb
speaker_frame_cb See speaker_frame_cb
lte_test_frame_cb See lte_test_frame_cb
r_ccid_frame_cb See r_ccid_frame_cb
flag_dect_frame_cb See flag_dect_frame_cb
customize_frame_cb See customize_frame_cb
key_async_frame_cb See key_async_frame_cb

enter_prodtest_frame_cb

int (*enter_prodtest_frame_cb)(void);

Functional specification

Register the callback function enter_prodtest_frame_cb of TYTEST_FRAME_CBS_S. The business is required to be implemented by the user layer to enter the production test. If not applicable, 0 is returned.

Parameter description

VOID

Return value

Return value Description
0 Successful
-1 Failed

exit_prodtest_frame_cb

int (*exit_prodtest_frame_cb)(void);

Functional specification

Register the callback function exit_prodtest_frame_cb of TYTEST_FRAME_CBS_S. The business is required to be implemented by the user layer to exit the production test. If not applicable, 0 is returned.

Parameter description

VOID

Return value

Return value Description
0 Successful
-1 Failed

master_firm_frame_cb

int (*master_firm_frame_cb)(char *buf);

Functional specification

Register the callback function master_firm_frame_cb of TYTEST_FRAME_CBS_S. Read the master firmware information and store the information in buf.

Parameter description

Parameter name Description
buf The location where the master firmware information is stored by you.

Return value

Return value Description
0 Successful
-1 Failed

slave_firm_frame_cb

int (*slave_firm_frame_cb)(char *buf);

Functional specification

Register the callback function slave_firm_frame_cb of TYTEST_FRAME_CBS_S. Read the slave firmware information and store the information in buf.

Parameter description

Parameter name Description
buf The location where the slave firmware information is stored by you.

Return value

Return value Description
0 Successful
-1 Failed

w_cfg_frame_cb

int (*w_cfg_frame_cb)(char *auzkey, char *uuid, char *pid, int prodtest, char *ap_ssid, char *ap_pwd);

Functional specification

Register the callback function w_cfg_frame_cb of TYTEST_FRAME_CBS_S. Write firmware configuration information, including auzkey, uuid, pid, prodtest, and ssid and password required by AP mode.

Parameter description

Parameter name Description
auzkey The auzkey of device authorization code.
uuid The UUID of device authorization code.
pid Product ID of the device.
prodtest Deprecated.
ap_ssid The SSID used for pairing wireless products in the AP mode.
ap_pwd The password used for pairing wireless products in the AP mode.

Return value

Return value Description
0 Successful
-1 Failed

r_cfg_frame_cb

int (*r_cfg_frame_cb)(char *auzkey, char *uuid, char *pid, int *prodtest, char *ap_ssid, char *ap_pwd);

Functional specification

Register the callback function r_cfg_frame_cb of TYTEST_FRAME_CBS_S. Read firmware configuration information, including auzkey, uuid, pid, prodtest, and the memory specified by ssid and password pointer required by AP mode.

Parameter description

Parameter name Description
auzkey The address where auzkey is stored.
uuid The address where UUID is stored.
pid The address where the product ID is stored.
prodtest Deprecated.
ap_ssid The address where the SSID is stored, which is used for pairing wireless products in the AP mode.
ap_pwd The address where the password is stored, which is used for pairing wireless products in the AP mode.

Return value

Return value Description
0 Successful
-1 Failed

w_master_mac_frame_cb

int (*w_master_mac_frame_cb)(char *buf);

Functional specification

Register the callback function w_master_mac_frame_cb of TYTEST_FRAME_CBS_S. Write the main MAC address.

Parameter description

Parameter name Description
buf Main MAC address.

Return value

Return value Description
0 Successful
-1 Failed

r_master_mac_frame_cb

int (*r_master_mac_frame_cb)(char *buf);

Functional specification

Register the callback function r_master_mac_frame_cb of TYTEST_FRAME_CBS_S. Read the main MAC address.

Parameter description

Parameter name Description
buf Store the main MAC address.

Return value

Return value Description
0 Successful
-1 Failed

w_slave_mac_frame_cb

int (*w_slave_mac_frame_cb)(int cpunum,char *mac);

Functional specification

Register the callback function w_slave_mac_frame_cb of TYTEST_FRAME_CBS_S. Write the MAC address of the slave firmware.

Parameter description

Parameter name Description
cpunum Used to identify the slave firmware. If cpunum is 1, it represents the Zigbee MAC address.
buf MAC address of the slave firmware.

Return value

Return value Description
0 Successful
-1 Failed

r_slave_mac_frame_cb

int (*r_slave_mac_frame_cb)(int cpunum,char *mac);

Functional specification

Register the callback function r_slave_mac_frame_cb of TYTEST_FRAME_CBS_S. Read the MAC address of the slave firmware.

Parameter description

Parameter name Description
cpunum Used to identify the slave firmware. If cpunum is 1, it represents the Zigbee MAC address.
buf Store the MAC address of the slave firmware.

Return value

Return value Description
0 Successful
-1 Failed

w_bsn_frame_cb

int (*w_bsn_frame_cb)(char *buf);

Functional specification

Register the callback function w_bsn_frame_cb of TYTEST_FRAME_CBS_S. Write the BSN.

Parameter description

Parameter name Description
buf BSN serial number.

Return value

Return value Description
0 Successful
-1 Failed

r_bsn_frame_cb

int (*r_bsn_frame_cb)(char *buf);

Functional specification

Register the callback function r_bsn_frame_cb of TYTEST_FRAME_CBS_S. Read the BSN.

Parameter description

Parameter name Description
buf Store the BSN serial number.

Return value

Return value Description
0 Successful
-1 Failed

w_sn_frame_cb

int (*w_sn_frame_cb)(char *buf);

Functional specification

Register the callback function w_sn_frame_cb of TYTEST_FRAME_CBS_S. Write the SN.

Parameter description

Parameter name Description
buf SN serial number.

Return value

Return value Description
0 Successful
-1 Failed

r_sn_frame_cb

int (*r_sn_frame_cb)(char *buf);

Functional specification

Register the callback function r_sn_frame_cb of TYTEST_FRAME_CBS_S. Read the SN.

Parameter description

Parameter name Description
buf Store the SN serial number.

Return value

Return value Description
0 Successful
-1 Failed

w_country_frame_cb

int (*w_country_frame_cb)(char *buf);

Functional specification

Register the callback function w_country_frame_cb of TYTEST_FRAME_CBS_S. Write the country code.

Parameter description

Parameter name Description
buf Country code

Return value

Return value Description
0 Successful
-1 Failed

r_country_frame_cb

int (*r_country_frame_cb)(char *buf);

Functional specification

Register the callback function r_country_frame_cb of TYTEST_FRAME_CBS_S. Read the country code.

Parameter description

Parameter name Description
buf Store the country code.

Return value

Return value Description
0 Successful
-1 Failed

key_frame_cb

int (*key_frame_cb)(unsigned int *response_key_num);

Functional specification

Register the callback function key_frame_cb of TYTEST_FRAME_CBS_S. The function is blocked during the key test. If both key_frame_cb and key_async_frame_cb are implemented at the same time, key_async_frame_cb is called by default. If only key_frame_cb is implemented, key_frame_cb is called.

Parameter description

Parameter name Description
response_key_num Store the number of qualified test keys.

Return value

Return value Description
0 Successful
-1 Failed

led_frame_cb

void  (*led_frame_cb)(TYPT_LED_STATE state);

Functional specification

Register the callback function led_frame_cb of TYTEST_FRAME_CBS_S. It is the LED test.

Parameter description

Parameter name Description
state LED status, including on, off, and flashing.
// LED status 
typedef enum {
    TYPT_LED_ALL_ON = 0,
    TYPE_LED_ALL_OFF,
    TYPT_LED_FLASH
}TYPT_LED_STATE;

Return value

Return value Description
0 Successful
-1 Failed

zigbee_rf_frame_cb

int (*zigbee_rf_frame_cb)(int index, int channel, int num, unsigned int *receive_num);

Functional specification

Register the callback function zigbee_rf_frame_cb of TYTEST_FRAME_CBS_S. The function is blocked during the Zigbee RF test.

Parameter description

Parameter name Description
index See the description of index.
channel The channel where the test message is sent.
num The number of transmitted messages.
receive_num Store the number of received messages.

Return value

Return value Description
0 Successful
-1 Failed

wifi_rf_frame_cb

int (*wifi_rf_frame_cb)(char *ssid, int *rssi);

Functional specification

Register the callback function wifi_rf_frame_cb of TYTEST_FRAME_CBS_S. Wi-Fi RF test detects the RSSI of a specified SSID.

Parameter description

Parameter name Description
ssid Wireless SSID.
rssi Store the signal strength of the SSID.

Return value

Return value Description
0 Successful
-1 Failed

ble_rf_frame_cb

int (*ble_rf_frame_cb)(char *ssid, int *rssi);

Functional specification

Register the callback function ble_rf_frame_cb of TYTEST_FRAME_CBS_S. Bluetooth Low Energy (LE) RF test detects the RSSI of a specified Bluetooth LE.

Parameter description

Parameter name Description
ssid Bluetooth LE name.
rssi Store the signal strength of the Bluetooth LE.

Return value

Return value Description
0 Successful
-1 Failed

upgrade_slave_frame_cb

int (*upgrade_slave_frame_cb)(int image_type);

Functional specification

Register the callback function upgrade_slave_frame_cb of TYTEST_FRAME_CBS_S. Specify the update type as the slave firmware update. If this test item is not executed, the default update type is the master firmware update.

Parameter description

Parameter name Description
image_type Slave firmware update type. if image_type is 1, it represents Zigbee firmware.

Return value

Return value Description
0 Successful
-1 Failed

upgrade_cfg_frame_cb

int (*upgrade_cfg_frame_cb)(unsigned long baud, unsigned long crc32, unsigned long size);

Functional specification

Register the callback function upgrade_cfg_frame_cb of TYTEST_FRAME_CBS_S. Configure the update test.

Parameter description

Parameter name Description
baud Specify the baud of the serial port. The TCP test on Linux does not use this item.
crc32 The CRC32 check value of the firmware updates.
size The size of firmware updates.

Return value

Return value Description
0 Successful
-1 Failed

upgrade_start_frame_cb

int (*upgrade_start_frame_cb)(void);

Functional specification

Register the callback function upgrade_start_frame_cb of TYTEST_FRAME_CBS_S. The flag of the start of test update. With a successful return, the next step is to start to transfer the update firmware.

Parameter description

VOID

Return value

Return value Description
0 Successful
-1 Failed

upgrade_rev_packet_frame_cb

int (*upgrade_rev_packet_frame_cb)(char *data, unsigned int data_len);

Functional specification

Register the callback function upgrade_rev_packet_frame_cb of TYTEST_FRAME_CBS_S. Transfer firmware, up to 1024 bytes each time.

Parameter description

Parameter name Description
data Data of the firmware updates.
data_len Data length of firmware updates.

Return value

Return value Description
0 Successful
-1 Failed

upgrade_end_frame_cb

int (*upgrade_end_frame_cb)(void);

Functional specification

Register the callback function upgrade_end_frame_cb of TYTEST_FRAME_CBS_S. After the update test is completed, the general approach is to verify the update at the user layer. Execute the update, and then return the update result.

Parameter description

VOID

Return value

Return value Description
0 Successful
-1 Failed

reboot_frame_cb

void  (*reboot_frame_cb)(void);

Functional specification

Register the callback function reboot_frame_cb of TYTEST_FRAME_CBS_S. Reboot the device.

Parameter description

VOID

Return value

VOID

speaker_frame_cb

void  (*speaker_frame_cb)(TYPT_SOUND_STATE state);

Functional specification

Register the callback function speaker_frame_cb of TYTEST_FRAME_CBS_S. It is the speaker test.

Parameter description

Parameter name Description
state The speaker is on or off. On means to play a piece of audio, and off means to stop playing.
// Speaker switch 
typedef enum {
    TYPT_SOUND_OFF = 0,    
    TYPT_SOUND_ON
}TYPT_SOUND_STATE;

Return value

VOID

lte_test_frame_cb

int (*lte_test_frame_cb)(TYPT_LTE_TEST state);

Functional specification

Register the callback function lte_test_frame_cb of TYTEST_FRAME_CBS_S. LTE test is performed on three frequency bands.

Parameter description

Parameter name Description
state Each stage of LTE test.
// LTE test steps 
typedef enum{
    TYPT_LTE_ENTER_TEST = 1,
    TYPT_LTE_EXIT_TEST,
    TYPT_LTE_TEST_MODE1,    
    TYPT_LTE_TEST_MODE2,
    TYPT_LTE_TEST_MODE3,
}TYPT_LTE_TEST;

Three modes represent the three frequency bands during the LTE test. The RF of each frequency band must be tested.

Return value

Return value Description
0 Successful
-1 Failed

r_ccid_frame_cb

int (*r_ccid_frame_cb)(char *ccid);

Functional specification

Register the callback function r_ccid_frame_cb of TYTEST_FRAME_CBS_S. Read the SIM card’s CCID.

Parameter description

Parameter name Description
ccid Store the CCID.

Return value

Return value Description
0 Successful
-1 Failed

flag_dect_frame_cb

int (*flag_dect_frame_cb)(TYPT_FLAG_TYPE type);

Functional specification

Register the callback function flag_dect_frame_cb of TYTEST_FRAME_CBS_S. Detect the onboard flag to determine whether the device has performed a pre-test or Wi-Fi calibration test.

Parameter description

Parameter name Description
type Test type, including the Wi-Fi RF test and pre-test.
// Onboard flag detection 
typedef enum{
    TYPT_FLAG_WIFIRF = 0,    
    TYPT_FLAG_BOARDTEST = 1,
}TYPT_FLAG_TYPE;

Return value

Return value Description
0 Successful
-1 Failed

customize_frame_cb

int (*customize_frame_cb)(char *data, char *out_buf);

Functional specification

Register the callback function customize_frame_cb of TYTEST_FRAME_CBS_S. Process your proprietary protocol. If you do not use the standard Tuya test protocol, you can use this function to extend.

Parameter description

Parameter name Description
data The data field of the test frame.
out_buf The data field of the test frame returned to the host.

Return value

Return value Description
0 Successful
-1 Failed

key_async_frame_cb

int (*key_async_frame_cb)(int index);

Functional specification

Parameter description

Parameter name Description
index See the description of index.

Return value

Return value Description
0 Successful
-1 Failed

Index

index is the flag value used for asynchronous reporting. This parameter is required when calling the asynchronous reporting interface.