Jelajahi Sumber

修改初始化传感器列表的方法

Void_F 8 bulan lalu
induk
melakukan
de0026fa84

+ 7 - 0
Assets/Scripts/HttpGetData.cs

@@ -7,6 +7,13 @@ public class HttpGetData
 {
 }
 
+[Serializable]
+public class SensorListResult
+{
+    public int total;
+    public List<DevicesId_Data> rows;
+}
+
 /// <summary>
 /// ???code>0 data: string message
 /// </summary>

+ 285 - 262
Assets/Scripts/HttpHelper.cs

@@ -19,7 +19,7 @@ public class HttpHelper : MonoBehaviour
 
     public static HttpHelper _Instance;
 
-    public static Dictionary<string, DevicesId_Data> _devicesIdDatas_BuYuan = new Dictionary<string, DevicesId_Data>();
+    public static Dictionary<string, DevicesId_Data> _devicesIdDatas = new Dictionary<string, DevicesId_Data>();
 
     public const int timeOut = 3;
 
@@ -37,8 +37,10 @@ public class HttpHelper : MonoBehaviour
         }
         if (GlobalData.pageIndex == PageIndex.Page1) 
         {
-            InItBuYuanDevicesList();
+            GetSensorList();
             SendBuYuan_GetSensorData();
+            SendTaoKou_GetSensorData();
+            
             GetBuYuanDevicesGroupInfo();
         }
         if (GlobalData.pageIndex == PageIndex.Page1)
