Exemple #1
0
 //! \brief Append a bit
 void addBit(bit_value_t combinedValue)
    {
       switch (combinedValue) {
       case BIT_0:
          addBit(1, 0);
          break;
       case BIT_1:
          addBit(1, 1);
          break;
       case X:
          addBit(0, 0);
          break;
       }
    }
	void BitWriter::addByte(LByte input)
	{
		for(int i = 0; i < 8; i++)
		{
			addBit(getBit(input, i));
		}
	}
Exemple #3
0
int RLZCompressor::compress() {
    code_t cHigh = code_t_max;
    code_t cLow = 0;
    for(size_t i = 0; i<data.size(); i++) {
        code_t cLength = (cHigh - cLow) + 1;
        int cVal = static_cast<unsigned char>(data[i]);
        //printf("CVal: %d\n", cVal);

        //printf("tIdx: %d\n", charToIdxMap[cVal]);
        Segment nSegment = freqsMap[charToIdxMap[cVal]];

        cHigh = cLow + (nSegment.high * cLength) / freqsRaw[0] - 1;
        cLow = cLow + (nSegment.low * cLength) / freqsRaw[0];

        if(compMode == COMP_MODEL_ADAPTIVE) {
            requestAddSymbolToModel(cVal);
        }

        //normalize it!
        while(1) {
            if(cHigh < code_h) {
                pushBit(0);
            } else if(cLow >= code_h) {
                pushBit(1);
            } else if(cLow >= code_q && cHigh < code_3q) {
                addBit();
                cLow -= code_q;
                cHigh -= code_q;
            } else {
                break;
            }
            cHigh <<= 1;
            cHigh++;
            cLow <<= 1;
            cHigh &= code_t_max;
            cLow &= code_t_max;
        }
    }
    addBit();
    if(cLow < code_q) {
        pushBit(0);
    } else {
        pushBit(1);
    }
    stopEmitter();
    return 1;
}
Exemple #4
0
__interrupt void Port_1(void)
{
	P1IES ^= BIT0;
	int data = (P1IN & BIT0);

	if ( data == SPACE )
	{
		count = 0;
		TotalBitCount++;
		BitCount++;
		if ( BitCount >= 16 )
		{
			index++;
			BitCount = 0;
		}
	}
	else if ( data == MARK )
	{
		addBit(index, count);
		count = 0;
	}

	P1IFG &= ~BIT0;
}
 /*
  * @param a: The first integer
  * @param b: The second integer
  * @return: The sum of a and b
  */
 int aplusb(int a, int b) {
     int s = 0;
     int c = 0;
     addBit(a, b, s, 0, c);
     addBit(a, b, s, 1, c);
     addBit(a, b, s, 2, c);
     addBit(a, b, s, 3, c);
     addBit(a, b, s, 4, c);
     addBit(a, b, s, 5, c);
     addBit(a, b, s, 6, c);
     addBit(a, b, s, 7, c);
     addBit(a, b, s, 8, c);
     addBit(a, b, s, 9, c);
     addBit(a, b, s, 10, c);
     addBit(a, b, s, 11, c);
     addBit(a, b, s, 12, c);
     addBit(a, b, s, 13, c);
     addBit(a, b, s, 14, c);
     addBit(a, b, s, 15, c);
     addBit(a, b, s, 16, c);
     addBit(a, b, s, 17, c);
     addBit(a, b, s, 18, c);
     addBit(a, b, s, 19, c);
     addBit(a, b, s, 20, c);
     addBit(a, b, s, 21, c);
     addBit(a, b, s, 22, c);
     addBit(a, b, s, 23, c);
     addBit(a, b, s, 24, c);
     addBit(a, b, s, 25, c);
     addBit(a, b, s, 26, c);
     addBit(a, b, s, 27, c);
     addBit(a, b, s, 28, c);
     addBit(a, b, s, 29, c);
     addBit(a, b, s, 30, c);
     addBit(a, b, s, 31, c);
     return s;
 }
bool OregonV1Decoder::decode(uint16_t duration, bool pinstate)
{
    bool isLong = duration > 2000;

    switch(signalstate)
    {
        case NOSIGNAL: // Look for preamble
        prelength = 0;
        if (duration >= 1400 && duration <= 2000 && pinstate)
        {
            signalstate = PREAMBLE;
            prelength = 1;
        }
        else
            reset();
        return false;

        case PREAMBLE: // Look for long low
        if (duration >= 1000 && duration <= 1600 && !pinstate)
            prelength++;
        else if (duration >= 1400 && duration <= 2000 && pinstate)
            prelength++;
        else if (duration >= 4000 && duration <= 4600 && !pinstate && prelength > 10)
            signalstate = SYNCLOW;
        else
        {
            signalstate = NOSIGNAL;
            reset();
        }
        return false;

        case SYNCLOW: // Look for long high
        if (duration >= 5300 && duration <= 6000 && pinstate)
            signalstate = SYNCHIGH;
        else
        {
            signalstate = NOSIGNAL;
            reset();
        }
        return false;

        case SYNCHIGH: // Look for long low
        if (duration >= 5000 && duration <= 6000 && !pinstate)
            signalstate = WAIT;
        else if (duration > 6000 && duration <= 7500 && !pinstate)
            signalstate = LOW;
        else
        {
            signalstate = NOSIGNAL;
            reset();
        }
        return false;

        case HIGH:
        addBit(true);
        signalstate = isLong ? LOW : WAIT;
        break;

        case LOW:
        addBit(false);
        signalstate = isLong ? HIGH : WAIT;
        break;

        case WAIT:
        if (isLong)
        {
            signalstate = NOSIGNAL;
            reset();
            return false;
        }
        signalstate = pinstate ? HIGH : LOW;
        break;
    }

    if (totalBitCount == 32)
    {
        signalstate = NOSIGNAL;
        return true;
    }
    else
        return false;
}
	void BitWriter::operator+=(LBit bit_in)
	{
		addBit(bit_in);
	}