| | |
| | | /// </summary> |
| | | private bool finish = false; |
| | | |
| | | #if DEBUG |
| | | private string SeverAddr = "https://test-gz.hdlcontrol.com"; |
| | | #else |
| | | private string SeverAddr = "https://bahrain-gateway.hdlcontrol.com"; |
| | | //private string SeverAddr = "https://test-gz.hdlcontrol.com"; |
| | | #endif |
| | | |
| | | FrameLayout contentView; |
| | | |
| | |
| | | Button btnSave; |
| | | Button btnClose; |
| | | |
| | | Alert sssAlert = new Alert ("", "Please press the PROG button on Gateway for 3 sec.", "Confirm"); |
| | | |
| | | Action tipLockedAction; |
| | | |
| | | bool showedLockedTip = false; |
| | | |
| | | public MigrationServer () |
| | | { |
| | | loading = new Loading (); |
| | | loading = new Loading (); |
| | | tipLockedAction = () => { |
| | | Application.RunOnMainThread (() => { |
| | | if (!showedLockedTip) { |
| | | sssAlert.Show (); |
| | | showedLockedTip = true; |
| | | sssAlert.ResultEventHandler += (sd, dd) => { |
| | | showedLockedTip = false; |
| | | }; |
| | | } |
| | | }); |
| | | }; |
| | | Packet.lockedAction = tipLockedAction; |
| | | } |
| | | |
| | | |
| | |
| | | public void ShowDialog() |
| | | { |
| | | |
| | | #region 弹窗 |
| | | #region 弹窗 |
| | | Dialog dialog = new Dialog (); |
| | | |
| | | FrameLayout dialogBodyView = new FrameLayout () { |
| | |
| | | bottomView.AddChidren (btnClose); |
| | | btnClose.MouseUpEventHandler += (send2er, e2) => { |
| | | dialog.Close (); |
| | | Packet.lockedAction = null; |
| | | |
| | | }; |
| | | |
| | | Button btnBottomLine = new Button () { |
| | |
| | | btnSave.MouseUpEventHandler += (sender2, e2) => { |
| | | if (finish) { |
| | | dialog.Close (); |
| | | Packet.lockedAction = null; |
| | | return; |
| | | } |
| | | |
| | | #if DEBUG |
| | | |
| | | //SetGateWayMqttUrlAddress (1, 0); |
| | | //WriteSecretKey (1, 0, new byte [] {1,1,2,3,2,3,4,5,2,3,5,6 }); |
| | | //CheckGateway (); |
| | | |
| | | |
| | | //var moveAccontResult = Account2New ("12345678"); |
| | | //var newHomeId = Home2New (); |
| | | //if (newHomeId == "") { } else { } |
| | | //Account2New (etPwd.Text.Trim()); |
| | | //return; |
| | | ////迁移网关 |
| | | //var moveGatewayResult = Gateway2New ("4D59383553502243", newHomeId, 0); |
| | | #endif |
| | | |
| | | if (etPwd.Text.Trim() == "") { |
| | |
| | | etPwd.Visible = false; |
| | | btnSave.MouseUpEventHandler = (sender2, e2) => { |
| | | dialog.Close (); |
| | | Packet.lockedAction = null; |
| | | }; |
| | | } else { |
| | | |
| | |
| | | //3.接收升级文件获取请求 |
| | | //迁移账号 |
| | | |
| | | #endregion |
| | | #endregion |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | #region 云端 |
| | | #region 云端 |
| | | /// <summary> |
| | | /// 账号登录验证 |
| | | /// </summary> |
| | |
| | | |
| | | |
| | | |
| | | #endregion |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 检测一端口信息 |
| | |
| | | gateWayString = CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (gatewayFileName)); |
| | | common = Newtonsoft.Json.JsonConvert.DeserializeObject<GatewayBase> (gateWayString); |
| | | |
| | | //bool |
| | | CommonPage.IsRemote = false; |
| | | Control.ControlBytesSendHasReturn (Command.ReadGateway, common.SubnetID, common.DeviceID, new byte [] { CommonPage.RandomHigh, CommonPage.RandomLow }); |
| | | |
| | | var bytes = Control.ControlBytesSendHasReturn (Command.readGatewayVision, common.SubnetID, common.DeviceID, new byte [] { }); |
| | | if(bytes == null) { |
| | |
| | | } |
| | | var visionString = Encoding.GetEncoding ("gb2312").GetString (bytes); |
| | | |
| | | |
| | | int result = -99; |
| | | |
| | | |
| | | if (visionString.Contains("Ind_V03.01U_2021/07/12")) { |
| | | if (visionString.Contains ("Ind_C03.02U_2022/06/22")) { |
| | | Application.RunOnMainThread (() => { |
| | | btnTipMsg.Text = "Gateway firmware has been upgraded, initializing gateway."; |
| | | btnTipMsg.TextColor = SkinStyle.Current.TextColor; |
| | | }); |
| | | result = 100; |
| | | //} else if (!visionString.Contains ("Ind_V02.35U_2019/06/25")) {//目前只允许升级这个固件的网关 |
| | | // Application.RunOnMainThread (() => { |
| | | // btnTipTitle.Text = "The gateway does not support automatic migration. Please contact technical support."; |
| | | // btnTipTitle.Height = Application.GetRealHeight (150); |
| | | // btnTipTitle.TextColor = SkinStyle.Current.DelColor; |
| | | // btnTipMsg.Text = ""; |
| | | // etPwd.Visible = false; |
| | | // loading.Hide (); |
| | | // btnSave.Visible = false; |
| | | // btnClose.Width = Application.GetRealWidth (500); |
| | | // }); |
| | | // return; |
| | | } else { |
| | | Application.RunOnMainThread (() => { |
| | | btnTipMsg.Text = "Upgrading gateway."; |
| | |
| | | while (true) { |
| | | var ub = MainPage.GatewayStatus.Split ("_"); |
| | | if (ub.Length > 1) { |
| | | result = Convert.ToInt32 (ub [1]); |
| | | result = Convert.ToInt32 (ub [1]); |
| | | //if (result < result0 && result0 < 100) |
| | | { |
| | | //result = result0; |
| | |
| | | btnTipMsg.Text = "Gateway upgrade succeeded. Initializing gateway."; |
| | | btnTipMsg.TextColor = SkinStyle.Current.TextColor; |
| | | }); |
| | | //初始化标记 |
| | | MainPage.GatewayStatus = ""; |
| | | break; |
| | | } |
| | | else { |
| | | } else { |
| | | if (upgradeData.Count >= result) { |
| | | var listPack = upgradeData [result-1];// |
| | | var listPack = upgradeData [result - 1];// |
| | | byte [] packData = new byte [2 + listPack.Count]; |
| | | packData [0] = Convert.ToByte (result / 256); |
| | | packData [1] = Convert.ToByte (result % 256 ); |
| | | packData [1] = Convert.ToByte (result % 256); |
| | | Array.Copy (listPack.ToArray (), 0, packData, 2, listPack.Count); |
| | | Console.WriteLine ("packId"+result); |
| | | Console.WriteLine ("packId" + result); |
| | | SendUpgradeData (common.SubnetID, common.DeviceID, packData); |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //重新设置一下子网号 |
| | | SetSubnetId (common); |
| | | System.Threading.Thread.Sleep (1000); |
| | | |
| | | if (result == 100) { |
| | | |
| | |
| | | if (MainPage.GatewayStatus != "Initialization_complete") { |
| | | System.Threading.Thread.Sleep (100); |
| | | } else if (initiaIndex == 0) { |
| | | //初始化标记 |
| | | MainPage.GatewayStatus = ""; |
| | | Application.RunOnMainThread (() => { |
| | | btnTipMsg.Text = "Successfully initialized the gateway. Opening the gateway remote configuration."; |
| | | btnTipMsg.TextColor = SkinStyle.Current.TextColor; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置子网号 |
| | | /// </summary> |
| | | /// <param name="gatewayDevice"></param> |
| | | private void SetSubnetId (GatewayBase gatewayDevice) |
| | | { |
| | | string [] macAddress = gatewayDevice.MAC.Split ('.'); |
| | | byte [] Musics = new byte [10]; |
| | | for (int i = 0; i < macAddress.Length; i++) { |
| | | Musics [i] = Convert.ToByte (macAddress [i], 16); |
| | | } |
| | | try { |
| | | Musics [8] = Convert.ToByte (Convert.ToInt32 (gatewayDevice.SubnetID)); |
| | | if (Musics [8] < 0 || Musics [8] > 255) { |
| | | throw new Exception (); |
| | | } |
| | | } catch { |
| | | return; |
| | | } |
| | | Control.ControlBytesSend (Command.SetDeviceSubnetID, gatewayDevice.SubnetID, gatewayDevice.DeviceID, Musics); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设备网关开启远程 |
| | | /// </summary> |
| | | private bool SetGatewayRemote(byte subnetId, byte deviceId) |