classdef HDLCRCDetector< matlab.System
%HDLCRCDetector Detect errors in input data using CRC
%   CRCDET = comm.HDLCRCDetector creates a cyclic redundancy code (CRC)
%   detector System object, CRCDET, that detects errors in the input data
%   according to a specified generator polynomial.
%
%   CRCDET = comm.HDLCRCDetector(Name,Value) creates a CRC detector
%   object, CRCDET, with the specified property Name set to the specified
%   Value. You can specify additional name-value pair arguments in any
%   order as (Name1,Value1,...,NameN,ValueN).
%
%   CRCDET = comm.HDLCRCDetector(POLY,Name,Value) creates a CRC detector
%   object, CRCDET, with the Polynomial property set to POLY, and other
%   specified property Names set to the specified Values.
%
%   Step method syntax:
%
%   [Y,STARTOUT,ENDOUT,VALIDOUT,ERR] = step(CRCDET,X,STARTIN,ENDIN,VALIDIN)
%   computes CRC checksums for an input message X based on the control
%   signals and compares the computed checksum with input checksum. The
%   output err is high if the two checksums are not equal.
%
%   The input X must be  be a unsigned scalar integer or its equivalent
%   binary column vector with data type double or logical. The input X can
%   be part or the entire message to be encoded. The number of bits in X or
%   the length of X should be less than or equal to the CRC length, and the
%   CRC length should be divisible by the length of X. The CRC length is
%   the order of the polynomial that you specify in the Polynomial
%   property. The output Y outputs the message after removing the checksum
%   bits. Y has the same length and data type as input X.
%
%   All the control signals are scalars with data type logical.
%   STARTIN/STARTOUT and ENDIN/ENDOUT indicate the start and end of a
%   input/output message. Input X is processed for CRC checksum
%   computation when validIn is high. validOut indicates the validation
%   of output message. err is valid only when endOut signal is high.
%
%   System objects may be called directly like a function instead of using
%   the step method. For example, y = step(obj, x) and y = obj(x) are
%   equivalent.
%
%
%   HDLCRCDetector methods:
%
%   step       - Generate CRC code and append it to the input signal
%                (see above)
%   release    - Allow property value and input characteristics changes
%   clone      - Create CRC generator object with same property values
%   isLocked   - Locked status (logical)
%   <a href="matlab:help matlab.System/reset   ">reset</a>      - Reset states of CRC detector object
%   getLatency - Get latency of CRC detector object
%
%   HDLCRCDetector properties:
%
%   Polynomial         - Generator polynomial
%   InitialState       - Initial conditions of shift register
%   DirectMethod       - Direct method (logical)
%   ReflectInput       - Reflect Input at byte wise if true
%   ReflectCRCChecksum - Reflect CRC Checksum if true
%   FinalXORValue      - Final XOR value with CRC Checksum
%
% % Example: 
% % Encode and Decode a signal m using a CRC generator and CRC Detector
%   % Using default polynomial with CRC length 16
%   crcGen = comm.HDLCRCGenerator;
%   crcDet = comm.HDLCRCDetector;
%
%   % run CRC Generator 10 steps
%   numSteps = 10;
%
%   % Control signals for all 10 steps
%   startIn = logical([1 0 0 0 0 0 0 0 0 0]);
%   endIn   = logical([0 1 0 0 0 0 0 0 0 0]);
%   validIn = logical([1 1 0 0 0 0 0 0 0 0]);
%   
%   % 32 bit data to be encoded, in two 16 by 1 columns
%   msg = randi([0 1],16,2); 
%   % random input to HDLCRCGenerator while it is processing the msg
%   randIn = randi([0, 1],16,numSteps-2);
%   dataIn = [msg randIn];
%   
%   % Run CRC Generator 10 steps
%   % Output data: dataOutGen
%   % Output Control signals: startOutGen, endOutGen, validOutGen
%   for i =  1: numSteps
%   [dataOutGen(:,i),startOutGen(i),endOutGen(i),validOutGen(i)] = crcGen(...
%                              dataIn(:,i),startIn(i),endIn(i),validIn(i));
%   end
%   
%   % Add noise to encoded message 
%   dataOutGen(2,4) = ~dataOutGen(2,4);
%   
%   % Run CRC Detector 10 steps
%   % Output data: dataOut
%   % Output Control signals: startOut, endOut, validOut,err
%    for i = 1:numSteps 
%    [dataOut(:,i), startOut(i),endOut(i), validOut(i),err(i)] = crcDet(...
%              dataOutGen(:,i),startOutGen(i),endOutGen(i),validOutGen(i));
%    end
%
%   See also comm.HDLCRCGenerator, comm.CRCDetector.

     
    
    
%  Copyright 2011-2018 The MathWorks, Inc.

    methods
        function out=HDLCRCDetector
        end

        function out=getExecutionSemanticsImpl(~) %#ok<STOUT>
            % works in both classic and synchronous subsystems
        end

        function out=getHeaderImpl(~) %#ok<STOUT>
            %getHeaderImpl   Return header for object display
        end

        function out=getIconImpl(~) %#ok<STOUT>
        end

        function out=getInputNamesImpl(~) %#ok<STOUT>
        end

        function out=getLatency(~) %#ok<STOUT>
        end

        function out=getNumInputsImpl(~) %#ok<STOUT>
        end

        function out=getNumOutputsImpl(~) %#ok<STOUT>
        end

        function out=getOutputNamesImpl(~) %#ok<STOUT>
        end

        function out=loadObjectImpl(~) %#ok<STOUT>
        end

        function out=outputCRCGen(~) %#ok<STOUT>
            % delay
            %            obj.outputCRC =  obj.counter2 > obj.depth;
            %
            %              if obj.counter2== 2*obj.depth
            %                 obj.counter2 =0;
            %                 obj.counter2En = false;
            %              end
            %
            %            if obj.counter2En
            %                obj.counter2= obj.counter2+1;
            %             end
            %
            %             if obj.endInReg
            %
            %                 obj.counter2En = true;
            %             end
            %             obj.endInReg = endIn;
        end

        function out=outputImpl(~) %#ok<STOUT>
            % output, no state update
            %               if isempty(coder.target) || ~eml_ambiguous_types
            %                 y = zeros(size(m));
            %                 [startOut,endOut,validOut] = deal(0);
            %                 err = false;
            %             else
        end

        function out=resetImpl(~) %#ok<STOUT>
            % resetImpl
        end

        function out=saveObjectImpl(~) %#ok<STOUT>
            % Save the public properties
        end

        function out=setupImpl(~) %#ok<STOUT>
            % Input validation  moved from validateInputsImpl
        end

        function out=showSimulateUsingImpl(~) %#ok<STOUT>
            % do not show simulate using option on mask
        end

        function out=supportsMultipleInstanceImpl(~) %#ok<STOUT>
            % Support in For Each Subsystem
        end

        function out=updateImpl(~) %#ok<STOUT>
            %               if isempty(coder.target) || ~eml_ambiguous_types
            %                 y = zeros(size(m));
            %                 [startOut,endOut,validOut] = deal(0);
            %                 err = false;
            %             else
            % output and update are both called
            % output is being called a second time, but that's ok since
            % there is no update of states in output
        end

        function out=validateInitValue(~) %#ok<STOUT>
        end

        function out=validateInputsImpl(~) %#ok<STOUT>
        end

    end
    properties
        %DirectMethod Direct method
        %   Set this property to true to use the direct algorithm for CRC
        %   checksum calculation. Refer to the Communications Toolbox ->
        %   System Design -> Error Detection and Correction -> Cyclic Redundancy
        %   Check Coding -> CRC Algorithm section to learn more about the direct
        %   and non-direct algorithms. The default value of this property is
        %   false.
        DirectMethod;

        %FinalXORValue Final XOR value
        % The value with which the CRC checksum is to be XORed just prior
        % to being appended to the input data. This property can be
        % specified as a binary,double or single precision data type scalar
        % or vector. The vector length is the degree of the generator
        % polynomial that you specify in the Polynomial property. When you
        % specify Final XOR Value as a scalar, the object expands the value
        % to a row vector of length equal to the degree of the generator
        % polynomial. The default value is 0.
        FinalXORValue;

        %InitialState Initial state
        %   Specify the initial conditions of the shift register as a
        %   binary, double or single precision data type scalar or vector.
        %   The vector length is the degree of the generator polynomial
        %   that you specify in the Polynomial property. When you specify
        %   initial conditions as a scalar, the object expands the value to
        %   a row vector of length equal to the degree of the generator
        %   polynomial. The default value is 0.
        InitialState;

        %Polynomial
        %   Specify the generator polynomial as a binary row vector, with
        %   coefficients in descending order of powers. If you set this
        %   property to a binary vector, its length must be equal to the
        %   degree of  the polynomial plus 1.
        Polynomial;

        %ReflectCRCChecksum Reflect CRC checksum
        % A logical quantity that specifies whether the output CRC checksum
        % should be flipped around its center after the input data is
        % completely through the shift register.
        ReflectCRCChecksum;

        %ReflectInput Reflect input
        % A logical quantity that specifies whether the input data should
        % be flipped on a bytewise basis prior to entering the shift
        % register.
        ReflectInput;

    end
end
