Commit 7e3a8a11 authored by 耿迪迪's avatar 耿迪迪

设备上报校验规则修改 gengdidi

parent d68f0ac9
......@@ -79,9 +79,9 @@ public class TCPServerHandler extends ChannelInboundHandlerAdapter {
String msgStr = HexUtils.bytesToHex(bytes1);
logger.info("receiveTCPMsgstr======="+msgStr);
byte[] bytes = HexUtils.hexToByteArray( msgStr.substring(0,msgStr.length()-4));
String checkVule = CrcUtil.getCrcToHex(bytes,true);
int checkVule = CrcUtil.getCrcToHex(bytes,true);
String checkCode = msgStr.substring(msgStr.length()-4,msgStr.length());
if(!checkVule.equals(checkCode)){
if(checkVule != Integer.parseInt(checkCode, 16)){
logger.error("接收数据校验失败");
throw new Exception("接收数据校验失败");
}
......
......@@ -44,9 +44,9 @@ public class UDPServerHandler extends SimpleChannelInboundHandler<DatagramPacket
String msgStr = HexUtils.bytesToHex(bytes1);
logger.info("receiveUPDMsgstr======="+msgStr);
byte[] bytes = HexUtils.hexToByteArray( msgStr.substring(0,msgStr.length()-4));
String checkVule = CrcUtil.getCrcToHex(bytes,true);
int checkVule = CrcUtil.getCrcToHex(bytes,true);
String checkCode = msgStr.substring(msgStr.length()-4,msgStr.length());
if(!checkVule.equals(checkCode)){
if(checkVule != Integer.parseInt(checkCode, 16)){
logger.error("接收数据校验失败");
throw new Exception("接收数据校验失败");
}
......
......@@ -39,29 +39,15 @@ public class CrcUtil {
* @param reverse 是否转换高低位
* @return
*/
public static String getCrcToHex(byte[] bytes,boolean reverse) {
public static int getCrcToHex(byte[] bytes,boolean reverse) {
int CRC = getCRC(bytes);
//高低位转换,看情况使用(譬如本人这次对led彩屏的通讯开发就规定校验码高位在前低位在后,也就不需要转换高低位)
if(reverse){
CRC = ( (CRC & 0x0000FF00) >> 8) | ( (CRC & 0x000000FF ) << 8);
}
return Integer.toHexString(CRC);
return CRC;
}
public static void main(String[] args) {
//字符串转16进制byte数组
String str16 = "0806040303030004040803070309010002032108271532404136cb5fdbd2b0004132f1e60000000042ef193b42d3cd6742012c5242edf73a0000000080a6";
/* byte[] bytes = HexUtils.hexToByteArray(str16);
// byte[] bytes = str16.getBytes();
System.out.println("str16:" + str16);
System.out.println(getCrcToHex(bytes,true));
System.out.println("str16:" + str16.substring(0,str16.length()-4));
System.out.println(str16.substring(str16.length()-4,str16.length()));*/
//System.out.println(HexUtils.hexToByte(str16.substring(0,36)));
System.out.println(Integer.parseInt(str16.substring(0,36),16));
}
}
......
......@@ -15,7 +15,7 @@ server:
spring:
profiles:
active: prd
active: test
#mybatis的相关配置
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment