| package com.dy.pipirrComCreator.p206V1; | 
|   | 
| import com.dy.common.mw.protocol.p206V1.ProtocolConstantV206V1; | 
| import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; | 
| import com.dy.common.util.ByteUtil; | 
|   | 
| /** | 
|  * @Author: liurunyu | 
|  * @Date: 2025/5/7 8:43 | 
|  * @Description | 
|  */ | 
| public abstract class P206V1Cd { | 
|   | 
|     protected static final byte CTRL = (byte)0xB0 ;//控制域 | 
|   | 
|     /** | 
|      * 检查命令参数 | 
|      * @return 信息 | 
|      */ | 
|     public abstract String checkParams(String ...params) ; | 
|     /** | 
|      * 命令帮助信息 | 
|      * @return 信息 | 
|      */ | 
|     public abstract String helpInfo() ; | 
|     /** | 
|      * 构造命令数据(十六进制) | 
|      * @return 字符串 | 
|      * @throws Exception 异常 | 
|      */ | 
|     public abstract String hex(String rtuAddr, String ...params) throws Exception ; | 
|     /** | 
|      * 构造命令数据(字节数组) | 
|      * @return 字节数组 | 
|      * @throws Exception 异常 | 
|      */ | 
|     public abstract byte[] bs(String rtuAddr, String ...params) throws Exception ; | 
|   | 
|     public byte[] createHead(String rtuAddr, String code, byte ctrl)throws Exception { | 
|         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] = ctrl; //控制域功能码 | 
|   | 
|         index++ ; | 
|         GlCreate.createRtuAddr4P206(rtuAddr, bsHead, index); | 
|         index += 5 ; | 
|   | 
|         ByteUtil.hex2Bytes(code, bsHead, index) ; | 
|   | 
|         return bsHead ; | 
|     } | 
|   | 
|     public byte[] createHead4Upgrade(String rtuAddr, String preCode, String sufCode)throws Exception { | 
|         byte[] bsHead = new byte[12] ; | 
|         byte index = 0 ; | 
|         bsHead[index] = ProtocolConstantV206V1.UG_P_Head_Byte ; | 
|   | 
|         index++ ; | 
|         bsHead[index] = 0 ;//帧长度 | 
|         index++ ; | 
|         bsHead[index] = 0 ;//帧长度 | 
|   | 
|         index++ ; | 
|         bsHead[index] = ProtocolConstantV206V1.UG_P_Head_Byte ; | 
|   | 
|         index++ ; | 
|         bsHead[index] = ByteUtil.hex2Bytes(preCode)[0]; //功能码域 | 
|   | 
|         index++ ; | 
|         bsHead[index] = ByteUtil.hex2Bytes(sufCode)[0]; //功能码域 | 
|   | 
|         index++ ; | 
|         GlCreate.createRtuAddr4P206(rtuAddr, bsHead, index); | 
|   | 
|         return bsHead ; | 
|     } | 
| } |