|
@@ -1,7 +1,5 @@
|
|
|
package com.zd.laboratory.socket.service;
|
|
package com.zd.laboratory.socket.service;
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
-import com.zd.common.core.annotation.FunctionMapper;
|
|
|
|
|
import com.zd.common.core.redis.RedisService;
|
|
import com.zd.common.core.redis.RedisService;
|
|
|
import com.zd.common.core.utils.SpringUtils;
|
|
import com.zd.common.core.utils.SpringUtils;
|
|
|
import com.zd.laboratory.api.entity.ControlEntity;
|
|
import com.zd.laboratory.api.entity.ControlEntity;
|
|
@@ -20,7 +18,6 @@ import com.zd.laboratory.socket.command.Symbol;
|
|
|
import com.zd.laboratory.socket.runner.TCPServer;
|
|
import com.zd.laboratory.socket.runner.TCPServer;
|
|
|
import com.zd.laboratory.socket.vo.TransmissionVo;
|
|
import com.zd.laboratory.socket.vo.TransmissionVo;
|
|
|
import com.zd.laboratory.utils.CRCCHECK;
|
|
import com.zd.laboratory.utils.CRCCHECK;
|
|
|
-import com.zd.laboratory.utils.FunctionMapperUtil;
|
|
|
|
|
import com.zd.laboratory.utils.HexUtils;
|
|
import com.zd.laboratory.utils.HexUtils;
|
|
|
import com.zd.model.constant.CacheConstants;
|
|
import com.zd.model.constant.CacheConstants;
|
|
|
import com.zd.model.constant.CacheDevice;
|
|
import com.zd.model.constant.CacheDevice;
|
|
@@ -40,9 +37,6 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.validation.constraints.NotNull;
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.lang.reflect.Field;
|
|
|
|
|
-import java.lang.reflect.InvocationHandler;
|
|
|
|
|
-import java.lang.reflect.Proxy;
|
|
|
|
|
import java.net.Socket;
|
|
import java.net.Socket;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -68,8 +62,6 @@ public class SocketService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SubMessageSendManager subMessageSendManager;
|
|
private SubMessageSendManager subMessageSendManager;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private FunctionMapperUtil functionMapperUtil;
|
|
|
|
|
- @Autowired
|
|
|
|
|
private LabRelayMapper labRelayMapper;
|
|
private LabRelayMapper labRelayMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISensorConfigService sensorConfigService;
|
|
private ISensorConfigService sensorConfigService;
|
|
@@ -78,18 +70,9 @@ public class SocketService {
|
|
|
|
|
|
|
|
private List<SensorConfig> sensorConfigs;
|
|
private List<SensorConfig> sensorConfigs;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CommonSend commonSend;
|
|
private CommonSend commonSend;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取当前网关与传感器功能配置
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
- public List<SensorConfig> getSensorConfigs() {
|
|
|
|
|
- return sensorConfigs;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
private void queryRelays(){
|
|
private void queryRelays(){
|
|
|
relays = labRelayMapper.selectLabRelayList(new LabRelay());
|
|
relays = labRelayMapper.selectLabRelayList(new LabRelay());
|
|
@@ -138,123 +121,6 @@ public class SocketService {
|
|
|
}*/
|
|
}*/
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void confiSensorData(TransmissionVo transmissionVo, SensorConfig sensorConfig) {
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- // 煤尘
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getFenchen())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getFenchen(), "fenchen");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 温度
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getWendu())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getWendu(), "wendu");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 湿度
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getShidu())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getShidu(), "shidu");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 一氧化碳
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getCo())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getCo(), "co");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 大气压
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getDaqiya())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getDaqiya(), "daqiya");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 氧气浓度
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getO2())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getO2(), "o2");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 烟雾
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getYanwu())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getYanwu(), "yanwu");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 甲烷
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getJiawan())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getJiawan(), "jiawan");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // voc
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getVoc())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getVoc(), "voc");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 二氧化硫
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getSo2())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getSo2(), "so2");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 一氧化氮
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorConfig.getNo())){
|
|
|
|
|
- doConfig(transmissionVo, sensorConfig.getNo(), "no");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void doConfig(TransmissionVo transmissionVo, String data, String type) throws NoSuchFieldException, IllegalAccessException {
|
|
|
|
|
- String[] nums = data.split(",");
|
|
|
|
|
- for (String num : nums) {
|
|
|
|
|
- String field = "A7_" + num;
|
|
|
|
|
-
|
|
|
|
|
- Field a = transmissionVo.getClass().getDeclaredField(field);
|
|
|
|
|
- if(a == null){continue;};
|
|
|
|
|
- String name = a.getName();
|
|
|
|
|
-
|
|
|
|
|
- if(name.equals(field)){
|
|
|
|
|
- //获取注解
|
|
|
|
|
- FunctionMapper foo = a.getAnnotation(FunctionMapper.class);
|
|
|
|
|
- if(foo == null){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- InvocationHandler h = Proxy.getInvocationHandler(foo);
|
|
|
|
|
- Field hField ;
|
|
|
|
|
-
|
|
|
|
|
- String value = foo.funNum();
|
|
|
|
|
-
|
|
|
|
|
- hField = h.getClass().getDeclaredField("memberValues");
|
|
|
|
|
- // 因为这个字段事 private final 修饰,所以要打开权限
|
|
|
|
|
- hField.setAccessible(true);
|
|
|
|
|
- Map memberValues = (Map) hField.get(h);
|
|
|
|
|
-
|
|
|
|
|
- // 修改 value 属性值
|
|
|
|
|
- memberValues.put("funNum", type);
|
|
|
|
|
- // 获取 foo 的 value 属性值
|
|
|
|
|
- value = foo.funNum();
|
|
|
|
|
- a.setAccessible(true);
|
|
|
|
|
-
|
|
|
|
|
- System.out.println("传感器数据转换--" + field + ": " + value + ", " + a.get(transmissionVo));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 通过传感器ID 获取传输数据
|
|
|
|
|
- * @param sensorId 传感器id
|
|
|
|
|
- * @return 缓存数据
|
|
|
|
|
- */
|
|
|
|
|
- public TransmissionVo getSensorData(String sensorId){
|
|
|
|
|
- TransmissionVo transmissionVo = null;
|
|
|
|
|
- if(StringUtils.isNotBlank(sensorId) && redisService.hasKey(CacheDevice.SENSOR_KEY.getRedisKey() + sensorId)){
|
|
|
|
|
-
|
|
|
|
|
- String str = redisService.getCacheObject(CacheDevice.SENSOR_KEY.getRedisKey() + sensorId);
|
|
|
|
|
- if(StringUtils.isNotBlank(str)){
|
|
|
|
|
- transmissionVo = JSONObject.parseObject(str, TransmissionVo.class);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return transmissionVo;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 通过传感器ID 获取传输数据
|
|
* 通过传感器ID 获取传输数据
|
|
|
* @return 缓存数据
|
|
* @return 缓存数据
|