* @brief Reads the next block from the file and sends it. */
| 285 | * @brief Reads the next block from the file and sends it. |
| 286 | */ |
| 287 | void IO::Protocols::XMODEM::sendBlock() |
| 288 | { |
| 289 | Q_ASSERT(m_file.isOpen()); |
| 290 | Q_ASSERT(m_state == State::SendingBlocks); |
| 291 | |
| 292 | m_lastBlockStart = m_file.pos(); |
| 293 | |
| 294 | int blockSize = m_use1K ? 1024 : 128; |
| 295 | QByteArray data = m_file.read(blockSize); |
| 296 | if (data.isEmpty()) { |
| 297 | sendEOT(); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | if (data.size() > blockSize) [[unlikely]] { |
| 302 | Q_EMIT finished(false, tr("File read returned more data than requested")); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | m_lastBlockBytes = data.size(); |
| 307 | |
| 308 | while (data.size() < blockSize) |
| 309 | data.append(static_cast<char>(0x1A)); |
| 310 | |
| 311 | QByteArray packet = buildBlock(data, m_blockNumber); |
| 312 | Q_EMIT writeRequested(packet); |
| 313 | |
| 314 | m_bytesSent = qMin(m_bytesSent + m_lastBlockBytes, m_fileSize); |
| 315 | Q_EMIT progressChanged(m_bytesSent, m_fileSize); |
| 316 | Q_EMIT statusMessage(tr("Sending block %1 (%2 bytes)") |
| 317 | .arg(QString::number(m_blockNumber), QString::number(m_bytesSent))); |
| 318 | m_state = State::WaitingForAck; |
| 319 | m_timeoutTimer.start(m_timeoutMs); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * @brief Sends the End-of-Transmission marker. |