Computer Interfacing
Discussions about interfacing and electronics
 

ROC Protocal and CRC


 

       Computer Interfacing Forum Index -> Error detection and correction
Author Message
jolyrojr
New User



Joined: 17 Feb 2014
Posts: 1
Location: New Mexico

Feb 17, 2014 5:24 pm

So, I am trying to write c++ code to check the CRC using the ROC protocol, however, the manual points to a library I cant get to actually work.

"The ROC uses the 16-bit polynomial CRC-16: X16 + X15 + X2 + 1 The ROC uses the standard GPLIB CRC routine, and calculates CRC by table lookup, with the initial condition of 0000 (zeros). "


I also have a CRC16 routine written out in c++, using the poly 0x8005. I get different CRC's for the Lammert Bies online calculator, my routine, and whats listed as the only example in the manual.

1 2 1 0 17 3 M O C crc = 133 and 24

for which I am entering {0x01, 0x02, 0x01, 0x00, 0x11, 0x03, 0x4D, 0x4F, 0x43 };

any help or suggestions would be incredibly appreciated, I am sooo over the crc and I just want to get past this.

Thank you
Gammatester
Guest







Feb 18, 2014 8:13 am

Your example and another taken from a ROC manual shows that the used CRC16 algorithm is CRC-16/ARC
Code:
===== Checking for known algorithms =====
Checked data sets
CRC1: $8518,   Data1: 0102010011034D4F43
CRC2: $7611,   Data2: 01020100E1020700
Found known algorithm: CRC-16/ARC
CRC=$1885  Poly=$8005  init=$0000  xorout=$0000  refin=true   refout=true
 *** Second data set verified
===== done =====
Therefore the polynomial 0x8005 is correct. May be your C++ code uses other Rocksoft parameters. Here is a simple sample C source which implements CRC-16/ARC and reproduce the test values from Rocksoft, the manual and your example:
Code:
//-----------------------------------------------------------------
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>

static uint16_t CRC16_ARC(uint8_t *data, size_t len) {
  uint16_t crc = 0x0000;
  size_t j;
  int i;
  // Note: 0xA001 is the reflection of 0x8005
  for (j=len; j>0; j--) {
    crc ^= *data++;
    for (i=0; i<8; i++) {
      if (crc & 1) crc = (crc >> 1) ^ 0xA001;
      else crc >>= 1;
    }
  }
  return (crc);
}

int main() {
  uint8_t test[9]  = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};
  uint8_t test2[9] = {1, 2, 1, 0, 17, 3, 'M', 'O', 'C'};
  uint8_t test3[8] = {1, 2, 1, 0, 225, 2, 7, 0};
  uint16_t crc;
  crc = CRC16_ARC(test, 9);
  printf("Rocksoft check value: 0x%04X, test ", crc);
  if (crc==0xBB3D) printf("passed.\n"); else printf("failed!\n");

  crc = CRC16_ARC(test2, 9);
  printf("jolyrojr check value: 0x%04X, test ", crc);
  if (crc==0x1885) printf("passed.\n"); else printf("failed!\n");

  crc = CRC16_ARC(test3, 8);
  printf("Manual   check value: 0x%04X, test ", crc);
  if (crc==0x7611) printf("passed.\n"); else printf("failed!\n");

  return 0;
}
Compiled with GNU C and executed
Code:
C:\TMP>gcc arc.c -o arc.exe
C:\TMP>arc.exe
Rocksoft check value: 0xBB3D, test passed.
jolyrojr check value: 0x1885, test passed.
Manual   check value: 0x1176, test passed.
Hope that helps,

Gammatester

       Computer Interfacing Forum Index -> Error detection and correction
Page 1 of 1



Running on php BB © 2001, 2009 php BB Group
   Lammert Bies     Interfacing     Sitemap     Forum