时速计算bug
parent
4cf4047a86
commit
53216b6918
File diff suppressed because one or more lines are too long
|
@ -227,7 +227,9 @@ public class VehicleInstance {
|
||||||
);
|
);
|
||||||
// 计算总速度
|
// 计算总速度
|
||||||
vehicleData.setSpeed(
|
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.imitateBase();
|
||||||
vehicleData.imitateMotor();
|
vehicleData.imitateMotor();
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.vehicle.core;
|
||||||
import com.muyu.vehicle.VehicleInstance;
|
import com.muyu.vehicle.VehicleInstance;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +22,9 @@ public class LocalContainer {
|
||||||
* 添加车辆
|
* 添加车辆
|
||||||
* @param vehicleInstance 车辆信息
|
* @param vehicleInstance 车辆信息
|
||||||
*/
|
*/
|
||||||
|
public static void setVehicleInstance(List<VehicleInstance> vehicleInstance){
|
||||||
|
vehicleInstance.forEach(LocalContainer::setVehicleInstance);
|
||||||
|
}
|
||||||
public static void setVehicleInstance(VehicleInstance vehicleInstance){
|
public static void setVehicleInstance(VehicleInstance vehicleInstance){
|
||||||
String vin = vehicleInstance.getVehicle().getVin();
|
String vin = vehicleInstance.getVehicle().getVin();
|
||||||
if (!vehicleDataMap.containsKey(vin)) {
|
if (!vehicleDataMap.containsKey(vin)) {
|
||||||
|
|
|
@ -3,12 +3,17 @@ package com.muyu.vehicle.core;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
import com.muyu.service.VehicleService;
|
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.AllArgsConstructor;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,27 +29,46 @@ public class VehicleConfiguration implements ApplicationRunner {
|
||||||
|
|
||||||
private final VehicleService vehicleService;
|
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();
|
long startTime = System.currentTimeMillis();
|
||||||
int page = 0, pageSize = 1000;
|
int page = 0, pageSize = 10;
|
||||||
log.info("初始开始,批量从数据库当中加载数据到内存当中,每次[{}]条", pageSize);
|
log.info("初始开始,批量从数据库当中加载数据到内存当中,每次[{}]条", pageSize);
|
||||||
while (true){
|
while (true){
|
||||||
Page<Vehicle> vehiclePage = vehicleService.page(new Page<Vehicle>(page++, pageSize));
|
Page<Vehicle> vehiclePage = vehicleService.page(new Page<>(page++, pageSize));
|
||||||
List<Vehicle> records = vehiclePage.getRecords();
|
List<Vehicle> vehicleList = vehiclePage.getRecords();
|
||||||
// records.forEach(LocalContainer::setVehicle);
|
vehicleList.stream()
|
||||||
log.info("第[{}]页,[{}]条", page, records.size());
|
.map(this::init)
|
||||||
if (records.size() < pageSize){
|
.forEach(LocalContainer::setVehicleInstance);
|
||||||
|
log.info("第[{}]页,[{}]条", page, vehicleList.size());
|
||||||
|
if (vehicleList.size() < pageSize){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.info("数据加载完成,耗时:{}MS", System.currentTimeMillis() - startTime);
|
log.info("数据加载完成,耗时:{} MS", System.currentTimeMillis() - startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run (ApplicationArguments args) throws Exception {
|
public void run (ApplicationArguments args) throws Exception {
|
||||||
this.vehicleInit();
|
this.vehiclePageInit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,102 +276,100 @@ public class VehicleData {
|
||||||
private String batteryMsg;
|
private String batteryMsg;
|
||||||
|
|
||||||
public String getMsg(){
|
public String getMsg(){
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
//第一位VIN
|
//第一位VIN
|
||||||
sb.append(vin);
|
return vin +
|
||||||
// 当前时间戳
|
// 当前时间戳
|
||||||
sb.append(System.currentTimeMillis());
|
System.currentTimeMillis() +
|
||||||
//第二位经度 longitude latitude
|
//第二位经度 longitude latitude
|
||||||
sb.append(getValue(longitude ,11));
|
getValue(longitude, 11) +
|
||||||
//第三位维度 longitude latitude
|
//第三位维度 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
|
//绝缘电阻 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
|
//动力电池剩余电量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自检计数器
|
//BMS自检计数器
|
||||||
sb.append(getValue(selfCheckCounter,2));
|
getValue(selfCheckCounter, 2) +
|
||||||
//动力电池充放电电流
|
//动力电池充放电电流
|
||||||
sb.append(getValue(totalBatteryCurrent,5));
|
getValue(totalBatteryCurrent, 5) +
|
||||||
//动力电池负载端总电压V3
|
//动力电池负载端总电压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
|
//SOC
|
||||||
sb.append(socStatus);
|
socStatus +
|
||||||
//可充电储能装置工作状态
|
//可充电储能装置工作状态
|
||||||
sb.append(chargingEnergyStorageStatus);
|
chargingEnergyStorageStatus +
|
||||||
//驱动电机状态
|
//驱动电机状态
|
||||||
sb.append(driveMotorStatus);
|
driveMotorStatus +
|
||||||
//定位是否有效
|
//定位是否有效
|
||||||
sb.append(positionStatus);
|
positionStatus +
|
||||||
//EAS
|
//EAS
|
||||||
sb.append(easStatus);
|
easStatus +
|
||||||
//PTC
|
//PTC
|
||||||
sb.append(ptcStatus);
|
ptcStatus +
|
||||||
//EPS
|
//EPS
|
||||||
sb.append(epsStatus);
|
epsStatus +
|
||||||
//ABS
|
//ABS
|
||||||
sb.append(absStatus);
|
absStatus +
|
||||||
//MCU
|
//MCU
|
||||||
sb.append(mcuStatus);
|
mcuStatus +
|
||||||
//动力电池加热状态
|
//动力电池加热状态
|
||||||
sb.append(heatingStatus);
|
heatingStatus +
|
||||||
//动力电池当前状态
|
//动力电池当前状态
|
||||||
sb.append(batteryStatus);
|
batteryStatus +
|
||||||
//动力电池保温状态
|
//动力电池保温状态
|
||||||
sb.append(batteryInsulationStatus);
|
batteryInsulationStatus +
|
||||||
//DCDC
|
//DCDC
|
||||||
sb.append(dcdcStatus);
|
dcdcStatus +
|
||||||
//CHG
|
//CHG
|
||||||
sb.append(chgStatus);
|
chgStatus;
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue(String val , int valLength){
|
public String getValue(String val , int valLength){
|
||||||
|
|
|
@ -68,3 +68,4 @@ logging:
|
||||||
pattern:
|
pattern:
|
||||||
file: '%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n'
|
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'
|
console: '%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue