* @brief Sends @a data to the connected device using the current send options. */
| 513 | * @brief Sends @a data to the connected device using the current send options. |
| 514 | */ |
| 515 | void Console::Handler::send(const QString& data) |
| 516 | { |
| 517 | if (!IO::ConnectionManager::instance().isConnected()) |
| 518 | return; |
| 519 | |
| 520 | if (!data.isEmpty()) |
| 521 | addToHistory(data); |
| 522 | |
| 523 | QByteArray bin; |
| 524 | if (dataMode() == DataMode::DataHexadecimal) |
| 525 | bin = SerialStudio::hexToBytes(data); |
| 526 | else |
| 527 | bin = SerialStudio::encodeText(SerialStudio::resolveEscapeSequences(data), m_encoding); |
| 528 | |
| 529 | switch (lineEnding()) { |
| 530 | case LineEnding::NoLineEnding: |
| 531 | break; |
| 532 | case LineEnding::NewLine: |
| 533 | bin.append('\n'); |
| 534 | break; |
| 535 | case LineEnding::CarriageReturn: |
| 536 | bin.append('\r'); |
| 537 | break; |
| 538 | case LineEnding::BothNewLineAndCarriageReturn: |
| 539 | bin.append('\r'); |
| 540 | bin.append('\n'); |
| 541 | break; |
| 542 | } |
| 543 | |
| 544 | const auto checksums = IO::availableChecksums(); |
| 545 | if (m_checksumMethod >= 0 && m_checksumMethod < checksums.count()) { |
| 546 | const auto checksumName = checksums.at(m_checksumMethod); |
| 547 | auto checksum = IO::checksum(checksumName, bin); |
| 548 | if (!checksum.isEmpty()) |
| 549 | bin.append(checksum); |
| 550 | } |
| 551 | |
| 552 | if (!bin.isEmpty()) { |
| 553 | if (m_currentDeviceId >= 0) |
| 554 | (void)IO::ConnectionManager::instance().writeDataToDevice(m_currentDeviceId, bin); |
| 555 | else |
| 556 | (void)IO::ConnectionManager::instance().writeData(bin); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | //-------------------------------------------------------------------------------------------------- |
| 561 | // Settings modification slots |