function copyConfigSet(srcModelH, harnessH)
% copy config set

%   Copyright 2015-2022 The MathWorks, Inc.
    
    srcModelDirty = get_param(srcModelH, 'Dirty');
    
    isSILOrPILMode = false;
    simMode = '';
    if strcmp(get_param(srcModelH, 'SimulationMode'), 'software-in-the-loop (sil)')
        isSILOrPILMode = true;
        simMode = 'Software-in-the-loop (SIL)';
    end
    if strcmp(get_param(srcModelH, 'SimulationMode'), 'processor-in-the-loop (pil)')
        isSILOrPILMode = true;
        simMode = 'Processor-in-the-loop (PIL)';
    end
    
    isSLTestHarness = strcmp(get_param(harnessH, 'IsHarness'), 'on');
    if isSILOrPILMode && isSLTestHarness
        CUTBlock = Simulink.ID.getFullName([get_param(harnessH, 'Name') ':1']);
        if strcmp(get_param(CUTBlock, 'BlockType'), 'ModelReference')
            set_param(srcModelH, 'SimulationMode', 'normal');            
        end
    end
    
    origCS = getActiveConfigSet(srcModelH);
    
    Sldv.utils.replaceConfigSetRefWithCopy(srcModelH);                
    
    configSetUtils = Simulink.ModelReference.Conversion.ConfigSet.create;
    configSetUtils.copy(srcModelH, harnessH);
    
    Sldv.utils.restoreConfigSet(srcModelH, origCS);        
    if isSILOrPILMode && isSLTestHarness
        CUTBlock = Simulink.ID.getFullName([get_param(harnessH, 'Name') ':1']);
        if strcmp(get_param(CUTBlock, 'BlockType'), 'ModelReference')
            % restore original simulation mode of the src model
            set_param(srcModelH, 'SimulationMode', simMode);
            % set the simulation mode of the CUTBlock to desired mode
            set_param(CUTBlock, 'SimulationMode', simMode);                                    
        end
    end    
    set_param(srcModelH, 'Dirty', srcModelDirty);
    if(~isempty(get_param(srcModelH, 'SimUserIncludeDirs')))
        sldv.code.slcc.internal.fixReplacementCustomCodeSettings(srcModelH, harnessH);
    end
    if isSILOrPILMode && isSLTestHarness
        hObj = get_param(harnessH, 'Object');
        hObj.refreshModelBlocks
    end
    
end
