解析报文

server_five_liuyunhu
dongxiaodong 2024-03-31 22:28:46 +08:00
parent b17a7104e0
commit a20dc82049
14 changed files with 587 additions and 67 deletions

View File

@ -15,6 +15,7 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
@ -23,5 +24,6 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
main:
allow-bean-definition-overriding: true

View File

@ -15,6 +15,7 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
@ -23,6 +24,7 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
sentinel:
# 取消控制台懒加载
eager: true

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 00004c44-c962-48f0-bc9a-7e589b2881e3
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 00004c44-c962-48f0-bc9a-7e589b2881e3
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -17,4 +17,68 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- MuYu Common DataSource -->
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-common-datasource</artifactId>
</dependency>
<!-- MuYu Common DataScope -->
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-common-datascope</artifactId>
</dependency>
<!-- MuYu Common Log -->
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-common-log</artifactId>
</dependency>
<!-- MuYu Common Swagger -->
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-common-swagger</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,382 @@
package com.couplet.msg.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @author DongXiaoDong
* @version 1.0
* @date 2024/3/31 16:01
* @description
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MsgData {
/**
* VIN
*/
private String vin;
/**
* 线
*/
private String drivingRoute;
/**
*
*/
private String longitude;
/**
*
*/
private String latitude;
/**
*
*/
private String speed;
/**
*
*/
private BigDecimal mileage;
/**
*
*/
private String voltage;
/**
*
*/
private String current;
/**
*
*/
private String resistance;
/**
*
*/
private String gear = "P";
/**
*
*/
private String accelerationPedal;
/**
*
*/
private String brakePedal;
/**
*
*/
private String fuelConsumptionRate;
/**
*
*/
private String motorControllerTemperature;
/**
*
*/
private String motorSpeed;
/**
*
*/
private String motorTorque;
/**
*
*/
private String motorTemperature;
/**
*
*/
private String motorVoltage;
/**
*
*/
private String motorCurrent;
/**
* SOC
*/
private BigDecimal remainingBattery;
/**
*
*/
private BigDecimal batteryLevel;
/**
*
*/
private String maximumFeedbackPower;
/**
*
*/
private String maximumDischargePower;
/**
* BMS
*/
private String selfCheckCounter;
/**
*
*/
private String totalBatteryCurrent;
/**
* V3
*/
private String totalBatteryVoltage;
/**
*
*/
private String singleBatteryMaxVoltage;
/**
*
*/
private String singleBatteryMinVoltage;
/**
*
*/
private String singleBatteryMaxTemperature;
/**
*
*/
private String singleBatteryMinTemperature;
/**
*
*/
private String availableBatteryCapacity;
/**
*
*/
private int vehicleStatus = 1;
/**
*
*/
private int chargingStatus = 1;
/**
*
*/
private int operatingStatus = 1;
/**
* SOC
*/
private int socStatus = 1;
/**
*
*/
private int chargingEnergyStorageStatus = 1;
/**
*
*/
private int driveMotorStatus = 1;
/**
*
*/
private int positionStatus = 1;
/**
* EAS()
*/
private int easStatus = 1;
/**
* PTC()
*/
private int ptcStatus = 1;
/**
* EPS()
*/
private int epsStatus = 1;
/**
* ABS()
*/
private int absStatus = 1;
/**
* MCU(/)
*/
private int mcuStatus = 1;
/**
*
*/
private int heatingStatus = 1;
/**
*
*/
private int batteryStatus = 1;
/**
*
*/
private int batteryInsulationStatus = 1;
/**
* DCDC()
*/
private int dcdcStatus = 1;
/**
* CHG()
*/
private int chgStatus = 1;
/**
*
*/
private String vehicleStatusMsg;
/**
*
*/
private String smartHardwareMsg;
/**
*
*/
private String batteryMsg;
public String getMsg(){
//第一位VIN
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){
if(val == null){
val = "";
}
int length = val.length();
if (length > valLength){
return val.substring( 0 , valLength);
}
val = val + "0".repeat(valLength - length);
return val;
}
}

View File

@ -0,0 +1,51 @@
package com.couplet.msg.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* @author DongXiaoDong
* @version 1.0
* @date 2024/3/31 21:18
* @description
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TroubleLog {
/**
* Id
*/
private Integer troubleLogId;
/**
*
*/
private String troubleLogCode;
/**
* VIN
*/
private String troubleLogVin;
/**
*
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date troubleLogStartTime;
/**
*
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date troubleLogEndTime;
}

View File

@ -0,0 +1,28 @@
package com.couplet.msg;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author DongXiaoDong
* @version 1.0
* @date 2024/3/31 16:57
* @description
*/
public class Main {
public static void main(String[] args) {
String msgString = "VIN123456789DIJE41711764104506116.664380039.531990072.00031.3760000022000022000852000000D00809.600940000589066790930000203002030000044282.55000014000080700007440003000400095000058000054000011111111111111111";
//使用正则表达式匹配需要的部分
String pattern = "(.{17})(.{10})(.{4})(.{2})(.{2})";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(msgString);
if (matcher.find()) {
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group "+ i + ":" + matcher.group(i));
}
}
}
}

View File

