Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void notify(NotifyInfo ...infos) { | 
|---|
|  |  |  | notify.notify(rtuAddr, ProtocolConstantV206V1.protocolName, ProtocolConstantV206V1.protocolVer, infos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | isFail = true ; | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1.protocolName, rtuAddr, "严重错误,分析Rtu数据出错!数据为:" + upHex + (e.getMessage() == null?"":(",出错信息:" + e.getMessage())), e))} ; | 
|---|
|  |  |  | 
|---|
|  |  |  | index += 2 ; | 
|---|
|  |  |  | GlCreate.createRtuAddr4PUg(para.rtuAddr, preBytes, index); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(preBytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(preBytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(preBytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | ByteUtil.hex2Bytes(vo.softStartAddr, bs, 0) ; | 
|---|
|  |  |  | bytes = ByteUtil.bytesMerge(bytes, bs) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(bytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(bytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(bytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bytes = ByteUtil.bytesMerge(bytes, (byte[])para.attachment) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(bytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(bytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(bytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | index += 2 ; | 
|---|
|  |  |  | GlCreate.createRtuAddr4PUg(para.rtuAddr, preBytes, index); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(preBytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(preBytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(preBytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void createLen4PUg(byte[] bytes) throws Exception { | 
|---|
|  |  |  | int len = bytes.length - 4; | 
|---|
|  |  |  | byte[] bs = ByteUtil.int2BCD_LE(len) ; | 
|---|
|  |  |  | byte[] bs = ByteUtil.short2Bytes_LE((short)len) ; | 
|---|
|  |  |  | if(bs != null && bs.length == 1){ | 
|---|
|  |  |  | bytes[1] = bs[0] ; | 
|---|
|  |  |  | bytes[1] = 0 ; | 
|---|
|  |  |  | bytes[2] = bs[0] ; | 
|---|
|  |  |  | }else if(bs != null && bs.length > 1){ | 
|---|
|  |  |  | bytes[1] = bs[0] ; | 
|---|
|  |  |  | bytes[2] = bs[1] ; | 
|---|
|  |  |  | bytes[1] = bs[1] ; | 
|---|
|  |  |  | bytes[2] = bs[0] ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static byte[] createCrcTail4Ug(byte[] bsNoTail) throws Exception { | 
|---|
|  |  |  | short crc = new CRC16().CRC(bsNoTail, 0, bsNoTail.length -1) ; | 
|---|
|  |  |  | int crc = new CRC16().CRC16_table(bsNoTail, 0, bsNoTail.length -1) ; | 
|---|
|  |  |  | byte[] crcBs = new byte[4] ; | 
|---|
|  |  |  | ByteUtil.int2Bytes_BE(crcBs, crc, 0); | 
|---|
|  |  |  | byte[] bytes = new byte[ProtocolConstantV206V1.UG_lenTail] ; | 
|---|
|  |  |  | ByteUtil.short2Bytes_BE(bytes, crc, 0); | 
|---|
|  |  |  | bytes[0] = crcBs[2] ; | 
|---|
|  |  |  | bytes[1] = crcBs[3] ; | 
|---|
|  |  |  | bytes[2] = ProtocolConstantV206V1.P_Tail_Byte ; | 
|---|
|  |  |  | return bytes ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.dy.common.mw.protocol.p206V2; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.*; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; | 
|---|
|  |  |  | import com.dy.common.util.DateTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @AnnotationDriver(enable = true, | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void notify(NotifyInfo ...infos) { | 
|---|
|  |  |  | notify.notify(rtuAddr, ProtocolConstantV206V1.protocolName, ProtocolConstantV206V1.protocolVer, infos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.dy.common.mw.protocol.p206V2.parse; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.*; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.CodeV2; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.ParseParamsForDownV2; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.ProtocolConstantV206V2; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.parse.global.GlCreate; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; | 
|---|
|  |  |  | import com.dy.common.util.ByteUtil; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | index += 2 ; | 
|---|
|  |  |  | GlCreate.createRtuAddr4PUg(para.rtuAddr, preBytes, index); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(preBytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(preBytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(preBytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.CodeV2; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.ParseParamsForDownV2; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.ProtocolConstantV206V2; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.parse.global.GlCreate; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; | 
|---|
|  |  |  | import com.dy.common.softUpgrade.Com1601Vo; | 
|---|
|  |  |  | import com.dy.common.util.ByteUtil; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | ByteUtil.hex2Bytes(vo.softStartAddr, bs, 0) ; | 
|---|
|  |  |  | bytes = ByteUtil.bytesMerge(bytes, bs) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(bytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(bytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(bytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bytes = ByteUtil.bytesMerge(bytes, (byte[])para.attachment) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(bytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(bytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(bytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | index += 2 ; | 
|---|
|  |  |  | GlCreate.createRtuAddr4PUg(para.rtuAddr, preBytes, index); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(preBytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(preBytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(preBytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.dy.common.mw.protocol.p206V2.parse.global; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.ProtocolConstantV206V2; | 
|---|
|  |  |  | import com.dy.common.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | bsNoTail[ProtocolConstantV206V2.dataLenIndex] = (byte)len ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void createLen4PUg(byte[] bytes) throws Exception { | 
|---|
|  |  |  | int len = bytes.length - 4; | 
|---|
|  |  |  | byte[] bs = ByteUtil.short2Bytes_LE((short)len) ; | 
|---|
|  |  |  | if(bs != null && bs.length == 1){ | 
|---|
|  |  |  | bytes[1] = 0 ; | 
|---|
|  |  |  | bytes[2] = bs[0] ; | 
|---|
|  |  |  | }else if(bs != null && bs.length > 1){ | 
|---|
|  |  |  | bytes[1] = bs[1] ; | 
|---|
|  |  |  | bytes[2] = bs[0] ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 生成IC卡编码 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static byte[] createCrcTail4Ug(byte[] bsNoTail) throws Exception { | 
|---|
|  |  |  | int crc = new CRC16().CRC(bsNoTail, 0, bsNoTail.length -1) ; | 
|---|
|  |  |  | int crc = new CRC16().CRC16_table(bsNoTail, 0, bsNoTail.length -1) ; | 
|---|
|  |  |  | byte[] crcBs = new byte[4] ; | 
|---|
|  |  |  | ByteUtil.int2Bytes_BE(crcBs, crc, 0); | 
|---|
|  |  |  | byte[] bytes = new byte[ProtocolConstantV206V2.UG_lenTail] ; | 
|---|
|  |  |  | ByteUtilUnsigned.short2Bytes_BE(bytes, crc, 0); | 
|---|
|  |  |  | bytes[2] = ProtocolConstantV206V2.P_Tail_Byte ; | 
|---|
|  |  |  | bytes[0] = crcBs[2] ; | 
|---|
|  |  |  | bytes[1] = crcBs[3] ; | 
|---|
|  |  |  | bytes[2] = ProtocolConstantV206V1.P_Tail_Byte ; | 
|---|
|  |  |  | return bytes ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if(crcStr != null){ | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V202404.protocolName, rtuAddr, "严重错误,上行数据CRC检查失败," + crcStr, null))} ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | rtuAddr = cp.parseRtuAddr(upBuffer) ; | 
|---|
|  |  |  | upCode = cp.parseCode(upBuffer) ; | 
|---|
|  |  |  | if(upCode == null){ | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V202404.protocolName, rtuAddr, "严重错误,未能从上行数据中解析出功能码!", null))} ; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void notify(NotifyInfo ...infos) { | 
|---|
|  |  |  | notify.notify(rtuAddr, ProtocolConstantV206V1.protocolName, ProtocolConstantV206V1.protocolVer, infos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | index += 2 ; | 
|---|
|  |  |  | GlCreate.createRtuAddr4PUg(para.rtuAddr, preBytes, index); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(preBytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(preBytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(preBytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | ByteUtil.hex2Bytes(vo.softStartAddr, bs, 0) ; | 
|---|
|  |  |  | bytes = ByteUtil.bytesMerge(bytes, bs) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(bytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(bytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(bytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bytes = ByteUtil.bytesMerge(bytes, (byte[])para.attachment) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(bytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(bytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(bytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | index += 2 ; | 
|---|
|  |  |  | GlCreate.createRtuAddr4PUg(para.rtuAddr, preBytes, index); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GlCreate.createLen4PUg(preBytes);//长度放字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] bsTail = GlCreate.createCrcTail4Ug(preBytes) ;//CRC和尾叠加字节数组中 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ByteUtil.bytesMerge(preBytes, bsTail) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.dy.common.mw.protocol.p206V202404.parse.global; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.ProtocolConstantV206V2; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V202404.CommonV202404; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V202404.ProtocolConstantV206V202404; | 
|---|
|  |  |  | import com.dy.common.util.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void createLen(byte[] bsNoTail) throws Exception { | 
|---|
|  |  |  | int len = bsNoTail.length - ProtocolConstantV206V1.lenHead2ctrl; | 
|---|
|  |  |  | bsNoTail[ProtocolConstantV206V1.dataLenIndex] = (byte)len ; | 
|---|
|  |  |  | int len = bsNoTail.length - ProtocolConstantV206V202404.lenHead2ctrl; | 
|---|
|  |  |  | bsNoTail[ProtocolConstantV206V202404.dataLenIndex] = (byte)len ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void createLen4PUg(byte[] bytes) throws Exception { | 
|---|
|  |  |  | int len = bytes.length - 4; | 
|---|
|  |  |  | byte[] bs = ByteUtil.short2Bytes_LE((short)len) ; | 
|---|
|  |  |  | if(bs != null && bs.length == 1){ | 
|---|
|  |  |  | bytes[1] = 0 ; | 
|---|
|  |  |  | bytes[2] = bs[0] ; | 
|---|
|  |  |  | }else if(bs != null && bs.length > 1){ | 
|---|
|  |  |  | bytes[1] = bs[1] ; | 
|---|
|  |  |  | bytes[2] = bs[0] ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static byte[] createCrcTail(byte[] bsNoTail) throws Exception { | 
|---|
|  |  |  | int crc = new CRC8_for_2_0().CRC8(bsNoTail, ProtocolConstantV206V1.ctrlIndex, bsNoTail.length -1) ; | 
|---|
|  |  |  | byte[] bytes = new byte[ProtocolConstantV206V1.lenTail] ; | 
|---|
|  |  |  | int crc = new CRC8_for_2_0().CRC8(bsNoTail, ProtocolConstantV206V202404.ctrlIndex, bsNoTail.length -1) ; | 
|---|
|  |  |  | byte[] bytes = new byte[ProtocolConstantV206V202404.lenTail] ; | 
|---|
|  |  |  | bytes[0] = (byte)crc ; | 
|---|
|  |  |  | bytes[1] = ProtocolConstantV206V1.P_Tail_Byte ; | 
|---|
|  |  |  | bytes[1] = ProtocolConstantV206V202404.P_Tail_Byte ; | 
|---|
|  |  |  | return bytes ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static byte[] createCrcTail4Ug(byte[] bsNoTail) throws Exception { | 
|---|
|  |  |  | int crc = new CRC16().CRC(bsNoTail, 0, bsNoTail.length -1) ; | 
|---|
|  |  |  | byte[] bytes = new byte[ProtocolConstantV206V2.UG_lenTail] ; | 
|---|
|  |  |  | ByteUtilUnsigned.short2Bytes_BE(bytes, crc, 0); | 
|---|
|  |  |  | bytes[2] = ProtocolConstantV206V2.P_Tail_Byte ; | 
|---|
|  |  |  | int crc = new CRC16().CRC16_table(bsNoTail, 0, bsNoTail.length -1) ; | 
|---|
|  |  |  | byte[] crcBs = new byte[4] ; | 
|---|
|  |  |  | ByteUtil.int2Bytes_BE(crcBs, crc, 0); | 
|---|
|  |  |  | byte[] bytes = new byte[ProtocolConstantV206V202404.UG_lenTail] ; | 
|---|
|  |  |  | bytes[0] = crcBs[2] ; | 
|---|
|  |  |  | bytes[1] = crcBs[3] ; | 
|---|
|  |  |  | bytes[2] = ProtocolConstantV206V202404.P_Tail_Byte ; | 
|---|
|  |  |  | return bytes ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | package com.dy.common.util; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("unused") | 
|---|
|  |  |  | public final class CRC16 { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return (short)crc; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final int[] crc16_rev_table = new int[] | 
|---|
|  |  |  | {   0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, | 
|---|
|  |  |  | 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, | 
|---|
|  |  |  | 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, | 
|---|
|  |  |  | 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, | 
|---|
|  |  |  | 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, | 
|---|
|  |  |  | 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, | 
|---|
|  |  |  | 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, | 
|---|
|  |  |  | 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, | 
|---|
|  |  |  | 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, | 
|---|
|  |  |  | 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, | 
|---|
|  |  |  | 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, | 
|---|
|  |  |  | 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, | 
|---|
|  |  |  | 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, | 
|---|
|  |  |  | 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, | 
|---|
|  |  |  | 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, | 
|---|
|  |  |  | 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, | 
|---|
|  |  |  | 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, | 
|---|
|  |  |  | 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, | 
|---|
|  |  |  | 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, | 
|---|
|  |  |  | 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, | 
|---|
|  |  |  | 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, | 
|---|
|  |  |  | 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, | 
|---|
|  |  |  | 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, | 
|---|
|  |  |  | 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, | 
|---|
|  |  |  | 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, | 
|---|
|  |  |  | 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, | 
|---|
|  |  |  | 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, | 
|---|
|  |  |  | 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, | 
|---|
|  |  |  | 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, | 
|---|
|  |  |  | 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, | 
|---|
|  |  |  | 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, | 
|---|
|  |  |  | 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final int[] crc16_rev_table = new int[]{ | 
|---|
|  |  |  | 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, | 
|---|
|  |  |  | 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, | 
|---|
|  |  |  | 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, | 
|---|
|  |  |  | 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, | 
|---|
|  |  |  | 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, | 
|---|
|  |  |  | 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, | 
|---|
|  |  |  | 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, | 
|---|
|  |  |  | 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, | 
|---|
|  |  |  | 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, | 
|---|
|  |  |  | 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, | 
|---|
|  |  |  | 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, | 
|---|
|  |  |  | 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, | 
|---|
|  |  |  | 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, | 
|---|
|  |  |  | 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, | 
|---|
|  |  |  | 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, | 
|---|
|  |  |  | 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, | 
|---|
|  |  |  | 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, | 
|---|
|  |  |  | 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, | 
|---|
|  |  |  | 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, | 
|---|
|  |  |  | 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, | 
|---|
|  |  |  | 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, | 
|---|
|  |  |  | 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, | 
|---|
|  |  |  | 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, | 
|---|
|  |  |  | 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, | 
|---|
|  |  |  | 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, | 
|---|
|  |  |  | 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, | 
|---|
|  |  |  | 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, | 
|---|
|  |  |  | 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, | 
|---|
|  |  |  | 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, | 
|---|
|  |  |  | 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, | 
|---|
|  |  |  | 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, | 
|---|
|  |  |  | 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 16位的CRC值是无符号两字节整数, | 
|---|
|  |  |  | * @param bs 字节数组 | 
|---|
|  |  |  | * @param startIndex 开始下标 | 
|---|
|  |  |  | * @param endIndex 截止下标 | 
|---|
|  |  |  | * @return CRC | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @SuppressWarnings("unused") | 
|---|
|  |  |  | public int CRC16_table(byte[] bs, int startIndex, int endIndex) { | 
|---|
|  |  |  | int x ; | 
|---|
|  |  |  | int crc = 0xffff; | 
|---|
|  |  |  | if(bs != null && bs.length >= endIndex + 1){ | 
|---|
|  |  |  | for (int i = startIndex ; i <= endIndex; i++){ | 
|---|
|  |  |  | x =  (crc ^ bs[i]) ; | 
|---|
|  |  |  | crc =  ((crc >> 8) ^ crc16_rev_table[x & 0x00FF]) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return crc ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 16位的CRC值 ,查表法 | 
|---|
|  |  |  | * @param bs 字节数组 | 
|---|
|  |  |  | * @return CRC | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @SuppressWarnings("unused") | 
|---|
|  |  |  | public int CRC_table(byte[] bs) { | 
|---|
|  |  |  | int x ; | 
|---|
|  |  |  | int crc = 0xffff; | 
|---|
|  |  |  | public short CRC16_table(byte[] bs) { | 
|---|
|  |  |  | short x ; | 
|---|
|  |  |  | short crc = (short)0xffff; | 
|---|
|  |  |  | if(bs != null && bs.length > 0){ | 
|---|
|  |  |  | for(byte b : bs){ | 
|---|
|  |  |  | x = crc ^ b ; | 
|---|
|  |  |  | crc = (crc >> 8) ^ crc16_rev_table[x & 0x00FF]; | 
|---|
|  |  |  | x = (short)(crc ^ b) ; | 
|---|
|  |  |  | crc = (short)((crc >> 8) ^ crc16_rev_table[x & 0x00FF]) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return crc ; | 
|---|
|  |  |  | 
|---|
|  |  |  | System.arraycopy(new byte[] {(byte)(c - ((c / 256) * 256)) }, 0, crc, 1, 1); | 
|---|
|  |  |  | return crc; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) throws Exception { | 
|---|
|  |  |  | int s = 62430 ; | 
|---|
|  |  |  | //String hex = "AA0018AA16015301150599800001100000014A005D4D5D4D00004000AA7E16" ; | 
|---|
|  |  |  | String hex = "AA0018AA16015301150599800001100000014A005D4D5D4D00004000" ; | 
|---|
|  |  |  | byte[] bs = ByteUtil.hex2Bytes(hex) ; | 
|---|
|  |  |  | int crc = new CRC16().CRC16_table(bs, 0 , bs.length - 1) ; | 
|---|
|  |  |  | byte[] crcBs = new byte[4] ; | 
|---|
|  |  |  | ByteUtil.int2Bytes_BE(crcBs, crc, 0); | 
|---|
|  |  |  | System.out.println(ByteUtil.bytes2Hex(crcBs, true)) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | String url = UriComponentsBuilder.fromUriString(toMwUrl) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .toUriString(); | 
|---|
|  |  |  | HttpHeaders headers = new HttpHeaders(); | 
|---|
|  |  |  | HttpEntity<?> httpEntity = new HttpEntity<>(headers); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) | 
|---|
|  |  |  | //        .queryParam("test", test); | 
|---|
|  |  |  | UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ResponseEntity<BaseResponse> response = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | // 通过Post方式调用接口 | 
|---|
|  |  |  | response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, BaseResponse.class); | 
|---|
|  |  |  | // 通过Get方式调用接口 | 
|---|
|  |  |  | response = restTemplate.exchange(builder.toUriString(), | 
|---|
|  |  |  | HttpMethod.GET, | 
|---|
|  |  |  | new HttpEntity<>(new HttpHeaders()), | 
|---|
|  |  |  | BaseResponse.class); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return BaseResponseUtils.buildError("后端系统出错,中间件调用异常"); | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.dy.rtuMw.server.forTcp.MidResultActionError; | 
|---|
|  |  |  | import com.dy.rtuMw.server.forTcp.MidResultActionFromRtu; | 
|---|
|  |  |  | import com.dy.rtuMw.server.forTcp.MidResultActionToRtu; | 
|---|
|  |  |  | import com.dy.rtuMw.server.protocolDriver.RtuInfoNotify; | 
|---|
|  |  |  | import com.dy.rtuMw.server.rtuStatus.RtuInfoNotify; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class AdapterImp_ProtocolUnit implements ProtocolUnitAdapter { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | this.valveCloseLastDt = DateTime.yyyy_MM_dd_HH_mm_ss() ; | 
|---|
|  |  |  | this.valveStatusLastTimeStamp = System.currentTimeMillis() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | * 得到部分状态 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static Map<String, RtuStatus> partStatus(String[] rtuAddrArrGrp){ | 
|---|
|  |  |  | public static Map<String, RtuStatus> someStatus(String[] rtuAddrArrGrp){ | 
|---|
|  |  |  | synchronized (map){ | 
|---|
|  |  |  | Map<String, RtuStatus> map = new HashMap<>(); | 
|---|
|  |  |  | Map<String, RtuStatus> rsMap = new HashMap<>(); | 
|---|
|  |  |  | for(String rtuAddr : rtuAddrArrGrp){ | 
|---|
|  |  |  | RtuStatus status = map.get(rtuAddr) ; | 
|---|
|  |  |  | if(status != null){ | 
|---|
|  |  |  | map.put(rtuAddr, status) ; | 
|---|
|  |  |  | rsMap.put(rtuAddr, status) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return map ; | 
|---|
|  |  |  | return rsMap ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到一个RTU的状态 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static RtuStatus oneStatus(String rtuAddr){ | 
|---|
|  |  |  | return map.get(rtuAddr) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void onLine(String rtuAddr, String ip, Integer port, String protocolName, Short protocolVersion){ | 
|---|
|  |  |  | RtuStatus vo = map.get(rtuAddr) ; | 
|---|
|  |  |  | if(vo == null) { | 
|---|
|  |  |  | 
|---|
|  |  |  | * 得到Tcp通信协议名称 | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | public static String getTcpProtocolName(String rtuAddr){ | 
|---|
|  |  |  | TcpSession tcpSe = sessionTable.get(rtuAddr) ; | 
|---|
|  |  |  | if(tcpSe != null){ | 
|---|
|  |  |  | return tcpSe.protocolName ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到Tcp通信协议名称 | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * */ | 
|---|
|  |  |  | public static Object[] getTcpProtocolNameVersion(String rtuAddr){ | 
|---|
|  |  |  | TcpSession tcpSe = map.get(rtuAddr) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | return map ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    /** | 
|---|
|  |  |  | //     * 得到所有RTU连接状态情况 | 
|---|
|  |  |  | //     * @return | 
|---|
|  |  |  | //     */ | 
|---|
|  |  |  | //    public static List<RtuSessionStatus> allConnectStatus(){ | 
|---|
|  |  |  | //        synchronized (sessionTable){ | 
|---|
|  |  |  | //            List<RtuSessionStatus> list = new ArrayList<RtuSessionStatus>(); | 
|---|
|  |  |  | //            Iterator<Entry<String, TcpSession>> it = sessionTable.entrySet().iterator() ; | 
|---|
|  |  |  | //            Entry<String, TcpSession> entry = null ; | 
|---|
|  |  |  | //            while(it.hasNext()){ | 
|---|
|  |  |  | //                entry = it.next() ; | 
|---|
|  |  |  | //                RtuSessionStatus vo = new RtuSessionStatus() ; | 
|---|
|  |  |  | //                vo.rtuAddr = entry.getKey() ; | 
|---|
|  |  |  | //                IoSession se = entry.getValue().ioSession ; | 
|---|
|  |  |  | //                vo.onTrueOffLine = se.isConnected() ; | 
|---|
|  |  |  | //                InetSocketAddress sa = (InetSocketAddress)se.getRemoteAddress() ; | 
|---|
|  |  |  | //                if(sa != null){ | 
|---|
|  |  |  | //                    InetAddress inetAddr = sa.getAddress() ; | 
|---|
|  |  |  | //                    if(inetAddr != null){ | 
|---|
|  |  |  | //                        vo.ip = inetAddr.getHostAddress() ; | 
|---|
|  |  |  | //                        vo.port = sa.getPort() ; | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                list.add(vo) ; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            return list ; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | // | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 得到IoSession | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //    public IoSession getIoSession(String rtuAddr){ | 
|---|
|  |  |  | //        TcpSession tcpSe = sessionMap.get(rtuAddr) ; | 
|---|
|  |  |  | //        if(tcpSe != null){ | 
|---|
|  |  |  | //            return tcpSe.ioSession ; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return null ; | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 网络是否连接 | 
|---|
|  |  |  | * @param rtuAddr | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    public static void updateRtuStatus(Long now){ | 
|---|
|  |  |  | //        synchronized (sessionTable){ | 
|---|
|  |  |  | //            Iterator<TcpSession> it = sessionTable.values().iterator() ; | 
|---|
|  |  |  | //            TcpSession tcpSe ; | 
|---|
|  |  |  | //            while(it.hasNext()){ | 
|---|
|  |  |  | //                tcpSe = it.next() ; | 
|---|
|  |  |  | //                if(tcpSe.lastUpDataTime != null){ | 
|---|
|  |  |  | //                    if(now - tcpSe.lastUpDataTime > ServerProperties.lastUpDataTimeLive){ | 
|---|
|  |  |  | //                        tcpSe.lastUpDataTime = null ; | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | }else if(code.equals(CodeLocal.allRtuStates)){ | 
|---|
|  |  |  | return this.allRtuStates(com) ; | 
|---|
|  |  |  | }else if(code.equals(CodeLocal.partRtuStates)){ | 
|---|
|  |  |  | return this.partRtuStates(com) ; | 
|---|
|  |  |  | return this.someRtuStates(com) ; | 
|---|
|  |  |  | }else if(code.equals(CodeLocal.oneRtuStates)){ | 
|---|
|  |  |  | return this.oneRtuStates(com) ; | 
|---|
|  |  |  | }else if(code.equals(CodeLocal.allProtocols)){ | 
|---|
|  |  |  | return this.allProtocols(com) ; | 
|---|
|  |  |  | }else if(code.equals(CodeLocal.stopTcpSv)){ | 
|---|
|  |  |  | 
|---|
|  |  |  | * 查询部分RTU状态 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Command partRtuStates(Command command) throws Exception{ | 
|---|
|  |  |  | private Command someRtuStates(Command command) throws Exception{ | 
|---|
|  |  |  | if(command.param != null && command.param instanceof String && !command.param.equals("")){ | 
|---|
|  |  |  | String[] rtuAddrGrp = ((String)command.param).split(","); | 
|---|
|  |  |  | Map<String, RtuStatus> map = new RtuStatusDeal().dealPart(rtuAddrGrp) ; | 
|---|
|  |  |  | Map<String, RtuStatus> map = new RtuStatusDeal().dealSome(rtuAddrGrp) ; | 
|---|
|  |  |  | return ReturnCommand.successed("查询部分RTU状态结果", command.getId(), command.getCode(), map) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return ReturnCommand.errored("出错,命令参数应该是所查询RTU的地址串",  command.getId(), command.getCode()) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询部分RTU状态 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Command oneRtuStates(Command command) throws Exception{ | 
|---|
|  |  |  | if(command.param != null && command.param instanceof String && !command.param.equals("")){ | 
|---|
|  |  |  | String rtuAddr = (String)command.param; | 
|---|
|  |  |  | RtuStatus rtuStatus = new RtuStatusDeal().dealOne(rtuAddr) ; | 
|---|
|  |  |  | return ReturnCommand.successed("查询部分RTU状态结果", command.getId(), command.getCode(), rtuStatus) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return ReturnCommand.errored("出错,命令参数应该是所查询RTU的地址",  command.getId(), command.getCode()) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询所有RTU协议配置 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String partRtuStates = "LCD0011" ;//查询部分RTU状态 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String oneRtuStates = "LCD0012" ;//查询一个RTU状态 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String allProtocols = "LCD0100" ;//查询所有协议配置 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final String stopTcpSv = "LCD0110" ;//停止TCP服务,不再接入新的TCP连接,已经TCP连接的全部断连接 | 
|---|
|  |  |  | 
|---|
|  |  |  | public class RtuStatusDeal { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询在线与不在线情况 | 
|---|
|  |  |  | * 查询状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Map<String, RtuStatus> dealAll(){ | 
|---|
|  |  |  | return RtuStatusDealer.allStatus(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询在线与不在线情况 | 
|---|
|  |  |  | * 查询状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Map<String, RtuStatus> dealPart(String[] rtuAddrGrp){ | 
|---|
|  |  |  | return RtuStatusDealer.partStatus(rtuAddrGrp) ; | 
|---|
|  |  |  | public Map<String, RtuStatus> dealSome(String[] rtuAddrGrp){ | 
|---|
|  |  |  | return RtuStatusDealer.someStatus(rtuAddrGrp) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public RtuStatus dealOne(String rtuAddr){ | 
|---|
|  |  |  | return RtuStatusDealer.oneStatus(rtuAddr) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
| File was renamed from pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/protocolDriver/RtuInfoNotify.java | 
|  |  |  | 
|---|
|  |  |  | package com.dy.rtuMw.server.protocolDriver; | 
|---|
|  |  |  | package com.dy.rtuMw.server.rtuStatus; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.Notify; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.NotifyInfo; | 
|---|
|  |  |  | 
|---|
|  |  |  | * 接收web系统发来强制结束升级任务 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @GetMapping(path = "ugForceOver", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @GetMapping(path = "ugForceOver") | 
|---|
|  |  |  | public BaseResponse<String> ugForceOver() { | 
|---|
|  |  |  | log.info("收到停止RTU升级任务命令") ; | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | String mes = UpgradeUnit.getInstance().forceOverUpgradeTask(); | 
|---|
|  |  |  | if(mes == null){ | 
|---|
|  |  |  | mes = "停止升级任务成功" ; | 
|---|
|  |  |  | return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.SUCCESS_CODE, mes, mes); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.FAIL_CODE, mes, mes); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.SUCCESS_CODE, mes, mes); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("停止RTU升级任务时发生异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildError("停止RTU升级任务时发生异常" + (e.getMessage() == null?"":(":" + e.getMessage()))); | 
|---|
|  |  |  | 
|---|
|  |  |  | //通信中间件内部命令,例如查询监控中间件时钟,查询RTU在线情况等 | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | Command reCom = new CommandInnerDeaLer().deal(com) ; | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | boolean error = false ; | 
|---|
|  |  |  | if(reCom.param != null && reCom.param != null){ | 
|---|
|  |  |  | CommandBackParam cbp = (CommandBackParam)reCom.param ; | 
|---|
|  |  |  | if(cbp.getSuccess() != null && !cbp.getSuccess().booleanValue()){ | 
|---|
|  |  |  | error = true ; | 
|---|
|  |  |  | return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!error){ | 
|---|
|  |  |  | return BaseResponseUtils.buildError(ReturnCommand.errored(cbp.getMessage(), com.getId(), null)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(reCom); | 
|---|
|  |  |  | }catch(Exception e){ | 
|---|
|  |  |  | return BaseResponseUtils.buildError(ReturnCommand.errored("处理内部命令出错" + (e.getMessage() == null?"":("," + e.getMessage())), com.getId(), com.getCode()) ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else if(commandType.equals(CommandType.outerCommand)){ | 
|---|
|  |  |  | //发向RTU的外部命令,异步处理,web端jroups成员同步得到命令处理结果,但构造命令及下发命令和命令结果接收要异步得到 | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | 
|---|
|  |  |  | BaseResponse res = sendGetRequest2Mw(restTemplate, rqUrl) ; | 
|---|
|  |  |  | if(res != null){ | 
|---|
|  |  |  | if(res.isSuccess()){ | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | RtuUpgradeStateReceiverCtrl.afterMwForceOverCurUgTask(); | 
|---|
|  |  |  | String msg = res.getContent()==null?null:(String)res.getContent() ; | 
|---|
|  |  |  | if(msg == null){ | 
|---|
|  |  |  | msg = res.getMsg() ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildResult(ResultCodeMsg.RsCode.SUCCESS_CODE, msg, msg) ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | String msg = res.getContent()==null?null:(String)res.getContent() ; | 
|---|
|  |  |  | if(msg == null){ | 
|---|
|  |  |  | 
|---|
|  |  |  | private RtuUpgradeSv sv ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 强制结束升级任务通信中间件成功执行后 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static void afterMwForceOverCurUgTask(){ | 
|---|
|  |  |  | cache = null ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * rtu远程升级任务通信中间件执行情况统计回收 | 
|---|
|  |  |  | * @param info 数据 | 
|---|
|  |  |  | * @return 操作结果 | 
|---|
|  |  |  | 
|---|
|  |  |  | for (int i = list.size()-1; i >= 0 ; i--) { | 
|---|
|  |  |  | Optional.ofNullable(list.get(i).getGift()).orElse(0d); | 
|---|
|  |  |  | if (!list.get(i).getGift().equals(0d)){ | 
|---|
|  |  |  | Double gift1 = list.get(i).getGift(); | 
|---|
|  |  |  | String districtTitle = list.get(i).getDistrictTitle(); | 
|---|
|  |  |  | String clientNum = list.get(i).getClientNum(); | 
|---|
|  |  |  | String clientName = list.get(i).getClientName(); | 
|---|
|  |  |  | String phone = list.get(i).getPhone(); | 
|---|
|  |  |  | Date tradeTime = list.get(i).getTradeTime(); | 
|---|
|  |  |  | Double gift1 = list.get(i).getGift();//赠送金额 | 
|---|
|  |  |  | String districtTitle = list.get(i).getDistrictTitle();//地址 | 
|---|
|  |  |  | String clientNum = list.get(i).getClientNum();//农户编号 | 
|---|
|  |  |  | String clientName = list.get(i).getClientName();//农户姓名 | 
|---|
|  |  |  | String phone = list.get(i).getPhone();//手机号 | 
|---|
|  |  |  | Date tradeTime = list.get(i).getTradeTime();//交易时间 | 
|---|
|  |  |  | String orderNumber = list.get(i).getOrderNumber();//订单编号 | 
|---|
|  |  |  | String cardNum = list.get(i).getCardNum();//卡编号 | 
|---|
|  |  |  | String idCard = list.get(i).getIdCard();//身份证 | 
|---|
|  |  |  | String cashierName = list.get(i).getCashierName();//操作人 | 
|---|
|  |  |  | Double money = list.get(i).getMoney();//余额 | 
|---|
|  |  |  | Double cardCost1 = list.get(i).getCardCost();//购卡金额 | 
|---|
|  |  |  | Double tradeAmount = list.get(i).getTradeAmount();//交易金额 | 
|---|
|  |  |  | Double waterCost1 = list.get(i).getWaterCost();//购水金额 | 
|---|
|  |  |  | Double refundAmount1 = list.get(i).getRefundAmount();//返回金额 | 
|---|
|  |  |  | String paymentName = list.get(i).getPaymentName();//支付方式 | 
|---|
|  |  |  | String operateType = list.get(i).getOperateType();//业务类型 | 
|---|
|  |  |  | String cardState = list.get(i).getCardState();//卡状态 | 
|---|
|  |  |  | Long villageId = list.get(i).getVillageId();//村id | 
|---|
|  |  |  | Long cashierId = list.get(i).getCashierId();//收银员id | 
|---|
|  |  |  |  | 
|---|
|  |  |  | list.get(i).setGift(0d); | 
|---|
|  |  |  | list.get(i).setMoney(money-gift1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | VoTradeDetails voTradeDetail = new VoTradeDetails(); | 
|---|
|  |  |  | voTradeDetail.setDistrictTitle(districtTitle); | 
|---|
|  |  |  | voTradeDetail.setClientNum(clientNum); | 
|---|
|  |  |  | voTradeDetail.setClientName(clientName); | 
|---|
|  |  |  | voTradeDetail.setPhone(phone); | 
|---|
|  |  |  | voTradeDetail.setOperateType("赠送"); | 
|---|
|  |  |  | voTradeDetail.setTradeTime(tradeTime); | 
|---|
|  |  |  | voTradeDetail.setWaterCost(0d); | 
|---|
|  |  |  | voTradeDetail.setCardCost(0d); | 
|---|
|  |  |  | voTradeDetail.setGift(gift1); | 
|---|
|  |  |  | voTradeDetail.setDistrictTitle(districtTitle);//2 | 
|---|
|  |  |  | voTradeDetail.setClientNum(clientNum);//2 | 
|---|
|  |  |  | voTradeDetail.setClientName(clientName);//2 | 
|---|
|  |  |  | voTradeDetail.setPhone(phone);//2 | 
|---|
|  |  |  | voTradeDetail.setOperateType("赠送");//2 | 
|---|
|  |  |  | voTradeDetail.setTradeTime(tradeTime);//2 | 
|---|
|  |  |  | voTradeDetail.setWaterCost(0d);//2 | 
|---|
|  |  |  | voTradeDetail.setCardCost(0d);//2 | 
|---|
|  |  |  | voTradeDetail.setGift(gift1);//2 | 
|---|
|  |  |  | voTradeDetail.setTradeAmount(0d);//2 | 
|---|
|  |  |  | voTradeDetail.setRefundAmount(refundAmount1);//2 | 
|---|
|  |  |  | voTradeDetail.setMoney(money);//待2 | 
|---|
|  |  |  | voTradeDetail.setPaymentName("赠送");//2 | 
|---|
|  |  |  | voTradeDetail.setOrderNumber(orderNumber);//2 | 
|---|
|  |  |  | voTradeDetail.setCardNum(cardNum);//2 | 
|---|
|  |  |  | voTradeDetail.setIdCard(idCard);//2 | 
|---|
|  |  |  | voTradeDetail.setCashierName(cashierName);//2 | 
|---|
|  |  |  | voTradeDetail.setCashierId(cashierId);//2 | 
|---|
|  |  |  | voTradeDetail.setCardState(cardState);//2 | 
|---|
|  |  |  | voTradeDetail.setVillageId(villageId);//2 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | list.add(voTradeDetail); | 
|---|
|  |  |  | itemTotal = itemTotal + 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | list.sort(Comparator.comparing(VoTradeDetails::getTradeTime)); | 
|---|
|  |  |  | rsVo.obj = list; | 
|---|
|  |  |  | rsVo.calculateAndSet(itemTotal, params); | 
|---|
|  |  |  |  | 
|---|