Production Test SDK of Tuya IPC

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

The Production Test SDK of the Tuya IPC is the solution code developed and provided by Tuya to connect to the Tuya IoT platform. The Production Test SDK of the Tuya IPC is mainly for you to quickly integrate Tuya PC and complete production development.

Directory structure

├── demo
│   ├── cJSON.c
│   ├── cJSON.h
│   ├── main.c
│   ├── resource
│   │   ├── speaker_test_8k.pcm
│   │   └── tuya.h264
│   ├── tool
│   │   ├── iperf-3.1.3-source.tar.gz
│   │   ├── iperf3_pc.zip
│   │   └── rtwpriv.tar.gz
│   ├── tuya_fac_cmd_demo.c
│   ├── tuya_fac_cmd_demo.h
│   └── tuya_fac_media_demo.c
├── include
│   ├── tuya_fac_cmd.h
│   ├── tuya_fac_media.h
│   ├── tuya_fac_protocol.h
│   └── tuya_fac_test.h
├── lib
│   └── libtuya_fac.a
├── Makefile
|- output

Set up development environment

Extract

Get and extract the Tuya production test development SDK to any directory in ubuntu. The code directory structure is as shown above:

  • In the development section of the demo folder, the corresponding demo routines have been given.

  • The include folder contains header files required by the SDK and functions that you need to complete by yourself.

  • The lib folder is the SDK static library.

  • The resource folder contains audio and video files.

  • The output folder contains output files from compilation and data running.

  • The tool folder contains some compilation tools that may be needed for production testing.

Compilation

Specified compilation chain

Modify the parameters in the Makefile file. COMPILE_PREX = XXXX

Execute the Makefile script in the current directory, and execute the make command in sequence to generate a binary executable program in the output directory.

Procedure

Modify Demo code

main.c

  • You must specify the output path of the video and audio files and the .iperf. file, otherwise, the audio and video files will be loaded incorrectly.

  • You must ignore the SIGPIPE signal signal(SIGPIPE, SIG_IGN);

  • The input parameter of the aging time, in hours.

tuya_ipc_media_demo.c

The user initializes the streaming media by themselves.

  • extern FILE *aud_save_fp;

  • extern FILE *aud_save_pcm_fp;

  • extern int data_size;

  • extern pthread_mutex_t mutex;

The above global variables need to be quoted to realize the writing of audio file data. For examples of routine, refer to the void *tuya_fac_media_loop(void *arg)function.

Initialize the RTSP service

RTSP is an IPC_SDK service, and RTSP can be initialized after the initialization of the streaming media and Ring Buffer. See tuya_fac_media_start_rtsp();

E_CHANNEL_VIDEO_MAIN is the main video stream, and E_CHANNEL_VIDEO_SUB is the video sub-stream.

tuya_ipc_cmd_demo.c

This file describes how to test the interface. It gives the routine. The user needs to complete the device’s read-write process.

For functional interfaces, see tuya_fac_cmd.h.

tuya_test_path

Function prototype

void tuya_test_path(char *path , int verbose);

Functional specification

Specify executable program and tool running path to call first.

Parameters description

Name Description Type Required Setting
Path Specify the running path Char * Yes Input the parameter
Verbose Enable the logs Int Yes Input the parameter

Return Value

Return Value Description
None None

tuya_get_version

Function prototype

int tuya_get_version(char *data);

Functional specification

Get the version number, production test field is 0×01.

Parameters description

Name Description Type Required Setting
data Version No. Content Char * Yes Input the parameter

Return Value

Return Value Description
0 Return Version No.
-1 Return {“ret”:false}

tuya_test_rw_partition

Function prototype

int tuya_test_rw_partition();

Functional specification

Before entering the production test, the user can choose whether to test the read-write partition function.

Parameters description

Name Description Type Required Setting
None None None No None

Return Value

Return Value Description
0 Started the production test successfully
-1 Failed to start the production test

tuya_test_sd_write

Function prototype

int tuya_test_sd_write();

Functional specification

Before entering the production test, the user can choose whether to test the partition function of the SD card.

Parameters description

