|  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.parse.global.GlParse; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.upVos.DataCd83CloseVo; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.upVos.DataCd83OpenVo; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.rtuState.ValveStateInfo; | 
|---|
|  |  |  | import com.dy.common.util.ByteUtil; | 
|---|
|  |  |  | import org.apache.logging.log4j.LogManager; | 
|---|
|  |  |  | import org.apache.logging.log4j.Logger; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback)throws Exception { | 
|---|
|  |  |  | ParseParamsForUpV1 para = (ParseParamsForUpV1)params ; | 
|---|
|  |  |  | int bsLen = new CommonV1().parseDataLen(para.upBuffer) ; | 
|---|
|  |  |  | int bsLen = new CommonV1().parseDataLen4P206(para.upBuffer) ; | 
|---|
|  |  |  | if(bsLen > 0){ | 
|---|
|  |  |  | this.doParse(para.upBuffer, | 
|---|
|  |  |  | bsLen, | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MidResultFromRtu midRs = new MidResultFromRtu() ; | 
|---|
|  |  |  | midRs.protocolName = para.protocolName ;//协议名称 | 
|---|
|  |  |  | midRs.protocolVersion = para.protocolVersion; //协议版本号 | 
|---|
|  |  |  | midRs.rtuAddr = para.rtuAddr ;//Rtu地址 | 
|---|
|  |  |  | midRs.upCode = para.upCode ;//上行数据中的功能码 | 
|---|
|  |  |  | midRs.upHex = para.upHex ;//上行数据十六进制形式 | 
|---|
|  |  |  | 
|---|
|  |  |  | downCpParams.setValue( | 
|---|
|  |  |  | null, | 
|---|
|  |  |  | ProtocolConstantV206V1.protocolName, | 
|---|
|  |  |  | para.protocolVersion, | 
|---|
|  |  |  | para.rtuAddr, | 
|---|
|  |  |  | Command.defaultId, | 
|---|
|  |  |  | confirmComCode, | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MidResultToRtu confirmCommand = new MidResultToRtu() ; | 
|---|
|  |  |  | confirmCommand.protocolName = para.protocolName ;//协议名称 | 
|---|
|  |  |  | confirmCommand.protocolVersion = para.protocolVersion ;//协议版本号 | 
|---|
|  |  |  | confirmCommand.rtuAddr = para.rtuAddr ;//Rtu地址 | 
|---|
|  |  |  | confirmCommand.commandId = Command.defaultId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 | 
|---|
|  |  |  | confirmCommand.downCode = confirmComCode ;//下行命令功能码; | 
|---|
|  |  |  | 
|---|
|  |  |  | //低功耗时,尽快发送 | 
|---|
|  |  |  | confirmCommand.isQuickSend = true ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(para.data != null && para.data.getSubData() != null){ | 
|---|
|  |  |  | Object subData = ((DataV1)para.data.getSubData()).subData ; | 
|---|
|  |  |  | if(subData instanceof DataCd83OpenVo){ | 
|---|
|  |  |  | callback.notify(new ValveStateInfo(true)); | 
|---|
|  |  |  | }else if(subData instanceof DataCd83CloseVo){ | 
|---|
|  |  |  | callback.notify(new ValveStateInfo(false)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | callback.callback(midRs.reportOrResponse_trueOrFalse); | 
|---|
|  |  |  | return new MidResult[]{midRs, confirmCommand} ; | 
|---|
|  |  |  | callback.callback(midRs.reportOrResponse_trueOrFalse, para.data.subData==null?null:((DataV1)(para.data.subData)).subData); | 
|---|
|  |  |  | return new MidResult[]{confirmCommand, midRs} ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 执行分析 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | short index = ProtocolConstantV206V1.dataIndex + 1 ; | 
|---|
|  |  |  | //累计流量:5字节BCD码,取值范围0~99999999.99,单位为m3。 | 
|---|
|  |  |  | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; | 
|---|
|  |  |  | cdData.totalAmount = tpInt/100.0 ; | 
|---|
|  |  |  | long tpLong = ByteUtil.BCD2Long_LE(bs, index, index + 4) ; | 
|---|
|  |  |  | cdData.totalAmount = tpLong/100.0 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 5 ; | 
|---|
|  |  |  | //用水户号数据格式:8字节低位在前高位在后。 | 
|---|
|  |  |  | if(ByteUtil.bytesIsAll0xFF(bs, index, 8)){ | 
|---|
|  |  |  | throw new Exception("IC卡号数据格式错误,8字节全部为0xFF,舍弃数据") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cdData.icCardNo = GlParse.parseIcCardNo(bs, index) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 8 ; | 
|---|
|  |  |  | //IC卡号格式:4字节HEX码低位在前高位在后。 | 
|---|
|  |  |  | if(ByteUtil.bytesIsAll0xFF(bs, index, 4)){ | 
|---|
|  |  |  | throw new Exception("IC地址数据格式错误,4字节全部为0xFF,舍弃数据") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cdData.icCardAddr = ByteUtil.bytes2Hex_LE(bs, false,  index, 4) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 4 ; | 
|---|
|  |  |  | //用水户余额:用户余额4字节BCD码,取值范围0.00~999999.99,单位为元。 | 
|---|
|  |  |  | tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; | 
|---|
|  |  |  | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; | 
|---|
|  |  |  | cdData.remainMoney = tpInt/100.0 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 4 ; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | short index = ProtocolConstantV206V1.dataIndex + 1 ; | 
|---|
|  |  |  | //累计流量:5字节BCD码,取值范围0~9999999999,单位为m3。 | 
|---|
|  |  |  | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; | 
|---|
|  |  |  | cdData.totalAmount = tpInt/100.0 ; | 
|---|
|  |  |  | long tpLong = ByteUtil.BCD2Long_LE(bs, index, index + 4) ; | 
|---|
|  |  |  | cdData.totalAmount = tpLong/100.0 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 5 ; | 
|---|
|  |  |  | //用水户号数据格式:8字节低位在前高位在后。 | 
|---|
|  |  |  | if(ByteUtil.bytesIsAll0xFF(bs, index, 8)){ | 
|---|
|  |  |  | throw new Exception("IC卡号数据格式错误,8字节全部为0xFF,舍弃数据") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cdData.icCardNo = GlParse.parseIcCardNo(bs, index) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 8 ; | 
|---|
|  |  |  | //IC卡号格式:4字节HEX码低位在前高位在后。 | 
|---|
|  |  |  | if(ByteUtil.bytesIsAll0xFF(bs, index, 4)){ | 
|---|
|  |  |  | throw new Exception("IC地址数据格式错误,4字节全部为0xFF,舍弃数据") ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | cdData.icCardAddr = ByteUtil.bytes2Hex_LE(bs, false,  index, 4) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 4 ; | 
|---|
|  |  |  | //用水户余额:用户余额4字节BCD码,取值范围0.00~999999.99,单位为元。 | 
|---|
|  |  |  | tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; | 
|---|
|  |  |  | cdData.remainMoney = tpInt/100.0 ; | 
|---|
|  |  |  | tpLong = ByteUtil.BCD2Long_LE(bs, index, index + 3) ; | 
|---|
|  |  |  | cdData.remainMoney = tpLong/100.0 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 4 ; | 
|---|
|  |  |  | //用水户用水开始时间:6字节BCD码,顺序是年月日时分秒,其中公元年=2000+年。 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 6 ; | 
|---|
|  |  |  | //用水户本次用水量:累计流量5字节BCD码,取值范围0~9999999999,单位为m3。 | 
|---|
|  |  |  | tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 4) ; | 
|---|
|  |  |  | cdData.thisAmount = tpInt/100.0 ; | 
|---|
|  |  |  | tpLong = ByteUtil.BCD2Long_LE(bs, index, index + 4) ; | 
|---|
|  |  |  | cdData.thisAmount = tpLong/100.0 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 5 ; | 
|---|
|  |  |  | //用水户本次消费金额:用户余额4字节BCD码,取值范围0.00~999999.99,单位为元。 | 
|---|
|  |  |  | tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 3) ; | 
|---|
|  |  |  | cdData.thisMoney = tpInt/100.0 ; | 
|---|
|  |  |  | tpLong = ByteUtil.BCD2Long_LE(bs, index, index + 3) ; | 
|---|
|  |  |  | cdData.thisMoney = tpLong/100.0 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 4 ; | 
|---|
|  |  |  | //用水户本次用水时长:用水时长2字节BCD码,取值范围0~9999,单位为分钟。 | 
|---|
|  |  |  | tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 1) ; | 
|---|
|  |  |  | int tpInt = ByteUtil.BCD2Int_LE(bs, index, index + 1) ; | 
|---|
|  |  |  | cdData.thisTime = tpInt; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | index += 2 ; | 
|---|
|  |  |  | 
|---|
|  |  |  | Cd_83_Up obj = new Cd_83_Up() ; | 
|---|
|  |  |  | //下面两条上报数据,IC卡编码都是非BCD编码而异常 | 
|---|
|  |  |  | //String hex = "683C68B08485353448830200000000001000282353FE739444000001000313000101211615000101210000000000000000000200019000011518000101210A7B16"; | 
|---|
|  |  |  | String hex = "683C68B05301154CEA8306001000000004343638483BBBB9E0001000001603000101215907000101210000000000000000000500019000015308000101210AF716"; | 
|---|
|  |  |  | //String hex = "683C68B05301154CEA8306001000000004343638483BBBB9E0001000001603000101215907000101210000000000000000000500019000015308000101210AF716"; | 
|---|
|  |  |  | String hex = "683868B0532328B90083074065840000FE00061010282353535B7F7691590100404022231024737F3F3F1FFF957296944239050000390001900000F916"; | 
|---|
|  |  |  | byte[] bs = ByteUtil.hex2Bytes(hex) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Data data = new Data() ; | 
|---|
|  |  |  | data.setSubData(new DataV1()) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int bsLen = new CommonV1().parseDataLen(bs) ; | 
|---|
|  |  |  | int bsLen = new CommonV1().parseDataLen4P206(bs) ; | 
|---|
|  |  |  | if(bsLen > 0){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | obj.doParse(bs, | 
|---|