feat 测试解析报文

new-master
rouchen 2024-06-05 22:29:07 +08:00
parent 1de1644ade
commit 6e12122a9d
2 changed files with 240 additions and 3 deletions

View File

@ -1,7 +1,11 @@
package com.muyu.utils;
import com.muyu.vehicle.model.VehicleData;
import lombok.extern.log4j.Log4j2;
import java.nio.charset.StandardCharsets;
@Log4j2
public class ConversionUtil {
/**
@ -28,12 +32,245 @@ public class ConversionUtil {
// System.out.println(str.length());
// System.out.println(strToSixteen);
// System.out.println(strToSixteen.replace(" ", "").length());
String hexStr = "3C3F786D6C2076657273696F6E3D22312E30223F3E0D0A3C6D6F6E69746F72526F6F7420747970653D22706172616D223E3C73796E6368726F6E697A65537970746F6D206576656E743D22302220696E697469616C3D2274727565223E3C416374696F6E5F4543473E3C52687974686D3E53696E75733C2F52687974686D3E3C48523E38303C2F48523E3C454D443E4E6F204368616E67653C2F454D443E3C436F6E647563743E303C2F436F6E647563743E3C2F416374696F6E5F4543473E3C416374696F6E5F4F7361742076616C75653D2239342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F425020697352656C617469766550657263656E743D2266616C7365223E3C536872696E6B2076616C75653D22313230222F3E3C537472657463682076616C75653D223830222F3E3C2F416374696F6E5F42503E3C416374696F6E5F5265737020627265617468547970653D224E6F726D616C222076616C75653D2231342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F6574434F322076616C75653D2233342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F54656D70657261747572652076616C75653D2233352E32222F3E3C416374696F6E5F4356502076616C75653D22362E30222F3E3C416374696F6E5F5041504469612076616C75653D223130222F3E3C416374696F6E5F5041505379732076616C75653D223235222F3E3C416374696F6E5F57502076616C75653D2239222F3E3C2F73796E6368726F6E697A65537970746F6D3E3C2F6D6F6E69746F72526F6F743E0D0A";
String hexStr = "7E 48 58 49 54 48 58 55 51 52 32 54 55 43 30 58 33 55 31 37 31 37 35 38 39 32 35 37 35 35 31 31 31 36 2e 37 36 34 36 35 30 30 33 39 2e 35 37 34 38 38 30 30 32 37 30 2e 30 30 32 30 2e 33 35 30 30 30 30 30 30 32 37 36 30 30 30 38 30 30 30 30 32 32 30 38 30 30 30 30 30 44 31 30 30 30 39 2e 30 30 30 33 32 30 30 30 30 34 34 37 34 39 37 38 36 30 31 30 39 30 30 30 32 32 32 30 30 35 32 38 34 30 30 30 30 37 35 38 38 34 2e 33 32 30 30 30 30 31 33 30 30 30 30 31 31 34 30 30 30 30 36 39 39 30 30 30 34 30 30 30 33 30 30 30 35 30 30 30 30 30 35 30 30 30 30 30 32 33 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 11 7E";
String hexStringToString = hexStringToString(hexStr);
System.out.println(hexStr);
System.out.println(hexStr.length());
System.out.println(hexStringToString);
System.out.println(hexStringToString.length());
//截取第一位和最后两位
String substring = hexStringToString.substring(1, hexStringToString.length() - 2);
log.error("substring:{}",substring.length());
//vin
String vin = substring.substring(0,17);
log.error("length:{}",vin.length());
log.error("vin:{}",vin);
//时间戳
String timestamp = substring.substring(17,30);
log.error("length:{}",timestamp.length());
log.error("timestamp:{}",timestamp);
//经度
String longitude = substring.substring(30, 41);
log.error("length:{}",longitude.length());
log.error("longitude:{}",longitude);
//维度
String latitude = substring.substring(41, 51);
log.error("length:{}",latitude.length());
log.error("latitude:{}",latitude);
//车速
String speed = substring.substring(51, 57);
int length = speed.length();
log.error("length:{}",length);
log.info("speed:{}",speed);
//总里程
String mileage = substring.substring(57, 68);
log.error("length:{}",mileage.length());
log.error("mileage:{}",mileage);
//总电压
String dischargeVoltage = substring.substring(68, 74);
log.error("length:{}",dischargeVoltage.length());
log.error("dischargeVoltage:{}",dischargeVoltage);
//总电流
String dischargeCurrent = substring.substring(74, 79);
log.error("length:{}",dischargeCurrent.length());
log.error("dischargeCurrent:{}",dischargeCurrent);
//绝缘电阻
String insulationResistance = substring.substring(79, 88);
log.error("length:{}",insulationResistance.length());
log.error("insulationResistance:{}",insulationResistance);
//档位
String gear = substring.substring(88, 89);
log.error("length:{}",gear.length());
log.error("gear:{}",gear);
//加速踏板行程值
String accelerationPedal = substring.substring(89, 91);
log.error("length:{}",accelerationPedal.length());
log.error("accelerationPedal:{}",accelerationPedal);
//制动踏板行程值
String brakePedal = substring.substring(91, 93);
log.error("length:{}",brakePedal.length());
log.error("brakePedal:{}",brakePedal);
//燃料消耗率
String fuelConsumption = substring.substring(93, 98);
log.error("length:{}",fuelConsumption.length());
log.error("fuelConsumption:{}",fuelConsumption);
////////////////
//电机控制器温度
String motorControllerTemperature = substring.substring(98, 104);
log.error("length:{}",motorControllerTemperature.length());
log.error("motorControllerTemperature:{}",motorControllerTemperature);
//电机转速
String motorSpeed = substring.substring(104, 109);
log.error("length:{}",motorSpeed.length());
log.error("motorSpeed:{}",motorSpeed);
//电机转矩
String motorTorque = substring.substring(109, 113);
log.error("length:{}",motorTorque.length());
log.error("motorTorque:{}",motorTorque);
//电机温度
String motorTemperature = substring.substring(113, 119);
log.error("length:{}",motorTemperature.length());
log.error("motorTemperature:{}",motorTemperature);
//电机电压
String motorVoltage = substring.substring(119, 124);
log.error("length:{}",motorVoltage.length());
log.error("motorVoltage:{}",motorVoltage);
//电机电流
String motorCurrent = substring.substring(124, 132);
log.error("length:{}",motorCurrent.length());
log.error("motorCurrent:{}",motorCurrent);
//动力电池剩余电量SOC
String powerBattery = substring.substring(132, 138);
log.error("length:{}",powerBattery.length());
log.error("powerBattery:{}",powerBattery);
//当前状态允许的最大反馈功率
String maxFeedbackPower = substring.substring(138, 144);
log.error("length:{}",maxFeedbackPower.length());
log.error("maxFeedbackPower:{}",maxFeedbackPower);
//当前状态允许最大放电功率
String maxDischargePower = substring.substring(144, 150);
log.error("length:{}",maxDischargePower.length());
log.error("maxDischargePower:{}",maxDischargePower);
//BMS自检计数器
String bmsSelfCheck = substring.substring(150, 152);
log.error("length:{}",bmsSelfCheck.length());
log.error("bmsSelfCheck:{}",bmsSelfCheck);
//动力电池充放电电流
String powerBatteryCurrent = substring.substring(152, 157);
log.error("length:{}",powerBatteryCurrent.length());
log.error("powerBatteryCurrent:{}",powerBatteryCurrent);
//动力电池负载端总电压V3
String powerBatteryV3 = substring.substring(157, 163);
log.error("length:{}",powerBatteryV3.length());
log.error("powerBatteryV3:{}",powerBatteryV3);
//单次最大电压
String maxVoltage = substring.substring(163, 167);
log.error("length:{}",maxVoltage.length());
log.error("maxVoltage:{}",maxVoltage);
//单体电池最低电压
String minVoltage = substring.substring(167, 171);
log.error("length:{}",minVoltage.length());
log.error("minVoltage:{}",minVoltage);
//单体电池最高温度
String maxTemperature = substring.substring(171, 177);
log.error("length:{}",maxTemperature.length());
log.error("maxTemperature:{}",maxTemperature);
//单体电池最低温度
String minTemperature = substring.substring(177, 183);
log.error("length:{}",minTemperature.length());
log.error("minTemperature:{}",minTemperature);
//动力电池可用容量
String availableCapacity = substring.substring(183, 189);
log.error("length:{}",availableCapacity.length());
log.error("availableCapacity:{}",availableCapacity);
//车辆状态
String vehicleStatus = substring.substring(189, 190);
log.error("length:{}",vehicleStatus.length());
log.error("vehicleStatus:{}",vehicleStatus);
//充电状态
String chargeStatus = substring.substring(190, 191);
log.error("length:{}",chargeStatus.length());
log.error("chargeStatus:{}",chargeStatus);
//运行状态
String runStatus = substring.substring(191, 192);
log.error("length:{}",runStatus.length());
log.error("runStatus:{}",runStatus);
//SOC
String soc = substring.substring(192, 193);
log.error("length:{}",soc.length());
log.error("soc:{}",soc);
//可充电储能装置工作状态
String chargeWorkStatus = substring.substring(193, 194);
log.error("length:{}",chargeWorkStatus.length());
log.error("chargeWorkStatus:{}",chargeWorkStatus);
//驱动电机状态
String driveMotorStatus = substring.substring(194, 195);
log.error("length:{}",driveMotorStatus.length());
log.error("driveMotorStatus:{}",driveMotorStatus);
//定位是否有效
String location = substring.substring(195, 196);
log.error("length:{}",location.length());
log.error("location:{}",location);
//EAS
String eas = substring.substring(196, 197);
log.error("length:{}",eas.length());
log.error("eas:{}",eas);
//PTC
String ptc = substring.substring(197, 198);
log.error("length:{}",ptc.length());
log.error("ptc:{}",ptc);
//EPS
String eps = substring.substring(198, 199);
log.error("length:{}",eps.length());
log.error("eps:{}",eps);
//ABS
String abs = substring.substring(199, 200);
log.error("length:{}",abs.length());
log.error("abs:{}",abs);
//MCU
String mcu = substring.substring(200, 201);
log.error("length:{}",mcu.length());
log.error("mcu:{}",mcu);
//动力电池加热状态
String powerBatteryHeating = substring.substring(201, 202);
log.error("length:{}",powerBatteryHeating.length());
log.error("powerBatteryHeating:{}",powerBatteryHeating);
//动力电池当前状态
String powerBatteryCurrentStatus = substring.substring(202, 203);
log.error("length:{}",powerBatteryCurrentStatus.length());
log.error("powerBatteryCurrentStatus:{}",powerBatteryCurrentStatus);
//动力电池保温状态
String powerBatteryHeat = substring.substring(203, 204);
log.error("length:{}",powerBatteryHeat.length());
log.error("powerBatteryHeat:{}",powerBatteryHeat);
//DCDC
String dcdc = substring.substring(204, 205);
log.error("length:{}",dcdc.length());
log.error("dcdc:{}",dcdc);
//CHG
String chg = substring.substring(205, 206);
log.error("length:{}",chg.length());
log.error("chg:{}",chg);
System.out.println(hexStringToString.length());
}

View File

@ -296,7 +296,7 @@ public class VehicleData {
getValue(resistance, 9) +
//档位
(gear == null ? "D" : gear) +
// 加速踏板行程值
// 加速踏板行程值91
getValue(accelerationPedal, 2) +
// 制动踏板行程值
getValue(brakePedal, 2) +