Beispiel #1
0
QVariantMap NetworkManager::SerialSetting::toMap() const
{
    QVariantMap setting;

    if (baud() != 57600) {
        setting.insert(QLatin1String(NM_SETTING_SERIAL_BAUD), baud());
    }

    if (bits() != 8) {
        setting.insert(QLatin1String(NM_SETTING_SERIAL_BITS), bits());
    }

    if (parity() != NoParity) {
        if (parity() == EvenParity) {
            setting.insert(QLatin1String(NM_SETTING_SERIAL_PARITY), 'E');
        } else if (parity() == OddParity) {
            setting.insert(QLatin1String(NM_SETTING_SERIAL_PARITY), 'o');
        }
    }

    if (stopbits() != 1) {
        setting.insert(QLatin1String(NM_SETTING_SERIAL_STOPBITS), stopbits());
    }

    if (sendDelay()) {
        setting.insert(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY), sendDelay());
    }

    return setting;
}
Beispiel #2
0
void dcf_decode(void)
{
	//minutes

	//start bit dcf_data[20]
	//RTCTime rtc;
	uint8_t minutes = bcd2num(&dcf_data[21], 7);
	uint8_t hours = bcd2num(&dcf_data[29], 6);
	uint8_t day = bcd2num(&dcf_data[36], 6);
	uint8_t month = bcd2num(&dcf_data[45], 5);
	uint32_t year = bcd2num(&dcf_data[50], 8);

	uint8_t p1 = parity(&dcf_data[21], 7);
	uint8_t p2 = parity(&dcf_data[29], 6);
	uint8_t p3 = parity(&dcf_data[36], 22);

	uint8_t p11 = dcf_data[28];
	uint8_t p22 = dcf_data[35];
	uint8_t p33 = dcf_data[58];

	if (p1 == p11 && p2 == p22 && p3 == p33)
	{
		time = minutes * 60;
		time += hours * 3600;
		time_valid = 1;

		//rtc.tv_sec += day * 86400;
		//rtc.tv_sec += month * 2629743;
		//rtc.tv_sec += year * 31556926;

		//rtcSetTime(&RTCD1, &rtc);
	}
}
Beispiel #3
0
/**
* Handle parameters and decide which function should be used
* @param argc Number of parameters
* @param argv Array of paramters
* @return Status code
**/
int main(int argc, char* argv[])
{
	CURL* curlHandle;
	int p, wgetCode;

	if(argc == 2)
	{
		p = parity(argv[1]);
		if(p == 0 || p ==1)
		{
			printf("%d\n", p);
			return EXIT_SUCCESS;
		}
		else
		{
			printError(p, argv[1]);
			return EXIT_FAILURE;
		}
	}
	else if(argc % 2 == 0)
	{
		printError(PARAMCOUNT, NULL);
		return EXIT_FAILURE;
	}
	else
	{

		curlHandle = curl_easy_init();

		for(int i = 1; i < argc; i = i + 2)
		{
			wgetCode = wget(argv[i], argv[i+1], &curlHandle);
			if(wgetCode == 0)
			{
				p = parity(argv[i+1]);

				if(p == 1 || p == 0)
				{
					printf("%d", p);
				}
				else
				{
					return 2;
				}
			}
			else
			{
				return 3;
			}
		}

		printf("\n");
		curl_easy_cleanup(curlHandle);
	}

	return EXIT_SUCCESS;
}
void easyVitEncoder(unsigned char data[], int arrayBits, unsigned char symbols[], unsigned char bits[]) {
  int sr = 0;
  int i = 0;
  for(i = 0; i < arrayBits + 6; i++) {
    int bit = i < arrayBits ? ((data[i / 8]) >> (i % 8)) & 1 : 0;
    sr = (sr << 1) | bit;
    bits[i / 8] = sr & 0xFF;
    symbols[2 * i + 0] = parity(sr & V27POLYA) == 0 ? 0: 255;
    symbols[2 * i + 1] = parity(sr & V27POLYB) == 0 ? 0: 255;
  }
}
Beispiel #5
0
///////////////////////////////////////////////////////////////////////////////
// Function Name:void ProChunk()
// Feature:To compute sha1_A sha1 value of datas in blocks of fixed size(512 bit)
///////////////////////////////////////////////////////////////////////////////
static void ProChunk()
{
	short t;
	unsigned long wTmp;
	
	sha_ClearW();
	CopyM2W();
	
	for(t=16;t<80;t++)
	{
		wTmp=sha1_w[t-3]^sha1_w[t-8]^sha1_w[t-14]^sha1_w[t-16];
		sha1_w[t]=S_LEFT(wTmp,1);
	}
	
	sha1_A=sha1_h[0];
	sha1_B=sha1_h[1];
	sha1_C=sha1_h[2];
	sha1_D=sha1_h[3];
	sha1_E=sha1_h[4];
	
	for(t=0;t<80;t++)
	{
		sha1_temp=S_LEFT(sha1_A,5);
		sha1_temp=sha1_temp+sha1_E;
		sha1_temp=sha1_temp+sha1_w[t];
		if(0<=t&&t<=19)
		{
			sha1_temp+=ch(sha1_B,sha1_C,sha1_D)+KT1;        
		}
		if(20<=t&&t<=39)
		{
			sha1_temp+=parity(sha1_B,sha1_C,sha1_D)+KT2;
		}
		if(40<=t&&t<=59)
		{
			sha1_temp+=maj(sha1_B,sha1_C,sha1_D)+KT3;
		}
		if(60<=t&&t<=79)
		{
			sha1_temp+=parity(sha1_B,sha1_C,sha1_D)+KT4;
		}
		sha1_E=sha1_D;
		sha1_D=sha1_C;
		sha1_C=S_LEFT(sha1_B,30);
		sha1_B=sha1_A;
		sha1_A=sha1_temp;
	}
	sha1_h[0]+=sha1_A;
	sha1_h[1]+=sha1_B;
	sha1_h[2]+=sha1_C;
	sha1_h[3]+=sha1_D;
	sha1_h[4]+=sha1_E;
}
Beispiel #6
0
// convert 96 bit AWID FSK data to 8 digit BCD UID
BOOL awid26_hex_to_uid(unsigned char *response, unsigned char *awid26)
{
    BYTE i, tmp[96], tmp1[7];
    unsigned int site;
    unsigned int id;

    if(!hextobinarray(tmp, awid26))
        return FALSE;

    // data is in blocks of 4 bits - every 4th bit is parity, except the first
    // block which is all zeros
    for(i= 0 ; i < 4 ; ++i)
        if(tmp[i] != 0x00)
            return FALSE;

    // discard 1st block
    memcpy(tmp, tmp + 4, 92);

    // check and strip parity on the rest
    for(i= 1 ; i < 23 ; ++i)
        if(tmp[(i * 4) - 1] != parity(tmp + (i - 1) * 4, ODD, 3))
            return FALSE;
        else
            memcpy((tmp + (i - 1) * 3), tmp + (i - 1) * 4, 3);

    // discard the rest of the header - 1 more 3 bit block
    memcpy(tmp, tmp + 3, 66);

    // next 8 bits is data length - should be 26: 0x1A
    binarraytohex(tmp1, tmp, 8);
    if(strcmp(tmp1, "1A") != 0)
        return FALSE;
    memcpy(tmp, tmp +8, 58);

    // standard wiegand parity check - even for 1st 12 bits, odd for 2nd 12
    if(tmp[0] != parity(tmp + 1, EVEN, 12))
        return FALSE;
    if(tmp[25] != parity(tmp + 13, ODD, 12))
        return FALSE;

    // convert to hex, ignoring parity bits
    if(!binarraytohex(tmp1, tmp + 1, 24))
        return FALSE;

    // convert hex to site/id
    sscanf(tmp1,"%2X%4X", &site, &id);

    // final output 8 byte BCD
    sprintf(response,"%03d%05d", site, id);

    return TRUE;
}
Beispiel #7
0
void test()
{

  uint8_t i,j;

  for(i=0; i<NROWS; i++)
    {
      row_buffer(i)[2] = parity(hex(i>>4));
      row_buffer(i)[3] = parity(hex(i&0xf));
      row_buffer(i)[4] = ' ';
      for(j=5; j<42; j++)
        row_buffer(i)[j] = parity('A'-5+j);
    }

}
// -----------------------------------------------------------------------------
// CWPPushMessage::ConvertIMSIL
// -----------------------------------------------------------------------------
//
void CWPPushMessage::ConvertIMSIL( const TDesC& aIMSI, TPtr8& aKey ) const
    {
    TUint8 parity( TUint8((aIMSI.Length() % 2) << KParityBitNum) );

    if( aIMSI.Length() == 0 )
        {
        aKey.Append( (KPadNibble<<KNumBitsInNibble) + KFirstNibble + parity );
        return;
        }

    // First byte contains just a header and one digit
    TInt first( aIMSI[0] - KZero );
    aKey.Append( (first<<KNumBitsInNibble) | KFirstNibble | parity );

    // Use semi-octet or BCD packing of IMSI. It means that one byte contains
    // two decimal numbers, each in its own nibble.
    for( TInt i( 1 ); i < aIMSI.Length(); i += KNumDigitsInByte )
        {
        first = aIMSI[i] - KZero;
        TInt second( 0 );

        if( aIMSI.Length() == i+1 )
            {
            second = KPadNibble;
            }
        else
            {
            second = aIMSI[i+1] - KZero;
            }

        aKey.Append( (second<<KNumBitsInNibble) + first );
        }
    }
