From b6c9ed01ffa674f6d5e7ffb23051702dbc859abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E5=A5=87=E6=B5=B7=E8=9E=BA?= <> Date: Mon, 13 May 2019 14:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96OTA=E6=8F=90=E7=A4=BA,?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Device/TCDeviceInfoTableViewController.swift | 13 +++++++++++-- .../Device/TCDeviceMainViewController.swift | 4 ++++ .../Controller/MainList/TCListViewController.swift | 6 +----- TC1-NG/TC1ServiceManager.swift | 1 + 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/TC1-NG/Controller/Device/TCDeviceInfoTableViewController.swift b/TC1-NG/Controller/Device/TCDeviceInfoTableViewController.swift index 661ed56..ec43a04 100755 --- a/TC1-NG/Controller/Device/TCDeviceInfoTableViewController.swift +++ b/TC1-NG/Controller/Device/TCDeviceInfoTableViewController.swift @@ -93,7 +93,7 @@ class TCDeviceInfoTableViewController: UITableViewController { let update = UIAlertAction(title: "马上更新", style: .destructive, handler: { (_) in TC1ServiceManager.share.publishMessage(["mac":self.deviceModel.mac,"setting":["ota":"http://home.wula.vip:4380/TC1_OTA.bin"]]) DispatchQueue.main.async { - HUD.flash(.labeledProgress(title: "正在更新", subtitle: "请勿退出程序"), delay: 2) + HUD.show(.labeledProgress(title: "正在更新", subtitle: "请勿断开设备电源!")) } }) alert.addAction(update) @@ -119,7 +119,16 @@ extension TCDeviceInfoTableViewController:TC1ServiceReceiveDelegate{ func TC1ServiceReceivedMessage(message: Data) { let messageJSON = try! JSON(data: message) - print(messageJSON) + let otaProgress = messageJSON["ota_progress"].floatValue + if otaProgress > 0{ + print("OTA 进度 ---> \(otaProgress)") + } + if otaProgress == 100 { + DispatchQueue.main.async { + HUD.flash(.labeledSuccess(title: "更新成功!", subtitle: nil)) + } + } + } func TC1ServicePublish(messageId: Int) { diff --git a/TC1-NG/Controller/Device/TCDeviceMainViewController.swift b/TC1-NG/Controller/Device/TCDeviceMainViewController.swift index 591a3e4..313f782 100755 --- a/TC1-NG/Controller/Device/TCDeviceMainViewController.swift +++ b/TC1-NG/Controller/Device/TCDeviceMainViewController.swift @@ -151,6 +151,10 @@ extension TCDeviceMainViewController:TC1ServiceReceiveDelegate{ self.powerView.animateToProgress(progress: 1/2500 * power) self.powerLabel.text = "\(power)W"; } + if let ip = messageJSON["ip"].string{ + self.deviceModel.ip = ip + TCSQLManager.updateTCDevice(self.deviceModel) + } self.plugMessageReload(message: messageJSON) } } diff --git a/TC1-NG/Controller/MainList/TCListViewController.swift b/TC1-NG/Controller/MainList/TCListViewController.swift index fa9f069..4788551 100755 --- a/TC1-NG/Controller/MainList/TCListViewController.swift +++ b/TC1-NG/Controller/MainList/TCListViewController.swift @@ -32,11 +32,6 @@ class TCListViewController: UIViewController { self.tableView.reloadData() } - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - TC1ServiceManager.share.closeService() - } - private func discoverDevices(mac:String){ TC1ServiceManager.share.delegate = self TC1ServiceManager.share.connectService() @@ -153,6 +148,7 @@ extension TCListViewController:UITableViewDelegate,UITableViewDataSource{ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if let vc = UIStoryboard(name: "TCDeviceMain", bundle: nil).instantiateInitialViewController() as? TCDeviceMainViewController{ + TC1ServiceManager.share.closeService() vc.deviceModel = self.dataSource[indexPath.row] vc.title = self.dataSource[indexPath.row].name self.navigationController?.pushViewController(vc, animated: true) diff --git a/TC1-NG/TC1ServiceManager.swift b/TC1-NG/TC1ServiceManager.swift index 40cde26..b40266c 100644 --- a/TC1-NG/TC1ServiceManager.swift +++ b/TC1-NG/TC1ServiceManager.swift @@ -218,6 +218,7 @@ extension TC1ServiceManager{ "plug_5":["setting":["name":nil]] ] as [String : Any?] self.publishMessage(cmd as [String : Any],qos: 1) + self.sendDeviceReportCmd() } }