提交修改
This commit is contained in:
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@SysProtocol(name = "IECF6113-JSON协议",protocolCode = XinDaConstant.PROTOCOL.IECF6113,description = "IECF6113-JSON协议")
|
||||
@SysProtocol(name = "IECF6113-JSON协议", protocolCode = XinDaConstant.PROTOCOL.IECF6113, description = "IECF6113-JSON协议")
|
||||
public class IECF6113ProtocolService implements IProtocol {
|
||||
|
||||
|
||||
@@ -49,67 +49,67 @@ public class IECF6113ProtocolService implements IProtocol {
|
||||
|
||||
/**
|
||||
* 上报数据格式: <p>
|
||||
* {
|
||||
* "AD6": 0.27333333333333,
|
||||
* "AD15": 0.27333333333333,
|
||||
* "AD14": 0.27333333333333,
|
||||
* "AD7": 0.27333333333333,
|
||||
* "AD11": 0.26,
|
||||
* "AD1": 0.27333333333333,
|
||||
* "AD4": 0.26,
|
||||
* "AD3": 0.26,
|
||||
* "AD10": 0.27333333333333,
|
||||
* "AD8": 0.26,
|
||||
* "AD16": 0.27333333333333,
|
||||
* "AD12": 0.26,
|
||||
* "AD13": 0.27333333333333,
|
||||
* "AD9": 0.27333333333333,
|
||||
* "AD2": 0.27333333333333,
|
||||
* "AD5": 0.27333333333333
|
||||
* }
|
||||
*
|
||||
* {
|
||||
* "I0.1": 0,
|
||||
* "I0.3": 0,
|
||||
* "I0.4": 0,
|
||||
* "I0.6": 0,
|
||||
* "I0.5": 0,
|
||||
* "I0.2": 0
|
||||
* "AD6": 0.27333333333333,
|
||||
* "AD15": 0.27333333333333,
|
||||
* "AD14": 0.27333333333333,
|
||||
* "AD7": 0.27333333333333,
|
||||
* "AD11": 0.26,
|
||||
* "AD1": 0.27333333333333,
|
||||
* "AD4": 0.26,
|
||||
* "AD3": 0.26,
|
||||
* "AD10": 0.27333333333333,
|
||||
* "AD8": 0.26,
|
||||
* "AD16": 0.27333333333333,
|
||||
* "AD12": 0.26,
|
||||
* "AD13": 0.27333333333333,
|
||||
* "AD9": 0.27333333333333,
|
||||
* "AD2": 0.27333333333333,
|
||||
* "AD5": 0.27333333333333
|
||||
* }
|
||||
*
|
||||
* <p>
|
||||
* {
|
||||
* "lng": "104.0902886",
|
||||
* "lat": "030.8176553"
|
||||
* "I0.1": 0,
|
||||
* "I0.3": 0,
|
||||
* "I0.4": 0,
|
||||
* "I0.6": 0,
|
||||
* "I0.5": 0,
|
||||
* "I0.2": 0
|
||||
* }
|
||||
*
|
||||
* <p>
|
||||
* {
|
||||
* "PAD": 3905
|
||||
* "lng": "104.0902886",
|
||||
* "lat": "030.8176553"
|
||||
* }
|
||||
*
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* {
|
||||
* "PAD": 3905
|
||||
* }
|
||||
* <p>
|
||||
* <p>
|
||||
* <p>
|
||||
* 下发报文格式<p>
|
||||
* device 从机编号 <p>
|
||||
* name 标识符 <p>
|
||||
* value 值 <p>
|
||||
* serNo 流水号 <p>
|
||||
* {
|
||||
* "device": 1,
|
||||
* "name": "template",
|
||||
* "value": 111,
|
||||
* "serNo": "213245489543789"
|
||||
* "device": 1,
|
||||
* "name": "template",
|
||||
* "value": 111,
|
||||
* "serNo": "213245489543789"
|
||||
* }
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* 下发指令回复格式<p>
|
||||
* serNo 平台的流水号,用于对应回复消息 <p>
|
||||
* ack 下发指令状态 0是失败 1是成功 <p>
|
||||
* {
|
||||
* "serNo": "213245489543789",
|
||||
* "ack": 1
|
||||
* {
|
||||
* "serNo": "213245489543789",
|
||||
* "ack": 1
|
||||
* }
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* {"AD6":0.20666666666667,"AD15":0.22,"AD14":0.22,"AD7":0.20666666666667,"AD11":0.20666666666667,
|
||||
* "AD1":18.886666666667,"AD4":0.22,"AD3":0.22,"AD10":0.22,"AD8":15.526666666667,"AD16":0.22,"AD12":0.22,
|
||||
* "AD13":0.22,"AD9":0.20666666666667,"AD2":0.22,"AD5":0.22}
|
||||
@@ -118,58 +118,103 @@ public class IECF6113ProtocolService implements IProtocol {
|
||||
* {"lng":"104.1536100","lat":"030.8336398","PAD":4185,"CSQ":28}
|
||||
*/
|
||||
private static final Set<String> EXCLUDE_KEYS = new HashSet<>(Arrays.asList(
|
||||
"AD1", "AD2", "AD3","AD4", "AD5", "AD6","AD7", "AD8", "AD9","AD10", "AD11", "AD12",
|
||||
"AD13", "AD14", "AD15","AD16", "I0.1", "I0.2","I0.3", "I0.4", "I0.5","I0.6","lng", "lat", "PAD", "CSQ",
|
||||
"K0", "K1", "温度","温度1", "标况流量", "工况流量", "压力"
|
||||
"AD1", "AD2", "AD3", "AD4", "AD5", "AD6", "AD7", "AD8", "AD9", "AD10", "AD11", "AD12",
|
||||
"AD13", "AD14", "AD15", "AD16", "I0.1", "I0.2", "I0.3", "I0.4", "I0.5", "I0.6", "lng", "lat", "PAD", "CSQ",
|
||||
"K0", "K1", "温度", "温度1", "标况流量", "工况流量", "压力"
|
||||
));
|
||||
|
||||
@Override
|
||||
public DeviceReport decode(DeviceData deviceData, String clientId) {
|
||||
try {
|
||||
DeviceReport reportMessage = new DeviceReport();
|
||||
String data = new String(deviceData.getData(),StandardCharsets.UTF_8);
|
||||
String data = new String(deviceData.getData(), StandardCharsets.UTF_8);
|
||||
List<ThingsModelSimpleItem> result = new ArrayList<>();
|
||||
if(data.trim().equals("ok")||data.trim().equals("ERROR")){
|
||||
if (data.trim().equals("ok") || data.trim().equals("ERROR")) {
|
||||
log.info(data);
|
||||
}else{
|
||||
Map<String,Object> values = JSON.parseObject(data, Map.class);
|
||||
} else {
|
||||
Map<String, Object> values = JSON.parseObject(data, Map.class);
|
||||
// if (values.containsKey("AD1") || values.containsKey("lng") || values.containsKey("I0.1")||values.containsKey("PAD")||values.containsKey("K1")){
|
||||
// 初始化纬度变量,使用BigDecimal来存储高精度值
|
||||
BigDecimal latitude = new BigDecimal("39.9042");
|
||||
// 初始化经度变量,同样使用BigDecimal
|
||||
BigDecimal longitude = new BigDecimal("116.4074");
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
// 初始化纬度变量,使用BigDecimal来存储高精度值
|
||||
BigDecimal latitude = new BigDecimal("39.9042");
|
||||
// 初始化经度变量,同样使用BigDecimal
|
||||
BigDecimal longitude = new BigDecimal("116.4074");
|
||||
String volt = "";
|
||||
Integer rssi = 0;
|
||||
String sd = "";
|
||||
String pd = "";
|
||||
String imei = "";
|
||||
String iccid = "";
|
||||
Device device = new Device();
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
// if (EXCLUDE_KEYS.contains(entry.getKey())){
|
||||
ThingsModelSimpleItem simpleItem = new ThingsModelSimpleItem();
|
||||
simpleItem.setTs(DateUtils.getNowDate());
|
||||
simpleItem.setId(entry.getKey());
|
||||
simpleItem.setValue(entry.getValue()+"");
|
||||
result.add(simpleItem);
|
||||
if(values.containsKey("lng")) {
|
||||
if (entry.getKey().equals("lng")) {
|
||||
longitude = new BigDecimal(entry.getValue() + "");
|
||||
ThingsModelSimpleItem simpleItem = new ThingsModelSimpleItem();
|
||||
simpleItem.setTs(DateUtils.getNowDate());
|
||||
simpleItem.setId(entry.getKey());
|
||||
simpleItem.setValue(entry.getValue() + "");
|
||||
result.add(simpleItem);
|
||||
if (entry.getKey().equals("lng")) {
|
||||
longitude = new BigDecimal(entry.getValue() + "");
|
||||
device.setLongitude(longitude);
|
||||
|
||||
}
|
||||
if (entry.getKey().equals("lat")) {
|
||||
latitude = new BigDecimal(entry.getValue() + "");
|
||||
|
||||
}
|
||||
//更新设备经纬度信息
|
||||
Device device = new Device();
|
||||
device.setSerialNumber(deviceData.getSerialNumber());
|
||||
device.setLongitude(longitude);
|
||||
device.setLatitude(latitude);
|
||||
deviceService.updateDeviceStatus(device);
|
||||
}
|
||||
// }
|
||||
}
|
||||
// }
|
||||
if (entry.getKey().equals("lat")) {
|
||||
latitude = new BigDecimal(entry.getValue() + "");
|
||||
device.setLatitude(latitude);
|
||||
|
||||
}
|
||||
if (entry.getKey().equals("PAD")) {
|
||||
// volt = entry.getValue() + "";
|
||||
BigDecimal num = new BigDecimal( entry.getValue() + "");
|
||||
volt = num.divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP).toPlainString();
|
||||
device.setVolt(volt);
|
||||
}
|
||||
if (entry.getKey().equals("CSQ")) {
|
||||
rssi = Integer.parseInt(entry.getValue() + "");
|
||||
device.setRssi(rssi);
|
||||
}
|
||||
|
||||
if (entry.getKey().equals("SD")) {
|
||||
BigDecimal num1 = new BigDecimal( entry.getValue() + "");
|
||||
sd = num1.divide(new BigDecimal("1000"), 3, BigDecimal.ROUND_HALF_UP).toPlainString();
|
||||
device.setSd(sd);
|
||||
|
||||
}
|
||||
if (entry.getKey().equals("BD")) {
|
||||
BigDecimal num2 = new BigDecimal( entry.getValue() + "");
|
||||
pd = num2.divide(new BigDecimal("1000"), 3, BigDecimal.ROUND_HALF_UP).toPlainString();
|
||||
device.setPd(pd);
|
||||
}
|
||||
if (entry.getKey().equals("ICCID")) {
|
||||
iccid = entry.getValue() + "";
|
||||
device.setIccid(iccid);
|
||||
}
|
||||
if (entry.getKey().equals("IMEI")) {
|
||||
imei = entry.getValue() + "";
|
||||
device.setImei(imei);
|
||||
}
|
||||
// }
|
||||
}
|
||||
if (values.containsKey("lng")) {
|
||||
//更新设备经纬度信息
|
||||
// Device device = new Device();
|
||||
device.setSerialNumber(deviceData.getSerialNumber());
|
||||
// device.setLongitude(longitude);
|
||||
// device.setLatitude(latitude);
|
||||
// device.setVolt(volt);
|
||||
// device.setRssi(rssi);
|
||||
// device.setSd(sd);
|
||||
// device.setPd(pd);
|
||||
deviceService.updateDeviceStatus(device);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
reportMessage.setThingsModelSimpleItem(result);
|
||||
reportMessage.setClientId(clientId);
|
||||
reportMessage.setSerialNumber(clientId);
|
||||
return reportMessage;
|
||||
}catch (Exception e){
|
||||
throw new ServiceException("数据解析异常"+e.getMessage());
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("数据解析异常" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +225,8 @@ public class IECF6113ProtocolService implements IProtocol {
|
||||
* 4.更改上报时间 GKB29810,JCZ,{"TIME":20}
|
||||
* 5.通 信 控制 GKB29810,MODBUS, {"KO":12}
|
||||
* 6.开关量输出控制 GKB29810,OUT,{"Q0.1":0,"Q0.2":0,"Q0.3":0,"Q0.4":0,"Q0.5":0,"Q0.6":0}
|
||||
* GKB29810,0UT,{"Q0.1":1 ,"Q0.2":1,"Q0.3":1,"Q0.4":1,"Q0.5":1 "Q0.6":1)
|
||||
* GKB29810,0UT,{"Q0.1":1 ,"Q0.2":1,"Q0.3":1,"Q0.4":1,"Q0.5":1 "Q0.6":1)
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
@@ -238,21 +284,21 @@ public class IECF6113ProtocolService implements IProtocol {
|
||||
callBack.setMessage(msg.toString().getBytes());
|
||||
}
|
||||
|
||||
if(params.containsKey("select")) {
|
||||
String msg = params.get("select") + "";
|
||||
callBack.setSources(msg);
|
||||
callBack.setMessage(msg.getBytes());
|
||||
}
|
||||
if(params.containsKey("OUT")){
|
||||
String msg = params.get("OUT") + "";
|
||||
callBack.setSources(msg);
|
||||
callBack.setMessage(msg.getBytes());
|
||||
}
|
||||
if(params.containsKey("TIME")){
|
||||
String msg = "GKB29810,JCZ,{\"TIME\":" + params.get("TIME")+ "}";
|
||||
callBack.setSources(msg);
|
||||
callBack.setMessage(msg.getBytes());
|
||||
}
|
||||
if (params.containsKey("select")) {
|
||||
String msg = params.get("select") + "";
|
||||
callBack.setSources(msg);
|
||||
callBack.setMessage(msg.getBytes());
|
||||
}
|
||||
if (params.containsKey("OUT")) {
|
||||
String msg = params.get("OUT") + "";
|
||||
callBack.setSources(msg);
|
||||
callBack.setMessage(msg.getBytes());
|
||||
}
|
||||
if (params.containsKey("TIME")) {
|
||||
String msg = "GKB29810,JCZ,{\"TIME\":" + params.get("TIME") + "}";
|
||||
callBack.setSources(msg);
|
||||
callBack.setMessage(msg.getBytes());
|
||||
}
|
||||
// 调用方法检查并获取以前缀开头的键和值
|
||||
Map<String, Object> result = getKeysAndValuesWithPrefix(params, "Q0.");
|
||||
// 输出结果
|
||||
|
||||
Reference in New Issue
Block a user