| | |
| | | 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.ComCd16Vo; |
| | | import com.dy.common.mw.protocol.p206V202404.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.common.util.NumUtil; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV202404.cd_16 |
| | |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ; |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址 |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | | midRs.downCode = para.commandCode ;//下行命令功能码; |
| | |
| | | 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(); |
| | | ComCd16Vo cvo = JSON.parseObject(json, ComCd16Vo.class) ; |
| | | if(cvo == null){ |
| | | throw new Exception("json转ComCd16Vo为null") ; |
| | | } |
| | | if(cvo.moneyAlarm < 0 || cvo.moneyAlarm > 65535){ |
| | | throw new Exception("剩余金额报警值必须是0~65535范围内的整数") ; |
| | | if(cvo.moneyAlarm < 0 || cvo.moneyAlarm > 9999){ |
| | | throw new Exception("剩余金额报警值必须是0~9999范围内的整数") ; |
| | | } |
| | | if(cvo.waterAlarm < 0 || cvo.waterAlarm > 65535){ |
| | | throw new Exception("剩余水量报警值必须是0~65535范围内的整数") ; |
| | | if(cvo.waterAlarm < 0 || cvo.waterAlarm > 9999){ |
| | | throw new Exception("剩余水量报警值必须是0~9999范围内的整数") ; |
| | | } |
| | | |
| | | |
| | | byte[] bs = new byte[13] ; |
| | | int index = 0 ; |
| | |
| | | index ++ ; |
| | | bs[index] = cvo.projectNo.byteValue() ; |
| | | |
| | | index ++ ; |
| | | ByteUtilUnsigned.short2Bytes_BE(bs, cvo.waterAlarm, index); |
| | | |
| | | index ++ ; |
| | | ByteUtilUnsigned.short2Bytes_BE(bs, cvo.moneyAlarm, index); |
| | | String strTemp = "" + cvo.waterAlarm ; |
| | | byte[] bTemp = ByteUtil.string2BCD_LE(strTemp) ; |
| | | int bTempLen = bTemp.length ; |
| | | int 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 ; |
| | | } |
| | | |
| | | index ++ ; |
| | | strTemp = "" + cvo.moneyAlarm ; |
| | | bTemp = ByteUtil.string2BCD_LE(strTemp) ; |
| | | 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 ; |
| | | } |
| | | |
| | | GlCreate.createPw(bs, index); |
| | | |
| | | index ++ ; |
| | | index += 2 ; |
| | | GlCreate.createS2D(bs, index) ; |
| | | |
| | | index += 4 ; |