| | |
| | | { |
| | | //修改主页连接状态 |
| | | HomePage.LoadEvent_CheckLinkStatus(); |
| | | MainPage.Log($"网关局域网在线,刷新设备状态"); |
| | | //MainPage.Log($"网关局域网在线,刷新设备状态"); |
| | | new System.Threading.Thread(() => |
| | | { |
| | | System.Threading.Thread.Sleep(1000); |
| | |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"状态一致,不更新数据(本地)"); |
| | | //MainPage.Log($"状态一致,不更新数据(本地)"); |
| | | } |
| | | } |
| | | } |
| | |
| | | while (true) |
| | | { |
| | | System.Threading.Thread.Sleep(500); |
| | | if (MqttClient.isSubscribeSuccess || count<1) |
| | | if (MqttClient.isSubscribeSuccess || count < 1) |
| | | { |
| | | break; |
| | | } |
| | |
| | | { |
| | | MainPage.Log($"状态一致,不更新数据(云端)"); |
| | | } |
| | | }catch(Exception ex) |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"Set GatewayCloudOnline Error:{ex.Message}"); |
| | | } |
| | |
| | | /// </summary> |
| | | public void OpenTcpClent() |
| | | { |
| | | return; |
| | | if (myTcpClient == null) |
| | | { |
| | | myTcpClient = new Control_TcpClient(reportIp); |
| | | myTcpClient = new Control_TcpClient(reportIp, 8586); |
| | | } |
| | | myTcpClient.Connect(); |
| | | MainPage.Log("打开tcp"); |
| | | myTcpClient.init(); |
| | | Ins.LoginGateway(); |
| | | |
| | | } |
| | | |
| | |
| | | public void SearchLoaclGateway() |
| | | { |
| | | //2021-01-15 : 住宅没有绑定网关的时候不用搜索,并且不能链接mqtt |
| | | if (DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId) || |
| | | !UserInfo.Current.IsLogin) |
| | | if (DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId)) |
| | | { |
| | | return; |
| | | } |
| | |
| | | } |
| | | else if (MainPage.InternetStatus == 1) |
| | | { |
| | | DAL.Mqtt.MqttClient.InitState(); |
| | | MqttClient.InitState(); |
| | | } |
| | | else if (MainPage.InternetStatus == 2) |
| | | { |
| | | DAL.Mqtt.MqttClient.InitState(); |
| | | MqttClient.InitState(); |
| | | OpenUdp(DB_ResidenceData.Instance.GatewayType == 0 ? 6000 : 8585); |
| | | //重置搜索网关标志 |
| | | IsSearchLocalGatewaySuccessful = false; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private System.Threading.Thread loginGatewayThread; |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public void LoginGateway() |
| | | { |
| | | return;//tcp控制存在问题,但是先不用tcp控制了,要经过测试先 2023-07-29 10:14:32 |
| | | if (loginGatewayThread == null) |
| | | if (loginGatewayThread == null && !LocalTcpClientLogin) |
| | | { |
| | | loginGatewayThread = new System.Threading.Thread(() => |
| | | { |
| | | while (!Ins.myTcpClient.isConnected) |
| | | if (Ins.GatewayOnline_Local) |
| | | { |
| | | if (Ins.GatewayOnline_Local && myTcpClient.isConnected) |
| | | while (!LocalTcpClientLogin) |
| | | { |
| | | var sendData = new { clientType = "app", version = "1.0" }; |
| | | var sendJob = new { id = Control.Ins.msg_id.ToString(), time_stamp = Utlis.GetTimestamp(), objects = sendData }; |
| | | |
| | | var bodyString = JsonConvert.SerializeObject(sendJob); |
| | | |
| | | var sendBytes = ConvertSendBodyData($"/user/{GatewayId}/custom/gateway/login", bodyString); |
| | | |
| | | Ins.myTcpClient.SendMessage(sendBytes); |
| | | Ins.myTcpClient.CommSend(sendBytes, sendBytes.Length); |
| | | System.Threading.Thread.Sleep(1000); |
| | | } |
| | | System.Threading.Thread.Sleep(2000); |
| | | } |
| | | //loginGatewayThread?.Abort(); |
| | | //loginGatewayThread = null; |
| | | |
| | | }); |
| | | loginGatewayThread.Start(); |
| | | } |
| | | else |
| | | { |
| | | try |
| | | { |
| | | loginGatewayThread?.Abort(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"重启登录网关线程异常:{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | loginGatewayThread = null; |
| | | LoginGateway(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | asd.status = status1; |
| | | upDataObj.objects.Add(asd); |
| | | revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj); |
| | | revString = JsonConvert.SerializeObject(upDataObj); |
| | | UpdataFunctionStatus(revString, null, true); |
| | | } |
| | | return; |
| | |
| | | |
| | | |
| | | //如果是控制调光的开时,亮度值不能为0 |
| | | if (commandDictionary.Count > 2) |
| | | if (commandDictionary.Count >= 2) |
| | | { |
| | | if (commandDictionary.ContainsKey(FunctionAttributeKey.OnOff) && commandDictionary.ContainsKey(FunctionAttributeKey.Brightness)) |
| | | { |
| | |
| | | } |
| | | asd.status = status1; |
| | | upDataObj.objects.Add(asd); |
| | | revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj); |
| | | revString = JsonConvert.SerializeObject(upDataObj); |
| | | UpdataFunctionStatus(revString, null, true); |
| | | return true; |
| | | } |
| | | |
| | | //MainPage.Log($"发送数据:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}"); |
| | | //MainPage.Log($"发送数据:{JsonConvert.SerializeObject(commandDictionary)}"); |
| | | |
| | | ///第三方涂鸦设备统一使用远程控制 |
| | | switch (function.spk) |
| | |
| | | else |
| | | { |
| | | var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary); |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); |
| | | var functionControlDataJson = JsonConvert.SerializeObject(functionControlDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, resend); |
| | | MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}"); |
| | | //Ins.myTcpClient.SendMessage(sendBytes); |
| | | //Ins.myTcpClient.SendMessage(sendBytes); |
| | | } |
| | | } |
| | | //远程通讯 |
| | |
| | | { |
| | | foreach (var temp in functions) |
| | | { |
| | | if((temp.trait_on_off.state.ToString() == "on" && open)|| temp.trait_on_off.state.ToString() == "off"&& !open) |
| | | if ((temp.trait_on_off.state.ToString() == "on" && open) || temp.trait_on_off.state.ToString() == "off" && !open) |
| | | { |
| | | continue; |
| | | } |
| | |
| | | if (pack != null && pack.Data != null) |
| | | { |
| | | //待测试2021-03-04 |
| | | var ddd = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AlinkStatusData>>(pack.Data.ToString()); |
| | | var ddd = JsonConvert.DeserializeObject<List<AlinkStatusData>>(pack.Data.ToString()); |
| | | if (ddd != null) |
| | | { |
| | | foreach (var function in ddd) |
| | |
| | | }, |
| | | time_stamp = Utlis.GetTimestamp() |
| | | }; |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); |
| | | var functionControlDataJson = JsonConvert.SerializeObject(readDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson); |
| | | MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}"); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id); |
| | |
| | | try |
| | | { |
| | | pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); |
| | | }catch(Exception ex) |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"远程读取设备状态异常:{ex.Message}"); |
| | | } |
| | |
| | | objects = objects, |
| | | time_stamp = Utlis.GetTimestamp() |
| | | }; |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); |
| | | var functionControlDataJson = JsonConvert.SerializeObject(readDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson); |
| | | MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}"); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id); |
| | |
| | | }, |
| | | time_stamp = Utlis.GetTimestamp() |
| | | }; |
| | | var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData); |
| | | var aLinkJson = JsonConvert.SerializeObject(aLinkData); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlSeurity, aLinkJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id); |
| | | } |
| | |
| | | objects = objects, |
| | | time_stamp = Utlis.GetTimestamp() |
| | | }; |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); |
| | | var functionControlDataJson = JsonConvert.SerializeObject(readDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData($"/base/{DB_ResidenceData.Instance.HomeGateway.gatewayId}/thing/service/MusicPlayGroupListGet/down", functionControlDataJson); |
| | | MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}"); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id); |
| | |
| | | /// </summary> |
| | | public void AuthGateway() |
| | | { |
| | | MainPage.Log($"网关进入配网模式"); |
| | | var objects1 = new { spk = "", time = "180" }; |
| | | //{"objects":[{"spk":"","time":"180"}],"id":"8","time_stamp":"1635241216669"} |
| | | var sendId = Ins.msg_id.ToString(); |
| | | var sendObj = new { objects = objects1, id = sendId, time_stamp = Utlis.GetTimestamp() }; |
| | | |
| | | var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(sendObj); |
| | | var aLinkJson = JsonConvert.SerializeObject(sendObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.AuthGateway, aLinkJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, Ins.msg_id.ToString()); |
| | | } |
| | |
| | | /// <returns></returns> |
| | | public byte[] ConvertSendBodyData(string topic, string bodyDataString, bool isEncryption = true) |
| | | { |
| | | //string topicString = "Topic:" + topic + "\r\n"; |
| | | //byte[] bodyBytes = Encoding.ASCII.GetBytes(bodyDataString); |
| | | //string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n"; |
| | | |
| | | //string sendDataString = topicString + lengthString + bodyDataString; |
| | | //byte[] sendDataBytes = Encoding.ASCII.GetBytes(sendDataString); |
| | | //MainPage.Log($"转换HDL-Link数据\r\n{sendDataString}\r\n"); |
| | | |
| | | //*************************************************************** |
| | | //2021-09-23 增加本地通信加密处理 |
| | | //1.拼接头 |
| | |
| | | if (isEncryption && IsLocalEncryptAndGetAesKey) |
| | | { |
| | | bodyBytes = Securitys.EncryptionService.AesEncryptPayload(bodyBytes, DB_ResidenceData.Instance.CurrentRegion.localSecret); |
| | | //bodyDataString = Encoding.UTF8.GetString(bodyBytes); |
| | | //MainPage.Log($"转换HDL-Link数据 加密key:" + DB_ResidenceData.Instance.CurrentRegion.localSecret); |
| | | } |
| | | //3.拼接body的Length长度数据 |
| | | string lengthString = "Length:" + bodyBytes.Length.ToString() + "\r\n" + "\r\n"; |
| | |
| | | bodyBytes.CopyTo(sendDataBytes, topicAndLengthBytes.Length); |
| | | |
| | | var sendDataString = Encoding.UTF8.GetString(sendDataBytes); |
| | | MainPage.Log($"转换HDL-Link数据\r\n{sendDataString}\r\n"); |
| | | //*************************************************************** |
| | | |
| | | return sendDataBytes; |
| | |
| | | /// <returns></returns> |
| | | public void ConvertReceiveData(byte[] receiveBytes, string ip) |
| | | { |
| | | if (!UserInfo.Current.IsLogin) |
| | | { |
| | | return; |
| | | } |
| | | var reString = Encoding.UTF8.GetString(receiveBytes); |
| | | AnalysisReceiveData(reString, receiveBytes, ip); |
| | | } |
| | |
| | | /// <returns></returns> |
| | | public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes, string sIp = null) |
| | | { |
| | | |
| | | LocalCommunicationData receiveObj = new LocalCommunicationData(); |
| | | |
| | | |
| | | var res = receiveString.Split("\r\n\r\n"); |
| | | |
| | | if (res.Length == 2) |
| | | { |
| | | var topics = res[0].Split("\r\n"); |
| | | //MainPage.Log(res[1]); |
| | | foreach (var ts in topics) |
| | | { |
| | | var key = ts.Split(":"); |
| | |
| | | } |
| | | } |
| | | |
| | | //MainPage.Log($"局域网信息: {receiveObj.Topic} : 内容: {res[1]}"); |
| | | |
| | | //验证有效数据长度 |
| | | //if (res[1].Length != receiveObj.Length) |
| | | //{ |
| | | // MainPage.Log($"收到数据包长度不够"); |
| | | // return receiveObj; |
| | | //} |
| | | receiveObj.BodyDataString = res[1]; |
| | | |
| | | ///UDP不出tcp心跳包 |
| | | if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply") |
| | | { |
| | | //Ins.myTcpClient.ClearHeartBeatLog(); |
| | | MainPage.Log("tcp心跳回复"); |
| | | return null; |
| | | } |
| | | |
| | |
| | | { |
| | | var revString = Encoding.UTF8.GetString(receiveBytes); |
| | | receiveObj.BodyDataString = revString; |
| | | MainPage.Log($"局域网信息: 解密后:" + receiveObj.BodyDataString); |
| | | //if (receiveObj.Topic.EndsWith("/thing/property/up")) |
| | | //{ |
| | | // MsgInfoList.Add(revString + "\r\n"); |
| | | //} |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //目前不拿原始Bytes数据 解密不了 |
| | | //byte[] receiveBytes = Encoding.UTF8.GetBytes(res[1]); |
| | | //MainPage.Log($"局域网信息 receiveBytes {receiveBytes.Length}"); |
| | | //receiveBytes = Securitys.EncryptionService.AesDecryptPayload(receiveBytes, DB_ResidenceData.Instance.CurrentRegion.localSecret); |
| | | //MainPage.Log($"局域网信息 解密后:receiveBytes {receiveBytes.Length}"); |
| | | //var revString = Encoding.UTF8.GetString(receiveBytes); |
| | | //receiveObj.BodyDataString = revString; |
| | | //MainPage.Log($"局域网信息: 解密后:" + receiveObj.BodyDataString); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"局域网信息: 明文:" + receiveObj.BodyDataString); |
| | | } |
| | | if (receiveObj.BodyDataString == null) |
| | | { |
| | | MainPage.Log($"UDP receiveObj.BodyDataString == null"); |
| | | return null; |
| | | } |
| | | |
| | | try |
| | | { |
| | | var idMsg = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); |
| | | var idMsg = JsonConvert.DeserializeObject<ResponsePack>(receiveObj.BodyDataString); |
| | | var hasProcess = hasItBeenProcessed(idMsg.id); |
| | | if (hasProcess) |
| | | { |
| | | return null; |
| | | if (receiveObj.Topic != CommunicationTopic.SearchLoaclGatewayReply) |
| | | { |
| | | //MainPage.Log($"UDP不处理重复数据:{idMsg.id}"); |
| | | return null; |
| | | } |
| | | } |
| | | MainPage.Log($"处理局域网数据id:{idMsg.id}"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"解析局域网数据异常{ex.Message}"); |
| | | MainPage.Log($"解析数据异常:{ex.StackTrace}\r\n<<-->>{receiveObj.BodyDataString}"); |
| | | } |
| | | |
| | | MainPage.Log($"UDP处理数据:Topic:{receiveObj.Topic}===Context====" + receiveObj.BodyDataString); |
| | | |
| | | if (receiveObj.Topic == CommunicationTopic.SearchLoaclGatewayReply || receiveObj.Topic == CommunicationTopic.GatewayBroadcast) |
| | | { |
| | | |
| | | var bodyJObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack>(res[1]); |
| | | var bodyJObj = JsonConvert.DeserializeObject<ResponsePack>(res[1]); |
| | | if (bodyJObj == null) |
| | | { |
| | | return receiveObj; |
| | | } |
| | | |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); |
| | | var device = JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); |
| | | if (device.device_mac.ToUpper() == DB_ResidenceData.Instance.HomeGateway.mac.ToUpper()) |
| | | { |
| | | MainPage.Log("本地搜索网关成功"); |
| | | MainPage.Log("网关本地在线"); |
| | | Ins.IsSearchLocalGatewaySuccessful = true; |
| | | Ins.GatewayOnline_Local = true; |
| | | if (!string.IsNullOrEmpty(device.gatewayId)) |
| | |
| | | reportIp = device.ip_address;//主播地址也能控制设备//"239.0.168.188";// |
| | | //2021-09-23 新增获取当前网关是否本地加密 |
| | | Ins.IsLocalEncrypt = device.isLocalEncrypt; |
| | | //MainPage.Log("网关本地加密状态:" + device.local_encrypt.ToString()); |
| | | //登录网关Tcp |
| | | //OpenTcpClent(); |
| | | |
| | | //登录网关Tcp tcp连接网关 |
| | | OpenTcpClent(); |
| | | |
| | | } |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.ControlGroupControlTopic + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.ControlGroupControlTopic + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus || |
| | | receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic)) |
| | | { |
| | | //TODO 暂时不传正确的数据上去,如果后面要优化前面这些代码 |
| | | //Console.WriteLine($"{receiveObj.Topic}\r\n{receiveObj.BodyDataString}"); |
| | | UpdataFunctionStatus(receiveObj.BodyDataString, null); |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity + "_reply" |
| | |
| | | { |
| | | try |
| | | { |
| | | MainPage.Log($"局域网安防信息: {receiveObj.Topic} : 内容: {res[1]}"); |
| | | var tt = ""; |
| | | lock (tt) |
| | | { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString); |
| | | var temp = JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString); |
| | | if (temp != null) |
| | | { |
| | | Control_Udp.ReceiveRepeatManager(temp.id, null); |
| | |
| | | } |
| | | else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") |
| | | { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString); |
| | | var temp = JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString); |
| | | if (temp.GetValue("objects").ToString().Contains("success")) |
| | | { |
| | | LocalTcpClientLogin = true; |
| | |
| | | return receiveObj; |
| | | } |
| | | |
| | | public LocalCommunicationData AnalysisReceiveData(string topic, byte[] bodyBytes) |
| | | { |
| | | LocalCommunicationData receiveObj = new LocalCommunicationData(); |
| | | receiveObj.Topic = topic; |
| | | |
| | | if (receiveObj.Topic == CommunicationTopic.ct.HeartBeat + "_reply") |
| | | { |
| | | Ins.myTcpClient.ClearHeartBeatLog(); |
| | | MainPage.Log("tcp心跳回复"); |
| | | return null; |
| | | } |
| | | |
| | | //2021-09-23 过滤不需要解密的主题 目前搜索网关主题不加密 |
| | | if (receiveObj.Topic != CommunicationTopic.SearchLoaclGatewayReply) |
| | | { |
| | | //判断当前网关是否开启了本地加密 |
| | | if (IsLocalEncryptAndGetAesKey) |
| | | { |
| | | byte[] receiveBytes = Securitys.EncryptionService.AesDecryptPayload(bodyBytes, DB_ResidenceData.Instance.CurrentRegion.localSecret); |
| | | if (receiveBytes != null) |
| | | { |
| | | receiveObj.BodyDataString = Encoding.UTF8.GetString(receiveBytes); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | receiveObj.BodyDataString = Encoding.UTF8.GetString(bodyBytes); |
| | | } |
| | | |
| | | if (receiveObj.BodyDataString == null) |
| | | { |
| | | MainPage.Log($"TCP receiveObj.BodyDataString == null"); |
| | | return null; |
| | | } |
| | | |
| | | try |
| | | { |
| | | var idMsg = JsonConvert.DeserializeObject<ResponsePack>(receiveObj.BodyDataString); |
| | | var hasProcess = hasItBeenProcessed(idMsg.id); |
| | | if (hasProcess) |
| | | { |
| | | //MainPage.Log($"TCP不处理重复数据{idMsg.id}"); |
| | | return null; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"解析数据异常:{ex.StackTrace}\r\n<<-->>{receiveObj.BodyDataString}"); |
| | | } |
| | | MainPage.Log($"TCP处理数据:Topic:{receiveObj.Topic}===Context====" + receiveObj.BodyDataString); |
| | | |
| | | |
| | | if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.ControlFunctionTopic + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.ControlGroupControlTopic + "_reply" || |
| | | receiveObj.Topic == CommunicationTopic.ct.GatewayUpStatus || |
| | | receiveObj.Topic.Contains(CommunicationTopic.ct.GatewayUpSortTopic)) |
| | | { |
| | | UpdataFunctionStatus(receiveObj.BodyDataString, null); |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ControlSeurity + "_reply" |
| | | || receiveObj.Topic == CommunicationTopic.ct.ReadSecurityStatus + "_reply" |
| | | || receiveObj.Topic == CommunicationTopic.ct.SecurityStatusUp) |
| | | { |
| | | try |
| | | { |
| | | var tt = ""; |
| | | lock (tt) |
| | | { |
| | | var temp = JsonConvert.DeserializeObject<SecurityStatusObj>(receiveObj.BodyDataString); |
| | | if (temp != null) |
| | | { |
| | | Control_Udp.ReceiveRepeatManager(temp.id, null); |
| | | foreach (var updataSecurity in temp.objects) |
| | | { |
| | | var updataLocalSecurity = FunctionList.List.securities.Find((obj) => obj.sid == updataSecurity.sid); |
| | | if (updataLocalSecurity != null) |
| | | { |
| | | updataLocalSecurity.status = updataSecurity.status; |
| | | updataLocalSecurity.alarm = updataSecurity.alarm; |
| | | ArmCenterPage.LoadEvent_RefreshSecurityStatus(updataLocalSecurity); |
| | | } |
| | | } |
| | | HomePage.LoadEvent_RefreshSecurityStatus(); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"安防局域网异常:{ex.Message}"); |
| | | } |
| | | } |
| | | else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") |
| | | { |
| | | var temp = JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString); |
| | | if (temp.GetValue("objects").ToString().Contains("success")) |
| | | { |
| | | LocalTcpClientLogin = true; |
| | | try |
| | | { |
| | | loginGatewayThread?.Abort(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"终止登录网关tcp异常:{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | loginGatewayThread = null; |
| | | } |
| | | MainPage.Log("局域网tcp连接登录网关成功"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //一些特殊的主题处理(为了执行速度,尽可能的别加耗时的操作) |
| | | Stan.HdlCloudReceiveLogic.Current.CloudOverallMsgReceiveEx(receiveObj.Topic, receiveObj.BodyDataString); |
| | | } |
| | | return receiveObj; |
| | | } |
| | | |
| | | |
| | | private List<string> processedDataList = new List<string>(); |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | private bool hasItBeenProcessed(string msgId) |
| | | { |
| | | if (processedDataList.Contains(msgId)) |
| | | lock (processedDataList) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | if (processedDataList.Count > 50) |
| | | if (processedDataList.Contains(msgId)) |
| | | { |
| | | processedDataList.RemoveAt(0); |
| | | return true; |
| | | } |
| | | return false; |
| | | else |
| | | { |
| | | processedDataList.Add(msgId); |
| | | if (processedDataList.Count > 50) |
| | | { |
| | | processedDataList.RemoveAt(0); |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if (FunctionList.List.OtherBrandFunction.Count == 0) |
| | | { |
| | | MainPage.Log($"A协议更新状态:本地链接,除了涂鸦设备数据之外的云端数据不处理..."); |
| | | //MainPage.Log($"A协议更新状态:本地链接,除了涂鸦设备数据之外的云端数据不处理..."); |
| | | return; |
| | | } |
| | | else |
| | |
| | | { |
| | | continue; |
| | | } |
| | | MainPage.Log(localFunction.name); |
| | | |
| | | //if (SPK.MusicSpkList().Contains(localFunction.spk)) |
| | | //{ |
| | |
| | | // return; |
| | | // } |
| | | //} |
| | | MainPage.Log($"收到数据:{revString}"); |
| | | //MainPage.Log($"收到数据:{revString}"); |
| | | foreach (var attr in updateTemp.status) |
| | | { |
| | | localFunction.time_stamp = temp.time_stamp; |
| | | localFunction.SetAttrState(attr.key, attr.value); |
| | | |
| | | |
| | | } |
| | | if(localFunction.spk == SPK.AirSwitchP3) |
| | | if (localFunction.spk == SPK.AirSwitchP3) |
| | | { |
| | | localFunction.online = updateTemp.online; |
| | | } |
| | |
| | | { |
| | | localFunction.updateTime = DateTime.Now; |
| | | } |
| | | |
| | | |
| | | |
| | | //更新界面状态 |
| | | switch (localFunction.spk) |
| | |
| | | AcstParentPage.UpdateAcstSubInfo(localFunction); |
| | | AcstSubPage.UpdateStatus(localFunction); |
| | | break; |
| | | //case SPK.WaterHeaterJinmao: |
| | | // AcstParentPage.UpdateAcstSubInfo(localFunction); |
| | | // WaterHeaterJinmaoPage.UpdateStatus(); |
| | | // break; |
| | | //case SPK.InverterJinmao: |
| | | // InverterJinmaoPage.UpdateStatus(localFunction); |
| | | // break; |
| | | case SPK.AirSwitch: |
| | | AirSwitchPage.UpdataState(localFunction); |
| | | if (localFunction.GetAttribute(FunctionAttributeKey.Power) != null)//如果是带电量的空开也要更新能源界面 |
| | |
| | | break; |
| | | case SPK.AcStandard: |
| | | case SPK.HvacAC: |
| | | case SPK.HvacAcPanel: |
| | | case SPK.AcIr: |
| | | Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status); |
| | | if (localFunction != null) |
| | |
| | | } |
| | | break; |
| | | case SPK.HvacFloorHeat: |
| | | case SPK.HvacFloorHeatPanel: |
| | | case SPK.FloorHeatStandard: |
| | | localFunction.lastState = ""; |
| | | switch (localFunction.GetAttrState(FunctionAttributeKey.Mode)) |
| | |
| | | EnvironmentalPage.LoadEvent_UpdataStatus(localFunction); |
| | | //A_EnvironmentalDataCenter.LoadEvent_UpdataStatus(localFunction); |
| | | break; |
| | | case SPK.SensorEnvironment:case SPK.SensorEnvironmentHailin: |
| | | case SPK.SensorEnvironment: |
| | | case SPK.SensorEnvironmentHailin: |
| | | case SPK.SensorEnvironment2: |
| | | case SPK.SensorEnvironment3: |
| | | if (localFunction.GetAttributes().Contains(FunctionAttributeKey.Temperature)) |
| | |
| | | var tempPirStatus = localFunction.attributes.Find((sta) => sta.key == "people_status"); |
| | | if (tempPirStatus != null) |
| | | { |
| | | if(tempPirStatus.state == "true") |
| | | if (tempPirStatus.state == "true") |
| | | { |
| | | localFunction.lastState = Language.StringByID(StringId.Someone); |
| | | } |
| | |
| | | break; |
| | | case SPK.AvMusic: |
| | | case SPK.MusicStandard: |
| | | foreach(var music in UI.Music.A31MusicModel.A31MusicModelList)//每次收到数据都要更新一下时间 |
| | | //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp); |
| | | Console.WriteLine("音乐播放器显示状态=======" + revString); |
| | | foreach (var music in UI.Music.A31MusicModel.A31MusicModelList)//每次收到数据都要更新一下时间 |
| | | { |
| | | if(music.functionMusic.sid == localFunction.sid) |
| | | if (music.functionMusic.sid == localFunction.sid) |
| | | { |
| | | music.LastDateTime = DateTime.Now; |
| | | break; |
| | | } |
| | | } |
| | | if (UI.Music.A31MusicModel.Current != null&& UI.Music.A31MusicModel.Current.functionMusic.sid == localFunction.sid) |
| | | if (UI.Music.A31MusicModel.Current != null) |
| | | { |
| | | UI.Music.A31MusicModel.Current.LastDateTime = DateTime.Now; |
| | | } |
| | | Console.WriteLine("音乐播放器显示状态=======" + revString); |
| | | //wjc |
| | | break; |
| | | //case SPK.Inverter: |
| | | //case SPK.InverterRst: |
| | | // var status = new Dictionary<string, object> { ["method"] = "status", ["data"] = temp.objects }; |
| | | // Application.RunOnMainThread(() => |
| | | // { |
| | | // Inverter.Ins.H5Page.CallJS($"nativeToJs(\'{JsonConvert.SerializeObject(status)}\')"); |
| | | // }); |
| | | // break; |
| | | } |
| | | |
| | | |
| | | |
| | | HomePage.UpdataFunctionStates(localFunction); |
| | | RoomPage.UpdataStates(localFunction); |
| | | FunctionPage.UpdataStates(localFunction); |
| | |
| | | { |
| | | Dictionary<string, string> dic = new Dictionary<string, string>(); |
| | | var functionControlDataObj = doorlock.GetGatewayAlinkDoorlockData(UserInfo.Current.ID, extStr); |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); |
| | | var functionControlDataJson = JsonConvert.SerializeObject(functionControlDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData($"/base/{Control.Ins.GatewayId}/thing/service/doorRemoteOpen/down", functionControlDataJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, 0); |
| | | } |
| | |
| | | var pack = HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/pwdConfirm", requestJson); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | Newtonsoft.Json.Linq.JObject pairs = Newtonsoft.Json.Linq.JObject.Parse(pack.Data.ToString()); |
| | | JObject pairs = JObject.Parse(pack.Data.ToString()); |
| | | var scrip = pairs.GetValue("scrip"); |
| | | |
| | | d = new Dictionary<string, object>(); |