You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.3 KiB
114 lines
3.3 KiB
package com.automobile.system;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 汽车电子系统类 - 与汽车是组合关系
|
|
* 电子系统包含多个电子控制单元(ECU),展示复杂的组合关系
|
|
*/
|
|
public class ElectronicSystem {
|
|
private String status;
|
|
private boolean initialized;
|
|
|
|
// 组合关系 - 电子系统包含多个电子控制单元
|
|
private List<ElectronicControlUnit> ecus;
|
|
|
|
/**
|
|
* 构造方法 - 创建电子系统时同时创建各种电子控制单元
|
|
*/
|
|
public ElectronicSystem() {
|
|
this.status = "未初始化";
|
|
this.initialized = false;
|
|
|
|
// 创建各种电子控制单元(组合关系)
|
|
this.ecus = new ArrayList<>();
|
|
this.ecus.add(new ElectronicControlUnit("发动机控制单元", "ECM"));
|
|
this.ecus.add(new ElectronicControlUnit("变速箱控制单元", "TCM"));
|
|
this.ecus.add(new ElectronicControlUnit("车身控制单元", "BCM"));
|
|
this.ecus.add(new ElectronicControlUnit("防抱死制动系统", "ABS"));
|
|
this.ecus.add(new ElectronicControlUnit("安全气囊控制单元", "SRS"));
|
|
}
|
|
|
|
/**
|
|
* 初始化电子系统
|
|
*/
|
|
public void initializate() {
|
|
if (!initialized) {
|
|
initialized = true;
|
|
this.status = "运行中";
|
|
System.out.println("电子系统初始化中...");
|
|
|
|
// 初始化所有电子控制单元
|
|
for (ElectronicControlUnit ecu : ecus) {
|
|
ecu.initialize();
|
|
}
|
|
|
|
System.out.println("电子系统初始化完成");
|
|
} else {
|
|
System.out.println("电子系统已经初始化");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 关闭电子系统
|
|
*/
|
|
public void shutdown() {
|
|
if (initialized) {
|
|
initialized = false;
|
|
this.status = "已关闭";
|
|
System.out.println("电子系统关闭中...");
|
|
|
|
// 关闭所有电子控制单元
|
|
for (ElectronicControlUnit ecu : ecus) {
|
|
ecu.shutdown();
|
|
}
|
|
|
|
System.out.println("电子系统已关闭");
|
|
} else {
|
|
System.out.println("电子系统已经关闭");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 诊断电子系统
|
|
*/
|
|
public void runDiagnostics() {
|
|
System.out.println("===== 电子系统诊断 ====");
|
|
System.out.println("系统状态: " + status);
|
|
|
|
for (ElectronicControlUnit ecu : ecus) {
|
|
ecu.runSelfTest();
|
|
}
|
|
|
|
System.out.println("======================");
|
|
}
|
|
|
|
/**
|
|
* 更新软件
|
|
* @param ecuType ECU类型
|
|
* @param version 新版本
|
|
*/
|
|
public void updateSoftware(String ecuType, String version) {
|
|
for (ElectronicControlUnit ecu : ecus) {
|
|
if (ecu.getType().contains(ecuType)) {
|
|
ecu.updateSoftware(version);
|
|
return;
|
|
}
|
|
}
|
|
System.out.println("未找到类型为 " + ecuType + " 的电子控制单元");
|
|
}
|
|
|
|
// Getter 和 Setter 方法
|
|
public String getStatus() {
|
|
return status;
|
|
}
|
|
|
|
public boolean isInitialized() {
|
|
return initialized;
|
|
}
|
|
|
|
public List<ElectronicControlUnit> getEcus() {
|
|
return ecus;
|
|
}
|
|
} |