Beispiel #9
0
void console_putchar(char c)
{
  if (c==0) return;
  switch(c)
    {
    case '\n':
      column = 0;
      row++;
      break;
    default:
      row_buffer(row)[2+column] = parity(c);
      column++;
      break;
    }
  if(column >= 40)
    {
      column = 0;
      row++;
    }

  if((row > 0) && ((row%NROWS) == first_row))
    {
      row %= NROWS;
      first_row++;
      first_row %= NROWS;
      console_clear_buffer(row);
      move_rows();
    }
}
int myPrev(int rank, int dim){
    
    int nOnes;
    int position;
    int next;
    
    nOnes = parity(rank);
    
    /* If rank is 100..0 */
    if(rank == 0){
        
        next = (power(2, (dim-1) ));
    }
    /* Odd Number of one Bits */
    else if(nOnes % 2 == 1){
        
        next = flip(rank, 0);
        
    }
    /* Even number of one bits */
    else if(nOnes % 2 == 0){
        
        position = findFirst(rank);
        next = flip(rank, position+1);
    }
    
    return next;
    
}
Beispiel #11
0
void get_readings() {
    /*
    Get readings for current, raw angle, wraps, unwrapped angle, and velocity
    */
    // Read current pin and zero-center
    CURRENT.w = pin_read(&A[0]) - CUR_OFFSET;

    // Read the encoder, check parity, and subtract initial offset
    LAST_ANGLE = ANGLE;
    WORD result = enc_readReg((WORD) REG_ANG_ADDR);
    if (!parity(result.w)) {
        ANGLE.w = ((result.w & ENC_MASK) - ANG_OFFSET.w) & ENC_MASK;
    }

    // Check for wrapping; if the angle jumps from <~20 degrees
    // to >~340 degrees, or vice-versa, we wrapped
    if ((ANGLE.w < 0x038E) && (LAST_ANGLE.w > 0x3C71)) {
        WRAPS += 1;
    } else if ((ANGLE.w > 0x3C71) && (LAST_ANGLE.w < 0x038E)) {
        WRAPS -= 1;
    }

    // Apply wrapping to the raw angle
    uint16_t last = UNWRAPPED_ANGLE.w;
    UNWRAPPED_ANGLE.w = ANGLE.w + ENC_MASK * WRAPS;

    // Calculate velocity as (change in angle) / (time between readings)
    // Divide by 16 to avoid overflow
    VELOCITY.w = (UNWRAPPED_ANGLE.w - last) * (READ_FREQ / 16);
}
Beispiel #12
0
// convert 16 hex digit/64 bit EM4X02 ID to 40 bit raw UID
// safe to do in-place as we use a scratchpad
BOOL em4x02_hex_to_bin(unsigned char *bin, unsigned char *em)
{
    unsigned char i, j, colparity[4]= {0,0,0,0};

    if(!hextobinarray(TmpBits, em))
        return FALSE;
    
    // check header
    for(i= 0 ; i < 9 ; ++i)
        if(TmpBits[i] != 0x01)
            return FALSE;

    // skip 9 bit header and strip/check parity bits - every 5th bit
    for(i= 0 ; i < 10 ; ++i)
    {
        memcpy(bin + i * 4, (TmpBits + 9) + i * 5, 4);
        if(parity(bin + i * 4, EVEN, 4) != TmpBits[9 + i * 5 + 4])
            return FALSE;
    }

    // check column parity
    for(i= 0 ; i < 10 ; ++i)
        for(j= 0; j < 4 ; ++j)
            colparity[j] += bin[i * 4 + j];
    for(i= 0 ; i < 4 ; ++i)
        if(colparity[i] % 2 != TmpBits[9 + 50 + i])
            return FALSE;

    return TRUE;
}
Beispiel #13
0
int16_t main(void) {
    init_clock();
    init_timer();
    init_ui();
    init_pin();
    init_spi();
    init_oc();
    init_md();

    // Current measurement pin
    pin_analogIn(&A[0]);

    // SPI pin setup
    ENC_MISO = &D[1];
    ENC_MOSI = &D[0];
    ENC_SCK = &D[2];
    ENC_NCS = &D[3];
    pin_digitalOut(ENC_NCS);
    pin_set(ENC_NCS);

    // Open SPI in mode 1
    spi_open(&spi1, ENC_MISO, ENC_MOSI, ENC_SCK, 2e6, 1);

    // Motor setup
    md_velocity(&md1, 0, 0);

    // Get initial angle offset
    uint8_t unset = 1;
    while (unset) {
        ANG_OFFSET = enc_readReg((WORD) REG_ANG_ADDR);
        unset = parity(ANG_OFFSET.w);
    }
    ANG_OFFSET.w &= ENC_MASK;

    // USB setup
    InitUSB();
    while (USB_USWSTAT!=CONFIG_STATE) {
        ServiceUSB();
    }

    // Timers
    timer_setFreq(&timer2, READ_FREQ);
    timer_setFreq(&timer3, CTRL_FREQ);
    timer_start(&timer2);
    timer_start(&timer3);

    // Main loop
    while (1) {
        ServiceUSB();
        if (timer_flag(&timer2)) {
            timer_lower(&timer2);
            get_readings();
        }
        if (timer_flag(&timer3)) {
            timer_lower(&timer3);
            set_velocity();
        }
    }
}
Beispiel #14
0
static int __init sbf_value_valid(u8 v)
{
	if(v&SBF_RESERVED)		/* Reserved bits */
		return 0;
	if(!parity(v))
		return 0;
	return 1;
}
Beispiel #15
0
void main() {
    int val;
    while (1 == 1) {
        printf("Value?: ");
        scanf("%d", &val);
        printf("%s", parity(val) == EVEN ? "Even\n" : "Odd\n");
    }
}
Beispiel #16
0
std::string BBS::rand(const unsigned int & bits, const std::string & par){
    // returns string because SIZE might be larger than 64 bits
    std::string out(bits, '0');
    for(char & c : out){
        r_number();
        c += parity(par);
    }
    return out;
}
Beispiel #17
0
boolean RFStructure::reassembleFrame(byte packetIn){
  RFPacket packet;
  packet.__private_byte_ = packetIn;
  byte status = 0;
  switch (packet.PacketIDCheck.ID){
    case IdentifierPacket:
      if (frame.index != 0) {
        goto packetError; //packet was recieved at wrong time, so drop the current frame.
      }
      if (packet.IdentifierPacket.channel != channel) {
        goto packetError; //packet not meant for this channel
      }
      break;
    case ChecksumPacket:
      if (frame.index != frame.length-1) {
        goto packetError; //packet was recieved at wrong time, so drop the current frame.
      }
      if (packet.ChecksumPacket.checksum != (checksum()&0x3F)){
        goto packetError; //checkusm failed, so abandon this packet.
      }
      status = 1; //packet completed successfully.
      break;
    case DataPacket:
      if (packet.ParityChecker.parity != parity(packet).ParityChecker.parity) {
        goto packetError; //parity check failed, so abandon this packet
      }
      if ((frame.index == 0) || (frame.index > frame.payload + 1)) {
        goto packetError; //packet was recieved at wrong time, so drop the current frame.
      } else if (frame.index == 1) {
        //header
        frame.payload = packet.HeaderPacket.length;
        frame.length = packet.HeaderPacket.length + 3;
      }/* else if (frame.index == 2){
        //digital
        
      } else {
        //analog
        
      }*/ //for the time being, analog and digital are not handled here. Just accept them if parity is passed.
      break;
    default:
      //invalid packet, so ignore. This accounts mainly for noise induced packets which are usually 0x00 or 0x01 and so must be filtered out, but are not a frame error... yet.
      return status;
  }
  
  frame.data[frame.index] = packet;
  frame.index++;
  if (status) {
    frame.index = 0; //ready for next time.
  }
  return status;

packetError:
  frame.clear();
  return status;
}
Beispiel #18
0
void console_setup()
{

  /* In console mode the buffer is used like a text console.
     Scrolling is implemented by changing the line numbers
     in each packet. The whole buffer is sent repeatedly. */

  tt_buffer[0][0] = 0x2;
  tt_buffer[0][1] = 0x15;
  tt_buffer[0][2] = 0x15;
  tt_buffer[0][3] = 0x15;
  tt_buffer[0][4] = 0x15;
  tt_buffer[0][5] = 0x15;
  tt_buffer[0][6] = 0x15;
  tt_buffer[0][7] = 0x15;
  tt_buffer[0][8] = 0x15;
  tt_buffer[0][9] = 0x15;
  tt_buffer[0][10] = parity('A');
  tt_buffer[0][11] = parity('V');
  tt_buffer[0][12] = parity('R');
  tt_buffer[0][13] = parity(' ');
  tt_buffer[0][14] = parity('T');
  tt_buffer[0][15] = parity('e');
  tt_buffer[0][16] = parity('x');
  tt_buffer[0][17] = parity('t');
  tt_buffer[0][18] = 0x20;
  tt_buffer[0][19] = 0x31;
  tt_buffer[0][20] = 0xb0;
  tt_buffer[0][21] = 0xb0;
  tt_buffer[0][22] = 0x20;
  tt_buffer[0][23] = 0x54;
  tt_buffer[0][24] = 0x75;
  tt_buffer[0][25] = 0xe5;
  tt_buffer[0][26] = 0x20;
  tt_buffer[0][27] = 0x31;
  tt_buffer[0][28] = 0x37;
  tt_buffer[0][29] = 0x20;
  tt_buffer[0][30] = 0x4a;
  tt_buffer[0][31] = 0x61;
  tt_buffer[0][32] = 0x6e;
  tt_buffer[0][33] = 0x83;
  tt_buffer[0][34] = 0x32;
  tt_buffer[0][35] = 0x31;
  tt_buffer[0][36] = 0xba;
  tt_buffer[0][37] = 0xb5;
  tt_buffer[0][38] = 0xb0;
  tt_buffer[0][39] = 0x2f;
  tt_buffer[0][40] = 0xb3;
  tt_buffer[0][41] = 0xb6;

  console_clear();
  buffer_head = NBUFFERS; // Will never be reached.
}
void CSt4285::convolutional_init( void )
{
	int i;

	/* Build the encoding Tables */	
	for( i=0; i< 128; i++)
	{
		parity( i, &parity_lookup[i].bit1, &parity_lookup[i].bit2 );
	}
	path_length = NORMAL_PATH_LENGTH;
}
Beispiel #20
0
/* Determine basis size */
int BasisSize()
/*======================================================================= */
{

/* Loop variables */
int L1, jK1, K1, M1, pS1, qS1, pI1, qI1, pI1b, qI1b;

/* Min and max values for loop variables */
int K1max, M1max, qS1max, qI1max, qI1bmax;

int iRow = 0;
double I = Sys.I;
double Ib = Sys.Ib;

for (L1=0;L1<=Lemax;L1++) {
  if (isodd(L1) && (L1>Lomax)) continue;
  for (jK1=jKmin;jK1<=1;jK1+=2) {
    K1max = mini(Kmax,L1);
    for (K1=0;K1<=K1max;K1+=deltaK) {
      if ((K1==0)&(parity(L1)!=jK1)) continue;
      M1max = mini(Mmax,L1);
      for (M1=-M1max;M1<=M1max;M1++) {
      
        for (pS1=pSmin;pS1<=1;pS1++) {
          qS1max = 1 - abs(pS1);
          for (qS1=-qS1max;qS1<=qS1max;qS1+=2) {
          
            for (pI1 = -pImax;pI1<=pImax;pI1++) {
              qI1max = (int)(2*I) - abs(pI1);
              for (qI1=-qI1max;qI1<=qI1max;qI1+=2) {
                
                for (pI1b = -pIbmax;pI1b<=pIbmax;pI1b++) {
                  if ((MeirovitchSymm) && (Sys.DirTilt==0)&&((pI1+pI1b+pS1-1)!=M1)) continue;
                  qI1bmax = (int)(2*Ib) - abs(pI1b);
                  for (qI1b=-qI1bmax;qI1b<=qI1bmax;qI1b+=2) {
                
                    /*mexPrintf("%3d %3d %3d %3d    %2d %2d %2d %2d %2d %2d\n",L1,jK1,K1,M1,pS1,qS1,pI1,qI1,pI2,qI2);*/
                    
                    iRow++;
                  } /* qI1b */
                } /* pI1b */
              } /* qI1 */
            } /* pI1 */
          } /* qS1 */
        } /* pS1 */
		
      } /* M1 */
    } /* K1 */
  } /* jK1 */
} /* L1 */

return iRow; /* number of rows */

}
Beispiel #21
0
int main()
{
	int m_iExampleValue = 3213215;

	if (true == parity(m_iExampleValue))
		std::cout << "Parity check: even" << std::endl;	
	else
		std::cout << "Parity check: odd" << std::endl;	
	
	return 0;
}
Beispiel #22
0
static void calc_ecc(u8 *data, u8 *ecc)
{
	u8 a[12][2];
	int i, j;
	u32 a0, a1;
	u8 x;

	memset(a, 0, sizeof a);
	for (i = 0; i < 512; i++) {
		x = data[i];
		for (j = 0; j < 9; j++)
			a[3+j][(i >> j) & 1] ^= x;
	}

	x = a[3][0] ^ a[3][1];
	a[0][0] = x & 0x55;
	a[0][1] = x & 0xaa;
	a[1][0] = x & 0x33;
	a[1][1] = x & 0xcc;
	a[2][0] = x & 0x0f;
	a[2][1] = x & 0xf0;

	for (j = 0; j < 12; j++) {
		a[j][0] = parity(a[j][0]);
		a[j][1] = parity(a[j][1]);
	}

	a0 = a1 = 0;
	for (j = 0; j < 12; j++) {
		a0 |= a[j][0] << j;
		a1 |= a[j][1] << j;
	}

	ecc[0] = a0;
	ecc[1] = a0 >> 8;
	ecc[2] = a1;
	ecc[3] = a1 >> 8;
}
Beispiel #23
0
int main(void)
{
	init();

	//prog code
	PORTD = parity( 0x01 );
	delay_ms(1000);

	PORTD = 0xFF;
	delay_ms(1000);

	PORTD = parity( 0x03 );
	delay_ms(1000);

	PORTD = 0xFF;
	delay_ms(1000);

	PORTD = parity( 0x02 );
	delay_ms(1000);

	while(1);

	return 0;
}	
void CSt4285::code_generate(void)
{
	int i;
	int last0;
	int last1;
	int dibit0;
	int dibit1;
	int temp1;
	int temp2;
	
	for(i=0; i< NR_CONVOLUTIONAL_STATES; i++ )
	{
		last0 = (i<<1)&0x3F;
		last1 = ((i<<1)+1)&0x3F;

		parity((i<<1),&temp1,&temp2);
		dibit0 = (temp1<<1)+temp2;

		parity((i<<1)+1,&temp1,&temp2);
		dibit1 = (temp1<<1)+temp2;
		
		printf("\tBF(%d,%d,%d,%d,%d)\n",i,last0,dibit0,last1,dibit1);
	}
}
Beispiel #25
0
WORD enc_readReg(WORD address) {
    WORD cmd, result;
    cmd.w = 0x4000|address.w; //set 2nd MSB to 1 for a read
    cmd.w |= parity(cmd.w)<<15; //calculate even parity for

    pin_clear(ENC_NCS);
    spi_transfer(&spi1, cmd.b[1]);
    spi_transfer(&spi1, cmd.b[0]);
    pin_set(ENC_NCS);

    pin_clear(ENC_NCS);
    result.b[1] = spi_transfer(&spi1, 0);
    result.b[0] = spi_transfer(&spi1, 0);
    pin_set(ENC_NCS);
    return result;
}
Beispiel #26
0
static void __init sbf_write(u8 v)
{
	unsigned long flags;
	if(sbf_port != -1)
	{
		v &= ~SBF_PARITY;
		if(!parity(v))
			v|=SBF_PARITY;

		printk(KERN_INFO "SBF: Setting boot flags 0x%x\n",v);

		spin_lock_irqsave(&rtc_lock, flags);
		CMOS_WRITE(v, sbf_port);
		spin_unlock_irqrestore(&rtc_lock, flags);
	}
}
Beispiel #27
0
// convert null-terminated BCD UID (8 digits) to 96 bit awid26 encoded binary array
BOOL bcd_to_awid26_bin(unsigned char *awid26, unsigned char *bcd)
{
    unsigned char i, p, tmp1[8], tmp2[26];
    unsigned int tmpint;

    if(strlen(bcd) != 8)
        return FALSE;

    // convert BCD site code to HEX
    sscanf(bcd, "%03d", &tmpint);
    sprintf(tmp2, "%02x", tmpint);
    memcpy(tmp1, tmp2, 2);

    // convert BCD ID to HEX
    sscanf(bcd + 3, "%05d", &tmpint);;
    sprintf(tmp2, "%04x", tmpint);
    // copy with trailing NULL
    memcpy(tmp1 + 2, tmp2, 5);

    // convert full HEX to binary, leaving room for parity prefix
    hextobinarray(tmp2 + 1, tmp1);
    
    wiegand_add_parity(tmp2, tmp2 + 1, 24);

    memset(awid26, '\x0', 96);

    // magic 18 bit awid26 header (we will overwrite the last two bits)
    hextobinarray(awid26, "011D8");

    // copy to target leaving space for parity bits
    for(i= 0, p= 18 ; i < 26 ; ++i, ++p)
    {
        // skip target bit if this is a parity location
        if(!((p + 1) % 4))
            p += 1;
        awid26[p]= tmp2[i];
    }

    // add parity bits
    for(i= 1 ; i < 24 ; ++i)
        awid26[((i + 1) * 4) - 1]= parity(&awid26[i * 4], ODD, 3);

    return TRUE;
}
Beispiel #28
0
void
genmsg(const char *call, const char *grid, const int power)
{
    int c = encodecallsign(call) ;
    int g = encodegrid(grid) ;
    int p = encodepower(power) ;
    int i, mp = 0 ;
    unsigned int acc = 0;

    for (i=0; i<162; i++)
	msg[i] = sync[i] ;

    for (i=27; i>=0; i--) {		/* encode the callsign, 28 bits */
	acc <<= 1 ;
	if (c & (1<<i)) acc |= 1 ;
	msg[rdx[mp++]] += 2*parity(acc & 0xf2d05351L) ;
	msg[rdx[mp++]] += 2*parity(acc & 0xe4613c47L) ;
    }

    for (i=14; i>=0; i--) {		/* encode the grid, 15 bits */
	acc <<= 1 ;
	if (g & (1<<i)) acc |= 1 ;
	msg[rdx[mp++]] += 2*parity(acc & 0xf2d05351L) ;
	msg[rdx[mp++]] += 2*parity(acc & 0xe4613c47L) ;
    }

    for (i=6; i>=0; i--) {		/* encode the power, 7 bits */
	acc <<= 1 ;
	if (p & (1<<i)) acc |= 1 ;
	msg[rdx[mp++]] += 2*parity(acc & 0xf2d05351L) ;
	msg[rdx[mp++]] += 2*parity(acc & 0xe4613c47L) ;
    }

    for (i=30; i>=0; i--) {		/* pad with 31 zero bits */
	acc <<= 1 ;
	msg[rdx[mp++]] += 2*parity(acc & 0xf2d05351L) ;
	msg[rdx[mp++]] += 2*parity(acc & 0xe4613c47L) ;
    }
}
Beispiel #29
0
/* Wait until receiving a non-corrupted packet */
void comm_rx(finalDataRegister *data)
{
  finalDataRegister buff;
	union comm_value rx;
	int corrupted = TRUE;	
	while (corrupted) {
	
		/* Block until receiving */
		while (!e_randb_reception(&buff)) ; //NADA

		/* Check parity bit */
		rx.value = buff.data;
		corrupted = (parity(rx.value) != rx.bits.checksum);
		char msg[80];
		sprintf(msg,"%i\r\n",corrupted);
		btcomSendString(msg);
	}
	// Copy result in output buffer
	*data = buff;
}
Beispiel #30
0
WORD enc_readReg(WORD address) {
    /*
    Given an address, return the value from the encoder's register at that address
    */
    WORD cmd, result;
    cmd.w = 0x4000|address.w; //set 2nd MSB to 1 for a read
    cmd.w |= parity(cmd.w)<<15; //calculate even parity for

    // Tell the sensor which register we want to read
    pin_clear(ENC_NCS);
    spi_transfer(&spi1, cmd.b[1]);
    spi_transfer(&spi1, cmd.b[0]);
    pin_set(ENC_NCS);

    // Get the reading from the sensor
    pin_clear(ENC_NCS);
    result.b[1] = spi_transfer(&spi1, 0);
    result.b[0] = spi_transfer(&spi1, 0);
    pin_set(ENC_NCS);
    return result;
}