正在显示
9 个修改的文件
包含
57 行增加
和
464 行删除
| @@ -5,10 +5,13 @@ import cn.hutool.core.util.ObjectUtil; | @@ -5,10 +5,13 @@ import cn.hutool.core.util.ObjectUtil; | ||
| 5 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | import com.google.gson.Gson; | 6 | import com.google.gson.Gson; |
| 7 | import com.google.gson.JsonObject; | 7 | import com.google.gson.JsonObject; |
| 8 | +import com.ruoyi.common.utils.ByteUtil; | ||
| 8 | import com.ruoyi.common.utils.GsonConstructor; | 9 | import com.ruoyi.common.utils.GsonConstructor; |
| 9 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 10 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; |
| 10 | import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | 11 | import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; |
| 11 | import com.zhonglai.luhui.smart.feeder.dto.*; | 12 | import com.zhonglai.luhui.smart.feeder.dto.*; |
| 13 | +import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommd03Request; | ||
| 14 | +import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto; | ||
| 12 | import com.zhonglai.luhui.smart.feeder.dto.commd.FeederTimer; | 15 | import com.zhonglai.luhui.smart.feeder.dto.commd.FeederTimer; |
| 13 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; | 16 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; |
| 14 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.Condata; | 17 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.Condata; |
| @@ -24,6 +27,8 @@ import java.util.ArrayList; | @@ -24,6 +27,8 @@ import java.util.ArrayList; | ||
| 24 | import java.util.List; | 27 | import java.util.List; |
| 25 | import java.util.Map; | 28 | import java.util.Map; |
| 26 | import java.util.concurrent.TimeUnit; | 29 | import java.util.concurrent.TimeUnit; |
| 30 | +import java.util.regex.Matcher; | ||
| 31 | +import java.util.regex.Pattern; | ||
| 27 | 32 | ||
| 28 | /** | 33 | /** |
| 29 | * 数据监听服务 | 34 | * 数据监听服务 |
| @@ -40,6 +45,17 @@ public class DateListenService { | @@ -40,6 +45,17 @@ public class DateListenService { | ||
| 40 | this.serialPortService = serialPortService; | 45 | this.serialPortService = serialPortService; |
| 41 | } | 46 | } |
| 42 | 47 | ||
| 48 | + | ||
| 49 | + public static void main(String[] args) { | ||
| 50 | + ConfigurationParameterService.initConfigurationParameter(); | ||
| 51 | + String str = "01032E00010004FFE0000000000001000000000000000000000000000000010001000600070000001500000000000000001EC4"; | ||
| 52 | + byte[] bytes = ByteUtil.hexStringToByte(str.replaceAll(" ","")); | ||
| 53 | + FeederCommdDto commdDto = new FeederCommdDto(bytes); | ||
| 54 | + AnalysisDataService analysisDataService = new AnalysisDataService(); | ||
| 55 | + Map<String,Object> data = analysisDataService.analysis(commdDto); | ||
| 56 | + | ||
| 57 | + System.out.println(data); | ||
| 58 | + } | ||
| 43 | public void run() | 59 | public void run() |
| 44 | { | 60 | { |
| 45 | logger.info("数据上报"); | 61 | logger.info("数据上报"); |
| @@ -47,6 +63,7 @@ public class DateListenService { | @@ -47,6 +63,7 @@ public class DateListenService { | ||
| 47 | ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { | 63 | ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { |
| 48 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.readAll()); | 64 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.readAll()); |
| 49 | Map<String,Object> data = analysisDataService.analysis(modbusDto); | 65 | Map<String,Object> data = analysisDataService.analysis(modbusDto); |
| 66 | + logger.info("查询投料机所有参数返回的数据:{}",data); | ||
| 50 | if(null != data && data.size() != 0) | 67 | if(null != data && data.size() != 0) |
| 51 | { | 68 | { |
| 52 | Condata condata = BeanUtil.mapToBean(data, Condata.class,false,null); | 69 | Condata condata = BeanUtil.mapToBean(data, Condata.class,false,null); |
| @@ -62,25 +79,6 @@ public class DateListenService { | @@ -62,25 +79,6 @@ public class DateListenService { | ||
| 62 | } | 79 | } |
| 63 | OperatingData.feederData.setInfo(info); | 80 | OperatingData.feederData.setInfo(info); |
| 64 | 81 | ||
| 65 | - //投料机不可以读 | ||
| 66 | -// List<Integer[]> timerList = new ArrayList<>(); | ||
| 67 | -// for(String key:data.keySet()) | ||
| 68 | -// { | ||
| 69 | -// if(key.startsWith("timer")) | ||
| 70 | -// { | ||
| 71 | -// FeederTimer feederTimer = (FeederTimer) data.get(key); | ||
| 72 | -// timerList.add(new Integer[]{feederTimer.getTimer_start_h(),feederTimer.getTimer_start_m(),feederTimer.getTimer_close_h(),feederTimer.getTimer_start_m(),feederTimer.getTimer_if_start()}); | ||
| 73 | -// } | ||
| 74 | -// } | ||
| 75 | -// | ||
| 76 | -// if(null != timerList && timerList.size() != 0) | ||
| 77 | -// { | ||
| 78 | -// if(ObjectUtil.notEqual(OperatingData.feederConfig.getTimer(),timerList)) | ||
| 79 | -// { | ||
| 80 | -// OperatingData.feederConfig.setTimer(timerList); | ||
| 81 | -// reportTimer(); | ||
| 82 | -// } | ||
| 83 | -// } | ||
| 84 | } | 82 | } |
| 85 | },1,10, TimeUnit.SECONDS); | 83 | },1,10, TimeUnit.SECONDS); |
| 86 | 84 | ||
| @@ -115,6 +113,7 @@ public class DateListenService { | @@ -115,6 +113,7 @@ public class DateListenService { | ||
| 115 | 113 | ||
| 116 | //上报参数 | 114 | //上报参数 |
| 117 | ScheduledConfig.scheduler.schedule(() -> { | 115 | ScheduledConfig.scheduler.schedule(() -> { |
| 116 | + logger.info("内存数据--->{}",OperatingData.feederConfig.getCondata()); | ||
| 118 | try { | 117 | try { |
| 119 | Thread.sleep(10000); | 118 | Thread.sleep(10000); |
| 120 | reportSerialPortConfig(); | 119 | reportSerialPortConfig(); |
| @@ -161,27 +160,9 @@ public class DateListenService { | @@ -161,27 +160,9 @@ public class DateListenService { | ||
| 161 | devicedatRequest.setBattlevel(4); | 160 | devicedatRequest.setBattlevel(4); |
| 162 | devicedatRequest.setCondata(OperatingData.feederConfig.getCondata()); | 161 | devicedatRequest.setCondata(OperatingData.feederConfig.getCondata()); |
| 163 | String str = GsonConstructor.get().toJson(devicedatRequest); | 162 | String str = GsonConstructor.get().toJson(devicedatRequest); |
| 164 | - System.out.println(str); | ||
| 165 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | 163 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); |
| 166 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | 164 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); |
| 167 | } | 165 | } |
| 168 | -// /** | ||
| 169 | -// * 上报投料机定时参数 | ||
| 170 | -// */ | ||
| 171 | -// public void reportTimer() | ||
| 172 | -// { | ||
| 173 | -// DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 174 | -// devicedatRequest.setCmd("devicedata"); | ||
| 175 | -// devicedatRequest.setType("4G.hs"); | ||
| 176 | -// devicedatRequest.setSignal(4); | ||
| 177 | -// devicedatRequest.setMachstate(1); | ||
| 178 | -// devicedatRequest.setBattlevel(4); | ||
| 179 | -// devicedatRequest.setTimer(OperatingData.feederConfig.getTimer()); | ||
| 180 | -// String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 181 | -// System.out.println(str); | ||
| 182 | -// CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 183 | -// MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 184 | -// } | ||
| 185 | 166 | ||
| 186 | /** | 167 | /** |
| 187 | * 上报串口参数 | 168 | * 上报串口参数 |
| @@ -196,7 +177,6 @@ public class DateListenService { | @@ -196,7 +177,6 @@ public class DateListenService { | ||
| 196 | devicedatRequest.setBattlevel(4); | 177 | devicedatRequest.setBattlevel(4); |
| 197 | devicedatRequest.setSerialPortConfig(OperatingData.feederConfig.getSerialPortConfig()); | 178 | devicedatRequest.setSerialPortConfig(OperatingData.feederConfig.getSerialPortConfig()); |
| 198 | String str = GsonConstructor.get().toJson(devicedatRequest); | 179 | String str = GsonConstructor.get().toJson(devicedatRequest); |
| 199 | - System.out.println(str); | ||
| 200 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | 180 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); |
| 201 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | 181 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); |
| 202 | } | 182 | } |
| @@ -214,7 +194,6 @@ public class DateListenService { | @@ -214,7 +194,6 @@ public class DateListenService { | ||
| 214 | devicedatRequest.setBattlevel(4); | 194 | devicedatRequest.setBattlevel(4); |
| 215 | devicedatRequest.setSysConfig(OperatingData.sysConfig); | 195 | devicedatRequest.setSysConfig(OperatingData.sysConfig); |
| 216 | String str = GsonConstructor.get().toJson(devicedatRequest); | 196 | String str = GsonConstructor.get().toJson(devicedatRequest); |
| 217 | - System.out.println(str); | ||
| 218 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | 197 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); |
| 219 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | 198 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); |
| 220 | } | 199 | } |
| @@ -233,7 +212,6 @@ public class DateListenService { | @@ -233,7 +212,6 @@ public class DateListenService { | ||
| 233 | devicedatRequest.setBattlevel(4); | 212 | devicedatRequest.setBattlevel(4); |
| 234 | devicedatRequest.setCameraConfig(OperatingData.cameraConfig); | 213 | devicedatRequest.setCameraConfig(OperatingData.cameraConfig); |
| 235 | String str = GsonConstructor.get().toJson(devicedatRequest); | 214 | String str = GsonConstructor.get().toJson(devicedatRequest); |
| 236 | - System.out.println(str); | ||
| 237 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | 215 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); |
| 238 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | 216 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); |
| 239 | 217 | ||
| @@ -260,25 +238,4 @@ public class DateListenService { | @@ -260,25 +238,4 @@ public class DateListenService { | ||
| 260 | } | 238 | } |
| 261 | } | 239 | } |
| 262 | 240 | ||
| 263 | - public static void main(String[] args) { | ||
| 264 | - ConfigurationParameterService.initConfigurationParameter(); | ||
| 265 | - DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 266 | - devicedatRequest.setCmd("devicedata"); | ||
| 267 | - devicedatRequest.setType("4G.hs"); | ||
| 268 | - devicedatRequest.setSignal(4); | ||
| 269 | - devicedatRequest.setMachstate(1); | ||
| 270 | - devicedatRequest.setBattlevel(4); | ||
| 271 | - | ||
| 272 | - devicedatRequest.setCondata(OperatingData.feederConfig.getCondata()); | ||
| 273 | - devicedatRequest.setInfo(OperatingData.feederData.getInfo()); | ||
| 274 | -// devicedatRequest.setTimer(OperatingData.feederConfig.getTimer()); | ||
| 275 | - | ||
| 276 | - devicedatRequest.setSysConfig(OperatingData.sysConfig); | ||
| 277 | - devicedatRequest.setCameraData(OperatingData.cameraData); | ||
| 278 | - devicedatRequest.setCameraConfig(OperatingData.cameraConfig); | ||
| 279 | - devicedatRequest.setSerialPortConfig(OperatingData.feederConfig.getSerialPortConfig()); | ||
| 280 | - | ||
| 281 | - System.out.println(GsonConstructor.get().toJson(devicedatRequest)); | ||
| 282 | - } | ||
| 283 | - | ||
| 284 | } | 241 | } |
| @@ -5,13 +5,12 @@ import com.zhonglai.luhui.smart.feeder.config.OperatingData; | @@ -5,13 +5,12 @@ import com.zhonglai.luhui.smart.feeder.config.OperatingData; | ||
| 5 | import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | 5 | import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; |
| 6 | import com.zhonglai.luhui.smart.feeder.dto.*; | 6 | import com.zhonglai.luhui.smart.feeder.dto.*; |
| 7 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.Condata; | 7 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.Condata; |
| 8 | -import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService; | ||
| 9 | import com.zhonglai.luhui.smart.feeder.util.FeederCommd06ResponseType; | 8 | import com.zhonglai.luhui.smart.feeder.util.FeederCommd06ResponseType; |
| 10 | import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; | 9 | import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; |
| 10 | +import com.zhonglai.luhui.smart.spare.feeder.service.SerialPortService; | ||
| 11 | import org.slf4j.Logger; | 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; | 12 | import org.slf4j.LoggerFactory; |
| 13 | 13 | ||
| 14 | -import java.util.*; | ||
| 15 | import java.util.concurrent.TimeUnit; | 14 | import java.util.concurrent.TimeUnit; |
| 16 | 15 | ||
| 17 | /** | 16 | /** |
| 1 | package com.zhonglai.luhui.smart.feeder.service; | 1 | package com.zhonglai.luhui.smart.feeder.service; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import com.google.gson.JsonObject; | ||
| 5 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 4 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 6 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; |
| 7 | +import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; | ||
| 8 | +import com.zhonglai.luhui.smart.feeder.dto.mqtt.DevicedatRequest; | ||
| 5 | import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle; | 9 | import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle; |
| 6 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; | 10 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; |
| 11 | +import com.zhonglai.luhui.smart.feeder.util.MessageUtil; | ||
| 7 | import com.zhonglai.luhui.smart.spare.feeder.service.NettyClient; | 12 | import com.zhonglai.luhui.smart.spare.feeder.service.NettyClient; |
| 8 | import com.zhonglai.luhui.smart.spare.feeder.service.SerialPortService; | 13 | import com.zhonglai.luhui.smart.spare.feeder.service.SerialPortService; |
| 9 | 14 | ||
| 10 | -import java.io.BufferedReader; | ||
| 11 | -import java.io.InputStreamReader; | ||
| 12 | - | ||
| 13 | public class InitService { | 15 | public class InitService { |
| 14 | public static SerialPortService serialPortService; | 16 | public static SerialPortService serialPortService; |
| 15 | 17 | ||
| @@ -49,6 +51,8 @@ public class InitService { | @@ -49,6 +51,8 @@ public class InitService { | ||
| 49 | nettyClient = new NettyClient(OperatingData.sysConfig.getNettyConfig().getHost(), OperatingData.sysConfig.getNettyConfig().getPort()); | 51 | nettyClient = new NettyClient(OperatingData.sysConfig.getNettyConfig().getHost(), OperatingData.sysConfig.getNettyConfig().getPort()); |
| 50 | nettyClient.start(); | 52 | nettyClient.start(); |
| 51 | 53 | ||
| 54 | + jiaozhun(); | ||
| 55 | + | ||
| 52 | /** | 56 | /** |
| 53 | * 初始化海康的摄像头 | 57 | * 初始化海康的摄像头 |
| 54 | */ | 58 | */ |
| @@ -73,4 +77,21 @@ public class InitService { | @@ -73,4 +77,21 @@ public class InitService { | ||
| 73 | mqttService.start(); | 77 | mqttService.start(); |
| 74 | 78 | ||
| 75 | } | 79 | } |
| 80 | + | ||
| 81 | + private static void jiaozhun() | ||
| 82 | + { | ||
| 83 | + DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 84 | + devicedatRequest.setCmd("get_config"); | ||
| 85 | + devicedatRequest.setType("4G.hs"); | ||
| 86 | + devicedatRequest.setSignal(4); | ||
| 87 | + devicedatRequest.setMachstate(1); | ||
| 88 | + devicedatRequest.setBattlevel(4); | ||
| 89 | + String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 90 | + | ||
| 91 | + JsonObject jsonObject = GsonConstructor.get().fromJson( str, JsonObject.class); | ||
| 92 | + jsonObject.addProperty("configType","timer"); | ||
| 93 | + CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject(jsonObject); | ||
| 94 | + System.out.println("发送较准指令:"+cmdDto.generateCmd()); | ||
| 95 | + MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 96 | + } | ||
| 76 | } | 97 | } |
| 1 | -package com.zhonglai.luhui.smart.feeder.service.device; | ||
| 2 | - | ||
| 3 | - | ||
| 4 | -import cn.hutool.core.bean.BeanUtil; | ||
| 5 | -import cn.hutool.core.util.ObjectUtil; | ||
| 6 | -import com.fazecast.jSerialComm.SerialPort; | ||
| 7 | -import com.fazecast.jSerialComm.SerialPortDataListener; | ||
| 8 | -import com.fazecast.jSerialComm.SerialPortEvent; | ||
| 9 | -import com.ruoyi.common.utils.ByteUtil; | ||
| 10 | -import com.zhonglai.luhui.smart.feeder.config.OperatingData; | ||
| 11 | -import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | ||
| 12 | -import com.zhonglai.luhui.smart.feeder.dto.ModbusDto; | ||
| 13 | -import com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig; | ||
| 14 | -import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto; | ||
| 15 | -import com.zhonglai.luhui.smart.feeder.dto.mqtt.Condata; | ||
| 16 | -import com.zhonglai.luhui.smart.feeder.dto.mqtt.Info; | ||
| 17 | -import com.zhonglai.luhui.smart.feeder.service.AnalysisDataService; | ||
| 18 | -import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | ||
| 19 | -import com.zhonglai.luhui.smart.feeder.service.InitService; | ||
| 20 | -import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; | ||
| 21 | -import org.slf4j.Logger; | ||
| 22 | -import org.slf4j.LoggerFactory; | ||
| 23 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 24 | -import org.springframework.stereotype.Service; | ||
| 25 | - | ||
| 26 | -import java.io.IOException; | ||
| 27 | -import java.io.InputStream; | ||
| 28 | -import java.nio.charset.StandardCharsets; | ||
| 29 | -import java.util.Map; | ||
| 30 | -import java.util.concurrent.BlockingQueue; | ||
| 31 | -import java.util.concurrent.LinkedBlockingQueue; | ||
| 32 | -import java.util.concurrent.TimeUnit; | ||
| 33 | - | ||
| 34 | -public class SerialPortService { | ||
| 35 | - private static final Logger logger = LoggerFactory.getLogger(SerialPortService.class); | ||
| 36 | - private SerialPort serialPort; | ||
| 37 | - | ||
| 38 | - // 锁对象 | ||
| 39 | - private final Object lock = new Object(); | ||
| 40 | - // 用于存储串口返回的数据,使用线程安全的队列 | ||
| 41 | - private BlockingQueue<ModbusDto> dataQueue = new LinkedBlockingQueue<>(); | ||
| 42 | - | ||
| 43 | - private AnalysisDataService analysisDataService = new AnalysisDataService(); | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - public SerialPortService() | ||
| 47 | - { | ||
| 48 | - open(); | ||
| 49 | - ModbusDto modbusDto = sendHexData(FeederCommdUtil.readAll()); | ||
| 50 | - Map<String,Object> data = analysisDataService.analysis(modbusDto); | ||
| 51 | - if(null != data && data.size() != 0) | ||
| 52 | - { | ||
| 53 | - Condata condata = BeanUtil.mapToBean(data, Condata.class,false,null); | ||
| 54 | - if(condata.getRunstate()==0) | ||
| 55 | - { | ||
| 56 | - condata.setRunstate(3); | ||
| 57 | - } | ||
| 58 | - Info info = BeanUtil.mapToBean(data, Info.class,false,null); | ||
| 59 | - if(ObjectUtil.notEqual(OperatingData.feederConfig.getCondata(),condata)) | ||
| 60 | - { | ||
| 61 | - OperatingData.feederConfig.setCondata(condata); | ||
| 62 | - } | ||
| 63 | - OperatingData.feederData.setInfo(info); | ||
| 64 | - } | ||
| 65 | - logger.info("端口启动情况:{}",serialPort.isOpen()); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - private SerialPort findSerialPort() | ||
| 69 | - { | ||
| 70 | - SerialPort serialPort = null; | ||
| 71 | - SerialPort[] serialPorts = SerialPort.getCommPorts();//查找所有串口 | ||
| 72 | - | ||
| 73 | - for(SerialPort port:serialPorts){ | ||
| 74 | - logger.info("Port:{},PortDesc:{},PortDesc:{}",port.getSystemPortName(),port.getPortDescription(),port.getDescriptivePortName());//打印串口名称,如COM4;打印串口类型,如USB Serial;打印串口的完整类型,如USB-SERIAL CH340(COM4) | ||
| 75 | - if(port.getSystemPortName().indexOf("ttyS0")>=0) | ||
| 76 | - { | ||
| 77 | - serialPort = port; | ||
| 78 | - break; | ||
| 79 | - } | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - return serialPort; | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - private void setComPortParameters() | ||
| 86 | - { | ||
| 87 | - | ||
| 88 | - SerialPortConfig serialPortConfig = OperatingData.feederConfig.getSerialPortConfig(); | ||
| 89 | - | ||
| 90 | - serialPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING | SerialPort.TIMEOUT_WRITE_BLOCKING, 1000, 1000);//设置超时 | ||
| 91 | - serialPort.setFlowControl(SerialPort.FLOW_CONTROL_DISABLED);//设置串口的控制流,可以设置为disabled,或者CTS, RTS/CTS, DSR, DTR/DSR, Xon, Xoff, Xon/Xoff等 | ||
| 92 | - serialPort.setComPortParameters(serialPortConfig.getBaudrate(), serialPortConfig.getDataBits(), serialPortConfig.getStopBits(), serialPortConfig.getParity());//一次性设置所有的串口参数,第一个参数为波特率,默认9600;第二个参数为每一位的大小,默认8,可以输入5到8之间的值;第三个参数为停止位大小,只接受内置常量,可以选择(ONE_STOP_BIT, ONE_POINT_FIVE_STOP_BITS, TWO_STOP_BITS);第四位为校验位,同样只接受内置常量,可以选择 NO_PARITY, EVEN_PARITY, ODD_PARITY, MARK_PARITY,SPACE_PARITY。 | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - public boolean isOpen() | ||
| 96 | - { | ||
| 97 | - if(null != serialPort && serialPort.isOpen()) | ||
| 98 | - { | ||
| 99 | - return true; | ||
| 100 | - } | ||
| 101 | - return false; | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - public boolean open() | ||
| 105 | - { | ||
| 106 | - if(null == serialPort || !serialPort.isOpen()) | ||
| 107 | - { | ||
| 108 | - serialPort = findSerialPort(); | ||
| 109 | - if(null != serialPort) | ||
| 110 | - { | ||
| 111 | - setComPortParameters(); | ||
| 112 | - } | ||
| 113 | - } | ||
| 114 | - if(null == serialPort) | ||
| 115 | - { | ||
| 116 | - logger.error("没有找到串口"); | ||
| 117 | - return false; | ||
| 118 | - } | ||
| 119 | - if(!serialPort.isOpen()){ | ||
| 120 | - boolean isCommOpeded = serialPort.openPort();//判断串口是否打开,如果没打开,就打开串口。打开串口的函数会返回一个boolean值,用于表明串口是否成功打开了 | ||
| 121 | - addLister(); | ||
| 122 | - return isCommOpeded; | ||
| 123 | - } | ||
| 124 | - return true; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - private void addLister() | ||
| 128 | - { | ||
| 129 | - if(serialPort.isOpen()){ | ||
| 130 | - serialPort.addDataListener(new SerialPortDataListener() {//添加监听器。由于该监听器有两个函数,无法使用Lambda表达式 | ||
| 131 | - | ||
| 132 | - @Override | ||
| 133 | - public int getListeningEvents() { | ||
| 134 | - // TODO Auto-generated method stub | ||
| 135 | - return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;//返回要监听的事件类型,以供回调函数使用。可发回的事件包括:SerialPort.LISTENING_EVENT_DATA_AVAILABLE,SerialPort.LISTENING_EVENT_DATA_WRITTEN,SerialPort.LISTENING_EVENT_DATA_RECEIVED。分别对应有数据在串口(不论是读的还是写的),有数据写入串口,从串口读取数据。如果AVAILABLE和RECEIVED同时被监听,优先触发RECEIVED | ||
| 136 | - } | ||
| 137 | - | ||
| 138 | - @Override | ||
| 139 | - public void serialEvent(SerialPortEvent event) {//事件处理函数 | ||
| 140 | - // TODO Auto-generated method stub | ||
| 141 | - String data = ""; | ||
| 142 | - if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE){ | ||
| 143 | - return;//判断事件的类型 | ||
| 144 | - } | ||
| 145 | - SerialPort port = event.getSerialPort(); | ||
| 146 | - | ||
| 147 | - try { | ||
| 148 | - Thread.sleep(500); | ||
| 149 | - byte[] bytes = readFromPort(port); | ||
| 150 | - logger.info("串口返回数据:"+ByteUtil.toHexString(bytes)); | ||
| 151 | - FeederCommdDto commdDto = new FeederCommdDto(bytes); | ||
| 152 | - dataQueue.offer(commdDto); // 将数据添加到队列中// 处理串口返回的数据 | ||
| 153 | - } catch (Exception e) { | ||
| 154 | - logger.error("返回数据处理异常",e); | ||
| 155 | - } | ||
| 156 | - } | ||
| 157 | - | ||
| 158 | - }); | ||
| 159 | - } | ||
| 160 | - | ||
| 161 | - } | ||
| 162 | - public boolean close() | ||
| 163 | - { | ||
| 164 | - dataQueue.clear(); | ||
| 165 | - if(null != serialPort) | ||
| 166 | - { | ||
| 167 | - return serialPort.closePort();//关闭串口。该函数同样会返回一个boolean值,表明串口是否成功关闭 | ||
| 168 | - } | ||
| 169 | - return true; | ||
| 170 | - } | ||
| 171 | - | ||
| 172 | - | ||
| 173 | - /** | ||
| 174 | - * 发送16进制数据 | ||
| 175 | - * @param hexStr | ||
| 176 | - * @throws IOException | ||
| 177 | - */ | ||
| 178 | - public ModbusDto sendHexData(String hexStr) { | ||
| 179 | - logger.info("串口写入:{}",hexStr); | ||
| 180 | - byte[] bytes = ByteUtil.hexStringToByte(hexStr.replace(" ","").trim().toUpperCase()); | ||
| 181 | - return sendByte(bytes); | ||
| 182 | - } | ||
| 183 | - | ||
| 184 | -// /** | ||
| 185 | -// * 发送支持中文的字符串 | ||
| 186 | -// * @param str | ||
| 187 | -// * @throws IOException | ||
| 188 | -// */ | ||
| 189 | -// public ModbusDto sendStrData(String str) { | ||
| 190 | -// return sendByte(str.getBytes(StandardCharsets.UTF_8)); | ||
| 191 | -// } | ||
| 192 | - | ||
| 193 | - /** | ||
| 194 | - * 发送byte数组 | ||
| 195 | - * @param bytes | ||
| 196 | - * @return | ||
| 197 | - */ | ||
| 198 | - public ModbusDto sendByte(byte[] bytes) | ||
| 199 | - { | ||
| 200 | - synchronized (lock) | ||
| 201 | - { | ||
| 202 | - if(open()) | ||
| 203 | - { | ||
| 204 | - serialPort.writeBytes(bytes,bytes.length); | ||
| 205 | - try { | ||
| 206 | - ModbusDto reStr = dataQueue.poll(15, TimeUnit.SECONDS); | ||
| 207 | - return reStr; | ||
| 208 | - } catch (InterruptedException e) { | ||
| 209 | - logger.error("等待串口返回数据异常!" + e); | ||
| 210 | - } | ||
| 211 | - }else{ | ||
| 212 | - logger.error("串口未打开!" ); | ||
| 213 | - return null; | ||
| 214 | - } | ||
| 215 | - | ||
| 216 | - } | ||
| 217 | - return null; | ||
| 218 | - } | ||
| 219 | - | ||
| 220 | - private static byte[] readFromPort(SerialPort serialPort) throws Exception { | ||
| 221 | - | ||
| 222 | - InputStream in = null; | ||
| 223 | - byte[] bytes = null; | ||
| 224 | - | ||
| 225 | - try { | ||
| 226 | - if (serialPort != null) { | ||
| 227 | - in = serialPort.getInputStream(); | ||
| 228 | - } else { | ||
| 229 | - return null; | ||
| 230 | - } | ||
| 231 | - int bufflenth = in.available(); // 获取buffer里的数据长度 | ||
| 232 | - while (bufflenth > 0) { | ||
| 233 | - bytes = new byte[bufflenth]; // 初始化byte数组为buffer中数据的长度 | ||
| 234 | - in.read(bytes); | ||
| 235 | - bufflenth = in.available(); | ||
| 236 | - } | ||
| 237 | - } catch (Exception e) { | ||
| 238 | - throw e; | ||
| 239 | - } finally { | ||
| 240 | - try { | ||
| 241 | - if (in != null) { | ||
| 242 | - in.close(); | ||
| 243 | - } | ||
| 244 | - } catch (IOException e) { | ||
| 245 | - throw e; | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - } | ||
| 249 | - | ||
| 250 | - return bytes; | ||
| 251 | - | ||
| 252 | - } | ||
| 253 | - | ||
| 254 | -} |
| @@ -146,6 +146,7 @@ public class CameraRtspHandle implements CameraHandle { | @@ -146,6 +146,7 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | String rtspUrl = "rtsp://admin:"+OperatingData.sysConfig.getPassword()+"@"+ip+":554/h264/ch1/main/av_stream"; | 148 | String rtspUrl = "rtsp://admin:"+OperatingData.sysConfig.getPassword()+"@"+ip+":554/h264/ch1/main/av_stream"; |
| 149 | +// FFmpegLogCallback.set(); | ||
| 149 | grabber = new FFmpegFrameGrabber(rtspUrl); | 150 | grabber = new FFmpegFrameGrabber(rtspUrl); |
| 150 | // grabber.setOption("framerate", "30"); // 设置帧率为30帧/秒 | 151 | // grabber.setOption("framerate", "30"); // 设置帧率为30帧/秒 |
| 151 | // grabber.setOption("skip_frame", "nokey"); // 只抓取关键帧 | 152 | // grabber.setOption("skip_frame", "nokey"); // 只抓取关键帧 |
| @@ -155,7 +156,9 @@ public class CameraRtspHandle implements CameraHandle { | @@ -155,7 +156,9 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 155 | // grabber.setOption("buffer_size", "4096"); // 设置缓冲区大小为1024字节 | 156 | // grabber.setOption("buffer_size", "4096"); // 设置缓冲区大小为1024字节 |
| 156 | grabber.setVideoOption("rtsp_transport", "tcp"); | 157 | grabber.setVideoOption("rtsp_transport", "tcp"); |
| 157 | grabber.setOption("stimeout", "2000000"); | 158 | grabber.setOption("stimeout", "2000000"); |
| 158 | - avutil.av_log_set_level(avutil.AV_LOG_ERROR); | 159 | +// avutil.av_log_set_level(avutil.AV_LOG_ERROR); |
| 160 | + | ||
| 161 | + grabber.setAudioChannels(0); | ||
| 159 | grabber.start(); | 162 | grabber.start(); |
| 160 | while (!grabber.hasAudio() || !grabber.hasVideo()) | 163 | while (!grabber.hasAudio() || !grabber.hasVideo()) |
| 161 | { | 164 | { |
| @@ -49,7 +49,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | @@ -49,7 +49,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | ||
| 49 | @Override | 49 | @Override |
| 50 | protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception { | 50 | protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception { |
| 51 | try { | 51 | try { |
| 52 | - logger.info("读取到数据:{}",msg); | 52 | + logger.info("收到服务器数据:{}",msg); |
| 53 | if(StringUtils.isNotBlank(msg) && checkAgreement(msg)) | 53 | if(StringUtils.isNotBlank(msg) && checkAgreement(msg)) |
| 54 | { | 54 | { |
| 55 | CmdDto cmdDto = new CmdDto(msg); | 55 | CmdDto cmdDto = new CmdDto(msg); |
| @@ -45,7 +45,9 @@ public class CfgdataService { | @@ -45,7 +45,9 @@ public class CfgdataService { | ||
| 45 | try { | 45 | try { |
| 46 | CfgdataRequest cfgdataRequest = GsonConstructor.get().fromJson(data.toString(), CfgdataRequest.class); | 46 | CfgdataRequest cfgdataRequest = GsonConstructor.get().fromJson(data.toString(), CfgdataRequest.class); |
| 47 | Condata condata = cfgdataRequest.getCondata(); | 47 | Condata condata = cfgdataRequest.getCondata(); |
| 48 | - if(OperatingData.feederConfig.getCondata().getRunmode()==1) | 48 | + if (null != condata) |
| 49 | + { | ||
| 50 | + if(OperatingData.feederConfig.getCondata().getRunmode()==1 && condata.getRunmode()==0) | ||
| 49 | { | 51 | { |
| 50 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,0); | 52 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,0); |
| 51 | logger.info("自动模式切换成手动模式"); | 53 | logger.info("自动模式切换成手动模式"); |
| @@ -57,7 +59,6 @@ public class CfgdataService { | @@ -57,7 +59,6 @@ public class CfgdataService { | ||
| 57 | OperatingData.setClassObjecValue(feederConfig, (fieldname, fieldObject) -> { | 59 | OperatingData.setClassObjecValue(feederConfig, (fieldname, fieldObject) -> { |
| 58 | try { | 60 | try { |
| 59 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); | 61 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); |
| 60 | - logger.info("远程发送指令{}",commd); | ||
| 61 | InitService.serialPortService.sendHexData(commd); //通知串口 | 62 | InitService.serialPortService.sendHexData(commd); //通知串口 |
| 62 | }catch (Exception e) | 63 | }catch (Exception e) |
| 63 | { | 64 | { |
| @@ -66,6 +67,7 @@ public class CfgdataService { | @@ -66,6 +67,7 @@ public class CfgdataService { | ||
| 66 | throw new RuntimeException(e); | 67 | throw new RuntimeException(e); |
| 67 | } | 68 | } |
| 68 | }); | 69 | }); |
| 70 | + } | ||
| 69 | 71 | ||
| 70 | List<Integer[]> timerList = cfgdataRequest.getTimer(); | 72 | List<Integer[]> timerList = cfgdataRequest.getTimer(); |
| 71 | if(null != timerList) | 73 | if(null != timerList) |
| 1 | -package com.zhonglai.luhui.smart.feeder.service.netty; | ||
| 2 | - | ||
| 3 | -import com.zhonglai.luhui.smart.feeder.config.OperatingData; | ||
| 4 | -import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | ||
| 5 | -import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | ||
| 6 | -import com.zhonglai.luhui.smart.feeder.service.InitService; | ||
| 7 | -import com.zhonglai.luhui.smart.feeder.service.feeder.AgreementHandler; | ||
| 8 | -import io.netty.bootstrap.Bootstrap; | ||
| 9 | -import io.netty.channel.*; | ||
| 10 | -import io.netty.channel.nio.NioEventLoopGroup; | ||
| 11 | -import io.netty.channel.socket.nio.NioSocketChannel; | ||
| 12 | -import io.netty.handler.codec.string.StringDecoder; | ||
| 13 | -import io.netty.handler.codec.string.StringEncoder; | ||
| 14 | -import org.slf4j.Logger; | ||
| 15 | -import org.slf4j.LoggerFactory; | ||
| 16 | - | ||
| 17 | -import java.nio.charset.Charset; | ||
| 18 | -import java.util.concurrent.TimeUnit; | ||
| 19 | - | ||
| 20 | -public class NettyClient { | ||
| 21 | - private static final Logger logger = LoggerFactory.getLogger(NettyClient.class); | ||
| 22 | - | ||
| 23 | - private ChannelHandlerContext ctx; | ||
| 24 | - | ||
| 25 | - private EventLoopGroup groupThread; | ||
| 26 | - | ||
| 27 | - private Channel channel; | ||
| 28 | - | ||
| 29 | - public void run() | ||
| 30 | - { | ||
| 31 | - ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { | ||
| 32 | - if(!isOpen()) | ||
| 33 | - { | ||
| 34 | - close(); | ||
| 35 | - start(); | ||
| 36 | - } | ||
| 37 | - },1,3,TimeUnit.SECONDS); | ||
| 38 | - while (true) | ||
| 39 | - { | ||
| 40 | - if(null != ctx && ctx.channel().isActive() && ctx.channel().isOpen()) | ||
| 41 | - { | ||
| 42 | - return; | ||
| 43 | - } | ||
| 44 | - try { | ||
| 45 | - Thread.sleep(1000); | ||
| 46 | - } catch (InterruptedException e) { | ||
| 47 | - throw new RuntimeException(e); | ||
| 48 | - } | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | - private void start() { | ||
| 54 | - | ||
| 55 | - // 创建EventLoopGroup,用于处理客户端的I/O操作 | ||
| 56 | - groupThread = new NioEventLoopGroup(); | ||
| 57 | - | ||
| 58 | - try { | ||
| 59 | - // 创建Bootstrap实例,客户端启动对象 | ||
| 60 | - Bootstrap bootstrap = new Bootstrap(); | ||
| 61 | - bootstrap.group(groupThread); | ||
| 62 | - | ||
| 63 | - bootstrap.option(ChannelOption.SO_SNDBUF, 1024) // 设置发送缓冲大小 | ||
| 64 | - .option(ChannelOption.SO_RCVBUF, 1024) // 这是接收缓冲大小 | ||
| 65 | - .option(ChannelOption.SO_KEEPALIVE, true) ; // 保持连接 | ||
| 66 | - // 设置服务端Channel类型为NioSocketChannel作为通道实现 | ||
| 67 | - bootstrap.channel(NioSocketChannel.class); | ||
| 68 | - // 设置客户端处理 | ||
| 69 | - bootstrap.handler(new Channellitializer(this)); | ||
| 70 | - // 绑定端口 | ||
| 71 | - ChannelFuture channelFuture = bootstrap.connect(OperatingData.sysConfig.getNettyConfig().getHost(), OperatingData.sysConfig.getNettyConfig().getPort()).sync(); | ||
| 72 | - channel = channelFuture.channel(); | ||
| 73 | - | ||
| 74 | - } catch (Exception e) { | ||
| 75 | - throw new RuntimeException(e); | ||
| 76 | - } | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - public void close() | ||
| 80 | - { | ||
| 81 | - if (channel != null) { | ||
| 82 | - channel.close(); | ||
| 83 | - } | ||
| 84 | - if(null != groupThread) | ||
| 85 | - { | ||
| 86 | - try { | ||
| 87 | - groupThread.shutdownGracefully(); | ||
| 88 | - } catch (Exception e) { | ||
| 89 | - logger.info("服务端关闭资源失败【{}{}】",OperatingData.sysConfig.getNettyConfig().getHost(), OperatingData.sysConfig.getNettyConfig().getPort()); | ||
| 90 | - } | ||
| 91 | - } | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - protected class Channellitializer extends ChannelInitializer | ||
| 96 | - { | ||
| 97 | - private NettyClient nettyClient; | ||
| 98 | - public Channellitializer(NettyClient nettyClient) | ||
| 99 | - { | ||
| 100 | - this.nettyClient = nettyClient; | ||
| 101 | - } | ||
| 102 | - @Override | ||
| 103 | - protected void initChannel(Channel ch) { | ||
| 104 | - ChannelPipeline pipeline = ch.pipeline(); | ||
| 105 | - pipeline.addLast("StringEncoder", new StringEncoder(Charset.forName("gb2312"))); | ||
| 106 | - pipeline.addLast("StringDecoder", new StringDecoder(Charset.forName("gb2312"))); | ||
| 107 | - pipeline.addLast("AgreementHandler", new AgreementHandler()); | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - public ChannelHandlerContext getCtx() { | ||
| 112 | - if(null == ctx || !ctx.channel().isOpen()) | ||
| 113 | - { | ||
| 114 | - close(); | ||
| 115 | - start(); | ||
| 116 | - } | ||
| 117 | - return ctx; | ||
| 118 | - } | ||
| 119 | - | ||
| 120 | - public boolean isOpen() | ||
| 121 | - { | ||
| 122 | - if(null != ctx && ctx.channel().isActive() && ctx.channel().isOpen()) | ||
| 123 | - { | ||
| 124 | - return true; | ||
| 125 | - } | ||
| 126 | - return false; | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - public void setCtx(ChannelHandlerContext ctx) { | ||
| 130 | - this.ctx = ctx; | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | - public static void main(String[] args) { | ||
| 134 | - //配置参数 | ||
| 135 | - ConfigurationParameterService.initConfigurationParameter(); | ||
| 136 | - | ||
| 137 | - NettyClient nettyClient = new NettyClient(); | ||
| 138 | - nettyClient.start(); | ||
| 139 | - } | ||
| 140 | -} |
| @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | ||
| 4 | import com.ruoyi.common.utils.ByteUtil; | 4 | import com.ruoyi.common.utils.ByteUtil; |
| 5 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 5 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; |
| 6 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; | 6 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; |
| 7 | +import com.zhonglai.luhui.smart.feeder.service.DateListenService; | ||
| 7 | import io.netty.buffer.ByteBuf; | 8 | import io.netty.buffer.ByteBuf; |
| 8 | import io.netty.buffer.Unpooled; | 9 | import io.netty.buffer.Unpooled; |
| 9 | import io.netty.channel.ChannelFuture; | 10 | import io.netty.channel.ChannelFuture; |
| @@ -11,10 +12,13 @@ import io.netty.channel.ChannelHandlerContext; | @@ -11,10 +12,13 @@ import io.netty.channel.ChannelHandlerContext; | ||
| 11 | import io.netty.channel.socket.DatagramPacket; | 12 | import io.netty.channel.socket.DatagramPacket; |
| 12 | import io.netty.handler.codec.mqtt.MqttMessage; | 13 | import io.netty.handler.codec.mqtt.MqttMessage; |
| 13 | import org.apache.catalina.filters.ExpiresFilter; | 14 | import org.apache.catalina.filters.ExpiresFilter; |
| 15 | +import org.slf4j.Logger; | ||
| 16 | +import org.slf4j.LoggerFactory; | ||
| 14 | 17 | ||
| 15 | import java.net.InetSocketAddress; | 18 | import java.net.InetSocketAddress; |
| 16 | 19 | ||
| 17 | public class MessageUtil { | 20 | public class MessageUtil { |
| 21 | + private static final Logger logger = LoggerFactory.getLogger(MessageUtil.class); | ||
| 18 | public static void sendMandunMessage(ChannelHandlerContext ctx, InetSocketAddress recipient, String commd) | 22 | public static void sendMandunMessage(ChannelHandlerContext ctx, InetSocketAddress recipient, String commd) |
| 19 | { | 23 | { |
| 20 | byte[] bs = ByteUtil.hexStringToByte(commd.trim().toUpperCase()); | 24 | byte[] bs = ByteUtil.hexStringToByte(commd.trim().toUpperCase()); |
| @@ -34,6 +38,7 @@ public class MessageUtil { | @@ -34,6 +38,7 @@ public class MessageUtil { | ||
| 34 | * @param flush | 38 | * @param flush |
| 35 | */ | 39 | */ |
| 36 | public static ChannelFuture sendMessage(ChannelHandlerContext ctx, Object msg, boolean flush) { | 40 | public static ChannelFuture sendMessage(ChannelHandlerContext ctx, Object msg, boolean flush) { |
| 41 | + logger.info("给服务器发送数据:{}",msg); | ||
| 37 | return flush ? ctx.writeAndFlush(msg) : ctx.write(msg); | 42 | return flush ? ctx.writeAndFlush(msg) : ctx.write(msg); |
| 38 | } | 43 | } |
| 39 | 44 |
-
请 注册 或 登录 后发表评论