| | |
| | | import com.ld.igds.io.response.GrainResponse; |
| | | import com.ld.igds.protocol.bhzn.grainv2.msg.builder.CommandBuild; |
| | | import com.ld.igds.protocol.bhzn.grainv2.server.BhznGrainV2ServerEngine; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | // request.setPort(mainSer.getPort()); |
| | | |
| | | // 发送命令 |
| | | InvokeResult result = bhznGrainServerEngine.pushByMin(hexStr); |
| | | InvokeResult result = bhznGrainServerEngine.push(request.getIp(),request.getPort(), BytesUtil.hexStrToBytes(hexStr)); |
| | | |
| | | log.error("平台------>>>>控制柜:粮情检测-{}", hexStr); |
| | | |
| | |
| | | private void replayGrain(IoMessage message) { |
| | | String hexStr = CommandBuild.getMsgGrainReply(message.getAddr()); |
| | | log.info("平台--------->>>主机,返回粮情报文收到信息,报文={}", hexStr); |
| | | serverEngine.pushByMin(hexStr); |
| | | serverEngine.push(message.getIp(),message.getPort(),BytesUtil.hexStrToBytes(hexStr)); |
| | | } |
| | | |
| | | private void analysisGrain2(DeviceSer ser, IoMessage message, ExeRequest exeRequest, DepotConf depotConf, DicSysConf sysConf, String batchId, String grainStr) { |
| | |
| | | } finally { |
| | | String hexStr = CommandBuild.getMsgTHReply(message.getAddr()); |
| | | log.info("平台--------->>>主机,返回仓温仓湿收到信息,报文={}", hexStr); |
| | | serverEngine.pushByMin(hexStr); |
| | | serverEngine.push(message.getIp(),message.getPort(),BytesUtil.hexStrToBytes(hexStr)); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | //直接根据主机SESSIOn判断 |
| | | IoSession session1 = BhznGrainV2ServerUtils.getSession(); |
| | | //IoSession session1 = BhznGrainV2ServerUtils.getSession(); |
| | | |
| | | Long lastBeatTime = BhznGrainV2ServerUtils.getHearBeat(session1); |
| | | Long lastBeatTime = BhznGrainV2ServerUtils.getHearBeat(session); |
| | | |
| | | if (null == lastBeatTime) { |
| | | return null; |
| | |
| | | BhznGrainV2ServerUtils.addHeartBeat(ioSession); |
| | | |
| | | //默认设置主通讯服务 |
| | | BhznGrainV2ServerUtils.addSession(ioSession); |
| | | //BhznGrainV2ServerUtils.addSession(ioSession); |
| | | |
| | | try { |
| | | String hexStr = BytesUtil.bytesToString(bytes); |
| | |
| | | // return session.invoke(msg); |
| | | // } |
| | | |
| | | /** |
| | | * 直接使用内存的Session执行 |
| | | */ |
| | | public InvokeResult pushByMin(String hexStr) { |
| | | |
| | | IoSession session = BhznGrainV2ServerUtils.getSession(); |
| | | |
| | | if (null == session) { |
| | | return InvokeResult.CHANNEL_CLOSED; |
| | | } |
| | | byte[] msg = BytesUtil.hexStrToBytes(hexStr); |
| | | return session.invoke(msg); |
| | | } |
| | | |
| | | } |
| | |
| | | return BytesUtil.intToHexStr(256 - check).substring(2); |
| | | } |
| | | |
| | | public static void addSession(IoSession session) { |
| | | contextIoSession.put(DEFAULT_MAC_ID, session); |
| | | } |
| | | |
| | | public static IoSession getSession() { |
| | | return contextIoSession.get(DEFAULT_MAC_ID); |
| | | } |
| | | // public static void addSession(IoSession session) { |
| | | // contextIoSession.put(DEFAULT_MAC_ID, session); |
| | | // } |
| | | // |
| | | // public static IoSession getSession() { |
| | | // return contextIoSession.get(DEFAULT_MAC_ID); |
| | | // } |
| | | } |
| | |
| | | @Override |
| | | public void onCreate(IoSession session) { |
| | | |
| | | //添加到内存 |
| | | BhznGrainV2ServerUtils.addSession(session); |
| | | // //添加到内存 |
| | | // BhznGrainV2ServerUtils.addSession(session); |
| | | |
| | | log.info("++++新建连接++++-IP={},PORT={}", session.getAddress(), session.getPort()); |
| | | |