From 210f08452fcfe1a5ae8dfe6bb93d5421223414f5 Mon Sep 17 00:00:00 2001 From: philips77 Date: Mon, 1 Mar 2021 09:56:12 +0100 Subject: [PATCH 1/6] Bug fixed: Handling Get messages in Server models --- ...ricDefaultTransitionTimeServerDelegate.swift | 6 ++++-- .../GenericLevelServerDelegate.swift | 3 +++ .../GenericOnOffServerDelegate.swift | 3 +++ .../Mesh Network/SceneServerDelegate.swift | 17 +++++++++++------ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Example/nRFMeshProvision/Mesh Network/GenericDefaultTransitionTimeServerDelegate.swift b/Example/nRFMeshProvision/Mesh Network/GenericDefaultTransitionTimeServerDelegate.swift index a45621b6a..97e51dcb2 100644 --- a/Example/nRFMeshProvision/Mesh Network/GenericDefaultTransitionTimeServerDelegate.swift +++ b/Example/nRFMeshProvision/Mesh Network/GenericDefaultTransitionTimeServerDelegate.swift @@ -73,14 +73,16 @@ class GenericDefaultTransitionTimeServerDelegate: ModelDelegate { } defaultTransitionTime = request.transitionTime defaults.set(defaultTransitionTime.interval, forKey: "defaultTransitionTime") - fallthrough case is GenericDefaultTransitionTimeGet: - return GenericDefaultTransitionTimeStatus(transitionTime: defaultTransitionTime) + break default: fatalError("Not possible") } + + // Reply with GenericDefaultTransitionTimeStatus. + return GenericDefaultTransitionTimeStatus(transitionTime: defaultTransitionTime) } func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage, diff --git a/Example/nRFMeshProvision/Mesh Network/GenericLevelServerDelegate.swift b/Example/nRFMeshProvision/Mesh Network/GenericLevelServerDelegate.swift index 5fffde56e..c1240c6a1 100644 --- a/Example/nRFMeshProvision/Mesh Network/GenericLevelServerDelegate.swift +++ b/Example/nRFMeshProvision/Mesh Network/GenericLevelServerDelegate.swift @@ -211,6 +211,9 @@ class GenericLevelServerDelegate: StoredWithSceneModelDelegate { delay: delay, duration: transitionTime.interval) + case is GenericLevelGet: + break + default: fatalError("Not possible") } diff --git a/Example/nRFMeshProvision/Mesh Network/GenericOnOffServerDelegate.swift b/Example/nRFMeshProvision/Mesh Network/GenericOnOffServerDelegate.swift index be1837460..c90f67d7d 100644 --- a/Example/nRFMeshProvision/Mesh Network/GenericOnOffServerDelegate.swift +++ b/Example/nRFMeshProvision/Mesh Network/GenericOnOffServerDelegate.swift @@ -162,6 +162,9 @@ class GenericOnOffServerDelegate: StoredWithSceneModelDelegate { delay: delay, duration: transitionTime.interval) + case is GenericOnOffGet: + break + default: fatalError("Not possible") } diff --git a/Example/nRFMeshProvision/Mesh Network/SceneServerDelegate.swift b/Example/nRFMeshProvision/Mesh Network/SceneServerDelegate.swift index c5b509794..cf0ce2b38 100644 --- a/Example/nRFMeshProvision/Mesh Network/SceneServerDelegate.swift +++ b/Example/nRFMeshProvision/Mesh Network/SceneServerDelegate.swift @@ -174,15 +174,20 @@ class SceneServerDelegate: SceneServerModelDelegate { transitionTime: transitionTime, delay: delay) } - fallthrough + + case is SceneGet: + break default: - if let (targetScene, complete) = targetScene { - let remainingTime = TransitionTime(complete.timeIntervalSinceNow) - return SceneStatus(report: targetScene, remainingTime: remainingTime) - } - return SceneStatus(report: currentScene) + fatalError("Not possible") + } + + // Reply with SceneStatus. + if let (targetScene, complete) = targetScene { + let remainingTime = TransitionTime(complete.timeIntervalSinceNow) + return SceneStatus(report: targetScene, remainingTime: remainingTime) } + return SceneStatus(report: currentScene) } func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage, From 7546f49a6eac4d718e8e3c92de2cdc411ca73b99 Mon Sep 17 00:00:00 2001 From: philips77 Date: Mon, 1 Mar 2021 10:06:26 +0100 Subject: [PATCH 2/6] Bug fixed: Allow writing HEX as scene numbers --- Example/nRFMeshProvision/Utils/UIViewController+Alert.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Example/nRFMeshProvision/Utils/UIViewController+Alert.swift b/Example/nRFMeshProvision/Utils/UIViewController+Alert.swift index f5e1890a6..692f5afd5 100644 --- a/Example/nRFMeshProvision/Utils/UIViewController+Alert.swift +++ b/Example/nRFMeshProvision/Utils/UIViewController+Alert.swift @@ -183,9 +183,10 @@ extension UIViewController { textField.autocapitalizationType = .words break case .unicastAddress, .groupAddress, - .unicastAddressRequired, .groupAddressRequired: + .unicastAddressRequired, .groupAddressRequired, + .scene, .sceneRequired: textField.autocapitalizationType = .allCharacters - case .ttlRequired, .scene, .sceneRequired: + case .ttlRequired: textField.keyboardType = .numberPad default: break From 20d8ceab686e7d7471dd78e522f92cb9de8c63bd Mon Sep 17 00:00:00 2001 From: philips77 Date: Mon, 1 Mar 2021 10:14:34 +0100 Subject: [PATCH 3/6] Bug fixed: Possible crash fixed --- .../Network/Provisioning/ScannerTableViewController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Example/nRFMeshProvision/View Controllers/Network/Provisioning/ScannerTableViewController.swift b/Example/nRFMeshProvision/View Controllers/Network/Provisioning/ScannerTableViewController.swift index 6441a66de..26a2a5a72 100644 --- a/Example/nRFMeshProvision/View Controllers/Network/Provisioning/ScannerTableViewController.swift +++ b/Example/nRFMeshProvision/View Controllers/Network/Provisioning/ScannerTableViewController.swift @@ -116,10 +116,10 @@ class ScannerTableViewController: UITableViewController { selectedDevice = discoveredPeripherals[indexPath.row].device alert = UIAlertController(title: "Status", message: "Connecting...", preferredStyle: .alert) - alert!.addAction(UIAlertAction(title: "Cancel", style: .cancel) { action in + alert!.addAction(UIAlertAction(title: "Cancel", style: .cancel) { [weak self, bearer] action in action.isEnabled = false - self.alert!.title = "Aborting" - self.alert!.message = "Cancelling connection..." + self?.alert?.title = "Aborting" + self?.alert?.message = "Cancelling connection..." bearer.close() }) present(alert!, animated: true) { From ee3997211569e3c49c144ee71984d35669f5f9de Mon Sep 17 00:00:00 2001 From: philips77 Date: Mon, 1 Mar 2021 10:15:58 +0100 Subject: [PATCH 4/6] Version 3.1.0 build 3 --- Example/nRFMeshProvision.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/nRFMeshProvision.xcodeproj/project.pbxproj b/Example/nRFMeshProvision.xcodeproj/project.pbxproj index ef1266f10..fb69dfd63 100644 --- a/Example/nRFMeshProvision.xcodeproj/project.pbxproj +++ b/Example/nRFMeshProvision.xcodeproj/project.pbxproj @@ -1356,7 +1356,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; CODE_SIGN_ENTITLEMENTS = nRFMeshProvision_Example.entitlements; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = P3R8YQEV4L; ENABLE_BITCODE = NO; INFOPLIST_FILE = nRFMeshProvision/Info.plist; @@ -1383,7 +1383,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; CODE_SIGN_ENTITLEMENTS = nRFMeshProvision_Example.entitlements; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = P3R8YQEV4L; ENABLE_BITCODE = NO; INFOPLIST_FILE = nRFMeshProvision/Info.plist; From 49c5a666d99177841b9e9d7c6bbb086538334d1f Mon Sep 17 00:00:00 2001 From: philips77 Date: Mon, 1 Mar 2021 12:00:50 +0100 Subject: [PATCH 5/6] Bug fixed: Save modified keys --- .../Settings/EditKeyViewController.swift | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Example/nRFMeshProvision/View Controllers/Settings/EditKeyViewController.swift b/Example/nRFMeshProvision/View Controllers/Settings/EditKeyViewController.swift index cb82ae892..a67922359 100644 --- a/Example/nRFMeshProvision/View Controllers/Settings/EditKeyViewController.swift +++ b/Example/nRFMeshProvision/View Controllers/Settings/EditKeyViewController.swift @@ -60,8 +60,8 @@ class EditKeyViewController: UITableViewController { didSet { if let key = key { newKey = key.key + isApplicationKey = key is ApplicationKey } - isApplicationKey = key is ApplicationKey } } /// A flag containing `true` if the key is an Application Key, or `false` @@ -306,12 +306,24 @@ private extension EditKeyViewController { // Those 2 must be saved before setting the key. let index = newBoundNetworkKeyIndex let adding = isNewKey - + // It is not possible to modify the key without doing Key Refresh Procedure. + // Instead, we'll remove the old key and create a new one with the same key + // Index and new data. + let keyIndex = key?.index + if let oldKey = key, oldKey.key != newKey { + if let key = oldKey as? ApplicationKey { + try! network.remove(applicationKey: key, force: true) + } else if let key = oldKey as? NetworkKey { + try! network.remove(networkKey: key, force: true) + } + key = nil + } + // If a new key was added, or the old one removed, create new keys. if key == nil { if isApplicationKey { - key = try! network.add(applicationKey: newKey, name: newName) + key = try! network.add(applicationKey: newKey, withIndex: keyIndex, name: newName) } else { - key = try! network.add(networkKey: newKey, name: newName) + key = try! network.add(networkKey: newKey, withIndex: keyIndex, name: newName) } } key!.name = newName From 6dfbf27984c53e6c787702ee996c1316edc0f726 Mon Sep 17 00:00:00 2001 From: philips77 Date: Mon, 1 Mar 2021 12:43:15 +0100 Subject: [PATCH 6/6] Version 3.1.0 build 4 --- Example/nRFMeshProvision.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/nRFMeshProvision.xcodeproj/project.pbxproj b/Example/nRFMeshProvision.xcodeproj/project.pbxproj index fb69dfd63..4a7cda7c4 100644 --- a/Example/nRFMeshProvision.xcodeproj/project.pbxproj +++ b/Example/nRFMeshProvision.xcodeproj/project.pbxproj @@ -1356,7 +1356,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; CODE_SIGN_ENTITLEMENTS = nRFMeshProvision_Example.entitlements; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = P3R8YQEV4L; ENABLE_BITCODE = NO; INFOPLIST_FILE = nRFMeshProvision/Info.plist; @@ -1383,7 +1383,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; CODE_SIGN_ENTITLEMENTS = nRFMeshProvision_Example.entitlements; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = P3R8YQEV4L; ENABLE_BITCODE = NO; INFOPLIST_FILE = nRFMeshProvision/Info.plist;