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

Yann/feature/ble/improve sending speed #596

Closed
Show file tree
Hide file tree
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 @@ -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) {
Expand All @@ -282,30 +281,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {

private var cancellables: Set<AnyCancellable> = []

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -356,34 +355,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {

private var cancellables: Set<AnyCancellable> = []

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
)
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -264,7 +265,7 @@ private class StateSendingFile: GKState, StateEventProcessor {

private var cancellables: Set<AnyCancellable> = []

private let maximumPacketSize: Int = 61
private let maximumPacketSize: Int = 182 // MTU(max) - 3

private var currentPacket: Int = 0
private var expectedCompletePackets: Int
Expand All @@ -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()
}
)

Expand Down Expand Up @@ -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) {
Expand All @@ -356,34 +356,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {

private var cancellables: Set<AnyCancellable> = []

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)
Expand Down
Loading