Name Description Type Required Setting
None None None No None

Return Value

Return Value Description
0 Started the production test successfully
-1 Failed to start the production test

tuya_test_button

Function prototype

int tuya_test_button();

Functional specification

Button test. The production test field is 0×0a.

Parameters description

Name Description Type Required Setting
None None None Yes None

Return Value

Return Value Description
0 Return {“ret”:true,“keyEvent”:“key0” }
-1 Return {“ret”:false}

tuya_test_led

Function prototype

int tuya_test_led();

Functional specification

Button test. The production test field is 0×0b.

Parameters description

Name Description Type Required Setting
None None None Yes None

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_test_video

Function prototype

int tuya_test_video();

Functional specification

Video stream test. The production test field is 0×13.

Parameters description

Name Description Type Required Setting
None None None Yes None

Return Value

Return Value Description
0 Return {“ret”:true,“rtspUrl”:“”}
-1 Return {“ret”:false}

tuya_test_ircut

Function prototype

int tuya_test_ircut(char *str);

Functional specification

IR Cut switch test. The production test field is 0×14.

Parameters description

Name Description Type Required Setting
str Number of switch operations Char * Yes Parse json

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_test_speaker

Function prototype

int tuya_test_speaker();

Functional specification

Speaker test. The production test field is 0×15.

Parameters description

Name Description Type Required Setting
None None None Yes None

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_test_mic

Function prototype

int tuya_test_mic(char *str,char *ipaddr);

Functional specification

Microphone test. The production test field is 0×16.

Parameters description

Name Description Type Required Setting
str Switch Char * Yes JSON parse
ipaddr Receiving address of audio files Char * Yes None

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

Remarks

  • As the server, the PC opens the port 8095 first to wait for receiving the files and send the 0×16 command field.

  • After the device receives the command, it starts to record the 3s-audio in the current environment, converts it into a wav. format file, and sends it to the PC in tcp/ip mode. It will return the true or false field depending on whether it recorded and sent successfully.

  • After the PC receives the file, it will loop the audio and close the 8095 port.

  • Workers judge the result based on the sound they hear.

int tuya_test_irled

Function prototype

int tuya_test_irled();

Functional specification

IR light test. The production test field is 0×17.

Parameters description

Name Description Type Required Setting
None None None Yes None

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_write_cfg

Function prototype

int tuya_write_cfg(char *data);

Functional specification

Authorization information reading test. The production test field is 0×03.

Parameters description

Name Description Type Required Setting
data Authorization information Char * Yes Parse json

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_read_cfg

Function prototype

int tuya_read_cfg(char *data);

Functional specification

Authorization information reading test. The production test field is 0×04.

Parameters description

Name Description Type Required Setting
data Authorization information Char * Yes Input the parameter

Return Value

Return Value Description
0 Return {“auzkey”:”xxxx”,“uuid”:”xxxx”,”pid”:”xxx”,”prod_test”:true,“ap_ssid”:”xxxx”,“ap_pwd”:“xxxx”}
-1 Return {“ret”:false}

tuya_write_sn

Function prototype

int tuya_write_sn(char *str);

Functional specification

SN writing test. The production test field is 0×0e.

Parameters description

Name Description Type Required Setting
Str SN No. Char * Yes Parse json

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_read_sn

Function prototype

int tuya_read_sn(char *data);

Functional specification

SN reading test. The production test field is 0×0f.

Parameters description

Name Description Type Required Setting
data SN No. Char * Yes Input the parameter

Return Value

Return Value Description
0 Return {“sn”:“xxx”}
-1 Return {“ret”:false}

tuya_write_bsn

Function prototype

int tuya_write_bsn(char *str);

Functional specification

SN writing test. The production test field is 0×0c.

Parameters description

Name Description Type Required Setting
Str BSN No. Char * Yes Parse json

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_read_bsn

Function prototype

int tuya_read_bsn(char *data);

Functional specification

BSN reading test. The production test field is 0×0d.

Parameters description

Name Description Type Required Setting
data BSN No. Char * Yes Input the parameter

Return Value

