|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TcpProperties tcpProperties; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 数据下行 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static void write(ChPackage chPackage) { | 
|---|
|  |  |  | String uuid = chPackage.getUuid(); | 
|---|
|  |  |  | Channel channel = ChannelCache.getChannel(uuid); | 
|---|
|  |  |  | if (null == channel) { | 
|---|
|  |  |  | log.warn("通道uuid={} 不在线", uuid); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | channel.writeAndFlush(chPackage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) { | 
|---|
|  |  |  | //        log.info("读码器【IP:{}】 上行数据 ===>> {}", pac.getIp(), pac.getAscii()); | 
|---|
|  |  |  | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 数据下行 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static void write(ChPackage chPackage){ | 
|---|
|  |  |  | String uuid = chPackage.getUuid(); | 
|---|
|  |  |  | Channel channel = ChannelCache.getChannel(uuid); | 
|---|
|  |  |  | if (null == channel){ | 
|---|
|  |  |  | log.warn("通道uuid={} 不在线", uuid); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | channel.writeAndFlush(chPackage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|