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

John K.
Bacau,

Sep 24, 2011
55 Posts

0  |  0  

Re: 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, CA

Sep 26, 2011
358 Posts

0  |  0  

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

0  |  0  

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?

Solution Available
John K.
Bacau,

Sep 26, 2011
55 Posts

1  |  0  

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, CA

Sep 26, 2011
358 Posts

0  |  0  

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

Not sure I understand, upload an example... to your post.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]