|  |  | 
 |  |  | package com.dy.common.mw.protocol.p206V202404.parse; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson2.JSON; | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  | import com.dy.common.mw.protocol.*; | 
 |  |  | import com.dy.common.mw.protocol.p206V202404.CodeV202404; | 
 |  |  | import com.dy.common.mw.protocol.p206V202404.ParseParamsForDownV202404; | 
 |  |  | import com.dy.common.mw.protocol.p206V202404.downVos.ComCd10Vo; | 
 |  |  | import com.dy.common.mw.protocol.p206V202404.downVos.ComCd15Vo; | 
 |  |  | import com.dy.common.mw.protocol.p206V202404.parse.global.GlCreate; | 
 |  |  | import com.dy.common.util.ByteUtil; | 
 |  |  | 
 |  |  |  | 
 |  |  |         MidResultToRtu midRs = new MidResultToRtu() ; | 
 |  |  |         midRs.protocolName = para.protocolName ;//协议名称 | 
 |  |  |         midRs.protocolVersion = para.protocolVersion ;//协议版本号 | 
 |  |  |         midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ; | 
 |  |  |         midRs.rtuAddr = para.rtuAddr ;//Rtu地址 | 
 |  |  |         midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 | 
 |  |  |         midRs.downCode = para.commandCode ;//下行命令功能码; | 
 |  |  |         midRs.downCodeName = CodeV202404.getCodeName(para.commandCode) ;//下行命令功能码名称; | 
 |  |  |         midRs.downBuffer = bs ;//下行命令数据 | 
 |  |  |         midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//下行命令数据十六进制形式 | 
 |  |  |         midRs.hasResponse = true ;//是否有应答 | 
 |  |  | 
 |  |  |     public byte[] doParse(ParseParamsForDownV202404 para) throws Exception { | 
 |  |  |         byte[] bytes = GlCreate.createStart2Cd(para.rtuAddr, para.commandCode); | 
 |  |  |         if(para.param != null){ | 
 |  |  |             String json = (String)para.param; | 
 |  |  |             JSONObject obj = (JSONObject)para.param; | 
 |  |  |             String json = obj.toJSONString(); | 
 |  |  |             ComCd15Vo cvo = JSON.parseObject(json, ComCd15Vo.class) ; | 
 |  |  |             if(cvo == null){ | 
 |  |  |                 throw new Exception("json转ComCd15Vo为null") ; | 
 |  |  | 
 |  |  |             if(cvo.flowNo.length() != 12){ | 
 |  |  |                 throw new Exception("流水号必须是12位数字") ; | 
 |  |  |             } | 
 |  |  |             byte[] bs = new byte[17] ; | 
 |  |  |             byte[] bs = new byte[43] ; | 
 |  |  |             int index = 0 ; | 
 |  |  |             bs[index] = (byte)(Integer.parseInt(cvo.controllerType, 16)); | 
 |  |  |  | 
 |  |  | 
 |  |  |                     bs[index++] = 0 ; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             if(cvo.chargeMoney != null){ | 
 |  |  |                 String chargeMoney = "" + (Double.valueOf(cvo.chargeWater * 100)).longValue() ; | 
 |  |  |                 byte[] bTemp = ByteUtil.string2BCD_LE(chargeMoney) ; | 
 |  |  |             if(cvo.chargeWater != null){ | 
 |  |  |                 String chargeWater = "" + (Double.valueOf(cvo.chargeWater * 100)).longValue() ; | 
 |  |  |                 byte[] bTemp = ByteUtil.string2BCD_LE(chargeWater) ; | 
 |  |  |                 int bTempLen = bTemp.length ; | 
 |  |  |                 int count = 0 ; | 
 |  |  |                 for(int i = 0 ; i < bTempLen; i++){ | 
 |  |  | 
 |  |  |             ByteUtil.string2BCD_BE(bs, cvo.flowNo, index) ; | 
 |  |  |  | 
 |  |  |             index += 6 ; | 
 |  |  |             GlCreate.createDt(bs, index); | 
 |  |  |  | 
 |  |  |             index += 6 ; | 
 |  |  |             GlCreate.createPw(bs, index); | 
 |  |  |  | 
 |  |  |             index += 2 ; |