Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ladislas/bugfix/LekaUpdater epxlore hanging bug #330

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
}

globalRobotManager.robotPeripheral?.send(data, forCharacteristic: characteristic)
print("🔵 StateSettingFileExchangeState - did setFileExchangeState")
}
}

Expand Down Expand Up @@ -154,6 +155,7 @@
}

globalRobotManager.robotPeripheral?.send(destinationPath.data(using: .utf8)!, forCharacteristic: characteristic)
print("🔵 StateSettingDestinationPath - did setDestinationPath")
}
}

Expand Down Expand Up @@ -191,6 +193,7 @@
}

globalRobotManager.robotPeripheral?.send(data, forCharacteristic: characteristic)
print("🔵 StateClearingFile - did setClearPath")
}
}

Expand Down Expand Up @@ -278,6 +281,7 @@
progression.send(_progression)
if _progression < 1.0 {
sendNextPacket()
print("🔵 StateSendingFile - did sendNextPacket - \(_progression)")
} else {
process(event: .fileSent)
}
Expand All @@ -300,6 +304,7 @@
private var cancellables: Set<AnyCancellable> = []

private var isFileValid = false
private let kDefaultValue = "0000000000000000000000000000000000000000000000000000000000000000"
private var lastValue = "0000000000000000000000000000000000000000000000000000000000000000"

private var nextStateIsClearingFile = false
Expand All @@ -313,8 +318,10 @@
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)
Expand All @@ -325,40 +332,62 @@
}

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.kDefaultValue {
print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 3")
return
}

if value == self.lastValue {
print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 4")
self.process(event: .fileVerificationReceived)
return
}

self.lastValue = value

self.isFileValid = value == globalFirmwareManager.sha256
self.process(event: .fileVerificationReceived)
print("🔵 StateVerifyingFile - subscribeActualSHA256Updates - 4")
}
.store(in: &cancellables)
}
Expand All @@ -371,11 +400,13 @@
)
.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)
Expand Down Expand Up @@ -441,6 +472,7 @@
}

private func applyUpdate() {
print("🔵 StateApplyingUpdate - will applyUpdate")
let applyValue = Data([1])

let characteristic = WriteOnlyCharacteristic(
Expand All @@ -449,6 +481,7 @@
)

globalRobotManager.robotPeripheral?.send(applyValue, forCharacteristic: characteristic)
print("🔵 StateApplyingUpdate - did applyUpdate")
}
}

Expand Down Expand Up @@ -627,7 +660,7 @@
case is StateErrorRobotUnexpectedDisconnection:
currentStage.send(completion: .failure(.robotUnexpectedDisconnection))
default:
currentStage.send(completion: .failure(.unknown))

Check failure on line 663 in Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift

View workflow job for this annotation

GitHub Actions / lint

File should contain 400 lines or less: currently contains 663 (file_length)
}
}

Expand Down
Loading