| | |
| | | String hexStr = ""; |
| | | InvokeResult message; |
| | | for (int i = 1; i <= cableX; i++) { |
| | | if (1 == i) start = 255; |
| | | start = i * cableY + 1; |
| | | if (1 == i) { |
| | | start = 255; |
| | | } else { |
| | | start = (i - 1) * cableY + 1; |
| | | } |
| | | |
| | | hexStr = this.buildGrainCmd(device, i, start, length); |
| | | |
| | | // 发送命令 |
| | | Channel channel = ClientEngine.getChannel(device.getIp()); |
| | | // 发送命令 TODO----->>>暂时调整为每次创建一个新连接 |
| | | //Channel channel = ClientEngine.getChannel(device.getIp()); |
| | | Channel channel = null; |
| | | if (null == channel) { |
| | | ClientEngine clientEngine = new ClientEngine(device.getIp(), device.getPort()); |
| | | clientEngine.start(); |
| | | Thread.sleep(500); |
| | | Thread.sleep(300); |
| | | channel = clientEngine.getChannel(); |
| | | } |
| | | message = ClientEngine.send2(hexStr, channel); |
| | | |
| | | log.error("平台------>>>>控制柜:发送粮情检测命令-{}", message); |
| | | log.error("平台------>>>>主控:发送粮情检测命令-{}---{}", message,hexStr); |
| | | |
| | | // 封装返回信息 |
| | | if (!InvokeResult.SUCCESS.getCode().equals(message.getCode())) { |
| | |
| | | return resp; |
| | | } |
| | | |
| | | @Override |
| | | public BaseResp syncGrainTh(BaseReqData reqData) { |
| | | return new BaseResp(); |
| | | } |
| | | |
| | | /** |
| | | * 生成粮情采集命令 |
| | | * |
| | |
| | | //开始封装消息体-主机ID |
| | | String deviceSn = device.getDeviceSn(); |
| | | deviceSn = BytesUtil.intToHexStr1(Integer.valueOf(deviceSn)); |
| | | content = content.replaceAll("\\{id}", deviceSn); |
| | | content = content.replace("{id}", deviceSn); |
| | | content = content.replace("{id}", deviceSn); |
| | | |
| | | //命令ID |
| | | String msgIdHex = BytesUtil.intToHexStr1(cur); |
| | | content = content.replace("\\{msgId}", msgIdHex); |
| | | content = content.replace("{msgId}", msgIdHex); |
| | | |
| | | //命令类型 |
| | | content = content.replace("\\{funId}", ServiceUtils.FUNCTION_66); |
| | | content = content.replace("{funId}", ServiceUtils.FUNCTION_66); |
| | | |
| | | //开始根号 |
| | | String startCurHex = BytesUtil.intToHexStr1(startCur); |
| | | content = content.replace("\\{start}", startCurHex); |
| | | content = content.replace("{start}", startCurHex); |
| | | |
| | | //截取长度 |
| | | String lenHex = BytesUtil.intToHexStr1(length); |
| | | content = content.replace("\\{length}", lenHex); |
| | | content = content.replace("{length}", lenHex); |
| | | |
| | | //校验码 |
| | | String crcCode = this.getCRC(content); |