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

Question: how does UART Image Transfer sent multiple packets #59

Closed
ljunquera opened this issue Aug 9, 2023 · 1 comment
Closed

Question: how does UART Image Transfer sent multiple packets #59

ljunquera opened this issue Aug 9, 2023 · 1 comment

Comments

@ljunquera
Copy link

This is really informational. I'm new to this and needed a little help understanding how the UART Image Transfer sends multiple packets for the image. I followed the chain but don't see where it loops through the data to send.

ImageTransferModuleManager -> sendImage
ImageTransferModuleManager -> sendCommandWithCrc
ImageTransferModuleManager -> sendCommand
UartPacketManager -> sendEachPacketSequentially
BlePeripheral -> uartSendEachPacketSequentially
BlePeripheral -> uartSentPacket
BlePeripheral -> write

It seems like UartPacketManager -> sendEachPacketSequentially should do it but I only see:

    func sendEachPacketSequentially(blePeripheral: BlePeripheral, data: Data?, withResponseEveryPacketCount: Int, progress: ((Float)->Void)? = nil, completion: ((Error?) -> Void)? = nil) {
        sentBytes += Int64(data?.count ?? 0)
        blePeripheral.uartSendEachPacketSequentially(data: data, withResponseEveryPacketCount: withResponseEveryPacketCount, progress: progress, completion: completion)
    }

or

    func uartSendEachPacketSequentially(data: Data?, withResponseEveryPacketCount: Int,  progress: ((Float)->Void)? = nil, completion: ((Error?) -> Void)? = nil) {
        guard let data = data else { completion?(nil); return }
        
        guard let uartTxCharacteristic = uartTxCharacteristic else {//}, let uartTxCharacteristicWriteType = uartTxCharacteristicWriteType else {
            DLog("Command Error: characteristic no longer valid")
            completion?(PeripheralUartError.invalidCharacteristic)
            return
        }
        
        isSendSequentiallyCancelled = false
        uartSentPacket(data: data, offset: 0, uartTxCharacteristic: uartTxCharacteristic, withResponseEveryPacketCount: withResponseEveryPacketCount, numPacketsRemainingForDelay: withResponseEveryPacketCount, progress: progress, completion: completion)
    }

I'm not seeing where you loop through the image data.

@antonio-openroad
Copy link
Contributor

You are close to the answer. If you check inside uartSentPacket you will see that it splits the data and calls itself recursively until all the image data has been sent (or the process has been cancelled).

So to sent a new image:

  • uartSendEachPacketSequentially calls uartSentPacket the image data and a starting offset of 0.

  • uartSendPacket splits the data depending on the maximum transfer unit (MTU) negotiated with the peripheral and

calls write with that packet. When write finishes uartSendPacket calls itself recursively but with a new starting offset.

I hope this helps you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants