Please enable JavaScript to view this site.

Waijung 2 User Guide

Introduction

This tutorial demonstrate how to use Waijung2 ESP32 block set to conduct testing with Script Testing.

Script testing with Simulink involves writing test scripts or code snippets using MATLAB scripts or functions to automate the testing of Simulink models. The test scripts can be used to execute Simulink models, simulate various scenarios, and verify the results.

 

Here are the pros and cons of script testing with Simulink:

 

Pros of script testing:

 

It can help automate the testing of Simulink models, especially for complex systems that require extensive testing.

It enables you to run the same tests repeatedly and consistently, which can improve the accuracy and reliability of the testing process.

Script testing can be executed quickly and efficiently, which can save time and effort compared to manual testing.

It can be used to test different aspects of the Simulink model, including model functionality, inputs, outputs, and parameters.

MATLAB provides a rich set of built-in functions and tools for Simulink testing, which can simplify the testing process.

 

Cons of script testing:

 

It may require specialized skills and knowledge in MATLAB programming and Simulink modeling, which can be a barrier for some testers.

Script testing may not detect all types of defects or issues, especially those that are difficult to anticipate or test automatically.

It may require additional resources, such as hardware, software, and testing tools, which can increase the cost of the testing process.

Prerequisites

ESP32 development board

USB cable

Waijung2 ESP32 blockset installed in MATLAB/Simulink

Basic knowledge of MATLAB/Simulink

Block in Use

Waijung2 ESP32 UART Setup block

Waijung2 ESP32 UART Rx/Tx block

Use Case Scenario

How to conduct automated simulation testing using Script files.

Test Cases

TC001: Testing Setup block whether generated C file consist with the expected configurations

Expected Output

Generate result text file or error messages.

Setting Up Test Cases

TC001: Testing Setup block whether generated C file consist with the expected configurations

Step 01: Create Test Model

Create a new script file (Ctrl +n) and use following commands to create the test model.

function uart_setup_block_verification(modelname)

 % Insert your model name

 if nargin == 0

                    modelname = 'uart_setup_block_verification_model';

 end

 % create and open the model

 open_system(new_system(modelname));

end

Test Model:uart_setup_block_verification.m

Step 02: Add Blocks & Set configurations

Use following commands to add blocks.

% add the blocks

add_block('esp32_device_config_lib/Waijung 2 Target Setup',[modelname '/Waijung 2 Target setup']);

set_param([modelname '/Waijung 2 Target Setup'],'position',[365,171,545,269]);

add_block('esp32_uart_lib/UART Setup',[modelname '/UART Setup']);

set_param([modelname '/UART Setup'],'position',[335,314,580,436]);

 

Use following commands to get path to blocks.

% path to the block

target_setup_block = find_system(modelname, 'MaskType','esp32_target_setup');

uart_block = find_system(modelname, 'MaskType','esp32_uart_setup');

 

Use following commands to set parameters to the Waijung2 Target Setup block.

% disable lib link to target setup block

set_param(target_setup_block{1}, 'LinkStatus''inactive');

 

% set target setup parameters

waijung2.setMaskValue(target_setup_block{1}, 'buildoptions''Generate code');

waijung2.setMaskValue(target_setup_block{1}, 'esp32target''ESP32');

waijung2.setMaskValue(target_setup_block{1}, 'esp32flashsize''4MB');

waijung2.setMaskValue(target_setup_block{1}, 'esp32comport''COM5');

 

% restore lib link to target setup block

set_param(target_setup_block{1}, 'LinkStatus''restore');

 

Use following commands to set parameters to the Waijung2 UART Setup block.

% number of configurations

[configurationrowmax,~] = size(Parameterset);

 

% disable lib link to uart setup block

set_param(uart_block{1}, 'LinkStatus''inactive');

 

for i=1:configurationrowmax

% set uart setup parameters

waijung2.setMaskValue(uart_block{1}, 'uartmodule', Parameterset{i,1});

waijung2.setMaskValue(uart_block{1}, 'uartmode', Parameterset{i,2});

waijung2.setMaskValue(uart_block{1}, 'baudrate', Parameterset{i,3});

waijung2.setMaskValue(uart_block{1}, 'databits', Parameterset{i,4});

waijung2.setMaskValue(uart_block{1}, 'parity', Parameterset{i,5});

waijung2.setMaskValue(uart_block{1}, 'stopbit', Parameterset{i,6});

waijung2.setMaskValue(uart_block{1}, 'txpin', Parameterset{i,7});

waijung2.setMaskValue(uart_block{1}, 'rxpin', Parameterset{i,8});

waijung2.setMaskValue(uart_block{1}, 'flowcontrol', Parameterset{i,9});

