feat 接受报文 解析
parent
6e12122a9d
commit
3c3e4d195d
6
pom.xml
6
pom.xml
|
@ -23,6 +23,12 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
package com.muyu.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.muyu.common.Result;
|
||||
import com.muyu.domain.User;
|
||||
import com.muyu.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* com.muyu.controller 测试
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
/**
|
||||
* 构造方法注入
|
||||
*/
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
public Result login(){
|
||||
return Result.success();
|
||||
}
|
||||
@PostMapping("/info")
|
||||
public Result info(){
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/save")
|
||||
public Result save() {
|
||||
User user = new User();
|
||||
user.setId(10);
|
||||
user.setUsername("miaolinlin");
|
||||
user.setPwd("121212");
|
||||
userService.save(user);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/update")
|
||||
public Result update(Integer id) {
|
||||
User user = new User();
|
||||
user.setId(id);
|
||||
user.setPwd("1111111111");
|
||||
userService.updateById(user);
|
||||
return Result.success("{}");
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result list() {
|
||||
// 返回所有
|
||||
List<User> list = userService.list();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@GetMapping("/listByContion")
|
||||
public Result listByContion() {
|
||||
/**
|
||||
* 条件查询, 通过QueryWrapper来实现查询的条件:
|
||||
* eq: 代表相等
|
||||
* like: 模糊匹配
|
||||
* orderBy: 排序
|
||||
* in, notin
|
||||
* 大于,小于,between等
|
||||
*/
|
||||
List<User> list = userService.list(new LambdaQueryWrapper<User>()
|
||||
// 查询年龄=11的
|
||||
.eq(User::getUsername, "miao")
|
||||
// 模糊匹配
|
||||
.like(User::getPwd, "%111%")
|
||||
// 排序,按照创建时间
|
||||
.orderByDesc(User::getCreateTime)
|
||||
);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getById")
|
||||
public Result getById(Integer id) {
|
||||
User user = userService.getById(id);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/delete")
|
||||
public Result delete(Integer id) {
|
||||
userService.removeById(id);
|
||||
return Result.success("success");
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public Result page(int pageNum, int pageSize, String name) {
|
||||
IPage<User> page = new Page<>(pageNum, pageSize);
|
||||
|
||||
IPage<User> page1 = userService.page(page, new LambdaQueryWrapper<User>()
|
||||
// 主要演示这里可以加条件。在name不为空的时候执行
|
||||
.like(StringUtils.isNotEmpty(name), User::getUsername, "%" + name + "%"));
|
||||
|
||||
return Result.success(page1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package com.muyu.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表
|
||||
* </p>
|
||||
*
|
||||
* @author Leo825
|
||||
* @since 2022-07-05
|
||||
*/
|
||||
@TableName("t_user")
|
||||
public class User implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String pwd;
|
||||
|
||||
/**
|
||||
* 创建时间,MyMetaObjectHandler 配合使用,入库的时候自动填充
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 修改时间,MyMetaObjectHandler 配合使用,入库的时候自动填充
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", username=" + username +
|
||||
", pwd=" + pwd +
|
||||
", createTime=" + createTime +
|
||||
", updateTime=" + updateTime +
|
||||
"}";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.domain.User;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Leo825
|
||||
* @since 2022-07-05
|
||||
*/
|
||||
public interface UserMapper extends BaseMapper<User> {
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.mqtt;
|
||||
|
||||
import com.muyu.utils.ConversionUtil;
|
||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
|
||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 回执消息类 MessageCallbackService
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/6 15:08
|
||||
*/
|
||||
@Service
|
||||
public class MessageCallbackService implements MqttCallback {
|
||||
@Override
|
||||
public void connectionLost(Throwable cause) {
|
||||
System.out.println("connectionLost:"+cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
|
||||
System.out.println("topic:"+topic);
|
||||
System.out.println("Qos:"+mqttMessage.getQos());
|
||||
System.out.println("message content:"+new String(mqttMessage.getPayload()));
|
||||
String s = new String(mqttMessage.getPayload());
|
||||
ConversionUtil.main(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken token) {
|
||||
System.out.println("deliveryComplete---------" + token.isComplete());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.mqtt;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* mqtt配置 MqttFactory
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/6 15:10
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class MqttFactory {
|
||||
|
||||
private final MessageCallbackService messageCallbackService;
|
||||
|
||||
public MqttClient creatClient(MqttProperties mqttProperties) {
|
||||
MqttClient client =null;
|
||||
try {
|
||||
client = new MqttClient(mqttProperties.getBroker(), mqttProperties.getClientid(), new MemoryPersistence());
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
|
||||
// 连接参数
|
||||
if (mqttProperties.isLong())
|
||||
{
|
||||
options.setUserName(mqttProperties.getUsername());
|
||||
options.setPassword(mqttProperties.getPassword().toCharArray());
|
||||
}
|
||||
options.setConnectionTimeout(60);
|
||||
options.setKeepAliveInterval(60);
|
||||
client.connect(options);
|
||||
client.setCallback(messageCallbackService);
|
||||
client.subscribe(mqttProperties.getTopic(),0);
|
||||
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.muyu.mqtt;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 配置文件 MqttProperties
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/5/29 20:06
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
public class MqttProperties {
|
||||
|
||||
private String broker;
|
||||
private String topic ;
|
||||
private String username;
|
||||
private String password;
|
||||
private String clientid;
|
||||
|
||||
public static MqttProperties configBuild(String ip,String topic){
|
||||
return MqttProperties.builder()
|
||||
.broker("tcp://"+ip+":1883")
|
||||
.topic(topic)
|
||||
.clientid("protocol-parsing")
|
||||
.build();
|
||||
}
|
||||
|
||||
public boolean isLong(){
|
||||
return !StringUtils.isBlank(this.username) && !StringUtils.isBlank(this.password);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.mqtt;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 消费处理器 MsgHandler
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/6 15:15
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class MsgHandler {
|
||||
@Autowired
|
||||
private MqttFactory mqttFactory;
|
||||
@RabbitListener(queues = "ip")
|
||||
public void msg(String msg){
|
||||
log.info("接收到消息:{}",msg);
|
||||
|
||||
String[] split = msg.split(",");
|
||||
for (String s : split) {
|
||||
MqttProperties mqttProperties = MqttProperties.configBuild(
|
||||
s,
|
||||
"test1"
|
||||
);
|
||||
log.error("接收到消息初始化信息:{}",mqttProperties);
|
||||
MqttClient mqttClient = mqttFactory.creatClient(mqttProperties);
|
||||
log.error("client创建成功:{}",mqttClient.getClientId());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.mqtt;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* RabbitConfig
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/6 15:17
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitConfig {
|
||||
|
||||
@Bean
|
||||
public Queue autoDeleteQueue1() {
|
||||
return new Queue("create.topic", true);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DirectExchange directExchange() {
|
||||
return new DirectExchange("topic.direct");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding binding(DirectExchange directExchange,
|
||||
Queue autoDeleteQueue1 ) {
|
||||
return BindingBuilder.bind(autoDeleteQueue1)
|
||||
.to(directExchange)
|
||||
.with("protocol-parsing");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.rabbitmq;
|
||||
|
||||
import com.muyu.rabbitmq.confilg.RabbitmqConfig;
|
||||
import com.rabbitmq.client.impl.AMQImpl;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* 监听车辆上线的信息 SubscriptionHandler
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/6/6 14:24
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class SubscriptionHandler {
|
||||
|
||||
@RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_EMAIL})
|
||||
public void receive_email(Object msg, Message message, AMQImpl.Channel channel){
|
||||
System.out.println("QUEUE_INFORM_EMAIL msg"+msg);
|
||||
}
|
||||
//监听sms队列
|
||||
@RabbitListener(queues = "subscription")
|
||||
public void receiveSms(Message message) {
|
||||
try {
|
||||
log.info("消费者得到的消息: {}" , new String(message.getBody()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.rabbitmq.confilg;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
/**
|
||||
* rabbitMQ配置 RabbitmqConfig
|
||||
*
|
||||
* @author Yangle
|
||||
* Date 2024/5/28 21:42
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitmqConfig {
|
||||
public static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
|
||||
public static final String QUEUE_INFORM_SMS = "disconnect_connect";
|
||||
public static final String EXCHANGE_TOPICS_INFORM="exchange_topics_inform";
|
||||
public static final String ROUTINGKEY_EMAIL="inform.#.email.#";
|
||||
public static final String ROUTINGKEY_SMS="inform.#.sms.#";
|
||||
|
||||
|
||||
@Bean(EXCHANGE_TOPICS_INFORM)
|
||||
public Exchange EXCHANGE_TOPICS_INFORM(){
|
||||
//durable(true) 持久化,mq重启之后交换机还在
|
||||
return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
|
||||
}
|
||||
|
||||
//声明QUEUE_INFORM_EMAIL队列
|
||||
@Bean(QUEUE_INFORM_EMAIL)
|
||||
public Queue QUEUE_INFORM_EMAIL(){
|
||||
return new Queue(QUEUE_INFORM_EMAIL);
|
||||
}
|
||||
//声明QUEUE_INFORM_SMS队列
|
||||
@Bean(QUEUE_INFORM_SMS)
|
||||
public Queue QUEUE_INFORM_SMS(){
|
||||
return new Queue(QUEUE_INFORM_SMS);
|
||||
}
|
||||
|
||||
//ROUTINGKEY_EMAIL队列绑定交换机,指定routingKey
|
||||
@Bean
|
||||
public Binding BINDING_QUEUE_INFORM_EMAIL(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue,
|
||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){
|
||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
|
||||
}
|
||||
//ROUTINGKEY_SMS队列绑定交换机,指定routingKey
|
||||
@Bean
|
||||
public Binding BINDING_ROUTINGKEY_SMS(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
|
||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){
|
||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.User;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author Leo825
|
||||
* @since 2022-07-05
|
||||
*/
|
||||
public interface UserService extends IService<User> {
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.domain.User;
|
||||
import com.muyu.mapper.UserMapper;
|
||||
import com.muyu.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author Leo825
|
||||
* @since 2022-07-05
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package com.muyu.utils;
|
||||
|
||||
import com.muyu.vehicle.model.VehicleData;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -24,7 +23,7 @@ public class ConversionUtil {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main (String[] args) {
|
||||
public static void main (String args) {
|
||||
// String str = "<?xml version=\"1.0\"?>\n" +
|
||||
// "<monitorRoot type=\"param\"><synchronizeSyptom event=\"0\" initial=\"true\"><Action_ECG><Rhythm>Sinus</Rhythm><HR>80</HR><EMD>No Change</EMD><Conduct>0</Conduct></Action_ECG><Action_Osat value=\"94\" isRelativePercent=\"false\"/><Action_BP isRelativePercent=\"false\"><Shrink value=\"120\"/><Stretch value=\"80\"/></Action_BP><Action_Resp breathType=\"Normal\" value=\"14\" isRelativePercent=\"false\"/><Action_etCO2 value=\"34\" isRelativePercent=\"false\"/><Action_Temperature value=\"35.2\"/><Action_CVP value=\"6.0\"/><Action_PAPDia value=\"10\"/><Action_PAPSys value=\"25\"/><Action_WP value=\"9\"/></synchronizeSyptom></monitorRoot>";
|
||||
// String strToSixteen = strToSixteen(str);
|
||||
|
@ -32,10 +31,11 @@ public class ConversionUtil {
|
|||
// System.out.println(str.length());
|
||||
// System.out.println(strToSixteen);
|
||||
// System.out.println(strToSixteen.replace(" ", "").length());
|
||||
|
||||
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());
|
||||
String hexStringToString = hexStringToString(args);
|
||||
System.out.println(args);
|
||||
System.out.println(args.length());
|
||||
System.out.println(hexStringToString);
|
||||
System.out.println(hexStringToString.length());
|
||||
//截取第一位和最后两位
|
||||
|
|
|
@ -0,0 +1,484 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author 牧鱼
|
||||
* @Classname VehicleData
|
||||
* @Description 车辆模拟数据对象
|
||||
* @Date 2021/8/5
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleData {
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
private String vin;
|
||||
/**
|
||||
* 行驶路线
|
||||
*/
|
||||
private String drivingRoute;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
|
||||
/**
|
||||
* 维度
|
||||
*/
|
||||
private String latitude;
|
||||
|
||||
/**
|
||||
* 速度
|
||||
*/
|
||||
private String speed;
|
||||
|
||||
/**
|
||||
* 里程
|
||||
*/
|
||||
private String mileage;
|
||||
|
||||
/**
|
||||
* 总电压
|
||||
*/
|
||||
private String voltage;
|
||||
|
||||
/**
|
||||
* 总电流
|
||||
*/
|
||||
private String current;
|
||||
|
||||
/**
|
||||
* 绝缘电阻
|
||||
*/
|
||||
private String resistance;
|
||||
|
||||
/**
|
||||
* 档位
|
||||
*/
|
||||
private String gear;
|
||||
|
||||
/**
|
||||
* 加速踏板行程值
|
||||
*/
|
||||
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 String remainingBattery;
|
||||
|
||||
/**
|
||||
* 当前状态允许的最大反馈功率
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 充电状态
|
||||
*/
|
||||
private int chargingStatus;
|
||||
|
||||
/**
|
||||
* 运行状态
|
||||
*/
|
||||
private int operatingStatus;
|
||||
|
||||
/**
|
||||
* SOC
|
||||
*/
|
||||
private int socStatus;
|
||||
|
||||
/**
|
||||
* 可充电储能装置工作状态
|
||||
*/
|
||||
private int chargingEnergyStorageStatus;
|
||||
|
||||
/**
|
||||
* 驱动电机状态
|
||||
*/
|
||||
private int driveMotorStatus;
|
||||
|
||||
/**
|
||||
* 定位是否有效
|
||||
*/
|
||||
private int positionStatus;
|
||||
|
||||
/**
|
||||
* EAS(汽车防盗系统)状态
|
||||
*/
|
||||
private int easStatus;
|
||||
|
||||
/**
|
||||
* PTC(电动加热器)状态
|
||||
*/
|
||||
private int ptcStatus;
|
||||
|
||||
/**
|
||||
* EPS(电动助力系统)状态
|
||||
*/
|
||||
private int epsStatus;
|
||||
|
||||
/**
|
||||
* ABS(防抱死)状态
|
||||
*/
|
||||
private int absStatus;
|
||||
|
||||
/**
|
||||
* MCU(电机/逆变器)状态
|
||||
*/
|
||||
private int mcuStatus;
|
||||
|
||||
/**
|
||||
* 动力电池加热状态
|
||||
*/
|
||||
private int heatingStatus;
|
||||
|
||||
/**
|
||||
* 动力电池当前状态
|
||||
*/
|
||||
private int batteryStatus;
|
||||
|
||||
/**
|
||||
* 动力电池保温状态
|
||||
*/
|
||||
private int batteryInsulationStatus;
|
||||
|
||||
/**
|
||||
* DCDC(电力交换系统)状态
|
||||
*/
|
||||
private int dcdcStatus;
|
||||
|
||||
/**
|
||||
* CHG(充电机)状态
|
||||
*/
|
||||
private int chgStatus;
|
||||
|
||||
/**
|
||||
* 车辆状态 报文
|
||||
*/
|
||||
private String vehicleStatusMsg;
|
||||
/**
|
||||
* 智能硬件 报文
|
||||
*/
|
||||
private String smartHardwareMsg;
|
||||
/**
|
||||
* 电池报文
|
||||
*/
|
||||
private String batteryMsg;
|
||||
|
||||
public String getMsg(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
//第一位VIN
|
||||
sb.append(vin);
|
||||
//第二位经度 longitude latitude
|
||||
sb.append(getValue(longitude ,11));
|
||||
//第三位维度 longitude latitude
|
||||
sb.append(getValue(latitude ,10));
|
||||
//车速
|
||||
sb.append(getValue(speed,6));
|
||||
//总里程
|
||||
sb.append(getValue(mileage,11));
|
||||
// 总电压
|
||||
sb.append(getValue(voltage,6));
|
||||
//总电流
|
||||
sb.append(getValue(current,5));
|
||||
//绝缘电阻 79 - 87
|
||||
sb.append(getValue(resistance,9));
|
||||
//档位
|
||||
sb.append(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,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();
|
||||
}
|
||||
|
||||
public String getValue(String val , int valLength){
|
||||
int length = val.length();
|
||||
if (length > valLength){
|
||||
return val.substring( 0 , valLength);
|
||||
}
|
||||
val = val + "0".repeat(valLength - length);
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
VIN
|
||||
vin;
|
||||
行驶路线
|
||||
drivingRoute;
|
||||
经度
|
||||
longitude;
|
||||
维度
|
||||
latitude;
|
||||
速度
|
||||
speed;
|
||||
里程
|
||||
mileage;
|
||||
总电压
|
||||
voltage;
|
||||
总电流
|
||||
current;
|
||||
绝缘电阻
|
||||
resistance;
|
||||
档位
|
||||
gear;
|
||||
加速踏板行程值
|
||||
accelerationPedal;
|
||||
制动踏板行程值
|
||||
brakePedal;
|
||||
燃料消耗率
|
||||
fuelConsumptionRate;
|
||||
*/
|
||||
|
||||
/**
|
||||
电机控制器温度
|
||||
motorControllerTemperature;
|
||||
电机转速
|
||||
motorSpeed;
|
||||
电机转矩
|
||||
motorTorque;
|
||||
电机温度
|
||||
motorTemperature;
|
||||
电机电压
|
||||
motorVoltage;
|
||||
电机电流
|
||||
motorCurrent;
|
||||
*/
|
||||
|
||||
/**
|
||||
动力电池剩余电量SOC
|
||||
remainingBattery;
|
||||
当前状态允许的最大反馈功率
|
||||
maximumFeedbackPower;
|
||||
当前状态允许最大放电功率
|
||||
maximumDischargePower;
|
||||
BMS自检计数器
|
||||
selfCheckCounter;
|
||||
动力电池充放电电流
|
||||
totalBatteryCurrent;
|
||||
动力电池负载端总电压V3
|
||||
totalBatteryVoltage;
|
||||
单次最大电压
|
||||
singleBatteryMaxVoltage;
|
||||
单体电池最低电压
|
||||
singleBatteryMinVoltage;
|
||||
单体电池最高温度
|
||||
singleBatteryMaxTemperature;
|
||||
单体电池最低温度
|
||||
singleBatteryMinTemperature;
|
||||
动力电池可用容量
|
||||
availableBatteryCapacity;
|
||||
*/
|
||||
|
||||
/**
|
||||
车辆状态
|
||||
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;
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.muyu.vehicle.core;
|
||||
|
||||
/**
|
||||
* @author DongZeLiang
|
||||
* @version 1.0
|
||||
* @description 配置
|
||||
* @date 2023/11/9
|
||||
*/
|
||||
public class Config {
|
||||
}
|
|
@ -43,5 +43,6 @@ public class MqttProperties {
|
|||
* 节点ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
private int qos = 0;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ spring:
|
|||
host: 115.159.211.196
|
||||
port: 6379
|
||||
password: yl030509
|
||||
rabbitmq:
|
||||
host: 115.159.211.196
|
||||
port: 5672
|
||||
datasource:
|
||||
username: muyu
|
||||
password: 123456
|
||||
|
|
Loading…
Reference in New Issue