function [outData] = commCRCTransform(inData)
%COMMCRCTRANSFORM Transform function from CRC-N Generator/Syndrome Detector
%   block to General CRC Generator/Syndrome Detector block. 

% Copyright 2018 The MathWorks, Inc.

InstanceData = inData.InstanceData;
oldBlockParams = {InstanceData.Name};

% Map "generator polynomial" parameter
[~, paramIdx] = find(strcmp('crcMethod', oldBlockParams));
if ~isempty(paramIdx) 
    switch InstanceData(paramIdx).Value
        case 'CRC-32'
            gp = '[1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1]';
        case 'CRC-24'
            gp = '[1 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1]';
        case 'CRC-16'
            gp = '[1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1]';
        case 'Reversed CRC-16'
            gp = '[1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1]';
        case 'CRC-8'
            gp = '[1 1 1 0 1 0 1 0 1]';
        otherwise % 'CRC-4'
            gp = '[1 1 1 1 1]';
    end

    outData.NewInstanceData(1) = struct( ...
        'Name',  'genPoly', ...
        'Value', gp);
end

% Map "Initial states" parameter
[~, paramIdx] = find(strcmp('iniStates', oldBlockParams));
outData.NewInstanceData(end+1) = struct( ...
    'Name',  'iniStates', ...
    'Value', InstanceData(paramIdx).Value);

% Map "Checksums per frame" parameter
[~, paramIdx] = find(strcmp('numChecksums', oldBlockParams));
outData.NewInstanceData(end+1) = struct( ...
    'Name',  'numChecksums', ...
    'Value', InstanceData(paramIdx).Value);

% Set the rest parameters to fixed values
outData.NewInstanceData(end+1) = struct( ...
    'Name',  'directMethod', ...
    'Value', 'off');

outData.NewInstanceData(end+1) = struct( ...
    'Name',  'reflectInputBytes', ...
    'Value', 'off');

outData.NewInstanceData(end+1) = struct( ...
    'Name',  'reflectChecksums', ...
    'Value', 'off');

outData.NewInstanceData(end+1) = struct( ...
    'Name',  'finalXOR', ...
    'Value', '0');

outData.NewBlockPath = inData.ForwardingTableEntry.('__slOldName__');

end

% [EOF]