agv . mqtt 연동작업

This commit is contained in:
2025-05-24 14:11:29 +09:00
parent 5ab0270392
commit 9780c297e6
4 changed files with 25 additions and 19 deletions

View File

@@ -9,9 +9,9 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 421374873455346910} - component: {fileID: 421374873455346910}
- component: {fileID: 5492482365278483619} - component: {fileID: 802422837581587047}
m_Layer: 0 m_Layer: 0
m_Name: AGV 1 m_Name: TestAGV
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@@ -34,7 +34,7 @@ Transform:
- {fileID: 1627652318861080814} - {fileID: 1627652318861080814}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5492482365278483619 --- !u!114 &802422837581587047
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}

View File

@@ -89,6 +89,7 @@ namespace Studio
} }
} }
private void OnStateChangedMQTT(MQTTClient client, ClientStates oldState, ClientStates newState) private void OnStateChangedMQTT(MQTTClient client, ClientStates oldState, ClientStates newState)
{ {
Debug.Log($"{oldState} => {newState}"); Debug.Log($"{oldState} => {newState}");
@@ -132,13 +133,12 @@ namespace Studio
{ {
string key = prop.Name.ToString(); string key = prop.Name.ToString();
string value = prop.Value.ToString(); string value = prop.Value.ToString();
// Debug.Log($"kEY : {key}, Value:{value}");
} }
var T = json["data"]; var T = json["data"];
var split = T.ToString().Split('['); var split = T.ToString().Split('[');
var t = $"[{split[1]}"; var t = $"[{split[1]}";
//Debug.Log(T.ToString());
JArray jarray = JArray.Parse(t); JArray jarray = JArray.Parse(t);
var list = new Dictionary<string, Dictionary<string, string>>(); var list = new Dictionary<string, Dictionary<string, string>>();
foreach (JObject obj in jarray.Children()) foreach (JObject obj in jarray.Children())

View File

@@ -3,6 +3,7 @@ using Studio.Setting.Connect;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading;
using UnityEngine; using UnityEngine;
using XED; using XED;
@@ -64,6 +65,8 @@ namespace Studio
{ {
this.repository = repository; this.repository = repository;
listenerIdMap = new Dictionary<string, Dictionary<string, EventHandler<StudioServiceIdEventArgs>>>(); listenerIdMap = new Dictionary<string, Dictionary<string, EventHandler<StudioServiceIdEventArgs>>>();
listenerTypeMap = new Dictionary<string, EventHandler<StudioServiceTypeEventArgs>>();
repository.OnTopicList += OnTopicList; repository.OnTopicList += OnTopicList;
// repository.OnDetectedError += OnDetectedError; // repository.OnDetectedError += OnDetectedError;
@@ -77,7 +80,6 @@ namespace Studio
{ {
repository.Subscribe(topic); repository.Subscribe(topic);
} }
//Que에 담아둔다?
private void OnTopicList(string type, Dictionary<string, Dictionary<string, string>> entities) private void OnTopicList(string type, Dictionary<string, Dictionary<string, string>> entities)
{ {
foreach (var idKey in entities) foreach (var idKey in entities)
@@ -86,22 +88,19 @@ namespace Studio
} }
} }
private async Task UpdateTopicData(string type, string id, Dictionary<string, string> entity) private void UpdateTopicData(string type, string id, Dictionary<string, string> entity)
{ {
if (!updateTime.ContainsKey(type)) if (!updateTime.ContainsKey(type))
updateTime.Add(type, 0.5f); updateTime.Add(type, 0.5f);
var time = updateTime[type]; var time = updateTime[type];
var task = Task.Factory.StartNew(async () =>
var task = Task.Run(async () =>
{ {
var st = string.Empty;
st = $"{type}:";
int delayTime = (int)(time * 1000); int delayTime = (int)(time * 1000);
await Task.Delay(delayTime); await Task.Delay(delayTime);
DispatchMachineEvent(type, id, entity); DispatchMachineEvent(type, id, entity);
}); },CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
} }
@@ -124,12 +123,13 @@ namespace Studio
return result != null; return result != null;
} }
public void AddTypeIdListener(string type, string id, EventHandler<StudioServiceIdEventArgs> listener) public void AddTypeIdListener(string type, string id = null, EventHandler<StudioServiceIdEventArgs> listener=null)
{ {
if (!listenerIdMap.ContainsKey(type)) if (!listenerIdMap.ContainsKey(type))
{ {
listenerIdMap.Add(type, new()); listenerIdMap.Add(type, new());
//Debug.LogError($"Key Value is missing!!!! -Key:{type}-"); Debug.Log("딱한번들어옴");
return;
} }
if (!listenerIdMap[type].ContainsKey(id)) if (!listenerIdMap[type].ContainsKey(id))
{ {
@@ -160,13 +160,11 @@ namespace Studio
var t = sw.ElapsedMilliseconds; var t = sw.ElapsedMilliseconds;
if (data.State.Equals(APIState.Loaded)) if (data.State.Equals(APIState.Loaded))
{ {
if (!baseData.ContainsKey(url)) if (!baseData.ContainsKey(url))
baseData.Add(url, new()); baseData.Add(url, new());
CheckAPIBoarder(data.Entity.ToString(), data.ReqSize, url, t); CheckAPIBoarder(data.Entity.ToString(), data.ReqSize, url, t);
UpdateEntity(url, data.Entity.ToString()); UpdateEntity(url, data.Entity.ToString());
} }
@@ -214,7 +212,6 @@ namespace Studio
boardEntity.MaximumResponsePacketAPI = maxResponseApi; boardEntity.MaximumResponsePacketAPI = maxResponseApi;
boardEntity.MaximumResponseTimeAPI = maxResponseTimeApi; boardEntity.MaximumResponseTimeAPI = maxResponseTimeApi;
return boardEntity; return boardEntity;
//JsonUtility.ToJson()
} }
public void UpdateEntity(string type, string data) public void UpdateEntity(string type, string data)
@@ -242,7 +239,6 @@ namespace Studio
keyvalue.Add(key, value); keyvalue.Add(key, value);
} }
list.Add(keyvalue); list.Add(keyvalue);
//DispatchMachineEvent(type, id, keyvalue);
} }
} }
@@ -250,12 +246,22 @@ namespace Studio
{ {
if (!listenerIdMap.ContainsKey(type)) if (!listenerIdMap.ContainsKey(type))
{ {
Debug.LogError($"Key Value is missing!!!! -Key:{type}-"); Debug.Log($"Key Value is missing!!!! -Key:{type}-");
} }
if (listenerIdMap[type].ContainsKey(id)) if (listenerIdMap[type].ContainsKey(id))
{ {
listenerIdMap[type][id].Invoke(this, new StudioServiceIdEventArgs(type, entity)); listenerIdMap[type][id].Invoke(this, new StudioServiceIdEventArgs(type, entity));
} }
else
{
var data = new Dictionary<string, Dictionary<string, string>>();
data.Add(id, entity);
if (entity == null)
{
return;
}
DispatchTypeMachineEvent(type, data);
}
} }
private void DispatchTypeMachineEvent(string type, Dictionary<string,Dictionary<string, string>> entities) private void DispatchTypeMachineEvent(string type, Dictionary<string,Dictionary<string, string>> entities)