123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading.Tasks;
- using UnityAsync;
- using Best.HTTP;
- using Best.HTTP.JSON;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using UnityEngine;
- using UnityEngine.Networking;
- using Unity.VisualScripting;
- using static System.Net.WebRequestMethods;
- public class HttpHelper : MonoBehaviour
- {
- public Action OnSWYJRefresh;
- public static HttpHelper _Instance;
- public static Dictionary<string, DevicesId_Data> _devicesIdDatas_BuYuan = new Dictionary<string, DevicesId_Data>();
- private async void Awake()
- {
- _Instance = this;
- InItBuYuanDevicesList();
- SendBuYuan_GetSensorData();
- GetBuYuanDevicesGroupInfo();
- if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2 || GlobalData.pageIndex == PageIndex.Page3)
- {
- //可以并行,无需等待
- InitYZTData();
- }
- if (GlobalData.pageIndex == PageIndex.Page1)
- {
- //可以并行,无需等待
- InitXHGKData();//已完成迁移
- }
- if (GlobalData.pageIndex == PageIndex.Page1)
- {
- //可以并行,无需等待
- InitGCJKData();
- }
- if (GlobalData.pageIndex == PageIndex.Page1)
- {
- //可以并行,无需等待
- InitXHDDData();
- }
- if (GlobalData.pageIndex == PageIndex.Page1)
- {
- //可以并行,无需等待
- InitRKZYData();
- }
- if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2)
- {
- //可以并行,无需等待
- InitSWYJData();
- }
- if (GlobalData.pageIndex == PageIndex.Page1 || GlobalData.pageIndex == PageIndex.Page2)
- {
- //可以并行,无需等待
- InitGCYWData(0);
- }
- }
- public async Task InitYZTData()
- {
- await InitYZTData1();//已完成迁移
- InitYZTData2();//未完成迁移
- InitYZTData3();//已完成迁移
- }
- public async Task InitYZTData1()
- {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetWaterManagerProject);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.layerUnitDatas = JsonConvert.DeserializeObject<List<LayerUnitData>>(dataToken.ToString());
- }
- else
- {
- Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返序列化失败");
- successInternet = false;
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
- }
- requestData.Dispose();
- if (!successInternet)
- {
- WWW www = new WWW(Application.streamingAssetsPath + "/layerUnitDatas.json");
- await new UnityAsync.WaitUntil(() =>
- {
- return www.isDone;
- });
- GlobalData.layerUnitDatas = JsonConvert.DeserializeObject<List<LayerUnitData>>(www.text);
- www.Dispose();
- }
- for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
- {
- if (GlobalData.layerUnitDatas[i].type == LayerUnitType.JK)
- {
- GlobalData.obsCameraLib.Add(GlobalData.layerUnitDatas[i].name, GlobalData.layerUnitDatas[i].namePri);
- }
- }
- }
- public async Task InitYZTData2()
- {
- bool successInternet = true;
- string sendUrl = ServerAddress.API_GetDevicesInfo;
- sendUrl += "/34020000001180000001/channels?page=1&count=40";
- Debug.Log(sendUrl);
- UnityWebRequest requestData = UnityWebRequest.Get(sendUrl);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("监控数据联网不成功,原因:返request不成功:" + requestData.error);
- successInternet = false;
- }
- else
- {
- Debug.Log(requestData.downloadHandler.text);
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "0")
- {
- GlobalData.obsDatas = new List<ObsData>();
- ServerObsDatas serverObsDatas = JsonConvert.DeserializeObject<ServerObsDatas>(dataToken.ToString());
- for (int i = 0; i < serverObsDatas.list.Count; i++)
- {
- ObsData obsData = new ObsData();
- obsData.name = serverObsDatas.list[i].name;
- obsData.targetName = GlobalData.obsCameraLib[obsData.name];
- // if (i > 0)
- // {
- // obsData.url =
- // "http://www.chatgpt918.top:9080/rtp/34020000001180000001_34020000001310000001/hls.m3u8";
- // }
- // else
- // {
- obsData.url = ServerAddress.ObsSeverM3U8Address + string.Format("/rtp/{0}_{1}/hls.m3u8", serverObsDatas.list[i].deviceId, serverObsDatas.list[i].channelId);
- //}
- obsData.type = obsType.BuYuanObs;
- obsData.deviceId = serverObsDatas.list[i].deviceId;
- obsData.channelId = serverObsDatas.list[i].channelId;
- obsData.status = serverObsDatas.list[i].status;
- GlobalData.obsDatas.Add(obsData);
- }
- }
- else
- {
- Debug.LogWarning("监控数据联网不成功,原因:返序列化失败");
- successInternet = false;
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("监控数据联网不成功,原因:" + e.ToString());
- }
- requestData.Dispose();
- }
- public async Task InitYZTData3()
- {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetWaterHotPoint);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.hotPointDatas = JsonConvert.DeserializeObject<List<HotPointData>>(dataToken.ToString());
- }
- else
- {
- Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:返序列化失败");
- successInternet = false;
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("YZTLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
- }
- requestData.Dispose();
- if (!successInternet)
- {
- WWW www = new WWW(Application.streamingAssetsPath + "/hotPoints.json");
- await new UnityAsync.WaitUntil(() =>
- {
- return www.isDone;
- });
- GlobalData.hotPointDatas = JsonConvert.DeserializeObject<List<HotPointData>>(www.text);
- Debug.Log(GlobalData.hotPointDatas.Count);
- www.Dispose();
- }
- }
- public async Task InitXHGKData()
- {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGetProjectMilestones);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // ȡdata ֶε ֵ
- JToken dataToken = jsonObject["data"];
- //Debug.Log(dataToken.ToString());
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.dsjContents = JsonConvert.DeserializeObject<List<DSJData>>(dataToken.ToString());
- }
- else
- {
- Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返序列化失败");
- successInternet = false;
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
- }
- requestData.Dispose();
- if (!successInternet)
- {
- WWW www = new WWW(Application.streamingAssetsPath + "/dsj.json");
- await new UnityAsync.WaitUntil(() =>
- {
- return www.isDone;
- });
- GlobalData.dsjContents = JsonConvert.DeserializeObject<List<DSJData>>(www.text);
- www.Dispose();
- }
- }
- public async Task InitGCJKData()
- {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeQXZData);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("水文站联网不成功,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.qXZDatas = JsonConvert.DeserializeObject<List<QXZData>>(dataToken.ToString());
- }
- else
- {
- Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
- successInternet = false;
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
- }
- requestData.Dispose();
- successInternet = true;
- UnityWebRequest requestData1 = UnityWebRequest.Get(ServerAddress.APIGetGeSWZData);
- await requestData1.SendWebRequest();
- try
- {
- if (requestData1.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("水文站联网不成功,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData1.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.sWZDatas = JsonConvert.DeserializeObject<List<SWZData>>(dataToken.ToString());
- }
- else
- {
- Debug.LogWarning("水文站联网不成功,原因:返序列化失败");
- successInternet = false;
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("水文站联网不成功,原因:" + e.ToString());
- }
- requestData1.Dispose();
- }
- public async Task InitXHDDData()
- {
- WWW www = new WWW(Application.streamingAssetsPath + "/scheduling.json");
- await new UnityAsync.WaitUntil(() =>
- {
- return www.isDone;
- });
- GlobalData.schedulingData = JsonConvert.DeserializeObject<SchedulingData>(www.text);
- www.Dispose();
- }
- public async Task InitRKZYData()
- {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGetMovePlans);
- await requestData.SendWebRequest();
- try
- {
- if (true)
- {
- Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.allServerMovePlans = JsonConvert.DeserializeObject<List<ServerMovePlan>>(dataToken.ToString());
- }
- else
- {
- successInternet = false;
- Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返序列化失败");
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:" + e.ToString());
- }
- if (!successInternet)
- {
- WWW www = new WWW(Application.streamingAssetsPath + "/moveplan.json");
- await new UnityAsync.WaitUntil(() =>
- {
- return www.isDone;
- });
- GlobalData.allServerMovePlans = JsonConvert.DeserializeObject<List<ServerMovePlan>>(www.text);
- www.Dispose();
- }
- }
- public async Task InitSWYJData()
- {
- InitSWYJData0();
- await InitSWYJData1();
- await InitSWYJData2();
- OnSWYJRefresh?.Invoke();
- }
- public async Task InitSWYJData1()
- {
- GlobalData.BuYuanShuiWeiDataList = new List<ShuiWeiData>();
- var devicesInfo = _devicesIdDatas_BuYuan["上游水位计"];
- string sw1Result = await GetSingleDevicesInfo(devicesInfo.ChannelID, devicesInfo.DeviceID, 24);
- try
- {
- GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(sw1Result);
- if (tempData != null)
- {
- GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
- {
- name = "补元上游水位",
- targetName = "BY_ShuiWei_Up",
- value = tempData.datas[0].NodeValue / 100,
- type = shuiWeiType.BuYuanShuiWei,
- datas = tempData.datas.ToArray()
- });
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("补元上游水位不成功,原因:" + e.ToString());
- }
- var devicesInfo1 = _devicesIdDatas_BuYuan["下游水位计"];
- string sw2Result = await GetSingleDevicesInfo(devicesInfo1.ChannelID, devicesInfo1.DeviceID, 24);
- try
- {
- GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(sw2Result);
- if (tempData != null)
- {
- GlobalData.BuYuanShuiWeiDataList.Add(new ShuiWeiData()
- {
- name = "补元下游水位",
- targetName = "BY_ShuiWei_Down",
- value = tempData.datas[0].NodeValue / 100,
- type = shuiWeiType.BuYuanShuiWei,
- datas = tempData.datas.ToArray()
- });
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("补元下游水位不成功,原因:" + e.ToString());
- }
- string dayResult = await GetSingleDevicesInfo_day(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
- try
- {
- GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(dayResult);
- GlobalData.buYuanShuiWei_day = new ShuiWeiBianHuaData();
- GlobalData.buYuanShuiWei_day.name = new string[6];
- GlobalData.buYuanShuiWei_day.value = new double[6];
- for (int i = 0; i < tempData.datas.Count; i++)
- {
- GlobalData.buYuanShuiWei_day.name[i] = tempData.datas[i].RecvTime;
- GlobalData.buYuanShuiWei_day.value[i] = tempData.datas[i].NodeValue;
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取6天平均数据不成功,原因:" + e.ToString());
- }
- string monthResult = await GetSingleDevicesInfo_month(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
- try
- {
- GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(monthResult);
- GlobalData.buYuanShuiWei_month = new ShuiWeiBianHuaData();
- GlobalData.buYuanShuiWei_month.name = new string[6];
- GlobalData.buYuanShuiWei_month.value = new double[6];
- for (int i = 0; i < tempData.datas.Count; i++)
- {
- GlobalData.buYuanShuiWei_month.name[i] = tempData.datas[i].RecvTime;
- GlobalData.buYuanShuiWei_month.value[i] = tempData.datas[i].NodeValue;
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取6月平均数据不成功,原因:" + e.ToString());
- }
- string hourResult = await GetSingleDevicesInfo_hour(devicesInfo.ChannelID, devicesInfo.DeviceID, 6);
- try
- {
- GetDevicesRequestData tempData = JsonConvert.DeserializeObject<GetDevicesRequestData>(hourResult);
- GlobalData.buYuanShuiWei_hour = new ShuiWeiBianHuaData();
- GlobalData.buYuanShuiWei_hour.name = new string[6];
- GlobalData.buYuanShuiWei_hour.value = new double[6];
- for (int i = 0; i < tempData.datas.Count; i++)
- {
- GlobalData.buYuanShuiWei_hour.name[i] = tempData.datas[i].RecvTime;
- GlobalData.buYuanShuiWei_hour.value[i] = tempData.datas[i].NodeValue;
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取6小时平均数据不成功,原因:" + e.ToString());
- }
- }
- public async Task InitSWYJData2()
- {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeSWData);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("水位高度联网不成功,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.swDatas = JsonConvert.DeserializeObject<List<StationData>>(dataToken.ToString());
- }
- else
- {
- Debug.LogWarning("水位高度联网不成功,原因:返序列化失败");
- successInternet = false;
- }
- for (int i = 0; i < GlobalData.BuYuanShuiWeiDataList.Count; i++)
- {
- StationData stationData = new StationData();
- stationData.LGTD = 113.910187f;
- stationData.LTTD = 30.1765823f;
- stationData.STNM = GlobalData.BuYuanShuiWeiDataList[i].name;
- stationData.upz = GlobalData.BuYuanShuiWeiDataList[i].name.Contains("上") ? GlobalData.BuYuanShuiWeiDataList[i].value : -1;
- stationData.dwz = GlobalData.BuYuanShuiWeiDataList[i].name.Contains("下") ? GlobalData.BuYuanShuiWeiDataList[i].value : -1;
- GlobalData.swDatas.Add(stationData);
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("水位高度联网不成功,原因:" + e.ToString());
- }
- }
- public async Task InitSWYJData0()
- {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetThreeLevel);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("三线水位联网不成功,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- // 提取data字段的值
- JToken dataToken = jsonObject["data"];
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- GlobalData.threeLevelShuiWeiDatas = JsonConvert.DeserializeObject<List<ThreeLevelShuiWeiData>>(dataToken.ToString());
- }
- else
- {
- Debug.LogWarning("三线水位联网不成功,原因:返序列化失败");
- successInternet = false;
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("三线水位联网不成功,原因:" + e.ToString());
- }
- }
- public async Task SendBuYuan_GetSensorData()
- {
- UnityWebRequest www = UnityWebRequest.Get(ServerAddress.API_BuYuan_GetSensorData);
- await www.SendWebRequest();
- try
- {
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("获取补元闸门设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- else
- {
- GlobalData.buYuanSensorData = JsonUtility.FromJson<SensorDataResult>(www.downloadHandler.text);
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取补元闸门设备数据不成功,原因:" + e.ToString());
- }
- www.Dispose();
- }
- public async Task GetBuYuanDevicesGroupInfo()
- {
- //获取所有渗压记
- GetDevicesData tempData = new GetDevicesData();
- tempData.idsList = new List<DevicesMessage>();
- for (int i = 0; i < 13; i++)
- {
- var devicesInfo = _devicesIdDatas_BuYuan[$"P{i + 1}"];
- tempData.idsList.Add(new DevicesMessage()
- {
- DeviceID = devicesInfo.DeviceID,
- ChannelID = devicesInfo.ChannelID
- });
- }
- string jsonStr;
- try
- {
- jsonStr = await Devices(tempData);
- jsonStr = "{\"datas\":" + jsonStr + "}";
- GetDevicesRequestData resultData = JsonUtility.FromJson<GetDevicesRequestData>(jsonStr);
- GlobalData.BuYuanShuiYaDataList = new List<ShuiYaData>();
- for (int i = 0; i < resultData.datas.Count; i++)
- {
- GlobalData.BuYuanShuiYaDataList.Add(new ShuiYaData()
- {
- name = resultData.datas[i].NodeName,
- value = resultData.datas[i].NodeValue,
- type = shuiYaType.BuYuanShuiYa,
- targetName = $"BY_{resultData.datas[i].NodeName}"
- });
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取补元水压计设备数据不成功,原因:" + e.ToString());
- throw;
- }
- //获取所有位移记
- tempData = new GetDevicesData();
- tempData.idsList = new List<DevicesMessage>();
- for (int i = 0; i < 8; i++)
- {
- var devicesInfo = _devicesIdDatas_BuYuan[$"M{i + 1}"];
- tempData.idsList.Add(new DevicesMessage()
- {
- DeviceID = devicesInfo.DeviceID,
- ChannelID = devicesInfo.ChannelID
- });
- }
- try
- {
- jsonStr = await Devices(tempData);
- jsonStr = "{\"datas\":" + jsonStr + "}";
- GetDevicesRequestData resultData = JsonUtility.FromJson<GetDevicesRequestData>(jsonStr);
- GlobalData.BuYuanWeiYiDataList = new List<WeiYiData>();
- for (int i = 0; i < resultData.datas.Count; i++)
- {
- GlobalData.BuYuanWeiYiDataList.Add(new WeiYiData()
- {
- name = resultData.datas[i].NodeName,
- value = resultData.datas[i].NodeValue,
- type = weiYiType.BuYuanWeiYi,
- targetName = $"BY_{resultData.datas[i].NodeName}"
- });
- }
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取补元位移计设备数据不成功,原因:" + e.ToString());
- throw;
- }
- }
- /// <summary>
- /// 获取补元硬件组数据
- /// </summary>
- /// <param name="sendData"></param>
- /// <returns></returns>
- public async Task<string> Devices(GetDevicesData sendData)
- {
- string cmdUrl = ServerAddress.API_BuYuan_GetDevicesGroupInfo;
- string tempStr = JsonConvert.SerializeObject(sendData);
- var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
- UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
- www.uploadHandler = new UploadHandlerRaw(sendByte);
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning($"获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
- /// <summary>
- /// 获取设备的最近N条记录
- /// </summary>
- /// <param name="channelId"></param>
- /// <param name="deviceId"></param>
- /// <param name="count"></param>
- /// <returns></returns>
- public async Task<string> GetSingleDevicesInfo(int channelId, int deviceId, int count)
- {
- string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo;
- GetSingleDeviceData sendData = new GetSingleDeviceData();
- sendData.ChannelID = channelId;
- sendData.DeviceID = deviceId;
- sendData.N = count;
- string tempStr = JsonConvert.SerializeObject(sendData);
- var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
- UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
- www.uploadHandler = new UploadHandlerRaw(sendByte);
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("获取设备数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
- /// <summary>
- /// 获取设备最近几天的平均数据
- /// </summary>
- /// <param name="channelId"></param>
- /// <param name="deviceId"></param>
- /// <param name="count"></param>
- /// <returns></returns>
- public async Task<string> GetSingleDevicesInfo_day(int channelId, int deviceId, int count)
- {
- string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
- GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
- sendData.ChannelID = channelId;
- sendData.DeviceID = deviceId;
- sendData.AvgType = "day";
- sendData.N = count;
- string tempStr = JsonConvert.SerializeObject(sendData);
- var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
- UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
- www.uploadHandler = new UploadHandlerRaw(sendByte);
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("获取设备天平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
- /// <summary>
- /// 获取设备最近几小时的平均数据
- /// </summary>
- /// <param name="channelId"></param>
- /// <param name="deviceId"></param>
- /// <param name="count"></param>
- /// <returns></returns>
- public async Task<string> GetSingleDevicesInfo_hour(int channelId, int deviceId, int count)
- {
- string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
- GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
- sendData.ChannelID = channelId;
- sendData.DeviceID = deviceId;
- sendData.AvgType = "hour";
- sendData.N = count;
- string tempStr = JsonConvert.SerializeObject(sendData);
- var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
- UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
- www.uploadHandler = new UploadHandlerRaw(sendByte);
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("获取设备小时平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
- /// <summary>
- /// 获取设备最近几个月的平均数据
- /// </summary>
- /// <param name="channelId"></param>
- /// <param name="deviceId"></param>
- /// <param name="count"></param>
- /// <returns></returns>
- public async Task<string> GetSingleDevicesInfo_month(int channelId, int deviceId, int count)
- {
- string cmdUrl = ServerAddress.API_BuYuan_GetSingleDevicesInfo_avg;
- GetSingleDeviceData_AvgType sendData = new GetSingleDeviceData_AvgType();
- sendData.ChannelID = channelId;
- sendData.DeviceID = deviceId;
- sendData.AvgType = "month";
- sendData.N = count;
- string tempStr = JsonConvert.SerializeObject(sendData);
- var sendByte = System.Text.Encoding.UTF8.GetBytes(tempStr);
- UnityWebRequest www = new UnityWebRequest(cmdUrl, "POST");
- www.uploadHandler = new UploadHandlerRaw(sendByte);
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("获取设备月平均数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
- /// <summary>
- /// 0 补元 1套口
- /// </summary>
- /// <param name="type"></param>
- public async Task InitGCYWData(int type)
- {
- GlobalData.B08_Type = type;
- string jsonStr;
- try
- {
- jsonStr = await B08_API_data(ServerAddress.API_B08_dataStatis,type);
- Debug.Log("API_B08_dataStatis" + jsonStr);
- GlobalData.B08DataStatis = JsonConvert.DeserializeObject<B08_dataStatis>(jsonStr);
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取API_B08_dataStatis数据不成功,原因:" + e.ToString());
- }
- try
- {
- jsonStr = await B08_API_data(ServerAddress.API_B08_inspectResult,type);
- Debug.Log("API_B08_inspectResult" + jsonStr);
- GlobalData.B08InspectResult = JsonConvert.DeserializeObject<B08_inspectResult>(jsonStr);
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取API_B08_inspectResult数据不成功,原因:" + e.ToString());
- }
- try
- {
- jsonStr = await B08_API_data(ServerAddress.API_B08_projectExamine,type);
- Debug.Log("API_B08_projectExamine" + jsonStr);
- GlobalData.B08ProjectExamine = JsonConvert.DeserializeObject<B08_projectExamine>(jsonStr);
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取API_B08_projectExamine数据不成功,原因:" + e.ToString());
- }
- try
- {
- jsonStr = await B08_API_data(ServerAddress.API_B08_event,type);
- Debug.Log("API_B08_event" + jsonStr);
- GlobalData.B08Event = JsonConvert.DeserializeObject<B08_event>(jsonStr);
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取API_B08_event数据不成功,原因:" + e.ToString());
- }
- try
- {
- jsonStr = await B08_API_data(ServerAddress.API_B08_questionStatis,type);
- Debug.Log("API_B08_questionStatis" + jsonStr);
- GlobalData.B08QuestionStatis = JsonConvert.DeserializeObject<B08_questionStatis>(jsonStr);
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取API_B08_questionStatis数据不成功,原因:" + e.ToString());
- }
- try
- {
- jsonStr = await B08_API_data(ServerAddress.API_B08_inspectType,type);
- Debug.Log("API_B08_inspectType" + jsonStr);
- GlobalData.B08InspectType = JsonConvert.DeserializeObject<B08_inspectType>(jsonStr);
- }
- catch (Exception e)
- {
- Debug.LogWarning("获取API_B08_inspectType数据不成功,原因:" + e.ToString());
- }
- }
- public async Task<string> B08_API_data(string cmdUrl,int type)
- {
- if (type == 0)
- {
- cmdUrl += "1794245918999351298";
- }
- else
- {
- cmdUrl += "1798366756789653505";
- }
- UnityWebRequest www = new UnityWebRequest(cmdUrl, "Get");
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning($"获取{cmdUrl}数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
-
- /// <summary>
- /// 获取站点水位信息
- /// </summary>
- /// <param name="stcd"></param>
- /// <returns></returns>
- public async Task<string> GetWaterTrend_Chart(string stcd)
- {
- UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_chart+stcd, "Get");
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
- public async Task<string> GetWaterTrend_List(string stcd)
- {
- UnityWebRequest www = new UnityWebRequest(ServerAddress.API_GetWaterTrend_list+stcd, "Get");
- www.downloadHandler = new DownloadHandlerBuffer();
- www.SetRequestHeader("Content-Type", "application/json");
- await www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning($"获取stcd:{stcd},水位统计信息数据不成功,原因:返request不成功:" + www.downloadHandler.text);
- }
- string result = www.downloadHandler.text;
- www.Dispose();
- return result;
- }
- public void SaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
- {
- StartCoroutine(SendSaveFirstFrame(uploadData, fileName, _targetName));
- }
- IEnumerator SendSaveFirstFrame(byte[] uploadData, string fileName, string _targetName)
- {
- Debug.Log(fileName);
- WWWForm form = new WWWForm();
- form.AddBinaryData("file", uploadData, fileName);
- UnityWebRequest www = UnityWebRequest.Post(ServerAddress.API_TextureUploadPath, form);
- yield return www.SendWebRequest();
- if (www.result == UnityWebRequest.Result.Success)
- {
- ActionInstance._Instance.obsFmUpdata?.Invoke(_targetName);
- }
- Debug.Log(www.downloadHandler.text);
- www.Dispose();
- }
- #region 摄像头远程控制
- public void GetDeviceChannelId(string deviceId, Action<string> callBack)
- {
- StartCoroutine(SendGetDevicesChannel(deviceId, 1, 1, callBack));
- }
- IEnumerator SendGetDevicesChannel(string deviceId, int page, int count, Action<string> call)
- {
- string sendUrl = ServerAddress.API_GetDevicesInfo;
- sendUrl += $"/{deviceId}/channels?page={page}&count={count}&query&online&channelType&catalogUnderDevice";
- UnityWebRequest www = UnityWebRequest.Get(sendUrl);
- yield return www.SendWebRequest();
- ObsHttpRequestData tempData = JsonConvert.DeserializeObject<ObsHttpRequestData>(www.downloadHandler.text);
- GetObsChannelRequestData channelData = tempData.data.ToObject<GetObsChannelRequestData>();
- call?.Invoke(channelData.list[0].channelId);
- www.Dispose();
- }
- IEnumerator SendStartRTSP(string deviceId, string channelId)
- {
- string sendUrl = ServerAddress.API_PlayStart;
- sendUrl += $"/{deviceId}/{channelId}";
- UnityWebRequest www = UnityWebRequest.Get(sendUrl);
- yield return www.SendWebRequest();
- Debug.Log(www.downloadHandler.text);
- www.Dispose();
- }
- public void SendObsCameraCtrlCmd(string deviceId, string channelId, ObsCtrlType type)
- {
- StartCoroutine(SendCameraCtrl(deviceId, channelId, type.ToString()));
- }
- IEnumerator SendCameraCtrl(string deviceId, string channelId, string command)
- {
- string sendUrl = ServerAddress.API_CameraCtrl;
- sendUrl += $"/{deviceId}/{channelId}?command={command}&horizonSpeed=10&verticalSpeed=10&zoomSpeed=10";
- UnityWebRequest www = UnityWebRequest.Post(sendUrl, "");
- Debug.Log("send:" + sendUrl);
- yield return www.SendWebRequest();
- Debug.Log(www.downloadHandler.text);
- www.Dispose();
- }
- #endregion
- /// <summary>
- /// 初始化所有补元硬件设备的获取信息
- /// </summary>
- public void InItBuYuanDevicesList()
- {
- _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()
- {
- ChannelID = 1,
- DeviceID = 4,
- name = "P12/UP9",
- showName = "",
- value = -1
- });
- _devicesIdDatas_BuYuan.Add("P13", new DevicesId_Data()
- {
- 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++)
- {
- _devicesIdDatas_BuYuan.Add($"M{i + 1}", new DevicesId_Data()
- {
- ChannelID = m_cid + i,
- DeviceID = m_did,
- name = $"M{i + 1}",
- showName = "",
- value = -1
- });
- }
- //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
- }
- }
|