pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeRtuDev.java
@@ -31,7 +31,6 @@
    public UpgradeRtuDev(UpgradeTaskVo taskVo, Integer failTryTimes , String rtuAddr, int totalPackage) {
        super();
        //this.task = task ;
        this.taskVo = taskVo ;
        this.failTryTimes = failTryTimes ;
        this.rtuAddr = rtuAddr ;
@@ -40,13 +39,13 @@
        this.currentPackage = 0 ;
        this.currentRamAddr = 0 ;
        this.lastDownDt = "" ;
        this.lastDownDtAt = 0L ;
        this.reTryTimes = 0 ;
        this.isOver = false ;
    }
    public UpgradeRtuDev(UpgradeTaskVo taskVo, Integer failTryTimes, String rtuAddr, int totalPackage, int state) {
        super();
        //this.task = task ;
        this.taskVo = taskVo ;
        this.failTryTimes = failTryTimes ;
        this.rtuAddr = rtuAddr ;
@@ -55,6 +54,7 @@
        this.currentPackage = 0 ;
        this.currentRamAddr = 0 ;
        this.lastDownDt = "" ;
        this.lastDownDtAt = 0L ;
        this.reTryTimes = 0 ;
        this.isOver = false ;
    }
@@ -67,74 +67,96 @@
     */
    @Override
    public void trigger(String code, String protocolName, Short protocolVersion, byte[][] softData, Callback callbackCom){
        if(this.state == STATE_OFFLINE || this.state == STATE_UNSTART){
            //当前未开始升级过程,下发升级配置指令
            this.setStateAtCom1601Time();
            callbackCom.call(createCommand1601(protocolName, protocolVersion));
        }else if(this.state == STATE_RUNNING){
            //当前升级过程中
            if(code.equals(UpgradeCode.cd_9601)){
                //下发配置返回
                this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
                callbackCom.call(createCommand1602(protocolName, protocolVersion, currentPackage, currentRamAddr, softData));//下发数据包指令
            }else if(code.equals(UpgradeCode.cd_9602)){
                //下发数据包返回
                currentPackage++ ;
                currentRamAddr += RAMADDRADD ;
                if(currentPackage < totalPackage){
        if(!this.isOver){
            //升级未完成
            if(this.state == STATE_OFFLINE || this.state == STATE_UNSTART){
                //当前未开始升级过程,下发升级配置指令
                this.setStateAtSendCom1601Time();
                callbackCom.call(createCommand1601(protocolName, protocolVersion));
            }else if(this.state == STATE_RUNNING){
                //当前升级过程中
                if(code.equals(UpgradeCode.cd_9601)){
                    //下发配置返回
                    this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
                    callbackCom.call(createCommand1602(protocolName, protocolVersion, currentPackage, currentRamAddr, softData));
                }else{
                    this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
                    callbackCom.call(createCommand1603(protocolName, protocolVersion));//下发校验指令
                }
            }else if(code.equals(UpgradeCode.cd_9603)){
                //下发校验返回
                this.isOver = true ;//升级完成
                this.state = STATE_SUCCESS ;
                this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
                callbackCom.call(createCommand1600(protocolName, protocolVersion));//下发复位指令,此指令无应答
            }else{
                if(!this.isOver){
                    //升级未完成
                    if(this.state == STATE_FAILONE || this.state == STATE_FAIL){
                        //已经是升级失败态
                        if(this.reTryTimes < this.failTryTimes){
                            //重试次数未达到上限,继续重试
                            this.reTryTimes += 1 ;
                            this.setStateAtCom1601Time();
                            callbackCom.call(createCommand1601(protocolName, protocolVersion));//下发配置指令
                        }else{
                            this.isOver = true ;//升级完成
                        }
                    this.lastDownDtAt = System.currentTimeMillis() ;
                    callbackCom.call(createCommand1602(protocolName, protocolVersion, currentPackage, currentRamAddr, softData));//下发数据包指令
                }else if(code.equals(UpgradeCode.cd_9602)){
                    //下发数据包返回
                    currentPackage++ ;
                    currentRamAddr += RAMADDRADD ;
                    if(currentPackage < totalPackage){
                        this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
                        this.lastDownDtAt = System.currentTimeMillis() ;
                        callbackCom.call(createCommand1602(protocolName, protocolVersion, currentPackage, currentRamAddr, softData));
                    }else{
                        //非升级功能码,如果在升级过程中收到这个功能码的上行数据,说明升级失败了
                        if(currentPackage == 0 || currentPackage == 1){
                            //1包死,升级失败
                            this.state = STATE_FAILONE ;
                        }else{
                            //非1包死,升级失败
                            this.state = STATE_FAIL ;
                        }
                        this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
                        this.lastDownDtAt = System.currentTimeMillis() ;
                        callbackCom.call(createCommand1603(protocolName, protocolVersion));//下发校验指令
                    }
                }else if(code.equals(UpgradeCode.cd_9603)){
                    //下发校验返回
                    this.setStateAtReceiveRes9603Time() ;
                    callbackCom.call(createCommand1600(protocolName, protocolVersion));//下发复位指令,此指令无应答
                }else{
                    //升级完成,无业务逻辑
                    //当前是升级中状态,并且升级未完成,收到了非960X系列功能码,则升级失败
                    if(currentPackage == 0 || currentPackage == 1){
                        //1包死,升级失败
                        this.state = STATE_FAILONE ;
                    }else{
                        //非1包死,升级失败
                        this.state = STATE_FAIL ;
                    }
                }
            }else if(this.state == STATE_FAILONE || this.state == STATE_FAIL){
                //上次设置了失败状态,并且升级未完成,收到了非960X系列功能码,则升级失败
                if(this.reTryTimes < this.failTryTimes){
                    //重试次数未达到上限,继续重试
                    this.reTryTimes += 1 ;
                    this.setStateAtSendCom1601Time();
                    callbackCom.call(createCommand1601(protocolName, protocolVersion));//下发配置指令
                }else{
                    //升级失败,并且重试次数达到上限,强制设置升级完成
                    this.isOver = true ;
                }
            }else if(this.state == STATE_SUCCESS){
                //升级成功态,不会出现此情况,因为设置为成功态时,升级结束属性isOver设置为true了
                //为安全见,这里再设置为结束态
                this.isOver = true ;
            }else if(this.state == STATE_FAILOFFLINE){
                //已经被其他逻辑模块强制设置成离线失败态了,不会出现此情况,因为设置为离线失败态时,升级结束属性isOver设置为true了
                //这里不再有作为
                //为安全见,这里再设置为结束态
                this.isOver = true ;
            }else{
                //其他状态(没有其他态了,除非再设计开发时增加了状态)
                //为安全见,这里再设置为结束态
                this.isOver = true ;
            }
        }else{
            //在其他状态下,不触发任务工作
            //升级完成,无业务逻辑
        }
    }
    /**
     * 设置发送配置命令时刻的状态
     */
    private void setStateAtCom1601Time(){
        this.state = STATE_RUNNING;
    private void setStateAtSendCom1601Time(){
        this.state = STATE_RUNNING;//升级进行中
        this.currentPackage = 0 ;
        this.currentRamAddr = 0 ;
        this.isOver = false ;
        this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
        this.lastDownDtAt = System.currentTimeMillis() ;
    }
    /**
     * 设置1603指令返回时刻的状态
     */
    private void setStateAtReceiveRes9603Time(){
        this.isOver = true ;//升级完成
        this.state = STATE_SUCCESS ;
        this.lastDownDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
        this.lastDownDtAt = System.currentTimeMillis() ;
    }
    @Override