Skip to content
Merged
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
21 changes: 18 additions & 3 deletions flasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,24 @@ void Flasher::FileDownloaded() {
is_firmware_downloaded_ = true;
}

void Flasher::UpdateProgressBar(const quint64& sent_size, const quint64& firmware_size)
{
int progress_percentage = 0;
if (firmware_size != 0) {
progress_percentage = (100 * sent_size) / firmware_size;
}

if (last_progress_percentage_ != progress_percentage) {
last_progress_percentage_ = progress_percentage;
qInfo() << sent_size << "/" << firmware_size << "B, " << progress_percentage << "%";
emit UpdateProgressBarSignal(progress_percentage);
}
}

void Flasher::DownloadProgress(const qint64& bytes_received, const qint64& bytes_total) {
timer_.start();
emit UpdateProgressBar(bytes_received, bytes_total);
UpdateProgressBar(bytes_received, bytes_total);

}

void Flasher::LoopHandler() {
Expand Down Expand Up @@ -477,7 +492,7 @@ FlashingInfo Flasher::Flash() {
// Send file in packages
for (qint64 packet = 0; packet < num_of_packets; ++packet) {
const char *data_position = data_firmware + (packet * kPacketSize);
emit UpdateProgressBar((packet + 1U) * kPacketSize, firmware_size);
UpdateProgressBar((packet + 1U) * kPacketSize, firmware_size);
flashing_info.success = SendMessage(data_position, kPacketSize, kSerialTimeoutInMs);

if (!flashing_info.success) {
Expand All @@ -491,7 +506,7 @@ FlashingInfo Flasher::Flash() {
const qint64 rest_size = firmware_size % kPacketSize;

if (rest_size > 0) {
emit UpdateProgressBar(num_of_packets * kPacketSize + rest_size, firmware_size);
UpdateProgressBar(num_of_packets * kPacketSize + rest_size, firmware_size);
flashing_info.success = SendMessage(data_firmware + (num_of_packets * kPacketSize), rest_size, kSerialTimeoutInMs);

if (!flashing_info.success) {
Expand Down
15 changes: 11 additions & 4 deletions flasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,19 @@ class Flasher : public QObject {
*/
void TryToConnectConsole();

/*!
* \brief Update progress bar
* \param sent_size - Size that is sent
* \param firmware_size - Firmware size
*/
void UpdateProgressBar(const quint64& sent_size, const quint64& firmware_size);

signals:
/*!
* \brief UpdateProgressBar signal
* \param sent_size - Size that is sent
* \param firmware_size - Firmware size
* \brief Update progress bar signal
* \param progress_percentage - value for the update in percentage
*/
void UpdateProgressBar(const qint64& sent_size, const qint64& firmware_size);
void UpdateProgressBarSignal(const qint8& progress_percentage);

/*!
* \brief Clear progress signal
Expand Down Expand Up @@ -276,6 +282,7 @@ class Flasher : public QObject {
QFile config_file_; //!< Configuration file
QFile firmware_file_; //!< Firmware file
qint64 signature_size_{0}; //!< Firmware signature size
quint8 last_progress_percentage_{0}; //!< Last progress percentage
bool is_bootloader_ {false}; //!< Is bootloader detected flag
bool is_bootloader_expected_ {false}; //!< Is bootloader expected after board reset
bool is_read_protection_enabled_ {false}; //!< Is read protection enabled flag
Expand Down
10 changes: 2 additions & 8 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,9 @@ MainWindow::MainWindow(std::shared_ptr<flasher::Flasher> flasher) :
DisableAllButtons();
ClearProgress();

connect(flasher_.get(), &flasher::Flasher::UpdateProgressBar, this, [&] (const qint64& sent_size, const qint64& firmware_size) { // *NOPAD*
int progress_percentage = 0;
if (firmware_size != 0) {
progress_percentage = (100 * sent_size) / firmware_size;
}

connect(flasher_.get(), &flasher::Flasher::UpdateProgressBarSignal, this, [&] (const quint8& progress_percentage) { // *NOPAD*
ui_.progressBar->setValue(progress_percentage);
qInfo() << sent_size << "/" << firmware_size << "B, " << progress_percentage << "%";
});
}, Qt::DirectConnection);

connect(flasher_.get(), &flasher::Flasher::ClearProgress, this, &MainWindow::ClearProgress);

Expand Down