@ -1,44 +0,0 @@
package com.couplet.msg;
import java.util.ArrayList;
import java.util.List;
/**
* @author DongXiaoDong
* @version 1.0
* @date 2024/3/30 14:40
* @description
*/
public class Msg {
private static final List<String> hexDataList = new ArrayList<String>() {{
add("56 49 4e 31 32 33 34 35 36 37 38 39 44 49 4a 45 34 31 37 31 31 37 36 34 31 30 34 35 30 36 31 31 36 2e 36 36 34 33 38 30 30 33 39 2e 35 33 31 39 39 30 30 37 32 2e 30 30 30 33 31 2e 33 37 36 30 30 30 30 30 32 32 30 30 30 30 32 32 30 30 30 38 35 32 30 30 30 30 30 30 44 30 30 38 30 39 2e 36 30 30 39 34 30 30 30 30 35 38 39 30 36 36 37 39 30 39 33 30 30 30 30 32 30 33 30 30 32 30 33 30 30 30 30 30 34 34 32 38 32 2e 35 35 30 30 30 30 31 34 30 30 30 30 38 30 37 30 30 30 30 37 34 34 30 30 30 33 30 30 30 34 30 30 30 39 35 30 30 30 30 35 38 30 30 30 30 35 34 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 24");
}};
public static void main(String[] args) {
for (String hexData : hexDataList) {
int checksum = calculateChecksum(hexData);
System.out.println("Checksum: " + Integer.toHexString(checksum & 0xFF).toUpperCase());
}
}
private static int calculateChecksum(String hexData) {
// 将空格删除并将字符串转换为字符数组
String[] hexArray = hexData.replaceAll("\\s", "").split("");
// 将十六进制字符转换为字节数组
byte[] bytes = new byte[hexArray.length / 2];
for (int i = 0; i < hexArray.length; i += 2) {
String hex = hexArray[i] + hexArray[i + 1];
bytes[i / 2] = (byte) Integer.parseInt(hex, 16);
}
// 计算校验和
int sum = 0;
for (byte b : bytes) {
sum += b;
}
// 取低位字节
return sum & 0xFF;
}
}

View File

@ -2,6 +2,8 @@ package com.couplet.msg;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author DongXiaoDong
@ -15,22 +17,53 @@ public class ParsingMsg {
}};
public static void main(String[] args) {
// 去头去尾
for (String string : msgList) {
String substring = string.substring(2, string.length() - 2);
System.out.println(substring);
System.out.println("去头去尾字符串:"+ substring);
String hexStringWithoutSpaces = substring.replaceAll("\\s+", "");
String asciiString = hexToString(hexStringWithoutSpaces);
System.out.println("16进制解析后的数据"+asciiString);
// //截取前17位
// String substring1 = asciiString.substring(0, 17);
// System.out.println("VIN"+substring1);
// String substring2 = asciiString.substring(17, 30);
// System.out.println("时间戳:"+substring2);
// String substring3 = asciiString.substring(30, 40);
// System.out.println("经度:" +substring3);
// String substring4 = asciiString.substring(41, 50);
// System.out.println("纬度:"+ substring4);
// String substring5 = asciiString.substring(51, 56);
// System.out.println("车速:"+ substring5);
// String substring6 = asciiString.substring(57, 67);
// System.out.println("总里程:"+ substring6);
// String substring7 = asciiString.substring(68, 73);
// System.out.println("总电压:"+ substring7);
String pattern = "(.{17})(.{10})(.{9})(.{8})(.{2})";
Pattern compile = Pattern.compile(pattern);
Matcher matcher = compile.matcher(asciiString);
if (matcher.find()) {
for (int i = 1; i < matcher.groupCount(); i++) {
System.out.println("Group "+ i + ":" + matcher.group(i));
}
}
}
}
// private static String decodeHexString(String hexString) {
// //将第一个和最后一个字符删除
// hexString = hexString.substring(2, hexString.length() - 2);
//
// //将十六进制字符转换为字节数组
//// byte[] bytes = new byte[hexArray.length / 2];
//// for (int i = 0; i < hexArray.length; i +=2) {
//// String hex = hexArray[i] + hexArray[i + 1];
//// bytes[i / 2] = (byte) Integer.parseInt(hex, 16);
//// }
// return new String(hexString);
// }
/**
* 16ASCII
* @param hexString 16
* @return ASCII
*/
public static String hexToString(String hexString) {
StringBuilder asciiString = new StringBuilder();
for (int i = 0; i < hexString.length(); i += 2) {
String hex = hexString.substring(i, i + 2);
int decimal = Integer.parseInt(hex, 16);
asciiString.append((char) decimal);
}
return asciiString.toString();
}
}

View File

@ -15,6 +15,7 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
@ -23,6 +24,7 @@ spring:
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
main:
allow-bean-definition-overriding: true
logging:

View File

@ -31,8 +31,8 @@ public class SysTroubleController extends BaseController {
/**
*
*/
@GetMapping("/troubleList")
public Result<PageResult<CoupletTroubleCode>> list(TroubleResp troubleReq) {
@PostMapping("/troubleList")
public Result<PageResult<CoupletTroubleCode>> list(@RequestBody TroubleResp troubleReq) {
PageResult<CoupletTroubleCode> result = troubleService.selectTroubleList(troubleReq);
return Result.success(result);
}

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: 00004c44-c962-48f0-bc9a-7e589b2881e3
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: 00004c44-c962-48f0-bc9a-7e589b2881e3
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
# 配置文件格式
file-extension: yml
# 共享配置