CRC calculation confusion

Hi all, As you see I'm new to Arduino world, so please help about the following problem : I'm sending a string from Android to Arduino trough bluetooth, and I wand to ensure this string by calculating CRC. In my java code my string is : ":0100000035" it's CRC = E9601FB

in my sketch I have a function that calculate CRC :

static PROGMEM prog_uint32_t crc_table[16] = {
    0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
    0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
    0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
    0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};

unsigned long crc_update(unsigned long crc, byte data)
{
    byte tbl_idx;
    tbl_idx = crc ^ (data >> (0 * 4));
    crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4);
    tbl_idx = crc ^ (data >> (1 * 4));
    crc = pgm_read_dword_near(crc_table + (tbl_idx & 0x0f)) ^ (crc >> 4);
    return crc;
}

unsigned long crc_string(char *s)
{
  unsigned long crc = ~0L;
  while (*s)
    crc = crc_update(crc, *s++);
  crc = ~crc;
  return crc;
}

In my loop I'm reading from bluetooth module :

 if (BTSerial.available() > 0) {
      line[count] = (byte)BTSerial.read();
      if (line[count++] == '\r'){
        line[count] = '\0';             //  zero-terminate it
        Serial.println(line);
       
        bufferline[0] = line[0];
      
        bufferline[1] = line[1];
        bufferline[2] = line[2];
       
        //DATA
        bufferline[3] = line[3];
        bufferline[4] = line[4];
        bufferline[5] = line[5];
        bufferline[6] = line[6];
        bufferline[7] = line[7];
        bufferline[8] = line[8];
        bufferline[9] = line[9];
        bufferline[10] = line[10];

        
               
        Serial.println(bufferline); => :0100000035
        Serial.println(crc_string(bufferline), HEX); => F1D51E33
        
        Serial.println("CRC  OF  :0100000035");
        Serial.println(crc_string(":0100000035"), HEX); => E9601FB

        //Serial.println(encode_int(checksum(bufferline)));         //  and print it.
        Serial.println("loop");         // re-prompt
        count = 0;
      }
      delay(10);

As you see crc_string(bufferline) is different from crc_string(":0100000035") with bufferline is char[11]

Am I missing anything ?

Thanks

bufferline[0] = line[0];
      
        bufferline[1] = line[1];
        bufferline[2] = line[2];

What's all that?

        Serial.println(bufferline); => :0100000035
        Serial.println(crc_string(bufferline), HEX); => F1D51E33
        
        Serial.println("CRC  OF  :0100000035");
        Serial.println(crc_string(":0100000035"), HEX); => E9601FB

Is this crap supposed to compile?

PaulS:         Serial.println(bufferline); => :0100000035         Serial.println(crc_string(bufferline), HEX); => F1D51E33                 Serial.println("CRC  OF  :0100000035");         Serial.println(crc_string(":0100000035"), HEX); => E9601FB

Is this crap supposed to compile?

no of course, I'm showing you the diffence between the results given by Serial.println(crc_string(bufferline), HEX); and Serial.println(crc_string(":0100000035"), HEX);

AWOL: bufferline[0] = line[0];               bufferline[1] = line[1];         bufferline[2] = line[2];

What's all that?

Here I'm constructing : char[11] bufferline; from the chars received by serial

Here I'm constructing : Code:

char[11] bufferline;

from the chars received by serial

Why? Why not simply pass line to the function? Or, use strcpy() or memcpy()?

Anonymous Serial.print() statements are next to useless.

Serial.print("bufferline: [");
Serial.print(bufferline);
Serial.print("]");

conveys FAR more information.

PaulS:

Here I'm constructing : Code:

char[11] bufferline;

from the chars received by serial

Why? Why not simply pass line to the function? Or, use strcpy() or memcpy()?

Anonymous Serial.print() statements are next to useless.

Serial.print("bufferline: [");
Serial.print(bufferline);
Serial.print("]");

conveys FAR more information.

The hole line is supposed to be longer than 11, let's say 11+(CRC calculated by android), in arduino side, I will extract the data lenght of 11 calculate it's CRC and comparing it to the CRC calculated by Android to ensure the integrity of the received data, that's the idea

The hole line is supposed to be longer than 11

Then why are you dealing with only 11 characters? Why are you using an array that can only hold 11 characters?

What does that response have to do with not using a for loop or professionally tested function? What does that have to do with NOT bracketing and identifying what you are printing?

PaulS:

The hole line is supposed to be longer than 11

Then why are you dealing with only 11 characters? Why are you using an array that can only hold 11 characters?

What does that response have to do with not using a for loop or professionally tested function? What does that have to do with NOT bracketing and identifying what you are printing?

Thanks for the help, and sorry, I’m not understanding what you are trying to tell me, or that could be that I missexplained the problem.

or that could be that I missexplained the problem.

I'm not convinced that you are sending the same data to the function when passing an array and when passing a literal. I'm trying to get you to prove (or disprove) that you are.

PaulS:

or that could be that I missexplained the problem.

I'm not convinced that you are sending the same data to the function when passing an array and when passing a literal. I'm trying to get you to prove (or disprove) that you are.

Yeah mee to, I'm not convinced to be sending the same data TYPE but the same let's say value whitch is ":0100000035"

houssem_riahi:

PaulS:

or that could be that I missexplained the problem.

I'm not convinced that you are sending the same data to the function when passing an array and when passing a literal. I'm trying to get you to prove (or disprove) that you are.

Yeah mee to, I'm not convinced to be sending the same data TYPE but the same let's say value whitch is ":0100000035"

As I said, it's data type problem, my reading was line[count] = (byte)BTSerial.read(); and when I changed it to line[count] = (char)BTSerial.read(); the right CRC is calculated.