| | |
| | | package com.zy.core.netty.handle; |
| | | |
| | | import com.zy.asrs.service.impl.MainServiceImpl; |
| | | import com.zy.core.netty.AbstractInboundHandler; |
| | | import com.zy.core.netty.cache.ChannelCache; |
| | | import com.zy.core.netty.constant.Constant; |
| | | import com.zy.core.netty.constant.FireDataType; |
| | | import com.zy.core.netty.domain.ChPackage; |
| | | import com.zy.core.netty.properties.TcpProperties; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.netty.domain.fire.Fire_3030; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelHandler; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | |
| | | public class PackageServerHandler extends AbstractInboundHandler<ChPackage> { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private TcpProperties tcpProperties; |
| | | private MainServiceImpl mainService; |
| | | |
| | | @Override |
| | | protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) { |
| | | byte[] bytes = pac.getBytes(); |
| | | System.out.println("客户端断开===>>" + new String(bytes, 0, bytes.length)); |
| | | FireDataType dataType = FireDataType.get(pac.getBytes()[1], pac.getBytes()[2]); |
| | | switch (dataType) { |
| | | case HEARTBEAT: |
| | | Fire_3030 fire3030 = new Fire_3030().readFromBytes(pac.getBytes()); |
| | | String now = "20" + fire3030.getYear() + "-" + fire3030.getMonth() + "-" + fire3030.getDay() |
| | | + " " + fire3030.getHour() + ":" + fire3030.getMinute() + ":" + fire3030.getSeconds(); |
| | | |
| | | // log.info("读码器【IP:{}】 上行数据 ===>> {}", pac.getIp(), pac.getAscii()); |
| | | // //扫码上传数据格式必须2个#开头,如:##12345678 |
| | | // String msg = pac.getAscii().replaceAll("#", ""); |
| | | // if(!Cools.isEmpty(msg) && msg.length()>=tcpProperties.getBarcodeLen()){ |
| | | // msg = msg.substring(0,tcpProperties.getBarcodeLen()); |
| | | // |
| | | // for (Slave slave : slaveProperties.getBarcode()) { |
| | | // if (slave.getIp().equals(pac.getIp())) { |
| | | // BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, slave.getId()); |
| | | // if (barcodeThread == null) { continue; } |
| | | // barcodeThread.setBarcode(msg); |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | ChannelCache.setChannel(String.valueOf(fire3030.getNo()), ctx.channel()); |
| | | Constant.errorMap.remove(fire3030.getNo()); |
| | | break; |
| | | case FIRE_ALARM: |
| | | |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return true; |
| | | } |
| | | |