Beispiel #1
0
	/**
	 * Determines if message bits 0 - 47 pass the Fleetsync CRC checksum 
	 * contained in bits 48 - 63, using a lookup table of CRC checksum values
	 * derived from the CRC-15 value, and verifies the message has even parity
	 */
	public static CRC check( RadioLog.Common.SafeBitArray msg )
	{
		CRC crc = CRC.UNKNOWN;
		
		int calculated = 1; //Starting value

		//Check even parity
		if( msg.Cardinality() % 2 == 0 )
		{
			//Iterate bits that are set and XOR running checksum with lookup value
			for (int i = msg.nextSetBit( 0 ); i >= 0 && i < 48; i = msg.nextSetBit( i+1 ) ) 
			{
				calculated ^= sCHECKSUMS[ i ];
			}
			
			if( calculated == getChecksum( msg ) )
			{
				crc = CRC.PASSED;
			}
			else
			{
				crc = CRC.FAILED_CRC;
			}
		}
		else
		{
			crc = CRC.FAILED_PARITY;
		}
		
		return crc;
	}
Beispiel #2
0
            public void Receive(bool softBit)
            {
                if (mSampleCounter >= 0)
                {
                    if (softBit)
                    {
                        mBitSet.SetBit(mSampleCounter);
                    }
                    else
                    {
                        mBitSet.ClearBit(mSampleCounter);
                    }
                }

                mSampleCounter++;

                if (mSampleCounter >= mSymbolLength)
                {
                    bool decision = mBitSet.Cardinality() >= mDecisionThreshold;

                    send(decision);

                    /* Shift timing left if the left bit in the bitset is opposite
                     * the decision and the right bit is the same */
                    if ((mBitSet[0] ^ decision) &&
                        (!(mBitSet[mSymbolLength - 1] ^ decision)))
                    {
                        sendTapEvent(mBitSet, Shift.LEFT, decision);

                        reset();

                        mSampleCounter--;
                    }

                    /* Shift timing right if the left bit is the same as the
                     * decision and the right bit is opposite */
                    else if ((!(mBitSet[0] ^ decision)) && (mBitSet[mSymbolLength - 1] ^ decision))
                    {
                        sendTapEvent(mBitSet, Shift.RIGHT, decision);

                        /* Last bit from previous symbol to pre-fill next symbol */
                        bool previousSoftBit = mBitSet[mSymbolLength - 1];

                        reset();

                        if (previousSoftBit)
                        {
                            mBitSet.SetBit(0);
                        }

                        mSampleCounter++;
                    }
                    /* No shift */
                    else
                    {
                        sendTapEvent(mBitSet, Shift.NONE, decision);

                        reset();
                    }
                }
            }