@@ -704,8 +706,8 @@ public class HttpHelper : MonoBehaviour
     public async Task InitSWYJData1()
     {
         GlobalData.BuYuanShuiWeiDataList = new List<ShuiWeiData>();
-        var devicesInfo = _devicesIdDatas_BuYuan["上游水位计"];
-        string sw1Result = await GetSingleDevicesInfo(devicesInfo.ChannelID, devicesInfo.DeviceID, 24);
+        var devicesInfo = _devicesIdDatas["上游水位计"];
+        string sw1Result = await GetSingleDevicesInfo(devicesInfo.dataGid, devicesInfo.dataSid, 24);
         try
         {
             GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(sw1Result);
@@ -726,8 +728,8 @@ public class HttpHelper : MonoBehaviour
             Debug.LogWarning("补元上游水位不成功,原因:" + e.ToString());
         }
 
-        var devicesInfo1 = _devicesIdDatas_BuYuan["下游水位计"];
-        string sw2Result = await GetSingleDevicesInfo(devicesInfo1.ChannelID, devicesInfo1.DeviceID, 24);
+        var devicesInfo1 = _devicesIdDatas["下游水位计"];
+        string sw2Result = await GetSingleDevicesInfo(devicesInfo1.dataGid, devicesInfo1.dataSid, 24);
         try
         {
             GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(sw2Result);
@@ -748,7 +750,7 @@ public class HttpHelper : MonoBehaviour
             Debug.LogWarning("补元下游水位不成功,原因:" + e.ToString());
         }
 
-        string dayResult = await GetSingleDevicesInfo_day(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
+        string dayResult = await GetSingleDevicesInfo_day(devicesInfo.dataGid, devicesInfo.dataSid, 6);
         try
         {
             GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(dayResult);
@@ -766,7 +768,7 @@ public class HttpHelper : MonoBehaviour
             Debug.LogWarning("获取6天平均数据不成功,原因:" + e.ToString());
         }
 
-        string monthResult = await GetSingleDevicesInfo_month(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
+        string monthResult = await GetSingleDevicesInfo_month(devicesInfo.dataGid, devicesInfo.dataSid, 6);
         try
         {
             GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(monthResult);
@@ -784,7 +786,7 @@ public class HttpHelper : MonoBehaviour
             Debug.LogWarning("获取6月平均数据不成功,原因:" + e.ToString());
         }
 
-        string hourResult = await GetSingleDevicesInfo_hour(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
+        string hourResult = await GetSingleDevicesInfo_hour(devicesInfo.dataGid, devicesInfo.dataSid, 6);
         try
         {
             GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(hourResult);
@@ -920,11 +922,11 @@ public class HttpHelper : MonoBehaviour
         tempData.idsList = new List<DevicesMessage>();
         for (int i = 0; i < 13; i++)
         {
-            var devicesInfo = _devicesIdDatas_BuYuan[$"P{i + 1}"];
+            var devicesInfo = _devicesIdDatas[$"P{i + 1}"];
             tempData.idsList.Add(new DevicesMessage()
             {
-                DeviceID = devicesInfo.DeviceID,
-                ChannelID = devicesInfo.ChannelID
+                DeviceID = devicesInfo.dataSid,
+                ChannelID = devicesInfo.dataGid
             });
         }
         string jsonStr;
@@ -957,11 +959,11 @@ public class HttpHelper : MonoBehaviour
         tempData.idsList = new List<DevicesMessage>();
         for (int i = 0; i < 8; i++)
         {
-            var devicesInfo = _devicesIdDatas_BuYuan[$"M{i + 1}"];
+            var devicesInfo = _devicesIdDatas[$"M{i + 1}"];
             tempData.idsList.Add(new DevicesMessage()
             {
-                DeviceID = devicesInfo.DeviceID,
-                ChannelID = devicesInfo.ChannelID
+                DeviceID = devicesInfo.dataSid,
+                ChannelID = devicesInfo.dataGid
             });
         }
         try
@@ -1362,260 +1364,281 @@ public class HttpHelper : MonoBehaviour
     }
     #endregion
 
-
-    /// <summary>
-    /// 初始化所有补元硬件设备的获取信息
-    /// </summary>
-    public void InItBuYuanDevicesList()
+    // /// <summary>
+    // /// 所有硬件设备的获取信息
+    // /// </summary>
+    public async Task GetSensorList()
     {
-        _devicesIdDatas_BuYuan = new Dictionary<string, DevicesId_Data>();
-
-        _devicesIdDatas_BuYuan.Add("上游水位计", new DevicesId_Data()
-        {
-            ChannelID = 7,
-            DeviceID = 4,
-            name = "上游水位计",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("下游水位计", new DevicesId_Data()
-        {
-            ChannelID = 8,
-            DeviceID = 4,
-            name = "上游水位计",
-            showName = "",
-            value = -1
-        });
-
-        #region P
-
-        _devicesIdDatas_BuYuan.Add("P1", new DevicesId_Data()
-        {
-            ChannelID = 1,
-            DeviceID = 2,
-            name = "P1/UP1",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P2", new DevicesId_Data()
-        {
-            ChannelID = 2,
-            DeviceID = 2,
-            name = "P2/UP2",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P3", new DevicesId_Data()
-        {
-            ChannelID = 3,
-            DeviceID = 2,
-            name = "P3",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P4", new DevicesId_Data()
-        {
-            ChannelID = 4,
-            DeviceID = 2,
-            name = "P4/UP3",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P5", new DevicesId_Data()
-        {
-            ChannelID = 1,
-            DeviceID = 3,
-            name = "P5/UP5",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P6", new DevicesId_Data()
-        {
-            ChannelID = 2,
-            DeviceID = 3,
-            name = "P6/",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P7", new DevicesId_Data()
-        {
-            ChannelID = 3,
-            DeviceID = 3,
-            name = "P7/UP5",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P8", new DevicesId_Data()
-        {
-            ChannelID = 4,
-            DeviceID = 3,
-            name = "P8/UP6",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P5温度", new DevicesId_Data()
-        {
-            ChannelID = 9,
-            DeviceID = 3,
-            name = "P5温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P6温度", new DevicesId_Data()
-        {
-            ChannelID = 10,
-            DeviceID = 3,
-            name = "P6温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P7温度", new DevicesId_Data()
-        {
-            ChannelID = 11,
-            DeviceID = 3,
-            name = "P7温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P8温度", new DevicesId_Data()
-        {
-            ChannelID = 12,
-            DeviceID = 3,
-            name = "P8温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P9温度", new DevicesId_Data()
-        {
-            ChannelID = 9,
-            DeviceID = 4,
-            name = "P9温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P10温度", new DevicesId_Data()
-        {
-            ChannelID = 10,
-            DeviceID = 4,
-            name = "P10温度",
-            showName = "",
-            value = -1
-        });
-
-        _devicesIdDatas_BuYuan.Add("P12温度", new DevicesId_Data()
-        {
-            ChannelID = 11,
-            DeviceID = 4,
-            name = "P12温度",
-            showName = "",
-            value = -1
-        });
-
-        _devicesIdDatas_BuYuan.Add("P9", new DevicesId_Data()
-        {
-            ChannelID = 3,
-            DeviceID = 4,
-            name = "P9",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P10", new DevicesId_Data()
-        {
-            ChannelID = 4,
-            DeviceID = 4,
-            name = "P10/UP7",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P11", new DevicesId_Data()
-        {
-            ChannelID = 5,
-            DeviceID = 4,
-            name = "P11/UP8",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add("P12", new DevicesId_Data()
+        bool successInternet = true;
+        UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_GetAllSensorList);
+        await www.SendWebRequest();
+        try
         {
-            ChannelID = 1,
-            DeviceID = 4,
-            name = "P12/UP9",
-            showName = "",
-            value = -1
-        });
-
-        _devicesIdDatas_BuYuan.Add("P13", new DevicesId_Data()
+            if (www.result != UnityWebRequest.Result.Success)
+            {
+                successInternet = false;
+                Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
+            }
+            else
+            {
+                SensorListResult tempData = JsonUtility.FromJson<SensorListResult>(www.downloadHandler.text);
+                _devicesIdDatas = new Dictionary<string, DevicesId_Data>();
+                for (int i = 0; i < tempData.rows.Count; i++)
+                {
+                    _devicesIdDatas.Add(tempData.rows[i].sensorName, tempData.rows[i]);
+                }
+                Debug.Log($"初始化设备列表成功!!! count:{tempData.total}");
+            }
+        }
+        catch (Exception e)
         {
-            ChannelID = 2,
-            DeviceID = 4,
-            name = "P13/UP10",
-            showName = "",
-            value = -1
-        });
-
-        #endregion
-
-        #region M
-
-        //M1-8
-        int m_cid = 1;
-        int m_did = 5;
-        for (int i = 0; i < 8; i++)
+            successInternet = false;
+            Debug.LogWarning("获取设备数据不成功,原因:" + e.ToString());
+        }
+        www.Dispose();
+        
+        if (!successInternet)
         {
-            _devicesIdDatas_BuYuan.Add($"M{i + 1}", new DevicesId_Data()
+            WWW localWWW = new WWW(Application.streamingAssetsPath + "/SensorList.json");
+            await new UnityAsync.WaitUntil(() =>
             {
-                ChannelID = m_cid + i,
-                DeviceID = m_did,
-                name = $"M{i + 1}",
-                showName = "",
-                value = -1
+                return localWWW.isDone;
             });
+            SensorListResult tempData = JsonUtility.FromJson<SensorListResult>(www.downloadHandler.text);
+            _devicesIdDatas = new Dictionary<string, DevicesId_Data>();
+            for (int i = 0; i < tempData.rows.Count; i++)
+            {
+                _devicesIdDatas.Add(tempData.rows[i].sensorName, tempData.rows[i]);
+            }
+            Debug.Log($"读取本地初始化设备列表成功!!! count:{tempData.total}");
+            www.Dispose();
         }
-
-        //M温度
-        _devicesIdDatas_BuYuan.Add($"M2温度", new DevicesId_Data()
-        {
-            ChannelID = 10,
-            DeviceID = 5,
-            name = $"M2温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add($"M5温度", new DevicesId_Data()
-        {
-            ChannelID = 13,
-            DeviceID = 5,
-            name = $"M5温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add($"M6温度", new DevicesId_Data()
-        {
-            ChannelID = 14,
-            DeviceID = 5,
-            name = $"M6温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add($"M7温度", new DevicesId_Data()
-        {
-            ChannelID = 15,
-            DeviceID = 5,
-            name = $"M7温度",
-            showName = "",
-            value = -1
-        });
-        _devicesIdDatas_BuYuan.Add($"M8温度", new DevicesId_Data()
-        {
-            ChannelID = 16,
-            DeviceID = 5,
-            name = $"M8温度",
-            showName = "",
-            value = -1
-        });
-
-        #endregion
     }
-
+ 
+    // /// <summary>
+    // /// 初始化所有补元硬件设备的获取信息
+    // /// </summary>
+    // public void InItBuYuanDevicesList()
+    // {
+    //     _devicesIdDatas = new Dictionary<string, DevicesId_Data>();
+    //
+    //     _devicesIdDatas.Add("上游水位计", new DevicesId_Data()
+    //     {
+    //         dataGid = 7,
+    //         dataSid = 4,
+    //         sensorName = "上游水位计",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("下游水位计", new DevicesId_Data()
+    //     {
+    //         dataGid = 8,
+    //         dataSid = 4,
+    //         sensorName = "上游水位计",
+    //         realtimeValue1 = -1
+    //     });
+    //
+    //     #region P
+    //
+    //     _devicesIdDatas.Add("P1", new DevicesId_Data()
+    //     {
+    //         dataGid = 1,
+    //         dataSid = 2,
+    //         sensorName = "P1/UP1",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P2", new DevicesId_Data()
+    //     {
+    //         dataGid = 2,
+    //         dataSid = 2,
+    //         sensorName = "P2/UP2",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P3", new DevicesId_Data()
+    //     {
+    //         dataGid = 3,
+    //         dataSid = 2,
+    //         sensorName = "P3",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P4", new DevicesId_Data()
+    //     {
+    //         dataGid = 4,
+    //         dataSid = 2,
+    //         sensorName = "P4/UP3",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P5", new DevicesId_Data()
+    //     {
+    //         dataGid = 1,
+    //         dataSid = 3,
+    //         sensorName = "P5/UP5",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P6", new DevicesId_Data()
+    //     {
+    //         dataGid = 2,
+    //         dataSid = 3,
+    //         sensorName = "P6/",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P7", new DevicesId_Data()
+    //     {
+    //         dataGid = 3,
+    //         dataSid = 3,
+    //         sensorName = "P7/UP5",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P8", new DevicesId_Data()
+    //     {
+    //         dataGid = 4,
+    //         dataSid = 3,
+    //         sensorName = "P8/UP6",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P5温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 9,
+    //         dataSid = 3,
+    //         sensorName = "P5温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P6温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 10,
+    //         dataSid = 3,
+    //         sensorName = "P6温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P7温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 11,
+    //         dataSid = 3,
+    //         sensorName = "P7温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P8温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 12,
+    //         dataSid = 3,
+    //         sensorName = "P8温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P9温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 9,
+    //         dataSid = 4,
+    //         sensorName = "P9温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P10温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 10,
+    //         dataSid = 4,
+    //         sensorName = "P10温度",
+    //         realtimeValue1 = -1
+    //     });
+    //
+    //     _devicesIdDatas.Add("P12温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 11,
+    //         dataSid = 4,
+    //         sensorName = "P12温度",
+    //         realtimeValue1 = -1
+    //     });
+    //
+    //     _devicesIdDatas.Add("P9", new DevicesId_Data()
+    //     {
+    //         dataGid = 3,
+    //         dataSid = 4,
+    //         sensorName = "P9",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P10", new DevicesId_Data()
+    //     {
+    //         dataGid = 4,
+    //         dataSid = 4,
+    //         sensorName = "P10/UP7",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P11", new DevicesId_Data()
+    //     {
+    //         dataGid = 5,
+    //         dataSid = 4,
+    //         sensorName = "P11/UP8",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add("P12", new DevicesId_Data()
+    //     {
+    //         dataGid = 1,
+    //         dataSid = 4,
+    //         sensorName = "P12/UP9",
+    //         realtimeValue1 = -1
+    //     });
+    //
+    //     _devicesIdDatas.Add("P13", new DevicesId_Data()
+    //     {
+    //         dataGid = 2,
+    //         dataSid = 4,
+    //         sensorName = "P13/UP10",
+    //         realtimeValue1 = -1
+    //     });
+    //
+    //     #endregion
+    //
+    //     #region M
+    //
+    //     //M1-8
+    //     int m_cid = 1;
+    //     int m_did = 5;
+    //     for (int i = 0; i < 8; i++)
+    //     {
+    //         _devicesIdDatas.Add($"M{i + 1}", new DevicesId_Data()
+    //         {
+    //             dataGid = m_cid + i,
+    //             dataSid = m_did,
+    //             sensorName = $"M{i + 1}",
+    //             realtimeValue1 = -1
+    //         });
+    //     }
+    //
+    //     //M温度
+    //     _devicesIdDatas.Add($"M2温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 10,
+    //         dataSid = 5,
+    //         sensorName = $"M2温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add($"M5温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 13,
+    //         dataSid = 5,
+    //         sensorName = $"M5温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add($"M6温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 14,
+    //         dataSid = 5,
+    //         sensorName = $"M6温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add($"M7温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 15,
+    //         dataSid = 5,
+    //         sensorName = $"M7温度",
+    //         realtimeValue1 = -1
+    //     });
+    //     _devicesIdDatas.Add($"M8温度", new DevicesId_Data()
+    //     {
+    //         dataGid = 16,
+    //         dataSid = 5,
+    //         sensorName = $"M8温度",
+    //         realtimeValue1 = -1
+    //     });
+    //
+    //     #endregion
+    // }
 
 }

+ 19 - 5
Assets/Scripts/UI/Data/DevicesId_Data.cs

@@ -1,11 +1,25 @@
 using System;
+using UnityEngine.Serialization;
 
 [Serializable]
 public class DevicesId_Data
 {
-    public string name;
-    public string showName;
-    public int DeviceID;
-    public int ChannelID;
-    public float value;
+    public string sid;
+    public string stationName;//站点名称?
+    [FormerlySerializedAs("name")] public string sensorName;
+    public string sensorType;//设备类型?
+
+
+
+    public string valueType1;//单位
+    public string valueType2;
+    
+    [FormerlySerializedAs("DeviceID")] public int dataSid;
+    [FormerlySerializedAs("ChannelID")] public int dataGid;
+    [FormerlySerializedAs("value")] public float realtimeValue1;
+    public string realtimeValue2;
+    public string dataUpdateTime;
+
+    public string groupId;
+    public string groupName;
 }

+ 5 - 0
Assets/Scripts/UI/Tools/ServerAddress.cs

@@ -70,6 +70,11 @@ public class ServerAddress
     /// </summary>
     public static string API_TaoKou_GetSensorData = "http://10.123.10.11:8300/api/sensor_data?station_name=taokou";
     
+    /// <summary>
+    /// 获取传感器设备列表 套口&补元
+    /// </summary>
+    public static string API_GetAllSensorList = "http://10.123.10.11:9080/open/sensor/list";
+    
     /// <summary>
     /// 补元水闸获取硬件组 最后一条数据
     /// </summary>