refactor(driver): rewrite water-188b Netty handler and trim batch template

This commit is contained in:
pnoker
2020-08-19 22:58:45 +08:00
parent a381afe58a
commit bfeb773e51
2 changed files with 252 additions and 394 deletions
@@ -46,22 +46,46 @@ import java.util.concurrent.TimeUnit;
* 03221018200673 表号
* 0081
* 96 长度
* 15:905F 数据标识DI(90 5F)
* 17:2B2B3600 正向累计量单位(2B),反向累计量单位(2B),瞬时流量单位(36),水压单位(00)
* 21:18690100 当前正向累计水量 92.440
* 25:00000000 当前剩余金额
* 29:00000000 当前状态
* 33:00 充值识别码
* 34:00000000 当前反向累计流量
* 38:000000 当前瞬时流量
* 41:0000 当前水压
* 43:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* B700 信号强度
* 15: 905F 数据标识DI(90 5F)
* 17: 2B2B3600 正向累计量单位(2B),反向累计量单位(2B),瞬时流量单位(36),水压单位(00)
* 21: 18690100 当前正向累计水量 92.440
* 25: 00000000 当前剩余金额
* 29: 00000000 当前状态
* 33: 00 充值识别码
* 34: 00000000 当前反向累计流量
* 38: 000000 当前瞬时流量
* 41: 0000 当前水压
* 43: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 48: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 53: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 58: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 63: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 68: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 73: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 78: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 83: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 88: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 93: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 98: 0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 103:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 108:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 113:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 118:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 123:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 128:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 133:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 138:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 143:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 148:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 153:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 158:0A68010073 正向累计流量(0A680100)累加和(73) 92.17
* 163:B700 信号强度
* A9 校验和
* 16 帧尾
* <p>
* ----0--1--2--3--4--5--6--7--8--9--10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31-32-33-34-35-36-37-38-39-40-41-42-43-44-45-46-47-48-49-50-51
* lg:[FE FE FE 68 10 03 22 10 18 20 06 73 00 81 96 90 5F 2B 2B 36 00 18 69 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 68 01 00 73 B7 00 A9 16]
* lg:[FE FE FE 68 10 03 22 10 18 20 06 73 00 81 96 90 5F 2B 2B 36 00 18 69 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 0A 68 01 00 73 B7 00 A9 16]
* lg:[FE FE FE 68 10 06 02 01 07 20 06 36 00 81 96 90 5F 2B 2B 35 00 0E 01 00 00 00 00 00 00 00 00 00 24 00 00 00 00 00 00 00 00 00 00 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F 0E 01 00 00 0F A3 00 1B 16]
*
* @author pnoker
*/
@@ -83,6 +107,23 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
@Resource
private DriverContext driverContext;
/**
* 自定义报文解析,用于处理特殊位号数据
*
* @return PointValue
*/
private void customDecode(int start, long deviceId, long pointId, PointValue pointValue) {
//信号强度额外处理
if (start == 163) {
String value = that.driverService.convertValue(deviceId, pointId, pointValue.getValue());
int csq = (int) Double.parseDouble(value);
if (csq > 0) {
csq -= 200;
}
pointValue.setValue(String.valueOf(csq));
}
}
@Override
public void channelActive(ChannelHandlerContext context) {
log.debug("Water 188B Driver Listener({}) accept clint({})", context.channel().localAddress(), context.channel().remoteAddress());
@@ -101,7 +142,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
List<PointValue> pointValues = new ArrayList<>();
Map<Long, Map<String, AttributeInfo>> pointInfoMap = that.driverContext.getDevicePointInfoMap().get(deviceId);
for (Long pointId : pointInfoMap.keySet()) {
PointValue pointValue = decodePointValue(deviceId, pointId, pointInfoMap, byteBuf);
PointValue pointValue = decodePointValue(deviceId, pointId, pointInfoMap.get(pointId), byteBuf);
pointValues.add(pointValue);
}
PointValue pointValue = new PointValue(deviceId, pointValues, 1, TimeUnit.HOURS);
@@ -114,8 +155,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
context.close();
}
private PointValue decodePointValue(long deviceId, long pointId, Map<Long, Map<String, AttributeInfo>> pointInfoMap, ByteBuf byteBuf) {
Map<String, AttributeInfo> infoMap = pointInfoMap.get(pointId);
private PointValue decodePointValue(long deviceId, long pointId, Map<String, AttributeInfo> infoMap, ByteBuf byteBuf) {
String type = DriverUtils.value(infoMap.get("type").getType(), infoMap.get("type").getValue());
int start = DriverUtils.value(infoMap.get("start").getType(), infoMap.get("start").getValue());
int length = DriverUtils.value(infoMap.get("length").getType(), infoMap.get("length").getValue());
@@ -149,8 +189,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
default:
throw new IllegalStateException("Unexpected value: " + type.toLowerCase());
}
log.info("DecodePointValue: hex({}),rawValue({}),convertValue({})", ByteBufUtil.hexDump(byteBuf, start, length), rawValue, value);
return new PointValue(pointId, rawValue, value);
PointValue pointValue = new PointValue(pointId, rawValue, value);
customDecode(start, deviceId, pointId, pointValue);
log.info("DecodePointValue: hex({}),rawValue({}),convertValue({})", ByteBufUtil.hexDump(byteBuf, start, length).toUpperCase(), pointValue.getRawValue(), pointValue.getValue());
return pointValue;
}
}
+193 -377
View File
@@ -445,395 +445,211 @@
"base": 0,
"minimum": -999999,
"maximum": 999999,
"multiple": 0.001,
"multiple": 1,
"accrue": false,
"format": "%.3f",
"unit": "-"
}
],
"pointConfig": {
"数据标识": {
"start": 15,
"length": 2,
"type": "hex"
},
"正向累计量单位": {
"start": 17,
"length": 1,
"type": "hex"
},
"反向累计量单位": {
"start": 18,
"length": 1,
"type": "hex"
},
"瞬时流量单位": {
"start": 19,
"length": 1,
"type": "hex"
},
"水压单位": {
"start": 20,
"length": 1,
"type": "hex"
},
"正向累计水量": {
"start": 21,
"length": 4,
"type": "int"
},
"剩余金额": {
"start": 25,
"length": 4,
"type": "int"
},
"状态": {
"start": 29,
"length": 4,
"type": "hex"
},
"充值识别码": {
"start": 33,
"length": 1,
"type": "hex"
},
"反向累计流量": {
"start": 34,
"length": 4,
"type": "int"
},
"瞬时流量": {
"start": 38,
"length": 3,
"type": "int"
},
"水压": {
"start": 41,
"length": 2,
"type": "short"
},
"正向累计流量-0点": {
"start": 43,
"length": 4,
"type": "int"
},
"正向累计流量-1点": {
"start": 48,
"length": 4,
"type": "int"
},
"正向累计流量-2点": {
"start": 53,
"length": 4,
"type": "int"
},
"正向累计流量-3点": {
"start": 58,
"length": 4,
"type": "int"
},
"正向累计流量-4点": {
"start": 63,
"length": 4,
"type": "int"
},
"正向累计流量-5点": {
"start": 68,
"length": 4,
"type": "int"
},
"正向累计流量-6点": {
"start": 73,
"length": 4,
"type": "int"
},
"正向累计流量-7点": {
"start": 78,
"length": 4,
"type": "int"
},
"正向累计流量-8点": {
"start": 83,
"length": 4,
"type": "int"
},
"正向累计流量-9点": {
"start": 88,
"length": 4,
"type": "int"
},
"正向累计流量-10点": {
"start": 93,
"length": 4,
"type": "int"
},
"正向累计流量-11点": {
"start": 98,
"length": 4,
"type": "int"
},
"正向累计流量-12点": {
"start": 103,
"length": 4,
"type": "int"
},
"正向累计流量-13点": {
"start": 108,
"length": 4,
"type": "int"
},
"正向累计流量-14点": {
"start": 113,
"length": 4,
"type": "int"
},
"正向累计流量-15点": {
"start": 118,
"length": 4,
"type": "int"
},
"正向累计流量-16点": {
"start": 123,
"length": 4,
"type": "int"
},
"正向累计流量-17点": {
"start": 128,
"length": 4,
"type": "int"
},
"正向累计流量-18点": {
"start": 133,
"length": 4,
"type": "int"
},
"正向累计流量-19点": {
"start": 138,
"length": 4,
"type": "int"
},
"正向累计流量-20点": {
"start": 143,
"length": 4,
"type": "int"
},
"正向累计流量-21点": {
"start": 148,
"length": 4,
"type": "int"
},
"正向累计流量-22点": {
"start": 153,
"length": 4,
"type": "int"
},
"正向累计流量-23点": {
"start": 158,
"length": 4,
"type": "int"
},
"信号强度": {
"start": 163,
"length": 2,
"type": "short"
}
},
"groups": [
{
"name": "水表",
"devices": [
{
"name": "03221018200673",
"pointConfig": {
"数据标识": {
"start": 15,
"length": 2,
"type": "hex"
},
"正向累计量单位": {
"start": 17,
"length": 1,
"type": "hex"
},
"反向累计量单位": {
"start": 18,
"length": 1,
"type": "hex"
},
"瞬时流量单位": {
"start": 19,
"length": 1,
"type": "hex"
},
"水压单位": {
"start": 20,
"length": 1,
"type": "hex"
},
"正向累计水量": {
"start": 21,
"length": 4,
"type": "int"
},
"剩余金额": {
"start": 25,
"length": 4,
"type": "int"
},
"状态": {
"start": 29,
"length": 4,
"type": "hex"
},
"充值识别码": {
"start": 33,
"length": 1,
"type": "hex"
},
"反向累计流量": {
"start": 34,
"length": 4,
"type": "int"
},
"瞬时流量": {
"start": 38,
"length": 3,
"type": "int"
},
"水压": {
"start": 41,
"length": 2,
"type": "short"
},
"正向累计流量-0点": {
"start": 43,
"length": 4,
"type": "int"
},
"正向累计流量-1点": {
"start": 48,
"length": 4,
"type": "int"
},
"正向累计流量-2点": {
"start": 53,
"length": 4,
"type": "int"
},
"正向累计流量-3点": {
"start": 58,
"length": 4,
"type": "int"
},
"正向累计流量-4点": {
"start": 63,
"length": 4,
"type": "int"
},
"正向累计流量-5点": {
"start": 68,
"length": 4,
"type": "int"
},
"正向累计流量-6点": {
"start": 73,
"length": 4,
"type": "int"
},
"正向累计流量-7点": {
"start": 78,
"length": 4,
"type": "int"
},
"正向累计流量-8点": {
"start": 83,
"length": 4,
"type": "int"
},
"正向累计流量-9点": {
"start": 88,
"length": 4,
"type": "int"
},
"正向累计流量-10点": {
"start": 93,
"length": 4,
"type": "int"
},
"正向累计流量-11点": {
"start": 98,
"length": 4,
"type": "int"
},
"正向累计流量-12点": {
"start": 103,
"length": 4,
"type": "int"
},
"正向累计流量-13点": {
"start": 108,
"length": 4,
"type": "int"
},
"正向累计流量-14点": {
"start": 113,
"length": 4,
"type": "int"
},
"正向累计流量-15点": {
"start": 118,
"length": 4,
"type": "int"
},
"正向累计流量-16点": {
"start": 123,
"length": 4,
"type": "int"
},
"正向累计流量-17点": {
"start": 128,
"length": 4,
"type": "int"
},
"正向累计流量-18点": {
"start": 133,
"length": 4,
"type": "int"
},
"正向累计流量-19点": {
"start": 138,
"length": 4,
"type": "int"
},
"正向累计流量-20点": {
"start": 143,
"length": 4,
"type": "int"
},
"正向累计流量-21点": {
"start": 148,
"length": 4,
"type": "int"
},
"正向累计流量-22点": {
"start": 153,
"length": 4,
"type": "int"
},
"正向累计流量-23点": {
"start": 158,
"length": 4,
"type": "int"
},
"信号强度": {
"start": 163,
"length": 2,
"type": "short"
}
}
"name": "06020107200636"
},
{
"name": "06020107200636",
"pointConfig": {
"数据标识": {
"start": 15,
"length": 2,
"type": "hex"
},
"正向累计量单位": {
"start": 17,
"length": 1,
"type": "hex"
},
"反向累计量单位": {
"start": 18,
"length": 1,
"type": "hex"
},
"瞬时流量单位": {
"start": 19,
"length": 1,
"type": "hex"
},
"水压单位": {
"start": 20,
"length": 1,
"type": "hex"
},
"正向累计水量": {
"start": 21,
"length": 4,
"type": "int"
},
"剩余金额": {
"start": 25,
"length": 4,
"type": "int"
},
"状态": {
"start": 29,
"length": 4,
"type": "hex"
},
"充值识别码": {
"start": 33,
"length": 1,
"type": "hex"
},
"反向累计流量": {
"start": 34,
"length": 4,
"type": "int"
},
"瞬时流量": {
"start": 38,
"length": 3,
"type": "int"
},
"水压": {
"start": 41,
"length": 2,
"type": "short"
},
"正向累计流量-0点": {
"start": 43,
"length": 4,
"type": "int"
},
"正向累计流量-1点": {
"start": 48,
"length": 4,
"type": "int"
},
"正向累计流量-2点": {
"start": 53,
"length": 4,
"type": "int"
},
"正向累计流量-3点": {
"start": 58,
"length": 4,
"type": "int"
},
"正向累计流量-4点": {
"start": 63,
"length": 4,
"type": "int"
},
"正向累计流量-5点": {
"start": 68,
"length": 4,
"type": "int"
},
"正向累计流量-6点": {
"start": 73,
"length": 4,
"type": "int"
},
"正向累计流量-7点": {
"start": 78,
"length": 4,
"type": "int"
},
"正向累计流量-8点": {
"start": 83,
"length": 4,
"type": "int"
},
"正向累计流量-9点": {
"start": 88,
"length": 4,
"type": "int"
},
"正向累计流量-10点": {
"start": 93,
"length": 4,
"type": "int"
},
"正向累计流量-11点": {
"start": 98,
"length": 4,
"type": "int"
},
"正向累计流量-12点": {
"start": 103,
"length": 4,
"type": "int"
},
"正向累计流量-13点": {
"start": 108,
"length": 4,
"type": "int"
},
"正向累计流量-14点": {
"start": 113,
"length": 4,
"type": "int"
},
"正向累计流量-15点": {
"start": 118,
"length": 4,
"type": "int"
},
"正向累计流量-16点": {
"start": 123,
"length": 4,
"type": "int"
},
"正向累计流量-17点": {
"start": 128,
"length": 4,
"type": "int"
},
"正向累计流量-18点": {
"start": 133,
"length": 4,
"type": "int"
},
"正向累计流量-19点": {
"start": 138,
"length": 4,
"type": "int"
},
"正向累计流量-20点": {
"start": 143,
"length": 4,
"type": "int"
},
"正向累计流量-21点": {
"start": 148,
"length": 4,
"type": "int"
},
"正向累计流量-22点": {
"start": 153,
"length": 4,
"type": "int"
},
"正向累计流量-23点": {
"start": 158,
"length": 4,
"type": "int"
},
"信号强度": {
"start": 163,
"length": 2,
"type": "short"
}
}
"name": "03221018200673"
},
{
"name": "09451018200637"
}
]
}