From 4c904a8841998e2f7d7b8375eb4d2a61c5d5aca1 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 29 Sep 2023 10:11:04 +0200 Subject: [PATCH 1/3] :loud_sound: (LekaUpdater): Add logs for debug --- .../Version/UpdateProcessV130.swift | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift index 82ab045ac0..81ce1005b0 100644 --- a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift +++ b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift @@ -113,6 +113,7 @@ private class StateSettingFileExchangeState: GKState, StateEventProcessor { } globalRobotManager.robotPeripheral?.send(data, forCharacteristic: characteristic) + print("🔵 StateSettingFileExchangeState - did setFileExchangeState") } } @@ -154,6 +155,7 @@ private class StateSettingDestinationPath: GKState, StateEventProcessor { } globalRobotManager.robotPeripheral?.send(destinationPath.data(using: .utf8)!, forCharacteristic: characteristic) + print("🔵 StateSettingDestinationPath - did setDestinationPath") } } @@ -191,6 +193,7 @@ private class StateClearingFile: GKState, StateEventProcessor { } globalRobotManager.robotPeripheral?.send(data, forCharacteristic: characteristic) + print("🔵 StateClearingFile - did setClearPath") } } @@ -278,6 +281,7 @@ private class StateSendingFile: GKState, StateEventProcessor { progression.send(_progression) if _progression < 1.0 { sendNextPacket() + print("🔵 StateSendingFile - did sendNextPacket - \(_progression)") } else { process(event: .fileSent) } @@ -313,8 +317,10 @@ private class StateVerifyingFile: GKState, StateEventProcessor { override func didEnter(from previousState: GKState?) { if previousState is StateSettingDestinationPath { nextStateIsClearingFile = true + print("🔵 StateVerifyingFile - didEnter - previousState is StateSettingDestinationPath == true") } else { nextStateIsClearingFile = false + print("🔵 StateVerifyingFile - didEnter - previousState is StateSettingDestinationPath == false") } DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: startFileVerification) @@ -325,40 +331,55 @@ private class StateVerifyingFile: GKState, StateEventProcessor { } func process(event: UpdateEvent) { + print("🔵 StateVerifyingFile - process \(event)") switch event { case .fileVerificationReceived: if isFileValid { + print("🔵 StateVerifyingFile - process - case fileVerificationReceived - 1") self.stateMachine?.enter(StateApplyingUpdate.self) } else if nextStateIsClearingFile { + print("🔵 StateVerifyingFile - process - case fileVerificationReceived - 2") self.stateMachine?.enter(StateClearingFile.self) } else { + print("🔵 StateVerifyingFile - process - case fileVerificationReceived - 3") self.stateMachine?.enter(StateErrorFailedToVerifyFile.self) } case .robotDisconnected: + print("🔵 StateVerifyingFile - process - case robotDisconnected ") self.stateMachine?.enter(StateErrorRobotUnexpectedDisconnection.self) default: + print("🔵 StateVerifyingFile - process - default ") return } } private func startFileVerification() { + print("🔵 StateVerifyingFile - startFileVerification") subscribeActualSHA256Updates() + print("🔵 StateVerifyingFile - did subscribeActualSHA256Updates") readRequestSHA256() + print("🔵 StateVerifyingFile - did readRequestSHA256") } private func subscribeActualSHA256Updates() { globalRobotManager.$sha256 .receive(on: DispatchQueue.main) .sink { value in - guard let value = value else { return } + print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 1") + guard let value = value else { + print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 2") + return + } if value == self.lastValue { + print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 3") return } self.lastValue = value self.isFileValid = value == globalFirmwareManager.sha256 self.process(event: .fileVerificationReceived) + print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 4") } .store(in: &cancellables) } @@ -371,11 +392,13 @@ private class StateVerifyingFile: GKState, StateEventProcessor { ) .receive(on: DispatchQueue.main) .sink( - receiveCompletion: { _ in + receiveCompletion: { completion in // nothing to do + print("🔵 StateVerifyingFile - readRequestSHA256 - 1 - \(completion)") }, receiveValue: { data in // nothing to do + print("🔵 StateVerifyingFile - readRequestSHA256 - 2 - \(String(describing: data))") } ) .store(in: &cancellables) @@ -441,6 +464,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { } private func applyUpdate() { + print("🔵 StateApplyingUpdate - will applyUpdate") let applyValue = Data([1]) let characteristic = WriteOnlyCharacteristic( @@ -449,6 +473,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { ) globalRobotManager.robotPeripheral?.send(applyValue, forCharacteristic: characteristic) + print("🔵 StateApplyingUpdate - did applyUpdate") } } From 298880e04328c8d6d84a49a4d9ad65798cefdbae Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 29 Sep 2023 10:36:30 +0200 Subject: [PATCH 2/3] :construction: (WIP): Try to fix hanging --- .../Libs/UpdateProcess/Version/UpdateProcessV130.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift index 81ce1005b0..09e764ccd8 100644 --- a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift +++ b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift @@ -304,6 +304,7 @@ private class StateVerifyingFile: GKState, StateEventProcessor { private var cancellables: Set = [] private var isFileValid = false + private let kDefaultValue = "0000000000000000000000000000000000000000000000000000000000000000" private var lastValue = "0000000000000000000000000000000000000000000000000000000000000000" private var nextStateIsClearingFile = false @@ -371,10 +372,17 @@ private class StateVerifyingFile: GKState, StateEventProcessor { return } - if value == self.lastValue { + if value == self.kDefaultValue { print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 3") + self.process(event: .fileVerificationReceived) + return + } + + if value == self.lastValue { + print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 4") return } + self.lastValue = value self.isFileValid = value == globalFirmwareManager.sha256 From ba29cfc47cf907ff0a55fc51b9f1b2d3bc07ee20 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Fri, 29 Sep 2023 11:17:50 +0200 Subject: [PATCH 3/3] :construction: (WIP): Move process --- .../Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift index 09e764ccd8..c287f0bf47 100644 --- a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift +++ b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift @@ -374,12 +374,12 @@ private class StateVerifyingFile: GKState, StateEventProcessor { if value == self.kDefaultValue { print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 3") - self.process(event: .fileVerificationReceived) return } if value == self.lastValue { print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 4") + self.process(event: .fileVerificationReceived) return }