using HslCommunication.MQTT;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using File = System.IO.File;
public class MQTTManager : SerializedMonoBehaviour
{
public static MQTTManager instance = null;
[FoldoutGroup("Guid")]
[Header("存放客户端获取到的guid")]
public string guid = "kcrobot";
[FoldoutGroup("Guid")]
[Header("存放json的字典")]
public Dictionary<string, GuidJson> GuidDic = new Dictionary<string, GuidJson>();
[FoldoutGroup("Guid")]
[Header("json路径")]
//public string GuidPath = Application.streamingAssetsPath + @"/NetworkConfiguration/JsonGuid.json";
public string GuidPath;
[FoldoutGroup("Guid"), LabelText("用于读取转换")]
[Header("用于读取转换")]
private GetGuid getGuid;
[FoldoutGroup("Guid"), LabelText("机器人主动发送数据")]
[Header("用于读取转换")]
private SendKey sendkey;
[FoldoutGroup("机器人运行数据"), LabelText("接收数据的数据结构")]
[Header("要添加的订阅主题")]
/*
send:服务端发送数据,即机器人上报给客户端的数据,时间间隔1s。
recv:客户端发送数据,即客户端给机器人服务端发送的控制数据,有控制命令时下发,无控制命令时无需下发
alm:服务端上报实时报警数据,机器人产生报警后自动发送
record:服务端上报实时识别记录数据,机器人产生检测结果时自动发送
getKey:客户端获取权限,客户端需要控制权限时的申请权限topic
sendKey:服务端返回权限,服务端返回控制权限id时的topic
mapinfo: 机器人端转发激光导航数据.
gsStop:每当到巡检点位停车时发送当前点巡检信息
analysisCheck: 当识别标定配置为第三方检测时,第三方检测开始和结束均发送相应的配置信息.
analysisReceive: 当第三方检测完成时,可通过此接口将结果传回机器人端.机器人端将会显示检测结果.
*/
string[] topics = new string[] { "send", "getKey", "sendKey", "recv", "alm", "robotLog", "record", "mapinfo" };
private Queue<string> msgQue = new Queue<string>();
public bool isRecieve = false;
[Header("测试文本")]
public Text T1;
public Text T2;
public Text T3;
public Text T4;
[Header("机器人状态")]
public int Robotstate;
[FoldoutGroup("真实数据测试"), LabelText("机器人及环境数据显示路径")]
public string pathTest;
[FoldoutGroup("真实数据测试"), LabelText("数据显示str")]
public string 测试读取队列内容;
[FoldoutGroup("真实数据测试"), LabelText("定位数据str")]
public string 定位Test;
[FoldoutGroup("真实数据测试"), LabelText("定位数据路径")]
public string 定位path;
[FoldoutGroup("真实数据测试"), LabelText("报警数据str")]
public string AlarmTest;
[FoldoutGroup("真实数据测试"), LabelText("报警数据路径")]
public string 告警Path;
[FoldoutGroup("真实数据测试"), LabelText("智能数据str")]
public string 智能Test;
[FoldoutGroup("真实数据测试"), LabelText("智能数据路径")]
public string 智能Path;
private void Awake()
{
GuidPath = Application.dataPath + @"/StreamingAssets/NetworkConfiguration/JsonGuid.json";
pathTest = Application.dataPath + @"/StreamingAssets/1.json";
定位path = Application.dataPath + @"/StreamingAssets/Move.json";
告警Path = Application.dataPath + @"/StreamingAssets/Alarm.json";
智能Path = Application.dataPath + @"/StreamingAssets/Dispatch.json";
IstGetGuid();//将需要发送的消息进行初始化赋值
instance = this;
}
void Start()
{
测试读取队列内容 = File.ReadAllText(pathTest, Encoding.UTF8);
定位Test =
Unity程序使用MQTT进行通讯
于 2023-06-13 16:06:39 首次发布