Új hozzászólás Aktív témák

  • zolizozo80

    tag

    válasz Szirty #3660 üzenetére

    Rendben! Szóval ezt a kódot kéne beleverni SCL-be...

    #include <stdio.h>

    int crc_tab16_init;
    unsigned short crc_tab16[256];

    void init_crc16_tab( void );
    unsigned short update_crc_16(unsigned short crc, char c );

    #define P_16 0xA001

    void init_crc16_tab( void )
    {

    int i, j;
    unsigned short crc, c;

    for (i=0; i<256; i++) {
    crc = 0;
    c = (unsigned short) i;
    for (j=0; j<8; j++) {
    if ( (crc ^ c) & 0x0001 ) crc = ( crc >> 1 ) ^ P_16;
    else crc = crc >> 1;
    c = c >> 1;
    }
    crc_tab16 = crc;
    }

    crc_tab16_init = 1;

    }
    unsigned short update_crc_16( unsigned short crc, char c )
    {

    unsigned short tmp, short_c;
    short_c = 0x00ff & (unsigned short) c;

    if ( ! crc_tab16_init ) init_crc16_tab();

    tmp = crc ^ short_c;
    crc = (crc >> 8) ^ crc_tab16[ tmp & 0xff ];

    return crc;

    }
    unsigned short getCRC16( unsigned char * s, int len )
    {

    unsigned short crc16=0xffff;
    int index;
    int x;
    int str_length;
    unsigned char temp;

    crc_tab16_init=0;

    for ( index=0;index<len;index++)
    {
    temp = s[index];
    crc16=update_crc_16(crc16,temp);

    }
    return ( (crc16 & 0xFF) * 256 ) + (crc16>>8);

    } /* getCRC16 */

Új hozzászólás Aktív témák