| | |
| | | public void SearchLoaclGateway() |
| | | { |
| | | //2021-01-15 : 住宅没有绑定网关的时候不用搜索,并且不能链接mqtt |
| | | if(DB_ResidenceData.Instance.HomeGateway == null) |
| | | if(DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId)) |
| | | { |
| | | return; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | MainPage.Log($"发送数据:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}"); |
| | | //MainPage.Log($"发送数据:{Newtonsoft.Json.JsonConvert.SerializeObject(commandDictionary)}"); |
| | | |
| | | ///第三方涂鸦设备统一使用远程控制 |
| | | switch(function.spk) |
| | |
| | | /// 发送读取命令 |
| | | /// 自动判断是否为A协议设备 |
| | | /// </summary> |
| | | public void SendReadCommand(Function function) |
| | | public void SendReadCommand(Function function ,bool forceRemote = false) |
| | | { |
| | | function.refreshTime = DateTime.Now; |
| | | if (Ins.GatewayOnline_Local) |
| | | if (forceRemote) |
| | | { |
| | | |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); |
| | | } |
| | | else |
| | | { |
| | | if (Ins.GatewayOnline_Local) |
| | | { |
| | | try |
| | | |
| | | if (DB_ResidenceData.Instance.GatewayType == 0) |
| | | { |
| | | new Control_Udp().ReadBusData(function); |
| | | try |
| | | { |
| | | new Control_Udp().ReadBusData(function); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"发送数据异常: {ex.Message}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | else |
| | | { |
| | | MainPage.Log($"发送数据异常: {ex.Message}"); |
| | | var readKey = new Dictionary<string, string>(); |
| | | readKey.Add("sid", function.sid); |
| | | |
| | | var readDataObj = new AlinkReadFunctionStatusObj() |
| | | { |
| | | id = Ins.msg_id.ToString(), |
| | | objects = new List<Dictionary<string, string>>() |
| | | { |
| | | readKey |
| | | }, |
| | | time_stamp = Utlis.GetTimestamp() |
| | | }; |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson); |
| | | MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}"); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var readKey = new Dictionary<string, string>(); |
| | | readKey.Add("sid", function.sid); |
| | | |
| | | var readDataObj = new AlinkReadFunctionStatusObj() |
| | | { |
| | | id = Ins.msg_id.ToString(), |
| | | objects = new List<Dictionary<string, string>>() |
| | | { |
| | | readKey |
| | | }, |
| | | time_stamp = Utlis.GetTimestamp() |
| | | }; |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson); |
| | | MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}"); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id); |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | var pack = pm.RefreshDeviceStatus(new List<string>() { function.deviceId }); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | string sendDataString = topicString + lengthString + bodyDataString; |
| | | byte[] sendDataBytes = Encoding.ASCII.GetBytes(sendDataString); |
| | | //MainPage.Log($"转换HDL-Link数据\r\n{sendDataString}\r\n"); |
| | | MainPage.Log($"转换HDL-Link数据\r\n{sendDataString}\r\n"); |
| | | |
| | | return sendDataBytes; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | MainPage.Log($"局域网信息: {receiveObj.Topic}"); |
| | | MainPage.Log($"内容: {res[1]}"); |
| | | MainPage.Log($"局域网信息: {receiveObj.Topic} : 内容: {res[1]}"); |
| | | |
| | | |
| | | //验证有效数据长度 |
| | |
| | | } |
| | | |
| | | var device = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceModule>(bodyJObj.objects.ToString()); |
| | | if (device.device_mac == DB_ResidenceData.Instance.residenceGatewayMAC) |
| | | 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)) |
| | |
| | | { |
| | | Ins.GatewayId = device.device_mac; |
| | | } |
| | | reportIp = "239.0.168.188";// device.ip_address; |
| | | reportIp = "239.0.168.188";// device.ip_address;//主播地址也能控制设备 |
| | | } |
| | | } |
| | | else if (receiveObj.Topic == CommunicationTopic.ct.ReadStatus + "_reply" || |
| | |
| | | /// <param name="updateBytes"></param> |
| | | public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false) |
| | | { |
| | | |
| | | if (Ins.GatewayOnline_Local && isCloudData)//本地链接,除了涂鸦设备数据之外的云端数据不处理 |
| | | { |
| | | if (FunctionList.List.GetDeviceFunctionList(SPK.BrandType.Tuya).Count == 0) |
| | | { |
| | | //MainPage.Log($"A协议更新状态:本地链接,除了涂鸦设备数据之外的云端数据不处理..."); |
| | | return; |
| | | } |
| | | } |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<AlinkFunctionStatusObj>(revString); |
| | | if (temp != null) |
| | | { |
| | |
| | | { |
| | | try |
| | | { |
| | | |
| | | if (Ins.GatewayOnline_Local && isCloudData)//本地链接,除了涂鸦设备数据之外的云端数据不处理 |
| | | { |
| | | if (FunctionList.List.OtherBrandFunction.Count != 0) |
| | | { |
| | | if (FunctionList.List.OtherBrandFunction.Find((obj) => obj.sid == updateTemp.sid) == null) |
| | | { |
| | | //MainPage.Log($"A协议更新状态:本地链接,除了涂鸦设备数据之外的云端数据不处理..."); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | var localFunction = allLocalFuntion.Find((obj) => obj.sid == updateTemp.sid); |
| | | if (localFunction == null) |
| | | { |
| | |
| | | Function localObj = null; |
| | | switch (localFunction.spk) |
| | | { |
| | | case SPK.ElectricEnergy: |
| | | EnergyMainPage.UpdataStatus(localFunction); |
| | | break; |
| | | case SPK.LightSwitch: |
| | | RelayPage.UpdataState(localFunction); |
| | | break; |
| | |
| | | case SPK.SensorTVOC: |
| | | case SPK.SensorTemperature: |
| | | case SPK.SensorHumidity: |
| | | var sensor = FunctionList.List.GetEnvirSensorsList().Find((obj) => obj.sid == updateTemp.sid); |
| | | if (sensor != null) |
| | | if(localFunction.spk == SPK.SensorTemperature) |
| | | { |
| | | localObj = sensor; |
| | | foreach (var attr in updateTemp.status) |
| | | { |
| | | var localAttr = sensor.attributes.Find((obj) => obj.key == attr.key); |
| | | if (localAttr != null) |
| | | { |
| | | localAttr.curValue = attr.value; |
| | | } |
| | | } |
| | | EnvironmentalSciencePage.LoadEvent_UpdataStatus(sensor); |
| | | HomePage.LoadEvent_RefreshEnvirIndoorTemp(); |
| | | } |
| | | else if (localFunction.spk == SPK.SensorHumidity) |
| | | { |
| | | HomePage.LoadEvent_RefreshEnvirIndoorHumi(); |
| | | } |
| | | EnvironmentalPage.LoadEvent_UpdataStatus(localFunction); |
| | | break; |
| | | case SPK.ElectricSocket: |
| | | var es = FunctionList.List.GetElectricSocketList().Find((obj) => obj.sid == updateTemp.sid); |
| | | if (es != null) |
| | | { |
| | | localObj = es; |
| | | foreach (var attr in updateTemp.status) |
| | | { |
| | | var localAttr = es.attributes.Find((obj) => obj.key == attr.key); |
| | | if (localAttr != null) |
| | | { |
| | | localAttr.curValue = attr.value; |
| | | } |
| | | } |
| | | SocketPage.UpdataState(es); |
| | | } |
| | | SocketPage.UpdataState(localFunction); |
| | | break; |
| | | case SPK.ElectricTV: |
| | | break; |
| | |
| | | case SPK.SensorSmoke: |
| | | case SPK.SensorWater: |
| | | case SPK.ClothesHanger: |
| | | case SPK.IrAC: |
| | | case SPK.AcIr: |
| | | case SPK.SenesorMegahealth: |
| | | //设备状态推送 |
| | | //状态更新 |
| | | Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status); |
| | | break; |
| | | } |