#include <stdio.h> #include <string.h> unsigned short utils_crc16_modbus( unsigned char *buff,int len) { unsigned short tmp = 0xffff; unsigned short ret1 = 0; for(int n = 0; n < len; n++){ tmp = buff[n] ^ tmp; for(int i = 0;i < 8;i++){ if(tmp & 0x01){ tmp = tmp >> 1; tmp = tmp ^ 0xa001; } else{ tmp = tmp >> 1; } } } return tmp; }