02功能码解析问题
This commit is contained in:
parent
db67195702
commit
97aa125468
|
@ -48,7 +48,7 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
||||||
public void onMessageBatch(List<Message> messages) {
|
public void onMessageBatch(List<Message> messages) {
|
||||||
|
|
||||||
//读取全部提醒字段的配置
|
//读取全部提醒字段的配置
|
||||||
List<RemindSetting> settingList = remindService.getAllRemindSetting();
|
List<RemindSetting> settingList = this.remindService.getAllRemindSetting();
|
||||||
List<RemindRecord> recordList = new ArrayList<>();
|
List<RemindRecord> recordList = new ArrayList<>();
|
||||||
|
|
||||||
//将settingList转换为map,key为deviceId,value为List<RemindSetting>
|
//将settingList转换为map,key为deviceId,value为List<RemindSetting>
|
||||||
|
@ -75,11 +75,11 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//根据设备ID获取设备的产品类型
|
//根据设备ID获取设备的产品类型
|
||||||
DeviceVO device = deviceService.getDevice(Long.valueOf(deviceId));
|
DeviceVO device = this.deviceService.getDevice(Long.valueOf(deviceId));
|
||||||
//根据对应的产品类型,用对应的气井开关字段获取开关状态(wellStatus,solenoidValveStatus,firstSolenoidStatus)
|
//根据对应的产品类型,用对应的气井开关字段获取开关状态(wellStatus,solenoidValveStatus,firstSolenoidStatus)
|
||||||
String wellStatusKey = getWellStatusKey(device);
|
String wellStatusKey = getWellStatusKey(device);
|
||||||
//比对新旧数据,看开关状态是否一致
|
//比对新旧数据,看开关状态是否一致
|
||||||
if(!oldObject.getString(wellStatusKey).equals(newObject.getString(wellStatusKey))){
|
if (oldObject.getString(wellStatusKey) != null && (!oldObject.getString(wellStatusKey).equals(newObject.getString(wellStatusKey)))) {
|
||||||
deviceWellStatusMap.put(Long.valueOf(deviceId), newObject.getInteger(wellStatusKey));
|
deviceWellStatusMap.put(Long.valueOf(deviceId), newObject.getInteger(wellStatusKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,11 +95,11 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
||||||
if (!StringUtils.isEmpty(remindSetting.getMaxValue())) {
|
if (!StringUtils.isEmpty(remindSetting.getMaxValue())) {
|
||||||
if (newValue.compareTo(new BigDecimal(remindSetting.getMaxValue())) > 0) {
|
if (newValue.compareTo(new BigDecimal(remindSetting.getMaxValue())) > 0) {
|
||||||
//如果大于最大值,则保存提醒记录
|
//如果大于最大值,则保存提醒记录
|
||||||
addRemindRecordToList(remindSetting, deviceId, device, newValue, recordList);
|
this.addRemindRecordToList(remindSetting, deviceId, device, newValue, recordList);
|
||||||
} else if (!StringUtils.isEmpty(remindSetting.getMinValue())) {
|
} else if (!StringUtils.isEmpty(remindSetting.getMinValue())) {
|
||||||
if (newValue.compareTo(new BigDecimal(remindSetting.getMinValue())) < 0) {
|
if (newValue.compareTo(new BigDecimal(remindSetting.getMinValue())) < 0) {
|
||||||
//如果小于最小值,则保存提醒记录
|
//如果小于最小值,则保存提醒记录
|
||||||
addRemindRecordToList(remindSetting, deviceId, device, newValue, recordList);
|
this.addRemindRecordToList(remindSetting, deviceId, device, newValue, recordList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,6 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -131,7 +130,7 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
||||||
|
|
||||||
private void addRemindRecordToList(RemindSetting remindSetting, String deviceId, DeviceVO device, BigDecimal newValue, List<RemindRecord> recordList) {
|
private void addRemindRecordToList(RemindSetting remindSetting, String deviceId, DeviceVO device, BigDecimal newValue, List<RemindRecord> recordList) {
|
||||||
RemindRecord remindRecord = new RemindRecord();
|
RemindRecord remindRecord = new RemindRecord();
|
||||||
remindRecord.setId(snowflakeConfig.snowflakeId());
|
remindRecord.setId(this.snowflakeConfig.snowflakeId());
|
||||||
remindRecord.setDeviceId(Long.valueOf(deviceId));
|
remindRecord.setDeviceId(Long.valueOf(deviceId));
|
||||||
remindRecord.setGasWell(device.getGasWell().getId());
|
remindRecord.setGasWell(device.getGasWell().getId());
|
||||||
remindRecord.setContent("【" + remindSetting.getFieldName() + "】的值达到" + newValue + ",请及时处理");
|
remindRecord.setContent("【" + remindSetting.getFieldName() + "】的值达到" + newValue + ",请及时处理");
|
||||||
|
@ -140,11 +139,11 @@ public class BusinessMessageHandlerListener implements BatchMessageListener {
|
||||||
|
|
||||||
private static String getWellStatusKey(DeviceVO device) {
|
private static String getWellStatusKey(DeviceVO device) {
|
||||||
String wellStatusKey = "";
|
String wellStatusKey = "";
|
||||||
if(PersistenceHandler.KNPCV1_MODBUS_TYPE.equals(device.getDeviceType().getCode())){
|
if (PersistenceHandler.KNPCV1_MODBUS_TYPE.equals(device.getProduct().getCode())) {
|
||||||
wellStatusKey = "wellStatus";
|
wellStatusKey = "wellStatus";
|
||||||
} else if(PersistenceHandler.ETC_MODBUS_TYPE.equals(device.getDeviceType().getCode())){
|
} else if (PersistenceHandler.ETC_MODBUS_TYPE.equals(device.getProduct().getCode())) {
|
||||||
wellStatusKey = "solenoidValveStatus";
|
wellStatusKey = "solenoidValveStatus";
|
||||||
} else if(PersistenceHandler.SCSS_MODBUS_TYPE.equals(device.getDeviceType().getCode())){
|
} else if (PersistenceHandler.SCSS_MODBUS_TYPE.equals(device.getProduct().getCode())) {
|
||||||
wellStatusKey = "firstSolenoidStatus";
|
wellStatusKey = "firstSolenoidStatus";
|
||||||
}
|
}
|
||||||
return wellStatusKey;
|
return wellStatusKey;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class DynamicRabbitListener implements ApplicationRunner {
|
||||||
this.businessMessageListenerContainer = new SimpleMessageListenerContainer();
|
this.businessMessageListenerContainer = new SimpleMessageListenerContainer();
|
||||||
this.businessMessageListenerContainer.setConnectionFactory(connectionFactory);
|
this.businessMessageListenerContainer.setConnectionFactory(connectionFactory);
|
||||||
this.businessMessageListenerContainer.setMessageListener(this.businessMessageListener);
|
this.businessMessageListenerContainer.setMessageListener(this.businessMessageListener);
|
||||||
this.businessMessageListenerContainer.start();
|
// this.businessMessageListenerContainer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -96,28 +96,30 @@ public class ModbusMessagePersistListener implements BatchMessageListener {
|
||||||
RtuMessageResponse response = (RtuMessageResponse) masterParser.parseMessage(byteQueue);
|
RtuMessageResponse response = (RtuMessageResponse) masterParser.parseMessage(byteQueue);
|
||||||
ModbusResponse modbusResponse = response.getModbusResponse();
|
ModbusResponse modbusResponse = response.getModbusResponse();
|
||||||
|
|
||||||
short[] values = null;
|
byte[] byteValues = null;
|
||||||
|
short[] shortValues = null;
|
||||||
switch (modbusResponse.getFunctionCode()) {
|
switch (modbusResponse.getFunctionCode()) {
|
||||||
case FunctionCode.READ_COILS -> {
|
case FunctionCode.READ_COILS -> {
|
||||||
values = ((ReadCoilsResponse) modbusResponse).getShortData();
|
byteValues = ((ReadCoilsResponse) modbusResponse).getData();
|
||||||
}
|
}
|
||||||
case FunctionCode.READ_DISCRETE_INPUTS -> {
|
case FunctionCode.READ_DISCRETE_INPUTS -> {
|
||||||
values = ((ReadDiscreteInputsResponse) modbusResponse).getShortData();
|
byteValues = ((ReadDiscreteInputsResponse) modbusResponse).getData();
|
||||||
}
|
}
|
||||||
case FunctionCode.READ_INPUT_REGISTERS -> {
|
case FunctionCode.READ_INPUT_REGISTERS -> {
|
||||||
values = ((ReadInputRegistersResponse) modbusResponse).getShortData();
|
shortValues = ((ReadInputRegistersResponse) modbusResponse).getShortData();
|
||||||
}
|
}
|
||||||
case FunctionCode.READ_HOLDING_REGISTERS -> {
|
case FunctionCode.READ_HOLDING_REGISTERS -> {
|
||||||
values = ((ReadHoldingRegistersResponse) modbusResponse).getShortData();
|
shortValues = ((ReadHoldingRegistersResponse) modbusResponse).getShortData();
|
||||||
}
|
}
|
||||||
case FunctionCode.READ_EXCEPTION_STATUS -> {
|
case FunctionCode.READ_EXCEPTION_STATUS -> {
|
||||||
values = new short[]{((ReadExceptionStatusResponse) modbusResponse).getExceptionStatus()};
|
shortValues = new short[]{((ReadExceptionStatusResponse) modbusResponse).getExceptionStatus()};
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
throw new RuntimeException("Funcetion code not supported: " + modbusResponse.getFunctionCode());
|
throw new RuntimeException("Funcetion code not supported: " + modbusResponse.getFunctionCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (short value : values) {
|
if (Objects.nonNull(shortValues)) {
|
||||||
|
for (short value : shortValues) {
|
||||||
stepSize = index * 4;
|
stepSize = index * 4;
|
||||||
messagePointMap.put(StringUtils.leftPad(String.valueOf(startAddress), 4, '0'),
|
messagePointMap.put(StringUtils.leftPad(String.valueOf(startAddress), 4, '0'),
|
||||||
ModbusMessage.MessagePoint.builder()
|
ModbusMessage.MessagePoint.builder()
|
||||||
|
@ -127,6 +129,18 @@ public class ModbusMessagePersistListener implements BatchMessageListener {
|
||||||
index++;
|
index++;
|
||||||
startAddress++;
|
startAddress++;
|
||||||
}
|
}
|
||||||
|
} else if (Objects.nonNull(byteValues)) {
|
||||||
|
for (byte value : byteValues) {
|
||||||
|
stepSize = index * 2;
|
||||||
|
messagePointMap.put(StringUtils.leftPad(String.valueOf(startAddress), 4, '0'),
|
||||||
|
ModbusMessage.MessagePoint.builder()
|
||||||
|
.parseValue(String.valueOf(value))
|
||||||
|
.originalValue(StringUtils.substring(collectionMessage, 6 + stepSize, 8 + stepSize))
|
||||||
|
.build());
|
||||||
|
index++;
|
||||||
|
startAddress++;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("初始数据解析异常: {}", messageString, e);
|
log.error("初始数据解析异常: {}", messageString, e);
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue