#include <FastCRC.h>
FastCRC14 CRC14;
uint8_t t1[12];
uint16_t get_crc(uint8_t *c1,uint8_t *t1)
{
int i,j;
uint8_t bits;
uint16_t b_crc;
// Extract the 77-bit message
for(i = 0;i < 10;i++) {
bits = 0;
for(j = 0;j < 8;j++) {
// Have we processed the 77th bit?
if(i == 9 && j == 5)break;
bits <<= 1;
if(c1[i*8+j] == '1')bits |= 1;
}
t1[i] = bits;
}
t1[9] = bits << 3;
t1[10] = 0;
t1[11] = 0;
// The next 14 bits are the CRC
b_crc = 0;
for(i = 0;i < 14;i++) {
b_crc <<= 1;
if(c1[i+77] == '1')b_crc |= 1;
}
return b_crc;
}
void test_crc(const char *c)
{
uint16_t b_crc;
int i;
// Extract the message and the CRC
b_crc = get_crc((uint8_t *)c,t1);
Serial.printf("crc14 = 0x%04X, b_crc = 0x%04X\n",CRC14.ft4(t1,10),b_crc);
}
void setup() {
uint32_t crc;
Serial.begin(9600);
while(!Serial);
delay(1000);
char *p = &__FILE__[strlen(__FILE__)-1];
while(*p != '\\' && p >= __FILE__[0])*p--;
p++;
Serial.print("FILE = ");
Serial.println(p);
const char *c_bits[] = {
"010011000100101010110000110100000111001010011011011101000101001001100111101101000101110111010010000101001011100111111101000011101000101100101010110011111000001101000010000111",
"010011110111011001001100101001001110001001100001001011111111001001100101101101011110111101011001010001100011100101110110110011000011110100011011001010011101111001110111101010",
"001110100010110101011101100101001111111001100100000001001000001001100101111100100110010110110111101011011110000000110110001101000010111010110100100000010110011100101000011101",
"000010101011010100101011000100000000011101001101110011001000001001100101101101111001010000010010001001110111111010100110111100010011111010100000101110001111111111110000000011",
"010010100101111011010111110101001110001100110011011011101101110111101001111000000011101100110111100010001111101100101100101111010111011101101010110101101001001011000101001010",
"010011101000000101000100011110111000100001100110101111001100101001101100101100101101110101011100111011010010111011110000100010111001010101110101000010100110001110000100100100",
"010010100101111011010111110101100010001101011000001010000101110110001001001000100111010000111100010100000000000101101111001010110100000001110000101101111110111001001011000110", //???
"000000001010010000100101111110000001111011011111111111100001101001101011011100100000010011001010001110001101111011100011100001101011010001000011110111000001000101010100000110",
"101011011100101101000100001100000110000001010111010101011100101000011011001000010111000111100011110000001111100100101111110110001011101100011100000000100000001100001111000100",
"010001100100010100101011110100000000110000101111111101100100101000100011011000000101011000010011110111011000101010101000110011010100100101101110011110010111110101101011011000", //???
"000111111000110001010001100111001101000001101010011001100111001001101110111101101000000001111110110111111011010011010111101110110011010010100111010001110100011101000111000001",
"010000111001000100010010111000111011011111001100010001101100101000100011011001101011000101010010000001001100000011011000010110001011001101110111110010000100100100011100110000",
"010010100101111011010111110100111110001000000011000010010101110001000100011000111111100111101011000001110110101101000101011010110110110111000011001010111100101000110111010101",
"010011000100101010110000110100000111001010011011011101000101001001100111101101000101110111010010000101001011100111111101000011101000101100101010110011111000001101000010000111",
"010000000000111100000011100100000000000000111000100111011100101000100011011000001000011000110000110110010001110011101110111010011000110101111101010010100101100000100001111111",
"000111010011000000001011100010111000011101101011001011101110001001101111011100010011000110001000000001010010101001101111111100111101101010110111101101101010111110000101111011", //???
"010010100101111011010111110101001101000010000001011111101101111110101001001001101111110010010111101000011110000100101111110110101110111100010111011010000100010011100011000101",
};
for(uint32_t i = 0;i < sizeof(c_bits)/sizeof(c_bits[0]); i++) {
Serial.printf("i = %2d ",i);
test_crc(c_bits[i]);
// Serial.println();
}
}
void loop(void)
{
}