New file |
| | |
| | | package com.dy.rtuMw.server.upgrade; |
| | | |
| | | import com.dy.common.mw.UnitAdapterInterface; |
| | | import com.dy.common.mw.UnitCallbackInterface; |
| | | import com.dy.common.mw.UnitInterface; |
| | | import com.dy.common.softUpgrade.state.UpgradeTaskVo; |
| | | import com.dy.common.util.Callback; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/11/4 14:16 |
| | | * @Description |
| | | */ |
| | | public class UpgradeUnit implements UnitInterface { |
| | | |
| | | private static UpgradeUnit instance = new UpgradeUnit() ; |
| | | |
| | | public static UpgradeUnitAdapter adapter ; |
| | | public static UpgradeUnitConfigVo confVo ; |
| | | |
| | | private static UpgradeManager manager ; |
| | | |
| | | private UpgradeUnit(){} ; |
| | | |
| | | public static UpgradeUnit getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | | @Override |
| | | public void setAdapter(UnitAdapterInterface adapter) throws Exception { |
| | | if(adapter == null){ |
| | | throw new Exception("RTU远程升级模块适配器对象不能为空!") ; |
| | | } |
| | | UpgradeUnit.adapter = (UpgradeUnitAdapter)adapter ; |
| | | UpgradeUnit.confVo = UpgradeUnit.adapter.getConfig() ; |
| | | if(UpgradeUnit.confVo == null){ |
| | | throw new Exception("RTU远程升级模块配置对象不能为空!") ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化 |
| | | */ |
| | | @Override |
| | | public void start(UnitCallbackInterface callback) throws Exception { |
| | | if(confVo.enable){ |
| | | manager = UpgradeManager.getInstance() ; |
| | | manager.initOption(confVo); |
| | | callback.call(null) ; |
| | | System.out.println("RTU远程升级模块成功启动"); |
| | | }else{ |
| | | System.out.println("RTU远程升级模块配置不启动"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void stop(UnitCallbackInterface callback) throws Exception { |
| | | forceOverUpgradeTask() ; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 设置升级任务 |
| | | * @param vo UpgradeTaskVo 升级任务对象 |
| | | * @throws Exception |
| | | */ |
| | | public void setUpgradeTask(UpgradeTaskVo vo) throws Exception { |
| | | if(manager != null ){ |
| | | manager.setUpgradeTask(vo) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 结束当前升级任务 |
| | | * @throws Exception |
| | | * @return null:结束任务成功,否则返回失败原因 |
| | | */ |
| | | public String forceOverUpgradeTask() throws Exception { |
| | | if(manager != null ){ |
| | | return manager.forceOverUpgradeTask() ; |
| | | }else{ |
| | | return "通信中间件内部错误" ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * RTU有上行数据了,触发下发升级数据 |
| | | * @param rtuAddr |
| | | * @param code |
| | | * @param callback |
| | | */ |
| | | public void trigger(String rtuAddr, String code, String protocolName, Short protocolVersion, Callback callback, Object ...objects){ |
| | | if(manager != null ){ |
| | | manager.trigger(rtuAddr, code, protocolName, protocolVersion, callback, objects); |
| | | } |
| | | } |
| | | |
| | | //////////////////////////////////////////////////// |
| | | // |
| | | // 查询升级状态信息 |
| | | // |
| | | //////////////////////////////////////////////////// |
| | | /** |
| | | * 当前升级状态 |
| | | * @return |
| | | public UpgradeState currentUpgradeState() { |
| | | if(manager != null ){ |
| | | return manager.currentUpgradeState(); |
| | | } |
| | | return null ; |
| | | }*/ |
| | | |
| | | /** |
| | | * Rtu升级信息 |
| | | * @param rtuAddr |
| | | * @return |
| | | public UpgradeRtuDev upgradeRtuInfo(String rtuAddr){ |
| | | if(manager != null ){ |
| | | return manager.upgradeInfos(rtuAddr); |
| | | } |
| | | return null ; |
| | | }*/ |
| | | |
| | | /** |
| | | * Rtu升级信息 |
| | | * @param rtuAddrList |
| | | * @return |
| | | public List<UpgradeRtuDev> upgradeRtuInfos(List<String> rtuAddrList){ |
| | | if(manager != null ){ |
| | | return manager.upgradeInfos(rtuAddrList); |
| | | } |
| | | return null ; |
| | | }*/ |
| | | |
| | | /** |
| | | * Rtu升级信息 |
| | | * @return |
| | | public List<UpgradeRtuDev> upgradeRtuInfoAll(){ |
| | | if(manager != null ){ |
| | | return manager.upgradeInfoAll(); |
| | | } |
| | | return null ; |
| | | }*/ |
| | | |
| | | } |
| | | |