Last Updated on : 2024-11-20 08:51:47download
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 gateway production test SDK tuya_gw_pts_sdk in GitHub. For SDK usage, see the README.md
file and demo/demo.c
file in GitHub repository.
├── 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
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.
Generate a demo:
make
Clear:
make clean
Product: The product is under the output/bin
directory.
Command | Functional description |
---|---|
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. |
#include "tuya_testframe_handle.h"
void tuya_testframe_set_tcp_port(int TCP_port);
Functional description
Set the TCP port number. It must 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.
#include "tuya_testframe_handle.h"
int tuya_testframe_handle_init(TUYA_PRODTEST_MODE mode,
int port,
TYTEST_FRAME_CBS_S *cbs);
Functional description
The test initialization function. It will start the test thread for data transmission during 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 | Success. |
-1 | Failure. |
Note:
- If the mode is illegal, TCP transmission is selected by default.
- The port number shall not conflict with the existing program.
#include "tuya_testframe_handle.h"
int tuya_testframe_handle_deinit();
Functional description
Test exit function to exit the test mode.
Parameter description
Void.
Return value
Return value | Description |
---|---|
0 | Success. |
-1 | Failure. |
#include "tuya_testframe_handle.h"
int tuya_testframe_rep_key_event(int index, unsigned int key_num);
Functional description
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 | Success. |
-1 | Failure. |
#include "tuya_testframe_handle.h"
int tuya_testframe_rep_zigbeeRf_event(int index, unsigned int receive_num);
Functional description
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 | Success. |
-1 | Failure. |
//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.
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 description
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. |
int (*enter_prodtest_frame_cb)(void);
Functional description
Register the callback function enter_prodtest_frame_cb
of TYTEST_FRAME_CBS_S. The service is required to be implemented by the user layer to enter the test. If not applicable, 0 is returned.
Parameter description
Void.
Return value
Return value | Description |
---|---|
0 | Success. |
-1 | Failure. |
int (*exit_prodtest_frame_cb)(void);
Functional description
Register the callback function exit_prodtest_frame_cb
of TYTEST_FRAME_CBS_S. The service is required to be implemented by the user layer to exit the test. If not applicable, 0 is returned.
Parameter description
Void.
Return value
Return value | Description |
---|---|
0 | Success. |
-1 | Failure. |
int (*master_firm_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*slave_firm_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*w_cfg_frame_cb)(char *auzkey, char *uuid, char *pid, int prodtest, char *ap_ssid, char *ap_pwd);
Functional description
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 | Success. |
-1 | Failure. |
int (*r_cfg_frame_cb)(char *auzkey, char *uuid, char *pid, int *prodtest, char *ap_ssid, char *ap_pwd);
Functional description
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 | Success. |
-1 | Failure. |
int (*w_master_mac_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*r_master_mac_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*w_slave_mac_frame_cb)(int cpunum,char *mac);
Functional description
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 | Success. |
-1 | Failure. |
int (*r_slave_mac_frame_cb)(int cpunum,char *mac);
Functional description
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 | Success. |
-1 | Failure. |
int (*w_bsn_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*r_bsn_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*w_sn_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*r_sn_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*w_country_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*r_country_frame_cb)(char *buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*key_frame_cb)(unsigned int *response_key_num);
Functional description
key_frame_cb
of TYTEST_FRAME_CBS_S. The function is blocked during the key test.Parameter description
Parameter name | Description |
---|---|
response_key_num | Store the number of qualified test keys. |
Return value
Return value | Description |
---|---|
0 | Success. |
-1 | Failure. |
void (*led_frame_cb)(TYPT_LED_STATE state);
Functional description
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 | Success. |
-1 | Failure. |
int (*zigbee_rf_frame_cb)(int index, int channel, int num, unsigned int *receive_num);
Functional description
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 | Success. |
-1 | Failure. |
int (*wifi_rf_frame_cb)(char *ssid, int *rssi);
Functional description
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 | Success. |
-1 | Failure. |
int (*ble_rf_frame_cb)(char *ssid, int *rssi);
Functional description
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 | Success. |
-1 | Failure. |
int (*upgrade_slave_frame_cb)(int image_type);
Functional description
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 | Success. |
-1 | Failure. |
int (*upgrade_cfg_frame_cb)(unsigned long baud, unsigned long crc32, unsigned long size);
Functional description
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 the 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 | Success. |
-1 | Failure. |
int (*upgrade_start_frame_cb)(void);
Functional description
Register the callback function upgrade_start_frame_cb
of TYTEST_FRAME_CBS_S. The flag of the start of test update. The firmware will be transferred on success return.
Parameter description
Void.
Return value
Return value | Description |
---|---|
0 | Success. |
-1 | Failure. |
int (*upgrade_rev_packet_frame_cb)(char *data, unsigned int data_len);
Functional description
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 | Success. |
-1 | Failure. |
int (*upgrade_end_frame_cb)(void);
Functional description
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 | Success. |
-1 | Failure. |
void (*reboot_frame_cb)(void);
Functional description
Register the callback function reboot_frame_cb
of TYTEST_FRAME_CBS_S. Reboot the device.
Parameter description
Void.
Return value
Void.
void (*speaker_frame_cb)(TYPT_SOUND_STATE state);
Functional description
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.
int (*lte_test_frame_cb)(TYPT_LTE_TEST state);
Functional description
Register the callback function lte_test_frame_cb
of TYTEST_FRAME_CBS_S. The 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;
Return value
Return value | Description |
---|---|
0 | Success. |
-1 | Failure. |
int (*r_ccid_frame_cb)(char *ccid);
Functional description
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 | Success. |
-1 | Failure. |
int (*flag_dect_frame_cb)(TYPT_FLAG_TYPE type);
Functional description
Register the callback function flag_dect_frame_cb
of TYTEST_FRAME_CBS_S. Detect the onboard flag to determine whether the device has performed pre-test or Wi-Fi calibration test.
Parameter description
Parameter name | Description |
---|---|
type | Test type, including 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 | Success. |
-1 | Failure. |
int (*customize_frame_cb)(char *data, char *out_buf);
Functional description
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 | Success. |
-1 | Failure. |
int (*key_async_frame_cb)(int index);
Functional description
Register the callback function key_async_frame_cb
of TYTEST_FRAME_CBS_S. The asynchronous and unblocked interface of the test key indicates that a key test command has been received.
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 |
---|---|
index | See the description of index. |
Return value
Return value | Description |
---|---|
0 | Success. |
-1 | Failure. |
Index
is the flag value used for asynchronous reporting. This parameter is required when calling the asynchronous reporting interface.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback