function mcb_update_data_dictionary(dataSectObj, DataVal)
% function to update simulink data dictionary used in 
% project example

% Copyright 2022 The MathWorks, Inc.

% Update the structure in data dictionary 
dataEntry = getEntry(dataSectObj,'pwm');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.pwm)
    setValue(dataEntry,DataVal.pwm);
end

dataEntry = getEntry(dataSectObj,'sampleTime');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.sampleTime)
    setValue(dataEntry,DataVal.sampleTime);
end

dataEntry = getEntry(dataSectObj,'pmsm');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.pmsm)
    setValue(dataEntry,DataVal.pmsm);
end

dataEntry = getEntry(dataSectObj,'adc');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.adc)
    setValue(dataEntry,DataVal.adc);
end

dataEntry = getEntry(dataSectObj,'dataRange');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.dataRange)
    setValue(dataEntry,DataVal.dataRange);
end

dataEntry = getEntry(dataSectObj,'encoder');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.encoder)
    setValue(dataEntry,DataVal.encoder);
end

dataEntry = getEntry(dataSectObj,'PI_params');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.PI_params)
    setValue(dataEntry,DataVal.PI_params);
end

% Update the simuink parameter value
dataEntry = getEntry(dataSectObj,'paramAdcAmperePerCount');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramAdcAmperePerCount)
    dataValDictionary.Value = DataVal.paramAdcAmperePerCount;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramAdcCountAtZeroAmpere');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramAdcCountAtZeroAmpere)
    dataValDictionary.Value = DataVal.paramAdcCountAtZeroAmpere;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'enHwSwMaskDisplay');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary, DataVal.enHwSwMaskDisplay)
    setValue(dataEntry,DataVal.enHwSwMaskDisplay);
end

dataEntry = getEntry(dataSectObj,'paramCurrentControlSatVoltage');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramCurrentControlSatVoltage)
    dataValDictionary.Value = DataVal.paramCurrentControlSatVoltage;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramEncoderCalibrateAtStartup');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramEncoderCalibrateAtStartup)
    dataValDictionary.Value = DataVal.paramEncoderCalibrateAtStartup;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramEncoderCalibrationDuration');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramEncoderCalibrationDuration)
    dataValDictionary.Value = DataVal.paramEncoderCalibrationDuration;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramEncoderCalibrationMaxError');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramEncoderCalibrationMaxError)
    dataValDictionary.Value = DataVal.paramEncoderCalibrationMaxError;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramEncoderCalibrationVoltage');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramEncoderCalibrationVoltage)
    dataValDictionary.Value = DataVal.paramEncoderCalibrationVoltage;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramEncoderRotorPositionAtZeroCount');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramEncoderRotorPositionAtZeroCount)
    dataValDictionary.Value = DataVal.paramEncoderRotorPositionAtZeroCount;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramEncoderRotorPositionPerCount');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramEncoderRotorPositionPerCount)
    dataValDictionary.Value = DataVal.paramEncoderRotorPositionPerCount;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramOpenLoopVelocityAcceleration');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramOpenLoopVelocityAcceleration)
    dataValDictionary.Value = DataVal.paramOpenLoopVelocityAcceleration;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramOpenLoopVelocityToVoltsBias');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramOpenLoopVelocityToVoltsBias)
    dataValDictionary.Value = DataVal.paramOpenLoopVelocityToVoltsBias;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramOpenLoopVelocityToVoltsScalar');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramOpenLoopVelocityToVoltsScalar)
    dataValDictionary.Value = DataVal.paramOpenLoopVelocityToVoltsScalar;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramOverCurrentDuration');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramOverCurrentDuration)
    dataValDictionary.Value = DataVal.paramOverCurrentDuration;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramOverCurrentEnable');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramOverCurrentEnable)
    dataValDictionary.Value = DataVal.paramOverCurrentEnable;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramOverCurrentLimit');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramOverCurrentLimit)
    dataValDictionary.Value = DataVal.paramOverCurrentLimit;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramPwmCompareAtZeroVolt');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramPwmCompareAtZeroVolt)
    dataValDictionary.Value = DataVal.paramPwmCompareAtZeroVolt;
    setValue(dataEntry,dataValDictionary);
end


dataEntry = getEntry(dataSectObj,'paramPwmCompareMax');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramPwmCompareMax)
    dataValDictionary.Value = DataVal.paramPwmCompareMax;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramPwmComparePerVolt');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramPwmComparePerVolt)
    dataValDictionary.Value = DataVal.paramPwmComparePerVolt;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramVelocityControlSatCurrent');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramVelocityControlSatCurrent)
    dataValDictionary.Value = DataVal.paramVelocityControlSatCurrent;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramAdcEnablecalibration');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramAdcEnablecalibration)
    dataValDictionary.Value = DataVal.paramAdcEnablecalibration;
    setValue(dataEntry,dataValDictionary);
end

dataEntry = getEntry(dataSectObj,'paramAdcCalibrationSamples');
dataValDictionary = getValue(dataEntry);
if ~isequal(dataValDictionary.Value, DataVal.paramAdcCalibrationSamples)
    dataValDictionary.Value = DataVal.paramAdcCalibrationSamples;
    setValue(dataEntry,dataValDictionary);
end

end