Bonjour,
J’aimerais avoir la traduction en langage mathématique ou commun de l’algorithme calculant un CRC-16 afin de l’écrire sous Windev.Pour info, ce CRC permet de vérifier une trame entre un PC et un lecteur RFID. Le CRC-16 utilisé (codé sur 2 bytes) est une variante du standard CCITT-16 (Polynôme = 0x1021 / Valeur initiale = 0xFFFF).
Ci-dessous l’algorithme de calcul développé en C :
/** @fn void CRC_calcCrc8(u16 *crcReg, u16 poly, u16 u8Data)
* @brief Standard CRC calculation on an 8-bit piece of data. To make it
* CCITT-16, use poly=0x1021 and an initial crcReg=0xFFFF.
*
* Note: This function allows one to call it repeatedly to continue
* calculating a CRC. Thus, the first time it's called, it
* should have an initial crcReg of 0xFFFF, after which it
* can be called with its own result.
*
* @param *crcReg Pointer to current CRC register.
* @param poly Polynomial to apply.
* @param u8Data u8 data to perform CRC on.
* @return None.
*/
void CRC_calcCrc8(short *crcReg, short poly, short u8Data) {
short i;
short xorFlag;
short bit;
short dcdBitMask = 0x80;
for (i=0; i<8; i++) {
// Get the carry bit. This determines if the polynomial should be xor'd
// with the CRC register.
xorFlag = *crcReg & 0x8000;
// Shift the bits over by one.
*crcReg <<= 1;
// Shift in the next bit in the data byte
bit = ((u8Data & dcdBitMask) == dcdBitMask);
*crcReg |= bit;
// XOR the polynomial
if (xorFlag) {
*crcReg = *crcReg ^ poly;
}
// Shift over the dcd mask
dcdBitMask >>= 1;
}
}
MERCI+++ POUR VOTRE AIDE!
Configuration: Windows XP
Firefox 3.5.3