| | |
| | | |
| | | import com.dy.common.mw.protocol.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.*; |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.common.util.ByteUtilUnsigned; |
| | | import com.dy.common.util.CRC8_for_2_0; |
| | | import com.dy.common.util.DateTime; |
| | | |
| | | @AnnotationCodeDown(ifAny={ |
| | | CodeV1_0_1.cd_06 |
| | | }) |
| | | public class Cd_02_Down implements CodeParse { |
| | | |
| | | //private static Logger log = LogManager.getLogger(Cd_XY_Down.class); |
| | | //private static Logger log = LogManager.getLogger(Cd_02_Down.class); |
| | | |
| | | @Override |
| | | public MidResult[] parse(Boolean isLowPower, CodeParseParams params, CodeParseCallback callback) throws Exception { |
| | |
| | | |
| | | MidResultToRtu midRs = new MidResultToRtu() ; |
| | | midRs.protocolName = para.protocolName ;//协议名称 |
| | | midRs.rtuAddr = para.rtuAddr ;//IMEI号(电信平台设备IMEI) |
| | | midRs.rtuAddr = para.rtuAddr ;//Rtu地址(电信平台设备IMEI) |
| | | midRs.commandId = para.commandId ;//命令ID,发起命令的客户端(web端)生成,以匹配命令结果 |
| | | midRs.downCode = para.commandCode ;//下行命令功能码; |
| | | midRs.downBuffer = bs ;//下行命令数据 |
| | |
| | | } |
| | | /** |
| | | * 构造下行数据 |
| | | * @param para |
| | | * @return |
| | | * @throws Exception |
| | | * @param para 参数 |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public byte[] doParse(ParseParamsForDownV1_0_1 para) throws Exception { |
| | | CommonV1_0_1 commonV1_0_1 = new CommonV1_0_1() ; |
| | |
| | | index++ ; |
| | | bsHead[index] = commonV1_0_1.createCtrl((byte)0) ; |
| | | |
| | | String rtuAddr = para.rtuAddr ; |
| | | String rtuAddr1 = rtuAddr.substring(0, 6) ; |
| | | String rtuAddr2 = rtuAddr.substring(6) ; |
| | | |
| | | index++ ; |
| | | ByteUtil.string2BCD_BE(bsHead, rtuAddr1, index) ; |
| | | index += 3 ; |
| | | |
| | | Integer rtuAddr2Int = Integer.parseInt(rtuAddr2) ; |
| | | ByteUtilUnsigned.short2Bytes_BE(bsHead, rtuAddr2Int.shortValue(), index); |
| | | index += 2 ; |
| | | GlCreate.createRtuAddr(para.rtuAddr, bsHead, index); |
| | | index += 5 ; |
| | | |
| | | ByteUtil.hex2Bytes(para.commandCode, bsHead, index) ; |
| | | |
| | | byte[] bs = new byte[7] ; |
| | | bs[0] = (byte)0xF2 ; |
| | | ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), 1) ; |
| | | bs[0] = (byte)0xF2 ;//数据域: 1 个字节,F0 登录, F1 退出登录,F2 在线保持。 |
| | | GlCreate.createTp(bs, 1); |
| | | |
| | | bytes = ByteUtil.bytesMerge(bsHead, bs) ; |
| | | |
| | | int len = bytes.length + ProtocolConstantV206V1_0_0.lenTail; |
| | | bytes[ProtocolConstantV206V1_0_0.dataLenIndex] = (byte)len ; |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | int crc = new CRC8_for_2_0().CRC8(bytes, ProtocolConstantV206V1_0_0.ctrlIndex, bytes.length -1) ; |
| | | bs = new byte[ProtocolConstantV206V1_0_0.lenTail] ; |
| | | bs[0] = (byte)crc ; |
| | | bs[1] = ProtocolConstantV206V1_0_0.P_Tail_Byte ; |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | bytes = GlCreate.createCrcTail(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | return bytes ; |
| | | } |