时速计算bug

master
DongZeLiang 2023-11-22 15:13:57 +08:00
parent 4cf4047a86
commit 53216b6918
6 changed files with 145 additions and 115 deletions

File diff suppressed because one or more lines are too long

View File

@ -227,7 +227,9 @@ public class VehicleInstance {
);
// 计算总速度
vehicleData.setSpeed(
distance.divide(new BigDecimal(10)).multiply(new BigDecimal("3.6")).setScale(2, RoundingMode.HALF_UP).toString()
distance.divide(new BigDecimal(2))
.multiply(new BigDecimal("3600"))
.setScale(2, RoundingMode.HALF_UP).toString()
);
vehicleData.imitateBase();
vehicleData.imitateMotor();

View File

@ -3,6 +3,7 @@ package com.muyu.vehicle.core;
import com.muyu.vehicle.VehicleInstance;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -21,6 +22,9 @@ public class LocalContainer {
*
* @param vehicleInstance
*/
public static void setVehicleInstance(List<VehicleInstance> vehicleInstance){
vehicleInstance.forEach(LocalContainer::setVehicleInstance);
}
public static void setVehicleInstance(VehicleInstance vehicleInstance){
String vin = vehicleInstance.getVehicle().getVin();
if (!vehicleDataMap.containsKey(vin)) {

View File

@ -3,12 +3,17 @@ package com.muyu.vehicle.core;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.muyu.domain.Vehicle;
import com.muyu.service.VehicleService;
import com.muyu.vehicle.VehicleInstance;
import com.muyu.vehicle.model.VehicleData;
import com.muyu.vehicle.model.properties.MqttProperties;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
@ -24,19 +29,38 @@ public class VehicleConfiguration implements ApplicationRunner {
private final VehicleService vehicleService;
public VehicleInstance init(Vehicle vehicle){
log.info("构建车辆对象: [{}]", vehicle.getVin());
VehicleInstance vehicleInstance = new VehicleInstance(
MqttProperties.builder()
.broker("tcp://fluxmq.muyu.icu:1883")
.topic("test")
.clientId(vehicle.getVin())
.build()
);
log.info("构建车辆实例: [{}]", vehicle.getVin());
vehicleInstance.setVehicle(vehicle);
vehicleInstance.setVehicleData(VehicleData.vehicleBuild(vehicle));
vehicleInstance.initCline();
log.info("构建车辆客户端: [{}]", vehicle.getVin());
return vehicleInstance;
}
/**
*
*/
public void vehicleInit(){
public void vehiclePageInit (){
long startTime = System.currentTimeMillis();
int page = 0, pageSize = 1000;
int page = 0, pageSize = 10;
log.info("初始开始,批量从数据库当中加载数据到内存当中,每次[{}]条", pageSize);
while (true){
Page<Vehicle> vehiclePage = vehicleService.page(new Page<Vehicle>(page++, pageSize));
List<Vehicle> records = vehiclePage.getRecords();
// records.forEach(LocalContainer::setVehicle);
log.info("第[{}]页,[{}]条", page, records.size());
if (records.size() < pageSize){
Page<Vehicle> vehiclePage = vehicleService.page(new Page<>(page++, pageSize));
List<Vehicle> vehicleList = vehiclePage.getRecords();
vehicleList.stream()
.map(this::init)
.forEach(LocalContainer::setVehicleInstance);
log.info("第[{}]页,[{}]条", page, vehicleList.size());
if (vehicleList.size() < pageSize){
break;
}
}
@ -45,6 +69,6 @@ public class VehicleConfiguration implements ApplicationRunner {
@Override
public void run (ApplicationArguments args) throws Exception {
this.vehicleInit();
this.vehiclePageInit();
}
}

View File

@ -276,102 +276,100 @@ public class VehicleData {
private String batteryMsg;
public String getMsg(){
StringBuilder sb = new StringBuilder();
//第一位VIN
sb.append(vin);
return vin +
// 当前时间戳
sb.append(System.currentTimeMillis());
System.currentTimeMillis() +
//第二位经度 longitude latitude
sb.append(getValue(longitude ,11));
getValue(longitude, 11) +
//第三位维度 longitude latitude
sb.append(getValue(latitude ,10));
getValue(latitude, 10) +
//车速
sb.append(getValue(speed,6));
getValue(speed, 6) +
//总里程
sb.append(getValue(mileage == null ? "" : mileage.toString(),11));
getValue(mileage == null ? "" : mileage.toString(), 11) +
// 总电压
sb.append(getValue(voltage,6));
getValue(voltage, 6) +
//总电流
sb.append(getValue(current,5));
getValue(current, 5) +
//绝缘电阻 79 - 87
sb.append(getValue(resistance,9));
getValue(resistance, 9) +
//档位
sb.append(gear == null ? "D" : gear);
(gear == null ? "D" : gear) +
// 加速踏板行程值
sb.append(getValue(accelerationPedal,2));
getValue(accelerationPedal, 2) +
// 制动踏板行程值
sb.append(getValue(brakePedal,2));
getValue(brakePedal, 2) +
// 燃料消耗率
sb.append(getValue(fuelConsumptionRate,5));
getValue(fuelConsumptionRate, 5) +
//电机控制器温度
sb.append(getValue(motorControllerTemperature,6));
getValue(motorControllerTemperature, 6) +
//电机转速
sb.append(getValue(motorSpeed,5));
getValue(motorSpeed, 5) +
//点击转矩
sb.append(getValue(motorTorque,4));
getValue(motorTorque, 4) +
//电机温度
sb.append(getValue(motorTemperature,6));
getValue(motorTemperature, 6) +
//电机电压
sb.append(getValue(motorVoltage,5));
getValue(motorVoltage, 5) +
//电机电流
sb.append(getValue(motorCurrent,8));
getValue(motorCurrent, 8) +
//动力电池剩余电量SOC
sb.append(getValue(remainingBattery == null ? "" : remainingBattery.toString(),6));
getValue(remainingBattery == null ? "" : remainingBattery.toString(), 6) +
//当前状态允许的最大反馈功率
sb.append(getValue(maximumFeedbackPower,6));
getValue(maximumFeedbackPower, 6) +
//当前状态允许最大放电功率
sb.append(getValue(maximumDischargePower,6));
getValue(maximumDischargePower, 6) +
//BMS自检计数器
sb.append(getValue(selfCheckCounter,2));
getValue(selfCheckCounter, 2) +
//动力电池充放电电流
sb.append(getValue(totalBatteryCurrent,5));
getValue(totalBatteryCurrent, 5) +
//动力电池负载端总电压V3
sb.append(getValue(totalBatteryVoltage,6));
getValue(totalBatteryVoltage, 6) +
//单次最大电压
sb.append(getValue(singleBatteryMaxVoltage,4));
getValue(singleBatteryMaxVoltage, 4) +
//单体电池最低电压
sb.append(getValue(singleBatteryMinVoltage,4));
getValue(singleBatteryMinVoltage, 4) +
//单体电池最高温度
sb.append(getValue(singleBatteryMaxTemperature,6));
getValue(singleBatteryMaxTemperature, 6) +
//单体电池最低温度
sb.append(getValue(singleBatteryMinTemperature,6));
getValue(singleBatteryMinTemperature, 6) +
//动力电池可用容量
sb.append(getValue(availableBatteryCapacity,6));
getValue(availableBatteryCapacity, 6) +
//车辆状态
sb.append(vehicleStatus);
vehicleStatus +
//充电状态
sb.append(chargingStatus);
chargingStatus +
//运行状态
sb.append(operatingStatus);
operatingStatus +
//SOC
sb.append(socStatus);
socStatus +
//可充电储能装置工作状态
sb.append(chargingEnergyStorageStatus);
chargingEnergyStorageStatus +
//驱动电机状态
sb.append(driveMotorStatus);
driveMotorStatus +
//定位是否有效
sb.append(positionStatus);
positionStatus +
//EAS
sb.append(easStatus);
easStatus +
//PTC
sb.append(ptcStatus);
ptcStatus +
//EPS
sb.append(epsStatus);
epsStatus +
//ABS
sb.append(absStatus);
absStatus +
//MCU
sb.append(mcuStatus);
mcuStatus +
//动力电池加热状态
sb.append(heatingStatus);
heatingStatus +
//动力电池当前状态
sb.append(batteryStatus);
batteryStatus +
//动力电池保温状态
sb.append(batteryInsulationStatus);
batteryInsulationStatus +
//DCDC
sb.append(dcdcStatus);
dcdcStatus +
//CHG
sb.append(chgStatus);
return sb.toString();
chgStatus;
}
public String getValue(String val , int valLength){

View File

@ -68,3 +68,4 @@ logging:
pattern:
file: '%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n'
console: '%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n'