| | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ProtocolConstantV206V1_0_0; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.downVos.Com97Vo; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.mw.protocol.p206V202404.downVos.ComCd87Vo; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | |
| | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | | ParseParamsForDownV1_0_1 para = (ParseParamsForDownV1_0_1) params ; |
| | | byte[] bs = this.doParse(para) ; |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | byte[] bs = this.doParse(midRs, para) ; |
| | | |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;//rtu返回命令结果 发向目的地web URL |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址 |
| | |
| | | |
| | | /** |
| | | * 构造下行数据 |
| | | * @param midRs 参数 |
| | | * @param para 参数 |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | public byte[] doParse(MidResultToRtu midRs, ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | | byte[] bytes ; |
| | | byte[] bsHead = new byte[ProtocolConstantV206V1_0_0.lenHead2Code] ; |
| | |
| | | if(cvo.icCardNo == null){ |
| | | throw new Exception("虚拟IC卡编号不能为空") ; |
| | | } |
| | | if(cvo.money == null){ |
| | | if(cvo.moneyRemain == null){ |
| | | throw new Exception("剩余金额不能为空") ; |
| | | } |
| | | if(cvo.price == null){ |
| | | if(cvo.waterPrice == null){ |
| | | throw new Exception("水价不能为空") ; |
| | | } |
| | | String icCardNo = null ; |
| | | if(cvo.icCardNo.length() > 10){ |
| | | icCardNo = cvo.icCardNo.substring(cvo.icCardNo.length() - 10) ; |
| | | |
| | | String[] icCardNoGrp = CommonV1_0_1.dealIcCardNo(cvo.icCardNo) ; |
| | | if(icCardNoGrp[0] != null){ |
| | | midRs.param = icCardNoGrp[0] ; |
| | | } |
| | | |
| | | byte[] bs = new byte[11] ; |
| | | ByteUtil.string2BCD_LE(bs, icCardNo, 0) ; |
| | | index = 0 ; |
| | | ByteUtil.string2BCD_LE(bs, icCardNoGrp[1], index) ; |
| | | |
| | | Integer money = Double.valueOf(cvo.money * 100.0D).intValue() ; |
| | | ByteUtilUnsigned.int2Bytes_LE(bs, money, 4); |
| | | index += 5 ; |
| | | Integer money = Double.valueOf(cvo.moneyRemain * 100.0D).intValue() ; |
| | | byte[] bTemp = ByteUtil.int2BCD_LE(money) ; |
| | | int bTempLen = bTemp.length ; |
| | | int count = 0 ; |
| | | for(int i = 0 ; i < bTempLen; i++){ |
| | | bs[index++] = bTemp[i] ; |
| | | count ++ ; |
| | | if(count >= 4){ |
| | | break ; |
| | | } |
| | | } |
| | | for(; count < 4; count++){ |
| | | bs[index++] = 0 ; |
| | | } |
| | | |
| | | Short price = Double.valueOf(cvo.price * 100.0D).shortValue() ; |
| | | ByteUtilUnsigned.short2Bytes_LE(bs, price, 8); |
| | | Integer price = Double.valueOf(cvo.waterPrice * 100.0D).intValue() ; |
| | | bTemp = ByteUtil.int2BCD_LE(price) ; |
| | | bTempLen = bTemp.length ; |
| | | count = 0 ; |
| | | for(int i = 0 ; i < bTempLen; i++){ |
| | | bs[index++] = bTemp[i] ; |
| | | count ++ ; |
| | | if(count >= 2){ |
| | | break ; |
| | | } |
| | | } |
| | | for(; count < 2; count++){ |
| | | bs[index++] = 0 ; |
| | | } |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |