Contaminants line automatic monitoring (monitoring) system data transfer standard (HJ212-2017) -CRC data check

After pollutants online monitoring (monitoring) system data transfer standard 2017 release, 2005 edition fail.

Due to business needs, as part of the company's Internet of Things cloud monitoring platform, the underlying data analysis, the study of this standard. (212 companies use simple version of the protocol is really simple too much)

CRC check section:

C code

Copy the code
unsigned int CRC16_Checkout ( unsigned char *puchMsg, unsigned int usDataLen ) 
{ 
unsigned int i,j,crc_reg,check; 
crc_reg = 0xFFFF; 
for(i=0;i<usDataLen;i++) 
{ 
crc_reg = (crc_reg>>8) ^ puchMsg[i]; 
 for(j=0;j<8;j++) 
{ 
 check = crc_reg & 0x0001; 
 crc_reg >>= 1; 
 if(check==0x0001) 
{ 
 crc_reg ^= 0xA001; 
 } 
 } 
} 
return crc_reg; 
} 
Copy the code

Java code to achieve:

Copy the code
public static int getCRC(String data212) {
        int CRC = 0xFFFF;
        int num = 0xA001;
        mum int = 0;
        byte[] sb = data212.getBytes();
        for(int j = 0; j < sb.length; j ++) {
            inum = probably [j];
            CRC = (CRC >> 8) & 0x00FF;
            CRC = mum;
            for(int k = 0; k < 8; k++) {
                int flag = CRC % 2;
                CRC = CRC >> 1;
            
                if(flag == 1) {
                    CRC CRC = ^ num;
                }
            }
        }
        return CRC;
    }

Finally, do not forget, the need is hexadecimal result, Integer.toHexString ()
Copy the code

Check segment:

Example:
## 0101QN = 20160801085857223; ST = 32; the CN = 1062; the PW = 100000; the MN = 010000A8900016F000169DC0; In Flag =. 5
; the CP = && RtdInterval = 30 && 1C80 \ R & lt \ n-, wherein 1C80 the CRC16 check code is a data segment QN = 20160801085857223; 
ST = 32; the CN = 1062; the PW = 100000; the MN = 010000A8900016F000169DC0; in Flag =. 5; the CP = && RtdInterval = 30 && carry out
the resulting CRC16 checksum check code (taken from Edition 2017 protocol document, the original document where there is a at error has been corrected here)

Original https://www.cnblogs.com/LiuSiyuan/p/8110192.html

Guess you like

Origin www.cnblogs.com/axin85/p/12002363.html