Dear Group!
I have a device I'm trying to connect to, not very successfully... I
need to compute a 16bit CRC and would greatly appreciate some help. I
have an example written in C, and would like some help translating it to
PBP. This is the only information I have on the CRC. Any help would be
appreciated
Thanks for any help.
/************************************************** *********************
********
* crc16
*
* DESCRIPTION:
* This function computes a 16 bit CRC value for an array of bytes as
specified
* . The value that is returned by this
* function needs to be inverted before it gets placed into the packet.
The CRC
* goes at the end of the packet, low byte first. For example:
*
* crc = ~crc16(0xFFFF, msgbuf, length);
*
*
* INPUTS:
* crc - the value to start computing the CRC with. This allows for
chaining
* together of CRC values computed for multiple arrays of data. The
* initial value should be FFFFh (#defined as CRC_INIT).
* ptr - the pointer to the array of bytes to compute the CRC for
* length - the length of the data array
*
* OUTPUTS:
* returns - the computed 16 bit crc value ****/
#define unit16_t unsigned short
#define unit8_t unsigned char
uint16_t crc16(uint16_t crc, uint8_t *ptr, int length)
{
auto uint16_t i;
while(length--)
{
crc = crc ^ (uint16_t) *ptr++;
for(i=0;i<8;i++)
{
if(crc & 0x0001)
crc = (crc >> 1) ^ 0x8408;
else
crc >>= 1;
}
}
return crc;
}
And this is my ripped code in pbp:
for j = 0 to lenght
crc=crc^(send_data[j]*$ffff)
for i=0 to 7
if (crc & $0001) then
crc=(crc>>1)^$8408
else
crc=crc>>1
endif
next i
next j
return
but doesn't work
Bookmarks