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.util.Callback;
|
|
import java.util.List;
|
|
/**
|
* @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 {
|
stopUpgradeTask() ;
|
}
|
|
|
|
/**
|
* 设置升级任务
|
* @param softFileName 升级程序文件名
|
* @param softStoreAddr 升级程序存放地址
|
* @param softStartAddr 程序覆盖起始地址
|
* @param softFileData 升级程序字节数组
|
* @param softBytesCalculate 升级程序字节数(按公式计算)
|
* @param rtuAddrList 升级RTU
|
* @throws Exception
|
*/
|
public void setUpgradeTask(String softFileName,
|
String softStoreAddr,
|
String softStartAddr,
|
byte[] softFileData,
|
Integer softBytesCalculate,
|
List<String> rtuAddrList) throws Exception {
|
if(manager != null ){
|
manager.setUpgradeTask(softFileName,
|
softStoreAddr,
|
softStartAddr,
|
softFileData,
|
softBytesCalculate,
|
rtuAddrList) ;
|
}
|
}
|
|
/**
|
* 停止当前升级任务
|
* @throws Exception
|
*/
|
public void stopUpgradeTask() throws Exception {
|
if(manager != null ){
|
manager.stopUpgradeTask() ;
|
}
|
}
|
|
/**
|
* RTU有上行数据了,触发下发升级数据
|
* @param rtuAddr
|
* @param code
|
* @param callback
|
*/
|
public void trigger(String rtuAddr, String code, String protocolName, Short protocolVersion, Callback callback){
|
if(manager != null ){
|
manager.trigger(rtuAddr, code, protocolName, protocolVersion, callback);
|
}
|
}
|
|
////////////////////////////////////////////////////
|
//
|
// 查询升级状态信息
|
//
|
////////////////////////////////////////////////////
|
/**
|
* 当前升级状态
|
* @return
|
*/
|
public UpgradeState currentUpgradeState() {
|
if(manager != null ){
|
return manager.currentUpgradeState();
|
}
|
return null ;
|
}
|
|
/**
|
* Rtu升级信息
|
* @param rtuAddr
|
* @return
|
*/
|
public UpgradeRtu upgradeInfos(String rtuAddr){
|
if(manager != null ){
|
return manager.upgradeInfos(rtuAddr);
|
}
|
return null ;
|
}
|
|
/**
|
* Rtu升级信息
|
* @param rtuAddrList
|
* @return
|
*/
|
public List<UpgradeRtu> upgradeInfos(List<String> rtuAddrList){
|
if(manager != null ){
|
return manager.upgradeInfos(rtuAddrList);
|
}
|
return null ;
|
}
|
|
}
|