How to Compute The 16-bit CRC Of Struct Data?
John K.
Bacau,

Sep 24, 2011
55 Posts

#### How to compute the 16-bit CRC of struct data?

Hi there! I have to implement the CRC-CCITT 16 bit algorithm for computing the Cyclic Redundancy Check of some packets of data that has to be transmitted over a RS-232 communication line. I have the algorithm written in C++, but I have difficulties implementing it in ATEasy. First of all, the C++ algorithm needs a pointer to the data buffer (uint8 *buf) and its length. I don't know how can I express the pointer to byte so the bytes will be extracted like from an array of bytes (inside the CRC computing routine, there's buf[data_index]^=CRC_table[index] etc.). My IN data represents some custom defined structures in ATEasy, and I don't know how can I give them as parameters for the CRC computing routine (how can I transform a structure into a pointer to byte??). PLEASE, help me!!

Best regards,
John K.

DrATEasy (Ron Y.)
Mission Viejo,

Sep 26, 2011
240 Posts

#### Re: How to compute the 16-bit CRC of struct data?

Pass the element index to the procedure and the structure that holds the array:

a(st, iIndex)   ! call

! procedure to accept the structure and index
a(st: structA, iIndex : long)
{
st.array[iIndex]= ...
}

John K.
Bacau,

Sep 26, 2011
55 Posts

#### Re: How to compute the 16-bit CRC of struct data?

Hi, Ronnie! I think you've misunderstood. My struct doesn't have any array. My struct has 3 byte fields and one field that holds another structure that has to be one type out of 5. So, I've declared this last field as variant and my root structure accepts it. My CRC calculation routine needs a pointer to where the data is. So, it is of type "var byte[]", and I use MemoryCopy(&byteArray, &rootStruct,sizeof(rootStruct),); before this, I redim byteArray according to the size of rootStruct. Everything good 'til now. I'm passing the byteArray to my CRC procedure but everytime I open ATEasy and do this, a different CRC value is computed! I looked into my rootStruct and it contains different data that I suppose it came from that last field that holds a struct and is of type variant... What am I doing wrong?

John K.
Bacau,

Sep 26, 2011
55 Posts

#### Re: How to compute the 16-bit CRC of struct data?

So, that last field of the root struct (the field that holds a struct) is unchanged but it looks like the memory locations where it is placed contain different data and this is not normal, right?

DrATEasy (Ron Y.)
Mission Viejo,

Sep 26, 2011
240 Posts