正在显示
24 个修改的文件
包含
770 行增加
和
433 行删除
| @@ -18,8 +18,8 @@ public class OperatingData { | @@ -18,8 +18,8 @@ public class OperatingData { | ||
| 18 | public static SysConfig sysConfig = new SysConfig(); //系统配置 | 18 | public static SysConfig sysConfig = new SysConfig(); //系统配置 |
| 19 | public static CameraData cameraData = new CameraData(); //摄像头数据 | 19 | public static CameraData cameraData = new CameraData(); //摄像头数据 |
| 20 | public static CameraConfig cameraConfig = new CameraConfig() ; //摄像头配置 | 20 | public static CameraConfig cameraConfig = new CameraConfig() ; //摄像头配置 |
| 21 | - public static DevicedatRequest devicedat = new DevicedatRequest() ; //投料机数据 | ||
| 22 | public static FeederConfig feederConfig = new FeederConfig() ; //投料机配置 | 21 | public static FeederConfig feederConfig = new FeederConfig() ; //投料机配置 |
| 22 | + public static FeederData feederData = new FeederData() ; //投料机配置 | ||
| 23 | public static RegisterConfig registerConfig = new RegisterConfig(); //数据解析字典 | 23 | public static RegisterConfig registerConfig = new RegisterConfig(); //数据解析字典 |
| 24 | 24 | ||
| 25 | public static void setClassObjecValue(Object value,IfOperatingDataValueIsNotNull ifOperatingDataValueIsNotNull) throws IllegalAccessException { | 25 | public static void setClassObjecValue(Object value,IfOperatingDataValueIsNotNull ifOperatingDataValueIsNotNull) throws IllegalAccessException { |
| @@ -39,6 +39,8 @@ public class OperatingData { | @@ -39,6 +39,8 @@ public class OperatingData { | ||
| 39 | ifOperatingDataValueIsNotNull.exeValue(field.getName(),object); | 39 | ifOperatingDataValueIsNotNull.exeValue(field.getName(),object); |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | + | ||
| 43 | + operatingDataType.upFile(); | ||
| 42 | } | 44 | } |
| 43 | } | 45 | } |
| 44 | 46 |
| 1 | package com.zhonglai.luhui.smart.feeder.dto; | 1 | package com.zhonglai.luhui.smart.feeder.dto; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.io.FileUtil; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | ||
| 3 | import lombok.Data; | 6 | import lombok.Data; |
| 4 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
| 5 | 8 | ||
| 9 | +import java.io.File; | ||
| 6 | import java.lang.reflect.Field; | 10 | import java.lang.reflect.Field; |
| 7 | import java.util.ArrayList; | 11 | import java.util.ArrayList; |
| 8 | 12 | ||
| @@ -117,6 +121,29 @@ public class CameraConfig implements OperatingDataType{ | @@ -117,6 +121,29 @@ public class CameraConfig implements OperatingDataType{ | ||
| 117 | */ | 121 | */ |
| 118 | private Boolean feedingControl; | 122 | private Boolean feedingControl; |
| 119 | 123 | ||
| 124 | + /** | ||
| 125 | + * 鱼群规模配置,从小到大:鱼群未聚集,鱼群小量聚集,鱼群中量聚集,鱼群大量聚集 | ||
| 126 | + */ | ||
| 127 | + private Double[] fishSchoolSizeConfig; | ||
| 128 | + | ||
| 129 | + /** | ||
| 130 | + * 鱼群规模配置,从小到大:鱼群未聚集,鱼群小量聚集,鱼群中量聚集,鱼群大量聚集 | ||
| 131 | + */ | ||
| 132 | + private String[] fishSchoolSizeConfigString; | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * 采集尺度(分钟) | ||
| 136 | + */ | ||
| 137 | + private Integer collectionScale; | ||
| 138 | + /** | ||
| 139 | + * 步长(秒,小于采集尺度) | ||
| 140 | + */ | ||
| 141 | + private Integer scaleStep; | ||
| 142 | + /** | ||
| 143 | + * 停止尺度之内的面积之和触发的条件(百分比) | ||
| 144 | + */ | ||
| 145 | + private Integer stopTriggeringConditions; | ||
| 146 | + | ||
| 120 | 147 | ||
| 121 | public CameraConfig creteDefault() | 148 | public CameraConfig creteDefault() |
| 122 | { | 149 | { |
| @@ -145,7 +172,11 @@ public class CameraConfig implements OperatingDataType{ | @@ -145,7 +172,11 @@ public class CameraConfig implements OperatingDataType{ | ||
| 145 | this.identificationFrequency = 1000l; | 172 | this.identificationFrequency = 1000l; |
| 146 | this.fishGroupImageRecognition = true; | 173 | this.fishGroupImageRecognition = true; |
| 147 | this.feedingControl = true; | 174 | this.feedingControl = true; |
| 148 | - | 175 | + this.fishSchoolSizeConfig = new Double[]{200.0,1000.0,2000.0,3000.0}; |
| 176 | + this.fishSchoolSizeConfigString = new String[]{"鱼群未聚","鱼群小量聚集","鱼群中量聚集","鱼群大量聚集"}; | ||
| 177 | + this.collectionScale = 5; | ||
| 178 | + this.scaleStep = 60; | ||
| 179 | + this.stopTriggeringConditions = 30; | ||
| 149 | return this; | 180 | return this; |
| 150 | } | 181 | } |
| 151 | 182 | ||
| @@ -153,4 +184,10 @@ public class CameraConfig implements OperatingDataType{ | @@ -153,4 +184,10 @@ public class CameraConfig implements OperatingDataType{ | ||
| 153 | public void setValue(Field field, Object value) throws IllegalAccessException { | 184 | public void setValue(Field field, Object value) throws IllegalAccessException { |
| 154 | field.set(this,value); | 185 | field.set(this,value); |
| 155 | } | 186 | } |
| 187 | + | ||
| 188 | + @Override | ||
| 189 | + public void upFile() { | ||
| 190 | + File cameraConfigFile = new File("cameraConfig"); | ||
| 191 | + FileUtil.writeString(ConfigurationParameterService.gson.toJson(this),cameraConfigFile,"UTF-8"); | ||
| 192 | + } | ||
| 156 | } | 193 | } |
| @@ -3,6 +3,9 @@ package com.zhonglai.luhui.smart.feeder.dto; | @@ -3,6 +3,9 @@ package com.zhonglai.luhui.smart.feeder.dto; | ||
| 3 | import lombok.Data; | 3 | import lombok.Data; |
| 4 | import lombok.experimental.Accessors; | 4 | import lombok.experimental.Accessors; |
| 5 | 5 | ||
| 6 | +import java.util.ArrayList; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 6 | /** | 9 | /** |
| 7 | * 摄像头数据 | 10 | * 摄像头数据 |
| 8 | */ | 11 | */ |
| @@ -38,6 +41,11 @@ public class CameraData { | @@ -38,6 +41,11 @@ public class CameraData { | ||
| 38 | 41 | ||
| 39 | 42 | ||
| 40 | /** | 43 | /** |
| 44 | + * 鱼群数量 | ||
| 45 | + */ | ||
| 46 | + private Integer size; | ||
| 47 | + | ||
| 48 | + /** | ||
| 41 | * 当前斜率的差值 | 49 | * 当前斜率的差值 |
| 42 | */ | 50 | */ |
| 43 | private Double slopeDifference; | 51 | private Double slopeDifference; |
| @@ -74,4 +82,23 @@ public class CameraData { | @@ -74,4 +82,23 @@ public class CameraData { | ||
| 74 | */ | 82 | */ |
| 75 | private Boolean fishGroupImageRecognIsRun = false; | 83 | private Boolean fishGroupImageRecognIsRun = false; |
| 76 | 84 | ||
| 85 | + /** | ||
| 86 | + * 鱼群规模 | ||
| 87 | + */ | ||
| 88 | + private Integer fishSchoolSize = 0; | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 尺度之内的面积之和 | ||
| 92 | + */ | ||
| 93 | + private Double scaleAreaSum=0.0; | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 尺度之内的面积集合 | ||
| 97 | + */ | ||
| 98 | + private List<Double> scaleAreaList = new ArrayList<>(); | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 尺度之内的面积之和曲线的峰值 | ||
| 102 | + */ | ||
| 103 | + private Double scaleAreaSumMax = 0.0; | ||
| 77 | } | 104 | } |
| 1 | package com.zhonglai.luhui.smart.feeder.dto; | 1 | package com.zhonglai.luhui.smart.feeder.dto; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.io.FileUtil; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.smart.feeder.dto.mqtt.Condata; | ||
| 6 | +import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | ||
| 3 | import lombok.Data; | 7 | import lombok.Data; |
| 4 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 5 | 9 | ||
| 10 | +import java.io.File; | ||
| 6 | import java.lang.reflect.Field; | 11 | import java.lang.reflect.Field; |
| 12 | +import java.util.List; | ||
| 7 | 13 | ||
| 8 | @Data | 14 | @Data |
| 9 | @Accessors(chain = true) //链式写法 | 15 | @Accessors(chain = true) //链式写法 |
| 10 | public class FeederConfig implements OperatingDataType{ | 16 | public class FeederConfig implements OperatingDataType{ |
| 11 | private SerialPortConfig serialPortConfig; | 17 | private SerialPortConfig serialPortConfig; |
| 12 | 18 | ||
| 19 | + private Condata condata; | ||
| 20 | + | ||
| 21 | + private List<Integer[]> timer; //开启、关闭、使能 8:00开启-9:00关闭,状态:启用 | ||
| 22 | + | ||
| 13 | public FeederConfig creteDefault() | 23 | public FeederConfig creteDefault() |
| 14 | { | 24 | { |
| 15 | serialPortConfig = new SerialPortConfig().defaultSerialPortConfig(); | 25 | serialPortConfig = new SerialPortConfig().defaultSerialPortConfig(); |
| @@ -20,4 +30,10 @@ public class FeederConfig implements OperatingDataType{ | @@ -20,4 +30,10 @@ public class FeederConfig implements OperatingDataType{ | ||
| 20 | public void setValue(Field field, Object value) throws IllegalAccessException { | 30 | public void setValue(Field field, Object value) throws IllegalAccessException { |
| 21 | field.set(this,value); | 31 | field.set(this,value); |
| 22 | } | 32 | } |
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public void upFile() { | ||
| 36 | + File feederConfigFile = new File("feederConfig"); | ||
| 37 | + FileUtil.writeString(ConfigurationParameterService.gson.toJson(this),feederConfigFile,"UTF-8"); | ||
| 38 | + } | ||
| 23 | } | 39 | } |
| 1 | package com.zhonglai.luhui.smart.feeder.dto; | 1 | package com.zhonglai.luhui.smart.feeder.dto; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.smart.feeder.dto.mqtt.Condata; | ||
| 4 | +import com.zhonglai.luhui.smart.feeder.dto.mqtt.Info; | ||
| 3 | import lombok.Data; | 5 | import lombok.Data; |
| 4 | import lombok.experimental.Accessors; | 6 | import lombok.experimental.Accessors; |
| 5 | 7 | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 6 | @Data | 10 | @Data |
| 7 | @Accessors(chain = true) //链式写法 | 11 | @Accessors(chain = true) //链式写法 |
| 8 | public class FeederData { | 12 | public class FeederData { |
| 13 | + private String type; //设备网络型号 字符串("4G.hs") | ||
| 14 | + private Integer signal; //信号量 | ||
| 15 | + private Integer machstate; //机器状态 | ||
| 16 | + private Integer battlevel; //电池电量 | ||
| 17 | + private Info info; | ||
| 9 | 18 | ||
| 10 | } | 19 | } |
| @@ -4,4 +4,6 @@ import java.lang.reflect.Field; | @@ -4,4 +4,6 @@ import java.lang.reflect.Field; | ||
| 4 | 4 | ||
| 5 | public interface OperatingDataType { | 5 | public interface OperatingDataType { |
| 6 | public void setValue(Field field,Object value) throws IllegalAccessException; | 6 | public void setValue(Field field,Object value) throws IllegalAccessException; |
| 7 | + | ||
| 8 | + public void upFile(); | ||
| 7 | } | 9 | } |
| 1 | package com.zhonglai.luhui.smart.feeder.dto; | 1 | package com.zhonglai.luhui.smart.feeder.dto; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.io.FileUtil; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 3 | import com.zhonglai.luhui.smart.feeder.domain.Register; | 5 | import com.zhonglai.luhui.smart.feeder.domain.Register; |
| 6 | +import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | ||
| 4 | import lombok.Data; | 7 | import lombok.Data; |
| 5 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 6 | 9 | ||
| 10 | +import java.io.File; | ||
| 7 | import java.lang.reflect.Field; | 11 | import java.lang.reflect.Field; |
| 8 | import java.util.ArrayList; | 12 | import java.util.ArrayList; |
| 9 | import java.util.List; | 13 | import java.util.List; |
| @@ -117,4 +121,10 @@ public class RegisterConfig implements OperatingDataType{ | @@ -117,4 +121,10 @@ public class RegisterConfig implements OperatingDataType{ | ||
| 117 | public void setValue(Field field, Object value) throws IllegalAccessException { | 121 | public void setValue(Field field, Object value) throws IllegalAccessException { |
| 118 | field.set(this,value); | 122 | field.set(this,value); |
| 119 | } | 123 | } |
| 124 | + | ||
| 125 | + @Override | ||
| 126 | + public void upFile() { | ||
| 127 | + File registerFile = new File("register"); | ||
| 128 | + FileUtil.writeString(ConfigurationParameterService.gson.toJson(this),registerFile,"UTF-8"); | ||
| 129 | + } | ||
| 120 | } | 130 | } |
| 1 | package com.zhonglai.luhui.smart.feeder.dto; | 1 | package com.zhonglai.luhui.smart.feeder.dto; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.io.FileUtil; | ||
| 4 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 5 | +import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | ||
| 3 | import lombok.Data; | 6 | import lombok.Data; |
| 4 | import lombok.experimental.Accessors; | 7 | import lombok.experimental.Accessors; |
| 5 | 8 | ||
| 9 | +import java.io.File; | ||
| 6 | import java.lang.reflect.Field; | 10 | import java.lang.reflect.Field; |
| 7 | 11 | ||
| 8 | /** | 12 | /** |
| @@ -37,4 +41,10 @@ public class SysConfig implements OperatingDataType{ | @@ -37,4 +41,10 @@ public class SysConfig implements OperatingDataType{ | ||
| 37 | public void setValue(Field field, Object value) throws IllegalAccessException { | 41 | public void setValue(Field field, Object value) throws IllegalAccessException { |
| 38 | field.set(this,value); | 42 | field.set(this,value); |
| 39 | } | 43 | } |
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public void upFile() { | ||
| 47 | + File sysConfigFile = new File("sysConfig"); | ||
| 48 | + FileUtil.writeString(ConfigurationParameterService.gson.toJson(this),sysConfigFile,"UTF-8"); | ||
| 49 | + } | ||
| 40 | } | 50 | } |
| @@ -10,5 +10,10 @@ public class CameracontrolRequest { | @@ -10,5 +10,10 @@ public class CameracontrolRequest { | ||
| 10 | private String cmd; //操作指令 devicedata | 10 | private String cmd; //操作指令 devicedata |
| 11 | private String type; //设备网络型号 字符串("4G.hs") | 11 | private String type; //设备网络型号 字符串("4G.hs") |
| 12 | 12 | ||
| 13 | + /** | ||
| 14 | + * 是否摄像头推流 | ||
| 15 | + */ | ||
| 16 | + private Integer is_push_camera; | ||
| 17 | + | ||
| 13 | private CameraConfig cameraConfig; | 18 | private CameraConfig cameraConfig; |
| 14 | } | 19 | } |
| @@ -14,6 +14,9 @@ public class DevicedatRequest { | @@ -14,6 +14,9 @@ public class DevicedatRequest { | ||
| 14 | private Integer signal; //信号量 | 14 | private Integer signal; //信号量 |
| 15 | private Integer machstate; //机器状态 | 15 | private Integer machstate; //机器状态 |
| 16 | private Integer battlevel; //电池电量 | 16 | private Integer battlevel; //电池电量 |
| 17 | + | ||
| 18 | + private String intelligentFeedingLog; //智能投喂日志 | ||
| 19 | + | ||
| 17 | private Condata condata; | 20 | private Condata condata; |
| 18 | private Info info; | 21 | private Info info; |
| 19 | private List<Integer[]> timer; //开启、关闭、使能 8:00开启-9:00关闭,状态:启用 | 22 | private List<Integer[]> timer; //开启、关闭、使能 8:00开启-9:00关闭,状态:启用 |
| @@ -21,6 +24,7 @@ public class DevicedatRequest { | @@ -21,6 +24,7 @@ public class DevicedatRequest { | ||
| 21 | private SysConfig sysConfig; | 24 | private SysConfig sysConfig; |
| 22 | private CameraData cameraData; | 25 | private CameraData cameraData; |
| 23 | private CameraConfig cameraConfig; | 26 | private CameraConfig cameraConfig; |
| 24 | - private FeederConfig feederConfig; | 27 | + private SerialPortConfig serialPortConfig; |
| 25 | private RegisterConfig registerConfig; | 28 | private RegisterConfig registerConfig; |
| 29 | + | ||
| 26 | } | 30 | } |
| @@ -2,6 +2,9 @@ package com.zhonglai.luhui.smart.feeder.service; | @@ -2,6 +2,9 @@ package com.zhonglai.luhui.smart.feeder.service; | ||
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.io.FileUtil; | 4 | import cn.hutool.core.io.FileUtil; |
| 5 | +import com.google.gson.FieldNamingPolicy; | ||
| 6 | +import com.google.gson.Gson; | ||
| 7 | +import com.google.gson.GsonBuilder; | ||
| 5 | import com.ruoyi.common.utils.GsonConstructor; | 8 | import com.ruoyi.common.utils.GsonConstructor; |
| 6 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 9 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; |
| 7 | import com.zhonglai.luhui.smart.feeder.domain.Register; | 10 | import com.zhonglai.luhui.smart.feeder.domain.Register; |
| @@ -20,6 +23,8 @@ import java.util.Map; | @@ -20,6 +23,8 @@ import java.util.Map; | ||
| 20 | */ | 23 | */ |
| 21 | public class ConfigurationParameterService { | 24 | public class ConfigurationParameterService { |
| 22 | 25 | ||
| 26 | + public static Gson gson = (new GsonBuilder()).setVersion(1.0D).disableInnerClassSerialization().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).setDateFormat("yyyy-MM-dd").setPrettyPrinting().create(); | ||
| 27 | + | ||
| 23 | public static Map<Integer,List<Register>> registerMap = new HashMap<>(); //解析的数据字典 | 28 | public static Map<Integer,List<Register>> registerMap = new HashMap<>(); //解析的数据字典 |
| 24 | 29 | ||
| 25 | public static Map<String,Register> controlMap = new HashMap<>(); //控制的数据字典 | 30 | public static Map<String,Register> controlMap = new HashMap<>(); //控制的数据字典 |
| @@ -32,7 +37,7 @@ public class ConfigurationParameterService { | @@ -32,7 +37,7 @@ public class ConfigurationParameterService { | ||
| 32 | { | 37 | { |
| 33 | sysConfigFile.createNewFile(); | 38 | sysConfigFile.createNewFile(); |
| 34 | SysConfig sysConfig = new SysConfig().creteDefault(); | 39 | SysConfig sysConfig = new SysConfig().creteDefault(); |
| 35 | - FileUtil.writeString(GsonConstructor.get().toJson(sysConfig),sysConfigFile,"UTF-8"); | 40 | + FileUtil.writeString(gson.toJson(sysConfig),sysConfigFile,"UTF-8"); |
| 36 | BeanUtil.copyProperties(sysConfig,OperatingData.sysConfig); | 41 | BeanUtil.copyProperties(sysConfig,OperatingData.sysConfig); |
| 37 | }else{ | 42 | }else{ |
| 38 | String str = FileUtil.readUtf8String(sysConfigFile); | 43 | String str = FileUtil.readUtf8String(sysConfigFile); |
| @@ -45,7 +50,7 @@ public class ConfigurationParameterService { | @@ -45,7 +50,7 @@ public class ConfigurationParameterService { | ||
| 45 | { | 50 | { |
| 46 | cameraConfigFile.createNewFile(); | 51 | cameraConfigFile.createNewFile(); |
| 47 | CameraConfig cameraConfig = new CameraConfig().creteDefault(); | 52 | CameraConfig cameraConfig = new CameraConfig().creteDefault(); |
| 48 | - FileUtil.writeString(GsonConstructor.get().toJson(cameraConfig),cameraConfigFile,"UTF-8"); | 53 | + FileUtil.writeString(gson.toJson(cameraConfig),cameraConfigFile,"UTF-8"); |
| 49 | BeanUtil.copyProperties(cameraConfig,OperatingData.cameraConfig); | 54 | BeanUtil.copyProperties(cameraConfig,OperatingData.cameraConfig); |
| 50 | }else{ | 55 | }else{ |
| 51 | CameraConfig cameraConfig = GsonConstructor.get().fromJson(FileUtil.readUtf8String(cameraConfigFile),CameraConfig.class); | 56 | CameraConfig cameraConfig = GsonConstructor.get().fromJson(FileUtil.readUtf8String(cameraConfigFile),CameraConfig.class); |
| @@ -57,7 +62,7 @@ public class ConfigurationParameterService { | @@ -57,7 +62,7 @@ public class ConfigurationParameterService { | ||
| 57 | { | 62 | { |
| 58 | feederConfigFile.createNewFile(); | 63 | feederConfigFile.createNewFile(); |
| 59 | FeederConfig feederConfig = new FeederConfig().creteDefault(); | 64 | FeederConfig feederConfig = new FeederConfig().creteDefault(); |
| 60 | - FileUtil.writeString(GsonConstructor.get().toJson(feederConfig),feederConfigFile,"UTF-8"); | 65 | + FileUtil.writeString(gson.toJson(feederConfig),feederConfigFile,"UTF-8"); |
| 61 | BeanUtil.copyProperties(feederConfig,OperatingData.feederConfig); | 66 | BeanUtil.copyProperties(feederConfig,OperatingData.feederConfig); |
| 62 | }else{ | 67 | }else{ |
| 63 | FeederConfig feederConfig = GsonConstructor.get().fromJson(FileUtil.readUtf8String(feederConfigFile),FeederConfig.class); | 68 | FeederConfig feederConfig = GsonConstructor.get().fromJson(FileUtil.readUtf8String(feederConfigFile),FeederConfig.class); |
| @@ -69,7 +74,7 @@ public class ConfigurationParameterService { | @@ -69,7 +74,7 @@ public class ConfigurationParameterService { | ||
| 69 | { | 74 | { |
| 70 | registerFile.createNewFile(); | 75 | registerFile.createNewFile(); |
| 71 | RegisterConfig registerConfig = new RegisterConfig().creteDefault(); | 76 | RegisterConfig registerConfig = new RegisterConfig().creteDefault(); |
| 72 | - FileUtil.writeString(GsonConstructor.get().toJson(registerConfig),registerFile,"UTF-8"); | 77 | + FileUtil.writeString(gson.toJson(registerConfig),registerFile,"UTF-8"); |
| 73 | BeanUtil.copyProperties(registerConfig,OperatingData.registerConfig); | 78 | BeanUtil.copyProperties(registerConfig,OperatingData.registerConfig); |
| 74 | }else{ | 79 | }else{ |
| 75 | RegisterConfig registerConfig = GsonConstructor.get().fromJson(FileUtil.readUtf8String(registerFile),RegisterConfig.class); | 80 | RegisterConfig registerConfig = GsonConstructor.get().fromJson(FileUtil.readUtf8String(registerFile),RegisterConfig.class); |
| 1 | package com.zhonglai.luhui.smart.feeder.service; | 1 | package com.zhonglai.luhui.smart.feeder.service; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | +import cn.hutool.core.util.ObjectUtil; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 5 | import com.google.gson.Gson; | 6 | import com.google.gson.Gson; |
| 6 | import com.google.gson.JsonObject; | 7 | import com.google.gson.JsonObject; |
| @@ -42,15 +43,19 @@ public class DateListenService { | @@ -42,15 +43,19 @@ public class DateListenService { | ||
| 42 | public void run() | 43 | public void run() |
| 43 | { | 44 | { |
| 44 | //更新投料机数据 | 45 | //更新投料机数据 |
| 45 | - ScheduledConfig.scheduler.scheduleAtFixedRate(() -> { | 46 | + ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { |
| 46 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.readAll()); | 47 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.readAll()); |
| 47 | Map<String,Object> data = analysisDataService.analysis(modbusDto); | 48 | Map<String,Object> data = analysisDataService.analysis(modbusDto); |
| 48 | if(null != data && data.size() != 0) | 49 | if(null != data && data.size() != 0) |
| 49 | { | 50 | { |
| 50 | Condata condata = BeanUtil.mapToBean(data, Condata.class,false,null); | 51 | Condata condata = BeanUtil.mapToBean(data, Condata.class,false,null); |
| 51 | Info info = BeanUtil.mapToBean(data, Info.class,false,null); | 52 | Info info = BeanUtil.mapToBean(data, Info.class,false,null); |
| 52 | - OperatingData.devicedat.setCondata(condata); | ||
| 53 | - OperatingData.devicedat.setInfo(info); | 53 | + if(ObjectUtil.notEqual(OperatingData.feederConfig.getCondata(),condata)) |
| 54 | + { | ||
| 55 | + OperatingData.feederConfig.setCondata(condata); | ||
| 56 | + reportCondata(); | ||
| 57 | + } | ||
| 58 | + OperatingData.feederData.setInfo(info); | ||
| 54 | 59 | ||
| 55 | List<Integer[]> timerList = new ArrayList<>(); | 60 | List<Integer[]> timerList = new ArrayList<>(); |
| 56 | for(String key:data.keySet()) | 61 | for(String key:data.keySet()) |
| @@ -64,7 +69,11 @@ public class DateListenService { | @@ -64,7 +69,11 @@ public class DateListenService { | ||
| 64 | 69 | ||
| 65 | if(null != timerList && timerList.size() != 0) | 70 | if(null != timerList && timerList.size() != 0) |
| 66 | { | 71 | { |
| 67 | - OperatingData.devicedat.setTimer(timerList); | 72 | + if(ObjectUtil.notEqual(OperatingData.feederConfig.getTimer(),timerList)) |
| 73 | + { | ||
| 74 | + OperatingData.feederConfig.setTimer(timerList); | ||
| 75 | + reportTimer(); | ||
| 76 | + } | ||
| 68 | } | 77 | } |
| 69 | } | 78 | } |
| 70 | },1,10, TimeUnit.SECONDS); | 79 | },1,10, TimeUnit.SECONDS); |
| @@ -82,71 +91,13 @@ public class DateListenService { | @@ -82,71 +91,13 @@ public class DateListenService { | ||
| 82 | devicedatRequest.setSignal(4); | 91 | devicedatRequest.setSignal(4); |
| 83 | devicedatRequest.setMachstate(1); | 92 | devicedatRequest.setMachstate(1); |
| 84 | devicedatRequest.setBattlevel(4); | 93 | devicedatRequest.setBattlevel(4); |
| 85 | - devicedatRequest.setCondata(OperatingData.devicedat.getCondata()); | ||
| 86 | - devicedatRequest.setInfo(OperatingData.devicedat.getInfo()); | ||
| 87 | - devicedatRequest.setTimer(OperatingData.devicedat.getTimer()); | 94 | + devicedatRequest.setInfo(OperatingData.feederData.getInfo()); |
| 95 | + CameraData cameraData = BeanUtil.copyProperties(OperatingData.cameraData,CameraData.class,"scaleAreaList"); | ||
| 96 | + devicedatRequest.setCameraData(cameraData); | ||
| 88 | String str = GsonConstructor.get().toJson(devicedatRequest); | 97 | String str = GsonConstructor.get().toJson(devicedatRequest); |
| 89 | System.out.println(str); | 98 | System.out.println(str); |
| 90 | - if(str.length()>=1024) | ||
| 91 | - { | ||
| 92 | - System.out.println("超标了"); | ||
| 93 | - } | ||
| 94 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | 99 | CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); |
| 95 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | 100 | MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); |
| 96 | - | ||
| 97 | - Thread.sleep(10000); | ||
| 98 | - | ||
| 99 | - devicedatRequest = new DevicedatRequest(); | ||
| 100 | - devicedatRequest.setCmd("devicedata"); | ||
| 101 | - devicedatRequest.setType("4G.hs"); | ||
| 102 | - devicedatRequest.setSignal(4); | ||
| 103 | - devicedatRequest.setMachstate(1); | ||
| 104 | - devicedatRequest.setBattlevel(4); | ||
| 105 | - devicedatRequest.setSysConfig(OperatingData.sysConfig); | ||
| 106 | - devicedatRequest.setFeederConfig(OperatingData.feederConfig); | ||
| 107 | - str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 108 | - System.out.println(str); | ||
| 109 | - if(str.length()>=1024) | ||
| 110 | - { | ||
| 111 | - System.out.println("超标了"); | ||
| 112 | - } | ||
| 113 | - cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 114 | - MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 115 | - | ||
| 116 | - Thread.sleep(10000); | ||
| 117 | - | ||
| 118 | - devicedatRequest = new DevicedatRequest(); | ||
| 119 | - devicedatRequest.setCmd("devicedata"); | ||
| 120 | - devicedatRequest.setType("4G.hs"); | ||
| 121 | - devicedatRequest.setSignal(4); | ||
| 122 | - devicedatRequest.setMachstate(1); | ||
| 123 | - devicedatRequest.setBattlevel(4); | ||
| 124 | - devicedatRequest.setCameraData(OperatingData.cameraData); | ||
| 125 | - devicedatRequest.setCameraConfig(OperatingData.cameraConfig); | ||
| 126 | - str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 127 | - System.out.println(str); | ||
| 128 | - if(str.length()>=1024) | ||
| 129 | - { | ||
| 130 | - System.out.println("超标了"); | ||
| 131 | - } | ||
| 132 | - cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 133 | - MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 134 | - | ||
| 135 | - if(OperatingData.sysConfig.getIfRegisterConfig()) | ||
| 136 | - { | ||
| 137 | - Thread.sleep(10000); | ||
| 138 | - | ||
| 139 | - devicedatRequest = new DevicedatRequest(); | ||
| 140 | - devicedatRequest.setCmd("devicedata"); | ||
| 141 | - devicedatRequest.setType("4G.hs"); | ||
| 142 | - devicedatRequest.setSignal(4); | ||
| 143 | - devicedatRequest.setMachstate(1); | ||
| 144 | - devicedatRequest.setBattlevel(4); | ||
| 145 | - devicedatRequest.setRegisterConfig(OperatingData.registerConfig); | ||
| 146 | - str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 147 | - cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 148 | - MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 149 | - } | ||
| 150 | } | 101 | } |
| 151 | }catch (Exception e) | 102 | }catch (Exception e) |
| 152 | { | 103 | { |
| @@ -154,7 +105,153 @@ public class DateListenService { | @@ -154,7 +105,153 @@ public class DateListenService { | ||
| 154 | } | 105 | } |
| 155 | } | 106 | } |
| 156 | 107 | ||
| 157 | - },1,10, TimeUnit.SECONDS); | 108 | + },1,60, TimeUnit.SECONDS); |
| 109 | + | ||
| 110 | + //上报参数 | ||
| 111 | + ScheduledConfig.scheduler.schedule(() -> { | ||
| 112 | + try { | ||
| 113 | + Thread.sleep(10000); | ||
| 114 | + reportSerialPortConfig(); | ||
| 115 | + Thread.sleep(10000); | ||
| 116 | + reportSysConfig(); | ||
| 117 | + Thread.sleep(10000); | ||
| 118 | + reportCameraConfig(); | ||
| 119 | + Thread.sleep(10000); | ||
| 120 | + reportRegisterConfig(); | ||
| 121 | + } catch (Exception e) { | ||
| 122 | + throw new RuntimeException(e); | ||
| 123 | + } | ||
| 124 | + },0,TimeUnit.SECONDS); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * 上报智能投喂数据 | ||
| 129 | + */ | ||
| 130 | + public void reportIntelligentFeeding(String intelligentFeedingLog) | ||
| 131 | + { | ||
| 132 | + DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 133 | + devicedatRequest.setCmd("activitydata"); | ||
| 134 | + devicedatRequest.setType("4G.hs"); | ||
| 135 | + devicedatRequest.setSignal(4); | ||
| 136 | + devicedatRequest.setMachstate(1); | ||
| 137 | + devicedatRequest.setBattlevel(4); | ||
| 138 | + devicedatRequest.setIntelligentFeedingLog(intelligentFeedingLog); | ||
| 139 | + String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 140 | + System.out.println(str); | ||
| 141 | + CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 142 | + MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + /** | ||
| 146 | + * 上报投料机控制参数 | ||
| 147 | + */ | ||
| 148 | + public void reportCondata() | ||
| 149 | + { | ||
| 150 | + DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 151 | + devicedatRequest.setCmd("devicedata"); | ||
| 152 | + devicedatRequest.setType("4G.hs"); | ||
| 153 | + devicedatRequest.setSignal(4); | ||
| 154 | + devicedatRequest.setMachstate(1); | ||
| 155 | + devicedatRequest.setBattlevel(4); | ||
| 156 | + devicedatRequest.setCondata(OperatingData.feederConfig.getCondata()); | ||
| 157 | + String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 158 | + System.out.println(str); | ||
| 159 | + 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 | + } | ||
| 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 | + } | ||
| 179 | + | ||
| 180 | + /** | ||
| 181 | + * 上报串口参数 | ||
| 182 | + */ | ||
| 183 | + public void reportSerialPortConfig() | ||
| 184 | + { | ||
| 185 | + DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 186 | + devicedatRequest.setCmd("devicedata"); | ||
| 187 | + devicedatRequest.setType("4G.hs"); | ||
| 188 | + devicedatRequest.setSignal(4); | ||
| 189 | + devicedatRequest.setMachstate(1); | ||
| 190 | + devicedatRequest.setBattlevel(4); | ||
| 191 | + devicedatRequest.setSerialPortConfig(OperatingData.feederConfig.getSerialPortConfig()); | ||
| 192 | + String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 193 | + System.out.println(str); | ||
| 194 | + CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 195 | + MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + /** | ||
| 199 | + * 上报系统参数 | ||
| 200 | + */ | ||
| 201 | + public void reportSysConfig() | ||
| 202 | + { | ||
| 203 | + DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 204 | + devicedatRequest.setCmd("devicedata"); | ||
| 205 | + devicedatRequest.setType("4G.hs"); | ||
| 206 | + devicedatRequest.setSignal(4); | ||
| 207 | + devicedatRequest.setMachstate(1); | ||
| 208 | + devicedatRequest.setBattlevel(4); | ||
| 209 | + devicedatRequest.setSysConfig(OperatingData.sysConfig); | ||
| 210 | + String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 211 | + System.out.println(str); | ||
| 212 | + CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 213 | + MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + /** | ||
| 217 | + * 上报摄像头参数 | ||
| 218 | + * @throws Exception | ||
| 219 | + */ | ||
| 220 | + public void reportCameraConfig() { | ||
| 221 | + | ||
| 222 | + DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 223 | + devicedatRequest.setCmd("devicedata"); | ||
| 224 | + devicedatRequest.setType("4G.hs"); | ||
| 225 | + devicedatRequest.setSignal(4); | ||
| 226 | + devicedatRequest.setMachstate(1); | ||
| 227 | + devicedatRequest.setBattlevel(4); | ||
| 228 | + devicedatRequest.setCameraConfig(OperatingData.cameraConfig); | ||
| 229 | + String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 230 | + System.out.println(str); | ||
| 231 | + CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 232 | + MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 233 | + | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + /** | ||
| 237 | + * 上报寄存器参数 | ||
| 238 | + */ | ||
| 239 | + public void reportRegisterConfig() | ||
| 240 | + { | ||
| 241 | + if(OperatingData.sysConfig.getIfRegisterConfig()) | ||
| 242 | + { | ||
| 243 | + | ||
| 244 | + DevicedatRequest devicedatRequest = new DevicedatRequest(); | ||
| 245 | + devicedatRequest.setCmd("devicedata"); | ||
| 246 | + devicedatRequest.setType("4G.hs"); | ||
| 247 | + devicedatRequest.setSignal(4); | ||
| 248 | + devicedatRequest.setMachstate(1); | ||
| 249 | + devicedatRequest.setBattlevel(4); | ||
| 250 | + devicedatRequest.setRegisterConfig(OperatingData.registerConfig); | ||
| 251 | + String str = GsonConstructor.get().toJson(devicedatRequest); | ||
| 252 | + CmdDto cmdDto = new CmdDto().setImei(OperatingData.sysConfig.getNettyConfig().getClientId()).setJsonObject( GsonConstructor.get().fromJson( str, JsonObject.class)); | ||
| 253 | + MessageUtil.sendMessage(InitService.nettyClient.getCtx(), cmdDto.generateCmd(),true); | ||
| 254 | + } | ||
| 158 | } | 255 | } |
| 159 | 256 | ||
| 160 | public static void main(String[] args) { | 257 | public static void main(String[] args) { |
| @@ -166,14 +263,14 @@ public class DateListenService { | @@ -166,14 +263,14 @@ public class DateListenService { | ||
| 166 | devicedatRequest.setMachstate(1); | 263 | devicedatRequest.setMachstate(1); |
| 167 | devicedatRequest.setBattlevel(4); | 264 | devicedatRequest.setBattlevel(4); |
| 168 | 265 | ||
| 169 | - devicedatRequest.setCondata(OperatingData.devicedat.getCondata()); | ||
| 170 | - devicedatRequest.setInfo(OperatingData.devicedat.getInfo()); | ||
| 171 | - devicedatRequest.setTimer(OperatingData.devicedat.getTimer()); | 266 | + devicedatRequest.setCondata(OperatingData.feederConfig.getCondata()); |
| 267 | + devicedatRequest.setInfo(OperatingData.feederData.getInfo()); | ||
| 268 | + devicedatRequest.setTimer(OperatingData.feederConfig.getTimer()); | ||
| 172 | 269 | ||
| 173 | devicedatRequest.setSysConfig(OperatingData.sysConfig); | 270 | devicedatRequest.setSysConfig(OperatingData.sysConfig); |
| 174 | devicedatRequest.setCameraData(OperatingData.cameraData); | 271 | devicedatRequest.setCameraData(OperatingData.cameraData); |
| 175 | devicedatRequest.setCameraConfig(OperatingData.cameraConfig); | 272 | devicedatRequest.setCameraConfig(OperatingData.cameraConfig); |
| 176 | - devicedatRequest.setFeederConfig(OperatingData.feederConfig); | 273 | + devicedatRequest.setSerialPortConfig(OperatingData.feederConfig.getSerialPortConfig()); |
| 177 | 274 | ||
| 178 | System.out.println(GsonConstructor.get().toJson(devicedatRequest)); | 275 | System.out.println(GsonConstructor.get().toJson(devicedatRequest)); |
| 179 | } | 276 | } |
| 1 | package com.zhonglai.luhui.smart.feeder.service; | 1 | package com.zhonglai.luhui.smart.feeder.service; |
| 2 | 2 | ||
| 3 | +import com.ruoyi.common.utils.DateUtils; | ||
| 3 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 4 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; |
| 4 | import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | 5 | import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; |
| 5 | import com.zhonglai.luhui.smart.feeder.dto.*; | 6 | import com.zhonglai.luhui.smart.feeder.dto.*; |
| @@ -30,12 +31,10 @@ public class DeviceService { | @@ -30,12 +31,10 @@ public class DeviceService { | ||
| 30 | //投料控制 | 31 | //投料控制 |
| 31 | ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { | 32 | ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { |
| 32 | if (OperatingData.cameraConfig.getFeedingControl()) { | 33 | if (OperatingData.cameraConfig.getFeedingControl()) { |
| 33 | - Condata condata = OperatingData.devicedat.getCondata(); | 34 | + Condata condata = OperatingData.feederConfig.getCondata(); |
| 34 | CameraData cameraData = OperatingData.cameraData; | 35 | CameraData cameraData = OperatingData.cameraData; |
| 35 | logger.info("摄像头识别档位{},投料机的档位{},斜率{},斜率差值{},面积{},开关是否打开{}",cameraData.getNowGear(),condata.getRunspeed(),cameraData.getSlope(),cameraData.getAbsValue(),cameraData.getArea(),null == condata.getRunstate()?"未知":condata.getRunstate()); | 36 | logger.info("摄像头识别档位{},投料机的档位{},斜率{},斜率差值{},面积{},开关是否打开{}",cameraData.getNowGear(),condata.getRunspeed(),cameraData.getSlope(),cameraData.getAbsValue(),cameraData.getArea(),null == condata.getRunstate()?"未知":condata.getRunstate()); |
| 36 | 37 | ||
| 37 | - getGearFromAbsValue(); | ||
| 38 | - | ||
| 39 | if(null !=condata && 1==condata.getRunstate()) //数据状态出来了,并且设备已经启动 | 38 | if(null !=condata && 1==condata.getRunstate()) //数据状态出来了,并且设备已经启动 |
| 40 | { | 39 | { |
| 41 | if(1==condata.getRunmode()) //只有手动模式才能控制 | 40 | if(1==condata.getRunmode()) //只有手动模式才能控制 |
| @@ -52,6 +51,21 @@ public class DeviceService { | @@ -52,6 +51,21 @@ public class DeviceService { | ||
| 52 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.controlData(FeederCommd06ResponseType.runspeed,cameraData.getNowGear())); //较准档位 | 51 | ModbusDto modbusDto = serialPortService.sendHexData(FeederCommdUtil.controlData(FeederCommd06ResponseType.runspeed,cameraData.getNowGear())); //较准档位 |
| 53 | if(null!=modbusDto) | 52 | if(null!=modbusDto) |
| 54 | { | 53 | { |
| 54 | + | ||
| 55 | + String time = DateUtils.getTime(); | ||
| 56 | + String[] ss = OperatingData.cameraConfig.getFishSchoolSizeConfigString(); | ||
| 57 | + String fishSchoolSize = ss[OperatingData.cameraData.getFishSchoolSize()]; | ||
| 58 | + StringBuffer stringBuffer = new StringBuffer(); | ||
| 59 | + stringBuffer.append(time); | ||
| 60 | + stringBuffer.append(" "); | ||
| 61 | + stringBuffer.append(fishSchoolSize); | ||
| 62 | + stringBuffer.append(",智能调整档位"); | ||
| 63 | + stringBuffer.append(condata.getRunspeed()); | ||
| 64 | + stringBuffer.append("为"); | ||
| 65 | + stringBuffer.append(cameraData.getNowGear()); | ||
| 66 | + stringBuffer.append("档投喂"); | ||
| 67 | + InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); | ||
| 68 | + | ||
| 55 | condata.setRunspeed(cameraData.getNowGear()); | 69 | condata.setRunspeed(cameraData.getNowGear()); |
| 56 | } | 70 | } |
| 57 | } | 71 | } |
| @@ -60,30 +74,12 @@ public class DeviceService { | @@ -60,30 +74,12 @@ public class DeviceService { | ||
| 60 | },1,1, TimeUnit.SECONDS); | 74 | },1,1, TimeUnit.SECONDS); |
| 61 | } | 75 | } |
| 62 | 76 | ||
| 63 | - /** | ||
| 64 | - * 根据斜率计算档位 | ||
| 65 | - * @return | ||
| 66 | - */ | ||
| 67 | - private Integer getGearFromAbsValue() | 77 | + public void stop() |
| 68 | { | 78 | { |
| 69 | - Double absValue = OperatingData.cameraData.getAbsValue(); | ||
| 70 | - Integer gear = null; | ||
| 71 | - | ||
| 72 | - List<FishCurveControlCondition> list = OperatingData.cameraConfig.getAbsValue_command(); | ||
| 73 | - if(null != list && list.size() != 0) | ||
| 74 | - { | ||
| 75 | - list.sort(Comparator.comparing(FishCurveControlCondition::getSartAbsValue));//以 sartAbsValue 升序排序 | ||
| 76 | - | ||
| 77 | - for(FishCurveControlCondition fishCurveControlCondition:list) //根据斜率找到档位 | ||
| 78 | - { | ||
| 79 | - if(absValue>=fishCurveControlCondition.getSartAbsValue()) //向下查找 | ||
| 80 | - { | ||
| 81 | - gear = fishCurveControlCondition.getGear(); | ||
| 82 | - } | ||
| 83 | - } | ||
| 84 | - } | ||
| 85 | - OperatingData.cameraData.setNowGear(gear); | ||
| 86 | - return gear; | 79 | + OperatingData.cameraConfig.setFeedingControl(false); |
| 80 | + } | ||
| 81 | + public void start() | ||
| 82 | + { | ||
| 83 | + OperatingData.cameraConfig.setFeedingControl(true); | ||
| 87 | } | 84 | } |
| 88 | - | ||
| 89 | } | 85 | } |
| 1 | package com.zhonglai.luhui.smart.feeder.service; | 1 | package com.zhonglai.luhui.smart.feeder.service; |
| 2 | 2 | ||
| 3 | -import com.zhonglai.luhui.smart.feeder.config.OpenCVConfig; | 3 | +import com.ruoyi.common.utils.DateUtils; |
| 4 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 4 | 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.CameraConfig; | ||
| 7 | -import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil; | 6 | +import com.zhonglai.luhui.smart.feeder.dto.FishCurveControlCondition; |
| 8 | import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle; | 7 | import com.zhonglai.luhui.smart.feeder.service.device.CameraHandle; |
| 9 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; | 8 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; |
| 10 | -import org.bytedeco.opencv.opencv_core.Point2f; | ||
| 11 | import org.opencv.core.*; | 9 | import org.opencv.core.*; |
| 12 | -import org.opencv.highgui.HighGui; | ||
| 13 | -import org.opencv.imgcodecs.Imgcodecs; | ||
| 14 | import org.opencv.imgproc.Imgproc; | 10 | import org.opencv.imgproc.Imgproc; |
| 15 | import org.opencv.video.BackgroundSubtractorMOG2; | 11 | import org.opencv.video.BackgroundSubtractorMOG2; |
| 16 | import org.opencv.video.Video; | 12 | import org.opencv.video.Video; |
| 17 | -import org.opencv.videoio.VideoCapture; | ||
| 18 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| 19 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| 20 | -import org.springframework.stereotype.Service; | ||
| 21 | 15 | ||
| 22 | import java.util.ArrayList; | 16 | import java.util.ArrayList; |
| 23 | -import java.util.Arrays; | ||
| 24 | -import java.util.Collections; | 17 | +import java.util.Comparator; |
| 25 | import java.util.List; | 18 | import java.util.List; |
| 19 | +import java.util.concurrent.ScheduledFuture; | ||
| 26 | import java.util.concurrent.TimeUnit; | 20 | import java.util.concurrent.TimeUnit; |
| 27 | -import java.util.function.Predicate; | ||
| 28 | 21 | ||
| 29 | import static com.zhonglai.luhui.smart.feeder.service.InitService.*; | 22 | import static com.zhonglai.luhui.smart.feeder.service.InitService.*; |
| 30 | 23 | ||
| @@ -44,6 +37,25 @@ public class FishGroupImageRecognitionService { | @@ -44,6 +37,25 @@ public class FishGroupImageRecognitionService { | ||
| 44 | 37 | ||
| 45 | private static Mat thresh = new Mat(); //二值化图片 | 38 | private static Mat thresh = new Mat(); //二值化图片 |
| 46 | 39 | ||
| 40 | + private SrsService srsService; | ||
| 41 | + | ||
| 42 | + private Integer endTime = 0; | ||
| 43 | + | ||
| 44 | + private ScheduledFuture scheduledFuture; | ||
| 45 | + | ||
| 46 | + public void startPushimg(int time) | ||
| 47 | + { | ||
| 48 | + if(null == srsService) | ||
| 49 | + { | ||
| 50 | + srsService = new SrsService(); | ||
| 51 | + try { | ||
| 52 | + srsService.init(640,480); | ||
| 53 | + } catch (Exception e) { | ||
| 54 | + throw new RuntimeException(e); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + endTime=DateUtils.getNowTimeMilly()+time; | ||
| 58 | + } | ||
| 47 | 59 | ||
| 48 | public FishGroupImageRecognitionService() | 60 | public FishGroupImageRecognitionService() |
| 49 | { | 61 | { |
| @@ -52,28 +64,44 @@ public class FishGroupImageRecognitionService { | @@ -52,28 +64,44 @@ public class FishGroupImageRecognitionService { | ||
| 52 | 64 | ||
| 53 | public void run() | 65 | public void run() |
| 54 | { | 66 | { |
| 55 | - ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { | 67 | + scheduledFuture = ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { |
| 56 | if (!OperatingData.cameraData.getFishGroupImageRecognIsRun()) | 68 | if (!OperatingData.cameraData.getFishGroupImageRecognIsRun()) |
| 57 | { | 69 | { |
| 58 | start(); | 70 | start(); |
| 59 | - OperatingData.cameraData.setFishGroupImageRecognIsRun(false); | ||
| 60 | } | 71 | } |
| 61 | },1,1,TimeUnit.SECONDS); | 72 | },1,1,TimeUnit.SECONDS); |
| 62 | 73 | ||
| 63 | } | 74 | } |
| 64 | // 创建FrameConverter对象 | 75 | // 创建FrameConverter对象 |
| 65 | - private void start() | 76 | + public void start() |
| 66 | { | 77 | { |
| 67 | CameraHandle cameraHandle = InitService.cameraHandle; | 78 | CameraHandle cameraHandle = InitService.cameraHandle; |
| 68 | 79 | ||
| 69 | if(!cameraHandle.isOpen()) | 80 | if(!cameraHandle.isOpen()) |
| 70 | { | 81 | { |
| 71 | - cameraHandle.init(); | 82 | + if (!cameraHandle.init()) |
| 83 | + { | ||
| 84 | + return; | ||
| 85 | + } | ||
| 72 | } | 86 | } |
| 73 | OperatingData.cameraData.setFishGroupImageRecognIsRun(true); | 87 | OperatingData.cameraData.setFishGroupImageRecognIsRun(true); |
| 74 | brightnessIdentifyFishRegion(); | 88 | brightnessIdentifyFishRegion(); |
| 75 | } | 89 | } |
| 76 | 90 | ||
| 91 | + public void stop() | ||
| 92 | + { | ||
| 93 | + OperatingData.cameraData.setFishGroupImageRecognIsRun(false); | ||
| 94 | + scheduledFuture.cancel(true); | ||
| 95 | + while (!scheduledFuture.isCancelled()) | ||
| 96 | + { | ||
| 97 | + try { | ||
| 98 | + Thread.sleep(1000); | ||
| 99 | + } catch (InterruptedException e) { | ||
| 100 | + throw new RuntimeException(e); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + } | ||
| 77 | 105 | ||
| 78 | /** | 106 | /** |
| 79 | * 亮度查找水面,透明度过滤鱼群 | 107 | * 亮度查找水面,透明度过滤鱼群 |
| @@ -82,32 +110,50 @@ public class FishGroupImageRecognitionService { | @@ -82,32 +110,50 @@ public class FishGroupImageRecognitionService { | ||
| 82 | { | 110 | { |
| 83 | logger.info("启动鱼群识别"); | 111 | logger.info("启动鱼群识别"); |
| 84 | 112 | ||
| 85 | - Long time =1000l; | ||
| 86 | - if(null != OperatingData.cameraConfig.getIdentificationFrequency()) | ||
| 87 | - { | ||
| 88 | - time = OperatingData.cameraConfig.getIdentificationFrequency(); | ||
| 89 | - } | ||
| 90 | - while (cameraHandle.isOpen()) | 113 | + while (OperatingData.cameraConfig.getFishGroupImageRecognition() && cameraHandle.isOpen() && OperatingData.cameraData.getFishGroupImageRecognIsRun()) |
| 91 | { | 114 | { |
| 115 | + Long time =1000l; | ||
| 116 | + if(null != OperatingData.cameraConfig.getIdentificationFrequency()) | ||
| 117 | + { | ||
| 118 | + time = OperatingData.cameraConfig.getIdentificationFrequency(); | ||
| 119 | + } | ||
| 92 | try { | 120 | try { |
| 93 | - Boolean fishGroupImageRecognition = OperatingData.cameraConfig.getFishGroupImageRecognition(); | ||
| 94 | - frame = CameraRtspHandle.mat.clone(); | ||
| 95 | - | ||
| 96 | - Boolean isread = false; | ||
| 97 | - if(null != frame) | ||
| 98 | - { | ||
| 99 | - isread = true; | ||
| 100 | - } | ||
| 101 | - logger.info("逐帧处理视频,开始处理的判断参数:鱼群图像识别是否开启 {}、摄像头是否可读取 {}",fishGroupImageRecognition,isread); | ||
| 102 | - if(!isread ) | 121 | + if( null != CameraRtspHandle.mat) |
| 103 | { | 122 | { |
| 104 | - logger.info("摄像头不可读取"); | ||
| 105 | - frame.release(); | ||
| 106 | - return; | ||
| 107 | - } | ||
| 108 | - if (fishGroupImageRecognition && isread) { | ||
| 109 | - yidong(frame); | 123 | + frame = CameraRtspHandle.mat.clone(); |
| 124 | + Boolean isread = false; | ||
| 125 | + if(null != frame) | ||
| 126 | + { | ||
| 127 | + isread = true; | ||
| 128 | + } | ||
| 129 | + logger.info("逐帧处理视频,开始处理的判断参数:鱼群图像识别是否开启 {}、摄像头是否可读取 {}",OperatingData.cameraConfig.getFishGroupImageRecognition(),isread); | ||
| 130 | + if(!isread ) | ||
| 131 | + { | ||
| 132 | + logger.info("摄像头不可读取"); | ||
| 133 | + frame.release(); | ||
| 134 | + return; | ||
| 135 | + } | ||
| 136 | + if (isread) { | ||
| 137 | + yidong(frame,time); | ||
| 138 | +// getGearFromAbsValue(); | ||
| 139 | + //推送或者显示图片 | ||
| 140 | + if(OperatingData.cameraData.is_push_camera()) | ||
| 141 | + { | ||
| 142 | + if(null != srsService && endTime-DateUtils.getNowTimeMilly()>0) | ||
| 143 | + { | ||
| 144 | + srsService.push(frame); | ||
| 145 | + }else { | ||
| 146 | + if(null != srsService) | ||
| 147 | + { | ||
| 148 | + srsService.stop(); | ||
| 149 | + srsService = null; | ||
| 150 | + OperatingData.cameraData.set_push_camera(false); | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + } | ||
| 154 | + } | ||
| 110 | } | 155 | } |
| 156 | + | ||
| 111 | }catch (Exception e) | 157 | }catch (Exception e) |
| 112 | { | 158 | { |
| 113 | logger.error("识别错误",e); | 159 | logger.error("识别错误",e); |
| @@ -123,13 +169,14 @@ public class FishGroupImageRecognitionService { | @@ -123,13 +169,14 @@ public class FishGroupImageRecognitionService { | ||
| 123 | } | 169 | } |
| 124 | } | 170 | } |
| 125 | } | 171 | } |
| 172 | + OperatingData.cameraData.setFishGroupImageRecognIsRun(false); | ||
| 126 | } | 173 | } |
| 127 | 174 | ||
| 128 | /** | 175 | /** |
| 129 | * 检测移动 | 176 | * 检测移动 |
| 130 | * @return | 177 | * @return |
| 131 | */ | 178 | */ |
| 132 | - private void yidong(Mat image) | 179 | + private void yidong(Mat image,Long time) |
| 133 | { | 180 | { |
| 134 | if(!image.empty()) | 181 | if(!image.empty()) |
| 135 | { | 182 | { |
| @@ -147,12 +194,14 @@ public class FishGroupImageRecognitionService { | @@ -147,12 +194,14 @@ public class FishGroupImageRecognitionService { | ||
| 147 | 194 | ||
| 148 | double[] dsTotal = new double[5]; | 195 | double[] dsTotal = new double[5]; |
| 149 | 196 | ||
| 197 | + | ||
| 150 | contours.removeIf(matOfPoint -> { | 198 | contours.removeIf(matOfPoint -> { |
| 151 | Rect rect = Imgproc.boundingRect(matOfPoint); | 199 | Rect rect = Imgproc.boundingRect(matOfPoint); |
| 152 | matOfPoint.release(); | 200 | matOfPoint.release(); |
| 153 | if(rect.width!=image.width() && rect.width>OperatingData.cameraConfig.getCalloutBoxWidthMin()) | 201 | if(rect.width!=image.width() && rect.width>OperatingData.cameraConfig.getCalloutBoxWidthMin()) |
| 154 | { | 202 | { |
| 155 | double[] ds = count(image,rect); | 203 | double[] ds = count(image,rect); |
| 204 | + | ||
| 156 | if(filterate(ds)) | 205 | if(filterate(ds)) |
| 157 | { | 206 | { |
| 158 | dsTotal[0]+=ds[0]; | 207 | dsTotal[0]+=ds[0]; |
| @@ -172,7 +221,7 @@ public class FishGroupImageRecognitionService { | @@ -172,7 +221,7 @@ public class FishGroupImageRecognitionService { | ||
| 172 | double brightness = dsTotal[0]/dsTotal[4]; | 221 | double brightness = dsTotal[0]/dsTotal[4]; |
| 173 | double reflection= dsTotal[1]/dsTotal[4]; | 222 | double reflection= dsTotal[1]/dsTotal[4]; |
| 174 | double transparencyMeasure= dsTotal[2]/dsTotal[4]; | 223 | double transparencyMeasure= dsTotal[2]/dsTotal[4]; |
| 175 | - double area= dsTotal[3]/dsTotal[4]; | 224 | + double area = dsTotal[3]/dsTotal[4]; |
| 176 | 225 | ||
| 177 | //计算斜率 | 226 | //计算斜率 |
| 178 | double slope = area - (null==OperatingData.cameraData.getArea()?area:OperatingData.cameraData.getArea()); | 227 | double slope = area - (null==OperatingData.cameraData.getArea()?area:OperatingData.cameraData.getArea()); |
| @@ -188,13 +237,97 @@ public class FishGroupImageRecognitionService { | @@ -188,13 +237,97 @@ public class FishGroupImageRecognitionService { | ||
| 188 | OperatingData.cameraData.setSlope(slope); | 237 | OperatingData.cameraData.setSlope(slope); |
| 189 | OperatingData.cameraData.setSlopeDifference(slopeDifference); | 238 | OperatingData.cameraData.setSlopeDifference(slopeDifference); |
| 190 | OperatingData.cameraData.setAbsValue(absValue); | 239 | OperatingData.cameraData.setAbsValue(absValue); |
| 240 | + OperatingData.cameraData.setSize(new Double(dsTotal[4]).intValue()); | ||
| 241 | + | ||
| 242 | + List<Double> scaleAreaList = OperatingData.cameraData.getScaleAreaList(); | ||
| 243 | + //计算尺度之内的面积集合的大小 | ||
| 244 | + int size = new Double((OperatingData.cameraConfig.getCollectionScale()*60*1000l)/time).intValue(); | ||
| 245 | + //如何集合满了,就吧第一个挤出去,然后放在集合最后 | ||
| 246 | + if(scaleAreaList.size()>=size) | ||
| 247 | + { | ||
| 248 | + scaleAreaList.remove(0); | ||
| 249 | + } | ||
| 250 | + scaleAreaList.add(dsTotal[4]); | ||
| 251 | + | ||
| 252 | + //计算鱼群规模 | ||
| 253 | + Double[] fishSchoolSizeConfig = OperatingData.cameraConfig.getFishSchoolSizeConfig(); | ||
| 254 | + int grade = 0; | ||
| 255 | + double fishSchoolSize = area*dsTotal[4]; | ||
| 256 | + System.out.println("=======鱼群规模:"+fishSchoolSize+"========="); | ||
| 257 | + for (int i=0;i<fishSchoolSizeConfig.length;i++) | ||
| 258 | + { | ||
| 259 | + if(fishSchoolSize-fishSchoolSizeConfig[i]>0) | ||
| 260 | + { | ||
| 261 | + grade = i+1; | ||
| 262 | + } | ||
| 263 | + } | ||
| 264 | + | ||
| 265 | + if(OperatingData.cameraData.getFishSchoolSize()!=grade) | ||
| 266 | + { | ||
| 267 | + OperatingData.cameraData.setFishSchoolSize(grade); | ||
| 268 | + int finalGrade = grade; | ||
| 269 | + ScheduledConfig.scheduler.schedule(() -> { | ||
| 270 | + | ||
| 271 | + String nowtime = DateUtils.getTime(); | ||
| 272 | + String[] ss = OperatingData.cameraConfig.getFishSchoolSizeConfigString(); | ||
| 273 | + String fishSchoolSizeStr = ss[finalGrade]; | ||
| 274 | + StringBuffer stringBuffer = new StringBuffer(); | ||
| 275 | + stringBuffer.append(nowtime); | ||
| 276 | + stringBuffer.append(" "); | ||
| 277 | + stringBuffer.append(fishSchoolSizeStr); | ||
| 278 | +// stringBuffer.append(",当前档位:"); | ||
| 279 | +// stringBuffer.append(null==OperatingData.cameraData.getNowGear()?0:OperatingData.cameraData.getNowGear()); | ||
| 280 | +// stringBuffer.append("档"); | ||
| 281 | + InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); | ||
| 282 | + | ||
| 283 | + },0, TimeUnit.SECONDS); | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + } | ||
| 287 | + } | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + /** | ||
| 291 | + * 根据斜率计算档位 | ||
| 292 | + * @return | ||
| 293 | + */ | ||
| 294 | + private Integer getGearFromAbsValue() | ||
| 295 | + { | ||
| 296 | + Double absValue = OperatingData.cameraData.getAbsValue(); | ||
| 297 | + if(null == absValue) | ||
| 298 | + { | ||
| 299 | + return 0; | ||
| 300 | + } | ||
| 301 | + Integer gear = OperatingData.cameraData.getNowGear(); | ||
| 302 | + if(null == OperatingData.cameraData.getNowGear()) | ||
| 303 | + { | ||
| 304 | + OperatingData.cameraData.setNowGear(0); | ||
| 305 | + gear = 0; | ||
| 306 | + } | ||
| 307 | + List<FishCurveControlCondition> list = OperatingData.cameraConfig.getAbsValue_command(); | ||
| 308 | + if(null != list && list.size() != 0) | ||
| 309 | + { | ||
| 310 | + list.sort(Comparator.comparing(FishCurveControlCondition::getSartAbsValue));//以 sartAbsValue 升序排序 | ||
| 311 | + | ||
| 312 | + for(FishCurveControlCondition fishCurveControlCondition:list) //根据斜率找到档位 | ||
| 313 | + { | ||
| 314 | + if(absValue>=fishCurveControlCondition.getSartAbsValue()) //向下查找 | ||
| 315 | + { | ||
| 316 | + gear = fishCurveControlCondition.getGear(); | ||
| 317 | + } | ||
| 191 | } | 318 | } |
| 192 | } | 319 | } |
| 320 | + if(OperatingData.cameraData.getNowGear()-gear!=0) | ||
| 321 | + { | ||
| 322 | + OperatingData.cameraData.setNowGear(gear); | ||
| 323 | + | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + return gear; | ||
| 193 | } | 327 | } |
| 194 | 328 | ||
| 195 | private static Mat hsvImage = new Mat(); | 329 | private static Mat hsvImage = new Mat(); |
| 196 | private static Mat grayImage = new Mat(); | 330 | private static Mat grayImage = new Mat(); |
| 197 | - private static Scalar meanGray = Core.mean(grayImage); | ||
| 198 | /** | 331 | /** |
| 199 | * 运算 | 332 | * 运算 |
| 200 | * @param image | 333 | * @param image |
| @@ -215,6 +348,7 @@ public class FishGroupImageRecognitionService { | @@ -215,6 +348,7 @@ public class FishGroupImageRecognitionService { | ||
| 215 | double reflection = minMaxLocResult.maxVal; | 348 | double reflection = minMaxLocResult.maxVal; |
| 216 | 349 | ||
| 217 | // 计算灰度均值 | 350 | // 计算灰度均值 |
| 351 | + Scalar meanGray = Core.mean(grayImage); | ||
| 218 | double meanGrayValue = meanGray.val[0]; | 352 | double meanGrayValue = meanGray.val[0]; |
| 219 | // 将灰度均值映射到0到255范围内作为透明度度量(较低的灰度值表示较高的透明度,反之亦然) | 353 | // 将灰度均值映射到0到255范围内作为透明度度量(较低的灰度值表示较高的透明度,反之亦然) |
| 220 | double transparencyMeasure = 255 - meanGrayValue; | 354 | double transparencyMeasure = 255 - meanGrayValue; |
| @@ -13,7 +13,11 @@ public class InitService { | @@ -13,7 +13,11 @@ public class InitService { | ||
| 13 | 13 | ||
| 14 | public static NettyClient nettyClient; | 14 | public static NettyClient nettyClient; |
| 15 | 15 | ||
| 16 | - public static DeviceService deviceService; | 16 | + public static ScaleStepMethodService scaleStepMethodService; |
| 17 | + | ||
| 18 | + public static DateListenService dateListenService; | ||
| 19 | + | ||
| 20 | + public static FishGroupImageRecognitionService fishGroupImageRecognitionService; | ||
| 17 | /** | 21 | /** |
| 18 | * 加载配置 | 22 | * 加载配置 |
| 19 | */ | 23 | */ |
| @@ -33,7 +37,7 @@ public class InitService { | @@ -33,7 +37,7 @@ public class InitService { | ||
| 33 | * mq远程登录 | 37 | * mq远程登录 |
| 34 | */ | 38 | */ |
| 35 | nettyClient = new NettyClient(); | 39 | nettyClient = new NettyClient(); |
| 36 | - nettyClient.start(); | 40 | + nettyClient.run(); |
| 37 | 41 | ||
| 38 | /** | 42 | /** |
| 39 | * 初始化海康的摄像头 | 43 | * 初始化海康的摄像头 |
| @@ -43,14 +47,16 @@ public class InitService { | @@ -43,14 +47,16 @@ public class InitService { | ||
| 43 | /** | 47 | /** |
| 44 | * 图像识别 | 48 | * 图像识别 |
| 45 | */ | 49 | */ |
| 46 | - new FishGroupImageRecognitionService().run(); | 50 | + fishGroupImageRecognitionService = new FishGroupImageRecognitionService(); |
| 51 | + fishGroupImageRecognitionService.run(); | ||
| 47 | 52 | ||
| 48 | //鱼群图像识别控制投料控制 | 53 | //鱼群图像识别控制投料控制 |
| 49 | - deviceService = new DeviceService(serialPortService); | ||
| 50 | - deviceService.run(); | 54 | + scaleStepMethodService = new ScaleStepMethodService(serialPortService); |
| 55 | + scaleStepMethodService.run(); | ||
| 51 | 56 | ||
| 52 | //数据上报 | 57 | //数据上报 |
| 53 | - new DateListenService(serialPortService).run(); | 58 | + dateListenService = new DateListenService(serialPortService); |
| 59 | + dateListenService.run(); | ||
| 54 | } | 60 | } |
| 55 | 61 | ||
| 56 | } | 62 | } |
| 1 | +package com.zhonglai.luhui.smart.feeder.service; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.DateUtils; | ||
| 4 | +import com.zhonglai.luhui.smart.feeder.config.OperatingData; | ||
| 5 | +import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | ||
| 6 | +import com.zhonglai.luhui.smart.feeder.dto.ModbusDto; | ||
| 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; | ||
| 10 | +import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; | ||
| 11 | + | ||
| 12 | +import java.util.concurrent.ScheduledFuture; | ||
| 13 | +import java.util.concurrent.TimeUnit; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 尺度步长法 | ||
| 17 | + */ | ||
| 18 | +public class ScaleStepMethodService { | ||
| 19 | + private ScheduledFuture scheduledFuture; | ||
| 20 | + | ||
| 21 | + private SerialPortService serialPortService; | ||
| 22 | + | ||
| 23 | + public ScaleStepMethodService(SerialPortService serialPortService) | ||
| 24 | + { | ||
| 25 | + this.serialPortService = serialPortService; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public void run() | ||
| 29 | + { | ||
| 30 | + scheduledFuture = ScheduledConfig.scheduler.scheduleAtFixedRate(() -> { | ||
| 31 | + if( OperatingData.cameraData.getScaleAreaList().size()==0) | ||
| 32 | + { | ||
| 33 | + return; | ||
| 34 | + } | ||
| 35 | + // 使用Java 8流计算列表总和 | ||
| 36 | + double sum = OperatingData.cameraData.getScaleAreaList().stream().mapToDouble(Double::doubleValue).sum(); | ||
| 37 | + OperatingData.cameraData.setScaleAreaSum(sum); | ||
| 38 | + | ||
| 39 | + if(sum - OperatingData.cameraData.getScaleAreaSumMax()>0) | ||
| 40 | + { | ||
| 41 | + OperatingData.cameraData.setScaleAreaSumMax(sum); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + String nowtime = DateUtils.getTime(); | ||
| 45 | + StringBuffer stringBuffer = new StringBuffer(); | ||
| 46 | + stringBuffer.append(nowtime); | ||
| 47 | + stringBuffer.append(" "); | ||
| 48 | + //如果鱼群急剧减少,就停止投料 | ||
| 49 | + if (((OperatingData.cameraData.getScaleAreaSumMax()*OperatingData.cameraConfig.getStopTriggeringConditions())/100)-sum>=0) | ||
| 50 | + { | ||
| 51 | + Condata condata = OperatingData.feederConfig.getCondata(); | ||
| 52 | + | ||
| 53 | + stringBuffer.append("发现鱼群急剧减少,"); | ||
| 54 | + if(null != condata) | ||
| 55 | + { | ||
| 56 | + if( condata.getRunstate()==1) | ||
| 57 | + { | ||
| 58 | + stringBuffer.append("投料机处于运行状态,"); | ||
| 59 | + if (OperatingData.cameraConfig.getFeedingControl()) | ||
| 60 | + { | ||
| 61 | + //发送停止投料指令 | ||
| 62 | + if (serialPortService.isOpen()) | ||
| 63 | + { | ||
| 64 | + serialPortService.sendHexData(FeederCommdUtil.controlData(FeederCommd06ResponseType.OnOroff,0)); | ||
| 65 | + stringBuffer.append("发送停止投料指令,"); | ||
| 66 | + }else{ | ||
| 67 | + stringBuffer.append("投料机串口未打开,无法发送停止投料指令,"); | ||
| 68 | + } | ||
| 69 | + }else { | ||
| 70 | + stringBuffer.append("投料机串口未打开,无法发送停止投料指令,"); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + }else { | ||
| 74 | + stringBuffer.append("鱼群图像识别投料控制未开启,不用操作投料机,"); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + }else { | ||
| 78 | + stringBuffer.append("投料机串口未打开,无法发送停止投料指令,"); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + stringBuffer.append("当前鱼群状态:"); | ||
| 82 | + stringBuffer.append("尺度之内的面积之和:"); | ||
| 83 | + stringBuffer.append(OperatingData.cameraData.getScaleAreaSum()); | ||
| 84 | + stringBuffer.append(",尺度之内的面积之和曲线的峰值:"); | ||
| 85 | + stringBuffer.append(OperatingData.cameraData.getScaleAreaSumMax()); | ||
| 86 | + InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + //如果鱼群急剧增加,。。。 | ||
| 90 | + if (OperatingData.cameraData.getScaleAreaSumMax()-((OperatingData.cameraData.getScaleAreaSumMax()*OperatingData.cameraConfig.getStopTriggeringConditions())/100)-sum>=0) | ||
| 91 | + { | ||
| 92 | + stringBuffer.append("发现鱼群急剧增加,"); | ||
| 93 | + | ||
| 94 | + stringBuffer.append("当前鱼群状态:"); | ||
| 95 | + stringBuffer.append("尺度之内的面积之和:"); | ||
| 96 | + stringBuffer.append(OperatingData.cameraData.getScaleAreaSum()); | ||
| 97 | + stringBuffer.append(",尺度之内的面积之和曲线的峰值:"); | ||
| 98 | + stringBuffer.append(OperatingData.cameraData.getScaleAreaSumMax()); | ||
| 99 | + InitService.dateListenService.reportIntelligentFeeding(stringBuffer.toString()); | ||
| 100 | + } | ||
| 101 | + },0, OperatingData.cameraConfig.getScaleStep(), TimeUnit.SECONDS); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + public void stop() | ||
| 105 | + { | ||
| 106 | + scheduledFuture.cancel(true); | ||
| 107 | + while (!scheduledFuture.isCancelled()) | ||
| 108 | + { | ||
| 109 | + try { | ||
| 110 | + Thread.sleep(1000); | ||
| 111 | + } catch (InterruptedException e) { | ||
| 112 | + throw new RuntimeException(e); | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + } | ||
| 116 | +} |
| @@ -2,6 +2,7 @@ package com.zhonglai.luhui.smart.feeder.service; | @@ -2,6 +2,7 @@ package com.zhonglai.luhui.smart.feeder.service; | ||
| 2 | 2 | ||
| 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.draw.FishRegionPanel; | 6 | import com.zhonglai.luhui.smart.feeder.draw.FishRegionPanel; |
| 6 | import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; | 7 | import com.zhonglai.luhui.smart.feeder.dto.VeiwDto; |
| 7 | import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil; | 8 | import com.zhonglai.luhui.smart.feeder.opencv.OpenCVUtil; |
| @@ -27,19 +28,12 @@ import java.util.List; | @@ -27,19 +28,12 @@ import java.util.List; | ||
| 27 | import java.util.concurrent.ScheduledExecutorService; | 28 | import java.util.concurrent.ScheduledExecutorService; |
| 28 | import java.util.concurrent.TimeUnit; | 29 | import java.util.concurrent.TimeUnit; |
| 29 | 30 | ||
| 30 | -@Service | ||
| 31 | public class SrsService { | 31 | public class SrsService { |
| 32 | private static final Logger log = LoggerFactory.getLogger(SrsService.class); | 32 | private static final Logger log = LoggerFactory.getLogger(SrsService.class); |
| 33 | 33 | ||
| 34 | private static final String MP4_FILE_PATH = "C:\\Users\\123\\Pictures\\2.mp4"; | 34 | private static final String MP4_FILE_PATH = "C:\\Users\\123\\Pictures\\2.mp4"; |
| 35 | - @Value("${sys.srs_push_address}") | ||
| 36 | - private String SRS_PUSH_ADDRESS; | 35 | + private static String SRS_PUSH_ADDRESS = "rtmp://119.23.218.181:21935/live/"; |
| 37 | // private String SRS_PUSH_ADDRESS="rtmp://119.23.218.181:21935/live/70094a59d1d991d"; | 36 | // private String SRS_PUSH_ADDRESS="rtmp://119.23.218.181:21935/live/70094a59d1d991d"; |
| 38 | - @Autowired | ||
| 39 | - private ScheduledExecutorService scheduledExecutorService; | ||
| 40 | - | ||
| 41 | - @Autowired | ||
| 42 | - private FishGroupImageRecognitionService fishGroupImageRecognitionService; | ||
| 43 | 37 | ||
| 44 | private FFmpegFrameRecorder recorder; | 38 | private FFmpegFrameRecorder recorder; |
| 45 | 39 | ||
| @@ -49,34 +43,22 @@ public class SrsService { | @@ -49,34 +43,22 @@ public class SrsService { | ||
| 49 | return converter.convert(frame); | 43 | return converter.convert(frame); |
| 50 | } | 44 | } |
| 51 | 45 | ||
| 52 | - | ||
| 53 | private boolean isPush = false; | 46 | private boolean isPush = false; |
| 54 | private boolean displaySrc = false; | 47 | private boolean displaySrc = false; |
| 55 | private int endTime = 0; | 48 | private int endTime = 0; |
| 56 | 49 | ||
| 57 | - public boolean isDisplaySrc() { | ||
| 58 | - return displaySrc; | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - public void setDisplaySrc(boolean displaySrc) { | ||
| 62 | - this.displaySrc = displaySrc; | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | public void run(int time) throws Exception { | 50 | public void run(int time) throws Exception { |
| 66 | endTime = DateUtils.getNowTimeMilly()+time; | 51 | endTime = DateUtils.getNowTimeMilly()+time; |
| 67 | if(!isPush) | 52 | if(!isPush) |
| 68 | { | 53 | { |
| 69 | isPush = true; | 54 | isPush = true; |
| 70 | init(640,480+200); | 55 | init(640,480+200); |
| 71 | -// scheduledExecutorService.schedule(() -> { | ||
| 72 | -// while (endTime-DateUtils.getNowTimeMilly()>0) | ||
| 73 | -// { | ||
| 74 | -// Mat mat = drawChart(fishGroupImageRecognitionService.getVeiwDto().getFrame(),fishGroupImageRecognitionService.getVeiwDto().getAbsValue()); | ||
| 75 | -// push(mat); | ||
| 76 | -// mat.release(); | ||
| 77 | -// } | ||
| 78 | -// stop(); | ||
| 79 | -// },1, TimeUnit.SECONDS); | 56 | + } |
| 57 | + if(endTime-DateUtils.getNowTimeMilly()>0) | ||
| 58 | + { | ||
| 59 | + | ||
| 60 | + }else { | ||
| 61 | + stop(); | ||
| 80 | } | 62 | } |
| 81 | } | 63 | } |
| 82 | public void stop() | 64 | public void stop() |
| @@ -86,21 +68,6 @@ public class SrsService { | @@ -86,21 +68,6 @@ public class SrsService { | ||
| 86 | close(); | 68 | close(); |
| 87 | } | 69 | } |
| 88 | 70 | ||
| 89 | - public void timepush(Mat frame,Double absValue) | ||
| 90 | - { | ||
| 91 | - if(isPush) | ||
| 92 | - { | ||
| 93 | - if(endTime-DateUtils.getNowTimeMilly()>0) | ||
| 94 | - { | ||
| 95 | - Mat mat = drawChart(frame,absValue); | ||
| 96 | - push(mat); | ||
| 97 | - mat.release(); | ||
| 98 | - }else { | ||
| 99 | - stop(); | ||
| 100 | - } | ||
| 101 | - } | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | 71 | ||
| 105 | public SrsService init(int frameWidth,int frameHeight) throws Exception | 72 | public SrsService init(int frameWidth,int frameHeight) throws Exception |
| 106 | { | 73 | { |
| @@ -110,7 +77,7 @@ public class SrsService { | @@ -110,7 +77,7 @@ public class SrsService { | ||
| 110 | ); | 77 | ); |
| 111 | 78 | ||
| 112 | // 实例化FFmpegFrameRecorder,将SRS的推送地址传入 | 79 | // 实例化FFmpegFrameRecorder,将SRS的推送地址传入 |
| 113 | - recorder = new FFmpegFrameRecorder(SRS_PUSH_ADDRESS, | 80 | + recorder = new FFmpegFrameRecorder(SRS_PUSH_ADDRESS+ OperatingData.sysConfig.getNettyConfig().getClientId(), |
| 114 | frameWidth, | 81 | frameWidth, |
| 115 | frameHeight); | 82 | frameHeight); |
| 116 | 83 | ||
| @@ -124,64 +91,12 @@ public class SrsService { | @@ -124,64 +91,12 @@ public class SrsService { | ||
| 124 | // 调用av_guess_format方法,确定视频输出时的封装方式, | 91 | // 调用av_guess_format方法,确定视频输出时的封装方式, |
| 125 | // 媒体上下文对象的内存分配, | 92 | // 媒体上下文对象的内存分配, |
| 126 | // 编码器的各项参数设置 | 93 | // 编码器的各项参数设置 |
| 127 | - recorder.start(); | 94 | + recorder.setCloseOutputStream(true); |
| 128 | 95 | ||
| 96 | + recorder.start(); | ||
| 129 | return this; | 97 | return this; |
| 130 | } | 98 | } |
| 131 | 99 | ||
| 132 | - public Mat drawChart(Mat src,double area) | ||
| 133 | - { | ||
| 134 | - // 创建一个新的Mat对象,它的高度为200,它的宽度与原来的Mat对象相同 | ||
| 135 | - Mat curveArea = Mat.zeros(200, src.cols(), src.type()); | ||
| 136 | - | ||
| 137 | - // 计算曲线的y坐标 | ||
| 138 | - int y = (int) (200 - (area * 200) / (src.cols() * src.rows())); | ||
| 139 | - | ||
| 140 | - System.out.println(y); | ||
| 141 | - // 声明曲线的控制点 | ||
| 142 | - MatOfPoint curve = new MatOfPoint(); | ||
| 143 | - | ||
| 144 | - // 创建曲线的控制点数组 | ||
| 145 | - List<Point> points = addPoint(curveArea,area); | ||
| 146 | - | ||
| 147 | - // 将控制点数组设置给曲线 | ||
| 148 | - Point[] pointArray = points.toArray(new Point[0]); | ||
| 149 | - curve.fromArray(pointArray); | ||
| 150 | - | ||
| 151 | - // 绘制曲线 | ||
| 152 | - List<MatOfPoint> curveList = new ArrayList<>(); | ||
| 153 | - curveList.add(curve); | ||
| 154 | - Imgproc.polylines(curveArea, curveList, false, new Scalar(255, 255, 255), 2); | ||
| 155 | - | ||
| 156 | - // 将curveArea拼接到原来的Mat对象上 | ||
| 157 | - Mat pushmat = new Mat(); | ||
| 158 | - List<Mat> mats = new ArrayList<>(); | ||
| 159 | - | ||
| 160 | - if(displaySrc) | ||
| 161 | - { | ||
| 162 | - mats.add(src); | ||
| 163 | - } | ||
| 164 | - | ||
| 165 | - mats.add(curveArea); | ||
| 166 | - Core.vconcat(mats, pushmat); | ||
| 167 | - | ||
| 168 | - // 文字位置 | ||
| 169 | - Point org = new Point(50, 50); | ||
| 170 | - // 字体类型 | ||
| 171 | - int fontFace = Imgproc.FONT_HERSHEY_SIMPLEX; | ||
| 172 | - // 字体比例 | ||
| 173 | - double fontScale = 1; | ||
| 174 | - // 文字颜色(黑色) | ||
| 175 | - Scalar color = new Scalar(139, 0, 139); | ||
| 176 | - // 添加文字 | ||
| 177 | - Imgproc.putText(pushmat, "area:"+area, org, fontFace, fontScale, color); | ||
| 178 | - | ||
| 179 | - curveArea.release(); | ||
| 180 | - curve.release(); | ||
| 181 | - | ||
| 182 | - return pushmat; | ||
| 183 | - } | ||
| 184 | - | ||
| 185 | public void push(Mat pushmat) { | 100 | public void push(Mat pushmat) { |
| 186 | OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); | 101 | OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); |
| 187 | Frame frame = converter.convert(pushmat); | 102 | Frame frame = converter.convert(pushmat); |
| @@ -204,151 +119,12 @@ public class SrsService { | @@ -204,151 +119,12 @@ public class SrsService { | ||
| 204 | { | 119 | { |
| 205 | // 关闭帧录制器 | 120 | // 关闭帧录制器 |
| 206 | try { | 121 | try { |
| 122 | + recorder.release(); | ||
| 207 | recorder.close(); | 123 | recorder.close(); |
| 208 | } catch (FrameRecorder.Exception e) { | 124 | } catch (FrameRecorder.Exception e) { |
| 209 | throw new RuntimeException(e); | 125 | throw new RuntimeException(e); |
| 210 | } | 126 | } |
| 211 | - recorder = null; | ||
| 212 | - } | ||
| 213 | - | ||
| 214 | - } | ||
| 215 | - // 创建一个MatOfPoint对象来表示曲线 | ||
| 216 | - private List<Integer> listArea = new ArrayList<>(); | ||
| 217 | - | ||
| 218 | - /** | ||
| 219 | - * 根据反光查找水面 | ||
| 220 | - * @return | ||
| 221 | - */ | ||
| 222 | - public Mat fish(Mat src) { | ||
| 223 | - | ||
| 224 | - //读取和预处理图像 | ||
| 225 | - Mat gray = new Mat(); | ||
| 226 | - Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY); // 转为灰度图像 | ||
| 227 | - | ||
| 228 | - //水面反射检测 | ||
| 229 | - Mat threshold = new Mat(); | ||
| 230 | - double maxValue = 255; // 阈值 | ||
| 231 | - Imgproc.threshold(gray, threshold,100, maxValue, Imgproc.THRESH_BINARY); // 阈值化 | ||
| 232 | - | ||
| 233 | - //鱼群检测 | ||
| 234 | - Mat hierarchy = new Mat(); | ||
| 235 | - List<MatOfPoint> contours = new ArrayList<>(); | ||
| 236 | - Imgproc.findContours(threshold, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); // 寻找轮廓 | ||
| 237 | - | ||
| 238 | - //计算鱼群区域大小 | ||
| 239 | - double area = getArea(contours); | ||
| 240 | - | ||
| 241 | - Mat mat = drawChart(src,area); | ||
| 242 | - | ||
| 243 | - return mat; | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | - private static Image convertMatToImage(Mat mat) { | ||
| 247 | - BufferedImage bufferedImage = OpenCVUtils.matToBufferedImage(mat); | ||
| 248 | - return bufferedImage.getScaledInstance(mat.width(), mat.height(), Image.SCALE_SMOOTH); | ||
| 249 | - } | ||
| 250 | - | ||
| 251 | - int maxSize = 100; | ||
| 252 | - | ||
| 253 | - private List<Point> addPoint(Mat src, double area) | ||
| 254 | - { | ||
| 255 | - int panelWidth = src.width(); | ||
| 256 | - int panelHeight = src.height(); | ||
| 257 | - if(listArea.size()==maxSize) | ||
| 258 | - { | ||
| 259 | - listArea.remove(0); | ||
| 260 | - } | ||
| 261 | - | ||
| 262 | - int max = new Double(area).intValue(); | ||
| 263 | - int min = new Double(area).intValue(); | ||
| 264 | - if(listArea.size()>0) | ||
| 265 | - { | ||
| 266 | - max = listArea.stream().max(Integer::compare).get(); | ||
| 267 | - min = listArea.stream().min(Integer::compare).get(); | ||
| 268 | - } | ||
| 269 | - | ||
| 270 | - List<Point> points= new ArrayList<>(); | ||
| 271 | - | ||
| 272 | - for (int i = 0; i < listArea.size(); i++) { | ||
| 273 | - int dataPoint = listArea.get(i); | ||
| 274 | - int x = (int) ((double) i / listArea.size() * panelWidth); | ||
| 275 | - int y = (int) ((double) (dataPoint - min) / (max - min) * panelHeight); | ||
| 276 | - | ||
| 277 | - if (i != 0) { | ||
| 278 | - points.add(new Point(x,y)); | ||
| 279 | - } | ||
| 280 | } | 127 | } |
| 281 | - listArea.add(new Double(area).intValue()); | ||
| 282 | - return points; | ||
| 283 | - | ||
| 284 | - } | ||
| 285 | - | ||
| 286 | - /** | ||
| 287 | - * 计算鱼群面积 | ||
| 288 | - * @param contours | ||
| 289 | - * @return | ||
| 290 | - */ | ||
| 291 | - private double getArea(List<MatOfPoint> contours) { | ||
| 292 | - // 找到最大区域 | ||
| 293 | - double maxArea = 0; | ||
| 294 | - int maxAreaIndex = -1; | ||
| 295 | - double allArea = 0; | ||
| 296 | - for (int i = 0; i < contours.size(); i++) { | ||
| 297 | - double area = Imgproc.contourArea(contours.get(i)); | ||
| 298 | - if (area > maxArea) { | ||
| 299 | - maxArea = area; | ||
| 300 | - maxAreaIndex = i; | ||
| 301 | - } | ||
| 302 | - allArea += area; | ||
| 303 | - } | ||
| 304 | - | ||
| 305 | - //删除最大 | ||
| 306 | - if(-1 != maxAreaIndex) | ||
| 307 | - { | ||
| 308 | - contours.remove(maxAreaIndex); | ||
| 309 | - } | ||
| 310 | - | ||
| 311 | - // 返回总面积 | ||
| 312 | - return allArea; | ||
| 313 | - } | ||
| 314 | - | ||
| 315 | - | ||
| 316 | - public static void main(String[] args) { | ||
| 317 | -// OpenCVConfig.loadOpenCv(args); | ||
| 318 | -// SrsService srsService = new SrsService(); | ||
| 319 | -// FishRegionPanel fishRegionPanel = new FishRegionPanel(); | ||
| 320 | -// int i=0; | ||
| 321 | -// while (i++<10) | ||
| 322 | -// { | ||
| 323 | -// VideoCapture videoCapture = OpenCVUtil.readVideoCaptureForVideo(""); | ||
| 324 | -// Mat previousFrame = new Mat(); | ||
| 325 | -// if (!videoCapture.read(previousFrame)) { | ||
| 326 | -// System.out.println("无法读取视频帧"); | ||
| 327 | -// return; | ||
| 328 | -// } | ||
| 329 | -// | ||
| 330 | -// try { | ||
| 331 | -// if(null == srsService.recorder || !srsService.recorder.isInterleaved()) | ||
| 332 | -// { | ||
| 333 | -// srsService.init(previousFrame.width(),previousFrame.height()); | ||
| 334 | -// } | ||
| 335 | -// } catch (Exception e) { | ||
| 336 | -// throw new RuntimeException(e); | ||
| 337 | -// } | ||
| 338 | -// | ||
| 339 | -// Mat src = new Mat(); | ||
| 340 | -// while (videoCapture.read(src)) | ||
| 341 | -// { | ||
| 342 | -// Mat mat = srsService.fish(src); | ||
| 343 | -// fishRegionPanel.getLblImage().setIcon(new ImageIcon(convertMatToImage(mat))); | ||
| 344 | -// fishRegionPanel.getFrame().repaint(); | ||
| 345 | -// OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); | ||
| 346 | -// Frame frame = converter.convert(mat); | ||
| 347 | -// srsService.push(frame); | ||
| 348 | -// } | ||
| 349 | -// | ||
| 350 | -// } | ||
| 351 | -// srsService.close(); | ||
| 352 | 128 | ||
| 353 | } | 129 | } |
| 354 | } | 130 | } |
| @@ -65,6 +65,15 @@ public class SerialPortService { | @@ -65,6 +65,15 @@ public class SerialPortService { | ||
| 65 | 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。 | 65 | 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。 |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | + public boolean isOpen() | ||
| 69 | + { | ||
| 70 | + if(null != serialPort && serialPort.isOpen()) | ||
| 71 | + { | ||
| 72 | + return true; | ||
| 73 | + } | ||
| 74 | + return false; | ||
| 75 | + } | ||
| 76 | + | ||
| 68 | public boolean open() | 77 | public boolean open() |
| 69 | { | 78 | { |
| 70 | if(null == serialPort || !serialPort.isOpen()) | 79 | if(null == serialPort || !serialPort.isOpen()) |
| @@ -30,6 +30,8 @@ public class CameraRtspHandle implements CameraHandle { | @@ -30,6 +30,8 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 30 | 30 | ||
| 31 | public static Mat mat; | 31 | public static Mat mat; |
| 32 | 32 | ||
| 33 | + private boolean isclose = false; | ||
| 34 | + | ||
| 33 | public CameraRtspHandle() | 35 | public CameraRtspHandle() |
| 34 | { | 36 | { |
| 35 | init(); | 37 | init(); |
| @@ -38,6 +40,7 @@ public class CameraRtspHandle implements CameraHandle { | @@ -38,6 +40,7 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 38 | 40 | ||
| 39 | @Override | 41 | @Override |
| 40 | public boolean init() { | 42 | public boolean init() { |
| 43 | + | ||
| 41 | if(isOpen()) | 44 | if(isOpen()) |
| 42 | { | 45 | { |
| 43 | return true; | 46 | return true; |
| @@ -72,8 +75,9 @@ public class CameraRtspHandle implements CameraHandle { | @@ -72,8 +75,9 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 72 | } | 75 | } |
| 73 | converter2 = new OpenCVFrameConverter.ToOrgOpenCvCoreMat(); | 76 | converter2 = new OpenCVFrameConverter.ToOrgOpenCvCoreMat(); |
| 74 | Thread.sleep(3000); | 77 | Thread.sleep(3000); |
| 78 | + isclose = false; | ||
| 75 | Thread thread = new Thread(() -> { | 79 | Thread thread = new Thread(() -> { |
| 76 | - while (isOpen()) { | 80 | + while (isOpen() && !isclose) { |
| 77 | try { | 81 | try { |
| 78 | mat = getMat(); | 82 | mat = getMat(); |
| 79 | } catch (Exception e) { | 83 | } catch (Exception e) { |
| @@ -82,7 +86,6 @@ public class CameraRtspHandle implements CameraHandle { | @@ -82,7 +86,6 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 82 | } | 86 | } |
| 83 | }); | 87 | }); |
| 84 | thread.start(); | 88 | thread.start(); |
| 85 | - | ||
| 86 | return true; | 89 | return true; |
| 87 | } catch (Exception e) { | 90 | } catch (Exception e) { |
| 88 | logger.error("摄像头初始化失败",e); | 91 | logger.error("摄像头初始化失败",e); |
| @@ -91,9 +94,10 @@ public class CameraRtspHandle implements CameraHandle { | @@ -91,9 +94,10 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | private boolean iniLocal() throws FFmpegFrameGrabber.Exception, InterruptedException { | 96 | private boolean iniLocal() throws FFmpegFrameGrabber.Exception, InterruptedException { |
| 94 | - File file = new File("2.pm4"); | 97 | + File file = new File("2.mp4"); |
| 95 | if(!file.exists()) | 98 | if(!file.exists()) |
| 96 | { | 99 | { |
| 100 | + logger.info("{}未找到",file.getAbsolutePath()); | ||
| 97 | return false; | 101 | return false; |
| 98 | } | 102 | } |
| 99 | grabber = new FFmpegFrameGrabber(file); | 103 | grabber = new FFmpegFrameGrabber(file); |
| @@ -187,22 +191,32 @@ public class CameraRtspHandle implements CameraHandle { | @@ -187,22 +191,32 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 187 | } | 191 | } |
| 188 | 192 | ||
| 189 | private Frame getFrame() { | 193 | private Frame getFrame() { |
| 190 | - Frame frame = null; | ||
| 191 | - try { | ||
| 192 | - frame = grabber.grabImage(); | ||
| 193 | - if (frame == null || frame.imageHeight==0) { | ||
| 194 | - //TODO:连续n次为null,进行重连 | ||
| 195 | - logger.info("读取不到画面,当前grabber状态:hasAudio {},hasVideo {},isCloseInputStream {},isDeinterlace {},isTriggerMode {}",grabber.hasAudio(),grabber.hasVideo(),grabber.isCloseInputStream(),grabber.isDeinterlace(),grabber.isTriggerMode()); | 194 | + if(isOpen()) |
| 195 | + { | ||
| 196 | + Frame frame = null; | ||
| 197 | + try { | ||
| 198 | + frame = grabber.grabImage(); | ||
| 199 | + | ||
| 200 | + if (frame == null || frame.imageHeight==0) { | ||
| 201 | + if(null == frame && OperatingData.cameraConfig.getCameraInterfaceType().toLowerCase().equals("local")) | ||
| 202 | + { | ||
| 203 | + grabber.restart(); | ||
| 204 | + frame = grabber.grabImage(); | ||
| 205 | + return frame; | ||
| 206 | + } | ||
| 207 | + //TODO:连续n次为null,进行重连 | ||
| 208 | + logger.info("读取不到画面,当前grabber状态:hasAudio {},hasVideo {},isCloseInputStream {},isDeinterlace {},isTriggerMode {}",grabber.hasAudio(),grabber.hasVideo(),grabber.isCloseInputStream(),grabber.isDeinterlace(),grabber.isTriggerMode()); | ||
| 209 | + return null; | ||
| 210 | + } | ||
| 211 | + else{ | ||
| 212 | + return frame; | ||
| 213 | + } | ||
| 214 | + } catch (Exception e) { | ||
| 215 | + logger.error("抓取摄像头帧失败",e); | ||
| 196 | return null; | 216 | return null; |
| 197 | } | 217 | } |
| 198 | - else{ | ||
| 199 | - return frame; | ||
| 200 | - } | ||
| 201 | - } catch (Exception e) { | ||
| 202 | - logger.error("抓取摄像头帧失败",e); | ||
| 203 | - return null; | ||
| 204 | } | 218 | } |
| 205 | - | 219 | + return null; |
| 206 | } | 220 | } |
| 207 | 221 | ||
| 208 | public Frame compress(Frame frame) | 222 | public Frame compress(Frame frame) |
| @@ -223,13 +237,21 @@ public class CameraRtspHandle implements CameraHandle { | @@ -223,13 +237,21 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 223 | if(grabber.hasAudio() && grabber.hasVideo()) | 237 | if(grabber.hasAudio() && grabber.hasVideo()) |
| 224 | { | 238 | { |
| 225 | try { | 239 | try { |
| 226 | - Frame filteredFrame = compress(grabber.grabImage()); | 240 | + Frame frame = grabber.grabImage(); |
| 241 | + if(null == frame) | ||
| 242 | + { | ||
| 243 | + grabber.restart(); | ||
| 244 | + frame = grabber.grabImage(); | ||
| 245 | + } | ||
| 246 | + Frame filteredFrame = compress(frame); | ||
| 227 | if(null != filteredFrame) | 247 | if(null != filteredFrame) |
| 228 | { | 248 | { |
| 229 | pushVideo.display(filteredFrame); | 249 | pushVideo.display(filteredFrame); |
| 230 | } | 250 | } |
| 231 | } catch (FFmpegFrameGrabber.Exception e) { | 251 | } catch (FFmpegFrameGrabber.Exception e) { |
| 232 | logger.info("无法显示"); | 252 | logger.info("无法显示"); |
| 253 | + } catch (FrameGrabber.Exception e) { | ||
| 254 | + throw new RuntimeException(e); | ||
| 233 | } | 255 | } |
| 234 | } | 256 | } |
| 235 | 257 | ||
| @@ -349,6 +371,7 @@ public class CameraRtspHandle implements CameraHandle { | @@ -349,6 +371,7 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 349 | } | 371 | } |
| 350 | } | 372 | } |
| 351 | 373 | ||
| 374 | + | ||
| 352 | private static String getCameraIp(String ip) throws Exception { | 375 | private static String getCameraIp(String ip) throws Exception { |
| 353 | // 1.创建组播socket,加入指定的组播地址和端口 | 376 | // 1.创建组播socket,加入指定的组播地址和端口 |
| 354 | InetAddress group = InetAddress.getByName("239.255.255.250"); | 377 | InetAddress group = InetAddress.getByName("239.255.255.250"); |
| @@ -394,6 +417,12 @@ public class CameraRtspHandle implements CameraHandle { | @@ -394,6 +417,12 @@ public class CameraRtspHandle implements CameraHandle { | ||
| 394 | 417 | ||
| 395 | public void close() | 418 | public void close() |
| 396 | { | 419 | { |
| 420 | + isclose = true; | ||
| 421 | + try { | ||
| 422 | + Thread.sleep(1000); | ||
| 423 | + } catch (InterruptedException e) { | ||
| 424 | + throw new RuntimeException(e); | ||
| 425 | + } | ||
| 397 | if(null != grabber) | 426 | if(null != grabber) |
| 398 | { | 427 | { |
| 399 | try { | 428 | try { |
| @@ -10,6 +10,8 @@ import com.zhonglai.luhui.smart.feeder.util.MessageUtil; | @@ -10,6 +10,8 @@ import com.zhonglai.luhui.smart.feeder.util.MessageUtil; | ||
| 10 | import io.netty.channel.ChannelHandlerContext; | 10 | import io.netty.channel.ChannelHandlerContext; |
| 11 | import io.netty.handler.codec.MessageToMessageDecoder; | 11 | import io.netty.handler.codec.MessageToMessageDecoder; |
| 12 | import org.apache.commons.lang3.StringUtils; | 12 | import org.apache.commons.lang3.StringUtils; |
| 13 | +import org.slf4j.Logger; | ||
| 14 | +import org.slf4j.LoggerFactory; | ||
| 13 | 15 | ||
| 14 | import java.util.List; | 16 | import java.util.List; |
| 15 | import java.util.regex.Matcher; | 17 | import java.util.regex.Matcher; |
| @@ -19,6 +21,9 @@ import java.util.regex.Pattern; | @@ -19,6 +21,9 @@ import java.util.regex.Pattern; | ||
| 19 | * 协议解析 | 21 | * 协议解析 |
| 20 | */ | 22 | */ |
| 21 | public class AgreementHandler extends MessageToMessageDecoder<String> { | 23 | public class AgreementHandler extends MessageToMessageDecoder<String> { |
| 24 | + | ||
| 25 | + private static final Logger logger = LoggerFactory.getLogger(AgreementHandler.class); | ||
| 26 | + | ||
| 22 | private CfgdataService cfgdataService = new CfgdataService(); | 27 | private CfgdataService cfgdataService = new CfgdataService(); |
| 23 | private ManualcontrolService manualcontrolService = new ManualcontrolService(); | 28 | private ManualcontrolService manualcontrolService = new ManualcontrolService(); |
| 24 | 29 | ||
| @@ -33,6 +38,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | @@ -33,6 +38,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | ||
| 33 | 38 | ||
| 34 | @Override | 39 | @Override |
| 35 | public void channelActive(ChannelHandlerContext ctx) throws Exception { | 40 | public void channelActive(ChannelHandlerContext ctx) throws Exception { |
| 41 | + logger.info("设备上线"); | ||
| 36 | nettyClient.setCtx(ctx); | 42 | nettyClient.setCtx(ctx); |
| 37 | // 连接建立时的处理,发送请求注册消息给服务器 | 43 | // 连接建立时的处理,发送请求注册消息给服务器 |
| 38 | JsonObject jsonObject = new JsonObject(); | 44 | JsonObject jsonObject = new JsonObject(); |
| @@ -42,11 +48,8 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | @@ -42,11 +48,8 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | ||
| 42 | } | 48 | } |
| 43 | 49 | ||
| 44 | @Override | 50 | @Override |
| 45 | - public void channelInactive(ChannelHandlerContext ctx) throws Exception { | ||
| 46 | - Thread.sleep(3000); | ||
| 47 | - nettyClient.close(); | ||
| 48 | - Thread.sleep(3000); | ||
| 49 | - nettyClient.start(); | 51 | + public void channelInactive(ChannelHandlerContext ctx) { |
| 52 | + logger.info("设备离线"); | ||
| 50 | } | 53 | } |
| 51 | 54 | ||
| 52 | private static boolean checkAgreement(String data) | 55 | private static boolean checkAgreement(String data) |
| @@ -65,7 +68,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | @@ -65,7 +68,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | ||
| 65 | @Override | 68 | @Override |
| 66 | protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception { | 69 | protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception { |
| 67 | try { | 70 | try { |
| 68 | - System.out.println("读取到数据:"+msg); | 71 | + logger.info("读取到数据:{}",msg); |
| 69 | if(StringUtils.isNotBlank(msg) && checkAgreement(msg)) | 72 | if(StringUtils.isNotBlank(msg) && checkAgreement(msg)) |
| 70 | { | 73 | { |
| 71 | CmdDto cmdDto = new CmdDto(msg); | 74 | CmdDto cmdDto = new CmdDto(msg); |
| @@ -92,6 +95,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | @@ -92,6 +95,7 @@ public class AgreementHandler extends MessageToMessageDecoder<String> { | ||
| 92 | } | 95 | } |
| 93 | }catch (Exception e) | 96 | }catch (Exception e) |
| 94 | { | 97 | { |
| 98 | + logger.error("读取数据异常",e); | ||
| 95 | } | 99 | } |
| 96 | } | 100 | } |
| 97 | } | 101 | } |
| @@ -3,14 +3,11 @@ package com.zhonglai.luhui.smart.feeder.service.feeder; | @@ -3,14 +3,11 @@ package com.zhonglai.luhui.smart.feeder.service.feeder; | ||
| 3 | import com.google.gson.JsonObject; | 3 | 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.CameraConfig; | ||
| 7 | import com.zhonglai.luhui.smart.feeder.dto.commd.FeederBackstateTtpe; | 6 | import com.zhonglai.luhui.smart.feeder.dto.commd.FeederBackstateTtpe; |
| 8 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CameracontrolRequest; | 7 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CameracontrolRequest; |
| 9 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; | 8 | import com.zhonglai.luhui.smart.feeder.dto.mqtt.CmdDto; |
| 10 | import com.zhonglai.luhui.smart.feeder.service.InitService; | 9 | import com.zhonglai.luhui.smart.feeder.service.InitService; |
| 11 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; | 10 | import com.zhonglai.luhui.smart.feeder.service.device.handle.CameraRtspHandle; |
| 12 | -import com.zhonglai.luhui.smart.feeder.util.FeederCommd06ResponseType; | ||
| 13 | -import com.zhonglai.luhui.smart.feeder.util.FeederCommdUtil; | ||
| 14 | import com.zhonglai.luhui.smart.feeder.util.MessageUtil; | 11 | import com.zhonglai.luhui.smart.feeder.util.MessageUtil; |
| 15 | import io.netty.channel.ChannelHandlerContext; | 12 | import io.netty.channel.ChannelHandlerContext; |
| 16 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| @@ -21,34 +18,53 @@ public class CameracontrolService { | @@ -21,34 +18,53 @@ public class CameracontrolService { | ||
| 21 | private static final Logger logger = LoggerFactory.getLogger(CameracontrolService.class); | 18 | private static final Logger logger = LoggerFactory.getLogger(CameracontrolService.class); |
| 22 | public void noticeFeeder(ChannelHandlerContext ctx,CmdDto cmdDto) | 19 | public void noticeFeeder(ChannelHandlerContext ctx,CmdDto cmdDto) |
| 23 | { | 20 | { |
| 24 | - if(!InitService.cameraHandle.isOpen()) | 21 | + if(null != InitService.cameraHandle && !InitService.cameraHandle.isOpen()) |
| 25 | { | 22 | { |
| 26 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.cameraErr,0); | 23 | + MessageUtil.sendFeederResponseMessage(ctx,"cameracontrolOK", FeederBackstateTtpe.cameraErr,0); |
| 27 | return; | 24 | return; |
| 28 | } | 25 | } |
| 29 | 26 | ||
| 30 | JsonObject data = cmdDto.getJsonObject(); | 27 | JsonObject data = cmdDto.getJsonObject(); |
| 31 | if (null == data || data.size()==0) | 28 | if (null == data || data.size()==0) |
| 32 | { | 29 | { |
| 33 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0xE2); | 30 | + MessageUtil.sendFeederResponseMessage(ctx,"cameracontrolOK", FeederBackstateTtpe.success,0xE2); |
| 34 | return; | 31 | return; |
| 35 | } | 32 | } |
| 36 | 33 | ||
| 37 | try { | 34 | try { |
| 38 | CameracontrolRequest cameracontrolRequest = GsonConstructor.get().fromJson(data.toString(), CameracontrolRequest.class); | 35 | CameracontrolRequest cameracontrolRequest = GsonConstructor.get().fromJson(data.toString(), CameracontrolRequest.class); |
| 39 | - OperatingData.setClassObjecValue(cameracontrolRequest.getCameraConfig(), (fieldname, fieldObject) -> { | ||
| 40 | - switch (fieldname) | ||
| 41 | - { | ||
| 42 | - case "cameraInterfaceType": | ||
| 43 | - ((CameraRtspHandle)InitService.cameraHandle).close(); | ||
| 44 | - InitService.cameraHandle.init(); | ||
| 45 | - break; | ||
| 46 | - } | ||
| 47 | - }); | ||
| 48 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0); | 36 | + if(null != cameracontrolRequest.getCameraConfig()) |
| 37 | + { | ||
| 38 | + OperatingData.setClassObjecValue(cameracontrolRequest.getCameraConfig(), (fieldname, fieldObject) -> { | ||
| 39 | + switch (fieldname) | ||
| 40 | + { | ||
| 41 | + case "cameraInterfaceType": | ||
| 42 | + InitService.fishGroupImageRecognitionService.stop(); | ||
| 43 | + InitService.scaleStepMethodService.stop(); | ||
| 44 | + | ||
| 45 | + ((CameraRtspHandle)InitService.cameraHandle).close(); | ||
| 46 | + if(InitService.cameraHandle.init()) | ||
| 47 | + { | ||
| 48 | + InitService.fishGroupImageRecognitionService.run(); | ||
| 49 | + InitService.scaleStepMethodService.run(); | ||
| 50 | + } | ||
| 51 | + break; | ||
| 52 | + case "scaleStep": | ||
| 53 | + InitService.scaleStepMethodService.stop(); | ||
| 54 | + InitService.scaleStepMethodService.run(); | ||
| 55 | + break; | ||
| 56 | + } | ||
| 57 | + }); | ||
| 58 | + } | ||
| 59 | + if(null != cameracontrolRequest.getIs_push_camera() && 0!=cameracontrolRequest.getIs_push_camera()) | ||
| 60 | + { | ||
| 61 | + InitService.fishGroupImageRecognitionService.startPushimg(cameracontrolRequest.getIs_push_camera()*60); | ||
| 62 | + OperatingData.cameraData.set_push_camera(true); | ||
| 63 | + } | ||
| 64 | + MessageUtil.sendFeederResponseMessage(ctx,"cameracontrolOK", FeederBackstateTtpe.success,0); | ||
| 49 | }catch (Exception e) | 65 | }catch (Exception e) |
| 50 | { | 66 | { |
| 51 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.runErr,0); | 67 | + MessageUtil.sendFeederResponseMessage(ctx,"cameracontrolOK", FeederBackstateTtpe.runErr,0); |
| 52 | } | 68 | } |
| 53 | } | 69 | } |
| 54 | 70 |
| @@ -46,7 +46,8 @@ public class CfgdataService { | @@ -46,7 +46,8 @@ public class CfgdataService { | ||
| 46 | try { | 46 | try { |
| 47 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); | 47 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); |
| 48 | logger.info("远程发送指令{}",commd); | 48 | logger.info("远程发送指令{}",commd); |
| 49 | - InitService.serialPortService.sendStrData(commd); | 49 | + InitService.serialPortService.sendStrData(commd); //通知串口 |
| 50 | + InitService.dateListenService.reportCondata(); //通知服务器 | ||
| 50 | }catch (Exception e) | 51 | }catch (Exception e) |
| 51 | { | 52 | { |
| 52 | logger.error("发送指令失败:"+GsonConstructor.get().toJson(fieldname),e); | 53 | logger.error("发送指令失败:"+GsonConstructor.get().toJson(fieldname),e); |
| @@ -73,6 +74,7 @@ public class CfgdataService { | @@ -73,6 +74,7 @@ public class CfgdataService { | ||
| 73 | feederTimer.setTimer_is_close(1); | 74 | feederTimer.setTimer_is_close(1); |
| 74 | InitService.serialPortService.sendHexData(FeederCommdUtil.controlTimer((i/2)+1,feederTimer)); | 75 | InitService.serialPortService.sendHexData(FeederCommdUtil.controlTimer((i/2)+1,feederTimer)); |
| 75 | } | 76 | } |
| 77 | + InitService.dateListenService.reportTimer(); //通知服务器 | ||
| 76 | } | 78 | } |
| 77 | MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0); | 79 | MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0); |
| 78 | }catch (Exception e) | 80 | }catch (Exception e) |
| @@ -25,14 +25,14 @@ public class ManualcontrolService { | @@ -25,14 +25,14 @@ public class ManualcontrolService { | ||
| 25 | { | 25 | { |
| 26 | if(!InitService.serialPortService.open()) | 26 | if(!InitService.serialPortService.open()) |
| 27 | { | 27 | { |
| 28 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.serialPortErr,0); | 28 | + MessageUtil.sendFeederResponseMessage(ctx,"manualcontrolOK", FeederBackstateTtpe.serialPortErr,0); |
| 29 | return; | 29 | return; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | JsonObject data = cmdDto.getJsonObject(); | 32 | JsonObject data = cmdDto.getJsonObject(); |
| 33 | if (null == data || data.size()==0) | 33 | if (null == data || data.size()==0) |
| 34 | { | 34 | { |
| 35 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0xE2); | 35 | + MessageUtil.sendFeederResponseMessage(ctx,"manualcontrolOK", FeederBackstateTtpe.success,0xE2); |
| 36 | return; | 36 | return; |
| 37 | } | 37 | } |
| 38 | try { | 38 | try { |
| @@ -42,18 +42,19 @@ public class ManualcontrolService { | @@ -42,18 +42,19 @@ public class ManualcontrolService { | ||
| 42 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); | 42 | String commd = FeederCommdUtil.controlData( FeederCommd06ResponseType.valueOf(fieldname),(Integer) fieldObject); |
| 43 | logger.info("远程发送指令{}",commd); | 43 | logger.info("远程发送指令{}",commd); |
| 44 | InitService.serialPortService.sendStrData(commd); | 44 | InitService.serialPortService.sendStrData(commd); |
| 45 | + InitService.dateListenService.reportCondata(); //通知服务器 | ||
| 45 | }catch (Exception e) | 46 | }catch (Exception e) |
| 46 | { | 47 | { |
| 47 | logger.error("发送指令失败:"+GsonConstructor.get().toJson(fieldname),e); | 48 | logger.error("发送指令失败:"+GsonConstructor.get().toJson(fieldname),e); |
| 48 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.serialPortCommandSendErr,0); | 49 | + MessageUtil.sendFeederResponseMessage(ctx,"manualcontrolOK", FeederBackstateTtpe.serialPortCommandSendErr,0); |
| 49 | throw new RuntimeException(e); | 50 | throw new RuntimeException(e); |
| 50 | } | 51 | } |
| 51 | }); | 52 | }); |
| 52 | 53 | ||
| 53 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.success,0); | 54 | + MessageUtil.sendFeederResponseMessage(ctx,"manualcontrolOK", FeederBackstateTtpe.success,0); |
| 54 | }catch (Exception e) | 55 | }catch (Exception e) |
| 55 | { | 56 | { |
| 56 | - MessageUtil.sendFeederResponseMessage(ctx,"cfgdataOK", FeederBackstateTtpe.runErr,0); | 57 | + MessageUtil.sendFeederResponseMessage(ctx,"manualcontrolOK", FeederBackstateTtpe.runErr,0); |
| 57 | } | 58 | } |
| 58 | 59 | ||
| 59 | } | 60 | } |
| 1 | package com.zhonglai.luhui.smart.feeder.service.netty; | 1 | package com.zhonglai.luhui.smart.feeder.service.netty; |
| 2 | 2 | ||
| 3 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; | 3 | import com.zhonglai.luhui.smart.feeder.config.OperatingData; |
| 4 | +import com.zhonglai.luhui.smart.feeder.config.ScheduledConfig; | ||
| 4 | import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; | 5 | import com.zhonglai.luhui.smart.feeder.service.ConfigurationParameterService; |
| 6 | +import com.zhonglai.luhui.smart.feeder.service.InitService; | ||
| 5 | import com.zhonglai.luhui.smart.feeder.service.feeder.AgreementHandler; | 7 | import com.zhonglai.luhui.smart.feeder.service.feeder.AgreementHandler; |
| 6 | import io.netty.bootstrap.Bootstrap; | 8 | import io.netty.bootstrap.Bootstrap; |
| 7 | import io.netty.channel.*; | 9 | import io.netty.channel.*; |
| @@ -13,6 +15,7 @@ import org.slf4j.Logger; | @@ -13,6 +15,7 @@ import org.slf4j.Logger; | ||
| 13 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
| 14 | 16 | ||
| 15 | import java.nio.charset.Charset; | 17 | import java.nio.charset.Charset; |
| 18 | +import java.util.concurrent.TimeUnit; | ||
| 16 | 19 | ||
| 17 | public class NettyClient { | 20 | public class NettyClient { |
| 18 | private static final Logger logger = LoggerFactory.getLogger(NettyClient.class); | 21 | private static final Logger logger = LoggerFactory.getLogger(NettyClient.class); |
| @@ -22,7 +25,19 @@ public class NettyClient { | @@ -22,7 +25,19 @@ public class NettyClient { | ||
| 22 | private EventLoopGroup groupThread; | 25 | private EventLoopGroup groupThread; |
| 23 | 26 | ||
| 24 | private Channel channel; | 27 | private Channel channel; |
| 25 | - public void start() { | 28 | + |
| 29 | + public void run() | ||
| 30 | + { | ||
| 31 | + ScheduledConfig.scheduler.scheduleWithFixedDelay(() -> { | ||
| 32 | + if(!isOpen()) | ||
| 33 | + { | ||
| 34 | + close(); | ||
| 35 | + start(); | ||
| 36 | + } | ||
| 37 | + },1,1,TimeUnit.SECONDS); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + private void start() { | ||
| 26 | 41 | ||
| 27 | // 创建EventLoopGroup,用于处理客户端的I/O操作 | 42 | // 创建EventLoopGroup,用于处理客户端的I/O操作 |
| 28 | groupThread = new NioEventLoopGroup(); | 43 | groupThread = new NioEventLoopGroup(); |
| @@ -89,6 +104,15 @@ public class NettyClient { | @@ -89,6 +104,15 @@ public class NettyClient { | ||
| 89 | return ctx; | 104 | return ctx; |
| 90 | } | 105 | } |
| 91 | 106 | ||
| 107 | + public boolean isOpen() | ||
| 108 | + { | ||
| 109 | + if(null != ctx && ctx.channel().isActive() && ctx.channel().isOpen()) | ||
| 110 | + { | ||
| 111 | + return true; | ||
| 112 | + } | ||
| 113 | + return false; | ||
| 114 | + } | ||
| 115 | + | ||
| 92 | public void setCtx(ChannelHandlerContext ctx) { | 116 | public void setCtx(ChannelHandlerContext ctx) { |
| 93 | this.ctx = ctx; | 117 | this.ctx = ctx; |
| 94 | } | 118 | } |
-
请 注册 或 登录 后发表评论