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