| | |
| | | package com.dy.common.mw.protocol.p206V1_0_0.parse; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.CommonV1_0_1; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.ParseParamsForDownV1_0_1; |
| | | 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.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | |
| | | /** |
| | | * @Author liurunyu |
| | |
| | | @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] ; |
| | |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | /* |
| | | 参数格式: 虚拟卡号,电子钱包余额,水价 |
| | | */ |
| | | String param = (String)para.param ; |
| | | if(param == null || param.trim().equals("")){ |
| | | throw new Exception("未提供命令参数数据,不能构造功能码为" + para.commandCode + "的下行命令") ; |
| | | }else{ |
| | | String[] params = ((String)para.param).split(",") ; |
| | | if(params == null || params.length != 3){ |
| | | throw new Exception("命令参数数据不正确,不能构造功能码为" + para.commandCode + "的下行命令") ; |
| | | }else{ |
| | | byte index1 = 0 ; |
| | | byte[] bs = new byte[11] ; |
| | | ByteUtil.string2BCD_LE(bs, params[0], 0) ; |
| | | JSONObject obj = (JSONObject)para.param; |
| | | String json = obj.toJSONString(); |
| | | Com97Vo cvo = JSON.parseObject(json, Com97Vo.class) ; |
| | | if(cvo == null){ |
| | | throw new Exception("json转Com97Vo为null") ; |
| | | } |
| | | if(cvo.icCardNo == null){ |
| | | throw new Exception("虚拟IC卡编号不能为空") ; |
| | | } |
| | | if(cvo.moneyRemain == null){ |
| | | throw new Exception("剩余金额不能为空") ; |
| | | } |
| | | if(cvo.waterPrice == null){ |
| | | throw new Exception("水价不能为空") ; |
| | | } |
| | | |
| | | Integer money = (Double.valueOf(Double.parseDouble(params[1]) * 100)).intValue() ; |
| | | ByteUtilUnsigned.int2Bytes_LE(bs, money, 4); |
| | | //String[] icCardNoGrp = CommonV1_0_1.dealIcCardNo(cvo.icCardNo) ; |
| | | //if(icCardNoGrp[0] != null){ |
| | | // midRs.param = icCardNoGrp[0] ; |
| | | //} |
| | | |
| | | Short price = (Double.valueOf(Double.parseDouble(params[2]) * 100)).shortValue() ; |
| | | ByteUtilUnsigned.short2Bytes_LE(bs, price, 8); |
| | | byte[] bs = new byte[14] ; |
| | | index = 0 ; |
| | | GlCreate.createIcCardNo(cvo.icCardNo, bs, index); |
| | | //ByteUtil.string2BCD_LE(bs, icCardNoGrp[1], index) ; |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | index += 8 ; |
| | | 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 ; |
| | | } |
| | | |
| | | 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) ; |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |