新增KNPC温度解析

This commit is contained in:
wangshilong 2024-12-12 20:55:17 +08:00
parent 2f2522f8d3
commit 24f1296b93
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package com.isu.gaswellwatch.modbus.data.decode.impl;
import com.isu.gaswellwatch.modbus.data.decode.DecodeHandler;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Objects;
/**
* KNPC 温度解析
*
* @author <a href="mailto:scwsl@foxmail.com">王仕龙</a>
* 2024/12/12 20:15
*/
@Component(KnpcTemperatureDecodeHandler.NAME + DecodeHandler.DECODE_NAME)
public class KnpcTemperatureDecodeHandler extends SignedNumberDecodeHandler {
public static final String NAME = "knpcTemperature";
@Override
public String decode(Map<String, Object> commandPointMap, String value) {
if (StringUtils.isBlank(value) || !NumberUtils.isCreatable(value)) {
return value;
}
int decimalNumber = Integer.parseInt(value, 16);
if (decimalNumber == 0) {
return String.valueOf(decimalNumber);
}
String binaryNumber = super.decode(commandPointMap, value);
Long resultValue = NumberUtils.createLong(binaryNumber);
if (Objects.nonNull(resultValue) && resultValue < 0) {
binaryNumber = Long.toString(-(resultValue + 32768));
}
return binaryNumber;
}
}