feat():报文解析完毕,存入自定义车辆信息对象,下一步->存入kafka--topic--分区
parent
492d7c0453
commit
92f486ebb0
|
@ -0,0 +1,14 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="AliAccessStaticViaInstance" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliDeprecation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliEqualsAvoidNull" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliMissingOverrideAnnotation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AliWrapperTypeEquality" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
|
@ -0,0 +1,124 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
15
pom.xml
15
pom.xml
|
@ -79,8 +79,6 @@
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- excel工具 -->
|
<!-- excel工具 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
|
@ -88,6 +86,19 @@
|
||||||
<version>4.1.2</version>
|
<version>4.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.dtflys.forest</groupId>
|
||||||
|
<artifactId>forest-spring-boot-starter</artifactId>
|
||||||
|
<version>1.5.36</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.46</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
/**
|
/**
|
||||||
* @ClassName MqttApplication
|
* @ClassName MqttApplication
|
||||||
* @Description 描述
|
* @Description 描述
|
||||||
* @Author SaiSai.Liu
|
* @Author Mobai
|
||||||
* @Date 2024/5/31 14:33
|
* @Date 2024/5/31 14:33
|
||||||
*/
|
*/
|
||||||
@Log
|
@Log
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.mobai;
|
||||||
|
|
||||||
|
import com.mobai.domian.MqttServerModel;
|
||||||
|
import com.mobai.domian.Result;
|
||||||
|
import com.mobai.remote.MyClient;
|
||||||
|
import com.mobai.util.ConnectMqtt;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName MqttRunner
|
||||||
|
* @Description 描述
|
||||||
|
* @Author Mobai
|
||||||
|
* @Date 2024/6/5 19:09
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MqttRunner implements ApplicationRunner {
|
||||||
|
@Autowired
|
||||||
|
private MyClient myClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConnectMqtt conn;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
// 获取初始服务器配置 IP + topic
|
||||||
|
Result<List<MqttServerModel>> ips = myClient.getIps();
|
||||||
|
if (ips.getData()==null){
|
||||||
|
throw new ServletException("获取初始节点信息失败");
|
||||||
|
}
|
||||||
|
System.out.println(ips);
|
||||||
|
List<MqttServerModel> mqttServerModels = ips.getData();
|
||||||
|
mqttServerModels.forEach(mqttServerModel -> {
|
||||||
|
try {
|
||||||
|
// 监控队列消息
|
||||||
|
conn.connectMq(mqttServerModel);
|
||||||
|
} catch (ServletException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,33 +1,22 @@
|
||||||
package com.mobai.api;
|
package com.mobai.api;
|
||||||
|
|
||||||
import com.mobai.domian.GetOptions;
|
import com.mobai.domian.MqttServerModel;
|
||||||
import com.mobai.domian.MqttCallBackServiceImpl;
|
import com.mobai.util.ConnectMqtt;
|
||||||
import com.mobai.cofig.MqttFactory;
|
|
||||||
import com.mobai.cofig.MqttProperties;
|
import javax.servlet.ServletException;
|
||||||
import org.eclipse.paho.client.mqttv3.*;
|
|
||||||
|
|
||||||
public class SubscribeSample {
|
public class SubscribeSample {
|
||||||
public static void main(String[] args) {
|
|
||||||
MqttProperties mqttProperties = MqttProperties.configBuild("39.98.69.92", "topic0");
|
|
||||||
// MqttProperties mqttProperties = new MqttProperties();
|
|
||||||
// mqttProperties.setBroker("tcp://39.98.69.92:1883");
|
|
||||||
// mqttProperties.setTopic("mqtt/test");
|
|
||||||
mqttProperties.setUsername("emqx");
|
|
||||||
mqttProperties.setPassword("public");
|
|
||||||
// mqttProperties.setClientid("subscribe_client");
|
|
||||||
|
|
||||||
int qos = 0;
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ConnectMqtt mqtt = new ConnectMqtt();
|
||||||
try {
|
try {
|
||||||
MqttClient client = new MqttFactory(new MqttCallBackServiceImpl()).buildOptions(mqttProperties);
|
mqtt.connectMq(new MqttServerModel() {{
|
||||||
// 连接参数
|
setBroker("39.98.69.92");
|
||||||
MqttConnectOptions options = GetOptions.getMqttOptions(mqttProperties);
|
setTopic("topic0");
|
||||||
// 设置回调
|
}});
|
||||||
client.setCallback(new MqttCallBackServiceImpl());
|
} catch (ServletException e) {
|
||||||
// 进行连接
|
throw new RuntimeException(e);
|
||||||
client.connect(options);
|
|
||||||
client.subscribe(mqttProperties.getTopic(), qos);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
||||||
/**
|
/**
|
||||||
* @ClassName MqttFactory
|
* @ClassName MqttFactory
|
||||||
* @Description 描述
|
* @Description 描述
|
||||||
* @Author SaiSai.Liu
|
* @Author Mobai
|
||||||
* @Date 2024/5/31 11:35
|
* @Date 2024/5/31 11:35
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ public class MqttFactory {
|
||||||
mqttProperties.getBroker(),
|
mqttProperties.getBroker(),
|
||||||
mqttProperties.getClientid(),
|
mqttProperties.getClientid(),
|
||||||
new MemoryPersistence());
|
new MemoryPersistence());
|
||||||
MqttConnectOptions optionas = GetOptions.getMqttOptions(mqttProperties);
|
MqttConnectOptions options = GetOptions.getMqttOptions(mqttProperties);
|
||||||
client.connect(optionas);
|
client.connect(options);
|
||||||
client.setCallback(mqttCallBackService);
|
client.setCallback(mqttCallBackService);
|
||||||
|
|
||||||
client.subscribe(mqttProperties.getTopic(), 0);
|
client.subscribe(mqttProperties.getTopic(), 0);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
||||||
/**
|
/**
|
||||||
* @ClassName MqttProperties
|
* @ClassName MqttProperties
|
||||||
* @Description 描述
|
* @Description 描述
|
||||||
* @Author SaiSai.Liu
|
* @Author Mobai
|
||||||
* @Date 2024/5/30 20:05
|
* @Date 2024/5/30 20:05
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
/**
|
/**
|
||||||
* @ClassName RabbitConfig
|
* @ClassName RabbitConfig
|
||||||
* @Description 描述
|
* @Description 描述
|
||||||
* @Author SaiSai.Liu
|
* @Author Mobai
|
||||||
* @Date 2024/5/31 21:47
|
* @Date 2024/5/31 21:47
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||||
* 获取Mqtt连接参数
|
* 获取Mqtt连接参数
|
||||||
* @ClassName GetOptions
|
* @ClassName GetOptions
|
||||||
* @Description 获取Mqtt连接参数
|
* @Description 获取Mqtt连接参数
|
||||||
* @Author SaiSai.Liu
|
* @Author Mobai
|
||||||
* @Date 2024/5/31 14:26
|
* @Date 2024/5/31 14:26
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.mobai.domian;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回状态码
|
||||||
|
*
|
||||||
|
* @author Mobai
|
||||||
|
*/
|
||||||
|
public class HttpStatus {
|
||||||
|
/**
|
||||||
|
* 操作成功
|
||||||
|
*/
|
||||||
|
public static final int SUCCESS = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象创建成功
|
||||||
|
*/
|
||||||
|
public static final int CREATED = 201;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求已经被接受
|
||||||
|
*/
|
||||||
|
public static final int ACCEPTED = 202;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作已经执行成功,但是没有返回数据
|
||||||
|
*/
|
||||||
|
public static final int NO_CONTENT = 204;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源已被移除
|
||||||
|
*/
|
||||||
|
public static final int MOVED_PERM = 301;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重定向
|
||||||
|
*/
|
||||||
|
public static final int SEE_OTHER = 303;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源没有被修改
|
||||||
|
*/
|
||||||
|
public static final int NOT_MODIFIED = 304;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数列表错误(缺少,格式不匹配)
|
||||||
|
*/
|
||||||
|
public static final int BAD_REQUEST = 400;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未授权
|
||||||
|
*/
|
||||||
|
public static final int UNAUTHORIZED = 401;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 访问受限,授权过期
|
||||||
|
*/
|
||||||
|
public static final int FORBIDDEN = 403;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源,服务未找到
|
||||||
|
*/
|
||||||
|
public static final int NOT_FOUND = 404;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许的http方法
|
||||||
|
*/
|
||||||
|
public static final int BAD_METHOD = 405;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源冲突,或者资源被锁
|
||||||
|
*/
|
||||||
|
public static final int CONFLICT = 409;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不支持的数据,媒体类型
|
||||||
|
*/
|
||||||
|
public static final int UNSUPPORTED_TYPE = 415;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统内部错误
|
||||||
|
*/
|
||||||
|
public static final int ERROR = 500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口未实现
|
||||||
|
*/
|
||||||
|
public static final int NOT_IMPLEMENTED = 501;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统警告消息
|
||||||
|
*/
|
||||||
|
public static final int WARN = 601;
|
||||||
|
}
|
|
@ -5,11 +5,15 @@ import org.eclipse.paho.client.mqttv3.MqttCallback;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import static com.mobai.util.ConversionUtil.hexStringToString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回执消息类
|
* 回执消息类
|
||||||
* @ClassName MqttCallBackServiceImpl
|
* @ClassName MqttCallBackServiceImpl
|
||||||
* @Description 回执消息类
|
* @Description 回执消息类
|
||||||
* @Author SaiSai.Liu
|
* @Author Mobai
|
||||||
* @Date 2024/5/30 20:02
|
* @Date 2024/5/30 20:02
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@ -19,11 +23,166 @@ public class MqttCallBackServiceImpl implements MqttCallback {
|
||||||
System.out.println("connectionLost: " + cause.getMessage());
|
System.out.println("connectionLost: " + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取报文 并 处理
|
||||||
@Override
|
@Override
|
||||||
public void messageArrived(String topic, MqttMessage message) {
|
public void messageArrived(String topic, MqttMessage message) {
|
||||||
System.out.println("topic: " + topic);
|
System.out.println("topic: " + topic);
|
||||||
System.out.println("Qos: " + message.getQos());
|
System.out.println("Qos: " + message.getQos());
|
||||||
System.out.println("message content: " + new String(message.getPayload()));
|
System.out.println("message content: " + new String(message.getPayload()));
|
||||||
|
|
||||||
|
String hexStr = "7E 56 49 4e 31 32 33 34 35 36 37 38 39 44 49 4a 45 34 31 37 31 37 35 39 31 33 35 33 30 37 34 31 31 36 2e 37 32 31 34 31 37 30 33 39 2e 35 32 38 37 34 33 30 33 36 2e 30 30 30 32 36 2e 36 32 36 30 30 30 30 30 32 36 32 30 30 30 32 38 30 30 30 32 36 39 31 30 30 30 30 30 44 34 30 38 30 31 31 2e 32 30 37 30 30 30 30 30 37 36 32 32 32 35 37 37 30 31 33 39 30 30 30 31 35 31 30 30 31 33 37 38 35 30 30 30 34 34 37 37 30 2e 31 34 30 30 30 30 37 39 30 30 30 30 30 30 35 30 30 30 30 35 39 36 30 30 30 33 30 30 30 34 30 30 30 35 30 30 30 30 30 32 35 30 30 30 30 32 30 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 26 7E";
|
||||||
|
// 报文
|
||||||
|
String str = hexStringToString(hexStr);
|
||||||
|
System.out.println(hexStr);
|
||||||
|
System.out.println(hexStr.length());
|
||||||
|
System.out.println(str);
|
||||||
|
System.out.println(str.length());
|
||||||
|
String trainMsg = str.substring(1, str.length() - 2);
|
||||||
|
// 解析报文具体数据
|
||||||
|
String vin = trainMsg.substring(0, 17); // 车辆vin
|
||||||
|
String timestamp = trainMsg.substring(17, 30); // 时间戳
|
||||||
|
String longitude = trainMsg.substring(30, 41); // 经度
|
||||||
|
String latitude = trainMsg.substring(41, 51); // 纬度
|
||||||
|
String speed = trainMsg.substring(51, 57); // 速度
|
||||||
|
// String mileage = trainMsg.substring(57, 68); // 总里程
|
||||||
|
BigDecimal mileage = new BigDecimal(trainMsg.substring(57, 68));
|
||||||
|
// System.out.println("转换值"+mileage);
|
||||||
|
String voltage = trainMsg.substring(68, 74); // 总电压
|
||||||
|
String current = trainMsg.substring(74, 79); // 总电流
|
||||||
|
String resistance = trainMsg.substring(79, 88); // 绝缘电阻
|
||||||
|
String gear = trainMsg.substring(88, 89); // 档位
|
||||||
|
String accelerationPedal = trainMsg.substring(89, 91); // 加速踏板行程值
|
||||||
|
String brakePedal = trainMsg.substring(91, 93); // 制动踏板行程值
|
||||||
|
String fuelConsumptionRate = trainMsg.substring(93, 98); // 燃料消耗率
|
||||||
|
String motorControllerTemperature = trainMsg.substring(98, 104); // 电机控制器温度
|
||||||
|
String motorSpeed = trainMsg.substring(104, 109); // 电机转速
|
||||||
|
String motoTorque = trainMsg.substring(109, 113); //电机转矩
|
||||||
|
String motorTemperature = trainMsg.substring(113, 119); // 电机温度
|
||||||
|
String motorVoltage = trainMsg.substring(119, 124); // 电机电压
|
||||||
|
String motorCurrent = trainMsg.substring(124, 132); // 电机电流
|
||||||
|
BigDecimal remainingBattery = new BigDecimal(trainMsg.substring(132, 138)); // 动力电池剩余电量SOC
|
||||||
|
BigDecimal maximumFeedbackPower = new BigDecimal(trainMsg.substring(138, 144)); // 当前状态允许的最大反馈功率
|
||||||
|
String maximumDischargePower = trainMsg.substring(144, 150); // 当前状态允许的最大放电功率
|
||||||
|
String selfCheckCounter = trainMsg.substring(150, 152); // BMS自检计数器
|
||||||
|
String totalBatteryCurrent = trainMsg.substring(152, 157); // 动力电池充放电电流
|
||||||
|
String totalBatteryVoltage = trainMsg.substring(157, 163); // 动力电池负载端总电压V3
|
||||||
|
String singleBatteryMaxVoltage = trainMsg.substring(163, 167); // 单次最大电压
|
||||||
|
String singleBatteryMinVoltage = trainMsg.substring(167, 171); // 单次最低电压
|
||||||
|
String singleBatteryMaxTemperature = trainMsg.substring(171, 177); // 单体电池最高温度
|
||||||
|
String singleBatteryMinTemperature = trainMsg.substring(177, 183); // 单体电池最低温度
|
||||||
|
String availableBatteryCapacity = trainMsg.substring(183, 189); // 动力电池可用容量
|
||||||
|
Integer vehicleStatus = Integer.valueOf(trainMsg.substring(189, 190)); // 车辆状态
|
||||||
|
Integer chargingStatus = Integer.valueOf(trainMsg.substring(190, 191)); // 充电状态
|
||||||
|
Integer operatingStatus = Integer.valueOf(trainMsg.substring(191, 192)); // 运行状态
|
||||||
|
Integer chargingEnergyStorageStatus = Integer.valueOf(trainMsg.substring(192, 193)); // SOC
|
||||||
|
Integer driveMotorStatus = Integer.valueOf(trainMsg.substring(193, 194)); // 可充电储能装置工作状态
|
||||||
|
Integer positionStatus = Integer.valueOf(trainMsg.substring(194, 195)); // 定位是否有效
|
||||||
|
Integer easStatus = Integer.valueOf(trainMsg.substring(195, 196)); // EAS(汽车防盗系统)状态
|
||||||
|
Integer ptcStatus = Integer.valueOf(trainMsg.substring(196, 197)); // PTC(主动安全系统)状态
|
||||||
|
Integer epsStatus = Integer.valueOf(trainMsg.substring(197, 198)); // EPS(电动助力系统)状态
|
||||||
|
Integer absStatus = Integer.valueOf(trainMsg.substring(198, 199)); // ABS(防抱死)状态
|
||||||
|
Integer mcuStatus = Integer.valueOf(trainMsg.substring(199, 200)); // MCU(电机/逆变器)状态
|
||||||
|
Integer heatingStatus = Integer.valueOf(trainMsg.substring(200, 201)); // 动力电池加热状态
|
||||||
|
Integer batteryStatus = Integer.valueOf(trainMsg.substring(201, 202)); // 动力电池当前状态
|
||||||
|
Integer batteryInsulationStatus = Integer.valueOf(trainMsg.substring(202, 203)); // 动力电池保温状态
|
||||||
|
Integer dcdcStatus = Integer.valueOf(trainMsg.substring(203, 204)); // DCDC(电力交换系统)状态
|
||||||
|
Integer chgStatus = Integer.valueOf(trainMsg.substring(204, 205)); // CHG(充电机)状态
|
||||||
|
|
||||||
|
Vehicle vehicle = new Vehicle(vin,
|
||||||
|
timestamp,
|
||||||
|
longitude,
|
||||||
|
latitude,
|
||||||
|
speed,
|
||||||
|
mileage,
|
||||||
|
voltage,
|
||||||
|
current,
|
||||||
|
resistance,
|
||||||
|
gear,
|
||||||
|
accelerationPedal,
|
||||||
|
brakePedal,
|
||||||
|
fuelConsumptionRate,
|
||||||
|
motorControllerTemperature,
|
||||||
|
motorSpeed,
|
||||||
|
motoTorque,
|
||||||
|
motorTemperature,
|
||||||
|
motorVoltage,
|
||||||
|
motorCurrent,
|
||||||
|
remainingBattery,
|
||||||
|
maximumFeedbackPower,
|
||||||
|
maximumDischargePower,
|
||||||
|
selfCheckCounter,
|
||||||
|
totalBatteryCurrent,
|
||||||
|
totalBatteryVoltage,
|
||||||
|
singleBatteryMaxVoltage,
|
||||||
|
singleBatteryMinVoltage,
|
||||||
|
singleBatteryMaxTemperature,
|
||||||
|
singleBatteryMinTemperature,
|
||||||
|
availableBatteryCapacity,
|
||||||
|
vehicleStatus,
|
||||||
|
chargingStatus,
|
||||||
|
operatingStatus,
|
||||||
|
chargingEnergyStorageStatus,
|
||||||
|
driveMotorStatus,
|
||||||
|
positionStatus,
|
||||||
|
easStatus,
|
||||||
|
ptcStatus,
|
||||||
|
epsStatus,
|
||||||
|
absStatus,
|
||||||
|
mcuStatus,
|
||||||
|
heatingStatus,
|
||||||
|
batteryStatus,
|
||||||
|
batteryInsulationStatus,
|
||||||
|
dcdcStatus,
|
||||||
|
chgStatus);
|
||||||
|
System.out.println(
|
||||||
|
"车辆vin:" + vin + "\n\t" +
|
||||||
|
"时间戳:" + timestamp + "\n\t" +
|
||||||
|
"经度:" + longitude + "\n\t" +
|
||||||
|
"纬度:" + latitude + "\n\t" +
|
||||||
|
"速度:" + speed + "\n\t" +
|
||||||
|
"总里程:" + mileage + "\n\t" +
|
||||||
|
"总电压:" + voltage + "\n\t" +
|
||||||
|
"总电流:" + current + "\n\t" +
|
||||||
|
"绝缘电阻:" + resistance + "\n\t" +
|
||||||
|
"档位:" + gear + "\n\t" +
|
||||||
|
"加速踏板行程值:" + accelerationPedal + "\n\t" +
|
||||||
|
"制动踏板行程值:" + brakePedal + "\n\t" +
|
||||||
|
"燃料消耗率:" + fuelConsumptionRate + "\n\t" +
|
||||||
|
"电机控制器温度:" + motorControllerTemperature + "\n\t" +
|
||||||
|
"电机转速:" + motorSpeed + "\n\t" +
|
||||||
|
"电机转矩:" + motoTorque + "\n\t" +
|
||||||
|
"电机温度:" + motorTemperature + "\n\t" +
|
||||||
|
"电机电压:" + motorVoltage + "\n\t" +
|
||||||
|
"电机电流:" + motorCurrent + "\n\t" +
|
||||||
|
"动力电池剩余电量SOC:" + remainingBattery + "\n\t" +
|
||||||
|
"当前状态允许的最大反馈功率:" + maximumFeedbackPower + "\n\t" +
|
||||||
|
"当前状态允许的最大放电功率:" + maximumDischargePower + "\n\t" +
|
||||||
|
"BMS自检计数器:" + totalBatteryCurrent + "\n\t" +
|
||||||
|
"动力电池充放电电流:" + selfCheckCounter + "\n\t" +
|
||||||
|
"动力电池负载端总电压V3:" + totalBatteryVoltage + "\n\t" +
|
||||||
|
"单次最大电压:" + singleBatteryMaxVoltage + "\n\t" +
|
||||||
|
"单次最低电压:" + singleBatteryMinVoltage + "\n\t" +
|
||||||
|
"单体电池最高温度:" + singleBatteryMaxTemperature + "\n\t" +
|
||||||
|
"单体电池最低温度:" + singleBatteryMinTemperature + "\n\t" +
|
||||||
|
"动力电池可用容量:" + availableBatteryCapacity + "\n\t" +
|
||||||
|
"车辆状态:" + vehicleStatus + "\n\t" +
|
||||||
|
"充电状态:" + chargingStatus + "\n\t" +
|
||||||
|
"运行状态:" + operatingStatus + "\n\t" +
|
||||||
|
"SOC:" + chargingEnergyStorageStatus + "\n\t" +
|
||||||
|
"可充电储能装置工作状态:" + driveMotorStatus + "\n\t" +
|
||||||
|
"定位是否有效:" + positionStatus + "\n\t" +
|
||||||
|
"EAS(汽车防盗系统)状态:" + easStatus + "\n\t" +
|
||||||
|
"PTC(主动安全系统)状态:" + ptcStatus + "\n\t" +
|
||||||
|
"EPS(电动助力系统)状态:" + epsStatus + "\n\t" +
|
||||||
|
"ABS(防抱死)状态:" + absStatus + "\n\t" +
|
||||||
|
"MCU(电机/逆变器)状态:" + mcuStatus + "\n\t" +
|
||||||
|
"动力电池加热状态:" + heatingStatus + "\n\t" +
|
||||||
|
"动力电池当前状态:" + batteryStatus + "\n\t" +
|
||||||
|
"动力电池保温状态:" + batteryInsulationStatus + "\n\t" +
|
||||||
|
"DCDC(电力交换系统)状态:" + dcdcStatus + "\n\t" +
|
||||||
|
"CHG(充电机)状态:" + chgStatus
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.mobai.domian;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: Mqtt服务器模型
|
||||||
|
* @Date 2024-3-26 上午 09:53
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MqttServerModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT服务节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT订阅主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.mobai.domian;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应信息主体
|
||||||
|
*
|
||||||
|
* @author Mobai
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class Result<T> implements Serializable {
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
public static final int SUCCESS = HttpStatus.SUCCESS;
|
||||||
|
/**
|
||||||
|
* 失败
|
||||||
|
*/
|
||||||
|
public static final int FAIL = HttpStatus.ERROR;
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**
|
||||||
|
* 系统警告消息
|
||||||
|
*/
|
||||||
|
private static final int WARN = HttpStatus.WARN;
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
public static <T> Result<T> success () {
|
||||||
|
return restResult(null, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success (T data) {
|
||||||
|
return restResult(data, SUCCESS, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> success (T data, String msg) {
|
||||||
|
return restResult(data, SUCCESS, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error () {
|
||||||
|
return restResult(null, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (String msg) {
|
||||||
|
return restResult(null, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (T data) {
|
||||||
|
return restResult(data, FAIL, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (T data, String msg) {
|
||||||
|
return restResult(data, FAIL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error (int code, String msg) {
|
||||||
|
return restResult(null, code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn () {
|
||||||
|
return restResult(null, WARN, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (String msg) {
|
||||||
|
return restResult(null, WARN, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (T data) {
|
||||||
|
return restResult(data, WARN, "操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (T data, String msg) {
|
||||||
|
return restResult(data, WARN, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> warn (int code, String msg) {
|
||||||
|
return restResult(null, code, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> Result<T> restResult (T data, int code, String msg) {
|
||||||
|
Result<T> apiResult = new Result<>();
|
||||||
|
apiResult.setCode(code);
|
||||||
|
apiResult.setData(data);
|
||||||
|
apiResult.setMsg(msg);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isError (Result<T> ret) {
|
||||||
|
return !isSuccess(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isSuccess (Result<T> ret) {
|
||||||
|
return Result.SUCCESS == ret.getCode();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,207 @@
|
||||||
|
package com.mobai.domian;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆数据信息
|
||||||
|
* @author Mobai
|
||||||
|
* @className Vehicle
|
||||||
|
* @description 描述
|
||||||
|
* @date 2024/6/6 8:18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Vehicle {
|
||||||
|
/**
|
||||||
|
* 车辆vin
|
||||||
|
*/
|
||||||
|
private String vin;
|
||||||
|
/**
|
||||||
|
* 时间戳
|
||||||
|
*/
|
||||||
|
private String timestamp;
|
||||||
|
/**
|
||||||
|
* 经度
|
||||||
|
*/
|
||||||
|
private String longitude;
|
||||||
|
/**
|
||||||
|
* 纬度
|
||||||
|
*/
|
||||||
|
private String latitude;
|
||||||
|
/**
|
||||||
|
* 速度
|
||||||
|
*/
|
||||||
|
private String speed;
|
||||||
|
/**
|
||||||
|
* 总里程
|
||||||
|
*/
|
||||||
|
private BigDecimal 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 motoTorque;
|
||||||
|
/**
|
||||||
|
* 电机温度
|
||||||
|
*/
|
||||||
|
private String motorTemperature;
|
||||||
|
/**
|
||||||
|
* 电机电压
|
||||||
|
*/
|
||||||
|
private String motorVoltage;
|
||||||
|
/**
|
||||||
|
* 电机电流
|
||||||
|
*/
|
||||||
|
private String motorCurrent;
|
||||||
|
/**
|
||||||
|
* 动力电池剩余电量SOC
|
||||||
|
*/
|
||||||
|
private BigDecimal remainingBattery;
|
||||||
|
/**
|
||||||
|
* 当前状态允许的最大反馈功率
|
||||||
|
*/
|
||||||
|
private BigDecimal 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 Integer vehicleStatus;
|
||||||
|
/**
|
||||||
|
* 充电状态
|
||||||
|
*/
|
||||||
|
private Integer chargingStatus;
|
||||||
|
/**
|
||||||
|
* 运行状态
|
||||||
|
*/
|
||||||
|
private Integer operatingStatus;
|
||||||
|
/**
|
||||||
|
* SOC
|
||||||
|
*/
|
||||||
|
private Integer chargingEnergyStorageStatus;
|
||||||
|
/**
|
||||||
|
* 可充电储能装置工作状态
|
||||||
|
*/
|
||||||
|
private Integer driveMotorStatus;
|
||||||
|
/**
|
||||||
|
* 定位是否有效
|
||||||
|
*/
|
||||||
|
private Integer positionStatus;
|
||||||
|
/**
|
||||||
|
* EAS
|
||||||
|
*/
|
||||||
|
private Integer easStatus;
|
||||||
|
/**
|
||||||
|
* PTC
|
||||||
|
*/
|
||||||
|
private Integer ptcStatus;
|
||||||
|
/**
|
||||||
|
* EPS
|
||||||
|
*/
|
||||||
|
private Integer epsStatus;
|
||||||
|
/**
|
||||||
|
* ABS
|
||||||
|
*/
|
||||||
|
private Integer absStatus;
|
||||||
|
/**
|
||||||
|
* MCU
|
||||||
|
*/
|
||||||
|
private Integer mcuStatus;
|
||||||
|
/**
|
||||||
|
* 动力电池加热状态
|
||||||
|
*/
|
||||||
|
private Integer heatingStatus;
|
||||||
|
/**
|
||||||
|
* 动力电池当前状态
|
||||||
|
*/
|
||||||
|
private Integer batteryStatus;
|
||||||
|
/**
|
||||||
|
* 动力电池保温状态
|
||||||
|
*/
|
||||||
|
private Integer batteryInsulationStatus;
|
||||||
|
/**
|
||||||
|
* DCDC
|
||||||
|
*/
|
||||||
|
private Integer dcdcStatus;
|
||||||
|
/**
|
||||||
|
* CHG
|
||||||
|
*/
|
||||||
|
private Integer chgStatus;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,520 @@
|
||||||
|
//package com.mobai.domian;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//import lombok.AllArgsConstructor;
|
||||||
|
//import lombok.Builder;
|
||||||
|
//import lombok.Data;
|
||||||
|
//import lombok.NoArgsConstructor;
|
||||||
|
//
|
||||||
|
//import java.math.BigDecimal;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * 报文解析
|
||||||
|
// * @author Mobai
|
||||||
|
// * @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 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;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 汽车对象构造企业VIN
|
||||||
|
// * @param vehicle 汽车对象
|
||||||
|
// * @return 汽车数据对象
|
||||||
|
// */
|
||||||
|
// public static VehicleData vehicleBuild (Vehicle vehicle) {
|
||||||
|
// return VehicleData.builder()
|
||||||
|
// .vin(vehicle.getVin())
|
||||||
|
// .gear("P")
|
||||||
|
// .remainingBattery(vehicle.getRemainingBattery())
|
||||||
|
// .batteryLevel(vehicle.getBatteryLevel())
|
||||||
|
// .mileage(vehicle.getTotalMileage())
|
||||||
|
// .vehicleStatus(1)
|
||||||
|
// .chargingStatus(1)
|
||||||
|
// .operatingStatus(1)
|
||||||
|
// .socStatus(1)
|
||||||
|
// .chargingEnergyStorageStatus(1)
|
||||||
|
// .driveMotorStatus(1)
|
||||||
|
// .positionStatus(1)
|
||||||
|
// .easStatus(1)
|
||||||
|
// .ptcStatus(1)
|
||||||
|
// .epsStatus(1)
|
||||||
|
// .absStatus(1)
|
||||||
|
// .mcuStatus(1)
|
||||||
|
// .heatingStatus(1)
|
||||||
|
// .batteryStatus(1)
|
||||||
|
// .batteryInsulationStatus(1)
|
||||||
|
// .dcdcStatus(1)
|
||||||
|
// .chgStatus(1)
|
||||||
|
// .build();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 模拟基础项
|
||||||
|
// */
|
||||||
|
// public void imitateBase(){
|
||||||
|
// // 总电压
|
||||||
|
// this.voltage = genValue(110, 750);
|
||||||
|
// // 总电流
|
||||||
|
// this.current = genValue(3, 50);
|
||||||
|
// // 绝缘电阻
|
||||||
|
// this.resistance = genValue(0,30000);
|
||||||
|
// // 加速踏板行程值
|
||||||
|
// this.accelerationPedal = genValue(0, 10);
|
||||||
|
// // 制动踏板行程值
|
||||||
|
// this.brakePedal = genValue(0, 10);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 模拟电机数据
|
||||||
|
// */
|
||||||
|
// public void imitateMotor(){
|
||||||
|
// // 电机控制器温度
|
||||||
|
// this.motorControllerTemperature = genValue(0, 100);
|
||||||
|
// // 电机转速
|
||||||
|
// this.motorSpeed = genValue(0, 99999);
|
||||||
|
// // 电机转矩
|
||||||
|
// this.motorTorque = genValue(0, 1000);
|
||||||
|
// // 电机温度
|
||||||
|
// this.motorTemperature = genValue(0, 150);
|
||||||
|
// // 电机电压
|
||||||
|
// this.motorVoltage = genValue(110, 300);
|
||||||
|
// // 电机电流
|
||||||
|
// this.motorCurrent = genValue(0, 15000);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 模拟电池包数据
|
||||||
|
// */
|
||||||
|
// public void imitateBatteryPack(){
|
||||||
|
// // 当前状态允许的最大反馈功率
|
||||||
|
// this.maximumFeedbackPower = genValue(0, 100);
|
||||||
|
// // 当前状态允许最大放电功率
|
||||||
|
// this.maximumDischargePower = genValue(0, 100);
|
||||||
|
// // BMS自检计数器
|
||||||
|
// this.selfCheckCounter = genValue(0, 15);
|
||||||
|
// // 动力电池充放电电流
|
||||||
|
// this.totalBatteryCurrent = genValue(0, 15);
|
||||||
|
// // 动力电池负载端总电压V3
|
||||||
|
// this.totalBatteryVoltage = genValue(220, 750);
|
||||||
|
// // 单体电池最高电压
|
||||||
|
// this.singleBatteryMaxVoltage = genValue(3, 5);
|
||||||
|
// // 单体电池最低电压
|
||||||
|
// this.singleBatteryMinVoltage = genValue(3, 5);
|
||||||
|
// // 单体电池最高温度
|
||||||
|
// this.singleBatteryMaxTemperature = genValue(0, 100);
|
||||||
|
// // 单体电池最低温度
|
||||||
|
// this.singleBatteryMinTemperature = genValue(0, 100);
|
||||||
|
// // 动力电池可用容量
|
||||||
|
// this.availableBatteryCapacity = genValue(0,100 );
|
||||||
|
// }
|
||||||
|
// /**
|
||||||
|
// 车辆状态
|
||||||
|
// 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;
|
||||||
|
// */
|
||||||
|
//}
|
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
|
||||||
* 消费者:消息处理器
|
* 消费者:消息处理器
|
||||||
* @ClassName MessageHandler
|
* @ClassName MessageHandler
|
||||||
* @Description 描述
|
* @Description 描述
|
||||||
* @Author SaiSai.Liu
|
* @Author Mobai
|
||||||
* @Date 2024/5/31 14:37
|
* @Date 2024/5/31 14:37
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.mobai.remote;
|
||||||
|
|
||||||
|
import com.dtflys.forest.annotation.Request;
|
||||||
|
import com.mobai.domian.MqttServerModel;
|
||||||
|
import com.mobai.domian.Result;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public interface MyClient {
|
||||||
|
|
||||||
|
@Request("http://127.0.0.1:8081/fluxmq/getIps/")
|
||||||
|
Result<List<MqttServerModel>> getIps();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.mobai.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验位计算
|
||||||
|
*/
|
||||||
|
public class CalculateCheckDigit {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不去空格
|
||||||
|
* @param sHex
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String makeCheck(String sHex){
|
||||||
|
return makeCheckSum(sHex.replace(" ", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算校验位 ,返回十六进制校验位
|
||||||
|
* */
|
||||||
|
private static String makeCheckSum(String data) {
|
||||||
|
int dSum = 0;
|
||||||
|
int length = data.length();
|
||||||
|
int index = 0;
|
||||||
|
// 遍历十六进制,并计算总和
|
||||||
|
while (index < length) {
|
||||||
|
// 截取2位字符
|
||||||
|
String s = data.substring(index, index + 2);
|
||||||
|
// 十六进制转成十进制 , 并计算十进制的总和
|
||||||
|
dSum += Integer.parseInt(s, 16);
|
||||||
|
index = index + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用256取余,十六进制最大是FF,FF的十进制是255
|
||||||
|
int mod = dSum % 256;
|
||||||
|
// 余数转成十六进制
|
||||||
|
String checkSumHex = Integer.toHexString(mod);
|
||||||
|
length = checkSumHex.length();
|
||||||
|
if (length < 2) {
|
||||||
|
// 校验位不足两位的,在前面补0
|
||||||
|
checkSumHex = "0" + checkSumHex;
|
||||||
|
}
|
||||||
|
return checkSumHex;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.mobai.util;
|
||||||
|
|
||||||
|
import com.mobai.cofig.MqttFactory;
|
||||||
|
import com.mobai.cofig.MqttProperties;
|
||||||
|
import com.mobai.domian.MqttCallBackServiceImpl;
|
||||||
|
import com.mobai.domian.MqttServerModel;
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ConnectMqtt
|
||||||
|
* @description mqtt连接工具
|
||||||
|
* @author Mobai
|
||||||
|
* @date 2024/6/5 11:33
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ConnectMqtt {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
|
public void connectMq(MqttServerModel mqttServerModel) throws ServletException {
|
||||||
|
if (mqttServerModel == null) {
|
||||||
|
throw new ServletException("连接参数不能为空");
|
||||||
|
}
|
||||||
|
MqttProperties mqttProperties = MqttProperties.configBuild(mqttServerModel.getBroker(), mqttServerModel.getTopic());
|
||||||
|
// MqttProperties mqttProperties = new MqttProperties();
|
||||||
|
// mqttProperties.setBroker("tcp://39.98.69.92:1883");
|
||||||
|
// mqttProperties.setTopic("mqtt/test");
|
||||||
|
mqttProperties.setUsername("emqx");
|
||||||
|
mqttProperties.setPassword("public");
|
||||||
|
// mqttProperties.setClientid("subscribe_client");
|
||||||
|
int qos = 0;
|
||||||
|
try {
|
||||||
|
MqttClient client = new MqttFactory(new MqttCallBackServiceImpl()).buildOptions(mqttProperties);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.mobai.util;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进制转换工具
|
||||||
|
*/
|
||||||
|
public class ConversionUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串转化成为16进制字符串
|
||||||
|
* @param s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String strToSixteen(String s) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int length = s.length();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
int ch = s.charAt(i);
|
||||||
|
String s4 = Integer.toHexString(ch);
|
||||||
|
sb.append(s4 + " ");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
// System.out.println(str);
|
||||||
|
// System.out.println(str.length());
|
||||||
|
// System.out.println(strToSixteen);
|
||||||
|
// System.out.println(strToSixteen.replace(" ", "").length());
|
||||||
|
|
||||||
|
String hexStr = "3C3F786D6C2076657273696F6E3D22312E30223F3E0D0A3C6D6F6E69746F72526F6F7420747970653D22706172616D223E3C73796E6368726F6E697A65537970746F6D206576656E743D22302220696E697469616C3D2274727565223E3C416374696F6E5F4543473E3C52687974686D3E53696E75733C2F52687974686D3E3C48523E38303C2F48523E3C454D443E4E6F204368616E67653C2F454D443E3C436F6E647563743E303C2F436F6E647563743E3C2F416374696F6E5F4543473E3C416374696F6E5F4F7361742076616C75653D2239342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F425020697352656C617469766550657263656E743D2266616C7365223E3C536872696E6B2076616C75653D22313230222F3E3C537472657463682076616C75653D223830222F3E3C2F416374696F6E5F42503E3C416374696F6E5F5265737020627265617468547970653D224E6F726D616C222076616C75653D2231342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F6574434F322076616C75653D2233342220697352656C617469766550657263656E743D2266616C7365222F3E3C416374696F6E5F54656D70657261747572652076616C75653D2233352E32222F3E3C416374696F6E5F4356502076616C75653D22362E30222F3E3C416374696F6E5F5041504469612076616C75653D223130222F3E3C416374696F6E5F5041505379732076616C75653D223235222F3E3C416374696F6E5F57502076616C75653D2239222F3E3C2F73796E6368726F6E697A65537970746F6D3E3C2F6D6F6E69746F72526F6F743E0D0A";
|
||||||
|
String hexStringToString = hexStringToString(hexStr);
|
||||||
|
System.out.println(hexStr);
|
||||||
|
System.out.println(hexStr.length());
|
||||||
|
System.out.println(hexStringToString);
|
||||||
|
System.out.println(hexStringToString.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 16进制转换成为string类型字符串
|
||||||
|
* @param s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String hexStringToString(String s) {
|
||||||
|
if (s == null || s.equals("")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
s = s.replace(" ", "");
|
||||||
|
byte[] baKeyword = new byte[s.length() / 2];
|
||||||
|
for (int i = 0; i < baKeyword.length; i++) {
|
||||||
|
try {
|
||||||
|
baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
s = new String(baKeyword, StandardCharsets.UTF_8);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.mobai.util;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mqtt配置类
|
||||||
|
* @author Mobai
|
||||||
|
* @version 1.0
|
||||||
|
* @description Mqtt配置类
|
||||||
|
* @date 2023/11/8
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MqttProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点ID
|
||||||
|
*/
|
||||||
|
private String clientId;
|
||||||
|
private int qos = 0;
|
||||||
|
}
|
|
@ -5,3 +5,21 @@ spring:
|
||||||
name: mobai-mq
|
name: mobai-mq
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
host: 43.142.100.73
|
host: 43.142.100.73
|
||||||
|
# forest配置
|
||||||
|
forest:
|
||||||
|
backend: okhttp3 # 后端HTTP框架(默认为 okhttp3)
|
||||||
|
max-connections: 1000 # 连接池最大连接数(默认为 500)
|
||||||
|
max-route-connections: 500 # 每个路由的最大连接数(默认为 500)
|
||||||
|
max-request-queue-size: 100 # [自v1.5.22版本起可用] 最大请求等待队列大小
|
||||||
|
max-async-thread-size: 300 # [自v1.5.21版本起可用] 最大异步线程数
|
||||||
|
max-async-queue-size: 16 # [自v1.5.22版本起可用] 最大异步线程池队列大小
|
||||||
|
timeout: 30000 # [已不推荐使用] 请求超时时间,单位为毫秒(默认为 3000)
|
||||||
|
connect-timeout: 30000 # 连接超时时间,单位为毫秒(默认为 timeout)
|
||||||
|
read-timeout: 30000 # 数据读取超时时间,单位为毫秒(默认为 timeout)
|
||||||
|
max-retry-count: 0 # 请求失败后重试次数(默认为 0 次不重试)
|
||||||
|
ssl-protocol: TLS # 单向验证的HTTPS的默认TLS协议(默认为 TLS)
|
||||||
|
log-enabled: true # 打开或关闭日志(默认为 true)
|
||||||
|
log-request: true # 打开/关闭Forest请求日志(默认为 true)
|
||||||
|
log-response-status: true # 打开/关闭Forest响应状态日志(默认为 true)
|
||||||
|
log-response-content: true # 打开/关闭Forest响应内容日志(默认为 false)
|
||||||
|
async-mode: platform # [自v1.5.27版本起可用] 异步模式(默认为 platform)
|
||||||
|
|
Loading…
Reference in New Issue