nasa / CFS_IO_LIB

19 stars 10 forks source link

TMTF_UpdateErrCtrlField strange CRC #5

Open hartib opened 5 years ago

hartib commented 5 years ago

I have checked the CRC implementation of the TM with several other implementations and the one in TMTF_UpdateErrCtrlField seems to disagree with the others. If I read CCSDS 132.0-B-2 and http://reveng.sourceforge.net/crc-catalogue/16.htm#crc.cat-bits.16 correctly the CRC is the CRC-16/IBM-3740 (also CRC-16/CCITT-FALSE). For the test sequence 123456789 this is supposed to produce 0x29b1. So does the algorithm in https://github.com/nasa/channel-emulator/blob/master/lib/TM_Transfer_Frame.cpp and the one in https://github.com/Stefan-Korner/SpacePyLibrary/blob/master/UTIL/CRC.py.

TMTF_UpdateErrCtrlField however produces 0xa69d which corresponds to none of the CRCs with poly 0x1021.

To produce the right result the code in the function should be something like:

                byte = (reg >> 8) & 0xff;
                reg = (reg << 8);
                reg ^= crc_table[byte ^ *ptr];
                ptr++;

So, which of the CRCs is right?

harti