function mcb_SetOperatingModeExample(block_in, init, PI_params)
% mcb_host_mode_control_script.m
% Initializes the parameters for operating mode example's host model
% mcb_host_mode_control.slx

% Copyright 2020 The MathWorks, Inc.

block=[block_in,'/Serial Communication/Dashboard control/'];
block_first=[block_in,'/Serial Communication/Dashboard control/Change detect'];
block_last='/Unit Delay';

% update default values in dashboard block
set_param([block 'Operating Mode'],'value',num2str(init.mode));
set_param([block 'Signal Sel 1'],'value',num2str(init.signal1));
set_param([block 'Signal Sel 2'],'value',num2str(init.signal2));
set_param([block 'Id Ctrl Kp Gain'],'value',num2str(PI_params.Kp_i));
set_param([block 'Id Ctrl Ki Gain'],'value',num2str(PI_params.Ki_i));
set_param([block 'Iq Ctrl Kp Gain'],'value',num2str(PI_params.Kp_i));
set_param([block 'Iq Ctrl Ki Gain'],'value',num2str(PI_params.Ki_i));
set_param([block 'Speed Ctrl Kp Gain'],'value',num2str(PI_params.Kp_speed));
set_param([block 'Speed Ctrl Ki Gain'],'value',num2str(PI_params.Ki_speed));
set_param([block 'Voltage (open loop)'],'value',num2str(init.Vpk));
set_param([block 'Speed lmt (open loop)'],'value',num2str(init.N_rpm));
set_param([block 'Id Ref'],'value',num2str(init.Id_ref));
set_param([block 'Iq Ref'],'value',num2str(init.Iq_ref));
set_param([block 'Pos lock Input (torque mode)'],'value',num2str(init.Nmode));
set_param([block 'Speed Ref (speed mode)'],'value',num2str(init.Nref));
set_param([block 'Speed limit (Torque mode)'],'value',num2str(init.Tlmt));

% update default values in init blocks
set_param([block_first,block_last],'InitialCondition',num2str(init.mode));
set_param([block_first,'1',block_last],'InitialCondition',num2str(init.signal1));
set_param([block_first,'2',block_last],'InitialCondition',num2str(init.signal2));
set_param([block_first,'3',block_last],'InitialCondition',num2str(PI_params.Kp_i));
set_param([block_first,'4',block_last],'InitialCondition',num2str(PI_params.Ki_i));
set_param([block_first,'5',block_last],'InitialCondition',num2str(PI_params.Kp_i));
set_param([block_first,'6',block_last],'InitialCondition',num2str(PI_params.Ki_i));
set_param([block_first,'7',block_last],'InitialCondition',num2str(PI_params.Kp_speed));
set_param([block_first,'8',block_last],'InitialCondition',num2str(PI_params.Ki_speed));
set_param([block_first,'9',block_last],'InitialCondition',num2str(init.Vpk));
set_param([block_first,'10',block_last],'InitialCondition',num2str(init.N_rpm));
set_param([block_first,'11',block_last],'InitialCondition',num2str(init.Id_ref));
set_param([block_first,'12',block_last],'InitialCondition',num2str(init.Iq_ref));
set_param([block_first,'13',block_last],'InitialCondition',num2str(init.Nmode));
set_param([block_first,'14',block_last],'InitialCondition',num2str(init.Nref));
set_param([block_first,'15',block_last],'InitialCondition',num2str(init.Tlmt));

% % order of msgId defined in transmission block
% msgId=[162, 164, 165, 171, 172, 173, 174 175, 176, 191, 192, 201, 202, 203, 181, 204];

clear block;
clear block_first;
clear block_last;
