V1/Toolbox.NETMF.Hardware.InfraredRX/Decoders/InfraredLegoReceiver.cs
/// <summary>
/// The concrete implementation of the protocol decoder
/// </summary>
/// <param name="samples"></param>
/// <param name="count"></param>
The concrete implementation of the protocol decoder
The concrete implementation of the protocol decoder
protected override void Decode(
            int[] samples,
            int count)
        {
            if (count < PayLoad)
            {
                return;
            }
            int sample;
            if ((sample = samples[0]) < Threshold1S)
            {
                return;
            }
            int raw = 0;
            int mask = 0x8000;
            for (int i = 1; i < PayLoad; i++)
            {
                if ((sample = samples[i]) < Threshold01)
                {
                }
                else if (sample < Threshold1S)
                {
                    raw |= mask;
                }
                else
                {
                    return;
                }
                mask >>= 1;
            }
            int n1 = (raw & 0xF000) >> 12;
            int n2 = (raw & 0x0F00) >> 8;
            int func = (raw & 0x00F0) >> 4;
            int lrc = raw & 0x000F;
            if (lrc != (0x000F ^ func ^ n1 ^ n2))
            {
                return;
            }
            var message = new LegoMessage();
            message.Toggle = (raw & 0x8000) != 0;
            message.Escape = (raw & 0x4000) != 0;
            message.Channel = (raw & 0x3000) >> 12;
            message.ExtraAddress = (raw & 0x0800) != 0;
            message.Mode = (raw & 0x0700) >> 8;
            message.Func = func;
            this.OnInfraredMessageDecoded(message);
        }
protected override void Decode ( int [ ] samples , int count ) { if ( count < PayLoad ) { return ; } int sample ; if ( ( sample = samples [ 0 ] ) < Threshold1S ) { return ; } int raw = 0 ; int mask = 0x8000 ; for ( int i = 1 ; i < PayLoad ; i ++ ) { if ( ( sample = samples [ i ] ) < Threshold01 ) { } else if ( sample < Threshold1S ) { raw |= mask ; } else { return ; } mask >>= 1 ; } int n1 = ( raw & 0xF000 ) >> 12 ; int n2 = ( raw & 0x0F00 ) >> 8 ; int func = ( raw & 0x00F0 ) >> 4 ; int lrc = raw & 0x000F ; if ( lrc != ( 0x000F ^ func ^ n1 ^ n2 ) ) { return ; } var message = new LegoMessage ( ) ; message . Toggle = ( raw & 0x8000 ) != 0 ; message . Escape = ( raw & 0x4000 ) != 0 ; message . Channel = ( raw & 0x3000 ) >> 12 ; message . ExtraAddress = ( raw & 0x0800 ) != 0 ; message . Mode = ( raw & 0x0700 ) >> 8 ; message . Func = func ; this . OnInfraredMessageDecoded ( message ) ; }
The concrete implementation of the protocol decoder
The concrete implementation of the protocol decoder
//checks there're enough edges //Debug.Print("ERR: payload=" + count); //checks the duration of the "start" bit //Debug.Print("ERR: start=" + sample); //decode the remaining 16 bits, upon the edges' intervals //bit = ZERO //bit = ONE //Debug.Print("ERR: bit=" + sample); //fields decoding //checks the LRC //Debug.Print("ERR: lrc"); //compose the message to be notified //fires the notification event, carrying the decoded message
samples
int[]
None
count
int
None