| | |
| | | static Loading myLoading; |
| | | bool isReBind = false; |
| | | static List<Common> addedCommon; |
| | | static bool needRefresh; |
| | | public GuideSettingGateway (GatewayBase gd) |
| | | { |
| | | gatewayDeicve = gd as GatewayBase; |
| | |
| | | myLoading.Hide (); |
| | | btnCloseLoading.RemoveFromParent (); |
| | | WirelessConfig (new byte [] { 1 });//close |
| | | if (needRefresh) { |
| | | needRefresh = false; |
| | | SearchDeviceList (); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | |
| | | bottomView.AddChidren (btnAssignRoom); |
| | | btnAssignRoom.MouseUpEventHandler += (sender, e) => { |
| | | //bodyView.RemoveAll (); |
| | | |
| | | |
| | | btnAssignRoomAction (); |
| | | }; |
| | | SearchDeviceList (); |
| | |
| | | void btnAssignRoomAction () |
| | | { |
| | | if (gatewayDeicve.Type == DeviceType.OnePortMqttFR) { |
| | | |
| | | |
| | | Console.WriteLine ("Assign OnePortMqttFR,HDL MQTT"); |
| | | //RemoteSetting (); |
| | | RemoteSettingWithHDLMQTT (); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 开关无线配置 |
| | |
| | | //} |
| | | |
| | | if (config) { |
| | | System.Threading.Tasks.Task.Factory.StartNew (() => { |
| | | try { |
| | | byte bigClass = common.BigClass; |
| | | byte minClass = common.MinClass; |
| | | int count = common.LoopCount; |
| | | for (int k = 1, j = 0; k <= count; k++) { |
| | | if (Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, common.SubnetID, common.DeviceID, new byte [] { bigClass, minClass, (byte)k }) == null) { |
| | | j++; |
| | | //连续两次读取不到数据则跳出该循环 |
| | | if (j == 2 && k == 2) |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | Console.WriteLine ("Cinfig Read Device Loop Info " + ex.Message); |
| | | } |
| | | }); |
| | | needRefresh = true; |
| | | //System.Threading.Tasks.Task.Factory.StartNew (() => { |
| | | // try { |
| | | // byte bigClass = common.BigClass; |
| | | // byte minClass = common.MinClass; |
| | | // int count = common.LoopCount; |
| | | // for (int k = 1, j = 0; k <= count; k++) { |
| | | // if (Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, common.SubnetID, common.DeviceID, new byte [] { bigClass, minClass, (byte)k }) == null) { |
| | | // j++; |
| | | // //连续两次读取不到数据则跳出该循环 |
| | | // if (j == 2 && k == 2) |
| | | // break; |
| | | // } |
| | | // } |
| | | // } catch (Exception ex) { |
| | | // Console.WriteLine ("Cinfig Read Device Loop Info " + ex.Message); |
| | | // } |
| | | //}); |
| | | } |
| | | |
| | | #endregion |
| | |
| | | |
| | | //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); |
| | | |
| | | byte [] RegionIDBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID.ToString()); |
| | | byte [] RegionIDBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.Id.ToString ()); |
| | | var currentRegionIdBytes = new byte [4]; |
| | | Array.Copy (RegionIDBytes, 0, currentRegionIdBytes, 0, 4 < RegionIDBytes.Length ? 4 : RegionIDBytes.Length); |
| | | |
| | |
| | | gatewayDeicve.Remote_GroupName = MainPage.LoginUser.AccountString;//UserConfig.Instance.CurrentRegion.RegionName; |
| | | gatewayDeicve.Remote_ProjectName = gatewayDeicve.MAC.Replace (".", "");//UserConfig.Instance.CurrentRegion.RegionName; |
| | | gatewayDeicve.Remote_UserName = "Admin"; |
| | | gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.MasterID; |
| | | gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.ID; |
| | | byte [] ggn = new byte [20]; |
| | | byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName); |
| | | gatewayDeicve.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1); |
| | |
| | | return; |
| | | } |
| | | } |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Start ("Gateway setting succeeded,data up.Please wait..."); |
| | | }); |
| | | IO.FileUtils.SaveEquipmentMessage (gatewayDeicve); |
| | | var gatewayMAC = gatewayDeicve.MAC.Replace (".", ""); |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.RegionID, MAC = gatewayMAC, IsReBind = true }); |
| | | var respone = MainPage.RequestHttps ("EditMACByHomeId", requestJson); |
| | | if (respone.StateCode != "SUCCESS") { |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", "Communication abnormality,gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | if (MainPage.LoginUser.AccountString == "464027401@qq.com") { |
| | | new Alert (respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | var gatewayListObj = new GatewayListObj (); |
| | | var gatewayListJson = Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListObj); |
| | | var gatewayListRevertObj = MainPage.RequestHttps ("GatewayList", gatewayListJson); |
| | | if (gatewayListRevertObj.StateCode == "SUCCESS") { |
| | | var responseGatewayDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GatewayRes>> (gatewayListRevertObj.ResponseData.ToString ()); |
| | | if (responseGatewayDataObj.Count > 0) { |
| | | UserConfig.Instance.GatewayList.Clear (); |
| | | UserConfig.Instance.GatewayList.AddRange (responseGatewayDataObj); |
| | | UserConfig.Instance.GatewayMAC = gatewayDeicve.MAC; |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | MainPage.LoginUser.LastTime = DateTime.Now; |
| | | Application.RunOnMainThread (() => { |
| | | UserMiddle.Init (true); |
| | | }); |
| | | } else { |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", "Communication abnormality,gateway failed to bind residence.Please try again.", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | if (MainPage.LoginUser.AccountString == "464027401@qq.com") { |
| | | new Alert ("22:" + respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | BindGateways (); |
| | | } |
| | | } catch (Exception ex) { |
| | | Console.WriteLine (ex.Message); |
| | |
| | | }); |
| | | //Room.InitAllRoom (); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 远程配置 HDL MQTT模式 |
| | |
| | | gatewayDeicve.Remote_GroupName = MainPage.LoginUser.AccountString;//UserConfig.Instance.CurrentRegion.RegionName; |
| | | gatewayDeicve.Remote_ProjectName = gatewayDeicve.MAC.Replace (".", "");//UserConfig.Instance.CurrentRegion.RegionName; |
| | | gatewayDeicve.Remote_UserName = "Admin"; |
| | | gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.MasterID; |
| | | gatewayDeicve.Remote_Password = "c" + MainPage.LoginUser.ID; |
| | | //gatewayDeicve.Remote_Password = "85521566"; |
| | | byte [] ggn = new byte [20]; |
| | | byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName); |
| | |
| | | //3.写配置成功后下一步操作 |
| | | GatewaySettingSucceeded (); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="adminBytes"></param> |
| | | /// <returns></returns> |
| | | bool SetGateWayAdminInfo (byte[] adminBytes) { |
| | | bool SetGateWayAdminInfo (byte [] adminBytes) { |
| | | byte [] name = CommonPage.MyEncodingGB2312.GetBytes (MainPage.LoginUser.AccountString); |
| | | byte [] backBytes; |
| | | if (adminBytes != null && adminBytes.Length >= 73) {//返回数据正常,只修改账号信息 |
| | | Array.Copy (name, 0, adminBytes, 0, 36 < name.Length ? 36 : name.Length); |
| | | backBytes = Control.ControlBytesSendHasReturn (Command.SetGateWayAdminInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, adminBytes); |
| | | |
| | | |
| | | } else { |
| | | byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID.ToString()); |
| | | byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.Id.ToString ()); |
| | | //byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID); |
| | | //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); |
| | | adminBytes = new byte [73]; |
| | |
| | | Array.Copy (name, 0, adminBytes, 0, 36 < name.Length ? 36 : name.Length); |
| | | Array.Copy (currentRegionIdBytes, 0, adminBytes, 37, 36 < currentRegionIdBytes.Length ? 36 : currentRegionIdBytes.Length); |
| | | backBytes = Control.ControlBytesSendHasReturn (Command.SetGateWayAdminInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, adminBytes); |
| | | |
| | | |
| | | } |
| | | return CheckIsSuccessfulWithBytes (backBytes); |
| | | } |
| | |
| | | { |
| | | byte [] name = CommonPage.MyEncodingGB2312.GetBytes (MainPage.LoginUser.AccountString); |
| | | //byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID); |
| | | byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID.ToString()); |
| | | byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.Id.ToString ()); |
| | | //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); |
| | | byte [] adminBytes = new byte [73]; |
| | | adminBytes [36] = 1;//住宅标志位 |
| | |
| | | if (gatewayDeicve.Type == DeviceType.OnePortMqttFR) { |
| | | //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); |
| | | //byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID); |
| | | byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID.ToString()); |
| | | byte [] sendBytes = new byte [32]; |
| | | Array.Copy (currentRegionIdBytes, 0, sendBytes, 2, 32 < currentRegionIdBytes.Length ? 32 : currentRegionIdBytes.Length); |
| | | byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.Id.ToString ()); |
| | | byte [] sendBytes = new byte [36]; |
| | | Array.Copy (currentRegionIdBytes, 0, sendBytes, 2, 36 < currentRegionIdBytes.Length ? 36 : currentRegionIdBytes.Length); |
| | | |
| | | //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID); |
| | | var bindReginIdStatus = Control.ControlBytesSendHasReturn (Command.Write_APP_Data_STORE_1D5E_CMD, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, sendBytes); |
| | |
| | | } |
| | | } |
| | | |
| | | BindGateways (); |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Gateway setting succeeded,data up.Please wait... |
| | | /// </summary> |
| | | void BindGateways (){ |
| | | |
| | | Application.RunOnMainThread (() => { |
| | | MainPage.Loading.Start ("Gateway setting succeeded,data up.Please wait..."); |
| | | }); |
| | | IO.FileUtils.SaveEquipmentMessage (gatewayDeicve); |
| | | var gatewayMAC = gatewayDeicve.MAC.Replace (".", ""); |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.RegionID, MAC = gatewayMAC, IsReBind = true }); |
| | | var respone = MainPage.RequestHttps ("EditMACByHomeId", requestJson); |
| | | if (respone.StateCode != "SUCCESS") { |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", "Communication abnormality,gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | if (MainPage.LoginUser.AccountString == "464027401@qq.com") { |
| | | new Alert (respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | } |
| | | }); |
| | | return; |
| | | var oldMac = ""; |
| | | if (UserConfig.Instance.CheckHomeGateways () && !string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId)) { |
| | | //修改MAC接口 |
| | | oldMac = UserConfig.Instance.CurrentRegion.HomeGateways [0].GatewayUniqueId; |
| | | var mUpdateMacObj = new UpdateMacObj () { |
| | | LoginAccessToken = MainPage.LoginUser.LoginTokenString, |
| | | HomeId = UserConfig.Instance.CurrentRegion.Id, |
| | | NewMac = gatewayMAC, |
| | | OldMac = oldMac |
| | | }; |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mUpdateMacObj); |
| | | |
| | | //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = gatewayMAC, IsReBind = true }); |
| | | var respone = MainPage.RequestHttps (API.UpdateMac, requestJson); |
| | | if (respone.StateCode.ToUpper () != "SUCCESS") { |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", "Communication abnormality,gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | if (MainPage.LoginUser.AccountString == "464027401@qq.com") { |
| | | new Alert (respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | GetAllBindGatewarysPagger (); |
| | | } else { |
| | | //走新绑定接口 |
| | | var mBindMacObj = new BindGatewayToHomeObj () { |
| | | LoginAccessToken = MainPage.LoginUser.LoginTokenString, |
| | | HomeId = UserConfig.Instance.CurrentRegion.Id, |
| | | |
| | | }; |
| | | mBindMacObj.BindGateways.Add (gatewayMAC); |
| | | |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (mBindMacObj); |
| | | |
| | | //var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (new EditMACByHomeId { RegionID = UserConfig.Instance.CurrentRegion.Id, MAC = gatewayMAC, IsReBind = true }); |
| | | var respone = MainPage.RequestHttps (API.BindGatewayToHome, requestJson); |
| | | if (respone.StateCode.ToUpper () != "SUCCESS" && respone.StateCode != "BindGatewaysExists") { |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", "Communication abnormality,gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | if (MainPage.LoginUser.AccountString == "464027401@qq.com") { |
| | | new Alert (respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | GetAllBindGatewarysPagger (); |
| | | |
| | | } |
| | | var gatewayListObj = new GatewayListObj (); |
| | | |
| | | } |
| | | |
| | | void GetAllBindGatewarysPagger () { |
| | | var gatewayListObj = new GetAllBindGatewarysPaggerObj (); |
| | | gatewayListObj.ReqDto.LoginAccessToken = MainPage.LoginUser.LoginTokenString; |
| | | var gatewayListJson = Newtonsoft.Json.JsonConvert.SerializeObject (gatewayListObj); |
| | | var gatewayListRevertObj = MainPage.RequestHttps ("GatewayList", gatewayListJson); |
| | | if (gatewayListRevertObj.StateCode == "SUCCESS") { |
| | | var responseGatewayDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GatewayRes>> (gatewayListRevertObj.ResponseData.ToString ()); |
| | | var gatewayListRevertObj = MainPage.RequestHttps (API.GetAllBindGatewarysPagger, gatewayListJson); |
| | | if (gatewayListRevertObj.StateCode.ToUpper () == "SUCCESS") { |
| | | var mGateRes = Newtonsoft.Json.JsonConvert.DeserializeObject<AllBindGatewarysPaggerRes> (gatewayListRevertObj.ResponseData.ToString ()); |
| | | var responseGatewayDataObj = mGateRes.PageData; |
| | | if (responseGatewayDataObj.Count > 0) { |
| | | UserConfig.Instance.GatewayList.Clear (); |
| | | UserConfig.Instance.GatewayList.AddRange (responseGatewayDataObj); |
| | |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", "Communication abnormality,gateway failed to bind residence.Please try again.", Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | if (MainPage.LoginUser.AccountString == "464027401@qq.com") { |
| | | new Alert ("22:" + respone.StateCode, respone.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | new Alert ("22:" + gatewayListRevertObj.StateCode, gatewayListRevertObj.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | } |
| | | }); |
| | | } |
| | | } else { |
| | | |
| | | ShowGetAllBindGatewarysPaggerErrorInfo (gatewayListRevertObj.StateCode); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="stateCodeStr"></param> |
| | | void ShowGetAllBindGatewarysPaggerErrorInfo (string stateCodeStr) |
| | | { |
| | | string mes = ""; |
| | | //2020-01-06 待补充 |
| | | if (stateCodeStr == ErrorCode.NetworkError) { |
| | | mes = ErrorCode.NetworkError; |
| | | } else { |
| | | mes = ErrorCode.OperationFailed + ErrorCode.Reason + stateCodeStr; |
| | | |
| | | } |
| | | if (!string.IsNullOrEmpty (mes)) { |
| | | Application.RunOnMainThread (() => { |
| | | new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | } |