* @brief Processes one byte of an incoming binary header (ZDLE-decoded). */
| 317 | * @brief Processes one byte of an incoming binary header (ZDLE-decoded). |
| 318 | */ |
| 319 | void IO::Protocols::ZMODEM::processBinByte(quint8 ch) |
| 320 | { |
| 321 | static constexpr int kMaxBinHeaderBytes = 128; |
| 322 | |
| 323 | if (m_headerBuf.size() >= kMaxBinHeaderBytes) [[unlikely]] { |
| 324 | m_parseState = ParseState::Idle; |
| 325 | m_headerBuf.clear(); |
| 326 | m_zdleEscape = false; |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | if (m_zdleEscape) { |
| 331 | m_headerBuf.append(static_cast<char>(ch ^ 0x40)); |
| 332 | m_zdleEscape = false; |
| 333 | } else if (ch == kZDLE) { |
| 334 | m_zdleEscape = true; |
| 335 | return; |
| 336 | } else { |
| 337 | m_headerBuf.append(static_cast<char>(ch)); |
| 338 | } |
| 339 | |
| 340 | if (m_headerBuf.size() < m_headerBytesExpected) |
| 341 | return; |
| 342 | |
| 343 | quint8 type = static_cast<quint8>(m_headerBuf[0]); |
| 344 | quint32 arg = static_cast<quint32>(static_cast<quint8>(m_headerBuf[1])) |
| 345 | | (static_cast<quint32>(static_cast<quint8>(m_headerBuf[2])) << 8) |
| 346 | | (static_cast<quint32>(static_cast<quint8>(m_headerBuf[3])) << 16) |
| 347 | | (static_cast<quint32>(static_cast<quint8>(m_headerBuf[4])) << 24); |
| 348 | |
| 349 | parseReceivedHeader(type, arg); |
| 350 | m_parseState = ParseState::Idle; |
| 351 | } |
| 352 | |
| 353 | //-------------------------------------------------------------------------------------------------- |
| 354 | // Configuration |