fix():增添协议解析的YML #10
|
@ -30,16 +30,15 @@ public class MqttConsumerConfig {
|
||||||
String content = "Message from MqttPublishSample";
|
String content = "Message from MqttPublishSample";
|
||||||
int qos = 2;
|
int qos = 2;
|
||||||
String broker = "tcp://123.57.152.124:1883";
|
String broker = "tcp://123.57.152.124:1883";
|
||||||
String clientId = "xyr1";
|
String clientId = "xyr123456789";
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public String connect() {
|
public void connect() {
|
||||||
final String vin= "";
|
|
||||||
try {
|
try {
|
||||||
MqttClient sampleClient = new MqttClient(broker, clientId, new MemoryPersistence());
|
MqttClient sampleClient = new MqttClient(broker, clientId, new MemoryPersistence());
|
||||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
//是否清空session
|
//是否清空session
|
||||||
connOpts.setCleanSession(true);
|
connOpts.setCleanSession(false);
|
||||||
System.out.println("Connecting to broker: " + broker);
|
System.out.println("Connecting to broker: " + broker);
|
||||||
//连接
|
//连接
|
||||||
sampleClient.connect(connOpts);
|
sampleClient.connect(connOpts);
|
||||||
|
@ -75,6 +74,6 @@ public class MqttConsumerConfig {
|
||||||
me.printStackTrace();
|
me.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return vin;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ProcessData {
|
||||||
|
|
||||||
public static JSONObject DataConversion(String jsonVin ) {
|
public static JSONObject DataConversion(String jsonVin ) {
|
||||||
String vin = DataParseUtil.dataParsing(jsonVin);
|
String vin = DataParseUtil.dataParsing(jsonVin);
|
||||||
|
System.out.println("车辆转换的vin是:"+vin);
|
||||||
Result<Long> byTemplateId = remoteMessageValueService.findByTemplateId(vin);
|
Result<Long> byTemplateId = remoteMessageValueService.findByTemplateId(vin);
|
||||||
|
|
||||||
Long templateId = byTemplateId.getData();
|
Long templateId = byTemplateId.getData();
|
||||||
|
|
|
@ -1,32 +1,35 @@
|
||||||
package com.muyu.parse.uitl;
|
package com.muyu.parse.uitl;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @Author xie ya ru
|
* @Author xie ya ru
|
||||||
* @Date 2024/9/28 16:48
|
* @Date 2024/9/28 16:48
|
||||||
* @注释
|
* @注释
|
||||||
*/
|
*/
|
||||||
|
@Log4j2
|
||||||
public class DataParseUtil {
|
public class DataParseUtil {
|
||||||
public static final Integer STARTPOSITION = 0;
|
public static final Integer STARTPOSITION = 1;
|
||||||
|
|
||||||
public static final Integer ENDPOSITION = 18;
|
public static final Integer ENDPOSITION = 18;
|
||||||
|
|
||||||
public static final Integer INDEX = 16;
|
public static final Integer INDEX = 16;
|
||||||
public static String dataParsing(String jsonVin){
|
public static String dataParsing(String jsonVin){
|
||||||
jsonVin = jsonVin.substring(STARTPOSITION,ENDPOSITION);
|
|
||||||
StringBuilder asciiString = new StringBuilder();
|
//根据空格切割数据
|
||||||
String[] split = jsonVin.split(" ");
|
String[] hexArray = jsonVin.split(" ");
|
||||||
for (int i = 0; i < split.length; i++) {
|
StringBuilder result = new StringBuilder();
|
||||||
//十六进制转换为十进制
|
//遍历十六进制数据转换为字符
|
||||||
int decimal = Integer.parseInt(split[i],INDEX);
|
for (String hex : hexArray) {
|
||||||
//将十进制整数转换为字符
|
int decimal = Integer.parseInt(hex, INDEX);
|
||||||
char character =(char)decimal;
|
result.append((char) decimal);
|
||||||
//添加字符到ASCII 字符串
|
|
||||||
asciiString.append(character);
|
|
||||||
}
|
}
|
||||||
System.out.println(asciiString.toString());
|
//取出车辆VIN码
|
||||||
return asciiString.toString();
|
String vehicleVin = result.substring(STARTPOSITION, ENDPOSITION);
|
||||||
|
log.info("车辆VIN码: " + vehicleVin);
|
||||||
|
return vehicleVin;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9705
|
||||||
|
|
||||||
|
# nacos线上地址
|
||||||
|
nacos:
|
||||||
|
addr: 123.57.152.124:8848
|
||||||
|
user-name: nacos
|
||||||
|
password: nacos
|
||||||
|
namespace: xyr
|
||||||
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
amqp:
|
||||||
|
deserialization:
|
||||||
|
trust:
|
||||||
|
all: true
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: cloud-parse
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: ${nacos.addr}
|
||||||
|
# nacos用户名
|
||||||
|
username: ${nacos.user-name}
|
||||||
|
# nacos密码
|
||||||
|
password: ${nacos.password}
|
||||||
|
# 命名空间
|
||||||
|
namespace: ${nacos.namespace}
|
||||||
|
config:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: ${nacos.addr}
|
||||||
|
# nacos用户名
|
||||||
|
username: ${nacos.user-name}
|
||||||
|
# nacos密码
|
||||||
|
password: ${nacos.password}
|
||||||
|
# 命名空间
|
||||||
|
namespace: ${nacos.namespace}
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
# 系统共享配置
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# 系统环境Config共享配置
|
||||||
|
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# # xxl-job 配置文件
|
||||||
|
# - application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.muyu.system.mapper: DEBUG
|
|
@ -1,6 +1,6 @@
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
#server:
|
||||||
port: 9703
|
# port: 9703
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
|
|
Loading…
Reference in New Issue