|
@@ -1,10 +1,14 @@
|
|
|
package com.ozs.service.utils;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.ozs.common.utils.sign.Md5Utils;
|
|
|
+import com.ozs.common.utils.stateSecrets.SM4Utils;
|
|
|
import com.ozs.service.entity.vo.BaseCameraVersionVo;
|
|
|
import com.ozs.service.entity.vo.Data;
|
|
|
import com.ozs.service.entity.vo.Heartbeat;
|
|
|
+import com.ozs.service.entity.vo.Param;
|
|
|
+import com.ozs.service.entity.vo.Svp;
|
|
|
import com.ozs.service.entity.vo.UpdateDeviceSn;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttClient;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
|
@@ -16,6 +20,9 @@ import org.eclipse.paho.client.mqttv3.MqttTopic;
|
|
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
@@ -28,7 +35,7 @@ public class PublishClient {
|
|
|
/**
|
|
|
* mqtt服务器地址
|
|
|
*/
|
|
|
- public static final String HOST="tcp://124.70.58.209:1883";
|
|
|
+ public static final String HOST = "tcp://124.70.58.209:1883";
|
|
|
/**
|
|
|
* 主题
|
|
|
*/
|
|
@@ -47,16 +54,17 @@ public class PublishClient {
|
|
|
|
|
|
/**
|
|
|
* 初始化客户端实例
|
|
|
+ *
|
|
|
* @param topic
|
|
|
* @param clientId
|
|
|
* @throws MqttException
|
|
|
*/
|
|
|
- public PublishClient(String topic,String clientId) throws MqttException {
|
|
|
+ public PublishClient(String topic, String clientId) throws MqttException {
|
|
|
/**
|
|
|
* mqtt 客户机ID
|
|
|
* heart_DEVICESN
|
|
|
*/
|
|
|
- this.topic=topic;
|
|
|
+ this.topic = topic;
|
|
|
/**
|
|
|
* MemoryPersistence设置clientId的保存形式,默认为以内存保存
|
|
|
*/
|
|
@@ -100,6 +108,7 @@ public class PublishClient {
|
|
|
|
|
|
/**
|
|
|
* 发布
|
|
|
+ *
|
|
|
* @param topic
|
|
|
* @param message
|
|
|
* @throws MqttPersistenceException
|
|
@@ -111,12 +120,12 @@ public class PublishClient {
|
|
|
token.waitForCompletion();
|
|
|
System.out.println("message is published completely! " + token.isComplete());
|
|
|
}
|
|
|
-
|
|
|
- public static void pull(String sign,String deviceSn) throws MqttException, InterruptedException {
|
|
|
+
|
|
|
+ public static void pull(String sign, String deviceSn) throws MqttException, InterruptedException {
|
|
|
/**
|
|
|
* 发布客户端
|
|
|
*/
|
|
|
- PublishClient server = new PublishClient("heart_"+deviceSn,"heart_"+deviceSn);
|
|
|
+ PublishClient server = new PublishClient("heart_" + deviceSn, "heart_" + deviceSn);
|
|
|
Heartbeat test = new Heartbeat();
|
|
|
test.setName("HeartResponse");
|
|
|
Data data = new Data();
|
|
@@ -145,7 +154,7 @@ public class PublishClient {
|
|
|
server.publish(server.topic11, server.message);
|
|
|
}
|
|
|
|
|
|
- public static void updateDeviceSn(BaseCameraVersionVo baseCameraVersionVo){
|
|
|
+ public static void updateDeviceSn(BaseCameraVersionVo baseCameraVersionVo) {
|
|
|
/**
|
|
|
* 发布客户端
|
|
|
*/
|
|
@@ -181,4 +190,44 @@ public class PublishClient {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void confidenceCoefficient(String code) {
|
|
|
+ /**
|
|
|
+ * 发布客户端
|
|
|
+ */
|
|
|
+ try {
|
|
|
+ PublishClient server = new PublishClient("config_" + code, "config_" + code);
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ res.put("Name", "ConfigRequest");
|
|
|
+ Svp svp=new Svp();
|
|
|
+ Param param = new Param();
|
|
|
+ param.setThreshold(0.700000);
|
|
|
+ svp.setParam(param);
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
+ map.put("svp",svp);
|
|
|
+ res.put("data",map);
|
|
|
+ res.put("sign",UUID.randomUUID().toString());
|
|
|
+ String s = JSONObject.toJSONString(res);
|
|
|
+
|
|
|
+ server.message = new MqttMessage();
|
|
|
+ /**
|
|
|
+ * 保证消息能到达一次
|
|
|
+ */
|
|
|
+ server.message.setQos(1);
|
|
|
+ /**
|
|
|
+ * 消息保留
|
|
|
+ */
|
|
|
+// server.message.setRetained(false);
|
|
|
+ /**
|
|
|
+ * 消息内容
|
|
|
+ */
|
|
|
+ server.message.setPayload(s.getBytes());
|
|
|
+ /**
|
|
|
+ * 发布
|
|
|
+ */
|
|
|
+ server.publish(server.topic11, server.message);
|
|
|
+ } catch (MqttException e) {
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|