执行流程
public static void businessExecutionWork(){
//以下为业务逻辑部分
System.out.println("1、根据电池包控制风扇服务执行 开始!");
//1、获取电池包电压、电流、环境温度
//获取电池包电压、电流、环境温度
ObtainBatteryDataService obtainBatteryDataService = new ObtainBatteryDataServiceImpl();
List<ObtainBatteryBean> sendObtainBatteryData= obtainBatteryDataService.obtainBatteryDataList(BATTERY_ID);
//2、通过CAN总线发送 CAN信号到总控制系统
CanChannelUtil canChannelUtil = new CanChannelUtil();
canChannelUtil.sendObtainBattery(sendObtainBatteryData);
System.out.println("2、通过CAN总线发送 CAN信号到总控制系统!");
//3、总控制系统接收CAN信号
MainCenterBussinessService mainCenterBussinessService = new MainCenterBussinessServiceImpl();
List<ObtainBatteryBean> receiveObtainBatteryData= canChannelUtil.receiveObtainBattery();
//4、对电池包电压、电流、环境温度监测
System.out.println("4、对电池包电压、电流、环境温度监测!");
boolean status = mainCenterBussinessService.checkBatterystatus(receiveObtainBatteryData);
//5、根据电池包电压、电流、环境温度控制风扇
System.out.println("5、根据电池包控制风扇服务执行!");
if(status){
//控制风扇打开 打开时间为1分钟!
mainCenterBussinessService.fanHeatExchanger(true);
}else{
mainCenterBussinessService.fanHeatExchanger(false);
}
//6、根据电池包控制风扇服务执行 结束
System.out.println("6、根据电池包控制风扇服务执行 结束!");
}
监测风扇
public boolean checkBatterystatus(List<ObtainBatteryBean> obtainBatteryBeanList) {
System.out.println("4.1、检测开始");
if (obtainBatteryBeanList.size() == 0) {
return false;
}
int i = 0;
System.out.println("4.1、判断温度、电流、环境温度是否达到临界阀值");
for (ObtainBatteryBean obtainBatteryBean : obtainBatteryBeanList) {
if (obtainBatteryBean.getCurrent() > Constants.CURRENT) {
i++;
continue;
}
if (obtainBatteryBean.getTemperature() > Constants.TEMPERATURE) {
i++;
continue;
}
if (obtainBatteryBean.getVoltage() > Constants.VOLTAGE) {
i++;
continue;
}
}
System.out.println("4.2、估算soc");
if(i>obtainBatteryBeanList.size()/2){
System.out.println("4.3、需要预警保护");
return true;
}
System.out.println("4.3、不需要预警保护");
return false;
}
临界值配置 配置
/**
* @desc: 临界值配置 配置
* @author: langjf
* @date: 2024/5/6
*/
public class Constants {
/**
* 电流阈值
*/
public static final Double CURRENT = 10D;
/**
* 电压阈值
*/
public static final Double VOLTAGE = 220D;
/**
*温度阀值
*/
public static final Double TEMPERATURE = 80D;
/**
* 扇热时间 60秒
*/
public static final int HEAT_DISSIPATION_TIME = 60000;
/**
* 是否开启扇热
*/
public static AtomicInteger fanHeatExchanger = new AtomicInteger(0);
/**
* 监测周期 5秒
*/
public static final int MONITORING_CYCLE=5000;
/**
* 开启扇热
*/
public static void fanHeatStart(){
fanHeatExchanger.addAndGet(1);
System.out.println("开启扇热");
}
/**
* 关闭扇热
*/
public static void fanHeatStop(){
fanHeatExchanger.addAndGet(-1);
System.out.println("关闭扇热");
}
/**
* 查看开启状态
* @return
*/
public static boolean getFanHeatStatus(){
if(fanHeatExchanger.get()>0){
System.out.println("当前开启状态为:开启");
return true;
}
System.out.println("当前开启状态为:关闭");
return false;
}
}
发送CAN信号
/**
* @desc:发送CAN信号
* @author: langjf
* @date: 2024/5/6
*/
public class CanChannelUtil {
List<ObtainBatteryBean> beanList=new ArrayList<>();
/**
* 发送CAN信号 实际信号值为0101 类型二进制数据流 此处为数据模拟 暂不做处理
* @param beanList
*/
public void sendObtainBattery(List<ObtainBatteryBean> beanList){
this.beanList=beanList;
}
/**
* 接收CAN信号 实际信号值为0101 类型二进制数据流 此处为数据模拟 暂不做处理
* @return
*/
public List<ObtainBatteryBean> receiveObtainBattery(){
return beanList;
}
}
获取电池包的单体电压 电流 环境温度
/**
* @desc: 获取电池包的单体电压 电流 环境温度
* @author: langjf
* @date: 2024/5/6
*/
public class ObtainBatteryUtil {
/**
* 获取电池电流
* @param batteryId
* @return
*/
public static Double getCurrent(String batteryId){
//system get current 模拟值
Double current =Math.random()*100;
return current;
}
/**
* 获取电池电压
* @param batteryId
* @return
*/
public static Double getVoltage(String batteryId){
//system get voltage 模拟值
Double voltage =Math.random()*220;
return voltage;
}
/**
* 获取电池温度
* @param batteryId
* @return
*/
public static Double getTemperature(String batteryId){
//system get temperature 模拟值
Double temperature =Math.random()*100;
return temperature;
}
/**
* 获取电池包中所有电池编码集合 模拟值
* @return
*/
public static List<String> getBatteryIdList(){
//system get batteryIdList 模拟值
List<String> batteryIdList =new ArrayList<>();
while (batteryIdList.size()<=10){
String code="设备"+Math.random()*100;
if(!batteryIdList.contains(code)){
batteryIdList.add(code);
}
}
return batteryIdList;
}
}
电池数据封装
/**
* @desc: 电池数据封装
* @author: langjf
* @date: 2024/5/6
*/
@Data
public class ObtainBatteryBean {
/**
* 电池包ID
*/
private String batteryId;
/**
* 电流
*/
private Double current;
/**
* 电压
*/
private Double voltage;
/**
* 温度
*/
private Double temperature;
}
得到电池包含的数据 包括电流 电压 温度
/**
* @desc: 得到电池包含的数据 包括电流 电压 温度
* @author: langjf
* @date: 2024/5/6
*/
public class ObtainBatteryDataServiceImpl implements ObtainBatteryDataService {
@Override
public ObtainBatteryBean obtainBatteryData(String batteryId) {
ObtainBatteryBean obtainBatteryBean=new ObtainBatteryBean();
obtainBatteryBean.setBatteryId(batteryId);
obtainBatteryBean.setTemperature(ObtainBatteryUtil.getTemperature(batteryId));
obtainBatteryBean.setCurrent(ObtainBatteryUtil.getCurrent(batteryId));
obtainBatteryBean.setVoltage(ObtainBatteryUtil.getVoltage(batteryId));
return obtainBatteryBean;
}
@Override
public List<ObtainBatteryBean> obtainBatteryDataList(String equipment) {
List<String> batteryIdList=ObtainBatteryUtil.getBatteryIdList();
List<ObtainBatteryBean> obtainBatteryBeanList=new ArrayList<>();
batteryIdList.stream().forEach(batteryId -> {
obtainBatteryBeanList.add(obtainBatteryData(batteryId));
});
return obtainBatteryBeanList;
}
}
执行
public class Main {
/**
* 设备ID
*/
private static final String BATTERY_ID = "Battery";
public static void main(String[] args) {
try {
while (true){
//判断风扇是否开启
System.out.println("判断风扇是否开启");
Boolean fanHeatStatus = Constants.getFanHeatStatus();
if(!fanHeatStatus){
//未开启 执行电池包检测 业务逻辑
businessExecutionWork();
//判断是否开启
fanHeatStatus = Constants.getFanHeatStatus();
if(fanHeatStatus){
//风扇开启后60秒后在进行 电池包检测
System.out.println("风扇已开启 等待风扇开启60秒 进行扇热");
Thread.sleep(Constants.HEAT_DISSIPATION_TIME);
System.out.println("风扇已开启60秒,执行关闭风扇;");
Constants.fanHeatStop();
}
}
System.out.println("5秒后继续检测电池包");
Thread.sleep(Constants.MONITORING_CYCLE);
}
} catch (InterruptedException e) {
e.printStackTrace();
System.out.println("异常中断!");
}
}
}
main方法执行效果