diff --git a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV100.swift b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV100.swift index 2846b1b6dd..be5099f6cc 100644 --- a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV100.swift +++ b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV100.swift @@ -261,8 +261,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { } override func didEnter(from _: GKState?) { - DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.setMajorMinorRevision) - DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: self.applyUpdate) + self.setMajor() } override func willExit(to _: GKState) { @@ -282,30 +281,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { private var cancellables: Set = [] - private func setMajorMinorRevision() { + private func setMajor() { let majorData = Data([globalFirmwareManager.major]) let majorCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMajor, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.setMinor ) Robot.shared.connectedPeripheral?.send(majorData, forCharacteristic: majorCharacteristic) + } + private func setMinor() { let minorData = Data([globalFirmwareManager.minor]) let minorCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMinor, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.setRevision ) Robot.shared.connectedPeripheral?.send(minorData, forCharacteristic: minorCharacteristic) + } + private func setRevision() { let revisionData = globalFirmwareManager.revision.data let revisionCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionRevision, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.applyUpdate ) Robot.shared.connectedPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic) diff --git a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift index e90b08e507..5e9d4deeef 100644 --- a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift +++ b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV130.swift @@ -335,8 +335,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { } override func didEnter(from _: GKState?) { - DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.setMajorMinorRevision) - DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: self.applyUpdate) + self.setMajor() } override func willExit(to _: GKState) { @@ -356,34 +355,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { private var cancellables: Set = [] - private func setMajorMinorRevision() { + private func setMajor() { let majorData = Data([globalFirmwareManager.major]) let majorCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMajor, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.setMinor ) Robot.shared.connectedPeripheral?.send(majorData, forCharacteristic: majorCharacteristic) + } - sleep(1) - + private func setMinor() { let minorData = Data([globalFirmwareManager.minor]) let minorCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMinor, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.setRevision ) Robot.shared.connectedPeripheral?.send(minorData, forCharacteristic: minorCharacteristic) + } - sleep(1) - + private func setRevision() { let revisionData = globalFirmwareManager.revision.data let revisionCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionRevision, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.applyUpdate ) Robot.shared.connectedPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic) diff --git a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV150.swift b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV150.swift index 513511e035..c79d7e72cb 100644 --- a/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV150.swift +++ b/Apps/LekaUpdater/Sources/Libs/UpdateProcess/Version/UpdateProcessV150.swift @@ -95,7 +95,7 @@ private class StateSettingFileExchangeState: GKState, StateEventProcessor { } override func didEnter(from _: GKState?) { - DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.setFileExchangeState) + self.setFileExchangeState() } func process(event: UpdateEvent) { @@ -118,6 +118,7 @@ private class StateSettingFileExchangeState: GKState, StateEventProcessor { characteristicUUID: BLESpecs.FileExchange.Characteristics.setState, serviceUUID: BLESpecs.FileExchange.service, onWrite: { + sleep(1) self.process(event: .fileExchangeStateSet) } ) @@ -136,7 +137,7 @@ private class StateSettingDestinationPath: GKState, StateEventProcessor { } override func didEnter(from _: GKState?) { - DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: self.setDestinationPath) + self.setDestinationPath() } func process(event: UpdateEvent) { @@ -181,7 +182,7 @@ private class StateClearingFile: GKState, StateEventProcessor { } override func didEnter(from _: GKState?) { - DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.setClearPath) + self.setClearPath() } func process(event: UpdateEvent) { @@ -241,7 +242,7 @@ private class StateSendingFile: GKState, StateEventProcessor { } override func didEnter(from _: GKState?) { - DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.sendFile) + self.sendFile() } override func willExit(to _: GKState) { @@ -264,7 +265,7 @@ private class StateSendingFile: GKState, StateEventProcessor { private var cancellables: Set = [] - private let maximumPacketSize: Int = 61 + private let maximumPacketSize: Int = 182 // MTU(max) - 3 private var currentPacket: Int = 0 private var expectedCompletePackets: Int @@ -274,7 +275,7 @@ private class StateSendingFile: GKState, StateEventProcessor { serviceUUID: BLESpecs.FileExchange.service, onWrite: { self.currentPacket += 1 - DispatchQueue.main.asyncAfter(deadline: .now() + 0.04, execute: self.tryToSendNextPacket) + self.tryToSendNextPacket() } ) @@ -335,8 +336,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { } override func didEnter(from _: GKState?) { - DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.setMajorMinorRevision) - DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: self.applyUpdate) + self.setMajor() } override func willExit(to _: GKState) { @@ -356,34 +356,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor { private var cancellables: Set = [] - private func setMajorMinorRevision() { + private func setMajor() { let majorData = Data([globalFirmwareManager.major]) let majorCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMajor, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.setMinor ) Robot.shared.connectedPeripheral?.send(majorData, forCharacteristic: majorCharacteristic) + } - sleep(1) - + private func setMinor() { let minorData = Data([globalFirmwareManager.minor]) let minorCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMinor, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.setRevision ) Robot.shared.connectedPeripheral?.send(minorData, forCharacteristic: minorCharacteristic) + } - sleep(1) - + private func setRevision() { let revisionData = globalFirmwareManager.revision.data let revisionCharacteristic = CharacteristicModelWriteOnly( characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionRevision, - serviceUUID: BLESpecs.FirmwareUpdate.service + serviceUUID: BLESpecs.FirmwareUpdate.service, + onWrite: self.applyUpdate ) Robot.shared.connectedPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic)