| | |
| | | /// <summary> |
| | | /// 判断是否本地加密并且加密key不为空 |
| | | /// </summary> |
| | | public bool IsLocalEncryptAndGetAesKey { |
| | | get { |
| | | public bool IsLocalEncryptAndGetAesKey |
| | | { |
| | | get |
| | | { |
| | | return IsLocalEncrypt && (!string.IsNullOrEmpty(DB_ResidenceData.Instance.CurrentRegion.localSecret)); |
| | | } |
| | | } |
| | |
| | | if (_GatewayOnline_Cloud != value) |
| | | { |
| | | _GatewayOnline_Cloud = value; |
| | | if(GatewayOnline_Local) |
| | | if (GatewayOnline_Local) |
| | | { |
| | | return; |
| | | } |
| | |
| | | public void SearchLoaclGateway() |
| | | { |
| | | //2021-01-15 : 住宅没有绑定网关的时候不用搜索,并且不能链接mqtt |
| | | if(DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId)) |
| | | if (DB_ResidenceData.Instance.HomeGateway == null || string.IsNullOrEmpty(DB_ResidenceData.Instance.HomeGateway.gatewayId)) |
| | | { |
| | | return; |
| | | } |
| | |
| | | /// </summary> |
| | | public void LoginGateway() |
| | | { |
| | | if(loginGatewayThread== null) |
| | | if (loginGatewayThread == null) |
| | | { |
| | | loginGatewayThread = new System.Threading.Thread(() => { |
| | | loginGatewayThread = new System.Threading.Thread(() => |
| | | { |
| | | while (!Ins.myTcpClient.isConnected) |
| | | { |
| | | if (Ins.GatewayOnline_Local && myTcpClient.isConnected) |
| | |
| | | try |
| | | { |
| | | loginGatewayThread?.Abort(); |
| | | }catch (Exception ex) |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"重启登录网关线程异常:{ex.Message}"); |
| | | } |
| | |
| | | LoginGateway(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | public void ControlScene(Scene scene) |
| | | { |
| | | //体验模式 |
| | | if(MainPage.NoLoginMode) |
| | | if (MainPage.NoLoginMode) |
| | | { |
| | | foreach(var sceneFunction in scene.functions) |
| | | foreach (var sceneFunction in scene.functions) |
| | | { |
| | | var revString = ""; |
| | | var upDataObj = new AlinkFunctionStatusObj(); |
| | |
| | | /// <param name="function"></param> |
| | | /// <param name="useRemote">是否直接使用远程发送</param> |
| | | /// <returns></returns> |
| | | public bool SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3) |
| | | public bool SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false, int resend = 3) |
| | | { |
| | | function.controlCounter++; |
| | | function.refreshTime = DateTime.Now; |
| | |
| | | var functionControlDataObj = function.GetGatewayAlinkControlData(commandDictionary); |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlFunctionTopic, functionControlDataJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id,resend); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, resend); |
| | | MainPage.Log($"本地通讯 发送HDL-Link数据:{functionControlDataJson}"); |
| | | } |
| | | } |
| | |
| | | commandDictionary.Add(FunctionAttributeKey.OnOff, commandDictionary[FunctionAttributeKey.Brightness] == "0" ? "off" : "on"); |
| | | } |
| | | } |
| | | if(function.spk == SPK.LightCCT) |
| | | if (function.spk == SPK.LightCCT) |
| | | { |
| | | if (!commandDictionary.ContainsKey(FunctionAttributeKey.CCT)) |
| | | { |
| | |
| | | /// <summary> |
| | | /// 全开全关功能 |
| | | /// </summary> |
| | | public void SwtichFunctions(bool open,List<Function> functions) |
| | | public void SwtichFunctions(bool open, List<Function> functions) |
| | | { |
| | | //dome模式控制 |
| | | if(MainPage.NoLoginMode) |
| | | if (MainPage.NoLoginMode) |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | |
| | | { |
| | | Dictionary<string, string> d1 = new Dictionary<string, string>(); |
| | | d1.Add(FunctionAttributeKey.OnOff, open ? "on" : "off"); |
| | | if (function.spk == SPK.PanelSocket) |
| | | if (function.spk == SPK.PanelSocket) |
| | | { |
| | | if (function.attributes.Find((obj) => obj.key == "on_off_usb") != null) |
| | | { |
| | |
| | | { |
| | | var pm = new DAL.Server.HttpServerRequest(); |
| | | var pack = pm.GetDeviceInfoList(functionIds); |
| | | if(pack!= null&& pack.Data!=null) |
| | | if (pack != null && pack.Data != null) |
| | | { |
| | | //待测试2021-03-04 |
| | | var ddd = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AlinkStatusData>>(pack.Data.ToString()); |
| | | if(ddd!= null) |
| | | if (ddd != null) |
| | | { |
| | | foreach(var function in ddd) |
| | | foreach (var function in ddd) |
| | | { |
| | | var temp = FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.deviceId == function.deviceId); |
| | | if(temp!= null) |
| | | if (temp != null) |
| | | { |
| | | if (SPK.Get3tySpk(SPK.BrandType.Tuya).Contains(temp.spk)) |
| | | { |
| | |
| | | /// 发送读取命令 |
| | | /// 自动判断是否为A协议设备 |
| | | /// </summary> |
| | | public void SendReadCommand(Function function ,bool forceRemote = false) |
| | | public void SendReadCommand(Function function, bool forceRemote = false) |
| | | { |
| | | function.refreshTime = DateTime.Now; |
| | | if (forceRemote) |
| | |
| | | { |
| | | busClient.ReadBusData(function); |
| | | } |
| | | |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | /// <summary> |
| | | /// 安防控制 |
| | | /// </summary> |
| | | public void ControlSecurity(SecurityAlarm securityAlarm,string state) |
| | | public void ControlSecurity(SecurityAlarm securityAlarm, string state) |
| | | { |
| | | if (!Ins.GatewayOnline_Local)//网关本地不在线 |
| | | { |
| | |
| | | }; |
| | | var aLinkJson = Newtonsoft.Json.JsonConvert.SerializeObject(aLinkData); |
| | | var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlScene, aLinkJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id,0); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, aLinkData.id, 0); |
| | | } |
| | | } |
| | | |
| | |
| | | /// 转换接收到的数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public void ConvertReceiveData(byte[] receiveBytes,string ip) |
| | | public void ConvertReceiveData(byte[] receiveBytes, string ip) |
| | | { |
| | | var reString = Encoding.UTF8.GetString(receiveBytes); |
| | | AnalysisReceiveData(reString, receiveBytes,ip); |
| | | AnalysisReceiveData(reString, receiveBytes, ip); |
| | | } |
| | | /// <summary> |
| | | /// 转换接收到的数据 |
| | |
| | | /// <param name="receiveString">转String后的数据</param> |
| | | /// <param name="originalReceiveBytes"原始Bytes数据</param> |
| | | /// <returns></returns> |
| | | public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes , string sIp = null) |
| | | public LocalCommunicationData AnalysisReceiveData(string receiveString, byte[] originalReceiveBytes, string sIp = null) |
| | | { |
| | | LocalCommunicationData receiveObj = new LocalCommunicationData(); |
| | | |
| | |
| | | MainPage.Log($"安防局域网异常:{ex.Message}"); |
| | | } |
| | | } |
| | | else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") { |
| | | else if (receiveObj.Topic == $"/user/{GatewayId}/custom/gateway/login_reply") |
| | | { |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(receiveObj.BodyDataString); |
| | | if (temp.GetValue("objects").ToString().Contains("success")) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | if(processedDataList.Count> 50) |
| | | if (processedDataList.Count > 50) |
| | | { |
| | | processedDataList.RemoveAt(0); |
| | | } |
| | |
| | | /// A协议数据 |
| | | /// </summary> |
| | | /// <param name="updateBytes"></param> |
| | | public void UpdataFunctionStatus(string revString, byte[] usefulBytes,bool isCloudData = false) |
| | | public void UpdataFunctionStatus(string revString, byte[] usefulBytes, bool isCloudData = false) |
| | | { |
| | | ////test 云端连接成功时,不适用本地数据更新 |
| | | //if (Ins.GatewayOnline_Cloud && !isCloudData) |
| | |
| | | |
| | | if (Ins.GatewayOnline_Local && isCloudData)//本地链接,除了涂鸦设备数据之外的云端数据不处理 |
| | | { |
| | | if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(localFunction.spk) && !SPK.MusicSpkList().Contains( localFunction.spk)) |
| | | if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(localFunction.spk) && !SPK.MusicSpkList().Contains(localFunction.spk)) |
| | | { |
| | | //MainPage.Log($"A协议更新状态:本地链接,除了涂鸦设备数据之外的云端数据不处理........"); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | //if (SPK.MusicSpkList().Contains(localFunction.spk)) |
| | | //{ |
| | | // if (updateTemp.status.Count < 3) |
| | | // { |
| | | // ///是音乐功能的 |
| | | // ///上报属性少3条不做处理 |
| | | // return; |
| | | // } |
| | | //} |
| | | MainPage.Log($"音乐收到数据:{revString}"); |
| | | if (SPK.MusicSpkList().Contains(localFunction.spk)) |
| | | { |
| | | MainPage.Log($"音乐收到数据:{revString}"); |
| | | |
| | | } |
| | | foreach (var attr in updateTemp.status) |
| | | { |
| | | localFunction.time_stamp = temp.time_stamp; |
| | | localFunction.SetAttrState(attr.key, attr.value); |
| | | Console.WriteLine("音乐播放器添加缓存数据=======" + revString); |
| | | if (SPK.MusicSpkList().Contains(localFunction.spk)) |
| | | { |
| | | Console.WriteLine("音乐播放器添加缓存数据=======" + revString); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | break; |
| | | case SPK.AirSwitch: |
| | | AirSwitchPage.UpdataState(localFunction); |
| | | if(localFunction.GetAttribute(FunctionAttributeKey.Power)!=null)//如果是带电量的空开也要更新能源界面 |
| | | if (localFunction.GetAttribute(FunctionAttributeKey.Power) != null)//如果是带电量的空开也要更新能源界面 |
| | | { |
| | | EnergyMainPage.UpdataStatus(localFunction); |
| | | } |
| | |
| | | CurtainModulePage.UpdataState(localFunction); |
| | | break; |
| | | case SPK.CurtainDream: |
| | | if(localFunction.GetAttrState(FunctionAttributeKey.Percent) == "0") |
| | | if (localFunction.GetAttrState(FunctionAttributeKey.Percent) == "0") |
| | | { |
| | | localFunction.SetAttrState(FunctionAttributeKey.OnOff, "off"); |
| | | } |
| | |
| | | case SPK.SensorTemperature: |
| | | case SPK.SensorHumidity: |
| | | case SPK.SensorHcho: |
| | | if(localFunction.spk == SPK.SensorTemperature) |
| | | if (localFunction.spk == SPK.SensorTemperature) |
| | | { |
| | | HomePage.LoadEvent_RefreshEnvirIndoorTemp(); |
| | | } |
| | |
| | | case SPK.AvMusic: |
| | | case SPK.MusicStandard: |
| | | //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp); |
| | | Console.WriteLine("音乐播放器显示状态======="+ revString); |
| | | Console.WriteLine("音乐播放器显示状态=======" + revString); |
| | | //wjc |
| | | break; |
| | | case SPK.Inverter: |
| | |
| | | /// <summary> |
| | | /// //一键(远程)开锁 |
| | | /// </summary> |
| | | public void OneKeyUnlocking(Function doorlock,string extStr) |
| | | public void OneKeyUnlocking(Function doorlock, string extStr) |
| | | { |
| | | if (Ins.GatewayOnline_Local) |
| | | { |
| | | Dictionary<string, string> dic = new Dictionary<string, string>(); |
| | | var functionControlDataObj = doorlock.GetGatewayAlinkDoorlockData(UserInfo.Current.ID,extStr); |
| | | var functionControlDataObj = doorlock.GetGatewayAlinkDoorlockData(UserInfo.Current.ID, extStr); |
| | | var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj); |
| | | var sendBytes = Ins.ConvertSendBodyData($"/base/{Control.Ins.GatewayId}/thing/service/doorRemoteOpen/down", functionControlDataJson); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, 0); |
| | |
| | | /// </summary> |
| | | /// <param name="functionId"></param> |
| | | /// <param name="pwd"></param> |
| | | public void ConfirmUnlocking(string functionId,string pwd) |
| | | public void ConfirmUnlocking(string functionId, string pwd) |
| | | { |
| | | Loading loading = new Loading(); |
| | | MainPage.BaseView.AddChidren(loading); |
| | |
| | | //{ |
| | | // return false; |
| | | //} |
| | | if (pack.Code != StateCode.SUCCESS) { |
| | | Application.RunOnMainThread(() => { |
| | | if (pack.Code != StateCode.SUCCESS) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message); |
| | | UserInfo.Current.doorPasswordString = "";// |
| | | UserInfo.Current.LastTimeOpenDoor = DateTime.MinValue; |
| | |
| | | } |
| | | if (pack.Code != StateCode.SUCCESS) |
| | | { |
| | | Application.RunOnMainThread(() => { |
| | | if(string.IsNullOrEmpty(pack.message)) |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | if (string.IsNullOrEmpty(pack.message)) |
| | | { |
| | | new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), |
| | | Language.StringByID(StringId.OperationFailed)); |