| | |
| | | package com.zy.core.netty.handle; |
| | | |
| | | import com.core.common.Cools; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.netty.AbstractInboundHandler; |
| | | import com.zy.core.netty.cache.ChannelCache; |
| | | import com.zy.core.netty.domain.ChPackage; |
| | | import com.zy.core.netty.properties.TcpProperties; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.BarcodeThread; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelHandler; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | |
| | | @ChannelHandler.Sharable |
| | | public class PackageServerHandler extends AbstractInboundHandler<ChPackage> { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private TcpProperties tcpProperties; |
| | | |
| | | @Override |
| | | protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) { |
| | | // 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; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | log.info("{}", pac.getBytes().length); |
| | | return true; |
| | | } |
| | | |