MAC

void HexStrToByte(const char *src, unsigned char *dest, int srcLen)

{

short i;

unsigned char highByte, lowByte;


for (i = 0; i < srcLen; i += 2)

{

highByte = toupper(src[i]);

lowByte  = toupper(src[i + 1]);


if (highByte > 0x39)

highByte -= 0x37;

else

highByte -= 0x30;


if (lowByte > 0x39)

lowByte -= 0x37;

else

lowByte -= 0x30;


dest[i / 2] = (highByte << 4) | lowByte;

}

return;

}




unsigned short calc_crc( unsigned char *ptr, int len)

{

  unsigned short crc1 = 0,da=0,bbb =0;


    while ( len-- != 0 )

    {

        da = ( crc1 >> 8 ) & 0x00ff;    //8??????????CRC??8?

        crc1 <<= 8;                            //?8?,???CRC??8???

        crc1 ^= ccitt_table[ ( da ^ ( *ptr ) )];        // ?8?????????????CRC ,??????CRC

        ptr++;

    }


    return crc1;


int YD_Crc16(char *source,int len,char *mac)

{

        char    dest[1000] = {0};

        int      nret = 0;


HexStrToByte(source, dest,  len);

nret =  calc_crc(dest,len/2);

sprintf(mac,"%04X",nret);

memcpy(&mac[4],"0000",4);

}


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。