저장
This commit is contained in:
@@ -4,9 +4,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Studio;
|
|
||||||
using Studio.Core;
|
|
||||||
using Studio.Conifg;
|
|
||||||
|
|
||||||
namespace Studio
|
namespace Studio
|
||||||
{
|
{
|
||||||
@@ -22,17 +19,16 @@ namespace Studio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StudioService : UnitySingleton<StudioService>
|
public class StudioService
|
||||||
{
|
{
|
||||||
|
#region Singleton
|
||||||
|
private static readonly StudioService Instance = new StudioService(new StudioRepoistory());
|
||||||
|
public static StudioService Instance => instance;
|
||||||
|
static StudioService() { }
|
||||||
|
#endregion
|
||||||
|
|
||||||
private Dictionary<string, Dictionary<string, EventHandler<StudioServiceTypeEventArgs>>> listenerIdMap;
|
private Dictionary<string, Dictionary<string, EventHandler<StudioServiceTypeEventArgs>>> listenerIdMap;
|
||||||
private StudioRepoistory repository;
|
private StudioRepoistory repository;
|
||||||
public bool isConnected
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return repository.isConnected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private Dictionary<string, float> updateTime = new();
|
private Dictionary<string, float> updateTime = new();
|
||||||
private int totalRequestPacket;
|
private int totalRequestPacket;
|
||||||
private int totalResponsePacket;
|
private int totalResponsePacket;
|
||||||
@@ -46,29 +42,11 @@ namespace Studio
|
|||||||
private string maxResponseTimeApi;
|
private string maxResponseTimeApi;
|
||||||
|
|
||||||
public Dictionary<string, StudioEntityWithState<object>> apiData = new();
|
public Dictionary<string, StudioEntityWithState<object>> apiData = new();
|
||||||
public Dictionary<string, (Dictionary<string, Dictionary<string, string>>, TimeSpan)> mqttData = new();
|
|
||||||
|
|
||||||
private Dictionary<string, DateTime> lastUpdateTime = new();
|
private Dictionary<string, DateTime> lastUpdateTime = new();
|
||||||
|
|
||||||
public event Action<string, StudioEntityWithState<object>> onAPIDataLoaded;
|
public event Action<string, StudioEntityWithState<object>> onAPIDataLoaded;
|
||||||
public event Action<string, Dictionary<string, Dictionary<string, string>>, TimeSpan> onMQTTDataLoaded;
|
public event Action<string, Dictionary<string, Dictionary<string, string>>, TimeSpan> onMQTTDataLoaded;
|
||||||
|
|
||||||
bool isMQTTConnected;
|
|
||||||
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
this.repository = new StudioRepoistory();
|
|
||||||
listenerIdMap = new Dictionary<string, Dictionary<string, EventHandler<StudioServiceTypeEventArgs>>>();
|
|
||||||
|
|
||||||
repository.OnTopicList += OnTopicList;
|
|
||||||
|
|
||||||
Constants.MQTTDomain = "220.90.135.190";
|
|
||||||
Constants.APIDomain = "220.90.135.190";
|
|
||||||
Constants.APIPort = 23000;
|
|
||||||
Constants.MQTTPort = 8088;
|
|
||||||
ConnectMQTT();
|
|
||||||
}
|
|
||||||
|
|
||||||
//private string
|
//private string
|
||||||
private StudioService(StudioRepoistory repository)
|
private StudioService(StudioRepoistory repository)
|
||||||
{
|
{
|
||||||
@@ -80,12 +58,7 @@ namespace Studio
|
|||||||
}
|
}
|
||||||
public void ConnectMQTT()
|
public void ConnectMQTT()
|
||||||
{
|
{
|
||||||
if (isMQTTConnected)
|
|
||||||
return;
|
|
||||||
|
|
||||||
repository.MQTTConnect();
|
repository.MQTTConnect();
|
||||||
repository.isMQTTConnected = true;
|
|
||||||
isMQTTConnected = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SubscribeMQTT(string topic)
|
public void SubscribeMQTT(string topic)
|
||||||
@@ -116,15 +89,6 @@ namespace Studio
|
|||||||
UpdateTopicData(type, idKey.Key, idKey.Value);
|
UpdateTopicData(type, idKey.Key, idKey.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mqttData.ContainsKey(type))
|
|
||||||
{
|
|
||||||
mqttData.Add(type, (entities, elapsedTime));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mqttData[type] = (entities, elapsedTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
onMQTTDataLoaded?.Invoke(type, entities, elapsedTime); // 나중에 클래스 밖으로 이동 필요
|
onMQTTDataLoaded?.Invoke(type, entities, elapsedTime); // 나중에 클래스 밖으로 이동 필요
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +174,7 @@ namespace Studio
|
|||||||
Debug.Log($"APIState : Error , Message :{data.Message}");
|
Debug.Log($"APIState : Error , Message :{data.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
onAPIDataLoaded?.Invoke(url, data); // 나중에 클래스 밖으로 이동 필요
|
onAPIDataLoaded?.Invoke(url, data); // 나중에 클래스 밖으로 이동 필요
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckAPIBoarder(string data, int reqSize, string url, long time)
|
private void CheckAPIBoarder(string data, int reqSize, string url, long time)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace Studio
|
|||||||
foreach (UI_InputURLItem item in inputURLItems)
|
foreach (UI_InputURLItem item in inputURLItems)
|
||||||
{
|
{
|
||||||
string url = "/api/" + item.InputField_URL.text;
|
string url = "/api/" + item.InputField_URL.text;
|
||||||
await StudioService.instance.LoadBaseData(url);
|
await StudioService.Instance.LoadBaseData(url);
|
||||||
|
|
||||||
panel_DataRepository = FindAnyObjectByType<Panel_DataRepository>(FindObjectsInactive.Include);
|
panel_DataRepository = FindAnyObjectByType<Panel_DataRepository>(FindObjectsInactive.Include);
|
||||||
panel_DataRepository.apiConnected = true;
|
panel_DataRepository.apiConnected = true;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace Studio
|
|||||||
|
|
||||||
foreach (UI_InputTopicItem item in inputTopicItems)
|
foreach (UI_InputTopicItem item in inputTopicItems)
|
||||||
{
|
{
|
||||||
StudioService.instance.SubscribeMQTT(item.InputField_Topic.text);
|
StudioService.Instance.SubscribeMQTT(item.InputField_Topic.text);
|
||||||
|
|
||||||
panel_DataRepository = FindAnyObjectByType<Panel_DataRepository>(FindObjectsInactive.Include);
|
panel_DataRepository = FindAnyObjectByType<Panel_DataRepository>(FindObjectsInactive.Include);
|
||||||
panel_DataRepository.mqttConnected = true;
|
panel_DataRepository.mqttConnected = true;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace Studio
|
|||||||
*/
|
*/
|
||||||
if (apiConnected)
|
if (apiConnected)
|
||||||
{
|
{
|
||||||
StudioService studioService = StudioService.instance;
|
StudioService studioService = StudioService.Instance;
|
||||||
|
|
||||||
studioService.onAPIDataLoaded += UpdateAPIDataButton;
|
studioService.onAPIDataLoaded += UpdateAPIDataButton;
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ namespace Studio
|
|||||||
|
|
||||||
if (mqttConnected)
|
if (mqttConnected)
|
||||||
{
|
{
|
||||||
StudioService studioService = StudioService.instance;
|
StudioService studioService = StudioService.Instance;
|
||||||
|
|
||||||
studioService.onMQTTDataLoaded += UpdateMQTTDataButton;
|
studioService.onMQTTDataLoaded += UpdateMQTTDataButton;
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ namespace Studio
|
|||||||
|
|
||||||
public void ShowInformation_API()
|
public void ShowInformation_API()
|
||||||
{
|
{
|
||||||
APITotalBoardEntity info = StudioService.instance.GetAPIStatusBoarder();
|
APITotalBoardEntity info = StudioService.Instance.GetAPIStatusBoarder();
|
||||||
|
|
||||||
TotalRequestPacketSize.text = info.TotalRequestPacketSize.ToString();
|
TotalRequestPacketSize.text = info.TotalRequestPacketSize.ToString();
|
||||||
AverageRequestPacketSize.text = info.AverageRequestPacketSize.ToString();
|
AverageRequestPacketSize.text = info.AverageRequestPacketSize.ToString();
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ namespace Studio
|
|||||||
Constants.APIDomain = "220.90.135.190";
|
Constants.APIDomain = "220.90.135.190";
|
||||||
Constants.APIPort = 23000;
|
Constants.APIPort = 23000;
|
||||||
Constants.MQTTPort = 8088;
|
Constants.MQTTPort = 8088;
|
||||||
StudioService.instance.ConnectMQTT();
|
StudioService.Instance.ConnectMQTT();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Test()
|
private async void Test()
|
||||||
{
|
{
|
||||||
await AuthService.Instance.Login("xr", "@dbqlTl1");
|
await AuthService.Instance.Login("xr", "@dbqlTl1");
|
||||||
|
|
||||||
await StudioService.instance.LoadBaseData("/api/agv");
|
await StudioService.Instance.LoadBaseData("/api/agv");
|
||||||
Debug.Log(AuthService.Instance.Entiti.accessToken);
|
Debug.Log(AuthService.Instance.Entiti.accessToken);
|
||||||
}
|
}
|
||||||
private void Update()
|
private void Update()
|
||||||
@@ -34,12 +34,12 @@ namespace Studio
|
|||||||
}
|
}
|
||||||
if (Input.GetKeyDown(KeyCode.I))
|
if (Input.GetKeyDown(KeyCode.I))
|
||||||
{
|
{
|
||||||
StudioService.instance.SubscribeMQTT("STOCKER_CRANE");
|
StudioService.Instance.SubscribeMQTT("STOCKER_CRANE");
|
||||||
|
|
||||||
}
|
}
|
||||||
if(Input.GetKeyDown(KeyCode.U))
|
if(Input.GetKeyDown(KeyCode.U))
|
||||||
{
|
{
|
||||||
StudioService.instance.SubscribeMQTT("AGV");
|
StudioService.Instance.SubscribeMQTT("AGV");
|
||||||
}
|
}
|
||||||
if(Input.GetKeyDown(KeyCode.T))
|
if(Input.GetKeyDown(KeyCode.T))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Studio
|
|||||||
private void SetItem()
|
private void SetItem()
|
||||||
{
|
{
|
||||||
var apiItem = CreateAccordion();
|
var apiItem = CreateAccordion();
|
||||||
var basedatas = StudioService.instance.apiData;
|
var basedatas = StudioService.Instance.apiData;
|
||||||
foreach(var data in basedatas)
|
foreach(var data in basedatas)
|
||||||
{
|
{
|
||||||
CreateTabButton(data.Key, apiItem.BarList);
|
CreateTabButton(data.Key, apiItem.BarList);
|
||||||
|
|||||||
Reference in New Issue
Block a user