Return Value Description
0 Return {“bsn”:“xxx”}
-1 Return {“ret”:false}

tuya_write_mac

Function prototype

int tuya_write_mac(char *str);

Functional specification

MAC writing test. The production test field is 0×05.

Parameters description

Name Description Type Required Setting
Str MAC address Char * Yes Parse json

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_read_mac

Function prototype

int tuya_read_mac(char *data);

Functional specification

MAC writing test. The production test field is 0×06.

Parameters description

Name Description Type Required Setting
data MAC address Char * Yes Input the parameter

Return Value

Return Value Description
0 Return {“mac”:“xxx”}
-1 Return {“ret”:false}

tuya_write_cc

Function prototype

int tuya_write_sn(char *str);

Functional specification

Country code writing test. The production test field is 0×1c.

Parameters description

Name Description Type Required Setting
Str Country code Char * Yes Parse json

Return Value

Return Value Description
0 Return {“ret”:true}
-1 Return {“ret”:false}

tuya_read_cc

Function prototype

int tuya_read_cc(char *data);

Functional specification

Country code reading test. The production test field is 0×1d.

Parameters description

Name Description Type Required Setting
data Country code Char * Yes Input the parameter

Return Value

Return Value Description
0 Return {“country”:“xxx”}
-1 Return {“ret”:false}

tuya_test_iperf

Function prototype

int tuya_test_iperf(char *addr ,
                      char *str ,
                      double *max,
                      double *avr,
                      double *min);

Functional specification

Radio rate test. The production test field is 0×12.

Parameters description

Name Description Type Required Setting
Addr Host address Char * Yes None
Str Rate upper limit Char * Yes Parse json
max Maximum rate Double * Yes Input the parameter
avr Average rate Double * Yes Input the parameter
min Minimum rate Double * Yes Input the parameter

Return Value

Return Value Description
0 Return {“ret”:true, “bandwidth”:20}
-1 Return {“ret”:false}

Remarks

The parsing and reporting of the output of iperf has been completed in the routine. The user needs to compile the iperf app with the corresponding compilation chain in the tool folder.

Iperf-3.1.3 compilation example:
CURDIR=\`pwd\`
tar -xzvf iperf-3.1.3-source.tar.gz
mkdir out
cd iperf-3.1.3
./configure \--host=\${HOST} \--disable-shared \--enable-static \--prefix=\${CURDIR}/out
make
make install
  • The device acts as a client, and the PC side acts as a server.

  • The PC executes iperf3 -s to start the server in advance and sends the 0×12 command field to send the upper limit of the test rate.

  • The device receives the command and executes the iperf. command.

  • The device parses the value of the wifi rate in iperf_out.txt, feeds the data back to the PC in the frame format, and returns TRUE or FALSE according to the test result.

  • The PC terminal judges the test result according to the result and the comparison between the rate and the set rate threshold.

Public interface

tuya_fac_test_start

Function prototype

int tuya_fac_test_start(void** pphdl);

Functional specification

Start the test and enable the audio and video function.

Link functions

tuya_fac_stream_start();

tuya_fac_test_stop

Function prototype

int tuya_fac_test_stop(void** pphdl);

Functional specification

Stop the test and exit the audio and video function.

Link functions

tuya_fac_stream_stop();

tuya_fac_test_loop

Function prototype

int tuya_fac_test_loop(void* phdl , char *path);

Functional specification

Basic test. Establish the socket communication, receive messages from the host and reply.

tuya_fac_test_loop_exit

Function prototype

int tuya_fac_test_loop_exit(void* phdl);

Functional specification

Stop the basic test.

tuya_fac_media_start_rtsp

Function prototype

int tuya_fac_media_start_rtsp();

Functional specification

Starts the RTSP service.

tuya_fac_media_stop_RTSP

Function prototype

int tuya_fac_media_stop_rtsp();

Functional specification

Stop the RTSP service.

tuya_fac_media_loop

Function prototype

int tuya_fac_media_loop(void *arg);

Functional specification

Get the audio and video data and write them to the extern FILE *aud_save_fp
extern FILE *aud_save_pcm_fp