From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 07 四月 2025 15:18:51 +0800 Subject: [PATCH] 整理版本 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/parse/Cd_A1_Down.java | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 215 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/parse/Cd_A1_Down.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/parse/Cd_A1_Down.java new file mode 100644 index 0000000..ebd7844 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1/parse/Cd_A1_Down.java @@ -0,0 +1,215 @@ +package com.dy.common.mw.protocol.p206V1.parse; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.dy.common.mw.protocol.*; +import com.dy.common.mw.protocol.p206V1.CodeV1; +import com.dy.common.mw.protocol.p206V1.CommonV1; +import com.dy.common.mw.protocol.p206V1.ParseParamsForDownV1; +import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; +import com.dy.common.mw.protocol.p206V1.downVos.ComA1Vo; +import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; +import com.dy.common.util.ByteUtil; + +/** + * @Author liurunyu + * @Date 2024/06/12 9:30 + * @Description + */ +@AnnotationCodeDown(ifAny={ + CodeV1.cd_A1 +}) +public class Cd_A1_Down implements CodeParse { + + @Override + public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { + ParseParamsForDownV1 para = (ParseParamsForDownV1) params ; + MidResultToRtu midRs = new MidResultToRtu() ; + byte[] bs = this.doParse(midRs, para) ; + + midRs.rtuResultSendWebUrl = para.rtuResultSendWebUrl ;//rtu杩斿洖鍛戒护缁撴灉 鍙戝悜鐩殑鍦皐eb URL + midRs.protocolName = para.protocolName ;//鍗忚鍚嶇О + midRs.protocolVersion = para.protocolVersion; //鍗忚鐗堟湰鍙� + midRs.rtuAddr = para.rtuAddr ;//Rtu鍦板潃 + midRs.commandId = para.commandId ;//鍛戒护ID锛屽彂璧峰懡浠ょ殑瀹㈡埛绔�(web绔�)鐢熸垚锛屼互鍖归厤鍛戒护缁撴灉 + midRs.downCode = para.commandCode ;//涓嬭鍛戒护鍔熻兘鐮�; + midRs.downCodeName = CodeV1.getCodeName(para.commandCode) ;//涓嬭鍛戒护鍔熻兘鐮佸悕绉�; + midRs.downBuffer = bs ;//涓嬭鍛戒护鏁版嵁 + midRs.downBufHex = ByteUtil.bytes2Hex(bs, true) ;//涓嬭鍛戒护鏁版嵁鍗佸叚杩涘埗褰㈠紡 + midRs.hasResponse = true ;//鏄惁鏈夊簲绛� + midRs.maxSendTimes = null ;//鍛戒护鏈�澶у彂閫佹鏁�(褰撴敹涓嶅埌搴旂瓟鏃讹紝灏嗛噸鍙�)锛屽鏋滀笉璁剧疆锛屽懡浠ょ紦瀛樺櫒杩涜琛ュ厖璁剧疆 + midRs.isCachForOffLine = false ;//RTU涓嶅湪绾匡紝鍛戒护鏄惁缂撳瓨锛屼綆鍔熻�楁椂涓簍rue + + if(isLowPower != null && isLowPower.booleanValue()){ + //浣庡姛鑰楁椂锛屽敖蹇彂閫� + midRs.isQuickSend = true ; + } + + return new MidResult[]{midRs} ; + } + + /** + * 鏋勯�犱笅琛屾暟鎹� + * @param midRs 鍙傛暟 + * @param para 鍙傛暟 + * @return 瀛楄妭鏁扮粍 + * @throws Exception 寮傚父 + */ + public byte[] doParse(MidResultToRtu midRs, ParseParamsForDownV1 para) throws Exception { + CommonV1 commonV_1 = new CommonV1() ; + byte[] bytes ; + byte[] bsHead = new byte[ProtocolConstantV206V1.lenHead2Code] ; + byte index = 0 ; + bsHead[index] = ProtocolConstantV206V1.P_Head_Byte ; + + index++ ; + bsHead[index] = 0 ;//甯ч暱搴� + + index++ ; + bsHead[index] = ProtocolConstantV206V1.P_Head_Byte ; + + index++ ; + bsHead[index] = commonV_1.createCtrl((byte)0, (byte)0) ; + + index++ ; + GlCreate.createRtuAddr4P206(para.rtuAddr, bsHead, index); + index += 5 ; + + ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; + + JSONObject obj = (JSONObject)para.param; + String json = obj.toJSONString(); + ComA1Vo cvo = JSON.parseObject(json, ComA1Vo.class) ; + if(cvo == null){ + throw new Exception("json杞珻om99Vo涓簄ull") ; + } + if(cvo.icCardNo == null){ + throw new Exception("铏氭嫙IC鍗$紪鍙蜂笉鑳戒负绌�") ; + } + if(cvo.moneyRemain == null || cvo.moneyRemain == 0.0){ + throw new Exception("鍓╀綑閲戦涓嶈兘涓虹┖鎴栦负0") ; + } + if(cvo.waterPrice == null || cvo.waterPrice == 0.0){ + throw new Exception("姘翠环涓嶈兘涓虹┖鎴栦负0") ; + } + if(cvo.minutes == null || cvo.minutes == 0.0){ + throw new Exception("鐢ㄦ按鏃堕暱涓嶈兘涓虹┖鎴栦负0") ; + } + if(cvo.minutes < 0 || cvo.minutes > 9999){ + throw new Exception("鐢ㄦ按鏃堕暱鍙栧�艰寖鍥存槸0~9999鍒嗛挓") ; + } + if(cvo.year == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---骞翠笉鑳戒负绌�") ; + } + if(cvo.year < 24 || cvo.year > 9999){ + throw new Exception("璁″垝寮�闃�鏃堕棿---骞翠笉姝g‘") ; + } + if(cvo.year > 99 && cvo.year < 2024){ + throw new Exception("璁″垝寮�闃�鏃堕棿---骞翠笉姝g‘") ; + } + if(cvo.month == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏈堜笉鑳戒负绌�") ; + } + if(cvo.month < 1 || cvo.month > 12){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏈堜笉姝g‘") ; + } + if(cvo.day == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃ヤ笉鑳戒负绌�") ; + } + if(cvo.day < 1 || cvo.day > 31){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃ヤ笉姝g‘") ; + } + if(cvo.hour == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃朵笉鑳戒负绌�") ; + } + if(cvo.hour < 0 || cvo.hour > 23){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃朵笉姝g‘") ; + } + if(cvo.minute == null){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鏃朵笉鑳戒负绌�") ; + } + if(cvo.minute < 0 || cvo.minute > 59){ + throw new Exception("璁″垝寮�闃�鏃堕棿---鍒嗕笉姝g‘") ; + } + + byte[] bs = new byte[8] ; + GlCreate.createIcCardNo(cvo.icCardNo, bs, 0); + bytes = ByteUtil.bytesMerge(bsHead, bs) ; + + bs = new byte[4] ; + index = 0 ; + 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 ; + } + bytes = ByteUtil.bytesMerge(bytes, bs) ; + + bs = new byte[2] ; + 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(bytes, bs) ; + + + bs = new byte[2] ; + index = 0 ; + bTemp = ByteUtil.int2BCD_LE(cvo.minutes) ; + 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(bytes, bs) ; + + bs = new byte[5] ; + if(cvo.year >= 2024){ + cvo.year = cvo.year - 2000 ; + } + bs[0] = ByteUtil.int2BCD_LE(cvo.minute)[0] ; + bs[1] = ByteUtil.int2BCD_LE(cvo.hour)[0] ; + bs[2] = ByteUtil.int2BCD_LE(cvo.day)[0] ; + bs[3] = ByteUtil.int2BCD_LE(cvo.month)[0] ; + bs[4] = ByteUtil.int2BCD_LE(cvo.year)[0] ; + + bytes = ByteUtil.bytesMerge(bytes, bs) ; + + GlCreate.createLen(bytes);//闀垮害鏀惧瓧鑺傛暟缁勪腑 + + byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC鍜屽熬鍙犲姞瀛楄妭鏁扮粍涓� + + bytes = ByteUtil.bytesMerge(bytes, bsTail) ; + + return bytes ; + } + +} + -- Gitblit v1.8.0