waijung2.setMaskValue(uart_block{1}, 'rs485rtspin', Parameterset{i,10});

esp32_uart_callback('blockid',uart_block{1});

end

% restore lib link to uart setup block

set_param(uart_block{1}, 'LinkStatus''restore');

 

Step 03: Save & Build model to ESP32

Use following command to open waijung2 target setup block mask, which required to auto-update the available COM port

Note- Connect ESP32 before running the script file

% open target setup block mask

open_system(target_setup_block);

 

Use following command to Save the model

% save the model

save_system(modelname);

 

Use following command to build the model

% build the model

slbuild(modelname);

 

Step 04: Check generated Code

Create a text file using following commands

%Create txt file to write configuration data

resultfile = fopen('uart_setup_verification_results.txt','w');

 

% write a title to the text file

fprintf(resultfile,'-----------------------------------------------\n');

fprintf(resultfile,'-----------------------------------------------\n');

fprintf(resultfile,'|UART Setup Block Configurations Validation|\n');

fprintf(resultfile,'-----------------------------------------------\n');

fprintf(resultfile,'-----------------------------------------------\n');

fprintf(resultfile,'\n');

Enter Expected results to the text file using following commands  

% write configurations to the text file

fprintf(resultfile,'---------------------------------------------\n');

fprintf(resultfile,'Configuration Set %d\n',i);

fprintf(resultfile,'---------------------------------------------\n');

fprintf(resultfile,'UART Module: %s\nUART Mode: %s\nBaudrate: %s\nDatabits: %s\nParity: %s\nStopbit: %s\nTx Pin: %s\nRx Pin: %s\nFlowcontrol: %s\nRS485 RTS PIN: %s\n ', Parameterset{i,1},Parameterset{i,2},Parameterset{i,3},Parameterset{i,4},Parameterset{i,5},Parameterset{i,6},Parameterset{i,7},Parameterset{i,8},Parameterset{i,9},Parameterset{i,10});

fprintf(resultfile,'\n');

 

Find the path to configurations in the generated files  

% file path to open generated configuration file

fullFileName = [pwd '\' modelname '_esp32\' modelname '.c'];

fid = fopen(fullFileName,'rt');

 

Extract the data from the generated file to text file

% write a title to the text file

fprintf(resultfile,'-------------------------------------------------\n');

fprintf(resultfile,'Verification Results from generated source files \n');

fprintf(resultfile,'-------------------------------------------------\n');

% Extracting configuration data from Generated files to text file

idx = 1;

copydata = 0;

        while true

            thisline = fgetl(fid);

            if ~ischar(thisline); break; end  %end of file

            % finding starting line of configuration in source file

            if contains(thisline, 'void uart_setup_ver_model_initialize(void)')

               copydata = 1;

            end

            % finding end line of configuration in source file

            if contains(thisline, '[EOF] ')

                copydata = 0;   

                break;

            end

            if copydata == 1

                % writing source file data to text file

                fprintf(resultfile,'%s\n', thisline);

            end       

            idx = idx +1;

        end

 

Result text file: uart_setup_verification_results.txt

Useful Commands

1.Commands for a model

% Insert your model name

if nargin == 0

    modelname = 'new_model';

End

 

% Create and open the model

open_system(new_system(modelname));

 

% Open the model

open_system(modelname);

 

% Close the model

close_system(modelname); 

 

% Save the model

save_system(modelname);

 

% Build the model

slbuild(modelname);

2.Commands for a block

% add block & set position

add_block('esp32_device_config_lib/Waijung 2 Target Setup',[modelname '/Waijung 2 Target setup']);

set_param([modelname '/Waijung 2 Target Setup'],'position',[335,16,570,129]);

 

% delete block

delete_block([modelname '/Constant']);

 

% add line

add_line(modelname,'In1/1','UART Tx/1');

 

% delete line

delete_line(modelname,'In1/1','Terminator/1');

 

% get the path to a block

target_setup_block = find_system(modelname, 'MaskType','esp32_target_setup');

 

% get parameters

build_option = waijung2.getMaskValue(target_setup_block{1}, 'buildoptions');

 

% set parameters

waijung2.setMaskValue(target_setup_block{1}, 'buildoptions''Generate code');

 

% get parameters for non-waijung block

get_param(modelname/blockname,blockparameter)

 

3.Commands for a Test harness model

% load harness

sltest.harness.load('uart_ver_top/Model','uart_ver_Harness');

 

% rebuild harness

 sltest.harness.rebuild('spi_ver_top/Model''spi_ver_Harness');

 

% set code interface to model reference for PIL

set_param('spi_ver_Harness/Model','CodeInterface','Model reference');

 

% save harness

save_system('spi_ver_Harness');

 

Copyright 2024 Aimagin Co.,Ltd. Rev.1659