function helperGenerateCode(mode)
% helperGenerateCode Builds the example as generated code.
%
% Copyright 2017-2018 The MathWorks, Inc.

% Defautl to mex mode.
if nargin < 1
    mode = 'mex';
end

% Validate the input mode.
if ~any(strcmpi(mode,{'mex','sil'}))
    error('Mode must be ''mex'' or ''sil''.');
end

% Read the recorded detections file
[visionObjects, radarObjects, imu, lanes] = ...
    helperReadSensorRecordingsFile('01_city_c2s_fcw_10s_sensor.mat');
egoLane = struct('left', [0 0 0], 'right', [0 0 0]);
time = 0;
positionSelector = [1 0 0 0 0 0; 0 0 0 1 0 0];
velocitySelector = [0 1 0 0 0 0; 0 0 0 0 1 0];
 
% Define the properties of the input based on the data in the first time frame.
compInputs  = {visionObjects(1),radarObjects(1),imu(1),lanes(1), ...
    egoLane, time, positionSelector, velocitySelector}; %#ok<NASGU>

switch lower(mode)
    case 'mex'
        % Generate C code for MEX (requires MATLAB Coder).
        coderConfig = coder.config('mex'); %#ok<NASGU> % Generating a C/C++ static library.
        disp('Configured to generate trackingForFCW_kernel_mex.mex64.')
    otherwise 
        % Generate C code for Software-in-the-loop (requires Embedded Coder).
        coderConfig = coder.config('lib');    % Generating a C/C++ static library.
        coderConfig.VerificationMode = 'SIL'; % Software-in-the-loop (SIL) execution. 
        coderConfig.Verbose = true;           % Code generation progress display.
        disp('Configured to generate trackingForFCW_kernel_sil.mex64.')
end

% Generate code and notify.
codegen -config coderConfig trackingForFCW_kernel -args compInputs                                        
disp('Completed generating code.')
end
