|  |  |  | 
|---|
|  |  |  | package com.dy.common.mw.protocol.p206V1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.*; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V1.parse.TransparentDown; | 
|---|
|  |  |  | import com.dy.common.util.DateTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @AnnotationDriver(enable = true, | 
|---|
|  |  |  | 
|---|
|  |  |  | this.clear(); | 
|---|
|  |  |  | boolean isFail = false ; | 
|---|
|  |  |  | String upCode = null ; | 
|---|
|  |  |  | Object[] codeDataGrp = {null}; | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | CommonV1 cp = new CommonV1() ; | 
|---|
|  |  |  | Boolean p206TrueUgFalse = cp.protocolType_p206TrueUgFalse(upBuffer) ; | 
|---|
|  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return codeParse.parse(isLowPower, this.upCpParams, new CodeParseCallback(){ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void callback(Boolean flag) { | 
|---|
|  |  |  | public void callback(Boolean flag, Object codeData) { | 
|---|
|  |  |  | reportOrResponse_trueOrFalse = flag ; | 
|---|
|  |  |  | rtuAddrInData = dV1.getRtuAddr() ; | 
|---|
|  |  |  | codeDataGrp[0] = codeData ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void notify(NotifyInfo ...infos) { | 
|---|
|  |  |  | notify.notify(rtuAddr, ProtocolConstantV206V1.protocolName, ProtocolConstantV206V1.protocolVer, infos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | isFail = true ; | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1.protocolName, rtuAddr, "严重错误,分析Rtu数据出错!数据为:" + upHex + (e.getMessage() == null?"":(",出错信息:" + e.getMessage())), e))} ; | 
|---|
|  |  |  | } finally{ | 
|---|
|  |  |  | if(upCode != null){ | 
|---|
|  |  |  | //CRC验证失败时,upCode为null,此时不进行回调 | 
|---|
|  |  |  | callback.callback(rtuAddr, upCode, CodeV1.getCodeName(upCode), upHex, reportOrResponse_trueOrFalse, isFail, rtuAddr); | 
|---|
|  |  |  | callback.callback(rtuAddr, upCode, CodeV1.getCodeName(upCode), upHex, reportOrResponse_trueOrFalse, isFail, rtuAddr, codeDataGrp[0]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 构造下行透传数据(命令) | 
|---|
|  |  |  | * @param isLowPower 是否在低功耗环境下运行 | 
|---|
|  |  |  | * @param command 命令 | 
|---|
|  |  |  | * @return MidResult[] | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public MidResult[] transparentCommand(Boolean isLowPower, Command command, Object... params){ | 
|---|
|  |  |  | this.clear(); | 
|---|
|  |  |  | String RtuResultSendWebUrl = command.getRtuResultSendWebUrl() ; | 
|---|
|  |  |  | if(RtuResultSendWebUrl == null || RtuResultSendWebUrl.trim().equals("")){ | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1.protocolName, null, "严重错误,命令中rtu返回命令结果发向目的地web URL为空,不能构建任何命令!", null))} ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String rtuAddr = command.getRtuAddr() ; | 
|---|
|  |  |  | if(rtuAddr == null || rtuAddr.trim().equals("")){ | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1.protocolName, null, "严重错误,命令中Rtu地址为空,不能构建任何命令!", null))} ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String commandCode = command.getCode() ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.downCpParams.setValue( | 
|---|
|  |  |  | RtuResultSendWebUrl, | 
|---|
|  |  |  | ProtocolConstantV206V1.protocolName, | 
|---|
|  |  |  | command.protocolVersion==null?ProtocolConstantV206V1.protocolVer:command.protocolVersion, | 
|---|
|  |  |  | rtuAddr, | 
|---|
|  |  |  | command.getId(), | 
|---|
|  |  |  | commandCode, | 
|---|
|  |  |  | command.getParam(), | 
|---|
|  |  |  | command.getAttachment()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(commandCode == null){ | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1.protocolName, rtuAddr,  "严重错误,命令中功能码为空,不能构建任何命令!", null))} ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | return new TransparentDown().parse(isLowPower, this.downCpParams, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return new MidResult[]{(new MidResultError(ProtocolConstantV206V1.protocolName, rtuAddr,  "严重错误,构造下行数据出错!命令为:" + command.toString(), e))} ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|