ModelDataManager.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using LitJson;
  2. using Newtonsoft.Json;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class ModelDataManager : MonoSingleton<ModelDataManager>
  7. {
  8. public HumitdlyPanel humityObj;
  9. public NoisePanel NoiseObj;
  10. public OccPanel OccObj;
  11. public bool isLoadModel = false;
  12. private void Start()
  13. {
  14. GetPanelState();
  15. }
  16. // 获取三个设备的基础状态
  17. public void GetPanelState()
  18. {
  19. JsonData data = new JsonData();
  20. data["deviceClassification"] = "TEMPERATURE_HUMIDITY";
  21. PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/device/statisticsEquipmentStatus", data.ToJson(), (msg) =>
  22. {
  23. Debug.Log("DGJ ===> TEMPERATURE_HUMIDITY " + msg);
  24. if (msg == "Request Timeout")
  25. return;
  26. JsonData data = JsonMapper.ToObject(msg);
  27. if (data["code"].ToString() == "200")
  28. {
  29. string state = data["data"]["alarm"].ToString();
  30. humityObj.state = state;
  31. }
  32. });
  33. data["deviceClassification"] = "VIBRATE";
  34. PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/device/statisticsEquipmentStatus", data.ToJson(), (msg) =>
  35. {
  36. Debug.Log("DGJ ===> TEMPERATURE_HUMIDITY " + msg);
  37. if (msg == "Request Timeout")
  38. return;
  39. JsonData data = JsonMapper.ToObject(msg);
  40. if (data["code"].ToString() == "200")
  41. {
  42. string state = data["data"]["alarm"].ToString();
  43. OccObj.state = state;
  44. }
  45. });
  46. data["deviceClassification"] = "VOICE";
  47. PanelController.Instance.Post("https://api-fat1.ghz-tech.com" + "/feature-tester/v1/AIot/device/statisticsEquipmentStatus", data.ToJson(), (msg) =>
  48. {
  49. Debug.Log("DGJ ===> TEMPERATURE_HUMIDITY " + msg);
  50. if (msg == "Request Timeout")
  51. return;
  52. JsonData data = JsonMapper.ToObject(msg);
  53. if (data["code"].ToString() == "200")
  54. {
  55. string state = data["data"]["alarm"].ToString();
  56. NoiseObj.state = state;
  57. }
  58. });
  59. }
  60. /// <summary>
  61. /// 1. 温湿度 2. 噪声 3. 振动
  62. /// </summary>
  63. /// <param name="i"></param>
  64. ///
  65. public void ShowDataObj(int num)
  66. {
  67. if (isLoadModel == false)
  68. return;
  69. switch (num)
  70. {
  71. case 1:
  72. humityObj.gameObject.SetActive(true);
  73. NoiseObj.gameObject.SetActive(false);
  74. OccObj.gameObject.SetActive(false);
  75. break;
  76. case 2:
  77. humityObj.gameObject.SetActive(false);
  78. NoiseObj.gameObject.SetActive(true);
  79. OccObj.gameObject.SetActive(false);
  80. break;
  81. case 3:
  82. humityObj.gameObject.SetActive(false);
  83. NoiseObj.gameObject.SetActive(false);
  84. OccObj.gameObject.SetActive(true);
  85. break;
  86. case -1:
  87. humityObj.gameObject.SetActive(false);
  88. NoiseObj.gameObject.SetActive(false);
  89. OccObj.gameObject.SetActive(false);
  90. break;
  91. default:
  92. break;
  93. }
  94. }
  95. public void SetHumitdlyData(string Msg)
  96. {
  97. HumitureMqttData humitureData = JsonConvert.DeserializeObject<HumitureMqttData>(Msg);
  98. humityObj.SetData(humitureData);
  99. }
  100. public void SetOscData(string Msg)
  101. {
  102. OscillateMqttData oscillateData = JsonConvert.DeserializeObject<OscillateMqttData>(Msg);
  103. OccObj.SetData(oscillateData);
  104. }
  105. public void SetNoiseData(string Msg)
  106. {
  107. NoiseMqttData Noise = JsonConvert.DeserializeObject<NoiseMqttData>(Msg);
  108. NoiseObj.SetData(Noise);
  109. }
  110. }
  111. public class HumitureMqttData
  112. {
  113. public AIDeviceData device { get; set; }
  114. public DeviceValueData temperature { get; set; }
  115. public DeviceValueData humidity { get; set; }
  116. }
  117. public class OscillateMqttData
  118. {
  119. public AIDeviceData device { get; set; }
  120. public DeviceValueData disp { get; set; }
  121. public DeviceValueData speed { get; set; }
  122. public DeviceValueData temp { get; set; }
  123. }
  124. public class NoiseMqttData
  125. {
  126. public AIDeviceData device { get; set; }
  127. public float value { get; set; }
  128. public string unit { get; set; }
  129. }
  130. public class AIDeviceData
  131. {
  132. public string deviceCode { get; set; }
  133. public string deviceName { get; set; }
  134. public string deviceClassification { get; set; }
  135. public long unixTimestamp { get; set; }
  136. }
  137. public class DeviceValueData
  138. {
  139. public float value { get; set; }
  140. public string unit { get; set; }
  141. }