|
|
@ -19,118 +19,118 @@ import org.springframework.stereotype.Component; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* 子设备寄存器初始化服务 |
|
|
|
* 子设备寄存器初始化服务 |
|
|
|
*/ |
|
|
|
|
|
|
|
@Component |
|
|
|
@Slf4j |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class A8kSubModuleRegInitService { |
|
|
|
private final A8kCanBusService canBus; |
|
|
|
private final ModuleEnableCtrlDriver moduleEnableCtrlDriver; |
|
|
|
private final AppEventBusService eventBus; |
|
|
|
private final A8kSubModuleInitRegConfig a8kSubModuleInitRegConfig; |
|
|
|
private final SubModuleRegInitialValueMgrService subModuleRegInitialValueMgrService; |
|
|
|
private Boolean isInited = false; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
void init() { |
|
|
|
eventBus.regListener(this::onAppEvent); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized boolean getIsInited() { |
|
|
|
return isInited; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onAppEvent(AppEvent event) { |
|
|
|
if (event instanceof A8kCanBusOnConnectEvent) { |
|
|
|
var initThread = new Thread(this::initModuleRegVal); |
|
|
|
initThread.setName("initModuleRegVal"); |
|
|
|
initThread.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void initModuleRegVal() { |
|
|
|
do { |
|
|
|
private final A8kCanBusService canBus; |
|
|
|
private final ModuleEnableCtrlDriver moduleEnableCtrlDriver; |
|
|
|
private final AppEventBusService eventBus; |
|
|
|
private final A8kSubModuleInitRegConfig a8kSubModuleInitRegConfig; |
|
|
|
private final SubModuleRegInitialValueMgrService subModuleRegInitialValueMgrService; |
|
|
|
private Boolean isInited = false; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
void init() { |
|
|
|
eventBus.regListener(this::onAppEvent); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized boolean getIsInited() { |
|
|
|
return isInited; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onAppEvent(AppEvent event) { |
|
|
|
if (event instanceof A8kCanBusOnConnectEvent) { |
|
|
|
var initThread = new Thread(this::initModuleRegVal); |
|
|
|
initThread.setName("initModuleRegVal"); |
|
|
|
initThread.start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void initModuleRegVal() { |
|
|
|
do { |
|
|
|
// try { |
|
|
|
log.info("forceInitA8kModParams"); |
|
|
|
dumpAllSubBoardVersion(); |
|
|
|
log.info("forceInitA8kModParams"); |
|
|
|
dumpAllSubBoardVersion(); |
|
|
|
// initA8kModParams(); |
|
|
|
isInited = true; |
|
|
|
isInited = true; |
|
|
|
|
|
|
|
log.info("======================================================"); |
|
|
|
log.info("= init hardware param success...... ="); |
|
|
|
log.info("======================================================"); |
|
|
|
break; |
|
|
|
log.info("======================================================"); |
|
|
|
log.info("= init hardware param success...... ="); |
|
|
|
log.info("======================================================"); |
|
|
|
break; |
|
|
|
// } catch (HardwareException e) { |
|
|
|
// log.error("init hardware param fail......, try init it after 5s", e); |
|
|
|
// } |
|
|
|
} while (false); |
|
|
|
} |
|
|
|
|
|
|
|
private void dumpAllSubBoardVersion() { |
|
|
|
log.info("======================================================="); |
|
|
|
log.info("= dump all sub board version...... ="); |
|
|
|
log.info("="); |
|
|
|
|
|
|
|
boolean hasDiffVersion = false; |
|
|
|
Integer maxVersion = null; |
|
|
|
for (MId mid : MId.values()) { |
|
|
|
if (mid == MId.NotSet) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
try { |
|
|
|
if (!canBus.ping(mid)) { |
|
|
|
log.error(String.format("+ %-40s(%d): offline", mid, mid.index)); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
Integer ver = canBus.moduleReadVersion(mid); |
|
|
|
String moduleType = canBus.moduleReadType(mid).toString(); |
|
|
|
if (maxVersion != null && !maxVersion.equals(ver)) { |
|
|
|
hasDiffVersion = true; |
|
|
|
} |
|
|
|
if (maxVersion == null || ver > maxVersion) { |
|
|
|
maxVersion = ver; |
|
|
|
} |
|
|
|
log.info(String.format("+ %-40s(%d): type:%-20s version:%s", mid, mid.index, moduleType, ver)); |
|
|
|
} catch (HardwareException e) { |
|
|
|
log.error(String.format("+ %20s(%d): offline", mid, mid.index)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!hasDiffVersion) { |
|
|
|
// gStateMgrService.setMcuVersion(String.format("V%04d", maxVersion)); |
|
|
|
} else { |
|
|
|
//版本不一致,标记为(*),表示需要升级 |
|
|
|
// gStateMgrService.setMcuVersion(String.format("V%04d(*)", maxVersion)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initA8kModParams() throws HardwareException { |
|
|
|
for (MId mid : MId.values()) { |
|
|
|
if (mid == MId.NotSet) |
|
|
|
continue; |
|
|
|
|
|
|
|
log.info("============== {}({}) ===============", mid, mid.index); |
|
|
|
|
|
|
|
ModuleType moduleType = canBus.moduleReadType(mid); |
|
|
|
List<RegIndex> regIndexes = a8kSubModuleInitRegConfig.findRegIndexByModuleType(moduleType); |
|
|
|
|
|
|
|
for (RegIndex regIndex : regIndexes) { |
|
|
|
SubModuleRegInitialValue val = subModuleRegInitialValueMgrService.findByIDAndRegIndex(mid, regIndex); |
|
|
|
if (val == null) |
|
|
|
continue; |
|
|
|
|
|
|
|
log.info(String.format("= init %s(%d) %-45s: %d", mid, mid.index, regIndex, val.regInitVal)); |
|
|
|
canBus.moduleSetReg(mid, regIndex, val.regInitVal); |
|
|
|
} |
|
|
|
log.info("="); |
|
|
|
} |
|
|
|
} |
|
|
|
} while (false); |
|
|
|
} |
|
|
|
|
|
|
|
private void dumpAllSubBoardVersion() { |
|
|
|
log.info("======================================================="); |
|
|
|
log.info("= dump all sub board version...... ="); |
|
|
|
log.info("="); |
|
|
|
|
|
|
|
boolean hasDiffVersion = false; |
|
|
|
Integer maxVersion = null; |
|
|
|
for (MId mid : MId.values()) { |
|
|
|
if (mid == MId.NotSet) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
try { |
|
|
|
if (!canBus.ping(mid)) { |
|
|
|
log.error(String.format("+ %-40s(%d): offline", mid, mid.index)); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
Integer ver = canBus.moduleReadVersion(mid); |
|
|
|
String moduleType = canBus.moduleReadType(mid).toString(); |
|
|
|
if (maxVersion != null && !maxVersion.equals(ver)) { |
|
|
|
hasDiffVersion = true; |
|
|
|
} |
|
|
|
if (maxVersion == null || ver > maxVersion) { |
|
|
|
maxVersion = ver; |
|
|
|
} |
|
|
|
log.info(String.format("+ %-40s(%d): type:%-20s version:%s", mid, mid.index, moduleType, ver)); |
|
|
|
} catch (HardwareException e) { |
|
|
|
log.error(String.format("+ %20s(%d): offline", mid, mid.index)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!hasDiffVersion) { |
|
|
|
// gStateMgrService.setMcuVersion(String.format("V%04d", maxVersion)); |
|
|
|
} else { |
|
|
|
//版本不一致,标记为(*),表示需要升级 |
|
|
|
// gStateMgrService.setMcuVersion(String.format("V%04d(*)", maxVersion)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initA8kModParams() throws HardwareException { |
|
|
|
for (MId mid : MId.values()) { |
|
|
|
if (mid == MId.NotSet) |
|
|
|
continue; |
|
|
|
|
|
|
|
log.info("============== {}({}) ===============", mid, mid.index); |
|
|
|
|
|
|
|
ModuleType moduleType = canBus.moduleReadType(mid); |
|
|
|
List<RegIndex> regIndexes = a8kSubModuleInitRegConfig.findRegIndexByModuleType(moduleType); |
|
|
|
|
|
|
|
for (RegIndex regIndex : regIndexes) { |
|
|
|
SubModuleRegInitialValue val = subModuleRegInitialValueMgrService.findByIDAndRegIndex(mid, regIndex); |
|
|
|
if (val == null) |
|
|
|
continue; |
|
|
|
|
|
|
|
log.info(String.format("= init %s(%d) %-45s: %d", mid, mid.index, regIndex, val.regInitVal)); |
|
|
|
canBus.moduleSetReg(mid, regIndex, val.regInitVal); |
|
|
|
} |
|
|
|
log.info("="); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |