正在显示
22 个修改的文件
包含
539 行增加
和
254 行删除
| 1 | -package com.zhonglai.luhui.lsy.plc.service.comm.service; | ||
| 2 | - | ||
| 3 | -import com.alibaba.fastjson.JSONObject; | ||
| 4 | -import com.zhonglai.luhui.device.analysis.dto.ApiName; | ||
| 5 | -import com.zhonglai.luhui.device.analysis.dto.DeviceCommandApiParameter; | ||
| 6 | -import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 7 | -import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 8 | -import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 9 | -import com.zhonglai.luhui.device.domain.IotTerminal; | ||
| 10 | -import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * 设备指令接口 | ||
| 14 | - */ | ||
| 15 | -public class DeviceCommandApi { | ||
| 16 | - private ApiName apiName; //指令接口名称 | ||
| 17 | - private DeviceCommandApiParameter deviceCommandApiParameter; //参数 | ||
| 18 | - | ||
| 19 | - public Message invokeApi(MqttDeviceService deviceService) throws InterruptedException, MqttException { | ||
| 20 | - switch (apiName) | ||
| 21 | - { | ||
| 22 | -// case read: | ||
| 23 | -// return deviceService.read(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getMap()); | ||
| 24 | -// case control: | ||
| 25 | -// return deviceService.control(deviceCommandApiParameter.getClient_id(), deviceCommandApiParameter.getMap()); | ||
| 26 | -// case controlHex: | ||
| 27 | -// return deviceService.controlHex(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getData()); | ||
| 28 | -// case closeSession: | ||
| 29 | -// return deviceService.closeSession(deviceCommandApiParameter.getClient_id()); | ||
| 30 | -// case delIotDevice: | ||
| 31 | -// deviceService.closeSession(deviceCommandApiParameter.getClient_id()); //强制下线 | ||
| 32 | -// return deviceService.delIotDevice(deviceCommandApiParameter.getClient_id()); | ||
| 33 | -// case delIotTerminal: | ||
| 34 | -// deviceService.closeSession(deviceCommandApiParameter.getClient_id()); //强制下线 | ||
| 35 | -// return deviceService.delIotTerminal(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getNumber()); | ||
| 36 | -// case getFirmwareVersion: | ||
| 37 | -// return deviceService.getFirmwareVersion(deviceCommandApiParameter.getData()); | ||
| 38 | -// case updateIotDevice: | ||
| 39 | -// IotDevice iotDevice = JSONObject.parseObject(JSONObject.toJSONString(deviceCommandApiParameter.getMap()), IotDevice.class); | ||
| 40 | -// deviceCommandApiParameter.setClient_id(iotDevice.getClient_id()); | ||
| 41 | -// return deviceService.updateIotDevice(iotDevice); | ||
| 42 | -// case updateIotTerminal: | ||
| 43 | -// IotTerminal iotTerminal = JSONObject.parseObject(JSONObject.toJSONString(deviceCommandApiParameter.getMap()), IotTerminal.class); | ||
| 44 | -// deviceCommandApiParameter.setClient_id(iotTerminal.getId()); | ||
| 45 | -// return deviceService.updateIotTerminal(iotTerminal); | ||
| 46 | -// case delDeviceHost: | ||
| 47 | -// return deviceService.delDeviceHost(deviceCommandApiParameter.getClient_id()); | ||
| 48 | -// case delDeviceInfo: | ||
| 49 | -// deviceCommandApiParameter.setClient_id(deviceCommandApiParameter.getData()); | ||
| 50 | -// return deviceService.delDeviceInfo(deviceCommandApiParameter.getData()); | ||
| 51 | -// case delDeviceInfoFromDeviceId: | ||
| 52 | -// return deviceService.delDeviceInfoFromDeviceId(deviceCommandApiParameter.getClient_id()); | ||
| 53 | -// case transferPond: | ||
| 54 | -// return deviceService.transferPond(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getMap()); | ||
| 55 | -// case updateDeviceInfo: | ||
| 56 | -// return deviceService.updateDeviceInfo(deviceCommandApiParameter.getClient_id(),deviceCommandApiParameter.getMap()); | ||
| 57 | - default: | ||
| 58 | - return new Message(MessageCode.DEFAULT_FAIL_CODE,"接口不存在"); | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - public ApiName getApiName() { | ||
| 64 | - return apiName; | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - public void setApiName(ApiName apiName) { | ||
| 68 | - this.apiName = apiName; | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - public DeviceCommandApiParameter getDeviceCommandApiParameter() { | ||
| 72 | - return deviceCommandApiParameter; | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - public void setDeviceCommandApiParameter(DeviceCommandApiParameter deviceCommandApiParameter) { | ||
| 76 | - this.deviceCommandApiParameter = deviceCommandApiParameter; | ||
| 77 | - } | ||
| 78 | -} |
| 1 | -package com.zhonglai.luhui.lsy.plc.service.comm.service; | ||
| 2 | - | ||
| 3 | -import com.alibaba.fastjson.JSON; | ||
| 4 | -import com.alibaba.fastjson.JSONObject; | ||
| 5 | -import com.zhonglai.luhui.device.analysis.comm.db.DeviceService; | ||
| 6 | -import com.zhonglai.luhui.device.analysis.comm.db.mode.TerminalDataThingsModeService; | ||
| 7 | -import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation; | ||
| 8 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelBase; | ||
| 9 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelDataTypeEnum; | ||
| 10 | -import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase; | ||
| 11 | -import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | ||
| 12 | -import com.zhonglai.luhui.device.analysis.comm.service.BusinessDataUpdateService; | ||
| 13 | -import com.zhonglai.luhui.device.analysis.comm.service.CacheServiceImpl; | ||
| 14 | -import com.zhonglai.luhui.device.analysis.comm.service.DataPersistenceServiceImpl; | ||
| 15 | -import com.zhonglai.luhui.device.analysis.comm.service.DeviceLogService; | ||
| 16 | -import com.zhonglai.luhui.device.analysis.comm.util.DateUtils; | ||
| 17 | -import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 18 | -import com.zhonglai.luhui.device.analysis.dto.MessageCode; | ||
| 19 | -import com.zhonglai.luhui.device.analysis.dto.topic.AddPostDto; | ||
| 20 | -import com.zhonglai.luhui.device.domain.IotThingsModel; | ||
| 21 | -import com.zhonglai.luhui.lsy.plc.service.service.ClienNoticeService; | ||
| 22 | -import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 23 | -import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 24 | -import org.slf4j.Logger; | ||
| 25 | -import org.slf4j.LoggerFactory; | ||
| 26 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 27 | -import org.springframework.stereotype.Service; | ||
| 28 | - | ||
| 29 | -import java.util.ArrayList; | ||
| 30 | -import java.util.List; | ||
| 31 | -import java.util.Map; | ||
| 32 | - | ||
| 33 | -@Service | ||
| 34 | -public class MqttDeviceService { | ||
| 35 | - private static final Logger log = LoggerFactory.getLogger(MqttDeviceService.class); | ||
| 36 | - @Autowired | ||
| 37 | - private ClienNoticeService clienNoticeService; | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | -} |
| @@ -5,20 +5,13 @@ import com.google.gson.JsonObject; | @@ -5,20 +5,13 @@ import com.google.gson.JsonObject; | ||
| 5 | import com.ruoyi.common.utils.DateUtils; | 5 | import com.ruoyi.common.utils.DateUtils; |
| 6 | import com.ruoyi.common.utils.GsonConstructor; | 6 | import com.ruoyi.common.utils.GsonConstructor; |
| 7 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 7 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 8 | -import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | ||
| 9 | import com.zhonglai.luhui.device.analysis.comm.util.StringUtils; | 8 | import com.zhonglai.luhui.device.analysis.comm.util.StringUtils; |
| 10 | import com.zhonglai.luhui.device.analysis.comm.util.TableUtil; | 9 | import com.zhonglai.luhui.device.analysis.comm.util.TableUtil; |
| 11 | import com.zhonglai.luhui.device.analysis.dto.Message; | 10 | import com.zhonglai.luhui.device.analysis.dto.Message; |
| 12 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; | 11 | import com.zhonglai.luhui.device.analysis.dto.MessageCode; |
| 13 | -import com.zhonglai.luhui.device.domain.IotDevice; | ||
| 14 | -import com.zhonglai.luhui.device.domain.IotTerminal; | ||
| 15 | import com.zhonglai.luhui.lsy.plc.service.comm.service.DeviceService; | 12 | import com.zhonglai.luhui.lsy.plc.service.comm.service.DeviceService; |
| 16 | -import com.zhonglai.luhui.lsy.plc.service.comm.service.MqttDeviceService; | ||
| 17 | -import com.zhonglai.luhui.lsy.plc.service.comm.service.TerminalService; | ||
| 18 | -import com.zhonglai.luhui.lsy.plc.service.comm.util.TopicUtil; | ||
| 19 | import com.zhonglai.luhui.lsy.plc.service.dto.*; | 13 | import com.zhonglai.luhui.lsy.plc.service.dto.*; |
| 20 | import com.zhonglai.luhui.lsy.plc.service.service.ClienNoticeService; | 14 | import com.zhonglai.luhui.lsy.plc.service.service.ClienNoticeService; |
| 21 | -import com.zhonglai.luhui.lsy.plc.service.service.topic.AllPostTopic; | ||
| 22 | import io.swagger.annotations.Api; | 15 | import io.swagger.annotations.Api; |
| 23 | import io.swagger.annotations.ApiImplicitParam; | 16 | import io.swagger.annotations.ApiImplicitParam; |
| 24 | import io.swagger.annotations.ApiImplicitParams; | 17 | import io.swagger.annotations.ApiImplicitParams; |
| @@ -30,7 +23,6 @@ import org.slf4j.LoggerFactory; | @@ -30,7 +23,6 @@ import org.slf4j.LoggerFactory; | ||
| 30 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
| 31 | import org.springframework.web.bind.annotation.*; | 24 | import org.springframework.web.bind.annotation.*; |
| 32 | 25 | ||
| 33 | -import javax.servlet.http.HttpServletResponse; | ||
| 34 | import java.util.ArrayList; | 26 | import java.util.ArrayList; |
| 35 | import java.util.HashMap; | 27 | import java.util.HashMap; |
| 36 | import java.util.List; | 28 | import java.util.List; |
| @@ -65,6 +65,13 @@ | @@ -65,6 +65,13 @@ | ||
| 65 | <groupId>jakarta.xml.bind</groupId> | 65 | <groupId>jakarta.xml.bind</groupId> |
| 66 | <artifactId>jakarta.xml.bind-api</artifactId> | 66 | <artifactId>jakarta.xml.bind-api</artifactId> |
| 67 | </dependency> | 67 | </dependency> |
| 68 | + | ||
| 69 | + <!-- mqtt --> | ||
| 70 | + <dependency> | ||
| 71 | + <groupId>org.eclipse.paho</groupId> | ||
| 72 | + <artifactId>org.eclipse.paho.client.mqttv3</artifactId> | ||
| 73 | + </dependency> | ||
| 74 | + | ||
| 68 | </dependencies> | 75 | </dependencies> |
| 69 | 76 | ||
| 70 | <build> | 77 | <build> |
| @@ -12,7 +12,7 @@ public class OperatingData { | @@ -12,7 +12,7 @@ public class OperatingData { | ||
| 12 | public static CameraData cameraData = new CameraData(); //摄像头数据 | 12 | public static CameraData cameraData = new CameraData(); //摄像头数据 |
| 13 | public static CameraConfig cameraConfig = new CameraConfig() ; //摄像头配置 | 13 | public static CameraConfig cameraConfig = new CameraConfig() ; //摄像头配置 |
| 14 | public static FeederConfig feederConfig = new FeederConfig() ; //投料机配置 | 14 | public static FeederConfig feederConfig = new FeederConfig() ; //投料机配置 |
| 15 | - public static FeederData feederData = new FeederData() ; //投料机配置 | 15 | + public static FeederData feederData = new FeederData() ; //投料机数据 |
| 16 | public static RegisterConfig registerConfig = new RegisterConfig(); //数据解析字典 | 16 | public static RegisterConfig registerConfig = new RegisterConfig(); //数据解析字典 |
| 17 | 17 | ||
| 18 | public static void setClassObjecValue(Object value,IfOperatingDataValueIsNotNull ifOperatingDataValueIsNotNull) throws IllegalAccessException, InstantiationException { | 18 | public static void setClassObjecValue(Object value,IfOperatingDataValueIsNotNull ifOperatingDataValueIsNotNull) throws IllegalAccessException, InstantiationException { |
| @@ -30,7 +30,7 @@ public class RegisterConfig implements OperatingDataType{ | @@ -30,7 +30,7 @@ public class RegisterConfig implements OperatingDataType{ | ||
| 30 | registerList.add(new Register(6,"饲料重量",0,16,"fodderweight","java.lang.Float")); | 30 | registerList.add(new Register(6,"饲料重量",0,16,"fodderweight","java.lang.Float")); |
| 31 | registerList.add(new Register(7,"投料次数",0,16,"feednum","java.lang.Integer")); | 31 | registerList.add(new Register(7,"投料次数",0,16,"feednum","java.lang.Integer")); |
| 32 | registerList.add(new Register(8,"本次投料量",0,16,"feedweight","java.lang.Float")); | 32 | registerList.add(new Register(8,"本次投料量",0,16,"feedweight","java.lang.Float")); |
| 33 | - registerList.add(new Register(13,"运行模式",0,16,"runmode","java.lang.Boolean")); | 33 | + registerList.add(new Register(13,"运行模式",0,16,"runmode","java.lang.Integer")); |
| 34 | registerList.add(new Register(14,"投料量",0,16,"runspeed","java.lang.Integer")); | 34 | registerList.add(new Register(14,"投料量",0,16,"runspeed","java.lang.Integer")); |
| 35 | registerList.add(new Register(15,"投料时间",0,16,"worktime","java.lang.Integer")); | 35 | registerList.add(new Register(15,"投料时间",0,16,"worktime","java.lang.Integer")); |
| 36 | registerList.add(new Register(16,"间隔时间",0,16,"interval","java.lang.Integer")); | 36 | registerList.add(new Register(16,"间隔时间",0,16,"interval","java.lang.Integer")); |
| @@ -13,4 +13,6 @@ public class Condata | @@ -13,4 +13,6 @@ public class Condata | ||
| 13 | private Integer interval; //时间间隔 1-18秒 | 13 | private Integer interval; //时间间隔 1-18秒 |
| 14 | private Integer runstate; //运行状态 1运行、3停止(平台可以设置0启动中,2关闭中,4异常) | 14 | private Integer runstate; //运行状态 1运行、3停止(平台可以设置0启动中,2关闭中,4异常) |
| 15 | private Integer stopfeedcnt; //手动投料倒计时时间 单位分 | 15 | private Integer stopfeedcnt; //手动投料倒计时时间 单位分 |
| 16 | + | ||
| 17 | + private Integer onoff; | ||
| 16 | } | 18 | } |
| @@ -57,24 +57,25 @@ public class DateListenService { | @@ -57,24 +57,25 @@ public class DateListenService { | ||
| 57 | } | 57 | } |
| 58 | OperatingData.feederData.setInfo(info); | 58 | OperatingData.feederData.setInfo(info); |
| 59 | 59 | ||
| 60 | - List<Integer[]> timerList = new ArrayList<>(); | ||
| 61 | - for(String key:data.keySet()) | ||
| 62 | - { | ||
| 63 | - if(key.startsWith("timer")) | ||
| 64 | - { | ||
| 65 | - FeederTimer feederTimer = (FeederTimer) data.get(key); | ||
| 66 | - timerList.add(new Integer[]{feederTimer.getTimer_start_h(),feederTimer.getTimer_start_m(),feederTimer.getTimer_close_h(),feederTimer.getTimer_start_m(),feederTimer.getTimer_if_start()}); | ||
| 67 | - } | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - if(null != timerList && timerList.size() != 0) | ||
| 71 | - { | ||
| 72 | - if(ObjectUtil.notEqual(OperatingData.feederConfig.getTimer(),timerList)) | ||
| 73 | - { | ||
| 74 | - OperatingData.feederConfig.setTimer(timerList); | ||
| 75 | - reportTimer(); | ||
| 76 | - } | ||
| 77 | - } | 60 | + //投料机不可以读 |
| 61 | +// List<Integer[]> timerList = new ArrayList<>(); | ||
| 62 | +// for(String key:data.keySet()) | ||
| 63 | +// { | ||
| 64 | +// if(key.startsWith("timer")) | ||
| 65 | +// { | ||
| 66 | +// FeederTimer feederTimer = (FeederTimer) data.get(key); | ||
| 67 | +// timerList.add(new Integer[]{feederTimer.getTimer_start_h(),feederTimer.getTimer_start_m(),feederTimer.getTimer_close_h(),feederTimer.getTimer_start_m(),feederTimer.getTimer_if_start()}); | ||
| 68 | +// } | ||
| 69 | +// } | ||
| 70 | +// | ||
| 71 | +// if(null != timerList && timerList.size() != 0) | ||
| 72 | +// { | ||
| 73 | +// if(ObjectUtil.notEqual(OperatingData.feederConfig.getTimer(),timerList)) | ||
| 74 | +// { | ||
| 75 | +// OperatingData.feederConfig.setTimer(timerList); | ||
| 76 | +// reportTimer(); | ||
| 77 | +// } | ||
| 78 | +// } | ||
| 78 | } | 79 | } |
| 79 | },1,10, TimeUnit.SECONDS); | 80 | },1,10, TimeUnit.SECONDS); |
| 80 | 81 | ||
| @@ -159,23 +160,23 @@ public class DateListenService { | @@ -159,23 +160,23 @@ public class DateListenService { | ||
| 159 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | 160 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); |
| 160 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | 161 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); |
| 161 | } | 162 | } |
| 162 | - /** | ||
| 163 | - * 上报投料机定时参数 | ||
| 164 | - */ | ||
| 165 | - public void reportTimer() | ||
| 166 | - { | ||
| 167 | - DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 168 | - devicedatRequest.setCmd("devicedata"); | ||
| 169 | - devicedatRequest.setType("4G.hs"); | ||
| 170 | - devicedatRequest.setSignal(4); | ||
| 171 | - devicedatRequest.setMachstate(1); | ||
| 172 | - devicedatRequest.setBattlevel(4); | ||
| 173 | - devicedatRequest.setTimer(OperatingData.feederConfig.getTimer()); | ||
| 174 | - String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 175 | - System.out.println(str); | ||
| 176 | - CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 177 | - MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 178 | - } | 163 | +// /** |
| 164 | +// * 上报投料机定时参数 | ||
| 165 | +// */ | ||
| 166 | +// public void reportTimer() | ||
| 167 | +// { | ||
| 168 | +// DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 169 | +// devicedatRequest.setCmd("devicedata"); | ||
| 170 | +// devicedatRequest.setType("4G.hs"); | ||
| 171 | +// devicedatRequest.setSignal(4); | ||
| 172 | +// devicedatRequest.setMachstate(1); | ||
| 173 | +// devicedatRequest.setBattlevel(4); | ||
| 174 | +// devicedatRequest.setTimer(OperatingData.feederConfig.getTimer()); | ||
| 175 | +// String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 176 | +// System.out.println(str); | ||
| 177 | +// CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 178 | +// MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 179 | +// } | ||
| 179 | 180 | ||
| 180 | /** | 181 | /** |
| 181 | * 上报串口参数 | 182 | * 上报串口参数 |
| @@ -265,7 +266,7 @@ public class DateListenService { | @@ -265,7 +266,7 @@ public class DateListenService { | ||
| 265 | 266 | ||
| 266 | devicedatRequest.setCondata(OperatingData.feederConfig.getCondata()); | 267 | devicedatRequest.setCondata(OperatingData.feederConfig.getCondata()); |
| 267 | devicedatRequest.setInfo(OperatingData.feederData.getInfo()); | 268 | devicedatRequest.setInfo(OperatingData.feederData.getInfo()); |
| 268 | - devicedatRequest.setTimer(OperatingData.feederConfig.getTimer()); | 269 | +// devicedatRequest.setTimer(OperatingData.feederConfig.getTimer()); |
| 269 | 270 | ||
| 270 | devicedatRequest.setSysConfig(OperatingData.sysConfig); | 271 | devicedatRequest.setSysConfig(OperatingData.sysConfig); |
| 271 | devicedatRequest.setCameraData(OperatingData.cameraData); | 272 | devicedatRequest.setCameraData(OperatingData.cameraData); |
| @@ -42,7 +42,7 @@ public class DeviceService { | @@ -42,7 +42,7 @@ public class DeviceService { | ||
| 42 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.controlData(FeederCommd06ResponseType.runmode,0)); //,运行模式改成手动 | 42 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.controlData(FeederCommd06ResponseType.runmode,0)); //,运行模式改成手动 |
| 43 | if(null!=modbusDto) | 43 | if(null!=modbusDto) |
| 44 | { | 44 | { |
| 45 | - condata.setRunmode(1); | 45 | + condata.setRunmode(0); |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | 48 |
| @@ -6,16 +6,19 @@ import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | @@ -6,16 +6,19 @@ import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | ||
| 6 | import com.zhonglai.luhui.smart.feeder.dto.FishCurveControlCondition; | 6 | import com.zhonglai.luhui.smart.feeder.dto.FishCurveControlCondition; |
| 7 | import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle; | 7 | import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle; |
| 8 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; | 8 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; |
| 9 | +import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 9 | import org.opencv.core.*; | 10 | import org.opencv.core.*; |
| 11 | +import org.opencv.highgui.HighGui; | ||
| 12 | +import org.opencv.imgcodecs.Imgcodecs; | ||
| 10 | import org.opencv.imgproc.Imgproc; | 13 | import org.opencv.imgproc.Imgproc; |
| 11 | import org.opencv.video.BackgroundSubtractorMOG2; | 14 | import org.opencv.video.BackgroundSubtractorMOG2; |
| 12 | import org.opencv.video.Video; | 15 | import org.opencv.video.Video; |
| 13 | import org.slf4j.Logger; | 16 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; | 17 | import org.slf4j.LoggerFactory; |
| 15 | 18 | ||
| 16 | -import java.util.ArrayList; | ||
| 17 | -import java.util.Comparator; | ||
| 18 | -import java.util.List; | 19 | +import java.math.BigDecimal; |
| 20 | +import java.math.RoundingMode; | ||
| 21 | +import java.util.*; | ||
| 19 | import java.util.concurrent.ScheduledFuture; | 22 | import java.util.concurrent.ScheduledFuture; |
| 20 | import java.util.concurrent.TimeUnit; | 23 | import java.util.concurrent.TimeUnit; |
| 21 | 24 | ||
| @@ -77,6 +80,9 @@ public class FishGroupImageRecognitionService { | @@ -77,6 +80,9 @@ public class FishGroupImageRecognitionService { | ||
| 77 | { | 80 | { |
| 78 | CameraHandle cameraHandle = InitService.cameraHandle; | 81 | CameraHandle cameraHandle = InitService.cameraHandle; |
| 79 | 82 | ||
| 83 | +// // 创建一个窗口来显示图像 | ||
| 84 | +// HighGui.namedWindow("Image", HighGui.WINDOW_AUTOSIZE); | ||
| 85 | + | ||
| 80 | if(!cameraHandle.isOpen()) | 86 | if(!cameraHandle.isOpen()) |
| 81 | { | 87 | { |
| 82 | if (!cameraHandle.init()) | 88 | if (!cameraHandle.init()) |
| @@ -90,7 +96,10 @@ public class FishGroupImageRecognitionService { | @@ -90,7 +96,10 @@ public class FishGroupImageRecognitionService { | ||
| 90 | 96 | ||
| 91 | public void stop() | 97 | public void stop() |
| 92 | { | 98 | { |
| 99 | + if(null != srsService) | ||
| 100 | + { | ||
| 93 | srsService.stop(); | 101 | srsService.stop(); |
| 102 | + } | ||
| 94 | OperatingData.cameraData.setFishGroupImageRecognIsRun(false); | 103 | OperatingData.cameraData.setFishGroupImageRecognIsRun(false); |
| 95 | backgroundSubtractor.clear(); | 104 | backgroundSubtractor.clear(); |
| 96 | 105 | ||
| @@ -144,7 +153,22 @@ public class FishGroupImageRecognitionService { | @@ -144,7 +153,22 @@ public class FishGroupImageRecognitionService { | ||
| 144 | { | 153 | { |
| 145 | if(null != srsService && endTime-DateUtils.getNowTimeMilly()>0) | 154 | if(null != srsService && endTime-DateUtils.getNowTimeMilly()>0) |
| 146 | { | 155 | { |
| 147 | - srsService.push(frame); | 156 | + CameraRtspHandle cameraRtspHandle = (CameraRtspHandle)cameraHandle; |
| 157 | + Mat mat = cameraRtspHandle.compress(frame); | ||
| 158 | + // 将图像转换为二进制数据 | ||
| 159 | + MatOfByte matOfByte = new MatOfByte(); | ||
| 160 | + Imgcodecs.imencode(".jpg", mat, matOfByte); | ||
| 161 | + byte[] byteArray = matOfByte.toArray(); | ||
| 162 | + | ||
| 163 | + logger.info("推送图片大小:"+(byteArray.length/1024)+"kb"); | ||
| 164 | + String base64String = Base64.getEncoder().encodeToString(byteArray); | ||
| 165 | + mqttService.pullimg(base64String.getBytes()); | ||
| 166 | + | ||
| 167 | +// // 显示图像 | ||
| 168 | +// HighGui.imshow("Image", mat); | ||
| 169 | +// HighGui.waitKey(1); | ||
| 170 | + matOfByte.release(); | ||
| 171 | + mat.release(); | ||
| 148 | }else { | 172 | }else { |
| 149 | if(null != srsService) | 173 | if(null != srsService) |
| 150 | { | 174 | { |
| @@ -197,51 +221,35 @@ public class FishGroupImageRecognitionService { | @@ -197,51 +221,35 @@ public class FishGroupImageRecognitionService { | ||
| 197 | 221 | ||
| 198 | double[] dsTotal = new double[5]; | 222 | double[] dsTotal = new double[5]; |
| 199 | 223 | ||
| 200 | - | ||
| 201 | contours.removeIf(matOfPoint -> { | 224 | contours.removeIf(matOfPoint -> { |
| 202 | Rect rect = Imgproc.boundingRect(matOfPoint); | 225 | Rect rect = Imgproc.boundingRect(matOfPoint); |
| 203 | matOfPoint.release(); | 226 | matOfPoint.release(); |
| 204 | - if(rect.width!=image.width() && rect.width>OperatingData.cameraConfig.getCalloutBoxWidthMin()) | ||
| 205 | - { | 227 | + |
| 206 | double[] ds = count(image,rect); | 228 | double[] ds = count(image,rect); |
| 207 | 229 | ||
| 208 | - if(filterate(ds)) | ||
| 209 | - { | ||
| 210 | dsTotal[0]+=ds[0]; | 230 | dsTotal[0]+=ds[0]; |
| 211 | dsTotal[1]+=ds[1]; | 231 | dsTotal[1]+=ds[1]; |
| 212 | dsTotal[2]+=ds[2]; | 232 | dsTotal[2]+=ds[2]; |
| 213 | - dsTotal[3]+=ds[3]; | ||
| 214 | dsTotal[4]++; | 233 | dsTotal[4]++; |
| 234 | + if(rect.width!=image.width() && rect.width>OperatingData.cameraConfig.getCalloutBoxWidthMin()) | ||
| 235 | + { | ||
| 236 | + if(filterate(ds)) | ||
| 237 | + { | ||
| 238 | + dsTotal[3]+=ds[3]; | ||
| 215 | Imgproc.rectangle(image, rect.tl(), rect.br(), new Scalar(0, 255, 0), 2); | 239 | Imgproc.rectangle(image, rect.tl(), rect.br(), new Scalar(0, 255, 0), 2); |
| 216 | return false; | 240 | return false; |
| 241 | + }else{ | ||
| 242 | + dsTotal[3]+=0; | ||
| 217 | } | 243 | } |
| 244 | + }else{ | ||
| 245 | + dsTotal[3]+=0; | ||
| 218 | } | 246 | } |
| 219 | return true; | 247 | return true; |
| 220 | }); | 248 | }); |
| 221 | - | ||
| 222 | - if(0!=dsTotal[4]) | ||
| 223 | - { | ||
| 224 | - double brightness = dsTotal[0]/dsTotal[4]; | ||
| 225 | - double reflection= dsTotal[1]/dsTotal[4]; | ||
| 226 | - double transparencyMeasure= dsTotal[2]/dsTotal[4]; | ||
| 227 | - double area = dsTotal[3]/dsTotal[4]; | ||
| 228 | - | ||
| 229 | - //计算斜率 | ||
| 230 | - double slope = area - (null==OperatingData.cameraData.getArea()?area:OperatingData.cameraData.getArea()); | ||
| 231 | - //当前斜率的差值 | ||
| 232 | - double slopeDifference = slope-(null==OperatingData.cameraData.getSlope()?slope:OperatingData.cameraData.getSlope()); | ||
| 233 | - //计算斜率差值的绝对值 | ||
| 234 | - double absValue = Math.abs(slopeDifference); | ||
| 235 | - | ||
| 236 | - OperatingData.cameraData.setBrightness(brightness); | ||
| 237 | - OperatingData.cameraData.setReflection(reflection); | ||
| 238 | - OperatingData.cameraData.setTransparencyMeasure(transparencyMeasure); | ||
| 239 | - OperatingData.cameraData.setArea(area); | ||
| 240 | - OperatingData.cameraData.setSlope(slope); | ||
| 241 | - OperatingData.cameraData.setSlopeDifference(slopeDifference); | ||
| 242 | - OperatingData.cameraData.setAbsValue(absValue); | ||
| 243 | - OperatingData.cameraData.setSize(new Double(dsTotal[4]).intValue()); | ||
| 244 | - | 249 | + if(0==dsTotal[4]) |
| 250 | + { | ||
| 251 | + return; | ||
| 252 | + } | ||
| 245 | List<Double> scaleAreaList = OperatingData.cameraData.getScaleAreaList(); | 253 | List<Double> scaleAreaList = OperatingData.cameraData.getScaleAreaList(); |
| 246 | //计算尺度之内的面积集合的大小 | 254 | //计算尺度之内的面积集合的大小 |
| 247 | int size = new Double((OperatingData.cameraConfig.getCollectionScale()*60*1000l)/time).intValue(); | 255 | int size = new Double((OperatingData.cameraConfig.getCollectionScale()*60*1000l)/time).intValue(); |
| @@ -250,48 +258,77 @@ public class FishGroupImageRecognitionService { | @@ -250,48 +258,77 @@ public class FishGroupImageRecognitionService { | ||
| 250 | { | 258 | { |
| 251 | scaleAreaList.remove(0); | 259 | scaleAreaList.remove(0); |
| 252 | } | 260 | } |
| 253 | - scaleAreaList.add(dsTotal[4]); | ||
| 254 | - | ||
| 255 | - //计算鱼群规模 | ||
| 256 | - Double[] fishSchoolSizeConfig = OperatingData.cameraConfig.getFishSchoolSizeConfig(); | ||
| 257 | - int grade = 0; | ||
| 258 | - double fishSchoolSize = area*dsTotal[4]; | ||
| 259 | - System.out.println("=======鱼群规模:"+fishSchoolSize+"========="); | ||
| 260 | - for (int i=0;i<fishSchoolSizeConfig.length;i++) | ||
| 261 | - { | ||
| 262 | - if(fishSchoolSize-fishSchoolSizeConfig[i]>0) | ||
| 263 | - { | ||
| 264 | - grade = i+1; | ||
| 265 | - } | ||
| 266 | - } | ||
| 267 | - | ||
| 268 | - if(OperatingData.cameraData.getFishSchoolSize()!=grade) | ||
| 269 | - { | ||
| 270 | - OperatingData.cameraData.setFishSchoolSize(grade); | ||
| 271 | - if(OperatingData.cameraConfig.getIfSendFishSchoolSize()) | ||
| 272 | - { | ||
| 273 | - int finalGrade = grade; | ||
| 274 | - ScheduledConfig.scheduler.schedule(() -> { | ||
| 275 | - | ||
| 276 | - String nowtime = DateUtils.getTime(); | ||
| 277 | - String[] ss = OperatingData.cameraConfig.getFishSchoolSizeConfigString(); | ||
| 278 | - String fishSchoolSizeStr = ss[finalGrade]; | ||
| 279 | - StringBuffer stringBuffer = new StringBuffer(); | ||
| 280 | - stringBuffer.append(nowtime); | ||
| 281 | - stringBuffer.append(" "); | ||
| 282 | - stringBuffer.append(fishSchoolSizeStr); | ||
| 283 | -// stringBuffer.append(",当前档位:"); | ||
| 284 | -// stringBuffer.append(null==OperatingData.cameraData.getNowGear()?0:OperatingData.cameraData.getNowGear()); | ||
| 285 | -// stringBuffer.append("档"); | ||
| 286 | - InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); | ||
| 287 | - | ||
| 288 | - },0, TimeUnit.SECONDS); | ||
| 289 | - } | ||
| 290 | - } | ||
| 291 | - | ||
| 292 | - logger.info("当前画面的亮度:{},当前画面的反光:{},当前画面的透明度:{},当前画面的平均面积:{},鱼群规模:{},鱼群数量:{}",brightness,reflection,transparencyMeasure,area,fishSchoolSize, OperatingData.cameraData.getSize()); | 261 | + scaleAreaList.add(dsTotal[3]); |
| 262 | + OperatingData.cameraData.setBrightness(new BigDecimal(dsTotal[0]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue()); | ||
| 263 | + OperatingData.cameraData.setReflection(new BigDecimal(dsTotal[1]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue()); | ||
| 264 | + OperatingData.cameraData.setTransparencyMeasure(new BigDecimal(dsTotal[2]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue()); | ||
| 265 | + OperatingData.cameraData.setArea(new BigDecimal(dsTotal[3]/dsTotal[4]).setScale(2, RoundingMode.HALF_UP).doubleValue()); | ||
| 266 | + OperatingData.cameraData.setFishSchoolSize(new Double(dsTotal[3]).intValue()); | ||
| 267 | + OperatingData.cameraData.setSize(new Double(dsTotal[4]).intValue()); | ||
| 293 | 268 | ||
| 294 | - } | 269 | +// if(0!=dsTotal[4]) |
| 270 | +// { | ||
| 271 | +// double brightness = dsTotal[0]/dsTotal[4]; | ||
| 272 | +// double reflection= dsTotal[1]/dsTotal[4]; | ||
| 273 | +// double transparencyMeasure= dsTotal[2]/dsTotal[4]; | ||
| 274 | +// double area = dsTotal[3]/dsTotal[4]; | ||
| 275 | +// | ||
| 276 | +// //计算斜率 | ||
| 277 | +// double slope = area - (null==OperatingData.cameraData.getArea()?area:OperatingData.cameraData.getArea()); | ||
| 278 | +// //当前斜率的差值 | ||
| 279 | +// double slopeDifference = slope-(null==OperatingData.cameraData.getSlope()?slope:OperatingData.cameraData.getSlope()); | ||
| 280 | +// //计算斜率差值的绝对值 | ||
| 281 | +// double absValue = Math.abs(slopeDifference); | ||
| 282 | +// | ||
| 283 | +// OperatingData.cameraData.setBrightness(brightness); | ||
| 284 | +// OperatingData.cameraData.setReflection(reflection); | ||
| 285 | +// OperatingData.cameraData.setTransparencyMeasure(transparencyMeasure); | ||
| 286 | +// OperatingData.cameraData.setArea(area); | ||
| 287 | +// OperatingData.cameraData.setSlope(slope); | ||
| 288 | +// OperatingData.cameraData.setSlopeDifference(slopeDifference); | ||
| 289 | +// OperatingData.cameraData.setAbsValue(absValue); | ||
| 290 | +// OperatingData.cameraData.setSize(new Double(dsTotal[4]).intValue()); | ||
| 291 | +// | ||
| 292 | +// //计算鱼群规模 | ||
| 293 | +// Double[] fishSchoolSizeConfig = OperatingData.cameraConfig.getFishSchoolSizeConfig(); | ||
| 294 | +// int grade = 0; | ||
| 295 | +// double fishSchoolSize = dsTotal[3]; | ||
| 296 | +// System.out.println("=======鱼群规模:"+fishSchoolSize+"========="); | ||
| 297 | +// for (int i=0;i<fishSchoolSizeConfig.length;i++) | ||
| 298 | +// { | ||
| 299 | +// if(fishSchoolSize-fishSchoolSizeConfig[i]>0) | ||
| 300 | +// { | ||
| 301 | +// grade = i+1; | ||
| 302 | +// } | ||
| 303 | +// } | ||
| 304 | +// | ||
| 305 | +// if(OperatingData.cameraData.getFishSchoolSize()!=grade) | ||
| 306 | +// { | ||
| 307 | +// OperatingData.cameraData.setFishSchoolSize(grade); | ||
| 308 | +// if(OperatingData.cameraConfig.getIfSendFishSchoolSize()) | ||
| 309 | +// { | ||
| 310 | +// int finalGrade = grade; | ||
| 311 | +// ScheduledConfig.scheduler.schedule(() -> { | ||
| 312 | +// | ||
| 313 | +// String nowtime = DateUtils.getTime(); | ||
| 314 | +// String[] ss = OperatingData.cameraConfig.getFishSchoolSizeConfigString(); | ||
| 315 | +// String fishSchoolSizeStr = ss[finalGrade]; | ||
| 316 | +// StringBuffer stringBuffer = new StringBuffer(); | ||
| 317 | +// stringBuffer.append(nowtime); | ||
| 318 | +// stringBuffer.append(" "); | ||
| 319 | +// stringBuffer.append(fishSchoolSizeStr); | ||
| 320 | +//// stringBuffer.append(",当前档位:"); | ||
| 321 | +//// stringBuffer.append(null==OperatingData.cameraData.getNowGear()?0:OperatingData.cameraData.getNowGear()); | ||
| 322 | +//// stringBuffer.append("档"); | ||
| 323 | +// InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); | ||
| 324 | +// | ||
| 325 | +// },0, TimeUnit.SECONDS); | ||
| 326 | +// } | ||
| 327 | +// } | ||
| 328 | +// | ||
| 329 | +// logger.info("当前画面的亮度:{},当前画面的反光:{},当前画面的透明度:{},当前画面的平均面积:{},鱼群规模:{},鱼群数量:{}",brightness,reflection,transparencyMeasure,area,fishSchoolSize, OperatingData.cameraData.getSize()); | ||
| 330 | +// | ||
| 331 | +// } | ||
| 295 | } | 332 | } |
| 296 | } | 333 | } |
| 297 | 334 |
| @@ -17,6 +17,8 @@ public class InitService { | @@ -17,6 +17,8 @@ public class InitService { | ||
| 17 | 17 | ||
| 18 | public static DateListenService dateListenService; | 18 | public static DateListenService dateListenService; |
| 19 | 19 | ||
| 20 | + public static MqttService mqttService; | ||
| 21 | + | ||
| 20 | public static FishGroupImageRecognitionService fishGroupImageRecognitionService; | 22 | public static FishGroupImageRecognitionService fishGroupImageRecognitionService; |
| 21 | /** | 23 | /** |
| 22 | * 加载配置 | 24 | * 加载配置 |
| @@ -57,6 +59,10 @@ public class InitService { | @@ -57,6 +59,10 @@ public class InitService { | ||
| 57 | //数据上报 | 59 | //数据上报 |
| 58 | dateListenService = new DateListenService(serialPortService); | 60 | dateListenService = new DateListenService(serialPortService); |
| 59 | dateListenService.run(); | 61 | dateListenService.run(); |
| 62 | + | ||
| 63 | + //数据上报 | ||
| 64 | + mqttService = new MqttService(); | ||
| 65 | + mqttService.start(); | ||
| 60 | } | 66 | } |
| 61 | 67 | ||
| 62 | } | 68 | } |
lh-modules/lh-smart-feeder/src/main/java/com/zhonglai/luhui/smart/feeder/service/MqttService.java
0 → 100644
| 1 | +package com.zhonglai.luhui.smart.feeder.service; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.bean.BeanUtil; | ||
| 4 | +import com.alibaba.fastjson.JSON; | ||
| 5 | +import com.google.gson.JsonObject; | ||
| 6 | +import com.ruoyi.common.utils.ByteUtil; | ||
| 7 | +import com.ruoyi.common.utils.DateUtils; | ||
| 8 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 9 | +import com.zhonglai.luhui.smart.feeder.config.OperatingData; | ||
| 10 | +import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | ||
| 11 | +import com.zhonglai.luhui.smart.feeder.dto.CameraData; | ||
| 12 | +import org.eclipse.paho.client.mqttv3.*; | ||
| 13 | +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; | ||
| 14 | +import org.slf4j.Logger; | ||
| 15 | +import org.slf4j.LoggerFactory; | ||
| 16 | + | ||
| 17 | +import java.io.IOException; | ||
| 18 | +import java.util.Date; | ||
| 19 | +import java.util.Map; | ||
| 20 | +import java.util.concurrent.ScheduledFuture; | ||
| 21 | +import java.util.concurrent.TimeUnit; | ||
| 22 | + | ||
| 23 | +import static com.zhonglai.luhui.smart.feeder.service.InitService.mqttService; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +public class MqttService { | ||
| 27 | + private static final Logger log = LoggerFactory.getLogger(MqttService.class); | ||
| 28 | + private MqttClient mqttclient ; | ||
| 29 | + private MqttConnectOptions options; | ||
| 30 | + | ||
| 31 | + private String username="12_ZY_AI"; | ||
| 32 | + private String password="Luhui586"; | ||
| 33 | + | ||
| 34 | + private Long endTime=0l; | ||
| 35 | + | ||
| 36 | + private Long interval = 1000l; | ||
| 37 | + | ||
| 38 | + private boolean isRun = false ; | ||
| 39 | + | ||
| 40 | + private String imgtopic = "/2/"+username+"/IMG_POST/"+OperatingData.sysConfig.getNettyConfig().getClientId(); | ||
| 41 | + private String datatopic = "/2/"+username+"/ALL_POST/"+OperatingData.sysConfig.getNettyConfig().getClientId(); | ||
| 42 | + | ||
| 43 | + | ||
| 44 | + public void stop() | ||
| 45 | + { | ||
| 46 | + try { | ||
| 47 | + if(null != mqttclient) | ||
| 48 | + { | ||
| 49 | + mqttclient.close(); | ||
| 50 | + } | ||
| 51 | + } catch (MqttException e) { | ||
| 52 | + log.error("关闭失败",e); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public void start() | ||
| 57 | + { | ||
| 58 | + if(null == mqttclient) | ||
| 59 | + { | ||
| 60 | + init(); | ||
| 61 | + } | ||
| 62 | + try { | ||
| 63 | + connect(); | ||
| 64 | + } catch (MqttException e) { | ||
| 65 | + throw new RuntimeException(e); | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + private void init() | ||
| 70 | + { | ||
| 71 | + try { | ||
| 72 | + mqttclient = new MqttClient("tcp://47.112.163.61:1883", OperatingData.sysConfig.getNettyConfig().getClientId(),new MemoryPersistence()); | ||
| 73 | + options = new MqttConnectOptions(); | ||
| 74 | + options.setCleanSession(true); | ||
| 75 | + options.setConnectionTimeout(15); | ||
| 76 | + //设置断开后重新连接 | ||
| 77 | + options.setAutomaticReconnect(true); | ||
| 78 | + mqttclient.setCallback(new MqttCallbackExtended() { | ||
| 79 | + | ||
| 80 | + @Override | ||
| 81 | + public void connectComplete(boolean b, String s) { | ||
| 82 | + log.info("连接成功"); | ||
| 83 | + try { | ||
| 84 | + subscribe(); | ||
| 85 | + } catch (MqttException e) { | ||
| 86 | + throw new RuntimeException(e); | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public void connectionLost(Throwable cause) { | ||
| 92 | + log.error("连接丢失",cause); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @Override | ||
| 96 | + public void messageArrived(String topic, MqttMessage message) throws Exception { | ||
| 97 | + //接收到消息 | ||
| 98 | + StringBuffer buffer = new StringBuffer(); | ||
| 99 | + buffer.append("topic:"); | ||
| 100 | + buffer.append(topic); | ||
| 101 | + buffer.append("\r\n"); | ||
| 102 | + buffer.append("mqttMessage字符串:"); | ||
| 103 | + buffer.append(message.toString()); | ||
| 104 | + buffer.append("\r\n"); | ||
| 105 | + buffer.append("mqttMessage十六进制:"); | ||
| 106 | + buffer.append(ByteUtil.hexStringToSpace(ByteUtil.toHexString(message.getPayload()))); | ||
| 107 | + buffer.append("\r\n"); | ||
| 108 | + buffer.append("\r\n"); | ||
| 109 | + | ||
| 110 | + log.info(buffer.toString()); | ||
| 111 | + | ||
| 112 | + String str = new String(message.getPayload()); | ||
| 113 | + JsonObject jsonObject = GsonConstructor.get().fromJson(str, JsonObject.class); | ||
| 114 | + if(null != jsonObject && jsonObject.size() !=0) | ||
| 115 | + { | ||
| 116 | + for (String key:jsonObject.keySet()) | ||
| 117 | + { | ||
| 118 | + switch (key) | ||
| 119 | + { | ||
| 120 | + case "pulldata": | ||
| 121 | + JsonObject pulldata = jsonObject.get("pulldata").getAsJsonObject(); | ||
| 122 | + Long pullTime = pulldata.get("pullTime").getAsLong(); | ||
| 123 | + Long intervalTime = pulldata.get("intervalTime").getAsLong(); | ||
| 124 | + pulldata(pullTime,intervalTime); | ||
| 125 | + break; | ||
| 126 | + case "restartService": | ||
| 127 | + if(jsonObject.get("restartService").getAsInt()==1) | ||
| 128 | + { | ||
| 129 | + try { | ||
| 130 | + String shutdownCommand; | ||
| 131 | + String operatingSystem = System.getProperty("os.name"); | ||
| 132 | + | ||
| 133 | + if (operatingSystem.contains("Windows")) { | ||
| 134 | + shutdownCommand = "shutdown.exe -r -t 0"; | ||
| 135 | + } else { | ||
| 136 | + shutdownCommand = "sudo shutdown -r now"; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + Runtime.getRuntime().exec(shutdownCommand); | ||
| 140 | + } catch (IOException e) { | ||
| 141 | + e.printStackTrace(); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + break; | ||
| 145 | + default: | ||
| 146 | + break; | ||
| 147 | + } | ||
| 148 | + } | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 153 | + public void deliveryComplete(IMqttDeliveryToken token) { | ||
| 154 | + log.info("成功发出消息 token {}",token.getTopics()); | ||
| 155 | + } | ||
| 156 | + }); | ||
| 157 | + } catch (MqttException e) { | ||
| 158 | + throw new RuntimeException(e); | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + private void connect() throws MqttException { | ||
| 163 | + options.setUserName(username); | ||
| 164 | + options.setPassword(password.toCharArray()); | ||
| 165 | + mqttclient.connect(options); | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + | ||
| 169 | + private void subscribe() throws MqttException { | ||
| 170 | + mqttclient.subscribe(new String[]{"/2/"+username+"/PUT/"+OperatingData.sysConfig.getNettyConfig().getClientId()}); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + public void publish(String topic, MqttMessage message) throws MqttException { | ||
| 174 | + mqttclient.publish(topic,message); | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + public void pullimg(byte[] byteArray) | ||
| 178 | + { | ||
| 179 | + MqttMessage message = new MqttMessage(); | ||
| 180 | + message.setPayload(byteArray); | ||
| 181 | + try { | ||
| 182 | + mqttService.publish(imgtopic,message); | ||
| 183 | + } catch (MqttException e) { | ||
| 184 | + log.error("图片发送异常",e); | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + public void pulldata(Long pullTime,Long intervalTime) | ||
| 189 | + { | ||
| 190 | + if(intervalTime<1000l) | ||
| 191 | + { | ||
| 192 | + return; | ||
| 193 | + } | ||
| 194 | + endTime = System.currentTimeMillis()+pullTime; | ||
| 195 | + interval = intervalTime; | ||
| 196 | + if(isRun) | ||
| 197 | + { | ||
| 198 | + return; | ||
| 199 | + } | ||
| 200 | + MqttMessage mqttMessage = new MqttMessage(); | ||
| 201 | + ScheduledConfig.scheduler.schedule(() -> { | ||
| 202 | + isRun = true; | ||
| 203 | + while (endTime- System.currentTimeMillis()>0) | ||
| 204 | + { | ||
| 205 | + try { | ||
| 206 | + Map<String,Object> map = BeanUtil.beanToMap(OperatingData.cameraData, "brightness","reflection","transparencyMeasure","area","size","fishSchoolSize" | ||
| 207 | + ,"scaleAreaSum" ,"scaleAreaSumMax","scaleAreaSumPercentage"); | ||
| 208 | + map.put("update_time",DateUtils.parseDateToStr("HH:mm:ss",new Date())); | ||
| 209 | + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); | ||
| 210 | + publish(datatopic,mqttMessage); | ||
| 211 | + } catch (Exception e) { | ||
| 212 | + log.error("数据推送异常",e); | ||
| 213 | + }finally { | ||
| 214 | + try { | ||
| 215 | + Thread.sleep(interval); | ||
| 216 | + } catch (InterruptedException e) { | ||
| 217 | + throw new RuntimeException(e); | ||
| 218 | + } | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + isRun = false; | ||
| 222 | + },0,TimeUnit.SECONDS); | ||
| 223 | + } | ||
| 224 | +} |
| @@ -8,6 +8,7 @@ import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService; | @@ -8,6 +8,7 @@ import com.zhonglai.luhui.smart.feeder.service.device.SerialPortService; | ||
| 8 | import com.zhonglai.luhui.smart.feeder.util.FeederCommd06ResponseType; | 8 | import com.zhonglai.luhui.smart.feeder.util.FeederCommd06ResponseType; |
| 9 | import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; | 9 | import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; |
| 10 | 10 | ||
| 11 | +import java.util.Date; | ||
| 11 | import java.util.concurrent.ScheduledFuture; | 12 | import java.util.concurrent.ScheduledFuture; |
| 12 | import java.util.concurrent.TimeUnit; | 13 | import java.util.concurrent.TimeUnit; |
| 13 | 14 | ||
| @@ -15,6 +16,7 @@ import java.util.concurrent.TimeUnit; | @@ -15,6 +16,7 @@ import java.util.concurrent.TimeUnit; | ||
| 15 | * 尺度步长法 | 16 | * 尺度步长法 |
| 16 | */ | 17 | */ |
| 17 | public class ScaleStepMethodService { | 18 | public class ScaleStepMethodService { |
| 19 | + private Integer logTady = Integer.parseInt(DateUtils.parseDateToStr("yyyyMMdd",new Date())); | ||
| 18 | private ScheduledFuture scheduledFuture; | 20 | private ScheduledFuture scheduledFuture; |
| 19 | 21 | ||
| 20 | private SerialPortService serialPortService; | 22 | private SerialPortService serialPortService; |
| @@ -27,6 +29,7 @@ public class ScaleStepMethodService { | @@ -27,6 +29,7 @@ public class ScaleStepMethodService { | ||
| 27 | public void run() | 29 | public void run() |
| 28 | { | 30 | { |
| 29 | scheduledFuture = ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { | 31 | scheduledFuture = ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { |
| 32 | + Integer nowTady = Integer.parseInt(DateUtils.parseDateToStr("yyyyMMdd",new Date())); | ||
| 30 | if( OperatingData.cameraData.getScaleAreaList().size()==0) | 33 | if( OperatingData.cameraData.getScaleAreaList().size()==0) |
| 31 | { | 34 | { |
| 32 | return; | 35 | return; |
| @@ -40,6 +43,12 @@ public class ScaleStepMethodService { | @@ -40,6 +43,12 @@ public class ScaleStepMethodService { | ||
| 40 | OperatingData.cameraData.setScaleAreaSumMax(sum); | 43 | OperatingData.cameraData.setScaleAreaSumMax(sum); |
| 41 | } | 44 | } |
| 42 | 45 | ||
| 46 | + if(nowTady-logTady!=0) | ||
| 47 | + { | ||
| 48 | + OperatingData.cameraData.setScaleAreaSumMax(sum); | ||
| 49 | + logTady = nowTady; | ||
| 50 | + } | ||
| 51 | + | ||
| 43 | String nowtime = DateUtils.getTime(); | 52 | String nowtime = DateUtils.getTime(); |
| 44 | StringBuffer stringBuffer = new StringBuffer(); | 53 | StringBuffer stringBuffer = new StringBuffer(); |
| 45 | stringBuffer.append(nowtime); | 54 | stringBuffer.append(nowtime); |
| @@ -47,8 +56,7 @@ public class ScaleStepMethodService { | @@ -47,8 +56,7 @@ public class ScaleStepMethodService { | ||
| 47 | 56 | ||
| 48 | //如果鱼群急剧减少,就停止投料 | 57 | //如果鱼群急剧减少,就停止投料 |
| 49 | Integer scaleAreaSumPercentage = new Double((sum/OperatingData.cameraData.getScaleAreaSumMax())*100).intValue(); | 58 | Integer scaleAreaSumPercentage = new Double((sum/OperatingData.cameraData.getScaleAreaSumMax())*100).intValue(); |
| 50 | - OperatingData.cameraData.setScaleAreaSumPercentage(scaleAreaSumPercentage); | ||
| 51 | - if (scaleAreaSumPercentage-OperatingData.cameraConfig.getStopTriggeringConditions()<=0) | 59 | + if (100-scaleAreaSumPercentage!=0 && OperatingData.cameraData.getScaleAreaSumPercentage()-OperatingData.cameraConfig.getStopTriggeringConditions()>0 && scaleAreaSumPercentage-OperatingData.cameraConfig.getStopTriggeringConditions()<=0) |
| 52 | { | 60 | { |
| 53 | Condata condata = OperatingData.feederConfig.getCondata(); | 61 | Condata condata = OperatingData.feederConfig.getCondata(); |
| 54 | 62 | ||
| @@ -63,8 +71,20 @@ public class ScaleStepMethodService { | @@ -63,8 +71,20 @@ public class ScaleStepMethodService { | ||
| 63 | //发送停止投料指令 | 71 | //发送停止投料指令 |
| 64 | if (serialPortService.isOpen()) | 72 | if (serialPortService.isOpen()) |
| 65 | { | 73 | { |
| 74 | + if(OperatingData.feederConfig.getCondata().getRunmode()==1) | ||
| 75 | + { | ||
| 76 | + InitService.serialPortService.sendHexData(FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,0)); //通知串口 | ||
| 77 | + OperatingData.feederConfig.getCondata().setRunmode(0); | ||
| 78 | + } | ||
| 66 | serialPortService.sendHexData(FeederCommdUtil.controlData(FeederCommd06ResponseType.runstate,0)); | 79 | serialPortService.sendHexData(FeederCommdUtil.controlData(FeederCommd06ResponseType.runstate,0)); |
| 67 | stringBuffer.append("发送停止投料指令,"); | 80 | stringBuffer.append("发送停止投料指令,"); |
| 81 | + InitService.serialPortService.sendHexData(FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,1)); //通知串口 | ||
| 82 | + OperatingData.feederConfig.getCondata().setRunmode(1); | ||
| 83 | + try { | ||
| 84 | + Thread.sleep(2000); | ||
| 85 | + } catch (InterruptedException e) { | ||
| 86 | + throw new RuntimeException(e); | ||
| 87 | + } | ||
| 68 | }else{ | 88 | }else{ |
| 69 | stringBuffer.append("投料机串口未打开,无法发送停止投料指令,"); | 89 | stringBuffer.append("投料机串口未打开,无法发送停止投料指令,"); |
| 70 | } | 90 | } |
| @@ -89,7 +109,7 @@ public class ScaleStepMethodService { | @@ -89,7 +109,7 @@ public class ScaleStepMethodService { | ||
| 89 | } | 109 | } |
| 90 | 110 | ||
| 91 | //如果鱼群急剧增加,。。。 | 111 | //如果鱼群急剧增加,。。。 |
| 92 | - if (100-OperatingData.cameraConfig.getStopTriggeringConditions()-scaleAreaSumPercentage<=0) | 112 | + if (100-scaleAreaSumPercentage!=0 && OperatingData.cameraData.getScaleAreaSumPercentage()-(100-OperatingData.cameraConfig.getStopTriggeringConditions())<0 && scaleAreaSumPercentage-(100-OperatingData.cameraConfig.getStopTriggeringConditions())>=0) |
| 93 | { | 113 | { |
| 94 | stringBuffer.append("发现鱼群急剧增加,"); | 114 | stringBuffer.append("发现鱼群急剧增加,"); |
| 95 | 115 | ||
| @@ -100,8 +120,10 @@ public class ScaleStepMethodService { | @@ -100,8 +120,10 @@ public class ScaleStepMethodService { | ||
| 100 | stringBuffer.append(OperatingData.cameraData.getScaleAreaSumMax()); | 120 | stringBuffer.append(OperatingData.cameraData.getScaleAreaSumMax()); |
| 101 | InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); | 121 | InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); |
| 102 | } | 122 | } |
| 123 | + System.out.println("尺度之内的面积之和:"+sum+";尺度之内的面积之和曲线的峰值:"+OperatingData.cameraData.getScaleAreaSumMax()+";尺度之内的面积之和占比:"+scaleAreaSumPercentage+";上一个尺度之内的面积之和占比:"+OperatingData.cameraData.getScaleAreaSumPercentage()); | ||
| 124 | + | ||
| 125 | + OperatingData.cameraData.setScaleAreaSumPercentage(scaleAreaSumPercentage); | ||
| 103 | 126 | ||
| 104 | - System.out.println("尺度之内的面积之和:"+sum+";尺度之内的面积之和曲线的峰值:"+OperatingData.cameraData.getScaleAreaSumMax()+";尺度之内的面积之和占比:"+scaleAreaSumPercentage); | ||
| 105 | },0, OperatingData.cameraConfig.getScaleStep(), TimeUnit.SECONDS); | 127 | },0, OperatingData.cameraConfig.getScaleStep(), TimeUnit.SECONDS); |
| 106 | } | 128 | } |
| 107 | 129 |
| @@ -3,6 +3,7 @@ package com.zhonglai.luhui.smart.feeder.service; | @@ -3,6 +3,7 @@ package com.zhonglai.luhui.smart.feeder.service; | ||
| 3 | import com.ruoyi.common.utils.DateUtils; | 3 | import com.ruoyi.common.utils.DateUtils; |
| 4 | import com.zhonglai.luhui.smart.feeder.config.OpenCVConfig; | 4 | import com.zhonglai.luhui.smart.feeder.config.OpenCVConfig; |
| 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.config.ScheduledConfig; | ||
| 6 | import com.zhonglai.luhui.smart.feeder.draw.FishRegionPanel; | 7 | import com.zhonglai.luhui.smart.feeder.draw.FishRegionPanel; |
| 7 | import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; | 8 | import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; |
| 8 | import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil; | 9 | import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil; |
| 1 | package com.zhonglai.luhui.smart.feeder.service.device; | 1 | package com.zhonglai.luhui.smart.feeder.service.device; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import cn.hutool.core.bean.BeanUtil; | ||
| 5 | +import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import com.fazecast.jSerialComm.SerialPort; | 6 | import com.fazecast.jSerialComm.SerialPort; |
| 5 | import com.fazecast.jSerialComm.SerialPortDataListener; | 7 | import com.fazecast.jSerialComm.SerialPortDataListener; |
| 6 | import com.fazecast.jSerialComm.SerialPortEvent; | 8 | import com.fazecast.jSerialComm.SerialPortEvent; |
| 7 | import com.ruoyi.common.utils.ByteUtil; | 9 | import com.ruoyi.common.utils.ByteUtil; |
| 8 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 10 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; |
| 11 | +import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | ||
| 9 | import com.zhonglai.luhui.smart.feeder.dto.ModbusDto; | 12 | import com.zhonglai.luhui.smart.feeder.dto.ModbusDto; |
| 10 | import com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig; | 13 | import com.zhonglai.luhui.smart.feeder.dto.SerialPortConfig; |
| 11 | import com.zhonglai.luhui.smart.feeder.dto.commd.FeederCommdDto; | 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; | ||
| 12 | import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | 18 | import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; |
| 13 | import com.zhonglai.luhui.smart.feeder.service.InitService; | 19 | import com.zhonglai.luhui.smart.feeder.service.InitService; |
| 20 | +import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; | ||
| 14 | import org.slf4j.Logger; | 21 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 22 | import org.slf4j.LoggerFactory; |
| 16 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -19,6 +26,7 @@ import org.springframework.stereotype.Service; | @@ -19,6 +26,7 @@ import org.springframework.stereotype.Service; | ||
| 19 | import java.io.IOException; | 26 | import java.io.IOException; |
| 20 | import java.io.InputStream; | 27 | import java.io.InputStream; |
| 21 | import java.nio.charset.StandardCharsets; | 28 | import java.nio.charset.StandardCharsets; |
| 29 | +import java.util.Map; | ||
| 22 | import java.util.concurrent.BlockingQueue; | 30 | import java.util.concurrent.BlockingQueue; |
| 23 | import java.util.concurrent.LinkedBlockingQueue; | 31 | import java.util.concurrent.LinkedBlockingQueue; |
| 24 | import java.util.concurrent.TimeUnit; | 32 | import java.util.concurrent.TimeUnit; |
| @@ -32,9 +40,24 @@ public class SerialPortService { | @@ -32,9 +40,24 @@ public class SerialPortService { | ||
| 32 | // 用于存储串口返回的数据,使用线程安全的队列 | 40 | // 用于存储串口返回的数据,使用线程安全的队列 |
| 33 | private BlockingQueue<ModbusDto> dataQueue = new LinkedBlockingQueue<>(); | 41 | private BlockingQueue<ModbusDto> dataQueue = new LinkedBlockingQueue<>(); |
| 34 | 42 | ||
| 43 | + private AnalysisDataService analysisDataService = new AnalysisDataService(); | ||
| 44 | + | ||
| 45 | + | ||
| 35 | public SerialPortService() | 46 | public SerialPortService() |
| 36 | { | 47 | { |
| 37 | open(); | 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 | + Info info = BeanUtil.mapToBean(data, Info.class,false,null); | ||
| 55 | + if(ObjectUtil.notEqual(OperatingData.feederConfig.getCondata(),condata)) | ||
| 56 | + { | ||
| 57 | + OperatingData.feederConfig.setCondata(condata); | ||
| 58 | + } | ||
| 59 | + OperatingData.feederData.setInfo(info); | ||
| 60 | + } | ||
| 38 | } | 61 | } |
| 39 | 62 | ||
| 40 | private SerialPort findSerialPort() | 63 | private SerialPort findSerialPort() |
| @@ -96,6 +96,16 @@ public class CameraRtspHandle implements CameraHandle { | @@ -96,6 +96,16 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 96 | 96 | ||
| 97 | Thread thread1 = new Thread(() -> init()); | 97 | Thread thread1 = new Thread(() -> init()); |
| 98 | thread1.start(); | 98 | thread1.start(); |
| 99 | + | ||
| 100 | + while (true) | ||
| 101 | + { | ||
| 102 | + if(isOpen()) | ||
| 103 | + { | ||
| 104 | + InitService.fishGroupImageRecognitionService.run(); | ||
| 105 | + break; | ||
| 106 | + } | ||
| 107 | + Thread.sleep(1000); | ||
| 108 | + } | ||
| 99 | } | 109 | } |
| 100 | } catch (Exception e) { | 110 | } catch (Exception e) { |
| 101 | logger.error("抓取摄像头帧失败",e); | 111 | logger.error("抓取摄像头帧失败",e); |
| @@ -199,6 +209,7 @@ public class CameraRtspHandle implements CameraHandle { | @@ -199,6 +209,7 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 199 | return converter2.convert(frame); | 209 | return converter2.convert(frame); |
| 200 | } | 210 | } |
| 201 | 211 | ||
| 212 | + | ||
| 202 | public Frame toFram(Mat mat) { | 213 | public Frame toFram(Mat mat) { |
| 203 | if(null == mat) | 214 | if(null == mat) |
| 204 | { | 215 | { |
| @@ -236,6 +247,17 @@ public class CameraRtspHandle implements CameraHandle { | @@ -236,6 +247,17 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 236 | return null; | 247 | return null; |
| 237 | } | 248 | } |
| 238 | 249 | ||
| 250 | + public Mat compress(Mat mat) | ||
| 251 | + { | ||
| 252 | + Frame frame = toFram(mat); | ||
| 253 | + if(null != frame) | ||
| 254 | + { | ||
| 255 | + frame = compress(frame); | ||
| 256 | + return converter2.convertToOrgOpenCvCoreMat(frame); | ||
| 257 | + } | ||
| 258 | + return null; | ||
| 259 | + } | ||
| 260 | + | ||
| 239 | public Frame compress(Frame frame) | 261 | public Frame compress(Frame frame) |
| 240 | { | 262 | { |
| 241 | try { | 263 | try { |
| @@ -44,8 +44,16 @@ public class CfgdataService { | @@ -44,8 +44,16 @@ public class CfgdataService { | ||
| 44 | } | 44 | } |
| 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(); | ||
| 48 | + if(OperatingData.feederConfig.getCondata().getRunmode()==1) | ||
| 49 | + { | ||
| 50 | + String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,0); | ||
| 51 | + logger.info("自动模式切换成手动模式"); | ||
| 52 | + InitService.serialPortService.sendHexData(commd); //通知串口 | ||
| 53 | + OperatingData.feederConfig.getCondata().setRunmode(0); | ||
| 54 | + } | ||
| 47 | FeederConfig feederConfig = new FeederConfig(); | 55 | FeederConfig feederConfig = new FeederConfig(); |
| 48 | - feederConfig.setCondata(cfgdataRequest.getCondata()); | 56 | + feederConfig.setCondata(condata); |
| 49 | OperatingData.setClassObjecValue(feederConfig, (fieldname, fieldObject) -> { | 57 | OperatingData.setClassObjecValue(feederConfig, (fieldname, fieldObject) -> { |
| 50 | try { | 58 | try { |
| 51 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); | 59 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); |
| @@ -59,9 +67,8 @@ public class CfgdataService { | @@ -59,9 +67,8 @@ public class CfgdataService { | ||
| 59 | } | 67 | } |
| 60 | }); | 68 | }); |
| 61 | 69 | ||
| 62 | - | ||
| 63 | List<Integer[]> timerList = cfgdataRequest.getTimer(); | 70 | List<Integer[]> timerList = cfgdataRequest.getTimer(); |
| 64 | - if(null != timerList && timerList.size() != 0 ) | 71 | + if(null != timerList) |
| 65 | { | 72 | { |
| 66 | ModbusDto modbusDto = InitService.serialPortService.sendHexData(FeederCommdUtil.controlTimer(timerList)); | 73 | ModbusDto modbusDto = InitService.serialPortService.sendHexData(FeederCommdUtil.controlTimer(timerList)); |
| 67 | if(0x10==modbusDto.getCommdcode()) | 74 | if(0x10==modbusDto.getCommdcode()) |
| @@ -69,6 +76,11 @@ public class CfgdataService { | @@ -69,6 +76,11 @@ public class CfgdataService { | ||
| 69 | OperatingData.feederConfig.setTimer(timerList); | 76 | OperatingData.feederConfig.setTimer(timerList); |
| 70 | } | 77 | } |
| 71 | 78 | ||
| 79 | + String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,1); | ||
| 80 | + logger.info("定时在自动上运行"); | ||
| 81 | + InitService.serialPortService.sendHexData(commd); //通知串口 | ||
| 82 | + OperatingData.feederConfig.getCondata().setRunmode(1); | ||
| 83 | + Thread.sleep(2000); | ||
| 72 | } | 84 | } |
| 73 | MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0); | 85 | MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0); |
| 74 | }catch (Exception e) | 86 | }catch (Exception e) |
| @@ -78,4 +90,9 @@ public class CfgdataService { | @@ -78,4 +90,9 @@ public class CfgdataService { | ||
| 78 | 90 | ||
| 79 | } | 91 | } |
| 80 | 92 | ||
| 93 | + public static void main(String[] args) { | ||
| 94 | + String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,0); | ||
| 95 | + System.out.println(commd); | ||
| 96 | + } | ||
| 97 | + | ||
| 81 | } | 98 | } |
| @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; | ||
| 4 | import com.ruoyi.common.utils.GsonConstructor; | 4 | import com.ruoyi.common.utils.GsonConstructor; |
| 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.FeederConfig; | 6 | import com.zhonglai.luhui.smart.feeder.dto.FeederConfig; |
| 7 | +import com.zhonglai.luhui.smart.feeder.dto.ModbusDto; | ||
| 7 | import com.zhonglai.luhui.smart.feeder.dto.commd.FeederBackstateTtpe; | 8 | import com.zhonglai.luhui.smart.feeder.dto.commd.FeederBackstateTtpe; |
| 8 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CfgdataRequest; | 9 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CfgdataRequest; |
| 9 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; | 10 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; |
| @@ -38,8 +39,16 @@ public class ManualcontrolService { | @@ -38,8 +39,16 @@ public class ManualcontrolService { | ||
| 38 | } | 39 | } |
| 39 | try { | 40 | try { |
| 40 | ManualcontrolRequest manualcontrolRequest = GsonConstructor.get().fromJson(data.toString(), ManualcontrolRequest.class); | 41 | ManualcontrolRequest manualcontrolRequest = GsonConstructor.get().fromJson(data.toString(), ManualcontrolRequest.class); |
| 42 | + Condata condata = manualcontrolRequest.getCondata(); | ||
| 43 | + if( OperatingData.feederConfig.getCondata().getRunmode()==1) | ||
| 44 | + { | ||
| 45 | + String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.runmode,0); | ||
| 46 | + logger.info("自动模式切换成手动模式"); | ||
| 47 | + InitService.serialPortService.sendHexData(commd); //通知串口 | ||
| 48 | + OperatingData.feederConfig.getCondata().setRunmode(0); | ||
| 49 | + } | ||
| 41 | FeederConfig feederConfig = new FeederConfig(); | 50 | FeederConfig feederConfig = new FeederConfig(); |
| 42 | - feederConfig.setCondata(manualcontrolRequest.getCondata()); | 51 | + feederConfig.setCondata(condata); |
| 43 | OperatingData.setClassObjecValue(feederConfig, (fieldname, fieldObject) -> { | 52 | OperatingData.setClassObjecValue(feederConfig, (fieldname, fieldObject) -> { |
| 44 | try { | 53 | try { |
| 45 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); | 54 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); |
| @@ -34,7 +34,20 @@ public class NettyClient { | @@ -34,7 +34,20 @@ public class NettyClient { | ||
| 34 | close(); | 34 | close(); |
| 35 | start(); | 35 | start(); |
| 36 | } | 36 | } |
| 37 | - },1,1,TimeUnit.SECONDS); | 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 | + | ||
| 38 | } | 51 | } |
| 39 | 52 | ||
| 40 | private void start() { | 53 | private void start() { |
| @@ -6,6 +6,7 @@ import com.ruoyi.common.utils.ByteUtil; | @@ -6,6 +6,7 @@ import com.ruoyi.common.utils.ByteUtil; | ||
| 6 | import com.zhonglai.luhui.smart.feeder.dto.commd.*; | 6 | import com.zhonglai.luhui.smart.feeder.dto.commd.*; |
| 7 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CfgdataRequest; | 7 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CfgdataRequest; |
| 8 | 8 | ||
| 9 | +import java.util.ArrayList; | ||
| 9 | import java.util.List; | 10 | import java.util.List; |
| 10 | 11 | ||
| 11 | public class FeederCommdUtil { | 12 | public class FeederCommdUtil { |
| @@ -20,9 +21,6 @@ public class FeederCommdUtil { | @@ -20,9 +21,6 @@ public class FeederCommdUtil { | ||
| 20 | return feederCommdDto.getHstr(); | 21 | return feederCommdDto.getHstr(); |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | - public static void main(String[] args) { | ||
| 24 | - System.out.println(readAll()); | ||
| 25 | - } | ||
| 26 | 24 | ||
| 27 | /** | 25 | /** |
| 28 | * 写运行模式 | 26 | * 写运行模式 |
| @@ -34,6 +32,16 @@ public class FeederCommdUtil { | @@ -34,6 +32,16 @@ public class FeederCommdUtil { | ||
| 34 | return feederCommdDto.getHstr(); | 32 | return feederCommdDto.getHstr(); |
| 35 | } | 33 | } |
| 36 | 34 | ||
| 35 | + /** | ||
| 36 | + * 读取模式 | ||
| 37 | + * @return | ||
| 38 | + */ | ||
| 39 | + public static String readMode() | ||
| 40 | + { | ||
| 41 | + FeederCommdDto feederCommdDto = new FeederCommdDto(new FeederCommd03Response(13,14)); | ||
| 42 | + return feederCommdDto.getHstr(); | ||
| 43 | + } | ||
| 44 | + | ||
| 37 | 45 | ||
| 38 | /** | 46 | /** |
| 39 | * 写定时器 | 47 | * 写定时器 |
| @@ -41,6 +49,13 @@ public class FeederCommdUtil { | @@ -41,6 +49,13 @@ public class FeederCommdUtil { | ||
| 41 | */ | 49 | */ |
| 42 | public static String controlTimer(List<Integer[]> timerList) | 50 | public static String controlTimer(List<Integer[]> timerList) |
| 43 | { | 51 | { |
| 52 | + if(timerList.size() == 0) //情况定时器 | ||
| 53 | + { | ||
| 54 | + for (int i=0;i<8;i++) | ||
| 55 | + { | ||
| 56 | + timerList.add(new Integer[]{0,0,0,0,0}); | ||
| 57 | + } | ||
| 58 | + } | ||
| 44 | byte[] data = null; | 59 | byte[] data = null; |
| 45 | for (int i=0;i<timerList.size();i++) | 60 | for (int i=0;i<timerList.size();i++) |
| 46 | { | 61 | { |
| @@ -49,11 +64,19 @@ public class FeederCommdUtil { | @@ -49,11 +64,19 @@ public class FeederCommdUtil { | ||
| 49 | feederTimer.setTimer_start_m(timerNumbers[1]); | 64 | feederTimer.setTimer_start_m(timerNumbers[1]); |
| 50 | feederTimer.setTimer_start_h(timerNumbers[0]); | 65 | feederTimer.setTimer_start_h(timerNumbers[0]); |
| 51 | feederTimer.setTimer_if_start(timerNumbers[4]); | 66 | feederTimer.setTimer_if_start(timerNumbers[4]); |
| 52 | - feederTimer.setTimer_is_start(1); | 67 | + |
| 53 | feederTimer.setTimer_close_m(timerNumbers[3]); | 68 | feederTimer.setTimer_close_m(timerNumbers[3]); |
| 54 | feederTimer.setTimer_close_h(timerNumbers[2]); | 69 | feederTimer.setTimer_close_h(timerNumbers[2]); |
| 55 | feederTimer.setTimer_if_close(timerNumbers[4]); | 70 | feederTimer.setTimer_if_close(timerNumbers[4]); |
| 71 | + | ||
| 72 | + if(timerNumbers[1]-timerNumbers[3]==0 && timerNumbers[0]-timerNumbers[2]==0) | ||
| 73 | + { | ||
| 74 | + feederTimer.setTimer_is_start(0); | ||
| 75 | + feederTimer.setTimer_is_close(0); | ||
| 76 | + }else{ | ||
| 77 | + feederTimer.setTimer_is_start(1); | ||
| 56 | feederTimer.setTimer_is_close(1); | 78 | feederTimer.setTimer_is_close(1); |
| 79 | + } | ||
| 57 | 80 | ||
| 58 | int i23 = 0; | 81 | int i23 = 0; |
| 59 | if(null != feederTimer.getTimer_start_m()) | 82 | if(null != feederTimer.getTimer_start_m()) |
-
请 注册 或 登录 后发表评论