| | |
| | | package com.ld.igds.protocol.bhzn.inout; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ld.igds.inout.ApiInoutService; |
| | | import com.ld.igds.inout.InoutApiConstant; |
| | | import com.ld.igds.inout.InoutConstant; |
| | | import com.ld.igds.inout.dto.ApiInoutData; |
| | | import com.ld.igds.inout.dto.InoutData; |
| | | import com.ld.igds.io.constant.ProtocolEnum; |
| | | import com.ld.igds.protocol.bhzn.inout.client.BHZNClientEngine; |
| | | import com.ld.igds.protocol.bhzn.utils.CRC16; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Desc: 地磅主控协议实现,出入库相关接口 |
| | |
| | | @Override |
| | | public String gateControl(ApiInoutData param) { |
| | | try{ |
| | | // ReqGate reqGate = new ReqGate(); |
| | | log.info("BHZN出入库控制器控制道闸开始"); |
| | | String actionCode = param.getActionCode(); |
| | | BHZNClientEngine test = new BHZNClientEngine( |
| | | param.getIp(), param.getPort()); |
| | | test.start(); |
| | | String msg = "<BHZN>{\"cmd\":226,\"content\":{" + |
| | | "\"value\":[1,1]," + |
| | | "\"LEDValue\":[1,1]" + |
| | | "},\"orderId\":\"5009\",\"result\":\"\",\"sign\":\"0000\",\"stNum\":1,\"version\":\"V1.0000000\"}<END>"; |
| | | Integer[] value = new Integer[]{0,0}; |
| | | Map<String,Object> message = new HashMap<>(); |
| | | message.put("Cmd",226); |
| | | message.put("orderId","5009"); |
| | | message.put("result","0"); |
| | | message.put("sign","0000"); |
| | | message.put("stNum",100); |
| | | message.put("version","V1.0000000"); |
| | | message.put("sn","1000000001"); |
| | | Map<String,Object> content = new HashMap<>(); |
| | | // String msg = "<BHZN>{\"cmd\":226,\"content\":{" ; |
| | | if(InoutApiConstant.DEVICE_CODE_2002 == param.getDeviceCode()){ |
| | | content.put("value",new Integer[]{1,0}); |
| | | content.put("LEDValue",new Integer[]{1,0}); |
| | | // msg += "\"value\":[1,0]," ; |
| | | // msg+= "\"LEDValue\":[1,0]" ; |
| | | } |
| | | if(InoutApiConstant.DEVICE_CODE_2003 == param.getDeviceCode()){ |
| | | content.put("value",new Integer[]{0,1}); |
| | | content.put("LEDValue",new Integer[]{0,1}); |
| | | } |
| | | message.put("content", content); |
| | | // msg+= "},\"orderId\":\"5009\",\"result\":\"\",\"sign\":\"0000\",\"stNum\":100,\"version\":\"V1.0000000\"}<END>"; |
| | | |
| | | // Thread.sleep(3000L); |
| | | Thread.sleep(3000L); |
| | | String msg = "<BHZN>" + JSON.toJSONString(message) + "<END>" ; |
| | | InvokeResult result = test.send(msg.getBytes()); |
| | | log.info("BHZN出入库控制器控制道闸结束,MSG=" +msg); |
| | | log.info("result=" +result.getMessage()); |
| | | |
| | | test.send(BytesUtil.hexStrToBytes(msg)); |
| | | }catch (Exception e){ |
| | | log.error(e.getMessage(),e); |
| | | return "ERROR"; |
| | |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | try{ |
| | | String str1 = "许彬",str2="粤A123456",str3 = "3号仓" ,str4 = "小麦",str5="286000",str6 = "30000",str7 ="合格"; |
| | | String test = "我爱中航软件"; |
| | | //78340100290000000000000000 1400 0B00 01 02 00 01 0C 00 |
| | | // try{ |
| | | // String str1 = "许彬",str2="粤A123456",str3 = "3号仓" ,str4 = "小麦",str5="286000",str6 = "30000",str7 ="合格"; |
| | | // String test = "我爱中航软件"; |
| | | // //78340100290000000000000000 1400 0B00 01 02 00 01 0C 00 |
| | | // String start = "FFFFFFFFFF00000000"; |
| | | // String lengh = BytesUtil.tran_LH(BytesUtil.intToHexStr(8+(test.length() * 2))); |
| | | // String msg = "78340100290000000000000000" + lengh+ "0B00010201010C00"; |
| | | // msg = msg + convertStr(test); |
| | | // msg = msg.toUpperCase(); |
| | | // |
| | | //// String t = "78 34 01 00 29 BC FD 00 00 00 00 00 00 14 00 01 00 01 02 06 01 0C 00 CE D2 B0 AE D6 D0 BA BD C8 ED BC FE"; |
| | | //// t = t.replaceAll(" ",""); |
| | | // String check = BytesUtil.tran_LH(BytesUtil.intToHexStr(CRC16.calcCrc16(BytesUtil.hexStrToBytes(msg)))); |
| | | // System.out.println(check); |
| | | // |
| | | // msg+=check; |
| | | // msg += "A5"; |
| | | // msg = start +msg; |
| | | // System.out.println(msg); |
| | | // }catch (Exception e){ |
| | | // e.printStackTrace(); |
| | | // } |
| | | |
| | | String lengh = BytesUtil.tran_LH(BytesUtil.intToHexStr(8+test.length())); |
| | | String msg = "78340100290000000000000000 " + lengh+ "0B00010200010C00"; |
| | | msg = msg + convertStr(test); |
| | | msg = msg.toUpperCase(); |
| | | |
| | | // String t = "78 34 01 00 29 BC FD 00 00 00 00 00 00 14 00 01 00 01 02 06 01 0C 00 CE D2 B0 AE D6 D0 BA BD C8 ED BC FE"; |
| | | // t = t.replaceAll(" ",""); |
| | | String check = BytesUtil.tran_LH(BytesUtil.intToHexStr(CRC16.calcCrc16(BytesUtil.hexStrToBytes(msg)))); |
| | | System.out.println(check); |
| | | |
| | | msg+=check; |
| | | msg += "A5"; |
| | | |
| | | System.out.println(msg); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | Map<String,Object> message = new HashMap<>(); |
| | | message.put("cmd",226); |
| | | message.put("orderId","5009"); |
| | | message.put("result","0"); |
| | | message.put("sign","0000"); |
| | | message.put("stNum",100); |
| | | message.put("version","V1.0000000"); |
| | | Map<String,Object> content = new HashMap<>(); |
| | | content.put("value",new Integer[]{0,1}); |
| | | content.put("LEDValue",new Integer[]{0,1}); |
| | | message.put("content", content); |
| | | System.out.println(JSON.toJSONString(message)); |
| | | } |
| | | |
| | | |