diff --git a/Podfile b/Podfile index f327d8f7..5e35b845 100644 --- a/Podfile +++ b/Podfile @@ -24,6 +24,7 @@ def shared_pods pod 'RxSwift', '~> 6.2.0' pod 'RxCocoa', '~> 6.2.0' pod 'Introspect' + pod 'CocoaLumberjack/Swift' end def test_pods diff --git a/Podfile.lock b/Podfile.lock index b66d5c9b..d64664de 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -8,6 +8,9 @@ PODS: - Charts/Core (= 4.1.0) - Charts/Core (4.1.0): - SwiftAlgorithms (~> 1.0) + - CocoaLumberjack/Core (3.8.2) + - CocoaLumberjack/Swift (3.8.2): + - CocoaLumberjack/Core - Crashlytics (3.12.0): - Fabric (~> 1.9.0) - Fabric (1.9.0) @@ -41,6 +44,7 @@ DEPENDENCIES: - AEXML - ChameleonFramework (~> 2.1.0) - Charts (~> 4.1.0) + - CocoaLumberjack/Swift - Crashlytics (~> 3.12.0) - Fabric - Introspect @@ -66,6 +70,7 @@ SPEC REPOS: - AEXML - ChameleonFramework - Charts + - CocoaLumberjack - Crashlytics - Fabric - Introspect @@ -92,6 +97,7 @@ SPEC CHECKSUMS: AEXML: 1e255ecc6597212f97a7454a69ebd3ede64ac1cf ChameleonFramework: d21a3cc247abfe5e37609a283a8238b03575cf64 Charts: ce0768268078eee0336f122c3c4ca248e4e204c5 + CocoaLumberjack: f8d89a516e7710fdb2e9b8f1560b16ec6040eef0 Crashlytics: a33af323773f73904037dc2e684cd2f0d29f4fe2 Fabric: 09ef2d9b99b104702bede1acaf469fb8f20a9146 Introspect: b62c4dd2063072327c21d618ef2bedc3c87bc366 @@ -113,6 +119,6 @@ SPEC CHECKSUMS: UICircularProgressRing: 19927375b2b21b5fa5fd9582f15ccdef9659da16 XMLDictionary: fa07b6ff422b3a91d47a5de9bc82e3fc04fbd167 -PODFILE CHECKSUM: 90b577a05167576a7f2ac952330395b6f30605e3 +PODFILE CHECKSUM: 99c5e34410dda7fcf73bc0c4eccd032787e4da96 COCOAPODS: 1.12.1 diff --git a/SiliconLabsApp.xcodeproj/project.pbxproj b/SiliconLabsApp.xcodeproj/project.pbxproj index aced54de..5b704523 100644 --- a/SiliconLabsApp.xcodeproj/project.pbxproj +++ b/SiliconLabsApp.xcodeproj/project.pbxproj @@ -873,6 +873,12 @@ 2051328B270365A800C27B92 /* DispatchBlockHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 205131DB270365A800C27B92 /* DispatchBlockHelpers.swift */; }; 2051328C270365A800C27B92 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 205131DC270365A800C27B92 /* SettingsViewController.swift */; }; 2B257CB817ADC2635883B007 /* Pods_WirelessGecko.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E7E1967C516A49F37A0A7B8 /* Pods_WirelessGecko.framework */; }; + 2E4854CE2C4146050096699B /* DDLogFileInfo+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E4854C92C4146050096699B /* DDLogFileInfo+Ext.swift */; }; + 2E4854CF2C4146050096699B /* IOPLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E4854CA2C4146050096699B /* IOPLog.swift */; }; + 2E4854D02C4146050096699B /* IOPLogFilePrinter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E4854CB2C4146050096699B /* IOPLogFilePrinter.swift */; }; + 2E4854D12C4146050096699B /* LogFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E4854CC2C4146050096699B /* LogFile.swift */; }; + 2E4854D32C414B5D0096699B /* SILIOPDeviceResetInfoPopupViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2E4854D22C414B5D0096699B /* SILIOPDeviceResetInfoPopupViewController.xib */; }; + 2E4854D52C414B640096699B /* SILIOPDeviceResetInfoPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E4854D42C414B640096699B /* SILIOPDeviceResetInfoPopupViewController.swift */; }; 2E8E6E782B8C6CEA00906697 /* SILWifiOTAConfigViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2E8E6E762B8C6CEA00906697 /* SILWifiOTAConfigViewController.xib */; }; 2E8E6E792B8C6CEA00906697 /* SILWifiOTAConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E8E6E772B8C6CEA00906697 /* SILWifiOTAConfigViewController.swift */; }; 2E8E6E7D2B8C9B5700906697 /* TextField_Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E8E6E7C2B8C9B5700906697 /* TextField_Util.swift */; }; @@ -895,6 +901,21 @@ 4320C6BF2ADD210D00A6D67A /* OccupancySensorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4320C6BE2ADD210D00A6D67A /* OccupancySensorViewController.m */; }; 4320C6C22ADD214800A6D67A /* ContactSensorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4320C6C12ADD214800A6D67A /* ContactSensorViewController.m */; }; 4320C6C82ADD381800A6D67A /* TemperatureSensorController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4320C6C72ADD381800A6D67A /* TemperatureSensorController.m */; }; + 4388B2C72C2DA13E0068C950 /* SILWiFiLEDViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2C62C2DA13E0068C950 /* SILWiFiLEDViewController.swift */; }; + 4388B2C92C2DBC160068C950 /* SILWiFiLedSensorsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2C82C2DBC160068C950 /* SILWiFiLedSensorsViewModel.swift */; }; + 4388B2CB2C2DC14B0068C950 /* SILWiFiMotionSensorsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2CA2C2DC14B0068C950 /* SILWiFiMotionSensorsViewModel.swift */; }; + 4388B2CD2C2DD9FE0068C950 /* SILWiFiLEDModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2CC2C2DD9FE0068C950 /* SILWiFiLEDModel.swift */; }; + 4388B2CF2C2E8A3C0068C950 /* SILWiFiMotionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2CE2C2E8A3C0068C950 /* SILWiFiMotionViewController.swift */; }; + 4388B2D12C30476E0068C950 /* SILWiFiMotionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2D02C30476E0068C950 /* SILWiFiMotionVC.swift */; }; + 4388B2D32C3047910068C950 /* SILWiFiMotionVcCh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2D22C3047910068C950 /* SILWiFiMotionVcCh.swift */; }; + 4388B2D52C305B0C0068C950 /* WiFiMotionDemoConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2D42C305B0C0068C950 /* WiFiMotionDemoConnection.swift */; }; + 4388B2E22C3FC9370068C950 /* SILAllWiFiSensorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4388B2E12C3FC9370068C950 /* SILAllWiFiSensorModel.swift */; }; + 439F2C792C2C18BF00504A12 /* APIRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439F2C782C2C18BF00504A12 /* APIRequest.swift */; }; + 439F2C7F2C2C242E00504A12 /* SILWifiSensorsHomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439F2C7D2C2C242E00504A12 /* SILWifiSensorsHomeView.swift */; }; + 439F2C852C2C243600504A12 /* SILSensorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439F2C802C2C243600504A12 /* SILSensorCell.swift */; }; + 439F2C862C2C243600504A12 /* SILSensorCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 439F2C812C2C243600504A12 /* SILSensorCell.xib */; }; + 439F2C872C2C243600504A12 /* SILWifiSensors.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 439F2C832C2C243600504A12 /* SILWifiSensors.storyboard */; }; + 439F2C892C2C2B2C00504A12 /* SILWiFiSensorsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439F2C882C2C2B2C00504A12 /* SILWiFiSensorsViewModel.swift */; }; 43D819C92B8CC64C006EB860 /* SILSecurity_7_5TestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D819C82B8CC64C006EB860 /* SILSecurity_7_5TestCase.swift */; }; 43D819CC2B91C4A3006EB860 /* SILIOPTester_Test9.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D819CB2B91C4A3006EB860 /* SILIOPTester_Test9.swift */; }; 43D819CF2B91C610006EB860 /* SILLEPrivacy_7_6TestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D819CE2B91C610006EB860 /* SILLEPrivacy_7_6TestCase.swift */; }; @@ -1870,6 +1891,12 @@ 205131DB270365A800C27B92 /* DispatchBlockHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DispatchBlockHelpers.swift; sourceTree = ""; }; 205131DC270365A800C27B92 /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; 257E756EE6E82EC7E361629D /* Pods-SiliconLabsApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SiliconLabsApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SiliconLabsApp/Pods-SiliconLabsApp.debug.xcconfig"; sourceTree = ""; }; + 2E4854C92C4146050096699B /* DDLogFileInfo+Ext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DDLogFileInfo+Ext.swift"; sourceTree = ""; }; + 2E4854CA2C4146050096699B /* IOPLog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IOPLog.swift; sourceTree = ""; }; + 2E4854CB2C4146050096699B /* IOPLogFilePrinter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IOPLogFilePrinter.swift; sourceTree = ""; }; + 2E4854CC2C4146050096699B /* LogFile.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogFile.swift; sourceTree = ""; }; + 2E4854D22C414B5D0096699B /* SILIOPDeviceResetInfoPopupViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SILIOPDeviceResetInfoPopupViewController.xib; sourceTree = ""; }; + 2E4854D42C414B640096699B /* SILIOPDeviceResetInfoPopupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SILIOPDeviceResetInfoPopupViewController.swift; sourceTree = ""; }; 2E8E6E762B8C6CEA00906697 /* SILWifiOTAConfigViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SILWifiOTAConfigViewController.xib; sourceTree = ""; }; 2E8E6E772B8C6CEA00906697 /* SILWifiOTAConfigViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SILWifiOTAConfigViewController.swift; sourceTree = ""; }; 2E8E6E7C2B8C9B5700906697 /* TextField_Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField_Util.swift; sourceTree = ""; }; @@ -1903,6 +1930,21 @@ 4320C6C12ADD214800A6D67A /* ContactSensorViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContactSensorViewController.m; sourceTree = ""; }; 4320C6C62ADD381800A6D67A /* TemperatureSensorController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TemperatureSensorController.h; sourceTree = ""; }; 4320C6C72ADD381800A6D67A /* TemperatureSensorController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TemperatureSensorController.m; sourceTree = ""; }; + 4388B2C62C2DA13E0068C950 /* SILWiFiLEDViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiLEDViewController.swift; sourceTree = ""; }; + 4388B2C82C2DBC160068C950 /* SILWiFiLedSensorsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiLedSensorsViewModel.swift; sourceTree = ""; }; + 4388B2CA2C2DC14B0068C950 /* SILWiFiMotionSensorsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiMotionSensorsViewModel.swift; sourceTree = ""; }; + 4388B2CC2C2DD9FE0068C950 /* SILWiFiLEDModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiLEDModel.swift; sourceTree = ""; }; + 4388B2CE2C2E8A3C0068C950 /* SILWiFiMotionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiMotionViewController.swift; sourceTree = ""; }; + 4388B2D02C30476E0068C950 /* SILWiFiMotionVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiMotionVC.swift; sourceTree = ""; }; + 4388B2D22C3047910068C950 /* SILWiFiMotionVcCh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiMotionVcCh.swift; sourceTree = ""; }; + 4388B2D42C305B0C0068C950 /* WiFiMotionDemoConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WiFiMotionDemoConnection.swift; sourceTree = ""; }; + 4388B2E12C3FC9370068C950 /* SILAllWiFiSensorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILAllWiFiSensorModel.swift; sourceTree = ""; }; + 439F2C782C2C18BF00504A12 /* APIRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = APIRequest.swift; sourceTree = ""; }; + 439F2C7D2C2C242E00504A12 /* SILWifiSensorsHomeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SILWifiSensorsHomeView.swift; sourceTree = ""; }; + 439F2C802C2C243600504A12 /* SILSensorCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SILSensorCell.swift; sourceTree = ""; }; + 439F2C812C2C243600504A12 /* SILSensorCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SILSensorCell.xib; sourceTree = ""; }; + 439F2C832C2C243600504A12 /* SILWifiSensors.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = SILWifiSensors.storyboard; sourceTree = ""; }; + 439F2C882C2C2B2C00504A12 /* SILWiFiSensorsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILWiFiSensorsViewModel.swift; sourceTree = ""; }; 43D819C82B8CC64C006EB860 /* SILSecurity_7_5TestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SILSecurity_7_5TestCase.swift; sourceTree = ""; }; 43D819CB2B91C4A3006EB860 /* SILIOPTester_Test9.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SILIOPTester_Test9.swift; sourceTree = ""; }; 43D819CE2B91C610006EB860 /* SILLEPrivacy_7_6TestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SILLEPrivacy_7_6TestCase.swift; sourceTree = ""; }; @@ -3314,6 +3356,7 @@ 1E4D8F4326035FE000924430 /* IOP Test App */ = { isa = PBXGroup; children = ( + 2E4854CD2C4146050096699B /* Log */, 1E5FEAA4261F37BD00D00E5F /* UI */, 1E5FEAAA261F3A2800D00E5F /* ViewModel */, 1EC1F199260CE1EE00508552 /* TestScenario */, @@ -3547,6 +3590,8 @@ isa = PBXGroup; children = ( 80DBE36E282E4B0D00F7C579 /* SILIOPInfoPopup.swift */, + 2E4854D42C414B640096699B /* SILIOPDeviceResetInfoPopupViewController.swift */, + 2E4854D22C414B5D0096699B /* SILIOPDeviceResetInfoPopupViewController.xib */, 80DBE36D282E4B0D00F7C579 /* SILIOPInfoPopup.xib */, 1E4D8F4726035FE000924430 /* SILIOPTesterViewController.swift */, 1E4D8F4826035FE000924430 /* SILIOPTestScenarioCellView.swift */, @@ -4351,6 +4396,17 @@ path = "React-Sense"; sourceTree = ""; }; + 2E4854CD2C4146050096699B /* Log */ = { + isa = PBXGroup; + children = ( + 2E4854C92C4146050096699B /* DDLogFileInfo+Ext.swift */, + 2E4854CA2C4146050096699B /* IOPLog.swift */, + 2E4854CB2C4146050096699B /* IOPLogFilePrinter.swift */, + 2E4854CC2C4146050096699B /* LogFile.swift */, + ); + path = Log; + sourceTree = ""; + }; 2E8E6E7A2B8C7FFD00906697 /* WiFi_OTA */ = { isa = PBXGroup; children = ( @@ -4410,6 +4466,76 @@ path = stylekit; sourceTree = ""; }; + 439F2C742C2C178000504A12 /* APIService */ = { + isa = PBXGroup; + children = ( + 439F2C782C2C18BF00504A12 /* APIRequest.swift */, + ); + path = APIService; + sourceTree = ""; + }; + 439F2C762C2C17D800504A12 /* ViewModel */ = { + isa = PBXGroup; + children = ( + 439F2C882C2C2B2C00504A12 /* SILWiFiSensorsViewModel.swift */, + 4388B2C82C2DBC160068C950 /* SILWiFiLedSensorsViewModel.swift */, + 4388B2CA2C2DC14B0068C950 /* SILWiFiMotionSensorsViewModel.swift */, + ); + path = ViewModel; + sourceTree = ""; + }; + 439F2C772C2C17EC00504A12 /* Model */ = { + isa = PBXGroup; + children = ( + 4388B2CC2C2DD9FE0068C950 /* SILWiFiLEDModel.swift */, + 4388B2E12C3FC9370068C950 /* SILAllWiFiSensorModel.swift */, + ); + path = Model; + sourceTree = ""; + }; + 439F2C7C2C2C23C100504A12 /* WiFi_Sensor */ = { + isa = PBXGroup; + children = ( + 439F2C842C2C243600504A12 /* View */, + 439F2C7E2C2C242E00504A12 /* Controller */, + 439F2C772C2C17EC00504A12 /* Model */, + 439F2C762C2C17D800504A12 /* ViewModel */, + 439F2C742C2C178000504A12 /* APIService */, + ); + path = WiFi_Sensor; + sourceTree = ""; + }; + 439F2C7E2C2C242E00504A12 /* Controller */ = { + isa = PBXGroup; + children = ( + 439F2C7D2C2C242E00504A12 /* SILWifiSensorsHomeView.swift */, + 4388B2C62C2DA13E0068C950 /* SILWiFiLEDViewController.swift */, + 4388B2CE2C2E8A3C0068C950 /* SILWiFiMotionViewController.swift */, + 4388B2D02C30476E0068C950 /* SILWiFiMotionVC.swift */, + 4388B2D22C3047910068C950 /* SILWiFiMotionVcCh.swift */, + 4388B2D42C305B0C0068C950 /* WiFiMotionDemoConnection.swift */, + ); + path = Controller; + sourceTree = ""; + }; + 439F2C822C2C243600504A12 /* Cell */ = { + isa = PBXGroup; + children = ( + 439F2C802C2C243600504A12 /* SILSensorCell.swift */, + 439F2C812C2C243600504A12 /* SILSensorCell.xib */, + ); + path = Cell; + sourceTree = ""; + }; + 439F2C842C2C243600504A12 /* View */ = { + isa = PBXGroup; + children = ( + 439F2C822C2C243600504A12 /* Cell */, + 439F2C832C2C243600504A12 /* SILWifiSensors.storyboard */, + ); + path = View; + sourceTree = ""; + }; 43D819CA2B91C379006EB860 /* Test_9 */ = { isa = PBXGroup; children = ( @@ -4949,6 +5075,7 @@ E621B33D1A65562400223C5A /* ViewControllers */ = { isa = PBXGroup; children = ( + 439F2C7C2C2C23C100504A12 /* WiFi_Sensor */, 2E8E6E7A2B8C7FFD00906697 /* WiFi_OTA */, 72E78A482A97819A003F05F7 /* MatterDemo */, 1E0C126F298BE6E500BCADFC /* ESLDemo */, @@ -5484,6 +5611,7 @@ 0C2FCB9F1F9A542300F4F259 /* SILBeaconRegistryEntryCell.xib in Resources */, 20513202270365A800C27B92 /* SettingsViewController.storyboard in Resources */, 1E26EC45254B1BFC002FFAAB /* SILDebugCharacteristicEncodingFieldTableViewCell.xib in Resources */, + 439F2C872C2C243600504A12 /* SILWifiSensors.storyboard in Resources */, 1EEFB215252218DD00DD2DD7 /* SILCharacteristicWriteFieldTableViewCell.xib in Resources */, 20513228270365A800C27B92 /* TBSense_Rev_Lowpoly_2.mtl in Resources */, 0C2FCBA01F9A542300F4F259 /* SILDebugDeviceTableViewCell~iphone.xib in Resources */, @@ -5505,6 +5633,7 @@ 0C2FCBA61F9A542300F4F259 /* SILOTAHUDView.xib in Resources */, 80DBE36F282E4B0D00F7C579 /* SILIOPInfoPopup.xib in Resources */, 80671C38271EE2A4009B6284 /* BRD4184A_LowPoly.obj in Resources */, + 2E4854D32C414B5D0096699B /* SILIOPDeviceResetInfoPopupViewController.xib in Resources */, 0C2FCBA71F9A542300F4F259 /* SILDebugCharacteristicValueFieldTableViewCell.xib in Resources */, 0F34409620AF0E250067397C /* SILAppTypeRangeTest.storyboard in Resources */, 0C2FCBA81F9A542300F4F259 /* SILActivityBarViewController.xib in Resources */, @@ -5525,6 +5654,7 @@ 4C9EAB5924042FA90023FFB1 /* Roboto-Black.ttf in Resources */, 1EEE315723F57CED0076E731 /* SILBeaconTypeTableViewCell.xib in Resources */, 1E145AEF266E5EA1009792C2 /* SILWarningViewController.xib in Resources */, + 439F2C862C2C243600504A12 /* SILSensorCell.xib in Resources */, 1E4DB3AE266A720600405BD2 /* SILCreateGattCharacteristicViewController.xib in Resources */, 80671C3F271EE2A4009B6284 /* BRD4184A_LowPoly.dae in Resources */, 807B139B2523355A0056CFCC /* SILDebugCharacteristicEncodingFieldEntryCell.xib in Resources */, @@ -5722,6 +5852,7 @@ "${BUILT_PRODUCTS_DIR}/ActionSheetPicker-3.0/ActionSheetPicker_3_0.framework", "${BUILT_PRODUCTS_DIR}/ChameleonFramework/ChameleonFramework.framework", "${BUILT_PRODUCTS_DIR}/Charts/Charts.framework", + "${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework", "${BUILT_PRODUCTS_DIR}/IP-UIKit-Wisdom/IP_UIKit_Wisdom.framework", "${BUILT_PRODUCTS_DIR}/Introspect/Introspect.framework", "${BUILT_PRODUCTS_DIR}/KVOController/KVOController.framework", @@ -5747,6 +5878,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ActionSheetPicker_3_0.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ChameleonFramework.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Charts.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CocoaLumberjack.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IP_UIKit_Wisdom.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Introspect.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KVOController.framework", @@ -5800,6 +5932,7 @@ "${BUILT_PRODUCTS_DIR}/ActionSheetPicker-3.0/ActionSheetPicker_3_0.framework", "${BUILT_PRODUCTS_DIR}/ChameleonFramework/ChameleonFramework.framework", "${BUILT_PRODUCTS_DIR}/Charts/Charts.framework", + "${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework", "${BUILT_PRODUCTS_DIR}/IP-UIKit-Wisdom/IP_UIKit_Wisdom.framework", "${BUILT_PRODUCTS_DIR}/Introspect/Introspect.framework", "${BUILT_PRODUCTS_DIR}/KVOController/KVOController.framework", @@ -5821,6 +5954,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ActionSheetPicker_3_0.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ChameleonFramework.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Charts.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CocoaLumberjack.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IP_UIKit_Wisdom.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Introspect.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KVOController.framework", @@ -5883,6 +6017,7 @@ "${BUILT_PRODUCTS_DIR}/ActionSheetPicker-3.0/ActionSheetPicker_3_0.framework", "${BUILT_PRODUCTS_DIR}/ChameleonFramework/ChameleonFramework.framework", "${BUILT_PRODUCTS_DIR}/Charts/Charts.framework", + "${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework", "${BUILT_PRODUCTS_DIR}/IP-UIKit-Wisdom/IP_UIKit_Wisdom.framework", "${BUILT_PRODUCTS_DIR}/Introspect/Introspect.framework", "${BUILT_PRODUCTS_DIR}/KVOController/KVOController.framework", @@ -5904,6 +6039,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ActionSheetPicker_3_0.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ChameleonFramework.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Charts.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CocoaLumberjack.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IP_UIKit_Wisdom.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Introspect.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KVOController.framework", @@ -5935,6 +6071,7 @@ "${BUILT_PRODUCTS_DIR}/ActionSheetPicker-3.0/ActionSheetPicker_3_0.framework", "${BUILT_PRODUCTS_DIR}/ChameleonFramework/ChameleonFramework.framework", "${BUILT_PRODUCTS_DIR}/Charts/Charts.framework", + "${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework", "${BUILT_PRODUCTS_DIR}/IP-UIKit-Wisdom/IP_UIKit_Wisdom.framework", "${BUILT_PRODUCTS_DIR}/Introspect/Introspect.framework", "${BUILT_PRODUCTS_DIR}/KVOController/KVOController.framework", @@ -5956,6 +6093,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ActionSheetPicker_3_0.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ChameleonFramework.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Charts.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CocoaLumberjack.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IP_UIKit_Wisdom.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Introspect.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KVOController.framework", @@ -6043,6 +6181,7 @@ 205131EA270365A800C27B92 /* ApplicationConfig.swift in Sources */, 1EC1F2D6260CF44900508552 /* SILIOPTester_Test3.swift in Sources */, 1E56B233263702C7004F3EA6 /* SILIOPGATTOperationsTestHelper.swift in Sources */, + 4388B2E22C3FC9370068C950 /* SILAllWiFiSensorModel.swift in Sources */, 1EEE315D23F58C210076E731 /* SILBrowserFilterBeaconTypeViewController.m in Sources */, 2051326B270365A800C27B92 /* BleMotionDemoConnection.swift in Sources */, 1E1907B123FD850700DD014C /* SILSavedSearchesRealmModel.m in Sources */, @@ -6053,6 +6192,7 @@ 2FD579DD2579352C001D7E9E /* UIViewController+SILContext.swift in Sources */, 8044307D270F008200DD3EA6 /* SILIOPTestReconnectManager.swift in Sources */, 1E26EC99255019E0002FFAAB /* SILAdvertiserDetailsWireframe.swift in Sources */, + 4388B2CB2C2DC14B0068C950 /* SILWiFiMotionSensorsViewModel.swift in Sources */, 1E973CF22672693400B5FC71 /* SILAppTypeBlinkyViewController.swift in Sources */, 20513288270365A800C27B92 /* EnvironmentDemoCollectionViewDataSource.swift in Sources */, 0C2FCB031F9A542300F4F259 /* SILBluetoothFieldModel.m in Sources */, @@ -6149,6 +6289,7 @@ FE7B8FDF292E4FBD0075D894 /* SILIOPTestDeviceSelectorController.swift in Sources */, 1EC1F282260CECAF00508552 /* SILThroughputTestCase.swift in Sources */, 80DBE370282E4B0D00F7C579 /* SILIOPInfoPopup.swift in Sources */, + 2E4854D02C4146050096699B /* IOPLogFilePrinter.swift in Sources */, 0C2FCB1B1F9A542300F4F259 /* DebugDeviceFilterViewController.swift in Sources */, FEDB768A286D9CC3004FC2DC /* ViewWithFloatingButton.swift in Sources */, 1E51563D26B81B9300CCB2CA /* SILGattProjectMarker.swift in Sources */, @@ -6291,6 +6432,7 @@ 1EFC766226AEDF770035594E /* SILGattConfigurationCharacteristicEntity+SILGattXMLExportable.swift in Sources */, 1E4D8F6026035FE000924430 /* SILIopTestOTAUpdateManger.swift in Sources */, 1E26EC54255019A1002FFAAB /* SILAdvertiserRemoveSetting.swift in Sources */, + 4388B2CD2C2DD9FE0068C950 /* SILWiFiLEDModel.swift in Sources */, 1E26ECC025501A0A002FFAAB /* SILAdvertisingDataViewModelBuilder.swift in Sources */, 2E8E6EC62B8E297100906697 /* ProgressStyleKit.swift in Sources */, 2051326A270365A800C27B92 /* SwitchView.swift in Sources */, @@ -6301,12 +6443,14 @@ 0C2FCB3C1F9A542300F4F259 /* SILHeartRateMeasurement.m in Sources */, 1E4DB384266A71E000405BD2 /* SILBrowserDetailsTabBar.swift in Sources */, 1EFC76BE26AEE02A0035594E /* SILThroughputViewModel.swift in Sources */, + 4388B2C72C2DA13E0068C950 /* SILWiFiLEDViewController.swift in Sources */, 0C2FCB3D1F9A542300F4F259 /* SILApp+AttributedProfiles.m in Sources */, 0C2FCB3E1F9A542300F4F259 /* SILOTAFirmwareFile.m in Sources */, 1E4DB342266A711700405BD2 /* SILBluetoothServiceDescriptorModel.swift in Sources */, 1E90F5E42473E73E0013AABD /* SILDebugServicesMenuViewController.swift in Sources */, 1EC1F1DB260CE95900508552 /* SILDiscoverFirmwareInfo.swift in Sources */, 72CA90002ABCBBD700FE70BA /* MatterHomeViewController.m in Sources */, + 4388B2D52C305B0C0068C950 /* WiFiMotionDemoConnection.swift in Sources */, 2F0DE91D258B7F4D00BEFF76 /* SILContextMenu.swift in Sources */, FE417EB22893E4A0003FDDD0 /* CharacteristicFieldValueConverterError.swift in Sources */, 1EFC76AA26AEDFA40035594E /* SILCreateGattDescriptorViewModel.swift in Sources */, @@ -6331,6 +6475,7 @@ 0C2FCB471F9A542300F4F259 /* CBService+Categories.m in Sources */, 80B5FF9F275F912F008F08A8 /* SILWifiCommissioningConnectedAPCellView.swift in Sources */, 43D819CF2B91C610006EB860 /* SILLEPrivacy_7_6TestCase.swift in Sources */, + 2E4854CF2C4146050096699B /* IOPLog.swift in Sources */, 1E26EC85255019E0002FFAAB /* SILAdvertiserCellView.swift in Sources */, 13ACBA87256FB1D400D3EE11 /* SILRangeTestAppContainerViewController.swift in Sources */, 1E26EC9C255019E0002FFAAB /* SILAdvertiserAdd16BitServiceDialogViewController.swift in Sources */, @@ -6374,6 +6519,7 @@ 0C2FCB4D1F9A542300F4F259 /* SILKeyValueViewModel.m in Sources */, 80C67059255169950083D20C /* SILRadioButton.swift in Sources */, 1E4DB343266A711700405BD2 /* SILBluetoothServiceCharacteristicModel.swift in Sources */, + 439F2C7F2C2C242E00504A12 /* SILWifiSensorsHomeView.swift in Sources */, 2E8E6E9B2B8CAAD500906697 /* GCDAsyncUdpSocket.m in Sources */, 1EE26CB829CDBCE1006417D1 /* SILESLCommandDelete.swift in Sources */, 1EFC770D26AEE1D60035594E /* SILCharacteristicWriteCellViewModels.swift in Sources */, @@ -6422,6 +6568,7 @@ 20513273270365A800C27B92 /* DeviceTransportDelegate.swift in Sources */, 1E48A1E92484E27300C188C0 /* SILAnimatedUIButton.swift in Sources */, 72CA8FCC2ABCBB7B00FE70BA /* FabricKeys.m in Sources */, + 439F2C892C2C2B2C00504A12 /* SILWiFiSensorsViewModel.swift in Sources */, 80B5FF88275F911E008F08A8 /* SILTimeoutTimer.swift in Sources */, 0C08FD5820CB1CA90016CABC /* SILConnectedLightingViewController.m in Sources */, 1EFC770C26AEE1D60035594E /* SILCharacteristicWriteViewModel.swift in Sources */, @@ -6438,6 +6585,7 @@ 205131EC270365A800C27B92 /* DeviceConnection.swift in Sources */, 1E1457F5266E0555009792C2 /* SILThroughputPeripheral.swift in Sources */, 2051326C270365A800C27B92 /* DemoConnection.swift in Sources */, + 4388B2D12C30476E0068C950 /* SILWiFiMotionVC.swift in Sources */, 4C4F2DE124080E50005D43BB /* SILRoundedButton.swift in Sources */, 1E36E8B729D082C00011BA0D /* SILESLDemoTagCell.swift in Sources */, 20513254270365A800C27B92 /* ButtonSpinner.swift in Sources */, @@ -6467,6 +6615,7 @@ 0C2FCB5C1F9A542300F4F259 /* SILOTASetupViewController.m in Sources */, 1E7CD33A260DDE740022FE80 /* SILIOPTesterCentralManager.swift in Sources */, 80AF191E2677A068002A58DB /* SILGattConfiguratorCheckBoxCellView.swift in Sources */, + 439F2C852C2C243600504A12 /* SILSensorCell.swift in Sources */, 1EFC766126AEDF770035594E /* SILGattConfigurationProperty+SILGattXMLExportable.swift in Sources */, 1EEFB22A2524B45000DD2DD7 /* SILCharacteristicWriteEnumOptionsTableViewCell.swift in Sources */, 1EFC766E26AEDF770035594E /* SILGattXmlParser.swift in Sources */, @@ -6524,6 +6673,7 @@ 1E56E9EB2416974500D5B92A /* SILStoryboard+Constants.m in Sources */, 2051323D270365A800C27B92 /* NSDataExtensions.swift in Sources */, 0C2FCB671F9A542300F4F259 /* SILConstants.m in Sources */, + 4388B2D32C3047910068C950 /* SILWiFiMotionVcCh.swift in Sources */, 1EABF868251B7511006358C8 /* SILCharacteristicWriteViewController.swift in Sources */, 4C3BA289240D58DF00CF3268 /* SILKeychainViewController.swift in Sources */, 1EFC766D26AEDF770035594E /* SILGattXmlMarkerType.swift in Sources */, @@ -6547,6 +6697,7 @@ 2E8E6ECA2B8E297100906697 /* AnimationHelper.swift in Sources */, 0C2FCB6C1F9A542300F4F259 /* SILBluetoothXMLParser.m in Sources */, 4C9EAB4924042A7B0023FFB1 /* SILServiceCell.swift in Sources */, + 4388B2CF2C2E8A3C0068C950 /* SILWiFiMotionViewController.swift in Sources */, 0C2FCB701F9A542300F4F259 /* SILDebugHeaderView.m in Sources */, 4D9E26262212CA7000617DBA /* SILRangeTestBoardInfo.swift in Sources */, FE10E1A82965BBEC00D4D03B /* ScannerTabSettings.swift in Sources */, @@ -6575,6 +6726,7 @@ 1EE26CF529CF3F59006417D1 /* SILAddress.swift in Sources */, 205131F4270365A800C27B92 /* Logging.swift in Sources */, 1E2D9CAC23BA48D600816EC0 /* SILBluetoothBrowserViewController.m in Sources */, + 4388B2C92C2DBC160068C950 /* SILWiFiLedSensorsViewModel.swift in Sources */, 1E4DB3B0266A720600405BD2 /* SILGattConfiguratorCharacteristicCellView.swift in Sources */, 1E4D8F6A26035FE000924430 /* DateExtension.swift in Sources */, 0C2FCB791F9A542300F4F259 /* SILOTAHUDView.m in Sources */, @@ -6583,6 +6735,7 @@ 1EFC767026AEDF770035594E /* SILGattAssignedNumberEntity.swift in Sources */, 20513245270365A800C27B92 /* MotionDemoConnection.swift in Sources */, 0C2FCB7A1F9A542300F4F259 /* SILServiceTableModel.m in Sources */, + 2E4854CE2C4146050096699B /* DDLogFileInfo+Ext.swift in Sources */, 0C2FCB7B1F9A542300F4F259 /* SILBluetoothSearch.m in Sources */, 0C2FCB7D1F9A542300F4F259 /* SILBluetoothCharacteristicModel.m in Sources */, 1EC1F27B260CEC5D00508552 /* SILOTANonAckTestCase.swift in Sources */, @@ -6611,12 +6764,14 @@ 1E90F5EA2473EA650013AABD /* SILDebugServicesMenuViewControllerDelegate.swift in Sources */, 1EC1F28B260CED2400508552 /* SILSecurity_7_2TestCase.swift in Sources */, 1E4DB3B7266A720600405BD2 /* SILGattConfiguratorCharacteristicShadowCellView.swift in Sources */, + 2E4854D52C414B640096699B /* SILIOPDeviceResetInfoPopupViewController.swift in Sources */, 4C2CB435240E725C0079040D /* SILMap.swift in Sources */, FE36FC77286486F700A9CB41 /* TestView.swift in Sources */, 1E4DB3AA266A720600405BD2 /* SILGattConfiguratorHomeViewController.swift in Sources */, 80B5FFA2275F912F008F08A8 /* SILWifiCommissioningPasswordPopup.swift in Sources */, 1E26ECC125501A0A002FFAAB /* SILAdvertiserAdd16BitServiceDialogViewModel.swift in Sources */, 72EEF90E2BF883C0008E7EB4 /* NetworkMonitor.swift in Sources */, + 439F2C792C2C18BF00504A12 /* APIRequest.swift in Sources */, 0C2FCB891F9A542300F4F259 /* SILBluetoothBitModel.m in Sources */, 1E4DB377266A71AE00405BD2 /* SILAppSelectionViewController.swift in Sources */, 20513240270365A800C27B92 /* WYPopoverController+SILHelpers.m in Sources */, @@ -6638,6 +6793,7 @@ 0C2FCB8C1F9A542300F4F259 /* GradientView.swift in Sources */, 20513260270365A800C27B92 /* AsyncOperation.swift in Sources */, 80B5FF87275F911E008F08A8 /* SILWifiCommissioningPeripheralGATTDatabase.swift in Sources */, + 2E4854D12C4146050096699B /* LogFile.swift in Sources */, 0C2FCB8E1F9A542300F4F259 /* KZBehaviour.m in Sources */, FEA6B648295C6E3100D96645 /* SILBrowserPresenter.swift in Sources */, 0C2FCB8F1F9A542300F4F259 /* SILDescriptorTableModel.m in Sources */, @@ -7065,7 +7221,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_RESOURCE_RULES_PATH = ""; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 21; + CURRENT_PROJECT_VERSION = 5; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 52444FG85C; DISPLAY_NAME = "Si Connect"; @@ -7083,7 +7239,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2.9.0; + MARKETING_VERSION = 2.9.1; PRODUCT_BUNDLE_IDENTIFIER = com.silabs.BlueGeckoDemoApp; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -7107,7 +7263,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CODE_SIGN_RESOURCE_RULES_PATH = ""; CODE_SIGN_STYLE = Manual; - CURRENT_PROJECT_VERSION = 21; + CURRENT_PROJECT_VERSION = 5; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=iphoneos*]" = 52444FG85C; @@ -7125,7 +7281,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 2.9.0; + MARKETING_VERSION = 2.9.1; PRODUCT_BUNDLE_IDENTIFIER = com.silabs.BlueGeckoDemoApp; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "BlueGeckoDemoApp Distribution"; diff --git a/SiliconLabsApp/BluetoothControllers/SILCentralManager.m b/SiliconLabsApp/BluetoothControllers/SILCentralManager.m index a7b8cb41..0470df5a 100644 --- a/SiliconLabsApp/BluetoothControllers/SILCentralManager.m +++ b/SiliconLabsApp/BluetoothControllers/SILCentralManager.m @@ -16,6 +16,7 @@ #import "SILWeakNotificationPair.h" #import "SILConstants.h" #import "NSString+SILBrowserNotifications.h" +#import "BlueGecko-Swift.h" #if ENABLE_HOMEKIT #import #endif @@ -58,7 +59,7 @@ @interface SILCentralManager () @property (nonatomic, strong) NSArray *regions; @property (nonatomic, strong) CLLocationManager *locationManager; - +@property (nonatomic, strong) IOPLog *logObj; @end @implementation SILCentralManager @@ -73,6 +74,7 @@ - (instancetype)initWithServiceUUIDs:(NSArray *)serviceUUIDs { [self setupNotifications]; [self setupBeaconMonitoring]; self.connectionsViewModel = [SILBrowserConnectionsViewModel sharedInstance]; + _logObj = [[IOPLog alloc] init]; } return self; } @@ -124,9 +126,14 @@ - (void)setupNotifications { - (void)applicationWillTerminateNotification:(NSNotification *)notification { if (self.connectedPeripheral) { NSLog(@"Disconnected from connected peripheral"); + + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"Disconnected from connected peripheral: %@", self.connectedPeripheral]]; + [self disconnectFromPeripheral:self.connectedPeripheral]; } else if (self.connectingPeripheral) { NSLog(@"Disconnect from connecting peripheral"); + + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"Disconnect from connecting peripheral: %@", self.connectingPeripheral]]; [self disconnectFromPeripheral:self.connectingPeripheral]; } } @@ -383,6 +390,8 @@ - (double)getTimestampWithAdvertisementData:(NSDictionary *)advertisementData { - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { NSLog(@"didConnectPeripheral: %@", peripheral); + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"didConnectPeripheral: %@", peripheral]]; + [self removeUnfiredConnectionTimeoutTimer]; self.connectingPeripheral = nil; self.connectedPeripheral = peripheral; @@ -398,6 +407,11 @@ - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPerip - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { NSLog(@"didFailToConnectPeripheral: %@", peripheral.name); NSLog(@"error: %@", error); + + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"didDisconnectPeripheral: %@", peripheral]]; + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"didDisconnectPeripheral: %@", peripheral.name]]; + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"error: %@", error]]; + [self removeUnfiredConnectionTimeoutTimer]; [self handleConnectionFailureWithError:error]; [self postRegisterLogNotification:[SILLogDataModel prepareLogDescription:@"didFailToConnectPeripheral: " andPeripheral:peripheral andError:error]]; @@ -408,6 +422,10 @@ - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPe NSLog(@"didDisconnectPeripheral: %@", peripheral.name); NSLog(@"error: %@", error); + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"didDisconnectPeripheral: %@", peripheral]]; + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"didDisconnectPeripheral: %@", peripheral.name]]; + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"error: %@", error]]; + BOOL wasConnected = [self.connectionsViewModel isConnectedPeripheral:peripheral]; NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; userInfo[SILCentralManagerPeripheralKey] = peripheral; @@ -415,7 +433,9 @@ - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPe if (error) { userInfo[SILCentralManagerErrorKey] = error; } - + + [_logObj iopLogSwiftFunctionWithMessage:[NSString stringWithFormat:@"UserInfo: %@", userInfo]]; + [[NSNotificationCenter defaultCenter] postNotificationName:SILCentralManagerDidDisconnectPeripheralNotification object:self userInfo:userInfo]; diff --git a/SiliconLabsApp/Categories/UIImage+SILImages.h b/SiliconLabsApp/Categories/UIImage+SILImages.h index b6bc7252..f80c6efb 100644 --- a/SiliconLabsApp/Categories/UIImage+SILImages.h +++ b/SiliconLabsApp/Categories/UIImage+SILImages.h @@ -35,6 +35,8 @@ extern NSString * const SILImageNameHomeWifiCommissioning; extern NSString * const SILImageNameHomeESLDemo; extern NSString * const SILImageNameHomeMatterDemo; extern NSString * const SILImageNameHomeWifiOtaDemo; +//extern NSString * const SILImageNameHomeWifiSensor; +extern NSString * const SILImageNameHomeWiFiSensor; extern NSString * const SILImageNameKeyboard; extern NSString * const SILImageNameKeyboardCheckmark; diff --git a/SiliconLabsApp/Categories/UIImage+SILImages.m b/SiliconLabsApp/Categories/UIImage+SILImages.m index 0f93b963..84e49dd5 100644 --- a/SiliconLabsApp/Categories/UIImage+SILImages.m +++ b/SiliconLabsApp/Categories/UIImage+SILImages.m @@ -35,6 +35,9 @@ NSString * const SILImageNameHomeESLDemo = @"esl_icon"; NSString * const SILImageNameHomeMatterDemo = @"matter_icon"; NSString * const SILImageNameHomeWifiOtaDemo = @"wifi_ota_icon"; +//NSString * const SILImageNameHomeWifiSensor = @"icon - wifi commissioning"; +NSString * const SILImageNameHomeWiFiSensor = @"WiFi_sensore_icon"; + NSString * const SILImageNameKeyboard = @"Keyboard"; NSString * const SILImageNameKeyboardCheckmark = @"KeyboardCheckmark"; diff --git a/SiliconLabsApp/Models/SILApp.h b/SiliconLabsApp/Models/SILApp.h index 25acaf7e..610a8a4f 100644 --- a/SiliconLabsApp/Models/SILApp.h +++ b/SiliconLabsApp/Models/SILApp.h @@ -20,7 +20,8 @@ typedef NS_ENUM(NSInteger, SILAppType) { SILAppTypeWifiCommissioning, SILAppTypeESLDemo, SILAppTypeMatterDemo, - SILAppTypeWifiOTA + SILAppTypeWifiOTA, + SILAppTypeWifiSensor }; @interface SILApp : NSObject diff --git a/SiliconLabsApp/Models/SILApp.m b/SiliconLabsApp/Models/SILApp.m index 3758557b..268ebebb 100644 --- a/SiliconLabsApp/Models/SILApp.m +++ b/SiliconLabsApp/Models/SILApp.m @@ -23,7 +23,8 @@ + (NSArray *)demoApps { [self wifiCommissioningApp], [self eslDemoApp], [self matterDemoApp], - [self WifiOTADemoApp] + [self WifiOTADemoApp], + [self WifiSensorDemoApp] ]; } @@ -117,11 +118,18 @@ + (SILApp *)matterDemoApp { + (SILApp *)WifiOTADemoApp { return [[SILApp alloc] initWithAppType:SILAppTypeWifiOTA - title:@"Wi-fi OTA Demo" + title:@"Wi-Fi OTA Demo" description:@"Control OTA Firmware update over Wi-Fi." showcasedProfiles:@{} imageName:SILImageNameHomeWifiOtaDemo]; } ++ (SILApp *)WifiSensorDemoApp { + return [[SILApp alloc] initWithAppType:SILAppTypeWifiSensor + title:@"Wi-Fi Sensors" + description:@"Read and display sensor data from the dev kit sensors." + showcasedProfiles:@{} + imageName:SILImageNameHomeWiFiSensor]; +} - (instancetype)initWithAppType:(SILAppType)appType title:(NSString *)title diff --git a/SiliconLabsApp/SILAppDelegate.swift b/SiliconLabsApp/SILAppDelegate.swift index b1667b89..7c382271 100644 --- a/SiliconLabsApp/SILAppDelegate.swift +++ b/SiliconLabsApp/SILAppDelegate.swift @@ -12,6 +12,7 @@ import SwiftUI import Fabric import Crashlytics import CoreHaptics +import CocoaLumberjack class SILAppDelegate : UIResponder, UIApplicationDelegate { var window: UIWindow? @@ -33,6 +34,19 @@ class SILAppDelegate : UIResponder, UIApplicationDelegate { window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = UIHostingController(rootView: MainNavigationView()) window?.makeKeyAndVisible() + + setupLogs() + return true } + private func setupLogs() { + DDLog.add(DDOSLogger.sharedInstance) + + let fileLogger: DDFileLogger = DDFileLogger() // File Logger + fileLogger.rollingFrequency = 60 * 60 * 24 // 24 hours + fileLogger.logFileManager.maximumNumberOfLogFiles = 30 + fileLogger.maximumFileSize = 1024 * 1024 * 10 // 10 MiB + DDLog.add(fileLogger) + //SBMLogger.sharedInstance().delegate = self; + } } diff --git a/SiliconLabsApp/SupportingFiles/Colours.xcassets/WifiSensoreColor/Contents.json b/SiliconLabsApp/SupportingFiles/Colours.xcassets/WifiSensoreColor/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Colours.xcassets/WifiSensoreColor/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Colours.xcassets/WifiSensoreColor/sil_regularGreenColor.colorset/Contents.json b/SiliconLabsApp/SupportingFiles/Colours.xcassets/WifiSensoreColor/sil_regularGreenColor.colorset/Contents.json new file mode 100644 index 00000000..cc980d26 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Colours.xcassets/WifiSensoreColor/sil_regularGreenColor.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x59", + "green" : "0xA3", + "red" : "0x14" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Contents.json new file mode 100644 index 00000000..e827a2ce --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "Group 12923.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Group 12923@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Group 12923@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923.png new file mode 100644 index 00000000..09f0fe23 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923@2x.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923@2x.png new file mode 100644 index 00000000..627f1fdb Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923@2x.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923@3x.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923@3x.png new file mode 100644 index 00000000..d16d16ba Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_led_icon.imageset/Group 12923@3x.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Contents.json new file mode 100644 index 00000000..48868508 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "Group 12922.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Group 12922@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Group 12922@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922.png new file mode 100644 index 00000000..d4b47da7 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922@2x.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922@2x.png new file mode 100644 index 00000000..4d787364 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922@2x.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922@3x.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922@3x.png new file mode 100644 index 00000000..cdb74cf1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_motion_icon.imageset/Group 12922@3x.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/Contents.json new file mode 100644 index 00000000..c6e184c4 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "wifi_icon.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "wifi_icon 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "wifi_icon 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon 1.png new file mode 100644 index 00000000..8073f1b5 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon 2.png new file mode 100644 index 00000000..8073f1b5 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon.png new file mode 100644 index 00000000..8073f1b5 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/WiFi_sensore_icon.imageset/wifi_icon.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/Contents.json new file mode 100644 index 00000000..b2f1cbd8 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/Contents.json @@ -0,0 +1,26 @@ +{ + "images" : [ + { + "filename" : "graphic - light_demo - light - off.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "graphic - light_demo - light - off@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "graphic - light_demo - light - off@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off.png new file mode 100644 index 00000000..8f9343d5 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off@2x.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off@2x.png new file mode 100644 index 00000000..a62c13d1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off@2x.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off@3x.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off@3x.png new file mode 100644 index 00000000..8cc1e5eb Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/blub_off_tint.imageset/graphic - light_demo - light - off@3x.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/Contents.json new file mode 100644 index 00000000..13c4569f --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "lightbulb.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb 1.png new file mode 100644 index 00000000..4144d673 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb 2.png new file mode 100644 index 00000000..4144d673 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb.png new file mode 100644 index 00000000..4144d673 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_blue.imageset/lightbulb.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/Contents.json new file mode 100644 index 00000000..95d6c026 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "lightbulb (1).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb (1) 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb (1) 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1) 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1) 1.png new file mode 100644 index 00000000..d753a9ca Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1) 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1) 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1) 2.png new file mode 100644 index 00000000..d753a9ca Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1) 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1).png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1).png new file mode 100644 index 00000000..d753a9ca Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_cyan.imageset/lightbulb (1).png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/Contents.json new file mode 100644 index 00000000..13c4569f --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "lightbulb.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb 1.png new file mode 100644 index 00000000..896b51c1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb 2.png new file mode 100644 index 00000000..896b51c1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb.png new file mode 100644 index 00000000..896b51c1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_green.imageset/lightbulb.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/Contents.json new file mode 100644 index 00000000..13c4569f --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "lightbulb.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb 1.png new file mode 100644 index 00000000..a4c49dc1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb 2.png new file mode 100644 index 00000000..a4c49dc1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb.png new file mode 100644 index 00000000..a4c49dc1 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_magenta.imageset/lightbulb.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/Contents.json new file mode 100644 index 00000000..bbdfab82 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/Contents.json @@ -0,0 +1,26 @@ +{ + "images" : [ + { + "filename" : "lightbulb (3).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb (3) 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb (3) 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "original" + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3) 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3) 1.png new file mode 100644 index 00000000..7b889080 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3) 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3) 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3) 2.png new file mode 100644 index 00000000..7b889080 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3) 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3).png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3).png new file mode 100644 index 00000000..7b889080 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_off.imageset/lightbulb (3).png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/Contents.json new file mode 100644 index 00000000..4a909a21 --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "lightbulb (2).png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb (2) 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb (2) 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2) 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2) 1.png new file mode 100644 index 00000000..4cce2f18 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2) 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2) 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2) 2.png new file mode 100644 index 00000000..4cce2f18 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2) 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2).png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2).png new file mode 100644 index 00000000..4cce2f18 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_on.imageset/lightbulb (2).png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/Contents.json new file mode 100644 index 00000000..13c4569f --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "lightbulb.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb 1.png new file mode 100644 index 00000000..402b2674 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb 2.png new file mode 100644 index 00000000..402b2674 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb.png new file mode 100644 index 00000000..402b2674 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_red.imageset/lightbulb.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/Contents.json b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/Contents.json new file mode 100644 index 00000000..13c4569f --- /dev/null +++ b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "lightbulb.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "lightbulb 1.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "lightbulb 2.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb 1.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb 1.png new file mode 100644 index 00000000..76772222 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb 1.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb 2.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb 2.png new file mode 100644 index 00000000..76772222 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb 2.png differ diff --git a/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb.png b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb.png new file mode 100644 index 00000000..76772222 Binary files /dev/null and b/SiliconLabsApp/SupportingFiles/Images.xcassets/WifiSensore/bulb_yellow.imageset/lightbulb.png differ diff --git a/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionCollectionViewCell.swift b/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionCollectionViewCell.swift index 0f4be2d9..eee1ea4f 100644 --- a/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionCollectionViewCell.swift +++ b/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionCollectionViewCell.swift @@ -46,10 +46,10 @@ class SILAppSelectionCollectionViewCell: UICollectionViewCell { override func prepareForReuse() { super.prepareForReuse() - imageView = nil - iconImageView = nil - titleLabel = nil - descriptionLabel = nil +// imageView = nil +// iconImageView = nil +// titleLabel = nil +// descriptionLabel = nil } func setFieldsIn(_ appData: SILApp?) { diff --git a/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionViewController.swift b/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionViewController.swift index 65098646..6ddb8423 100644 --- a/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionViewController.swift +++ b/SiliconLabsApp/ViewControllers/AppSelection/SILAppSelectionViewController.swift @@ -127,6 +127,11 @@ class SILAppSelectionViewController : UIViewController, UICollectionViewDataSour let nextViewController = storyBoard.instantiateViewController(withIdentifier: "MatterHomeViewController") self.navigationController?.pushViewController(nextViewController, animated: true) } + private func moveToSILWifiSensorsDemoView() { + let storyBoard : UIStoryboard = UIStoryboard(name: "SILWifiSensors", bundle:nil) + let nextViewController = storyBoard.instantiateViewController(withIdentifier: "SILWifiSensorsHomeView") + self.navigationController?.pushViewController(nextViewController, animated: true) + } private func showWifiDisabledAlert() { let message = "Please check your Wi-Fi connection to use Wi-Fi OTA Demo" @@ -201,6 +206,8 @@ class SILAppSelectionViewController : UIViewController, UICollectionViewDataSour case .online(.wiFi): showWiFiOTAScreen() } + case .typeWifiSensor: + moveToSILWifiSensorsDemoView() default: return } diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTestReconnectManager.swift b/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTestReconnectManager.swift index 95facb55..824d8261 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTestReconnectManager.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTestReconnectManager.swift @@ -41,6 +41,7 @@ class SILIOPTestReconnectManager: NSObject { } func reconnectToDevice(withName name: String) { + self.nameToReconnect = name self.setCentralManagerSubscription() @@ -51,6 +52,7 @@ class SILIOPTestReconnectManager: NSObject { selector: #selector(self.scanIntervalTimerFired), userInfo: nil, repeats: false) + } private func setCentralManagerSubscription() { diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTesterCentralManager.swift b/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTesterCentralManager.swift index eae99a88..5219f836 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTesterCentralManager.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIOPTesterCentralManager.swift @@ -84,9 +84,15 @@ enum SILIOPTesterCentralManagerConnectionStatus { func connect(to discoveredPeripheral: SILDiscoveredPeripheral) { guard let peripheral = discoveredPeripheral.peripheral else { debugPrint("CENTRAL MANAGER discovered peripheral is nil!") + + IOPLog().iopLogSwiftFunction(message: "CENTRAL MANAGER discovered peripheral is nil!") + return } debugPrint("CONNECTING PERIPHERAL \(String(describing: peripheral))") + + IOPLog().iopLogSwiftFunction(message: "CONNECTING PERIPHERAL \(String(describing: peripheral))") + self.centralManager.connect(peripheral) } @@ -98,31 +104,52 @@ enum SILIOPTesterCentralManagerConnectionStatus { switch central.state { case .poweredOff: debugPrint("CENTRAL MANAGER powered off") + + IOPLog().iopLogSwiftFunction(message: "CENTRAL MANAGER powered off") + self.stopScanningActions() self.publishConnectionStatus.value = .bluetoothEnabled(enabled: false) case .poweredOn: debugPrint("CENTRAL MANAGER powered on") + + IOPLog().iopLogSwiftFunction(message: "CENTRAL MANAGER powered on") + self.publishConnectionStatus.value = .bluetoothEnabled(enabled: true) case .resetting: debugPrint("CENTRAL MANAGER resetting") + + IOPLog().iopLogSwiftFunction(message: "CENTRAL MANAGER powered resetting") + self.stopScanningActions() self.publishConnectionStatus.value = .bluetoothEnabled(enabled: false) case .unauthorized: debugPrint("CENTRAL MANAGER unauthorized") + + IOPLog().iopLogSwiftFunction(message: "CENTRAL MANAGER unauthorized") + self.stopScanningActions() self.publishConnectionStatus.value = .bluetoothEnabled(enabled: false) case .unknown: debugPrint("CENTRAL MANAGER unknown") + + IOPLog().iopLogSwiftFunction(message: "CENTRAL MANAGER unknown") + self.stopScanningActions() self.publishConnectionStatus.value = .bluetoothEnabled(enabled: false) case .unsupported: debugPrint("CENTRAL MANAGER UNSUPPORTED") + + IOPLog().iopLogSwiftFunction(message: "CENTRAL MANAGER UNSUPPORTED") + self.publishConnectionStatus.value = .bluetoothEnabled(enabled: false) } } func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { debugPrint("DID DISCOVER PERIPHERAL \(peripheral)") + + IOPLog().iopLogSwiftFunction(message: "DID DISCOVER PERIPHERAL \(peripheral)") + if let discoveredPeripheral = self.discoveredPeripherals.first(where: { discoveredPeripheral in discoveredPeripheral.peripheral == peripheral }) { discoveredPeripheral.update(withAdvertisementData: advertisementData, rssi: RSSI, andDiscoveringTimestamp: Date.timeIntervalBetween1970AndReferenceDate) } else { @@ -133,16 +160,25 @@ enum SILIOPTesterCentralManagerConnectionStatus { func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { debugPrint("DID CONNECT \(peripheral)") + + IOPLog().iopLogSwiftFunction(message: "DID CONNECT \(peripheral)") + publishConnectionStatus.value = .connected(peripheral: peripheral) } func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { debugPrint("DID DISCONNECT \(peripheral) WITH ERROR \(error.debugDescription)") + + IOPLog().iopLogSwiftFunction(message: "DID DISCONNECT \(peripheral) WITH ERROR \(error.debugDescription)") + publishConnectionStatus.value = .disconnected(peripheral: peripheral, error: error) } func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) { debugPrint("DID FAIL TO CONNECT \(peripheral) WITH EROR \(error.debugDescription)") + + IOPLog().iopLogSwiftFunction(message: "DID FAIL TO CONNECT \(peripheral) WITH EROR \(error.debugDescription)") + publishConnectionStatus.value = .failToConnect(peripheral: peripheral, error: error) } } diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIopTestOTAUpdateManger.swift b/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIopTestOTAUpdateManger.swift index b99ac5f7..e4345ac5 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIopTestOTAUpdateManger.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/Helpers/SILIopTestOTAUpdateManger.swift @@ -77,6 +77,7 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate @objc private func didConnectPeripheral(notification: Notification) { debugPrint("didConnectPeripheral**********OTA") + IOPLog().iopLogSwiftFunction(message: "didConnectPeripheral**********OTA") if self.otaProgress == .unknown { self.otaProgress = .reconnected } else if self.otaProgress == .initiated || self.otaProgress == .reconnected { @@ -84,11 +85,13 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate } else { self.unregisterNotifications() self.otaTestStatus.value = .failure(reason: "Not allowed connection to peripheral.") + IOPLog().iopLogSwiftFunction(message: "Not allowed connection to peripheral.") } } @objc private func didDisconnectPeripheral(notification: Notification) { debugPrint("didDisconnectPeripheral**********OTA") + IOPLog().iopLogSwiftFunction(message: "didDisconnectPeripheral**********OTA") if self.otaProgress == .reconnected { self.otaProgress = .initiated } else if self.otaProgress == .finished { @@ -101,20 +104,25 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate self.unregisterNotifications() self.failureReson = "Not allowed disconnection from peripheral." self.waitForChangeTopController() + IOPLog().iopLogSwiftFunction(message: "Not allowed disconnection from peripheral.") } } @objc private func didFailToConnectPeripheral(notification: Notification) { debugPrint("didFailToConnectPeripheral**********OTA") + IOPLog().iopLogSwiftFunction(message: "didFailToConnectPeripheral**********OTA") self.unregisterNotifications() self.otaTestStatus.value = .failure(reason: "Fail to connect to peripheral.") + IOPLog().iopLogSwiftFunction(message: "Fail to connect to peripheral.") } @objc private func bluetoothDisabled() { debugPrint("bluetoothDisabled**********OTA") + IOPLog().iopLogSwiftFunction(message: "bluetoothDisabled**********OTA") self.unregisterNotifications() self.dismissPopoverWithCompletion(completion: nil) self.otaTestStatus.value = .failure(reason: "Bluetooth disabled.") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled.") } func setupOTAFirmWareModel() { @@ -170,6 +178,7 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate guard let fileToUpdate = self.fileToUpdate else { self.unregisterNotifications() self.otaTestStatus.value = .failure(reason: "File to update not found.") + IOPLog().iopLogSwiftFunction(message: "File to update not found.") return } @@ -182,10 +191,12 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate } else { self.unregisterNotifications() self.otaTestStatus.value = .failure(reason: "Peripheral disconnected when choosing a file.") + IOPLog().iopLogSwiftFunction(message: "Peripheral disconnected when choosing a file.") } } else { self.unregisterNotifications() self.otaTestStatus.value = .failure(reason: "Chosen file isn't EBL or GBL file") + IOPLog().iopLogSwiftFunction(message: "Chosen file isn't EBL or GBL file") } } @@ -196,6 +207,7 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate } else { self.unregisterNotifications() self.otaTestStatus.value = .failure(reason: "No chosen file.") + IOPLog().iopLogSwiftFunction(message: "No chosen file.") } } @@ -221,6 +233,7 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate } else { self.unregisterNotifications() self.otaTestStatus.value = .failure(reason: "Error during a file update.") + IOPLog().iopLogSwiftFunction(message: "Error during a file update.") } } }) @@ -235,6 +248,7 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate self.handleFileUploadProgress(progress: fraction, uploadedBytes: bytes) }, completion: { (peripheral, error) in print("Completed Flash") + IOPLog().iopLogSwiftFunction(message: "Completed Flash") self.handleAppFileUploadCompletionForPeripheral(peripheral: peripheral, error: error) self.finishOTAError = error if self.finishOTAError == nil { @@ -244,6 +258,7 @@ class SILIopTestOTAUpdateManger: NSObject, SILOTAFirmwareUpdateManagerDelegate self.unregisterNotifications() self.dismissPopoverWithCompletion(completion: { self.otaTestStatus.value = .failure(reason: "Error during a file update.") + IOPLog().iopLogSwiftFunction(message: "Error during a file update.") }) } }) diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/Log/DDLogFileInfo+Ext.swift b/SiliconLabsApp/ViewControllers/IOP Test App/Log/DDLogFileInfo+Ext.swift new file mode 100644 index 00000000..9dc73b8f --- /dev/null +++ b/SiliconLabsApp/ViewControllers/IOP Test App/Log/DDLogFileInfo+Ext.swift @@ -0,0 +1,55 @@ +// +// DDLogFileInfo+Ext.swift +// BlueGecko +// +// Created by SovanDas Maity on 01/07/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import Foundation +import CocoaLumberjack + +private let sizeDivisor = 1024.0 +private let suffixes = ["KiB", "MiB", "GiB", "TiB"] +private let unknown = "Unknown" +private let dateFormat = "yyyy-MM-dd HH:mm:ss" + +extension DDLogFileInfo { + var formattedFileSize: String { + get { + var size: Double = Double(fileSize) / sizeDivisor + var suffixIndex = 0 + while size >= sizeDivisor { + size = size / sizeDivisor + suffixIndex = suffixIndex + 1 + } + + let formattedSize = String(format: "%3.2f", size) + return "\(formattedSize) \(suffixes[suffixIndex])" + } + } + + var localCreationDateString: String { + get { + guard let creationDate = creationDate else { + return unknown + } + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = dateFormat + dateFormatter.timeZone = TimeZone.current + return dateFormatter.string(from: creationDate) + } + } + + var localLastModificationDateString: String { + get { + guard let modificationDate = modificationDate else { + return unknown + } + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = dateFormat + dateFormatter.timeZone = TimeZone.current + return dateFormatter.string(from: modificationDate) + } + } +} diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/Log/IOPLog.swift b/SiliconLabsApp/ViewControllers/IOP Test App/Log/IOPLog.swift new file mode 100644 index 00000000..7f2bd933 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/IOP Test App/Log/IOPLog.swift @@ -0,0 +1,18 @@ +// +// IOPLog.swift +// BlueGecko +// +// Created by SovanDas Maity on 01/07/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import Foundation +import CocoaLumberjack + + +class IOPLog: NSObject { + @objc func iopLogSwiftFunction(message: String) { + let fileName = URL(fileURLWithPath: #file).deletingPathExtension().lastPathComponent + DDLogVerbose("Application: \(fileName): \(message)") + } +} diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/Log/IOPLogFilePrinter.swift b/SiliconLabsApp/ViewControllers/IOP Test App/Log/IOPLogFilePrinter.swift new file mode 100644 index 00000000..7fdef5dd --- /dev/null +++ b/SiliconLabsApp/ViewControllers/IOP Test App/Log/IOPLogFilePrinter.swift @@ -0,0 +1,174 @@ +// +// IOPLogFilePrinter.swift +// BlueGecko +// +// Created by SovanDas Maity on 01/07/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit + +class IOPLogFilePrinter: NSObject { + fileprivate var fileHandle: FileHandle? + private var timestamp: Date + private var deviceName: String + + var getFileUrl: URL { + return URL(fileURLWithPath: getFilePathOfExistingFile()) + } + + var getFilePath: String { + return (IOPLogFilePrinter.logDirPath as NSString).appendingPathComponent(getLogFileName) + } + + private var getLogFileName: String { + let nowString = longStyleDateFormatter().string(from: timestamp) + return String(format: "%@_%@.txt", deviceName.replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: ".", with: "_"), nowString.replacingOccurrences(of: " ", with: "_")) + } + + private static var logDirPath: String { + let documentDirPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + let logDir = (documentDirPath as NSString).appendingPathComponent("TestSILOG") + return logDir + } + + init(timestamp: Date, deviceName: String) { + self.timestamp = timestamp + self.deviceName = deviceName + } + + class func clearLogDir() { + let fileManager = FileManager.default + + do { + let fileNames = try fileManager.contentsOfDirectory(atPath: logDirPath) + for fileName in fileNames { + let filePath = (logDirPath as NSString).appendingPathComponent(fileName) + try fileManager.removeItem(atPath: filePath) + } + } catch { + print("Could not clear dictionary: \(error)") + } + } + + func createEmptyFile(atPath filePath: String) -> Bool { + guard prepareDictionary() else { + return false + } + + guard clearExisitingFile(filePath: filePath) else { + return false + } + + let success = FileManager.default.createFile(atPath: filePath, contents: nil, attributes: nil) + guard success else { + debugPrint("File didn't created.") + return false + } + + addSkipBackupAttributeToItem(filePath: filePath) + + return true + } + + private func prepareDictionary() -> Bool { + if !directoryExists(atPath: IOPLogFilePrinter.logDirPath) { + do { + try FileManager.default.createDirectory(atPath: IOPLogFilePrinter.logDirPath, withIntermediateDirectories: true, attributes: nil) + } catch let error { + debugPrint("Error when creating a directory \(error.localizedDescription)") + return false + } + } + + guard directoryExists(atPath: IOPLogFilePrinter.logDirPath) else { + debugPrint("Directory \(IOPLogFilePrinter.logDirPath) doesn't exists!") + return false + } + + return true + } + + private func clearExisitingFile(filePath: String) -> Bool { + if fileExists(atPath: filePath) { + do { + debugPrint("File at path \(filePath) already exists.") + try FileManager.default.removeItem(atPath: filePath) + } + catch let error { + debugPrint("Error when removing a file \(error.localizedDescription)") + return false + } + } + + return true + } + + func openFile(filePath: String) -> Bool { + if !fileExists(atPath: filePath) && !createEmptyFile(atPath: filePath) { + return false + } + + fileHandle = FileHandle(forWritingAtPath: filePath) + return (fileHandle != nil) + } + + func append(text: String) -> Bool { + if fileHandle == nil { + return false + } + + guard let data = text.data(using: .utf8) else { + return false + } + + fileHandle?.seekToEndOfFile() + fileHandle?.write(data) + return true + } + + func closeFile() { + fileHandle?.closeFile() + } + + private func getFilePathOfExistingFile() -> String { + do { + let fileNames: [String] = try FileManager.default.contentsOfDirectory(atPath: IOPLogFilePrinter.logDirPath) + if fileNames.count == 1, let fileName = fileNames.first { + return (IOPLogFilePrinter.logDirPath as NSString).appendingPathComponent(fileName) + } else { + return self.getFilePath + } + } catch { + return "" + } + } + + private func longStyleDateFormatter() -> DateFormatter { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = DateFormatString.fileNameDateTime.formatString + return dateFormatter + } + + private func directoryExists(atPath dirPath: String) -> Bool { + var isDir: ObjCBool = false + let exists = FileManager.default.fileExists(atPath: dirPath, isDirectory: &isDir) + return (exists && isDir.boolValue) + } + + private func fileExists(atPath dirPath: String) -> Bool { + var isDir: ObjCBool = false + let exists = FileManager.default.fileExists(atPath: dirPath, isDirectory: &isDir) + return (exists && !isDir.boolValue) + } + + private func addSkipBackupAttributeToItem(filePath: String) { + let fileManager = FileManager.default + if !fileManager.fileExists(atPath: filePath) { + return + } + + var url = URL(fileURLWithPath: filePath) + url.setTemporaryResourceValue(true, forKey: .isExcludedFromBackupKey) + } +} diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/Log/LogFile.swift b/SiliconLabsApp/ViewControllers/IOP Test App/Log/LogFile.swift new file mode 100644 index 00000000..05ee9ddf --- /dev/null +++ b/SiliconLabsApp/ViewControllers/IOP Test App/Log/LogFile.swift @@ -0,0 +1,17 @@ +// +// LogFile.swift +// ble_mesh-app +// +// Created by Kamil Czajka on 28/07/2020. +// Copyright © 2020 Silicon Labs, http://www.silabs.com. All rights reserved. +// + +import Foundation +import CocoaLumberjack + +struct LogFile { + var info: DDLogFileInfo + var url: URL { + URL(fileURLWithPath: info.filePath) + } +} diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_1/TestCases/SILScanTestCase.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_1/TestCases/SILScanTestCase.swift index 5c99a91f..abf14352 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_1/TestCases/SILScanTestCase.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_1/TestCases/SILScanTestCase.swift @@ -69,6 +69,7 @@ class SILScanTestCase: SILTestCase, SILTestCaseTimeout, SILTestCaseWithRetries { case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakSelf.invalidateTestTimer() weakSelf.scanTimer?.invalidate() weakSelf.iopCentralManager.stopScanning() @@ -80,6 +81,7 @@ class SILScanTestCase: SILTestCase, SILTestCaseTimeout, SILTestCaseWithRetries { default: weakSelf.publishTestResult(passed: false, description: "Unknown failure from central manager") + IOPLog().iopLogSwiftFunction(message: "Unknown failure from central manager") } }) disposeBag.add(token: centralManagerBluetoothStateSubscription) @@ -106,8 +108,10 @@ class SILScanTestCase: SILTestCase, SILTestCaseTimeout, SILTestCaseWithRetries { let testTime = weakSelf.stopTestTimerWithResult() if testTime < weakSelf.timeoutMS { weakSelf.publishTestResult(passed: true, description: "(Testing time: \(testTime)ms, Acceptable Time: \(weakSelf.timeoutMS)ms).") + IOPLog().iopLogSwiftFunction(message: "(Testing time: \(testTime)ms, Acceptable Time: \(weakSelf.timeoutMS)ms).") } else { weakSelf.publishTestResult(passed: false, description: "Peripheral was discovered but not in \(weakSelf.timeoutMS)ms") + IOPLog().iopLogSwiftFunction(message: "Peripheral was discovered but not in \(weakSelf.timeoutMS)ms") } } }) @@ -131,6 +135,7 @@ class SILScanTestCase: SILTestCase, SILTestCaseTimeout, SILTestCaseWithRetries { self.iopCentralManager.stopScanning() self.publishTestResult(passed: false, description: "Peripheral with name \(String(describing: self.peripheralLocalName)) wasn't found in any of 5 attempts of scanning for \(self.timeoutMS) ms") + IOPLog().iopLogSwiftFunction(message: "Peripheral with name \(String(describing: self.peripheralLocalName)) wasn't found in any of 5 attempts of scanning for \(self.timeoutMS) ms") } // Artifacts diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_2/TestCases/SILConnectDeviceTestCase.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_2/TestCases/SILConnectDeviceTestCase.swift index df28d59d..94a062dd 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_2/TestCases/SILConnectDeviceTestCase.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_2/TestCases/SILConnectDeviceTestCase.swift @@ -76,23 +76,29 @@ class SILConnectDeviceTestCase: SILTestCase, SILTestCaseTimeout, SILTestCaseWith if testTime < weakSelf.timeoutMS { weakSelf.publishTestResult(passed: true, description: "(Testing time: \(testTime)ms, Acceptable Time: \(weakSelf.timeoutMS)ms).") + IOPLog().iopLogSwiftFunction(message: "(Testing time: \(testTime)ms, Acceptable Time: \(weakSelf.timeoutMS)ms).") } else { weakSelf.notifyErrorInAttempt(reason: "Peripheral was connected but not in \(weakSelf.timeoutMS)ms") + IOPLog().iopLogSwiftFunction(message: "Peripheral was connected but not in \(weakSelf.timeoutMS)ms") + } break case let .disconnected(peripheral: peripheral, error: error): weakSelf.notifyErrorInAttempt(reason: "didDisconnectPeripheral \(peripheral) with error \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "didDisconnectPeripheral \(peripheral) with error \(String(describing: error?.localizedDescription))") break case let .failToConnect(peripheral: peripheral, error: error): weakSelf.notifyErrorInAttempt(reason: "didFailToConnectPeripheral \(peripheral) with error \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "didFailToConnectPeripheral \(peripheral) with error \(String(describing: error?.localizedDescription))") break case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakSelf.invalidateTestTimer() weakSelf.connectTimer?.invalidate() weakSelf.publishTestResult(passed: false, description: "Bluetooth disabled!") @@ -120,6 +126,7 @@ class SILConnectDeviceTestCase: SILTestCase, SILTestCaseTimeout, SILTestCaseWith private func notifyErrorInAttempt(reason: String) { debugPrint(reason) + IOPLog().iopLogSwiftFunction(message: "\(reason)") invalidateTestTimer() stopConnecting() } @@ -129,6 +136,7 @@ class SILConnectDeviceTestCase: SILTestCase, SILTestCaseTimeout, SILTestCaseWith self.iopCentralManager.disconnect(peripheral: peripheral) self.publishTestResult(passed: false, description: "Peripheral \(String(describing: self.cbPeripheral)) wasn't connected in any of 5 attempts of connecting for \(self.timeoutMS) ms") + IOPLog().iopLogSwiftFunction(message: "Peripheral \(String(describing: self.cbPeripheral)) wasn't connected in any of 5 attempts of connecting for \(self.timeoutMS) ms") } func getTestArtifacts() -> Dictionary { diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_3/TestCases/SILDiscoverGATTTestCase.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_3/TestCases/SILDiscoverGATTTestCase.swift index db2d4b9f..9fda1b6d 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_3/TestCases/SILDiscoverGATTTestCase.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_3/TestCases/SILDiscoverGATTTestCase.swift @@ -78,11 +78,13 @@ class SILDiscoverGATTTestCase: SILTestCase, SILTestCaseTimeout { switch status { case let .disconnected(peripheral: _, error: error): debugPrint("Peripheral disconnected with \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "Peripheral disconnected with \(String(describing: error?.localizedDescription))") weakSelf.notifyError(reason: "Peripheral was disconnected with \(String(describing: error?.localizedDescription)).") case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakSelf.notifyError(reason: "Bluetooth disabled.") } diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/SILIOPTester_Test4.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/SILIOPTester_Test4.swift index d8d09177..4412d293 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/SILIOPTester_Test4.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/SILIOPTester_Test4.swift @@ -88,19 +88,23 @@ class SILIOPTester_Test4 : SILTestScenario { switch state { case .initiated: debugPrint("DISCOVER FIRMWARE INFO INITIATED") + IOPLog().iopLogSwiftFunction(message: "DISCOVER FIRMWARE INFO INITIATED") break case .running: debugPrint("DISCOVER FIRMWARE INFO RUNNING") + IOPLog().iopLogSwiftFunction(message: "DISCOVER FIRMWARE INFO RUNNING") break case .failed: debugPrint("DISCOVER FIRMWARE INFO FAILED") + IOPLog().iopLogSwiftFunction(message: "DISCOVER FIRMWARE INFO FAILED") weakSelf.tests[0].performTestCase() break case let .completed(stackVersion: stackVersion): debugPrint("DISCOVER FIRMWARE COMPLETED") + IOPLog().iopLogSwiftFunction(message: "DISCOVER FIRMWARE COMPLETED") weakSelf.parameters["stackVersion"] = stackVersion weakSelf.stackVersion = stackVersion weakSelf.discoverRFUFeatures.injectParameters(parameters: weakSelf.parameters) @@ -120,19 +124,23 @@ class SILIOPTester_Test4 : SILTestScenario { switch state { case .initiated: debugPrint("DISCOVER RFU INITIATED") + IOPLog().iopLogSwiftFunction(message: "DISCOVER RFU INITIATED") break case .running: debugPrint("DISCOVER RFU RUNNING") + IOPLog().iopLogSwiftFunction(message: "DISCOVER RFU RUNNING") break case .failed: debugPrint("DISCOVER RFU FAILED") + IOPLog().iopLogSwiftFunction(message: "DISCOVER RFU FAILED") weakSelf.tests[0].performTestCase() break case let .completed(firmwareInfo: firmwareInfo, connectionParameters: connectionParameters): debugPrint("DISCOVER RFU COMPLETED") + IOPLog().iopLogSwiftFunction(message: "DISCOVER RFU COMPLETED") weakSelf.firmwareInfo = firmwareInfo weakSelf.connectionParameters = connectionParameters weakSelf.tests[0].performTestCase() diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverFirmwareInfo.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverFirmwareInfo.swift index 2d9b01c5..d4f42637 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverFirmwareInfo.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverFirmwareInfo.swift @@ -68,12 +68,14 @@ class SILDiscoverFirmwareInfo { switch status { case let .disconnected(peripheral: _, error: error): debugPrint("Peripheral disconnected with \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "Peripheral disconnected with \(String(describing: error?.localizedDescription))") weakSelf.invalidateObservableTokens() weakSelf.state.value = .failed case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakSelf.invalidateObservableTokens() weakSelf.state.value = .failed } diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverTestConnectionParameters.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverTestConnectionParameters.swift index aec58cf2..09d786ef 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverTestConnectionParameters.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILDiscoverTestConnectionParameters.swift @@ -91,11 +91,13 @@ class SILDiscoverTestConnectionParameters { switch status { case let .disconnected(peripheral: _, error: error): debugPrint("Peripheral disconnected with \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "Peripheral disconnected with \(String(describing: error?.localizedDescription))") weakSelf.setFailed() case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakSelf.setFailed() } diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPConstCharacteristicTestHelper.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPConstCharacteristicTestHelper.swift index 013186c5..e6cc1fa9 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPConstCharacteristicTestHelper.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPConstCharacteristicTestHelper.swift @@ -97,6 +97,7 @@ class SILIOPConstCharacteristicTestHelper { case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == weakSelf.iopTestCharacteristicTypesRWConstLen1 { debugPrint("DATA \(String(describing: data?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: data?.hexa()))") if weakSelf.isFirstSubtest, data?.hexa() == weakSelf.ExceptedValue_Subtest1 { weakSelf.isFirstSubtest = false if let dataToWrite = weakSelf.ValueToWrite_Subtest2.data(withCount: 1) { diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTNotificationTestHelper.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTNotificationTestHelper.swift index aec49237..4507de12 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTNotificationTestHelper.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTNotificationTestHelper.swift @@ -121,6 +121,7 @@ class SILIOPGATTNotificationTestHelper: SILTestCaseTimeout, SILTestCaseWithRetri case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == weakSelf.testedCharacteristicUUID { debugPrint("DATA \(String(describing: data?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: data?.hexa()))") weakSelf.testTimeoutTimer?.invalidate() if let data = data?.hexa(), weakSelf.exceptedValue.contains(data) { weakSelf.observableTokens.append(weakSelf.centralManagerSubscription) @@ -135,6 +136,8 @@ class SILIOPGATTNotificationTestHelper: SILTestCaseTimeout, SILTestCaseWithRetri case let .updateNotificationState(characteristic: characteristic, state: state): debugPrint("Notification \(state) on characteristic \(characteristic)") + IOPLog().iopLogSwiftFunction(message: "Notification \(state) on characteristic \(characteristic)") + if characteristic.uuid == weakSelf.testedCharacteristicUUID, state == true { weakSelf.testTimeoutTimer?.invalidate() let testTime = weakSelf.stopTestTimerWithResult() @@ -183,6 +186,7 @@ class SILIOPGATTNotificationTestHelper: SILTestCaseTimeout, SILTestCaseWithRetri switch status { case let .updateNotificationState(characteristic: characteristic, state: state): debugPrint("Notification \(state) on characteristic \(characteristic)") + IOPLog().iopLogSwiftFunction(message: "Notification \(state) on characteristic \(characteristic)") if characteristic.uuid == weakSelf.testedCharacteristicUUID, state == false { weakSelf.invalidateOldSubscriptions() weakSelf.test() diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTOperationsTestHelper.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTOperationsTestHelper.swift index 28613178..37766de6 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTOperationsTestHelper.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPGATTOperationsTestHelper.swift @@ -42,11 +42,13 @@ class SILIOPGATTOperationsTestHelper { switch status { case let .disconnected(peripheral: _, error: error): debugPrint("Peripheral disconnected with \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "Peripheral disconnected with \(String(describing: error?.localizedDescription))") weakTestCase.publishTestResult(passed: false, description: "Peripheral was disconnected with \(String(describing: error?.localizedDescription)).") case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakTestCase.publishTestResult(passed: false, description: "Bluetooth disabled.") } @@ -84,6 +86,7 @@ class SILIOPGATTOperationsTestHelper { case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == characteristicUUID { debugPrint("DATA \(String(describing: data?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: data?.hexa()))") if data?.hexa() == exceptedValue { weakTestCase.publishTestResult(passed: true) } else { @@ -136,6 +139,7 @@ class SILIOPGATTOperationsTestHelper { case let .successWrite(characteristic): if characteristic.uuid == characteristicUUID { debugPrint("DATA \(String(describing: characteristic.value?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: characteristic.value?.hexa()))") weakTestCase.publishTestResult(passed: true) return } @@ -185,6 +189,7 @@ class SILIOPGATTOperationsTestHelper { case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == characteristicUUID { debugPrint("DATA \(String(describing: data?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: data?.hexa()))") if data?.hexa() == exceptedValue { weakTestCase.publishTestResult(passed: true) } else { @@ -232,6 +237,7 @@ class SILIOPGATTOperationsTestHelper { case let .successWrite(characteristic: characteristic): if characteristic.uuid == characteristicUUID { debugPrint("DATA \(String(describing: characteristic.value?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: characteristic.value?.hexa()))") peripheralDelegate.readCharacteristic(characteristic: characteristic) return } @@ -241,6 +247,7 @@ class SILIOPGATTOperationsTestHelper { case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == characteristicUUID { debugPrint("DATA \(String(describing: data?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: data?.hexa()))") if data?.hexa() == exceptedValue { weakTestCase.publishTestResult(passed: true) } else { diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPLengthVariableTestHelper.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPLengthVariableTestHelper.swift index de349a4f..4c7b77ca 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPLengthVariableTestHelper.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPLengthVariableTestHelper.swift @@ -102,6 +102,7 @@ class SILIOPLengthVariableTestHelper { case let .successWrite(characteristic: characteristic): if characteristic.uuid == weakSelf.testedCharacteristicUUID { debugPrint("DATA \(String(describing: characteristic.value?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: characteristic.value?.hexa()))") weakSelf.peripheralDelegate.readCharacteristic(characteristic: characteristic) return } @@ -111,6 +112,7 @@ class SILIOPLengthVariableTestHelper { case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == weakSelf.testedCharacteristicUUID { debugPrint("DATA \(String(describing: data?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: data?.hexa()))") if weakSelf.isFirstSubtest, data?.hexa() == weakSelf.exceptedValue_Subtest1 { weakSelf.isFirstSubtest = false if let dataToWrite = weakSelf.expectedValue_Subtest2.data(withCount: 4) { diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPUserLenCharacteristicTestHelper.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPUserLenCharacteristicTestHelper.swift index a8d7d222..d77e066c 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPUserLenCharacteristicTestHelper.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_4/TestHelpers/SILIOPUserLenCharacteristicTestHelper.swift @@ -93,6 +93,7 @@ class SILIOPUserLenCharacteristicTestHelper { case let .successWrite(characteristic: characteristic): if characteristic.uuid == weakSelf.testedCharacteristicUUID { debugPrint("DATA \(String(describing: characteristic.value?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: characteristic.value?.hexa()))") weakSelf.peripheralDelegate.readCharacteristic(characteristic: characteristic) return } @@ -102,6 +103,7 @@ class SILIOPUserLenCharacteristicTestHelper { case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == weakSelf.testedCharacteristicUUID { debugPrint("DATA \(String(describing: data?.hexa()))") + IOPLog().iopLogSwiftFunction(message: "DATA \(String(describing: data?.hexa()))") if data?.hexa() == weakSelf.exceptedValue { weakSelf.testResult.value = TestResult(passed: true, description: "") } else { diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_5/TestCases/SILOTAAckTestCase.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_5/TestCases/SILOTAAckTestCase.swift index 1aa330aa..88ce317a 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_5/TestCases/SILOTAAckTestCase.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_5/TestCases/SILOTAAckTestCase.swift @@ -47,21 +47,25 @@ class SILOTAAckTestCase: SILTestCase { func performTestCase() { guard iopCentralManager.bluetoothState else { self.publishTestResult(passed: false, description: "Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") return } guard let _ = firmwareInfo else { self.testResult.value = SILTestResult(testID: self.testID, testName: self.testName, testStatus: .unknown(reason: "Firmware Info is nil.")) + IOPLog().iopLogSwiftFunction(message: "Firmware Info is nil.") return } guard firmwareInfo!.firmware != .unknown else { self.testResult.value = SILTestResult(testID: self.testID, testName: self.testName, testStatus: .unknown(reason: "Board not supported.")) + IOPLog().iopLogSwiftFunction(message: "Board not supported.") return } guard let _ = peripheral else { self.publishTestResult(passed: false, description: "Peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Peripheral is nil.") return } @@ -82,12 +86,14 @@ class SILOTAAckTestCase: SILTestCase { case let .disconnected(peripheral: peripheral, error: error): if peripheral === weakSelf.peripheral { debugPrint("DISCONNECTED WITH \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "DISCONNECTED WITH \(String(describing: error?.localizedDescription))") weakSelf.scanUsingBrowserBluetoothManager() } case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakSelf.otaUpdateManager = nil weakSelf.publishTestResult(passed: false, description: "Bluetooth disabled.") } @@ -96,6 +102,7 @@ class SILOTAAckTestCase: SILTestCase { break default: + IOPLog().iopLogSwiftFunction(message: "Unknown failure reason from IOP Central Manager.") weakSelf.publishTestResult(passed: false, description: "Unknown failure reason from IOP Central Manager.") } }) @@ -116,6 +123,7 @@ class SILOTAAckTestCase: SILTestCase { @objc private func didReceiveScanForPeripheralChange() { debugPrint("DID RECEIVE") + IOPLog().iopLogSwiftFunction(message: "DID RECEIVE") weak var weakSelf = self let discoveredPeripheral = browserCentralManager.discoveredPeripherals().first(where: { peripheral in guard let weakSelf = weakSelf else { return false } @@ -146,12 +154,15 @@ class SILOTAAckTestCase: SILTestCase { case .success: weakSelf.otaUpdateManager = nil weakSelf.invalidateObservableTokens() - - weakSelf.reconnectToDevice() - + UserDefaults.standard.setValue("IOP_Test_2", forKey: "deviceNameAfterOtaUpdate") + // weakSelf.reconnectToDevice(passed: true) + weakSelf.publishTestResult(passed: true) case let .failure(reason: reason): weakSelf.otaUpdateManager = nil - weakSelf.publishTestResult(passed: false, description: reason) + + UserDefaults.standard.setValue("IOP_Test_1", forKey: "deviceNameAfterOtaUpdate") + weakSelf.browserCentralManager.disconnect(from: self.peripheral ) + weakSelf.reconnectToDevice(passed: false,description: reason) case .unknown: break @@ -183,6 +194,7 @@ class SILOTAAckTestCase: SILTestCase { case .unknown: self.invalidateObservableTokens() self.testResult.value = SILTestResult(testID: self.testID, testName: self.testName, testStatus: .unknown(reason: "Unsupported board.")) + IOPLog().iopLogSwiftFunction(message: "Unsupported board.") } self.otaUpdateManager.startTest(for: boardID, firmwareVersion: firmwareInfo!.originalVersion) @@ -191,6 +203,7 @@ class SILOTAAckTestCase: SILTestCase { @objc private func scanIntervalTimerFired() { stopScanning() self.publishTestResult(passed: false, description: "Peripheral didn't found.") + IOPLog().iopLogSwiftFunction(message: "Peripheral didn't found.") } func stopScanning() { @@ -201,7 +214,7 @@ class SILOTAAckTestCase: SILTestCase { } } - private func reconnectToDevice() { + private func reconnectToDevice(passed: Bool, description: String? = nil) { weak var weakSelf = self let reconnectManager = SILIOPTestReconnectManager(with: peripheral, iopCentralManager: iopCentralManager) let reconnectManagerSubscription = reconnectManager.reconnectStatus.observe { reconnectStatus in @@ -212,8 +225,12 @@ class SILOTAAckTestCase: SILTestCase { weakSelf.peripheral = discoveredPeripheral?.peripheral weakSelf.firmwareVersionAfterOtaAckUpdate = SILIOPFirmwareVersion(version: stackVersion) weakSelf.invalidateObservableTokens() - weakSelf.publishTestResult(passed: true) + if passed{ + weakSelf.publishTestResult(passed: true) + }else{ + weakSelf.publishTestResult(passed: passed, description: description) + } case let .failure(reason: reason): weakSelf.publishTestResult(passed: false, description: reason) diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_6/TestCases/SILOTANonAckTestCase.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_6/TestCases/SILOTANonAckTestCase.swift index 710ebe36..14352b11 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_6/TestCases/SILOTANonAckTestCase.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_6/TestCases/SILOTANonAckTestCase.swift @@ -28,7 +28,10 @@ class SILOTANonAckTestCase: SILTestCase { private var deviceNameAfterOtaUpdate: String { get { - return firmwareInfo!.originalVersion.isLesserThan3_3_0() ? "IOP Test" : "IOP_Test_1" + + let deviceNameAfterOtaUpdate = UserDefaults.standard.value(forKey: "deviceNameAfterOtaUpdate") + + return firmwareInfo!.originalVersion.isLesserThan3_3_0() ? "IOP Test" : deviceNameAfterOtaUpdate as! String } } @@ -43,19 +46,26 @@ class SILOTANonAckTestCase: SILTestCase { func performTestCase() { guard let _ = firmwareInfo else { self.testResult.value = SILTestResult(testID: self.testID, testName: self.testName, testStatus: .unknown(reason: "Firmware Info is nil.")) + IOPLog().iopLogSwiftFunction(message: "Firmware Info is nil.") return } guard firmwareInfo!.firmware != .unknown else { self.testResult.value = SILTestResult(testID: self.testID, testName: self.testName, testStatus: .unknown(reason: "Board not supported.")) + IOPLog().iopLogSwiftFunction(message: "Board not supported.") return } guard let _ = peripheral else { self.publishTestResult(passed: false, description: "Peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Peripheral is nil.") return } + IOPLog().iopLogSwiftFunction(message: "\(firmwareInfo?.name ?? "")") + IOPLog().iopLogSwiftFunction(message: "\(firmwareInfo?.nameTag ?? "")") + //IOPLog().iopLogSwiftFunction(message: "\(firmwareInfo!.firmware)") + IOPLog().iopLogSwiftFunction(message: "\(String(describing: peripheral))") publishStartTestEvent() self.otaUpdateManager = SILIopTestOTAUpdateManger(with: self.peripheral, @@ -67,14 +77,21 @@ class SILOTANonAckTestCase: SILTestCase { guard let weakSelf = weakSelf else { return } switch status { case .success: + IOPLog().iopLogSwiftFunction(message: "Success OTA Non Ack TestCase\(status)") weakSelf.otaUpdateManager = nil weakSelf.invalidateObservableTokens() - weakSelf.reconnectToDevice() + UserDefaults.standard.setValue("IOP_Test_1", forKey: "deviceNameAfterOtaUpdate") + weakSelf.reconnectToDevice(passed: true) + + case let .failure(reason: reason): + IOPLog().iopLogSwiftFunction(message: "Failure OTA Non Ack TestCase\(reason)") weakSelf.otaUpdateManager = nil weakSelf.invalidateObservableTokens() - weakSelf.publishTestResult(passed: false, description: reason) + + weakSelf.browserCentralManager.disconnectConnectedPeripheral() + weakSelf.reconnectToDevice(passed: false,description: reason) case .unknown: break @@ -111,7 +128,7 @@ class SILOTANonAckTestCase: SILTestCase { self.otaUpdateManager.startTest(for: boardID, firmwareVersion: firmwareInfo!.originalVersion) } - private func reconnectToDevice() { + private func reconnectToDevice(passed: Bool, description: String? = nil) { weak var weakSelf = self let reconnectManager = SILIOPTestReconnectManager(with: peripheral, iopCentralManager: iopCentralManager) let reconnectManagerSubscription = reconnectManager.reconnectStatus.observe { reconnectStatus in @@ -122,8 +139,18 @@ class SILOTANonAckTestCase: SILTestCase { weakSelf.peripheral = discoveredPeripheral?.peripheral weakSelf.firmwareVersionAfterOtaAckUpdate = SILIOPFirmwareVersion(version: stackVersion) weakSelf.invalidateObservableTokens() - weakSelf.publishTestResult(passed: true) + IOPLog().iopLogSwiftFunction(message: "\(reconnectStatus)") + IOPLog().iopLogSwiftFunction(message: "\(String(describing: discoveredPeripheral))") + IOPLog().iopLogSwiftFunction(message: "\(String(describing: discoveredPeripheral?.peripheral))") + IOPLog().iopLogSwiftFunction(message: "\(SILIOPFirmwareVersion(version: stackVersion))") + + + if passed{ + weakSelf.publishTestResult(passed: true) + }else{ + weakSelf.publishTestResult(passed: passed, description: description) + } case let .failure(reason: reason): weakSelf.publishTestResult(passed: false, description: reason) @@ -134,6 +161,7 @@ class SILOTANonAckTestCase: SILTestCase { self.disposeBag.add(token: reconnectManagerSubscription) observableTokens.append(reconnectManagerSubscription) + reconnectManager.reconnectToDevice(withName: deviceNameAfterOtaUpdate) } diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_7/TestCases/SILThroughputTestCase.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_7/TestCases/SILThroughputTestCase.swift index 8d77cc4d..c7f7d306 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_7/TestCases/SILThroughputTestCase.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_7/TestCases/SILThroughputTestCase.swift @@ -56,16 +56,19 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { func performTestCase() { guard iopCentralManager.bluetoothState else { self.publishTestResult(passed: false, description: "Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "FBluetooth disabled!") return } guard let _ = discoveredPeripheral else { self.publishTestResult(passed: false, description: "Discovered peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Discovered peripheral is nil.") return } guard let _ = peripheral else { self.publishTestResult(passed: false, description: "Peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Peripheral is nil.") return } @@ -80,11 +83,15 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { switch status { case let .disconnected(peripheral: _, error: error): debugPrint("Peripheral disconnected with \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "Peripheral disconnected with \(String(describing: error?.localizedDescription))") + weakSelf.publishTestResult(passed: false, description: "Peripheral was disconnected with \(String(describing: error?.localizedDescription)).") case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") + weakSelf.publishTestResult(passed: false, description: "Bluetooth disabled.") } @@ -93,6 +100,8 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { default: weakSelf.publishTestResult(passed: false, description: "Unknown failure from central manager.") + IOPLog().iopLogSwiftFunction(message: "Unknown failure from central manager.") + } }) disposeBag.add(token: centralManagerSubscription) @@ -109,6 +118,7 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { case let .successForServices(services): guard let iopTestPhase3Service = services.first(where: { service in service.uuid == weakSelf.iopTestPhase3Service }) else { weakSelf.publishTestResult(passed: false, description: "Service Test Phase 3 didn't found.") + IOPLog().iopLogSwiftFunction(message: "Service Test Phase 3 didn't found.") return } @@ -119,6 +129,7 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { characteristic.uuid == weakSelf.iopTestPhase3ThroughputGATT }) else { weakSelf.publishTestResult(passed: false, description: "Throughput characteristic didn't found.") + IOPLog().iopLogSwiftFunction(message: "Throughput characteristic didn't found.") return } @@ -132,6 +143,7 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { } weakSelf.publishTestResult(passed: false, description: "Failure when writing to a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when writing to a characteristic.") case let .successGetValue(value: data, characteristic: characteristic): if characteristic.uuid == weakSelf.iopTestPhase3ThroughputGATT, let data = data { @@ -145,6 +157,7 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { } weakSelf.publishTestResult(passed: false, description: "Failure when notifying a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when notifying a characteristic.") case let .updateNotificationState(characteristic: characteristic, state: state): if characteristic.uuid == weakSelf.iopTestPhase3ThroughputGATT { @@ -154,6 +167,7 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { } else { let throughputSpped = Double(weakSelf.countCharacteristicThroughput / 5) debugPrint("Throughput speed: \(throughputSpped) kbps") + IOPLog().iopLogSwiftFunction(message: "Throughput speed: \(throughputSpped) kbps") let acceptableThroughput = weakSelf.calculateThroughput() if acceptableThroughput == 0 { @@ -172,6 +186,7 @@ class SILThroughputTestCase: SILTestCase, SILTestCaseTimeout { default: weakSelf.publishTestResult(passed: false, description: "Unknown failure from peripheral delegate.") + IOPLog().iopLogSwiftFunction(message: "Unknown failure from peripheral delegate.") } }) disposeBag.add(token: peripheralDelegateSubscription) diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPSecurityTestHelper.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPSecurityTestHelper.swift index 0a924fd2..05ebe3ad 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPSecurityTestHelper.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPSecurityTestHelper.swift @@ -46,6 +46,7 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { } func injectParameters(parameters: Dictionary) { + print(parameters) self.iopCentralManager = parameters["iopCentralManager"] as? SILIOPTesterCentralManager self.discoveredPeripheral = parameters["discoveredPeripheral"] as? SILDiscoveredPeripheral self.peripheral = parameters["peripheral"] as? CBPeripheral @@ -55,21 +56,25 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { func performTestCase() { guard iopCentralManager.bluetoothState else { self.testResult.value = SecurityTestResult(passed: false, description: "Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") return } guard let _ = discoveredPeripheral else { self.testResult.value = SecurityTestResult(passed: false, description: "Discovered peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Discovered peripheral is nil.") return } guard let _ = peripheral else { self.testResult.value = SecurityTestResult(passed: false, description: "Peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Peripheral is nil.") return } guard let _ = peripheralDelegate else { self.testResult.value = SecurityTestResult(passed: false, description: "Peripheral delegate is nil.") + IOPLog().iopLogSwiftFunction(message: "Peripheral delegate is nil.") return } @@ -78,6 +83,8 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { guard let iopTestPhase3Service = self.peripheral.services?.first(where: { service in service.uuid == iopTestPhase3Service }) else { self.testResult.value = SecurityTestResult(passed: false, description: "Service Test Phase 3 didn't found.") + IOPLog().iopLogSwiftFunction(message: "Service Test Phase 3 didn't found.") + return } @@ -91,10 +98,13 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { switch status { case let .disconnected(peripheral: _, error: error): debugPrint("PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Not allowed disconnection.") case let .bluetoothEnabled(enabled: enabled): if !enabled { + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") debugPrint("Bluetooth disabled!") weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Bluetooth disabled.") } @@ -120,6 +130,8 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID }) else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested characteristic didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested characteristic didn't found.") + return } @@ -128,6 +140,8 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { if weakSelf.initialValue == weakSelf.NotifyTest { guard pairingCharacteristic.properties.contains(.notify) else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Characteristic doesn't have notify property.") + IOPLog().iopLogSwiftFunction(message: "Characteristic doesn't have notify property.") + return } weakSelf.peripheralDelegate.notifyCharacteristic(characteristic: pairingCharacteristic, enabled: true) @@ -152,28 +166,36 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Failure when writing to a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when writing to a characteristic.") + //ADDED NEW... case let .updateNotificationState(characteristic, _): if(characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID){ debugPrint("DID WRITE VALUE TO CCCD of characteristic\(characteristic)") + IOPLog().iopLogSwiftFunction(message: "DID WRITE VALUE TO CCCD of characteristic\(characteristic)") return } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Failure when writing to CCCD of characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when writing to CCCD of characteristic.") //END case let .successWrite(characteristic: characteristic): if characteristic.uuid == weakSelf.iopTestPhase3Control { debugPrint("DID WRITE VALUE TO \(characteristic)") + IOPLog().iopLogSwiftFunction(message: "DID WRITE VALUE TO \(characteristic)") + return } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Failure when writing to a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when writing to a characteristic.") case .unknown: break default: weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Uknown failure from peripheral delegate.") + IOPLog().iopLogSwiftFunction(message: "Uknown failure from peripheral delegate.") } }) disposeBag.add(token: peripheralDelegateSubscription) @@ -189,6 +211,7 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { switch status { case let .connected(peripheral: peripheral): debugPrint("PERIPHERAL CONNECTED") + IOPLog().iopLogSwiftFunction(message: "PERIPHERAL CONNECTED") weakSelf.peripheral = peripheral weakSelf.connectionTimeout?.invalidate() weakSelf.peripheralDelegate.updatePeripheral(peripheral: peripheral) @@ -196,6 +219,8 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { case let .disconnected(peripheral: _, error: error): debugPrint("PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + weakSelf.pairingTimer?.invalidate() if weakSelf.retryCount > 0 { weakSelf.retryCount = weakSelf.retryCount - 1 @@ -209,10 +234,12 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { weakSelf.pairingTimer?.invalidate() weakSelf.connectionTimeout?.invalidate() weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Fail to connect to peripheral with error \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "Fail to connect to peripheral with error \(String(describing: error?.localizedDescription))") case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") weakSelf.connectionTimeout?.invalidate() weakSelf.pairingTimer?.invalidate() weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Bluetooth disabled.") @@ -231,6 +258,8 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { connectionTimeout = nil iopCentralManager.disconnect(peripheral: peripheral) testResult.value = SecurityTestResult(passed: false, description: "Peripheral wasn't reconnected in 10 seconds.") + IOPLog().iopLogSwiftFunction(message: "Peripheral wasn't reconnected in 10 seconds.") + } private func reconnectedPeripheralDelegateSubscription() { @@ -247,12 +276,16 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Service Test Phase 3 didn't found.") + IOPLog().iopLogSwiftFunction(message: "Service Test Phase 3 didn't found.") + case let .successForCharacteristics(characteristics): guard let pairingCharacteristic = characteristics.first(where: { characteristic in characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID }) else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested characteristic didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested characteristic didn't found.") + return } @@ -275,6 +308,8 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { descriptor.uuid.uuidString == CBUUIDClientCharacteristicConfigurationString }) else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested descriptor didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested descriptor didn't found.") + return } weakSelf.peripheralDelegate.readDescriptor(descriptor: pairingDescriptor) @@ -282,11 +317,15 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { case let .successGetValueDescriptor(value: data, descriptor: descriptor): guard descriptor.uuid.uuidString == CBUUIDClientCharacteristicConfigurationString else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested descriptor didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested descriptor didn't found.") + return } let valueDescriptor = (data as? NSNumber)?.stringValue if valueDescriptor != weakSelf.exceptedValue { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Wrong value in Client Characteristic Configuration Descriptor.") + IOPLog().iopLogSwiftFunction(message: "Wrong value in Client Characteristic Configuration Descriptor.") + return } weakSelf.peripheralDelegate.notifyCharacteristic(characteristic: descriptor.characteristic!, enabled: false) @@ -294,6 +333,8 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { case let .successGetValue(value: data, characteristic: characteristic): guard characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested characteristic didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested characteristic didn't found.") + return } @@ -303,22 +344,29 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { weakSelf.testResult.value = SecurityTestResult(passed: true, description: "") } else if weakSelf.retryCount == 0 { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Wrong value in a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Wrong value in a characteristic.") } //ADDED NEW case let .updateNotificationState(characteristic, _): if(characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID){ debugPrint("DID WRITE VALUE TO CCCD of characteristic\(characteristic)") + IOPLog().iopLogSwiftFunction(message: "DID WRITE VALUE TO CCCD of characteristic\(characteristic)") + weakSelf.testResult.value = SecurityTestResult(passed: true, description: "") return } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Failure when writing to CCCD of characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when writing to CCCD of characteristic.") + //END case .failure(error: _): weakSelf.pairingTimer?.invalidate() if weakSelf.retryCount == 0 { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Exceeded an allowed number of attempts.") + IOPLog().iopLogSwiftFunction(message: "Exceeded an allowed number of attempts.") + } case .unknown: @@ -327,6 +375,7 @@ class SILIOPSecurityTestHelper: SILTestCaseWithRetries { default: weakSelf.pairingTimer?.invalidate() weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Unknown failure from peripheral delegate.") + IOPLog().iopLogSwiftFunction(message: "Unknown failure from peripheral delegate.") } }) disposeBag.add(token: peripheralDelegateSubscription) diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPTester_Test8.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPTester_Test8.swift index bf6a3f2f..6f76029f 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPTester_Test8.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_8/SILIOPTester_Test8.swift @@ -24,7 +24,7 @@ class SILIOPTester_Test8: SILTestScenario { appendTestCase(testCase: SILSecurity_7_2TestCase()) appendTestCase(testCase: SILSecurity_7_3TestCase()) appendTestCase(testCase: SILSecurity_7_4TestCase()) - appendTestCase(testCase: SILSecurity_7_5TestCase()) //Added + appendTestCase(testCase: SILSecurity_7_5TestCase()) testResults.value = privTestResults } diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_9/SILIOPLEPrivacyHealper.swift b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_9/SILIOPLEPrivacyHealper.swift index 38c295e4..26a18d08 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_9/SILIOPLEPrivacyHealper.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/TestScenario/Test_9/SILIOPLEPrivacyHealper.swift @@ -54,21 +54,25 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { func performTestCase() { guard iopCentralManager.bluetoothState else { self.testResult.value = SecurityTestResult(passed: false, description: "Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") return } guard let _ = discoveredPeripheral else { self.testResult.value = SecurityTestResult(passed: false, description: "Discovered peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Discovered peripheral is nil.") return } guard let _ = peripheral else { self.testResult.value = SecurityTestResult(passed: false, description: "Peripheral is nil.") + IOPLog().iopLogSwiftFunction(message: "Peripheral is nil.") return } guard let _ = peripheralDelegate else { self.testResult.value = SecurityTestResult(passed: false, description: "Peripheral delegate is nil.") + IOPLog().iopLogSwiftFunction(message: "Peripheral delegate is nil.") return } @@ -77,6 +81,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { guard let iopTestPhase3Service = self.peripheral.services?.first(where: { service in service.uuid == iopTestPhase3Service }) else { self.testResult.value = SecurityTestResult(passed: false, description: "Service Test Phase 3 didn't found.") + IOPLog().iopLogSwiftFunction(message: "Service Test Phase 3 didn't found.") + return } @@ -90,11 +96,17 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { switch status { case let .disconnected(peripheral: _, error: error): debugPrint("PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Not allowed disconnection.") + IOPLog().iopLogSwiftFunction(message: "Not allowed disconnection.") + case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") + weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Bluetooth disabled.") } @@ -119,6 +131,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID }) else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested characteristic didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested characteristic didn't found.") + return } @@ -140,20 +154,28 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Failure when writing to a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when writing to a characteristic.") + case let .successWrite(characteristic: characteristic): if characteristic.uuid == weakSelf.iopTestPhase3Control { debugPrint("DID WRITE VALUE TO \(characteristic)") + IOPLog().iopLogSwiftFunction(message: "DID WRITE VALUE TO \(characteristic)") + return } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Failure when writing to a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Failure when writing to a characteristic.") + case .unknown: break default: weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Uknown failure from peripheral delegate.") + IOPLog().iopLogSwiftFunction(message: "Uknown failure from peripheral delegate.") + } }) disposeBag.add(token: peripheralDelegateSubscription) @@ -168,6 +190,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { self.iopCentralManager.connect(to: self.discoveredPeripheral) } else { self.testResult.value = SecurityTestResult(passed: false, description: "Exceeded an allowed number of attempts.") + IOPLog().iopLogSwiftFunction(message: "Exceeded an allowed number of attempts.") + } } @@ -178,6 +202,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { switch status { case let .connected(peripheral: peripheral): debugPrint("PERIPHERAL CONNECTED") + IOPLog().iopLogSwiftFunction(message: "PERIPHERAL CONNECTED") + weakSelf.peripheral = peripheral weakSelf.connectionTimeout?.invalidate() weakSelf.peripheralDelegate.updatePeripheral(peripheral: peripheral) @@ -185,6 +211,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { weakSelf.reconnectedPeripheralDelegateSubscription() case let .disconnected(peripheral: _, error: error): debugPrint("PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "PERIPHERAL DISCONNECTED WITH ERROR \(String(describing: error?.localizedDescription))") + weakSelf.pairingTimer?.invalidate() if weakSelf.retryCount > 0 { weakSelf.retryCount = weakSelf.retryCount - 1 @@ -192,16 +220,22 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { weakSelf.iopCentralManager.connect(to: weakSelf.discoveredPeripheral) } else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Exceeded an allowed number of attempts.") + IOPLog().iopLogSwiftFunction(message: "Exceeded an allowed number of attempts.") + } case let .failToConnect(peripheral: _, error: error): weakSelf.pairingTimer?.invalidate() weakSelf.connectionTimeout?.invalidate() weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Fail to connect to peripheral with error \(String(describing: error?.localizedDescription))") + IOPLog().iopLogSwiftFunction(message: "Fail to connect to peripheral with error \(String(describing: error?.localizedDescription))") + case let .bluetoothEnabled(enabled: enabled): if !enabled { debugPrint("Bluetooth disabled!") + IOPLog().iopLogSwiftFunction(message: "Bluetooth disabled!") + weakSelf.connectionTimeout?.invalidate() weakSelf.pairingTimer?.invalidate() weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Bluetooth disabled.") @@ -220,6 +254,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { connectionTimeout = nil iopCentralManager.disconnect(peripheral: peripheral) testResult.value = SecurityTestResult(passed: false, description: "Peripheral wasn't reconnected in 10 seconds.") + IOPLog().iopLogSwiftFunction(message: "Peripheral wasn't reconnected in 10 seconds") + } private func reconnectedPeripheralDelegateSubscription() { @@ -236,12 +272,16 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { } weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Service Test Phase 3 didn't found.") + IOPLog().iopLogSwiftFunction(message: "Service Test Phase 3 didn't found.") + case let .successForCharacteristics(characteristics): guard let pairingCharacteristic = characteristics.first(where: { characteristic in characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID }) else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested characteristic didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested characteristic didn't found.") + return } @@ -252,6 +292,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { case let .successGetValue(value: data, characteristic: characteristic): guard characteristic.uuid == weakSelf.iopTestPhase3TestedCharacteristicUUID else { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Tested characteristic didn't found.") + IOPLog().iopLogSwiftFunction(message: "Tested characteristic didn't found.") + return } @@ -261,6 +303,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { weakSelf.testResult.value = SecurityTestResult(passed: true, description: "") } else if weakSelf.retryCount == 0 { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Wrong value in a characteristic.") + IOPLog().iopLogSwiftFunction(message: "Wrong value in a characteristic.") + } case .failure(error: _): @@ -268,6 +312,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { if weakSelf.retryCount == 0 { weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Exceeded an allowed number of attempts.") + IOPLog().iopLogSwiftFunction(message: "Exceeded an allowed number of attempts.") + } case .unknown: @@ -276,6 +322,8 @@ class SILIOPLEPrivacyHealper: SILTestCaseWithRetries { default: weakSelf.pairingTimer?.invalidate() weakSelf.testResult.value = SecurityTestResult(passed: false, description: "Unknown failure from peripheral delegate.") + IOPLog().iopLogSwiftFunction(message: "Unknown failure from peripheral delegate.") + } }) disposeBag.add(token: peripheralDelegateSubscription) diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPDeviceResetInfoPopupViewController.swift b/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPDeviceResetInfoPopupViewController.swift new file mode 100644 index 00000000..456cdaf0 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPDeviceResetInfoPopupViewController.swift @@ -0,0 +1,22 @@ +// +// SILIOPDeviceResetInfoPopupViewController.swift +// BlueGecko +// +// Created by SovanDas Maity on 11/07/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit + +class SILIOPDeviceResetInfoPopupViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + @IBAction func okBtn(_ sender: UIButton) { + self.dismiss(animated: false, completion: nil) + } +} diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPDeviceResetInfoPopupViewController.xib b/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPDeviceResetInfoPopupViewController.xib new file mode 100644 index 00000000..a5d0e597 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPDeviceResetInfoPopupViewController.xib @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPTesterViewController.swift b/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPTesterViewController.swift index 5322241c..5a0760df 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPTesterViewController.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/UI/SILIOPTesterViewController.swift @@ -11,7 +11,7 @@ import UIKit @objc @objcMembers -class SILIOPTesterViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { +class SILIOPTesterViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, SILIOPTesterViewModelDelegate { @IBOutlet weak var allSpace: UIStackView! @IBOutlet weak var tableView: UITableView! @@ -153,15 +153,66 @@ class SILIOPTesterViewController: UIViewController, UITableViewDataSource, UITab } @objc func shareTestResult() { - guard let viewModel = viewModel, currentTestState != .initiated else { return } - let filesToShare = [viewModel.getReportFile() as Any] as [Any] - let iopTestLogSubject = "IOP Test Log" - let activityViewController = UIActivityViewController(activityItems: filesToShare, applicationActivities: nil) - activityViewController.setValue(iopTestLogSubject, forKey: "Subject") - activityViewController.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem + let alert = UIAlertController(title: "Select log file.", message: "", preferredStyle: .alert) + let debugLog = UIAlertAction(title: "Application Debug Log", style: .default) { (action) in + self.shareLogFile(logType: "ConsoleLog") + } + + let resultLog = UIAlertAction(title: "Test Result Log", style: .default) { (action) in + self.shareLogFile(logType: "UILog") + } - self.present(activityViewController, animated: true, completion: nil) + + + let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: nil) + alert.addAction(resultLog) + alert.addAction(debugLog) + alert.addAction(cancelAction) + //alert.popoverPresentationController?.sourceView = self.btnShare + self.present(alert, animated: true, completion: nil) + + + //Console: +// let fileSh = viewModel.getConsolLogsFile() +// +//// if let file = viewModel.getMeshLogsFile() { +//// self.shareTestResultTemp(fileURL: file, fileName: "Application/Mesh Logs") +//// } +// +// +// let iopTestLogSubject = "IOP Test Log" +// +// let activityViewController = UIActivityViewController(activityItems: [fileSh as Any], applicationActivities: nil) +// activityViewController.setValue(iopTestLogSubject, forKey: "Subject") +// activityViewController.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem +// +// self.present(activityViewController, animated: true, completion: nil) + } + + func shareLogFile(logType: String) { + guard let viewModel = viewModel, currentTestState != .initiated else { return } + if logType == "UILog" { + viewModel.prepareTestReport() + } + + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + var filesToShare:[Any] = [] + if logType == "UILog" { + filesToShare = [viewModel.getReportFile() as Any] + }else if logType == "ConsoleLog" { + filesToShare = [viewModel.getConsolLogsFile() as Any] + } + + let iopTestLogSubject = "IOP Test Log" + + let activityViewController = UIActivityViewController(activityItems: filesToShare, applicationActivities: nil) + activityViewController.setValue(iopTestLogSubject, forKey: "Subject") + activityViewController.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem + + self.present(activityViewController, animated: true, completion: nil) + } + } private func showBluetoothDisabledAlert() { @@ -176,6 +227,8 @@ class SILIOPTesterViewController: UIViewController, UITableViewDataSource, UITab func setupViewModel() { guard let deviceName = self.deviceNameToSearch else { return } self.viewModel = SILIOPTesterViewModel(deviceNameToSearch: deviceName) + + self.viewModel?.SILIOPTesterViewModelDelegate = self } func showDocumentPickerView() { @@ -218,6 +271,7 @@ class SILIOPTesterViewController: UIViewController, UITableViewDataSource, UITab extension SILIOPTesterViewController: UIDocumentPickerDelegate { func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { debugPrint("DID PICK") + IOPLog().iopLogSwiftFunction(message: "DID PICK") self.sendChosenUrl(urls: urls) } @@ -231,7 +285,20 @@ extension SILIOPTesterViewController: UIDocumentPickerDelegate { func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { debugPrint("DID CANCEL") + IOPLog().iopLogSwiftFunction(message: "DID CANCEL PICKER") NotificationCenter.default.post(Notification(name: .SILIOPFileUrlChosen, object: nil, userInfo: nil)) controller.dismiss(animated: true, completion: nil) } } +//MARK: SILIOPTesterViewModelDelegate +extension SILIOPTesterViewController { + func notifyAfterAllTest() { + print("END") + DispatchQueue.main.async { + let SILIOPDeviceResetInfoPopupViewControllerObj = SILIOPDeviceResetInfoPopupViewController(nibName: "SILIOPDeviceResetInfoPopupViewController", bundle: nil) + SILIOPDeviceResetInfoPopupViewControllerObj.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext + self.present(SILIOPDeviceResetInfoPopupViewControllerObj, animated: false) + } + + } +} diff --git a/SiliconLabsApp/ViewControllers/IOP Test App/ViewModel/SILIOPTesterViewModel.swift b/SiliconLabsApp/ViewControllers/IOP Test App/ViewModel/SILIOPTesterViewModel.swift index 28d94593..e80be582 100644 --- a/SiliconLabsApp/ViewControllers/IOP Test App/ViewModel/SILIOPTesterViewModel.swift +++ b/SiliconLabsApp/ViewControllers/IOP Test App/ViewModel/SILIOPTesterViewModel.swift @@ -9,6 +9,11 @@ import Foundation import CoreBluetooth import UIKit +import CocoaLumberjack + +protocol SILIOPTesterViewModelDelegate { + func notifyAfterAllTest() +} class SILIOPTesterViewModel: NSObject, ObservableObject { private var iopCentralManager: SILIOPTesterCentralManager = SILIOPTesterCentralManager() @@ -42,6 +47,7 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { case ended } + var SILIOPTesterViewModelDelegate:SILIOPTesterViewModelDelegate? var testStateStatus: SILObservable = SILObservable(initialValue: .initiated) var bluetoothState: SILObservable = SILObservable(initialValue: true) @@ -100,7 +106,9 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { var testCaseResults = [SILTestResult]() for testScenario in iopTest { let testCaseStatuses: [SILTestStatus] = testScenario.tests.map { _ in return .waiting } + print(testScenario.tests) allTestCases += testScenario.tests.count + print(allTestCases) for testCase in testScenario.tests { testCaseResults.append(SILTestResult(testID: testCase.testID, testName: testCase.testName, testStatus: .waiting)) @@ -135,14 +143,25 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { let failureStatus = SILTestStatus.failed(reason: SILTestFailureReason(description: "Mandatory test \(testID) failed.")) testCaseResults.markTestAfterIndex(indexOfFailedTestID, with: failureStatus) } - + private func prepareLoggerForTesting() { + //ViewModelServices.sharedInstance.bluetoothMeshNetworkManager.dropDatabase() + IOPLogFilePrinter.clearLogDir() + if let fileLogger = DDLog.allLoggers.last as? DDFileLogger { + fileLogger.rollLogFile(withCompletion: { + print("File rolled") + }) + } + } func startTest() { + prepareLoggerForTesting() createNewIOPTest() setInitialUIState() timestamp = Date.init() testStateStatus.value = .running debugPrint("START TEST") + IOPLog().iopLogSwiftFunction(message: "START TEST") + testParameters = ["iopCentralManager": self.iopCentralManager, "browserCentralManager": self.browserCentralManager, "peripheralLocalName": self.deviceNameToSearch] as [String : Any] @@ -154,11 +173,16 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { observableTokens.append(iopTest[i].testResults.observe({ testResults in if testResults.isEmpty { return } guard let weakSelf = weakSelf else { return } + print("SOVAN TEST: \(self.iopTest[i])") + print("SOVAN TEST RESULT: \(testResults)") + print(i) weakSelf.printTestResultInfo(testResults) let newTestCaseStatuses: [SILTestStatus] = testResults.map { testResult in weakSelf.testCaseResults.update(newTestResult: testResult) return testResult.testStatus } + + weakSelf.cellViewModels[i].update(newTestCaseStatuses: newTestCaseStatuses) weakSelf.updateTableViewWithCurrentTestScenarioIndex.value = i weakSelf.inProgressTestCases = weakSelf.testCaseResults.testInProgressCount() @@ -176,11 +200,17 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { case .failed(reason: _), .unknown(reason: _): + if weakSelf.iopTest[i].isMandatory { weakSelf.markRestTestsAsFailed(fromTestAtIndex: i + 1, andfromTestID: testResults.last!.testID) weakSelf.endTesting() } else { weakSelf.runNextTestIfPossible(index: i) + if i == 6 { + //print(i) + weakSelf.markRestTestsAsFailed(fromTestAtIndex: 6 + 1, andfromTestID: testResults.last!.testID) + weakSelf.markRestTestsAsFailed(fromTestAtIndex: 8 + 1, andfromTestID: testResults.last!.testID) + } } default: @@ -196,6 +226,9 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { private func printTestResultInfo(_ testResults: [SILTestResult]) { for testResult in testResults { var testResultText = "TEST RESULT \(testResult.testID) \(testResult.testName) \(testResult.testStatus.rawValue)" + + IOPLog().iopLogSwiftFunction(message: "TEST RESULT \(testResult.testID) \(testResult.testName) \(testResult.testStatus.rawValue)") + print(testResult) switch testResult.testStatus { case let .passed(details: details): if let details = details { @@ -236,8 +269,8 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { updateParametersDictionary(newArtifacts: dict, testIndex: i) iopTest[i].invalidateObservableTokens() - print(iopTest) - print(iopTest.count) + //print(iopTest) + // print(iopTest.count) if i + 1 < iopTest.count { iopTest[i + 1].injectParameters(parameters: testParameters) iopTest[i + 1].performTestScenario() @@ -297,12 +330,18 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { func endTesting() { debugPrint("END TESTING") + + IOPLog().iopLogSwiftFunction(message: "END TEST") + stopTest() prepareTestReport() testStateStatus.value = .ended + SILIOPTesterViewModelDelegate?.notifyAfterAllTest() + } - private func prepareTestReport() { + func prepareTestReport() { + IOPLog().iopLogSwiftFunction(message: "END TEST") let deviceSystemVersion = "\(UIDevice.current.systemName) \(UIDevice.current.systemVersion)" testReport = SILIOPTestReport(timestamp: timestamp ?? Date(), @@ -313,18 +352,27 @@ class SILIOPTesterViewModel: NSObject, ObservableObject { } func getReportFile() -> URL { - let fileWriter = SILIOPFileWriter(firmware: firmwareInfo?.firmware ?? .unknown, - timestamp: timestamp ?? Date(), - deviceModelName: deviceModelName) - - if fileWriter.createEmptyFile(atPath: fileWriter.getFilePath), let testReport = testReport { - let report = testReport.generateReport() - if fileWriter.openFile(filePath: fileWriter.getFilePath) { - _ = fileWriter.append(text: report) - fileWriter.closeFile() + let fileWriter = SILIOPFileWriter(firmware: self.firmwareInfo?.firmware ?? .unknown, + timestamp: self.timestamp ?? Date(), + deviceModelName: self.deviceModelName) + + + if fileWriter.createEmptyFile(atPath: fileWriter.getFilePath), let testReport = self.testReport { + let report = testReport.generateReport() + if fileWriter.openFile(filePath: fileWriter.getFilePath) { + _ = fileWriter.append(text: report) + fileWriter.closeFile() + } } - } + return fileWriter.getFileUrl } + + func getConsolLogsFile() -> URL? { + if let fileLogger = DDLog.allLoggers.last as? DDFileLogger { + return URL(fileURLWithPath: fileLogger.currentLogFileInfo!.filePath) + } + return nil + } } diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/APIService/APIRequest.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/APIService/APIRequest.swift new file mode 100644 index 00000000..ecf636a9 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/APIService/APIRequest.swift @@ -0,0 +1,79 @@ +// +// APIRequest.swift +// IPAddressDemo +// +// Created by SovanDas Maity on 24/06/24. +// + +import Foundation + +enum HttpMethods: String { + case POST = "POST" + case GET = "GET" + } +struct ApiHTTPrequest { + +} + +class APIRequest { + static let sharedInstance = APIRequest() + + func postApiCall(parameterDictionary: String, url : String, completionBlock: @escaping (_ ReponsData: Data?, _ APIClientError:Error?) -> Void) { + + let Url = String(format: "http://192.168.10.10/\(url)") + guard let serviceUrl = URL(string: Url) else { return } + var request = URLRequest(url: serviceUrl) + request.httpMethod = HttpMethods.POST.rawValue + request.setValue("Application/json", forHTTPHeaderField: "Content-Type") + request.timeoutInterval = 10 + let parameters = parameterDictionary + let postData = parameters.data(using: .utf8) + + request.httpBody = postData + let session = URLSession.shared + session.dataTask(with: request) { (data, response, error) in + if let response = response { + print(response) + if let httpResponse = response as? HTTPURLResponse { + if httpResponse.statusCode == 200 { + completionBlock(data, nil) + }else{ + completionBlock(nil, error) + } + }else{ + completionBlock(nil, error) + } + }else{ + completionBlock(nil, error) + } + + }.resume() + } + + func getApiCall(url : String, completionBlock: @escaping (_ ReponsData: Data?, _ APIClientError:Error?) -> Void) { + let Url = String(format: "http://192.168.10.10/\(url)") + guard let serviceUrl = URL(string: Url) else { return } + var request = URLRequest(url: serviceUrl) + request.httpMethod = HttpMethods.GET.rawValue + request.setValue("Application/json", forHTTPHeaderField: "Content-Type") + request.timeoutInterval = 10 + let session = URLSession.shared + session.dataTask(with: request) { (data, response, error) in + if let response = response { + print(response) + if let httpResponse = response as? HTTPURLResponse { + if httpResponse.statusCode == 200 { + completionBlock(data, nil) + }else{ + completionBlock(nil, error) + } + }else{ + completionBlock(nil, error) + } + }else{ + completionBlock(nil, error) + } + + }.resume() + } +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiLEDViewController.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiLEDViewController.swift new file mode 100644 index 00000000..9c91bfdb --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiLEDViewController.swift @@ -0,0 +1,441 @@ +// +// SILWiFiLEDViewController.swift +// BlueGecko +// +// Created by SovanDas Maity on 27/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit +import SVProgressHUD + +class SILWiFiLEDViewController: UIViewController { + @IBOutlet weak var blubImg: UIImageView! + @IBOutlet weak var redColorBtn: UIButton! + @IBOutlet weak var greenColorBtn: UIButton! + @IBOutlet weak var blueColorBtn: UIButton! + @IBOutlet weak var onBtn: UIButton! + @IBOutlet weak var offBtn: UIButton! + + + + var silWiFiLedSensorsViewModelObject:SILWiFiLedSensorsViewModel = SILWiFiLedSensorsViewModel() + var redColor: Bool = false + var greenColor: Bool = false + var blueColor: Bool = false + var redColorVlue: String = "on" + var greenColorVlue: String = "on" + var blueColorVlue: String = "on" + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + //blubImg.image = LedImage.ledOnImage + self.onBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + ledStatus() + } + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + redColorVlue = "on" + greenColorVlue = "on" + blueColorVlue = "on" + SVProgressHUD.show(withStatus: "Connecting") + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [self] in + getLedStatus() + } + } + func ledStatus(){ + //{"status_led": "on/off"} + self.silWiFiLedSensorsViewModelObject.statusLed(requestMethod: HttpMethods.GET.rawValue) { [self] sensorsData, APIClientError in + if APIClientError == nil{ + if let statusValue: String = sensorsData?["status_led"] as? String{ + print(statusValue) + if statusValue == "on" { + postLedStatus() + } + } + } + } + } + func postLedStatus(){ + self.silWiFiLedSensorsViewModelObject.statusLed(requestMethod: HttpMethods.POST.rawValue) { sensorsData, APIClientError in + if APIClientError == nil{ + print(sensorsData) + } + } + } + + func getLedStatus() { + silWiFiLedSensorsViewModelObject.getLedData { sensorsData, APIClientError in + DispatchQueue.main.async { + SVProgressHUD.dismiss() + } + if APIClientError == nil{ + + if let ledDic: Dictionary = sensorsData { + self.stateOfLed(ledDic: ledDic) + } + } + } + } + func stateOfLed(ledDic: Dictionary ){ + self.redColorVlue = "\(ledDic["red"] ?? "")" + self.greenColorVlue = "\(ledDic["green"] ?? "")" + self.blueColorVlue = "\(ledDic["blue"] ?? "")" + if "\(ledDic["red"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOnState.rawValue{ + self.setLedStatus(type: LedType.ledOn.rawValue) + }else if "\(ledDic["red"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOffState.rawValue { + self.setLedStatus(type: LedType.ledOff.rawValue) + }else if "\(ledDic["red"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOffState.rawValue { + self.setLedStatus(type: LedType.redOn.rawValue) + }else if "\(ledDic["red"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOffState.rawValue { + self.setLedStatus(type: LedType.greenOn.rawValue) + }else if "\(ledDic["red"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOnState.rawValue { + self.setLedStatus(type: LedType.blueOn.rawValue) + }else if "\(ledDic["red"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOffState.rawValue { + self.setLedStatus(type: LedType.redGreenOn.rawValue) + }else if "\(ledDic["red"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOnState.rawValue { + self.setLedStatus(type: LedType.redBlueOn.rawValue) + }else if "\(ledDic["red"] ?? "")" == LedStatus.ledOffState.rawValue && "\(ledDic["green"] ?? "")" == LedStatus.ledOnState.rawValue && "\(ledDic["blue"] ?? "")" == LedStatus.ledOnState.rawValue { + self.setLedStatus(type: LedType.greenBuleOn.rawValue) + } + } + + func setLedStatus(type: String){ + var ledImage = UIImage() + var ledColor = UIColor() + + switch type { + case LedType.ledOn.rawValue: + ledImage = LedImage.ledOnImage ?? UIImage() + DispatchQueue.main.async { + //self.redColorCheckImg.image = LedImage.checkBoxActiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_siliconLabsRedColor") + self.redColor = true + //self.greenColorCheckImg.image = LedImage.checkBoxActiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_regularGreenColor") + self.greenColor = true + //self.blueColorCheckImg.image = LedImage.checkBoxActiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_regularBlueColor") + self.blueColor = true + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + } + case LedType.ledOff.rawValue: + ledImage = LedImage.ledOffImage ?? UIImage() + DispatchQueue.main.async { + //self.redColorCheckImg.image = LedImage.checkBoxInactiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.redColor = false + //self.greenColorCheckImg.image = LedImage.checkBoxInactiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.greenColor = false + //self.blueColorCheckImg.image = LedImage.checkBoxInactiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.blueColor = false + + self.onBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.offBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + } + case LedType.redOn.rawValue: + //ledImage = LedImage.redLedOnImage ?? UIImage() + ledImage = LedImage.blubOffTint ?? UIImage() + ledColor = UIColor(red: 255.0, green: 0.0, blue: 0.0, alpha: 1) + DispatchQueue.main.async { + //self.redColorCheckImg.image = LedImage.checkBoxActiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_siliconLabsRedColor") + self.redColor = true + //self.greenColorCheckImg.image = LedImage.checkBoxInactiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.greenColor = false + //self.blueColorCheckImg.image = LedImage.checkBoxInactiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.blueColor = false + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + } + case LedType.greenOn.rawValue: + //ledImage = LedImage.greenLedOnImage ?? UIImage() + ledImage = LedImage.blubOffTint ?? UIImage() + ledColor = UIColor(red: 0.0, green: 255.0, blue: 0.0, alpha: 1) + DispatchQueue.main.async { + //self.greenColorCheckImg.image = LedImage.checkBoxActiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_regularGreenColor") + self.greenColor = true + //self.redColorCheckImg.image = LedImage.checkBoxInactiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.redColor = false + //self.blueColorCheckImg.image = LedImage.checkBoxInactiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.blueColor = false + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + } + case LedType.blueOn.rawValue: + //ledImage = LedImage.blueLedOnImage ?? UIImage() + ledImage = LedImage.blubOffTint ?? UIImage() + ledColor = UIColor(red: 0.0, green: 0.0, blue: 255.0, alpha: 1) + DispatchQueue.main.async { + //self.blueColorCheckImg.image = LedImage.checkBoxActiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_regularBlueColor") + self.blueColor = true + //self.redColorCheckImg.image = LedImage.checkBoxInactiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.redColor = false + //self.greenColorCheckImg.image = LedImage.checkBoxInactiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.greenColor = false + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + } + case LedType.redGreenOn.rawValue: + //ledImage = LedImage.yellowLedImage ?? UIImage() + ledImage = LedImage.blubOffTint ?? UIImage() + ledColor = UIColor(red: 255.0, green: 255.0, blue: 0.0, alpha: 1) + DispatchQueue.main.async { + //self.redColorCheckImg.image = LedImage.checkBoxActiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_siliconLabsRedColor") + self.redColor = true + //self.greenColorCheckImg.image = LedImage.checkBoxActiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_regularGreenColor") + self.greenColor = true + //self.blueColorCheckImg.image = LedImage.checkBoxInactiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.blueColor = false + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + } + case LedType.redBlueOn.rawValue: + //ledImage = LedImage.magentaLedImage ?? UIImage() + ledImage = LedImage.blubOffTint ?? UIImage() + ledColor = UIColor(red: 255.0, green: 0.0, blue: 255.0, alpha: 1) + DispatchQueue.main.async { + //self.redColorCheckImg.image = LedImage.checkBoxActiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_siliconLabsRedColor") + self.redColor = true + //self.blueColorCheckImg.image = LedImage.checkBoxActiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_regularBlueColor") + self.blueColor = true + //self.greenColorCheckImg.image = LedImage.checkBoxInactiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.greenColor = false + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + } + case LedType.greenBuleOn.rawValue: + //ledImage = LedImage.cyanLedImage ?? UIImage() + ledImage = LedImage.blubOffTint ?? UIImage() + ledColor = UIColor(red: 0.0, green: 255.0, blue: 255.0, alpha: 1) + DispatchQueue.main.async { + //self.greenColorCheckImg.image = LedImage.checkBoxActiveImage + self.greenColorBtn.backgroundColor = UIColor(named: "sil_regularGreenColor") + self.greenColor = true + //self.blueColorCheckImg.image = LedImage.checkBoxActiveImage + self.blueColorBtn.backgroundColor = UIColor(named: "sil_regularBlueColor") + self.blueColor = true + //self.redColorCheckImg.image = LedImage.checkBoxInactiveImage + self.redColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.redColor = false + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + } + default: + print("Have you done something new?") + } + DispatchQueue.main.async { + self.blubImg.image = ledImage + if type != LedType.ledOn.rawValue && type != LedType.ledOff.rawValue { + self.blubImg.tintColor = ledColor + } + } + } + @IBAction func Led_On(_ sender: Any) { + redColorVlue = "on" + greenColorVlue = "on" + blueColorVlue = "on" + self.onBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + self.offBtn.backgroundColor = UIColor(named: "sil_boulderColor") + ledControll() + } + + func ledControll() { + let paramStr = """ + {"red": "\(redColorVlue)", "green": "\(greenColorVlue)", "blue": "\(blueColorVlue)"} + """ + silWiFiLedSensorsViewModelObject.ledOnOf(ledType: LedType.ledOn.rawValue, parameter: paramStr, urlEndpoint: "led") { sensorsData, APIClientError in + if APIClientError == nil{ + if let ledDic: Dictionary = sensorsData { + print(ledDic) +// self.redColorVlue = "\(ledDic["red"] ?? "")" +// self.greenColorVlue = "\(ledDic["green"] ?? "")" +// self.blueColorVlue = "\(ledDic["blue"] ?? "")" +// self.setLedStatus(type: LedType.ledOn.rawValue) + self.stateOfLed(ledDic: ledDic) + }else{ + + } + } + } + } + + @IBAction func Led_off(_ sender: Any) { + redColorVlue = "off" + greenColorVlue = "off" + blueColorVlue = "off" + self.onBtn.backgroundColor = UIColor(named: "sil_boulderColor") + self.offBtn.backgroundColor = UIColor(named: "sil_primaryTextColor") + ledControll() +// silWiFiLedSensorsViewModelObject.ledOnOf(ledType: LedType.ledOff.rawValue, parameter: """ +// {"red": "off", "green": "off", "blue": "off"} +// """, urlEndpoint: "led") { sensorsData, APIClientError in +// if APIClientError == nil{ +// if let ledDic: Dictionary = sensorsData { +// print(ledDic) +//// self.redColorVlue = "\(ledDic["red"] ?? "")" +//// self.greenColorVlue = "\(ledDic["green"] ?? "")" +//// self.blueColorVlue = "\(ledDic["blue"] ?? "")" +//// self.setLedStatus(type: LedType.ledOff.rawValue) +// self.stateOfLed(ledDic: ledDic) +// } +// } +// } + } + + @IBAction func Led_Red(_ sender: Any) { + silWiFiLedSensorsViewModelObject.ledOnOf(ledType: LedType.redOn.rawValue, parameter: """ + {"red": "on", "green": "off", "blue": "off"} + """, urlEndpoint: "led") { sensorsData, APIClientError in + if APIClientError == nil{ + if let ledDic: Dictionary = sensorsData { + print(ledDic) + self.redColorVlue = "\(ledDic["red"] ?? "")" + self.greenColorVlue = "\(ledDic["green"] ?? "")" + self.blueColorVlue = "\(ledDic["blue"] ?? "")" + self.setLedStatus(type: LedType.redOn.rawValue) + } + } + } + } + + + @IBAction func Led_blue(_ sender: Any) { + silWiFiLedSensorsViewModelObject.ledOnOf(ledType: LedType.blueOn.rawValue, parameter: """ + {"red": "off", "green": "off", "blue": "on"} + """, urlEndpoint: "led") { sensorsData, APIClientError in + if APIClientError == nil{ + if let ledDic: Dictionary = sensorsData { + print(ledDic) + self.redColorVlue = "\(ledDic["red"] ?? "")" + self.greenColorVlue = "\(ledDic["green"] ?? "")" + self.blueColorVlue = "\(ledDic["blue"] ?? "")" + self.setLedStatus(type: LedType.blueOn.rawValue) + } + } + } + } + + + @IBAction func Led_Green(_ sender: Any) { + silWiFiLedSensorsViewModelObject.ledOnOf(ledType: LedType.blueOn.rawValue, parameter: """ + {"red": "off", "green": "on", "blue": "off"} + """, urlEndpoint: "led") { sensorsData, APIClientError in + if APIClientError == nil{ + if let ledDic: Dictionary = sensorsData { + print(ledDic) + self.redColorVlue = "\(ledDic["red"] ?? "")" + self.greenColorVlue = "\(ledDic["green"] ?? "")" + self.blueColorVlue = "\(ledDic["blue"] ?? "")" + self.setLedStatus(type: LedType.greenOn.rawValue) + } + } + } + } + + @IBAction func colorCheckBtn(_ sender: UIButton) { + if sender.tag == 1 { + if redColor { + //redColorCheckImg.image = LedImage.checkBoxInactiveImage + //redColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + redColor = false + redColorVlue = "off" + if !greenColor { + greenColorVlue = "off" + } + if !blueColor { + blueColorVlue = "off" + } + + }else{ + //redColorCheckImg.image = LedImage.checkBoxActiveImage + //redColorBtn.backgroundColor = UIColor(named: "sil_siliconLabsRedColor") + redColor = true + redColorVlue = "on" + if !greenColor { + greenColorVlue = "off" + } + if !blueColor { + blueColorVlue = "off" + } + } + }else if sender.tag == 2{ + if greenColor { + //greenColorCheckImg.image = LedImage.checkBoxInactiveImage + //greenColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + greenColor = false + greenColorVlue = "off" + if !redColor { + redColorVlue = "off" + } + if !blueColor { + blueColorVlue = "off" + } + + }else{ + //greenColorCheckImg.image = LedImage.checkBoxActiveImage + //greenColorBtn.backgroundColor = UIColor(named: "sil_regularGreenColor") + greenColor = true + greenColorVlue = "on" + if !redColor { + redColorVlue = "off" + } + if !blueColor { + blueColorVlue = "off" + } + } + }else if sender.tag == 3{ + if blueColor { + //blueColorCheckImg.image = LedImage.checkBoxInactiveImage + //blueColorBtn.backgroundColor = UIColor(named: "sil_boulderColor") + blueColor = false + blueColorVlue = "off" + if !redColor { + redColorVlue = "off" + } + if !greenColor { + greenColorVlue = "off" + } + + }else{ + //blueColorCheckImg.image = LedImage.checkBoxActiveImage + //blueColorBtn.backgroundColor = UIColor(named: "sil_regularBlueColor") + blueColor = true + blueColorVlue = "on" + if !redColor { + redColorVlue = "off" + } + if !greenColor { + greenColorVlue = "off" + } + } + } + ledControll() + } + @IBAction func cancelBtn(_ sender: UIButton) { + //sensorePopupView.isHidden = true + self.dismiss(animated: false, completion: nil) + } + @IBAction func refreshBtn(_ sender: UIButton) { + getLedStatus() + } +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionVC.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionVC.swift new file mode 100644 index 00000000..eab34cf4 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionVC.swift @@ -0,0 +1,311 @@ +// +// SILWiFiMotionVC.swift +// BlueGecko +// +// Created by SovanDas Maity on 29/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit +import SceneKit + +class SILWiFiMotionVC: UIViewController, MotionDemoInteractionOutput, SILWiFiMotionSensorsViewModelProtocol { + + fileprivate static let defaultWheelSize: Meters = 0.0301 + + fileprivate var acceleration = ThunderboardVector() + fileprivate var orientation = ThunderboardInclination() + fileprivate var position = ThunderboardWheel(diameter: defaultWheelSize) + + var connectedDeviceView: ConnectedDeviceBarView? + var connectedDeviceBarHeight: CGFloat = 70.0 + + @IBOutlet weak var tableView: UITableView! + @IBOutlet weak var tableLeftInset: NSLayoutConstraint! + @IBOutlet weak var tableRightInset: NSLayoutConstraint! + + //@IBOutlet var navigationBar: UIView! + + var silWiFiMotionSensorsViewModel:SILWiFiMotionSensorsViewModel = SILWiFiMotionSensorsViewModel() + + let tableInset: CGFloat = 16.0 + + var motionDemoView: MotionDemoView? + + var motionView: MotionDemoView! { + if let view: MotionDemoView = self.motionDemoView { + return view + } else { + if let cell: MotionCell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? MotionCell { + self.motionDemoView = cell.motionView + return self.motionDemoView + } + } + return nil + } + + var interaction: MotionDemoInteraction! + //var deviceConnector: DeviceConnection? + var ledMaterials: [SCNMaterial] = [] + var apiCallTimer: Timer? + fileprivate var calibrationAlert: UIAlertController? + + fileprivate let calibrationTitle = "Calibrating" + fileprivate let calibrationMessage = "Please ensure the Thunderboard is stationary during calibration" + + override func viewDidLoad() { + super.viewDidLoad() + silWiFiMotionSensorsViewModel.SILWiFiMotionSensorsViewModelDelegate = self + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + self.setupModel() + } + setupTableView() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + apiCallTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [weak self] (timer) in + self?.silWiFiMotionSensorsViewModel.getMotionData() + }) + + //interaction.checkMissingSensors() + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + //self.setupWheel() + self.updateModelOrientation(ThunderboardInclination(x: 0, y: 0, z: 0), animated: false) + //self.interaction.updateView() + } + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + //deviceConnector?.disconnectAllDevices() + apiCallTimer = nil + apiCallTimer?.invalidate() + } + + func displayInfoAbout(missingCapabilities: Set) { + let alertMessage = "The device cannot work properly, because it has broken sensors: \(missingCapabilities.map { $0.name }.joined(separator: ", ")). \nYou will be redirected to home screen." + self.alertWithOKButton(title: "Broken sensors", message: alertMessage) { _ in + self.navigationController?.popViewController(animated: true) + } + } + + func dispatchSetup() { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + self.setupModel() + self.tableView.reloadData() + } + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { + self.setupWheel() + self.updateModelOrientation(ThunderboardInclination(x: 0, y: 0, z: 0), animated: false) + self.interaction.updateView() + self.tableView.reloadData() + } + } + + func setupModel() { + // no-op - implemented in subclasses + } + + func setupTableView() { + if #available(iOS 13, *) { + tableView.separatorStyle = .none; + } else { + tableLeftInset.constant = tableInset; + tableRightInset.constant = tableInset; + } + } + + func modelTranformMatrixForOrientation(_ orientation: ThunderboardInclination) -> SCNMatrix4 { + // no-op - implemented in subclasses to account for model orientation deltas + return motionView.modelIdentity + } + + //MARK: - MotionDemoInteractionOutput + + func updateOrientation(_ orientation: ThunderboardInclination) { + let degrees = " °" + motionView.orientationXValue?.text = orientation.x.tb_toString(0)! + degrees + motionView.orientationYValue?.text = orientation.y.tb_toString(0)! + degrees + motionView.orientationZValue?.text = orientation.z.tb_toString(0)! + degrees + + updateModelOrientation(orientation, animated: true) + } + + func updateAcceleration(_ vector: ThunderboardVector) { + let gravity = " g" + + motionView.accelerationXValue?.text = vector.x.tb_toString(2, minimumDecimalPlaces: 2)! + motionView.accelerationXValue?.text = vector.x.tb_toString(2, minimumDecimalPlaces: 2)! + gravity + motionView.accelerationYValue?.text = vector.y.tb_toString(2, minimumDecimalPlaces: 2)! + gravity + motionView.accelerationZValue?.text = vector.z.tb_toString(2, minimumDecimalPlaces: 2)! + gravity + } + + func updateWheel(_ diameter: Meters) { + let settings = ThunderboardSettings() + switch settings.measurement { + case .metric: + let diameterInCentimeters: Centimeters = diameter * 100 + motionView.wheelDiameterValue?.text = diameterInCentimeters.tb_toString(2)! + " cm" + case .imperial: + let diameterInInches = diameter.tb_toInches() + motionView.wheelDiameterValue?.text = diameterInInches.tb_toString(2)! + "\"" + } + } + + func updateLocation(_ distance: Float, speed: Float, rpm: Float, totalRpm: UInt) { + let settings = ThunderboardSettings() + switch settings.measurement { + case .metric: + motionView.distanceValue?.text = distance.tb_toString(1) + motionView.speedValue?.text = speed.tb_toString(1) + case .imperial: + motionView.distanceValue?.text = distance.tb_toFeet().tb_toString(1) + motionView.speedValue?.text = speed.tb_toFeet().tb_toString(1) + } + motionView.rpmValue?.text = rpm.tb_toString(0) + motionView.totalRpmValue?.text = String(totalRpm) + } + + func updateLedColor(_ on: Bool, color: LedRgb) { + updateModelLedColor(on ? color.uiColor : StyleColor.mediumGray) + } + + func deviceCalibrating(_ isCalibrating: Bool) { + if isCalibrating { + if calibrationAlert == nil { + calibrationAlert = UIAlertController(title: calibrationTitle, message: calibrationMessage, preferredStyle: .alert) + calibrationAlert?.view.tintColor = StyleColor.vileRed + present(self.calibrationAlert!, animated: true, completion: nil) + } + } else { + guard calibrationAlert != nil else { return } + + // Call dismiss on self because calling it on UIAlertController does not produce a completion call + dismiss(animated: true, completion: { + let alertController = UIAlertController(title: "Calibration successful", message: nil, preferredStyle: .alert) + + let cancelAction = UIAlertAction(title: "Ok", style: .cancel, handler: nil) + alertController.addAction(cancelAction) + + self.present(alertController, animated: true, completion: nil) + }) + calibrationAlert = nil + } + } + + //MARK: - Actions + + @IBAction func calibrateButtonPressed(_ sender: AnyObject) { + interaction.calibrate() + } + + @IBAction func backButton() { + self.navigationController?.popViewController(animated: true) + } + + //MARK: - Private + + fileprivate func setupUnitsLabels() { + let settings = ThunderboardSettings() + + switch settings.measurement { + case .metric: + motionView.distanceValueLabel?.text = "m" + motionView.speedValueLabel?.text = "m/s" + case .imperial: + motionView.distanceValueLabel?.text = "ft" + motionView.speedValueLabel?.text = "ft/s" + } + + motionView.rpmValueLabel?.text = "rpm" + motionView.totalRpmValueLabel?.text = "total revolutions" + } + + fileprivate func setupWheel() { + let diameter = interaction.wheelDiameter() + updateWheel(diameter) + } + + fileprivate func updateModelOrientation(_ orientation : ThunderboardInclination, animated: Bool) { + let finalTransform = modelTranformMatrixForOrientation(orientation) + + SCNTransaction.begin() + SCNTransaction.animationDuration = animated ? 0.1 : 0.0 + motionView.scene.rootNode.childNodes.first?.transform = finalTransform + SCNTransaction.commit() + } + + fileprivate func updateModelLedColor(_ color: UIColor) { + ledMaterials.forEach { (material) in + material.diffuse.contents = color + material.emission.contents = color + } + } + + func notifyMotionSensorsData(sensorsData: Dictionary?) { + if let sensorsData = sensorsData { + let aX = (sensorsData["accelerometer"] as? Dictionary)?["x"] + let aY = (sensorsData["accelerometer"] as? Dictionary)?["y"] + let aZ = (sensorsData["accelerometer"] as? Dictionary)?["z"] + + let gX = (sensorsData["gyroscope"] as? Dictionary)?["x"] + let gY = (sensorsData["gyroscope"] as? Dictionary)?["y"] + let gZ = (sensorsData["gyroscope"] as? Dictionary)?["z"] + let xAcceleration = α("\(aX ?? "")") ?? 0.0 + let yAcceleration = α("\(aY ?? "")") ?? 0.0 + let zAcceleration = α("\(aZ ?? "")") ?? 0.0 + ThunderboardVector(x: xAcceleration, y: yAcceleration, z: zAcceleration) + let xDegrees = Degree("\(gX ?? "")") ?? 0.0 + let yDegrees = Degree("\(gY ?? "")") ?? 0.0 + let zDegrees = Degree("\(gZ ?? "")") ?? 0.0 + + //self.uiUpdate(sensorsData: sensorsData) + + + + + updateModelOrientation(orientation, animated: true) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + + let degrees = " °" + self.motionView.orientationXValue?.text = "\(gX ?? "")" + degrees + self.motionView.orientationYValue?.text = "\(gY ?? "")" + degrees + self.motionView.orientationZValue?.text = "\(gZ ?? "")" + degrees + + let gravity = " g" + self.motionView.accelerationXValue?.text = "\(aX ?? "")" + gravity + self.motionView.accelerationYValue?.text = "\(aY ?? "")" + gravity + self.motionView.accelerationZValue?.text = "\(aZ ?? "")" + gravity + + self.updateModelOrientation(ThunderboardInclination(x: xDegrees, y: yDegrees, z: zDegrees), animated: true) + //self.tableView.reloadData() + } + } + } +} +extension SILWiFiMotionVC: UITableViewDataSource { + func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 1 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell: MotionCell = tableView.dequeueReusableCell(withIdentifier: "MotionCell") as! MotionCell + motionDemoView = cell.motionView + setupModel() + + return cell + } + + func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { + SILTableViewWithShadowCells.tableView(tableView, willDisplay: cell, forRowAt: indexPath) + } +} + +extension SILWiFiMotionVC: UITableViewDelegate { + +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionVcCh.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionVcCh.swift new file mode 100644 index 00000000..088af09d --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionVcCh.swift @@ -0,0 +1,101 @@ +// +// SILWiFiMotionVcCh.swift +// BlueGecko +// +// Created by SovanDas Maity on 29/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit +import SceneKit + +class SILWiFiMotionVcCh: SILWiFiMotionVC { + + public var deviceModelName: String! + + override func viewDidLoad() { + super.viewDidLoad() + setLeftAlignedTitle("Motion") + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + self.navigationController?.tabBarController?.hideTabBarAndUpdateFrames() + } + + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + self.navigationController?.tabBarController?.showTabBarAndUpdateFrames() + } + + override func setupModel() { + + let scaleFactor: Float = 0.75 + let identity = SCNMatrix4Identity + let scale = SCNMatrix4Scale(identity, scaleFactor, scaleFactor, scaleFactor) + + var initialOrientation = SCNMatrix4Rotate(scale, 0, 1, 0, 0) + initialOrientation = SCNMatrix4Rotate(initialOrientation, .pi/2, 1, 0, 0) + + let modelScene = deviceModelName == "BRD4184A" ? "BRD4184A_LowPoly.scn" : "TBSense_Rev_Lowpoly_2.obj" + motionView.setModelScene(modelScene, initialOrientation: initialOrientation) + ledMaterials = locateMaterialsNamed([ + "thunderboardsense_lowpoly_007:lambert28sg", + "thunderboardsense_lowpoly_007:lambert32sg", + "lambert25sg", + "lambert26sg", + ]) + } + + override func modelTranformMatrixForOrientation(_ orientation: ThunderboardInclination) -> SCNMatrix4 { + let modelIdentity = motionView.modelIdentity + + if #available(iOS 13, *) { + var transform = SCNMatrix4Rotate(modelIdentity!, -orientation.x.tb_toRadian(), 1, 0, 0) + transform = SCNMatrix4Rotate(transform, orientation.y.tb_toRadian(), 0, 0, 1) + transform = SCNMatrix4Rotate(transform, orientation.z.tb_toRadian(), 0, 1, 0) + return transform + } else { + var transform = SCNMatrix4Rotate(modelIdentity!, -orientation.x.tb_toRadian(), 1, 0, 0) + transform = SCNMatrix4Rotate(transform, -orientation.y.tb_toRadian(), 0, 1, 0) + transform = SCNMatrix4Rotate(transform, orientation.z.tb_toRadian(), 0, 0, 1) + return transform + } + } + + // MARK: - Private + + fileprivate func locateMaterialsNamed(_ names: [String]) -> [SCNMaterial] { + let lowercaseNames = names.map({ $0.lowercased() }) + func recurseNode(_ node: SCNNode) -> [SCNMaterial] { + var results: [SCNMaterial] = [] + + node.childNodes.forEach({ (child) in + if let _ = child.geometry { + + child.childNodes.forEach({ + results.append(contentsOf: recurseNode($0)) + }) + + child.geometry?.materials.forEach({ (material) in + guard let materialName = material.name?.lowercased() else { + return + } + + if lowercaseNames.contains(materialName) { + results.append(material) + } + }) + } + + results.append(contentsOf: recurseNode(child)) + }) + + return results + } + + let results = recurseNode(motionView.scene.rootNode) + log.debug("results: \(results)") + return results + } +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionViewController.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionViewController.swift new file mode 100644 index 00000000..d67d323e --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWiFiMotionViewController.swift @@ -0,0 +1,102 @@ +// +// SILWiFiMotionViewController.swift +// BlueGecko +// +// Created by SovanDas Maity on 28/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit + +class SILWiFiMotionViewController: UIViewController, SILWiFiMotionSensorsViewModelProtocol { + + @IBOutlet weak var accelerationXLbl: StyledLabel! + @IBOutlet weak var accelerationYLbl: StyledLabel! + @IBOutlet weak var accelerationZLbl: StyledLabel! + + @IBOutlet weak var orientationXLbl: StyledLabel! + @IBOutlet weak var orientationYLbl: StyledLabel! + @IBOutlet weak var orientationZLbl: StyledLabel! + + var silWiFiMotionSensorsViewModel:SILWiFiMotionSensorsViewModel = SILWiFiMotionSensorsViewModel() + var apiCallTimer: Timer? + + var accelerationXStr: String = "" + var accelerationYStr: String = "" + var accelerationZStr: String = "" + + var orientationXStr: String = "" + var orientationYStr: String = "" + var orientationZStr: String = "" + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + silWiFiMotionSensorsViewModel.SILWiFiMotionSensorsViewModelDelegate = self + + let motionData = ["gyroscope": ["x": orientationXStr, "y": orientationYStr, "z": orientationZStr], "accelerometer": ["x": accelerationXStr, "y": accelerationYStr, "z": accelerationZStr]] + uiUpdate(sensorsData: motionData) + + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + apiCallTimer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true, block: { [weak self] (timer) in + self?.silWiFiMotionSensorsViewModel.getMotionData() + }) + //silWiFiMotionSensorsViewModel.getMotionData() + } + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + if self.apiCallTimer != nil{ + self.apiCallTimer?.invalidate() + self.apiCallTimer = nil + } + } + + @IBAction func cancelBtn(_ sender: UIButton) { + //sensorePopupView.isHidden = true + if self.apiCallTimer != nil{ + self.apiCallTimer?.invalidate() + self.apiCallTimer = nil + } + self.dismiss(animated: false, completion: nil) + } + @IBAction func refreshBtn(_ sender: UIButton) { + silWiFiMotionSensorsViewModel.getMotionData() + } + func uiUpdate(sensorsData: Dictionary){ + //print(sensorsData) + let degrees = " °" + let gravity = " g" + DispatchQueue.main.async { + self.orientationXLbl.text = "\((sensorsData["gyroscope"] as? Dictionary)?["x"] ?? "")\(degrees)" + self.orientationYLbl.text = "\((sensorsData["gyroscope"] as? Dictionary)?["y"] ?? "")\(degrees)" + self.orientationZLbl.text = "\((sensorsData["gyroscope"] as? Dictionary)?["z"] ?? "")\(degrees)" + self.accelerationXLbl.text = "\((sensorsData["accelerometer"] as? Dictionary)?["x"] ?? "")\(gravity)" + self.accelerationYLbl.text = "\((sensorsData["accelerometer"] as? Dictionary)?["y"] ?? "")\(gravity)" + self.accelerationZLbl.text = "\((sensorsData["accelerometer"] as? Dictionary)?["z"] ?? "")\(gravity)" + } + + } + func notifyMotionSensorsData(sensorsData: Dictionary?) { + if let sensorsData = sensorsData { + let aX = (sensorsData["accelerometer"] as? Dictionary)?["x"] + let aY = (sensorsData["accelerometer"] as? Dictionary)?["y"] + let aZ = (sensorsData["accelerometer"] as? Dictionary)?["z"] + + let gX = (sensorsData["accelerometer"] as? Dictionary)?["x"] + let gY = (sensorsData["accelerometer"] as? Dictionary)?["y"] + let gZ = (sensorsData["accelerometer"] as? Dictionary)?["z"] + let xAcceleration = α("\(aX ?? "")") ?? 0.0 + let yAcceleration = α("\(aY ?? "")") ?? 0.0 + let zAcceleration = α("\(aZ ?? "")") ?? 0.0 + ThunderboardVector(x: xAcceleration, y: yAcceleration, z: zAcceleration) + let xDegrees = Degree("\(gX ?? "")") ?? 0.0 + let yDegrees = Degree("\(gY ?? "")") ?? 0.0 + let zDegrees = Degree("\(gZ ?? "")") ?? 0.0 + ThunderboardInclination(x: xDegrees, y: yDegrees, z: zDegrees) + self.uiUpdate(sensorsData: sensorsData) + } + } +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWifiSensorsHomeView.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWifiSensorsHomeView.swift new file mode 100644 index 00000000..afed3ca9 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/SILWifiSensorsHomeView.swift @@ -0,0 +1,256 @@ +// +// SILWifiSensorsHomeView.swift +// BlueGecko +// +// Created by Mantosh Kumar on 05/04/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit +import SVProgressHUD + +class SILWifiSensorsHomeView: UIViewController, SILWiFiSensorsViewModelProtocol { + + @IBOutlet weak var sensoreValueLbl: UILabel! + @IBOutlet weak var sensoreImg: UIImageView! + @IBOutlet weak var sensoreTitleLbl: UILabel! + @IBOutlet weak var sensorePopupViewTitle: UILabel! + @IBOutlet weak var sensorePopupView: UIView! + @IBOutlet var collectionView: UICollectionView! + @IBOutlet weak var noDataView: UIView! + + //var timer = Timer() + var sensorsData: [Any] = [] + var sensorTypeStr: String = "" + var apiCallTimer: Timer? + + var silwifiSensorsViewModelObject:SILWiFiSensorsViewModel = SILWiFiSensorsViewModel() + + override func viewDidLoad() { + super.viewDidLoad() + //silwifiSensorsViewModelObject.checkServerAvailability() + //setupNavigationBar() + silwifiSensorsViewModelObject.SILWiFiSensorsViewModelDelegate = self + updateUI() + + + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + SVProgressHUD.show(withStatus: "Connecting") + sensorTypeStr = "" + silwifiSensorsViewModelObject.getTemperatureData { sensorsData, APIClientError in + if APIClientError == nil{ + DispatchQueue.main.async { + self.silwifiSensorsViewModelObject.getAllSensorData() + //self.silwifiSensorsViewModelObject.getAllSensor() + } + }else{ + DispatchQueue.main.async { + SVProgressHUD.dismiss() + } + } + } + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + self.tabBarController?.tabBar.isHidden = true + } + + private func updateUI() { + setLeftAlignedTitle("WiFi Sensors") + let nib = UINib(nibName: "SILSensorCell", bundle: nil) + collectionView.register(nib, forCellWithReuseIdentifier: "SILSensorCell") + collectionView.backgroundColor = UIColor.clear + collectionView.delegate = self + sensorePopupView.isHidden = true + } + + @IBAction func cancelBtn(_ sender: UIButton) { + sensorePopupView.isHidden = true + sensorTypeStr = "" + if self.apiCallTimer != nil{ + self.apiCallTimer?.invalidate() + self.apiCallTimer = nil + } + + } + @IBAction func refreshBtn(_ sender: UIButton) { + if sensorTypeStr == SensorType.temp.rawValue { + self.getTemp() + }else if sensorTypeStr == SensorType.humudity.rawValue { + self.getHumudity() + }else if sensorTypeStr == SensorType.ambient.rawValue { + self.getAmbient() + } + } + +} +extension SILWifiSensorsHomeView { + + func notifySensorsData(sensorsData: [Any]) { + self.sensorsData = sensorsData + DispatchQueue.main.async { + SVProgressHUD.dismiss() + if self.sensorsData.count > 0 { + self.noDataView.isHidden = true + self.collectionView.isHidden = false + }else{ + self.noDataView.isHidden = false + self.collectionView.isHidden = true + } + self.collectionView.reloadData() + } + } +} + +extension SILWifiSensorsHomeView: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return sensorsData.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SILSensorCell", for: indexPath as IndexPath) as? SILSensorCell else { return UICollectionViewCell() } + cell.updateSensorValue(sensorsData: sensorsData[indexPath.row] as! Dictionary) + return cell + } + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { + return UIEdgeInsets(top: 5, left: 10, bottom: 20, right: 10) + } + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + selectedSensor(cellIndex: indexPath.row) + } + +} +extension SILWifiSensorsHomeView { + + func setTimer(apiType: String){ + if apiType == SensorType.temp.rawValue { + if self.apiCallTimer != nil{ + self.apiCallTimer?.invalidate() + self.apiCallTimer = nil + } + apiCallTimer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true, block: { [weak self] (timer) in + //self?.getRequest() + self?.getTemp() + }) + }else if apiType == SensorType.humudity.rawValue { + if self.apiCallTimer != nil{ + self.apiCallTimer?.invalidate() + self.apiCallTimer = nil + } + apiCallTimer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true, block: { [weak self] (timer) in + //self?.getRequest() + self?.getHumudity() + }) + }else if apiType == SensorType.ambient.rawValue { + if self.apiCallTimer != nil{ + self.apiCallTimer?.invalidate() + self.apiCallTimer = nil + } + apiCallTimer = Timer.scheduledTimer(withTimeInterval: 3, repeats: true, block: { [weak self] (timer) in + //self?.getRequest() + self?.getAmbient() + }) + + } + } + func getTemp(){ + silwifiSensorsViewModelObject.getTemperatureData { sensorsData, APIClientError in + if APIClientError == nil{ + if let ledDic: Dictionary = sensorsData { + DispatchQueue.main.async { + self.setPopUpData(sensorePopupViewTitle: SensorePopupViewName.temperaturePopupViewTitle.rawValue, sensoreTitleLbl: SensorTitle.temperatureTitle.rawValue, sensoreImg: SensorImage.temp ?? UIImage(), sensoreValueLbl: "\(ledDic["temperature_celcius"] ?? "")°C") + } + } + } + } + } + func getHumudity() { + silwifiSensorsViewModelObject.getHumidityData { sensorsData, APIClientError in + if APIClientError == nil{ + if let ledDic: Dictionary = sensorsData { + DispatchQueue.main.async { + self.setPopUpData(sensorePopupViewTitle: SensorePopupViewName.humudityPopupViewTitle.rawValue, sensoreTitleLbl: SensorTitle.humudityTitle.rawValue, sensoreImg: SensorImage.humidity ?? UIImage(), sensoreValueLbl: "\(ledDic["humidity_percentage"] ?? "")%") + } + } + } + } + } + func getAmbient() { + silwifiSensorsViewModelObject.getLightData { sensorsData, APIClientError in + if APIClientError == nil{ + if let ledDic: Dictionary = sensorsData { + DispatchQueue.main.async { + self.setPopUpData(sensorePopupViewTitle: SensorePopupViewName.ambientLightPopupViewTitle.rawValue, sensoreTitleLbl: SensorTitle.ambientLightTitle.rawValue, sensoreImg: SensorImage.ambient ?? UIImage(), sensoreValueLbl: "\(ledDic["ambient_light_lux"] ?? "") lx") + } + } + } + } + } +} +extension SILWifiSensorsHomeView { + func setPopUpData(sensorePopupViewTitle: String, sensoreTitleLbl: String, sensoreImg: UIImage, sensoreValueLbl: String) { + self.sensorePopupViewTitle.text = sensorePopupViewTitle + self.sensoreTitleLbl.text = sensoreTitleLbl + self.sensoreImg.image = sensoreImg + self.sensoreValueLbl.text = sensoreValueLbl + } + + func selectedSensor(cellIndex: Int) { + let storyboard = UIStoryboard(name: "SILWifiSensors", bundle: .main) + if let sensorsDataDic: Dictionary = sensorsData[cellIndex] as? Dictionary{ + switch "\(sensorsDataDic["title"] ?? "")" { + case SensorType.temp.rawValue: + sensorePopupView.isHidden = false + self.sensorTypeStr = SensorType.temp.rawValue + self.setPopUpData(sensorePopupViewTitle: SensorePopupViewName.temperaturePopupViewTitle.rawValue, sensoreTitleLbl: SensorTitle.temperatureTitle.rawValue, sensoreImg: SensorImage.temp ?? UIImage(), sensoreValueLbl: "\(sensorsDataDic["value"] ?? "")°C") + self.setTimer(apiType: SensorType.temp.rawValue) + case SensorType.humudity.rawValue: + sensorePopupView.isHidden = false + self.sensorTypeStr = SensorType.humudity.rawValue + self.setPopUpData(sensorePopupViewTitle: SensorePopupViewName.humudityPopupViewTitle.rawValue, sensoreTitleLbl: SensorTitle.humudityTitle.rawValue, sensoreImg: SensorImage.humidity ?? UIImage(), sensoreValueLbl: "\(sensorsDataDic["value"] ?? "")%") + self.setTimer(apiType: SensorType.humudity.rawValue) + case SensorType.ambient.rawValue: + sensorePopupView.isHidden = false + self.sensorTypeStr = SensorType.ambient.rawValue + self.setPopUpData(sensorePopupViewTitle: SensorePopupViewName.ambientLightPopupViewTitle.rawValue, sensoreTitleLbl: SensorTitle.ambientLightTitle.rawValue, sensoreImg: SensorImage.ambient ?? UIImage(), sensoreValueLbl: "\((sensorsDataDic["value"] as? [String: Any])?["ambient_light_lux"] ?? "") lx") + self.setTimer(apiType: SensorType.ambient.rawValue) + case SensorType.led.rawValue: + sensorePopupView.isHidden = true + let SILWiFiLEDViewControllerObj = storyboard.instantiateViewController(withIdentifier: "SILWiFiLEDViewController") + SILWiFiLEDViewControllerObj.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext + present(SILWiFiLEDViewControllerObj, animated: false) + + //navigationController?.pushViewController(SILWiFiLEDViewControllerObj, animated: true) + case SensorType.motion.rawValue: + sensorePopupView.isHidden = true + //SILWiFiMotionVcCh + //let SILWiFiMotionViewControllerObj = storyboard.instantiateViewController(withIdentifier: "SILWiFiMotionVcCh") + let SILWiFiMotionViewControllerObj = storyboard.instantiateViewController(withIdentifier: "SILWiFiMotionViewController") + SILWiFiMotionViewControllerObj.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext + present(SILWiFiMotionViewControllerObj, animated: false) + + default: + print("Have you done something new?") + } + } + } +} + +extension SILWifiSensorsHomeView: UITextFieldDelegate { + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() + return true + } + + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + return true + } +} + diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/WiFiMotionDemoConnection.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/WiFiMotionDemoConnection.swift new file mode 100644 index 00000000..dd113c99 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Controller/WiFiMotionDemoConnection.swift @@ -0,0 +1,145 @@ +// +// WiFiMotionDemoConnection.swift +// BlueGecko +// +// Created by SovanDas Maity on 29/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit + +class WiFiMotionDemoConnection: MotionDemoConnection { + var device: any Device + + + fileprivate var bleDevice: BleDevice { + get { return device as! BleDevice } + } + + weak var connectionDelegate: MotionDemoConnectionDelegate? + + fileprivate let startCalibrationId = 0x01 + fileprivate let resetOrientationId = 0x02 + + init(device: BleDevice) { + self.device = device + self.bleDevice.demoConnectionCharacteristicValueUpdated = { [weak self] (characteristic: CBCharacteristic) in + self?.characteristicUpdated(characteristic) + } + self.bleDevice.demoDeviceDisconnectedHook = { [weak self] in + self?.connectionDelegate?.demoDeviceDisconnected() + } + } + + func characteristicUpdated(_ characteristic: CBCharacteristic) { + + switch characteristic.uuid { + case CBUUID.CSCMeasurement: + notifyRotation(characteristic) + + case CBUUID.AccelerationMeasurement: + notifyAcceleration(characteristic) + + case CBUUID.OrientationMeasurement: + notifyOrientation(characteristic) + + case CBUUID.Command: + notifyCommand(characteristic) + + case CBUUID.CSCControlPoint: + notifyCSCControlPoint(characteristic) + + case CBUUID.SenseRGBOutput: + notifyColorUpdated(characteristic) + + default: + log.debug("unknown UUID: \(characteristic.uuid)") + break + } + } + + // MotionDemoConnection protocol + + func startCalibration() { + let data = Data(bytes: [UInt8(0x01)]) + self.bleDevice.writeValueForCharacteristic(CBUUID.Command, value: data) + + self.connectionDelegate?.startedCalibration() + } + + func resetOrientation() { + let data = Data(bytes: [UInt8(0x02)]) + self.bleDevice.writeValueForCharacteristic(CBUUID.Command, value: data) + + self.connectionDelegate?.startedOrientationReset() + } + + func resetRevolutions() { + let data = Data(bytes: [UInt8(0x01), 0, 0, 0, 0]) + self.bleDevice.writeValueForCharacteristic(CBUUID.CSCControlPoint, value: data) + + self.connectionDelegate?.startedRevolutionsReset() + } + + func readLedColor() { + self.bleDevice.readValuesForCharacteristic(CBUUID.SenseRGBOutput) + } + + // Internal + + fileprivate func notifyRotation(_ characteristic: CBCharacteristic) { + if let cscMeasurement:ThunderboardCSCMeasurement = characteristic.tb_cscMeasurementValue() { + + let revolutions = cscMeasurement.revolutionsSinceConnecting + let elapsedTime = cscMeasurement.secondsSinceConnecting + self.connectionDelegate?.rotationUpdated(UInt(revolutions), elapsedTime: elapsedTime) + } + } + + fileprivate func notifyOrientation(_ characteristic: CBCharacteristic) { + if let inclination = characteristic.tb_inclinationValue() { + self.connectionDelegate?.orientationUpdated(inclination) + } + } + + fileprivate func notifyAcceleration(_ characteristic: CBCharacteristic) { + if let vector = characteristic.tb_vectorValue() { + self.connectionDelegate?.accelerationUpdated(vector) + } + } + + fileprivate func notifyCommand(_ characteristic: CBCharacteristic) { + if let value = characteristic.tb_uint32Value() { + + let command = Int(value >> 8) & 0b11 + if command == startCalibrationId { + self.connectionDelegate?.finishedCalbration() + } + + else if command == resetOrientationId { + self.connectionDelegate?.finishedOrientationReset() + } + + else { + log.debug("Unknown notify command: \(command)") + } + } + } + + fileprivate func notifyColorUpdated(_ characteristic: CBCharacteristic) { + guard let ledState = characteristic.tb_analogLedState() else { + return + } + + switch ledState { + case .rgb(let on, let color): + connectionDelegate?.ledColorUpdated(on, color: color) + default: + break + } + } + + fileprivate func notifyCSCControlPoint(_ characteristic: CBCharacteristic) { + self.connectionDelegate?.finishedRevolutionsReset() + } +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Model/SILAllWiFiSensorModel.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Model/SILAllWiFiSensorModel.swift new file mode 100644 index 00000000..38a9b902 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Model/SILAllWiFiSensorModel.swift @@ -0,0 +1,40 @@ +// +// SILAllWiFiSensorModel.swift +// BlueGecko +// +// Created by SovanDas Maity on 11/07/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import Foundation +enum SensorImage { + static let temp = UIImage(named: "icon - temp") + static let motion = UIImage(named: "WiFi_motion_icon") + static let humidity = UIImage(named: "icon - environment") + static let LED_Status = UIImage(named: "WiFi_led_icon") + static let ambient = UIImage(named: "icon - light") + static let unknown = UIImage(named: "icon - environment") +} + +enum SensorType: String { + case temp = "Temperature" + case humudity = "Humidity" + case ambient = "Ambient Light" + case led = "LED" + case motion = "Motion" + static let allSensors = ["Temperature", "Humidity", "Ambient Light", "Motion", "LED"] +} +enum SensorTitle: String { + case temperatureTitle = "Temperature" + case humudityTitle = "Humidity" + case ambientLightTitle = "Ambient Light" + case ledLightTitle = "LED" + case motionTitle = "Motion" +} +enum SensorePopupViewName: String { + case temperaturePopupViewTitle = "Temperature Sensor" + case humudityPopupViewTitle = "Humidity Sensor" + case ambientLightPopupViewTitle = "Ambient Light Sensor" + case ledLightPopupViewTitle = "LED Control" + case motionPopupViewTitle = "Motion Sensor" +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/Model/SILWiFiLEDModel.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Model/SILWiFiLEDModel.swift new file mode 100644 index 00000000..40941bdc --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/Model/SILWiFiLEDModel.swift @@ -0,0 +1,44 @@ +// +// SILWiFiLEDModel.swift +// BlueGecko +// +// Created by SovanDas Maity on 27/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import Foundation +enum LedImage { + static let ledOnImage = UIImage(named: "lightOn") + static let ledOffImage = UIImage(named: "lightOff") + static let redLedOnImage = UIImage(named: "bulb_red") + static let greenLedOnImage = UIImage(named: "bulb_green") + static let blueLedOnImage = UIImage(named: "bulb_blue") + static let magentaLedImage = UIImage(named: "bulb_magenta") + static let cyanLedImage = UIImage(named: "bulb_cyan") + static let yellowLedImage = UIImage(named: "bulb_yellow") + static let checkBoxActiveImage = UIImage(named: "checkBoxActive") + static let checkBoxInactiveImage = UIImage(named: "checkBoxInactive") + static let blubOffTint = UIImage(named: "blub_off_tint") +} +enum LedType: String { + case ledOn = "ledOn" + case ledOff = "ledOff" + case redOn = "redOn" + case greenOn = "greenOn" + case blueOn = "blueOn" + case redOff = "redOff" + case greenOff = "greenOff" + case blueOff = "blueOff" + case redGreenOn = "redGreenOn" + case redBlueOn = "redBlueOn" + case greenBuleOn = "greenBuleOn" +} +enum LedStatus: String { + case ledOnState = "on" + case ledOffState = "off" +} +enum LedColorType: String { + case redType = "red" + case greenType = "green" + case blueType = "blue" +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/Cell/SILSensorCell.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/Cell/SILSensorCell.swift new file mode 100644 index 00000000..ef06caa3 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/Cell/SILSensorCell.swift @@ -0,0 +1,69 @@ +// +// SILSensorCell.swift +// BlueGecko +// +// Created by Mantosh Kumar on 05/04/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import UIKit + + + +class SILSensorCell: UICollectionViewCell { + + @IBOutlet weak var canvasView: UIView! + @IBOutlet weak var sensorIconImage: UIImageView! + @IBOutlet weak var sensorTitleLabel: UILabel! + @IBOutlet weak var sensorValueLabel: UILabel! + + let cornerRadius: CGFloat = 16.0 + + override func awakeFromNib() { + super.awakeFromNib() + setupCellAppearence() + } + + override func layoutSubviews() { + super.layoutSubviews() + layer.masksToBounds = false + backgroundColor = UIColor.clear + addShadow(withOffset: SILCellShadowOffset, radius: SILCellShadowRadius) + } + + private func setupCellAppearence() { + canvasView.layer.cornerRadius = cornerRadius + } + + func updateSensorValue(sensorsData: Dictionary) { + print(sensorsData) + var valOfSensor = "" + + switch "\(sensorsData["title"] ?? "")" { + case SensorType.temp.rawValue: + valOfSensor = "\(sensorsData["value"] ?? "")°C" + case SensorType.humudity.rawValue: + valOfSensor = "\(sensorsData["value"] ?? "")%" + case SensorType.ambient.rawValue: + if let ambientDic: Dictionary = sensorsData["value"] as? Dictionary { + valOfSensor = "\(ambientDic["ambient_light_lux"] ?? "")lx" + } +// valOfSensor = "\(sensorsData["value"] ?? "")" + default: + print("Have you done something new?") + } + sensorTitleLabel.text = "\(sensorsData["title"] ?? "")" + //sensorValueLabel.text = "\(valOfSensor)" + if sensorsData["title"] as! String == SensorType.temp.rawValue { + sensorIconImage.image = SensorImage.temp + }else if sensorsData["title"] as! String == SensorType.humudity.rawValue { + sensorIconImage.image = SensorImage.humidity + }else if sensorsData["title"] as! String == SensorType.ambient.rawValue { + sensorIconImage.image = SensorImage.ambient + }else if sensorsData["title"] as! String == SensorType.led.rawValue { + sensorIconImage.image = SensorImage.LED_Status + }else if sensorsData["title"] as! String == SensorType.motion.rawValue { + sensorIconImage.image = SensorImage.motion + } + } +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/Cell/SILSensorCell.xib b/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/Cell/SILSensorCell.xib new file mode 100644 index 00000000..0c9eee29 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/Cell/SILSensorCell.xib @@ -0,0 +1,93 @@ + + + + + + + + + + + + + Roboto-Medium + + + Roboto-Regular + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/SILWifiSensors.storyboard b/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/SILWifiSensors.storyboard new file mode 100644 index 00000000..3474099d --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/View/SILWifiSensors.storyboard @@ -0,0 +1,1317 @@ + + + + + + + + + + + + + + Roboto-Medium + + + Roboto-Regular + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiLedSensorsViewModel.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiLedSensorsViewModel.swift new file mode 100644 index 00000000..b76fe418 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiLedSensorsViewModel.swift @@ -0,0 +1,97 @@ +// +// SILWiFiLedSensorsViewModel.swift +// BlueGecko +// +// Created by SovanDas Maity on 27/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import Foundation + +class SILWiFiLedSensorsViewModel { + + typealias completionBlockSensors = (_ sensorsData: Dictionary?, _ APIClientError:Error?) -> Void + + + func getLedData(completionBlockSensors: @escaping completionBlockSensors) { + APIRequest.sharedInstance.getApiCall(url: "led") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let ledDic: Dictionary = json as? Dictionary{ + completionBlockSensors(ledDic, nil) + } + } catch { + completionBlockSensors(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlockSensors(nil, APIClientError) + } + } + } + + func ledOnOf(ledType: String, parameter: String, urlEndpoint: String, completionBlockSensors: @escaping completionBlockSensors){ + APIRequest.sharedInstance.postApiCall(parameterDictionary: parameter, url: urlEndpoint) { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let ledDic: Dictionary = json as? Dictionary{ + completionBlockSensors(ledDic, nil) + } + } catch { + completionBlockSensors(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlockSensors(nil, APIClientError) + } + } + } + func statusLed(requestMethod:String, completionBlockSensors: @escaping completionBlockSensors) { + //{"status_led": "on/off"} + if requestMethod == HttpMethods.POST.rawValue { + let paramStr = """ + {"status_led": "off"} + """ + APIRequest.sharedInstance.postApiCall(parameterDictionary: paramStr, url: "status_led") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let statusLedDic: Dictionary = json as? Dictionary{ + completionBlockSensors(statusLedDic, nil) + } + } catch { + completionBlockSensors(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlockSensors(nil, APIClientError) + } + + } + }else if requestMethod == HttpMethods.GET.rawValue { + APIRequest.sharedInstance.getApiCall(url: "status_led") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let statusLedDic: Dictionary = json as? Dictionary{ + completionBlockSensors(statusLedDic, nil) + } + } catch { + completionBlockSensors(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlockSensors(nil, APIClientError) + } + } + } + + } + +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiMotionSensorsViewModel.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiMotionSensorsViewModel.swift new file mode 100644 index 00000000..77d2bbe7 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiMotionSensorsViewModel.swift @@ -0,0 +1,121 @@ +// +// SILWiFiMotionSensorsViewModel.swift +// BlueGecko +// +// Created by SovanDas Maity on 27/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import Foundation +protocol SILWiFiMotionSensorsViewModelProtocol { + // blueprint of a method + func notifyMotionSensorsData(sensorsData: Dictionary?) +} + +class SILWiFiMotionSensorsViewModel { + + var SILWiFiMotionSensorsViewModelDelegate: SILWiFiMotionSensorsViewModelProtocol? + typealias completionBlockMotionSensors = (_ sensorsData: Dictionary?, _ APIClientError:Error?) -> Void + var motionSensorsData = Dictionary() + var gyroscope = Dictionary() + var accelerometer = Dictionary() + let APIRequestdispatchGroup = DispatchGroup() + let concurrentQueue = DispatchQueue(label: "com.gcd.motionsensordispatchGroup", attributes: .concurrent) + var countInt = 0 + + func getGyroscopeData(completionBlockMotionSensors: @escaping completionBlockMotionSensors) { + APIRequest.sharedInstance.getApiCall(url: "gyroscope") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let temperatureDic: Dictionary = json as? Dictionary{ + completionBlockMotionSensors(temperatureDic, nil) + } + } catch { + completionBlockMotionSensors(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlockMotionSensors(nil, APIClientError) + } + } + } + + func getAccelerometerData(completionBlockMotionSensors: @escaping completionBlockMotionSensors) { + APIRequest.sharedInstance.getApiCall(url: "accelerometer") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let temperatureDic: Dictionary = json as? Dictionary{ + completionBlockMotionSensors(temperatureDic, nil) + } + } catch { + completionBlockMotionSensors(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlockMotionSensors(nil, APIClientError) + } + } + } + + func getMotionData() { + + if countInt == 3 { + countInt = 0 + } + //APIRequestdispatchGroup.leave() + + concurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + self.getGyroscopeData { sensorsData, APIClientError in + if APIClientError == nil { + if let ledDic: Dictionary = sensorsData { + self.gyroscope = ledDic + self.APIRequestdispatchGroup.leave() + }else{ + self.APIRequestdispatchGroup.leave() + } + + }else{ + self.APIRequestdispatchGroup.leave() + } + } + } + concurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + self.getAccelerometerData { sensorsData, APIClientError in + if APIClientError == nil { + if let ledDic: Dictionary = sensorsData { + self.accelerometer = ledDic + self.APIRequestdispatchGroup.leave() + }else{ + self.APIRequestdispatchGroup.leave() + } + }else{ + self.APIRequestdispatchGroup.leave() + } + } + } + + APIRequestdispatchGroup.notify(queue: .main) { + print("All functions completed notify") + print("All API done: \(self.countInt)") + print("gyroscope: \(self.gyroscope) ") + print("accelerometer: \(self.accelerometer) ") + self.sendMotionData() + } + APIRequestdispatchGroup.wait() + print("All functions completed wait") + } + + func sendMotionData() { + self.motionSensorsData = [:] + self.motionSensorsData = ["gyroscope": gyroscope, "accelerometer": accelerometer] + if self.motionSensorsData.count > 0 { + SILWiFiMotionSensorsViewModelDelegate?.notifyMotionSensorsData(sensorsData: self.motionSensorsData) + } + } +} diff --git a/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiSensorsViewModel.swift b/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiSensorsViewModel.swift new file mode 100644 index 00000000..e4508d32 --- /dev/null +++ b/SiliconLabsApp/ViewControllers/WiFi_Sensor/ViewModel/SILWiFiSensorsViewModel.swift @@ -0,0 +1,311 @@ +// +// SILWiFiSensorsViewModel.swift +// BlueGecko +// +// Created by SovanDas Maity on 26/06/24. +// Copyright © 2024 SiliconLabs. All rights reserved. +// + +import Foundation +import Network + + +protocol SILWiFiSensorsViewModelProtocol { + // blueprint of a method + func notifySensorsData(sensorsData: [Any]) +} + +class SILWiFiSensorsViewModel { + //static let silwifiSensorsViewModelObject = SILWiFiSensorsViewModel() + var SILWiFiSensorsViewModelDelegate: SILWiFiSensorsViewModelProtocol? + var temperature = "" + var humidity = "" + var ambientLightLux = "" + var whiteLightLux = "" + var gyroscope = Dictionary() + var accelerometer = Dictionary() + var led = Dictionary() + + + typealias completionBlockSensors = (_ sensorsData: [Any]?, _ APIClientError:Error?) -> Void + typealias completionBlock = (_ sensorsData: Dictionary?, _ APIClientError:Error?) -> Void + + + var sensorsData: [Any] = [] + let APIRequestdispatchGroup = DispatchGroup() + let sensorConcurrentQueue = DispatchQueue(label: "com.gcd.sensordispatchGroup", attributes: .concurrent) + var countInt = 0 + + + func getSensors() { + sensorsData = [] + for val in SensorType.allSensors{ + var valOfSensor = "" + var tempDic = Dictionary() + switch val { + case SensorType.temp.rawValue: + tempDic = ["title": "\(val)", "value": temperature] + case SensorType.humudity.rawValue: + tempDic = ["title": "\(val)", "value": humidity] + case SensorType.ambient.rawValue: + //valOfSensor = "AL:\(ambientLightLux) WL:\(whiteLightLux)" + //valOfSensor = "\(ambientLightLux) lx" + tempDic = ["title": "\(val)", "value": ["ambient_light_lux": ambientLightLux, "white_light_lux": whiteLightLux]] + case SensorType.motion.rawValue: + let motionDic = ["gyroscope": gyroscope, "accelerometer": accelerometer] + tempDic = ["title": "\(val)", "value": motionDic] + case SensorType.led.rawValue: + tempDic = ["title": "\(val)", "value": led] + + default: + print("Have you done something new?") + } + //let tempDic = ["title": "\(val)", "value": valOfSensor] + sensorsData.append(tempDic) + } + if sensorsData.count > 0 { + print(sensorsData) + SILWiFiSensorsViewModelDelegate?.notifySensorsData(sensorsData: sensorsData) + }else{ + SILWiFiSensorsViewModelDelegate?.notifySensorsData(sensorsData: sensorsData) + } + } + + + func getAllSensor() { + APIRequest.sharedInstance.getApiCall(url: "all_sensors") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) +// if let temperatureDic: Dictionary = json as? Dictionary{ +// self.temperature = "\(temperatureDic["temperature_celcius"] ?? "")" +// } + } catch { + print(APIClientError) + } + }else{ + print(APIClientError) + } + } + } + + func getAllSensorData(){ + if self.countInt == 0 { + sensorConcurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + APIRequest.sharedInstance.getApiCall(url: "temperature") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let temperatureDic: Dictionary = json as? Dictionary{ + self.temperature = "\(temperatureDic["temperature_celcius"] ?? "")" + } + self.countInt += 1 + self.APIRequestdispatchGroup.leave() + } catch { + self.APIRequestdispatchGroup.leave() + print(APIClientError) + } + }else{ + self.APIRequestdispatchGroup.leave() + } + } + + } + sensorConcurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + APIRequest.sharedInstance.getApiCall(url: "humidity") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let humidityDic: Dictionary = json as? Dictionary{ + self.humidity = "\(humidityDic["humidity_percentage"] ?? "")" + } + self.countInt += 1 + self.APIRequestdispatchGroup.leave() + } catch { + self.APIRequestdispatchGroup.leave() + print(APIClientError) + } + }else{ + self.APIRequestdispatchGroup.leave() + } + } + } + + sensorConcurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + APIRequest.sharedInstance.getApiCall(url: "light") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let lightDic: Dictionary = json as? Dictionary{ + self.ambientLightLux = "\(lightDic["ambient_light_lux"] ?? "")" + self.whiteLightLux = "\(lightDic["white_light_lux"] ?? "")" + } + self.countInt += 1 + self.APIRequestdispatchGroup.leave() + } catch { + self.APIRequestdispatchGroup.leave() + print(APIClientError) + } + }else{ + self.APIRequestdispatchGroup.leave() + } + } + + } + + sensorConcurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + APIRequest.sharedInstance.getApiCall(url: "led") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let ledDic: Dictionary = json as? Dictionary{ + self.led = ledDic + } + self.countInt += 1 + self.APIRequestdispatchGroup.leave() + } catch { + self.APIRequestdispatchGroup.leave() + print(APIClientError) + } + }else{ + self.APIRequestdispatchGroup.leave() + } + } + } + sensorConcurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + APIRequest.sharedInstance.getApiCall(url: "gyroscope") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let gyroscopeDic: Dictionary = json as? Dictionary{ + self.gyroscope = gyroscopeDic + } + self.countInt += 1 + self.APIRequestdispatchGroup.leave() + } catch { + self.APIRequestdispatchGroup.leave() + print(APIClientError) + } + }else{ + self.APIRequestdispatchGroup.leave() + } + } + } + sensorConcurrentQueue.async(group: APIRequestdispatchGroup) { + self.APIRequestdispatchGroup.enter() + APIRequest.sharedInstance.getApiCall(url: "accelerometer") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let accelerometerDic: Dictionary = json as? Dictionary{ + self.accelerometer = accelerometerDic + } + self.countInt += 1 + self.APIRequestdispatchGroup.leave() + } catch { + self.APIRequestdispatchGroup.leave() + print(APIClientError) + } + }else{ + self.APIRequestdispatchGroup.leave() + } + } + } + } + + APIRequestdispatchGroup.notify(queue: .main) { + if self.countInt == 6 { + self.countInt = 0 + } + self.getSensors() + } + APIRequestdispatchGroup.wait() + print("All functions completed wait") + } + func getTemperatureData(completionBlock: @escaping completionBlock) { + APIRequest.sharedInstance.getApiCall(url: "temperature") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let temperatureDic: Dictionary = json as? Dictionary{ + completionBlock(temperatureDic, nil) + } + } catch { + completionBlock(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlock(nil, APIClientError) + } + } + } + func getHumidityData(completionBlock: @escaping completionBlock) { + APIRequest.sharedInstance.getApiCall(url: "humidity") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let temperatureDic: Dictionary = json as? Dictionary{ + completionBlock(temperatureDic, nil) + } + } catch { + completionBlock(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlock(nil, APIClientError) + } + } + } + func getLightData(completionBlock: @escaping completionBlock) { + APIRequest.sharedInstance.getApiCall(url: "light") { ReponsData, APIClientError in + if APIClientError == nil { + do { + let json = try JSONSerialization.jsonObject(with: ReponsData ?? Data(), options: []) + print(json) + if let temperatureDic: Dictionary = json as? Dictionary{ + completionBlock(temperatureDic, nil) + } + } catch { + completionBlock(nil, APIClientError) + print(APIClientError) + } + }else{ + completionBlock(nil, APIClientError) + } + } + + } + + func checkServerAvailability() { + let monitor = NWPathMonitor() + monitor.pathUpdateHandler = { path in + let usesWiFi = path.usesInterfaceType(.wifi) + let usesCellular = path.usesInterfaceType(.cellular) + if path.status == .satisfied { + print("Internet connection is available.") + // Perform actions when internet is available + } else { + print("Internet connection is not available.") + // Perform actions when internet is not available + } + } + let queue = DispatchQueue(label: "NetworkMonitor") + monitor.start(queue: queue) + + } + +}