From 931caaa26cc01c5a2cd5d290864b93255aeaa6b6 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 24 三月 2021 09:59:10 +0800
Subject: [PATCH] 2021-03-24 1.定时器时间改为24小时制
---
Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs | 336 +++++++++++++++++++++++++++++--------------------------
1 files changed, 176 insertions(+), 160 deletions(-)
diff --git a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
index 2f278d8..570c048 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/Phone/Guide/GuideSettingGateway.cs
@@ -157,7 +157,7 @@
RemoteSettingWithHDLMQTT ();
} else {
Utlis.WriteLine ("Assign OnePortWirelessFR");
- RemoteSettingWithOldDevice ();
+ //RemoteSettingWithOldDevice ();
//RemoteSettingWithMQTT ();
}
}
@@ -602,134 +602,134 @@
- /// <summary>
- /// 杩滅▼閰嶇疆
- /// </summary>
- void RemoteSettingWithOldDevice ()
- {
- byte [] gatewayBytes = null;
- byte [] serverIPBytes = null;
+ ///// <summary>
+ ///// 杩滅▼閰嶇疆
+ ///// </summary>
+ //void RemoteSettingWithOldDevice ()
+ //{
+ // byte [] gatewayBytes = null;
+ // byte [] serverIPBytes = null;
- string [] strServerIP = (MainPage.SeviceIP).Split ('.');
- string [] strServerIP1 = (MainPage.SeviceIP).Split ('.');
- MainPage.Loading.Start ("Configuring device...");
- System.Threading.Tasks.Task.Run (() => {
- try {
+ // string [] strServerIP = (MainPage.SeviceIP).Split ('.');
+ // string [] strServerIP1 = (MainPage.SeviceIP).Split ('.');
+ // MainPage.Loading.Start ("Configuring device...");
+ // System.Threading.Tasks.Task.Run (() => {
+ // try {
- //var currentRegionIdBytes = new byte [] {
- // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256 / 256),
- // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256),
- // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256),
- // (byte)(UserConfig.Instance.CurrentRegion.RegionID % 256),
- //};
+ // //var currentRegionIdBytes = new byte [] {
+ // // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256 / 256),
+ // // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256 / 256),
+ // // (byte)(UserConfig.Instance.CurrentRegion.RegionID / 256),
+ // // (byte)(UserConfig.Instance.CurrentRegion.RegionID % 256),
+ // //};
- //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID);
+ // //var currentRegionIdBytes = Utlis.IntToByteArray (UserConfig.Instance.CurrentRegion.RegionID);
- 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);
+ // 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);
- gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
- serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
+ // gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
+ // serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
- 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.ID;
- byte [] ggn = new byte [20];
- byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName);
- gatewayDeicve.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1);
- Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.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.ID;
+ // byte [] ggn = new byte [20];
+ // byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_GroupName);
+ // gatewayDeicve.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1);
+ // Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length);
- byte [] gpn = new byte [20];
- byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_ProjectName);
- Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length);
+ // byte [] gpn = new byte [20];
+ // byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_ProjectName);
+ // Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length);
- byte [] gun = new byte [8];
- byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_UserName);
- Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length);
+ // byte [] gun = new byte [8];
+ // byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_UserName);
+ // Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length);
- byte [] gpw = new byte [8];
- byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_Password);
- Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length);
+ // byte [] gpw = new byte [8];
+ // byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDeicve.Remote_Password);
+ // Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length);
- byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
+ // byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, new byte [] { });
- gatewayBytes [0] = 2;//杩滅▼鏍囩ず
- Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length);
- Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length);
- Array.Copy (gun, 0, gatewayBytes, 41, 8 < gun.Length ? 8 : gun.Length);
- Array.Copy (gpw, 0, gatewayBytes, 49, 8 < gpw.Length ? 8 : gpw.Length);
+ // gatewayBytes [0] = 2;//杩滅▼鏍囩ず
+ // Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length);
+ // Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length);
+ // Array.Copy (gun, 0, gatewayBytes, 41, 8 < gun.Length ? 8 : gun.Length);
+ // Array.Copy (gpw, 0, gatewayBytes, 49, 8 < gpw.Length ? 8 : gpw.Length);
- Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, gatewayBytes);
+ // Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, gatewayBytes);
- serverIPBytes [0] = Convert.ToByte (strServerIP [0]);
- serverIPBytes [1] = Convert.ToByte (strServerIP [1]);
- serverIPBytes [2] = Convert.ToByte (strServerIP [2]);
- serverIPBytes [3] = Convert.ToByte (strServerIP [3]);
- int point1 = 9999;
+ // serverIPBytes [0] = Convert.ToByte (strServerIP [0]);
+ // serverIPBytes [1] = Convert.ToByte (strServerIP [1]);
+ // serverIPBytes [2] = Convert.ToByte (strServerIP [2]);
+ // serverIPBytes [3] = Convert.ToByte (strServerIP [3]);
+ // int point1 = 9999;
- serverIPBytes [4] = Convert.ToByte (point1 / 256);
- serverIPBytes [5] = Convert.ToByte (point1 % 256);
+ // serverIPBytes [4] = Convert.ToByte (point1 / 256);
+ // serverIPBytes [5] = Convert.ToByte (point1 % 256);
- serverIPBytes [6] = Convert.ToByte (strServerIP1 [0]);
- serverIPBytes [7] = Convert.ToByte (strServerIP1 [1]);
- serverIPBytes [8] = Convert.ToByte (strServerIP1 [2]);
- serverIPBytes [9] = Convert.ToByte (strServerIP1 [3]);
- int point2 = 9999;
+ // serverIPBytes [6] = Convert.ToByte (strServerIP1 [0]);
+ // serverIPBytes [7] = Convert.ToByte (strServerIP1 [1]);
+ // serverIPBytes [8] = Convert.ToByte (strServerIP1 [2]);
+ // serverIPBytes [9] = Convert.ToByte (strServerIP1 [3]);
+ // int point2 = 9999;
- serverIPBytes [10] = Convert.ToByte (point2 / 256);
- serverIPBytes [11] = Convert.ToByte (point2 % 256);
+ // serverIPBytes [10] = Convert.ToByte (point2 / 256);
+ // serverIPBytes [11] = Convert.ToByte (point2 % 256);
- //杩滅▼ip鍦板潃鐨勮缃�
- var mobytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInternetInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, serverIPBytes);
- if (mobytes == null) {
- Application.RunOnMainThread (() => {
- new Alert ("", ErrorCode.GatewayNoResponse,
- Language.StringByID (R.MyInternationalizationString.Close)).Show ();
- });
- } else if (mobytes [0] == 0xF5) {
- Application.RunOnMainThread (() => {
- new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed),
- Language.StringByID (R.MyInternationalizationString.Close)).Show ();
- });
- } else {
- if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR) {
- var bindReginIdStatus = Control.ControlBytesSendHasReturn (Command.Write_APP_Data_STORE_1D5E_CMD, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, currentRegionIdBytes);
- if (bindReginIdStatus == null) {
- Application.RunOnMainThread (() => {
- new Alert ("", ErrorCode.GatewayNoResponse, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
- });
- return;
- } else if (bindReginIdStatus [0] != 0xF8) {
- //new Alert ("", "缃戝叧缁戝畾浣忓畢澶辫触锛�", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
- Application.RunOnMainThread (() => {
- new Alert ("", "Gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
- });
- return;
- }
- }
- GotoHomePage ();
- }
- } catch (Exception ex) {
- Utlis.WriteLine (ex.Message);
- Application.RunOnMainThread (() => {
- new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
- });
- bool canRemove = false;
- } finally {
- Application.RunOnMainThread (() => {
- MainPage.Loading.Hide ();
- //this.RemoveAll ();
- });
- }
- });
- //Room.InitAllRoom ();
- }
+ // //杩滅▼ip鍦板潃鐨勮缃�
+ // var mobytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInternetInfo, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, serverIPBytes);
+ // if (mobytes == null) {
+ // Application.RunOnMainThread (() => {
+ // new Alert ("", ErrorCode.GatewayNoResponse,
+ // Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ // });
+ // } else if (mobytes [0] == 0xF5) {
+ // Application.RunOnMainThread (() => {
+ // new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed),
+ // Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ // });
+ // } else {
+ // if (gatewayDeicve.Type == DeviceType.OnePortWirelessFR) {
+ // var bindReginIdStatus = Control.ControlBytesSendHasReturn (Command.Write_APP_Data_STORE_1D5E_CMD, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, currentRegionIdBytes);
+ // if (bindReginIdStatus == null) {
+ // Application.RunOnMainThread (() => {
+ // new Alert ("", ErrorCode.GatewayNoResponse, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ // });
+ // return;
+ // } else if (bindReginIdStatus [0] != 0xF8) {
+ // //new Alert ("", "缃戝叧缁戝畾浣忓畢澶辫触锛�", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ // Application.RunOnMainThread (() => {
+ // new Alert ("", "Gateway failed to bind residence!", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ // });
+ // return;
+ // }
+ // }
+ // GotoHomePage ();
+ // }
+ // } catch (Exception ex) {
+ // Utlis.WriteLine (ex.Message);
+ // Application.RunOnMainThread (() => {
+ // new Alert ("", Language.StringByID (R.MyInternationalizationString.OperationFailed), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
+ // });
+ // bool canRemove = false;
+ // } finally {
+ // Application.RunOnMainThread (() => {
+ // MainPage.Loading.Hide ();
+ // //this.RemoveAll ();
+ // });
+ // }
+ // });
+ // //Room.InitAllRoom ();
+ //}
@@ -757,8 +757,11 @@
if (SetGateWayModelInfo()) {
//2.淇敼绠$悊淇℃伅
if (SetGateWayAdminInfo ()) {
- //3.鍐欓厤缃垚鍔熷悗涓嬩竴姝ユ搷浣�
- GatewaySettingSucceeded ();
+ //3.鍐橫qtt杩滅▼鍩熷悕鍦板潃
+ if (SetGateWayMqttUrlAddress ()) {
+ //4.鍐欓厤缃垚鍔熷悗涓嬩竴姝ユ搷浣�
+ GatewaySettingSucceeded ();
+ }
}
}
@@ -846,10 +849,9 @@
/// <returns></returns>
bool SetGateWayAdminInfo ()
{
- byte [] name = CommonPage.MyEncodingGB2312.GetBytes (MainPage.LoginUser.AccountString);
- //byte [] currentRegionIdBytes = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.CurrentRegion.RegionID);
+ //byte [] name = CommonPage.MyEncodingGB2312.GetBytes (MainPage.LoginUser.AccountString);
+ byte [] name = CommonPage.MyEncodingGB2312.GetBytes (UserConfig.Instance.HomeGateway.gatewayId);//甯愬彿鍚嶆敼鎴恎atewayId
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;//浣忓畢鏍囧織浣�
Array.Copy (name, 0, adminBytes, 0, 36 < name.Length ? 36 : name.Length);
@@ -859,6 +861,47 @@
return CheckIsSuccessfulWithBytes (backBytes, "Failed to modify gateway administrator information!");
}
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="bytes"></param>
+ /// <returns></returns>
+ private byte GetCheckSum (byte [] bytes)
+ {
+ //byte checksum = 0x00;
+ //foreach (byte bt in bytes) {
+ // checksum ^= bt;
+ //}
+
+ int iSum = 0;
+ for (int i = 0; i < bytes.Length; i++) {
+ iSum += bytes [i];
+ }
+ return (byte)(0xff & (0x100 - iSum));
+ }
+
+ /// <summary>
+ /// 淇敼Mqtt鍩熷悕鍦板潃
+ /// </summary>
+ /// <returns></returns>
+ bool SetGateWayMqttUrlAddress ()
+ {
+ byte [] utlBytes = new byte [65];
+ var url = new Uri (UserConfig.Instance.CurrentRegion.regionUrl);
+ var host = "";
+ if (url != null) {
+ host = url.Host;
+ }
+ byte [] hostBytes = CommonPage.MyEncodingGB2312.GetBytes (host);
+ Array.Copy (hostBytes, 0, utlBytes, 0, 64 < hostBytes.Length ? 64 : hostBytes.Length);
+ var sum = GetCheckSum (hostBytes);
+ utlBytes [64] = sum;//鏍¢獙浣�
+ byte [] backBytes = Control.ControlBytesSendHasReturn (Command.SetGateWayMqttURLAddress, gatewayDeicve.SubnetID, gatewayDeicve.DeviceID, utlBytes);
+
+ return CheckIsSuccessfulWithBytes (backBytes, "Failed to modify gateway remote address!");
+ }
+
/// <summary>
/// 鍒ゆ柇鏄惁淇鎴愬姛 F8 = 鎴愬姛锛� F5=澶辫触
@@ -914,58 +957,31 @@
}
}
- GotoHomePage ();
+ //GotoHomePage ();
+ UploadOidAndSidList ();
}
+ /// <summary>
+ /// 涓婁紶oid鍜宻id鍒楄〃
+ /// </summary>
+ void UploadOidAndSidList ()
+ {
- ///// <summary>
- ///// Gateway setting succeeded锛宒ata up.Please wait...
- ///// 缁戝畾Mac(鍗板害鐗�)
- ///// </summary>
- //void BindGatewaysNew ()
- //{
- // //Application.RunOnMainThread (() => {
- // // MainPage.Loading.Start ("Gateway setting succeeded锛宒ata up. Please wait...");
- // //});
- // //IO.FileUtils.SaveEquipmentMessage (gatewayDeicve);
- // //var gatewayMAC = gatewayDeicve.MAC.Replace (".", "");
+ Application.RunOnMainThread (() => {
+ MainPage.Loading.Start ("Uploading device list...");
+ });
+ var RES = HDLLinkUtlis.Current.UploadOidAndSidList ();
+ Application.RunOnMainThread (() => {
+ if (RES) {
+ //Utlis.ShowTip ("Device list upload successfully锛�");
+ } else {
+ Utlis.ShowTip ("Device list upload failed锛�");
+ }
+ GotoHomePage ();
+ });
- // ////璧版柊鏇存柊缁戝畾鎺ュ彛
- // //var mBindMacObj = new BindMacObj () {
- // // LoginAccessToken = MainPage.LoginUser.LoginTokenString,
- // // HomeId = UserConfig.Instance.CurrentRegion.Id,
- // // MAC = gatewayMAC
-
- // //};
-
- // //string urlHead = MainPage.RequestHttpsHost;
- // //if (mBindMacObj.IsOtherAccountCtrl) {
- // // urlHead = UserConfig.Instance.MasterAccountRequestBaseUrl;
- // // mBindMacObj.LoginAccessToken = UserConfig.Instance.MasterAccountToken;
- // //}
-
-
- // //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.BindMac, requestJson, urlHead);
- // //if (respone.StateCode.ToUpper () != StateCode.SUCCESS) {
- // // GetNowHomeGatewayAfterBindMacFailed ();//2020-01-11
- // // Application.RunOnMainThread (() => {
- // // new Alert ("", $"Failed to bind Mac address! {ErrorCode.Reason }{respone.StateCode}", 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;
- // //}
- // //GetNowHomeGateway ();
-
- // var gatewayMAC = gatewayDeicve.MAC.Replace (".", "");
- // AddMacToUserConfig (gatewayMAC);
-
- //}
+ }
/// <summary>
/// 璺宠浆涓婚〉闈�
--
Gitblit v1.8.0