12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331 |
- 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].name_pri);
- }
- }
- }
- 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.json");
- await new UnityAsync.WaitUntil(() =>
- {
- return www.isDone;
- });
- GlobalData.hotPointDatas = JsonConvert.DeserializeObject<List<HotPointData>>(www.text);
- 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
- }
- }
|