package com.gzlh.device.led.client; import com.gzlh.bus.EventConfig; import com.gzlh.config.ModuleEnum; import com.gzlh.config.dto.SerialSetting; import com.gzlh.device.led.brand.LedBrandType; import com.gzlh.entity.DeviceStatus; import com.gzlh.utils.DeviceCache; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import lombok.extern.slf4j.Slf4j; import java.util.List; import java.util.stream.Collectors; @Slf4j @ChannelHandler.Sharable public class LedClientHandler extends SimpleChannelInboundHandler { private LedNettyConfig ledNettyConfig; public LedClientHandler(LedNettyConfig ledNettyConfig) { this.ledNettyConfig = ledNettyConfig; } @Override protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { log.info("LED 客户端收到消息:" + msg); DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleEn(),1); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { log.error("led 客户端 连接断开,进行重连"); DeviceCache.changeDeviceStatus(ModuleEnum.LED_MODULE.getModuleEn(),0); ledNettyConfig.connect(); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { cause.printStackTrace(); ctx.close(); } }