Mercurial > public > ostc_companion
changeset 8:21ce6187d32e
Minor changes done by automatic style checker
| author | Ideenmodellierer |
|---|---|
| date | Mon, 12 Jan 2026 13:51:17 +0000 |
| parents | 0969ef86c42d |
| children | 971b9fd4cd30 |
| files | HexFile.cpp HexFile.h MainWindow.cpp MainWindow.h MainWindow.ui OSTC2Operations.cpp OSTC2Operations.h OSTC2cOperations.cpp OSTC2cOperations.h OSTC3Operations.cpp OSTC3Operations.h OSTC3pOperations.cpp OSTC3pOperations.h OSTCFrogOperations.cpp OSTCFrogOperations.h OSTCSportOperations.cpp OSTCSportOperations.h OSTC_CR_Operations.cpp OSTC_CR_Operations.h Settings.ui SettingsDialog.cpp SettingsDialog.h editlogdialog.cpp editlogdialog.h main.cpp o3pack.cpp |
| diffstat | 26 files changed, 1006 insertions(+), 1122 deletions(-) [+] |
line wrap: on
line diff
--- a/HexFile.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/HexFile.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -53,16 +53,19 @@ /////////////////////////////////////////////////////////////////////////////// HexFile::HexFile() -: _memSize(0), + : _memSize(0) + , #ifdef FROG_MASTER - _baseAddress(0), + _baseAddress(0) + , #endif - _buffer(0) + _buffer(0) {} HexFile::~HexFile() { - delete[] _buffer; _buffer = 0; + delete[] _buffer; + _buffer = 0; } /////////////////////////////////////////////////////////////////////////////// @@ -79,8 +82,8 @@ bool HexFile::sqwiz(size_t newMemSize) { - if( newMemSize >= _memSize ) { - LOG_THROW( "Squiz failed" ); + if (newMemSize >= _memSize) { + LOG_THROW("Squiz failed"); } _memSize = newMemSize; return true; @@ -93,65 +96,61 @@ void HexFile::readLine() { QByteArray line = _file.readLine(); - if( line[0] != ':' ) - LOG_THROW( "Bad HEX format" ); + if (line[0] != ':') + LOG_THROW("Bad HEX format"); unsigned char checksum = 0; bool ok = true; - for(int i=1; ok && i<line.length(); i+=2) { - if( line[i]=='\r' || line[i]=='\n' ) + for (int i = 1; ok && i < line.length(); i += 2) { + if (line[i] == '\r' || line[i] == '\n') break; - checksum += line.mid(i,2).toInt(&ok,16); + checksum += line.mid(i, 2).toInt(&ok, 16); } - if( ! ok ) - LOG_THROW( "Bad HEX header" ); - if( checksum != 0 ) - LOG_THROW( "Bad HEX checksum" ); + if (!ok) + LOG_THROW("Bad HEX header"); + if (checksum != 0) + LOG_THROW("Bad HEX checksum"); - int len = line.mid(1,2).toInt(0, 16); - int addr = line.mid(3,2).toInt(0, 16) << 8 - | line.mid(5,2).toInt(0, 16); - int type = line.mid(7,2).toInt(0, 16); + int len = line.mid(1, 2).toInt(0, 16); + int addr = line.mid(3, 2).toInt(0, 16) << 8 | line.mid(5, 2).toInt(0, 16); + int type = line.mid(7, 2).toInt(0, 16); - switch( type ) - { + switch (type) { case 00: //---- Data record ---------------------------------------------- - if( _baseAddress == 0x300000 ) // Skip configuration bits. + if (_baseAddress == 0x300000) // Skip configuration bits. return; - if( _baseAddress == 0xF00000 ) // Skip internal prom reset. + if (_baseAddress == 0xF00000) // Skip internal prom reset. return; - for(int i=0; i<len; i++, ++addr) - { + for (int i = 0; i < len; i++, ++addr) { size_t a = _baseAddress + addr; - if( a >= _memSize ) - LOG_THROW( "BAD HEX address" ); + if (a >= _memSize) + LOG_THROW("BAD HEX address"); - if( _buffer[a] != 0xFF ) - LOG_THROW( "Double write" ); + if (_buffer[a] != 0xFF) + LOG_THROW("Double write"); - _buffer[a] = line.mid(9+i*2,2).toInt(&ok,16); - if( !ok ) - LOG_THROW( "Bad HEX byte" ); + _buffer[a] = line.mid(9 + i * 2, 2).toInt(&ok, 16); + if (!ok) + LOG_THROW("Bad HEX byte"); bytes++; } break; - case 01: //---- END OF FILE record --------------------------------------- + case 01: //---- END OF FILE record --------------------------------------- _file.seek(-1); // Force to end of file. break; case 02: //---- Segment address record ----------------------------------- - if( len != 2 || addr != 0 ) - LOG_THROW( "Bad HEX Segment Address record" ); - _baseAddress = line.mid(9,4).toInt(0,16) << 4; + if (len != 2 || addr != 0) + LOG_THROW("Bad HEX Segment Address record"); + _baseAddress = line.mid(9, 4).toInt(0, 16) << 4; break; case 04: //---- Extended Linear Address Record --------------------------- - if( len != 2 || addr != 0 ) - LOG_THROW( "Bad HEX Extended Linear Address Record" ); - _baseAddress = line.mid( 9,2).toInt(0,16) << 20 - | line.mid(11,2).toInt(0,16) << 16; + if (len != 2 || addr != 0) + LOG_THROW("Bad HEX Extended Linear Address Record"); + _baseAddress = line.mid(9, 2).toInt(0, 16) << 20 | line.mid(11, 2).toInt(0, 16) << 16; break; default: @@ -161,17 +160,16 @@ /////////////////////////////////////////////////////////////////////////////// -void HexFile::load(const QString& fileName) +void HexFile::load(const QString &fileName) { Q_ASSERT(_buffer); _file.setFileName(fileName); - if( ! _file.open(QIODevice::ReadOnly) ) + if (!_file.open(QIODevice::ReadOnly)) LOG_THROW("Can't open HEX file"); bytes = 0; - while( ! _file.atEnd() ) - { + while (!_file.atEnd()) { PROGRESS(_file.pos(), _file.size()); readLine(); } @@ -179,13 +177,13 @@ _file.close(); - LOG_TRACE( int(bytes/1024.0f) << "KB loaded (" - << int(bytes * 100.0f / _memSize) << "% of firmware area)."); + LOG_TRACE(int(bytes / 1024.0f) + << "KB loaded (" << int(bytes * 100.0f / _memSize) << "% of firmware area)."); } /////////////////////////////////////////////////////////////////////////////// -const unsigned char* HexFile::data() const +const unsigned char *HexFile::data() const { Q_ASSERT(_buffer); return _buffer; @@ -199,27 +197,26 @@ unsigned short low = 0; unsigned short high = 0; - for(size_t i=0; i < _memSize; ++i) - { - low += _buffer[i]; + for (size_t i = 0; i < _memSize; ++i) { + low += _buffer[i]; high += low; } - return (((unsigned int)high) << 16) + low; + return (((unsigned int) high) << 16) + low; } /////////////////////////////////////////////////////////////////////////////// #ifndef FROG_MASTER -void HexFile::saveEncrypted(const QString&, byte [16]) +void HexFile::saveEncrypted(const QString &, byte[16]) { - LOG_THROW( "No encryption" ); + LOG_THROW("No encryption"); } #else -void HexFile::saveEncrypted(const QString& fileName, byte secretKey[16]) +void HexFile::saveEncrypted(const QString &fileName, byte secretKey[16]) { _file.setFileName(fileName); - if( ! _file.open(QIODevice::WriteOnly|QIODevice::Truncate) ) - LOG_THROW( "Can't save to encrypted file" ); + if (!_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) + LOG_THROW("Can't save to encrypted file"); QTextStream out(&_file); out.setIntegerBase(16); @@ -227,18 +224,16 @@ //---- Generates 128 bits of random initialization vector ---------------- Rijndael::CFB<128>::IV iv = {0}; - Rijndael::ECB<128> PRNG; PRNG.setupEncrypt(secretKey); - for(int i=0; i<sizeof iv; ++i) + Rijndael::ECB<128> PRNG; + PRNG.setupEncrypt(secretKey); + for (int i = 0; i < sizeof iv; ++i) iv[i] = PRNG.get_random() % 256; - size_t bytes = 0; // encrypted fake address - for(int i0 = 0; i0 < sizeof iv; i0+=0x10) - { - out << qSetFieldWidth(1) << ":" - << qSetFieldWidth(6) << bytes - << qSetFieldWidth(2); - for(int i=0; i<0x10; i++) - out << iv[i0+i]; + size_t bytes = 0; // encrypted fake address + for (int i0 = 0; i0 < sizeof iv; i0 += 0x10) { + out << qSetFieldWidth(1) << ":" << qSetFieldWidth(6) << bytes << qSetFieldWidth(2); + for (int i = 0; i < 0x10; i++) + out << iv[i0 + i]; out << qSetFieldWidth(1) << "\n"; bytes += 0x10; } @@ -250,15 +245,12 @@ PROGRESS(0, _memSize); byte encrypted[32]; - for(size_t addr = 0; addr < _memSize; addr += 0x10) - { + for (size_t addr = 0; addr < _memSize; addr += 0x10) { PROGRESS(addr, _memSize); enc.encrypt(_buffer + addr, encrypted); - out << qSetFieldWidth(1) << ":" - << qSetFieldWidth(6) << bytes - << qSetFieldWidth(2); - for(int i=0; i<16; i++) + out << qSetFieldWidth(1) << ":" << qSetFieldWidth(6) << bytes << qSetFieldWidth(2); + for (int i = 0; i < 16; i++) out << encrypted[i]; out << qSetFieldWidth(1) << "\n"; bytes += 16; @@ -266,18 +258,11 @@ //---- Process data ------------------------------------------------------ unsigned int sum = checksum(); // 33.29.BD.1D - out << qSetFieldWidth(1) << ":" - << qSetFieldWidth(6) << bytes - << qSetFieldWidth(2) - << ((sum ) & 0xff) - << ((sum>> 8) & 0xff) - << ((sum>>16) & 0xff) - << ((sum>>24) & 0xff) - << qSetFieldWidth(1) << "\n" - ; + out << qSetFieldWidth(1) << ":" << qSetFieldWidth(6) << bytes << qSetFieldWidth(2) + << ((sum) & 0xff) << ((sum >> 8) & 0xff) << ((sum >> 16) & 0xff) << ((sum >> 24) & 0xff) + << qSetFieldWidth(1) << "\n"; - qDebug().nospace() << int( bytes/1024.0f) << "KB saved into " - << fileName.section('/', -1); + qDebug().nospace() << int(bytes / 1024.0f) << "KB saved into " << fileName.section('/', -1); PROGRESS_RESET(); } @@ -285,33 +270,32 @@ /////////////////////////////////////////////////////////////////////////////// -void HexFile::loadEncrypted(const QString& fileName, unsigned char secretKey[16]) +void HexFile::loadEncrypted(const QString &fileName, unsigned char secretKey[16]) { Q_ASSERT(_buffer); _file.setFileName(fileName); - if( ! _file.open(QIODevice::ReadOnly) ) - LOG_THROW( "Cannot open HEX file " << fileName ); + if (!_file.open(QIODevice::ReadOnly)) + LOG_THROW("Cannot open HEX file " << fileName); //---- Read 128 bits of initialization vector ---------------------------- Rijndael::CFB<128>::IV iv = {0}; unsigned int bytes = 0; bool ok = true; - for(size_t i0 = 0; i0 < sizeof iv; i0+=0x10) - { + for (size_t i0 = 0; i0 < sizeof iv; i0 += 0x10) { QByteArray line = _file.readLine(); - if( line[0] != ':' ) - LOG_THROW( "Bad HEX line" ); + if (line[0] != ':') + LOG_THROW("Bad HEX line"); - unsigned int readAddr = line.mid(1,6).toInt(&ok, 16); - if( !ok || readAddr != bytes ) - LOG_THROW( "Bad HEX address" ); + unsigned int readAddr = line.mid(1, 6).toInt(&ok, 16); + if (!ok || readAddr != bytes) + LOG_THROW("Bad HEX address"); - for(int i=0; i<0x10; i++) - iv[i0+i] = line.mid(2*i+7,2).toInt(&ok, 16); - if( !ok ) - LOG_THROW( "Bad HEX file format" ); + for (int i = 0; i < 0x10; i++) + iv[i0 + i] = line.mid(2 * i + 7, 2).toInt(&ok, 16); + if (!ok) + LOG_THROW("Bad HEX file format"); bytes += 0x10; } @@ -320,39 +304,37 @@ Rijndael::CFB<128> dec(secretKey, iv); //---- Process data ------------------------------------------------------ - PROGRESS(0, (int)_memSize); + PROGRESS(0, (int) _memSize); Rijndael::Block encrypted; - for(size_t addr = 0; addr < _memSize; addr += 0x10) - { - PROGRESS((int)addr, (int)_memSize); + for (size_t addr = 0; addr < _memSize; addr += 0x10) { + PROGRESS((int) addr, (int) _memSize); QByteArray line = _file.readLine(); - if( line[0] != ':' ) - LOG_THROW( "Bad HEX line" ); + if (line[0] != ':') + LOG_THROW("Bad HEX line"); - unsigned int readAddr = line.mid(1,6).toInt(&ok, 16); - if( !ok || readAddr != bytes ) - LOG_THROW( "Bad HEX address" ); + unsigned int readAddr = line.mid(1, 6).toInt(&ok, 16); + if (!ok || readAddr != bytes) + LOG_THROW("Bad HEX address"); - for(int i=0; i<0x10; i++) - encrypted[i] = line.mid(2*i+7,2).toInt(&ok, 16); - if( !ok ) - LOG_THROW( "Bad HEX file format" ); + for (int i = 0; i < 0x10; i++) + encrypted[i] = line.mid(2 * i + 7, 2).toInt(&ok, 16); + if (!ok) + LOG_THROW("Bad HEX file format"); bytes += 0x10; - dec.decrypt(encrypted, *(Rijndael::Block*)(_buffer+addr)); + dec.decrypt(encrypted, *(Rijndael::Block *) (_buffer + addr)); } QByteArray line = _file.readLine(); - if( bytes != (unsigned int)line.mid(1,6).toInt(&ok, 16) || !ok ) - LOG_THROW( "Bad HEX address" ); + if (bytes != (unsigned int) line.mid(1, 6).toInt(&ok, 16) || !ok) + LOG_THROW("Bad HEX address"); - unsigned int sum = line.mid( 7,2).toInt(&ok, 16) - + (line.mid( 9,2).toInt(&ok, 16) << 8 ) - + (line.mid(11,2).toInt(&ok, 16) << 16) - + (line.mid(13,2).toInt(&ok, 16) << 24); - if( sum != checksum() ) - LOG_THROW( "Bad HEX checksum" ); + unsigned int sum = line.mid(7, 2).toInt(&ok, 16) + (line.mid(9, 2).toInt(&ok, 16) << 8) + + (line.mid(11, 2).toInt(&ok, 16) << 16) + + (line.mid(13, 2).toInt(&ok, 16) << 24); + if (sum != checksum()) + LOG_THROW("Bad HEX checksum"); PROGRESS_RESET(); }
--- a/HexFile.h Mon Jan 12 13:49:16 2026 +0000 +++ b/HexFile.h Mon Jan 12 13:51:17 2026 +0000 @@ -39,8 +39,8 @@ // 2014-07-07 : [jDG] Cleanups for Subsurface google-summer-of-code. // 2014-07-25 : [jDG] BSD 2-clause license. +#include <QFile> #include <QtGlobal> -#include <QFile> class QProgressBar; @@ -50,13 +50,13 @@ /// \note that OSTC3 firmware is NOT distributed in Intel HEX format, /// but is first flatened, then encrypted, then written back /// in a similar looking format. -class HexFile +class HexFile { - QFile _file; - size_t _memSize; - size_t _baseAddress; ///< Base for extended address modes. + QFile _file; + size_t _memSize; + size_t _baseAddress; ///< Base for extended address modes. - unsigned char* _buffer; + unsigned char *_buffer; /// \brief Read and interpret on line of the HEX file. void readLine(); @@ -72,10 +72,10 @@ /// \brief Load the .hex file into the internal buffer. /// \return TRUE is ok, FAlSE if some error occurs. - void load(const QString& fileName); + void load(const QString &fileName); /// \brief Return a pointer to the loaded data. - const unsigned char* data() const; + const unsigned char *data() const; /// \brief Returns the 4 bytes checksum of the loaded data. /// @@ -85,8 +85,8 @@ unsigned int checksum() const; /// \brief Save to encrypted HEX file. - void saveEncrypted(const QString& fileName, unsigned char secretKey[16]); + void saveEncrypted(const QString &fileName, unsigned char secretKey[16]); /// \brief Reload encrypted HEX file. - void loadEncrypted(const QString& fileName, unsigned char secretKey[16]); + void loadEncrypted(const QString &fileName, unsigned char secretKey[16]); };
--- a/MainWindow.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/MainWindow.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -39,11 +39,10 @@ #include "Utils/LogAppender.h" #include "Utils/ProgressEvent.h" +#include "SettingsDialog.h" +#include "editlogdialog.h" #include "ui_MainWindow.h" -#include "SettingsDialog.h" -#include "editLogDialog.h" -#include <QString> #include <QDateTime> #include <QFileDialog> #include <QInputDialog> @@ -53,59 +52,53 @@ #include <QPlainTextEdit> #include <QProgressBar> #include <QSettings> +#include <QString> #include <QTextCursor> -#include "OSTCFrogOperations.h" +#include "OSTC2Operations.h" #include "OSTC2cOperations.h" -#include "OSTC2Operations.h" -#include "OSTCSportOperations.h" #include "OSTC3Operations.h" #include "OSTC3pOperations.h" #include "OSTC4Operations.h" +#include "OSTCFrogOperations.h" +#include "OSTCSportOperations.h" #include "OSTC_CR_Operations.h" -extern QSettings* settings; +extern QSettings *settings; ////////////////////////////////////////////////////////////////////////////// -class EXPORT LogWindow - : public LogAppender +class EXPORT LogWindow : public LogAppender { - MainWindow* _window; + MainWindow *_window; //---- The <<printing>> function ----------------------------------------- - void operator()(const Log &log) override { + void operator()(const Log &log) override + { QString message = log.message; - message.replace("< ", "< ") - .replace(" >", " >"); - if( ! message.isEmpty() ) + message.replace("< ", "< ").replace(" >", " >"); + if (!message.isEmpty()) _window->statusMessage(message); } //---- Reimplementing mandatory methds ----------------------------------- - const char *type() const override { - return "File"; - } - Log::Level defaultMinLevel() const override { - return Log::LEVEL_INFO; - } - const char* defaultFormat() const override { - return "%m"; - } + const char *type() const override { return "File"; } + Log::Level defaultMinLevel() const override { return Log::LEVEL_INFO; } + const char *defaultFormat() const override { return "%m"; } public: - LogWindow(MainWindow* window) - : LogAppender(0, NULL), - _window(window) + LogWindow(MainWindow *window) + : LogAppender(0, NULL) + , _window(window) {} }; ////////////////////////////////////////////////////////////////////////////// MainWindow::MainWindow() - : QMainWindow(NULL), - _ui(new Ui::MainWindow), - _op(0) + : QMainWindow(NULL) + , _ui(new Ui::MainWindow) + , _op(0) { // Connect the Log system to this window: new LogWindow(this); @@ -119,15 +112,15 @@ // Auto-select last model: QString model = settings->value("Interface/computerType").toString(); - _ui->computerType->setCurrentIndex(0); + _ui->computerType->setCurrentIndex(0); - if( model == "ostc2c" ) + if (model == "ostc2c") _ui->computerType->setCurrentIndex(0); - else if( model == "hwOS (Bluetooth)" ) + else if (model == "hwOS (Bluetooth)") _ui->computerType->setCurrentIndex(1); - else if( model == "hwOS (USB)" ) + else if (model == "hwOS (USB)") _ui->computerType->setCurrentIndex(2); - else if( model == "ostc4" ) + else if (model == "ostc4") _ui->computerType->setCurrentIndex(3); changeTypeSlot(); @@ -135,21 +128,18 @@ #ifdef Q_OS_MAC { QMenuBar *menuBar = new QMenuBar(this); - QMenu* help = menuBar->addMenu(tr("&Help")); - help->addAction(tr("Preferences..."), this, SLOT(settingsSlot())); + QMenu *help = menuBar->addMenu(tr("&Help")); + help->addAction(tr("Preferences..."), this, SLOT(settingsSlot())); } #endif setWindowTitle(QString("OSTC Companion v%1.%2 %3") .arg(MAJOR_VERSION) - .arg(MINOR_VERSION) // kein sprintf nötig, arg konvertiert automatisch - .arg(BETA_VERSION - ? QString(" beta %1").arg(PATCH_VERSION) - : QString::number(PATCH_VERSION)) - ); + .arg(MINOR_VERSION) // kein sprintf nötig, arg konvertiert automatisch + .arg(BETA_VERSION ? QString(" beta %1").arg(PATCH_VERSION) + : QString::number(PATCH_VERSION))); } - ////////////////////////////////////////////////////////////////////////////// MainWindow::~MainWindow() @@ -160,23 +150,19 @@ ////////////////////////////////////////////////////////////////////////////// -bool MainWindow::event(QEvent* e) +bool MainWindow::event(QEvent *e) { - if( ProgressEvent* p = dynamic_cast<ProgressEvent*>(e) ) - { - QProgressBar* w = _ui->progressBar; + if (ProgressEvent *p = dynamic_cast<ProgressEvent *>(e)) { + QProgressBar *w = _ui->progressBar; - if( p->current > p->maximum && p->maximum > 0) - { - w->setMaximum(p->maximum); // Remove throttling mode, if any. + if (p->current > p->maximum && p->maximum > 0) { + w->setMaximum(p->maximum); // Remove throttling mode, if any. w->reset(); - } - else - { - if( ! w->isEnabled() ) + } else { + if (!w->isEnabled()) w->setEnabled(true); - if( w->maximum() != p->maximum ) - w->setMaximum(p->maximum); // Start throttling if max==0 + if (w->maximum() != p->maximum) + w->setMaximum(p->maximum); // Start throttling if max==0 w->setValue(p->current); } return true; @@ -194,17 +180,21 @@ //---- Setup a new driver ------------------------------------------------ delete _op; _op = 0; - switch( _ui->computerType->currentIndex() ) { - case 0: name = "ostc2c"; - _op = new OSTC2cOperations; + switch (_ui->computerType->currentIndex()) { + case 0: + name = "ostc2c"; + _op = new OSTC2cOperations; break; - case 1: name = "hwOS (USB)"; - _op = new OSTC3Operations; + case 1: + name = "hwOS (USB)"; + _op = new OSTC3Operations; break; - case 2: name = "hwOS (Bluetooth)"; - _op = new OSTC3pOperations; + case 2: + name = "hwOS (Bluetooth)"; + _op = new OSTC3pOperations; break; - case 3: name = "ostc4"; + case 3: + name = "ostc4"; _op = new OSTC4Operations; break; @@ -218,11 +208,14 @@ settings->sync(); // backword compatibility >= translate name if necessary - if ( name =="hwOS (Bluetooth)") name = "ostc3p"; - if( name =="hwOS (USB)") name = "ostc3"; - if( name =="ostc 4/5") name = "ostc4"; + if (name == "hwOS (Bluetooth)") + name = "ostc3p"; + if (name == "hwOS (USB)") + name = "ostc3"; + if (name == "ostc 4/5") + name = "ostc4"; - _ui->computerImage->setPixmap( QPixmap(":/Images/" + name + "_160x120.png")); + _ui->computerImage->setPixmap(QPixmap(":/Images/" + name + "_160x120.png")); updateStatus(); } @@ -231,7 +224,7 @@ void MainWindow::settingsSlot() { - Settings* s = new Settings(this, _op); + Settings *s = new Settings(this, _op); s->exec(); delete s; } @@ -240,29 +233,26 @@ void MainWindow::connectSlot() { - Q_ASSERT( _op ); + Q_ASSERT(_op); try { LOG_INFO("Connecting..."); //---- Already connected ? ---------------------------------------------- - if( ! _op->description().isEmpty() ) + if (!_op->description().isEmpty()) _op->disconnect(); //---- (Re)connect ------------------------------------------------------ - if( _op->connect() ) { - - if( Settings::autoSetDateTime ) + if (_op->connect()) { + if (Settings::autoSetDateTime) dateSlot(); - LOG_INFO("Connected: " + _op->description() ); + LOG_INFO("Connected: " + _op->description()); } updateStatus(); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } @@ -270,18 +260,16 @@ void MainWindow::closeSlot() { - Q_ASSERT( _op ); + Q_ASSERT(_op); try { LOG_INFO("Disconnecting..."); - if( _op->disconnect() ) + if (_op->disconnect()) LOG_INFO("Disconnected."); updateStatus(); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } @@ -290,49 +278,46 @@ void MainWindow::updateStatus() { bool ok = _op; - _ui->connectButton->setEnabled( ok ); + _ui->connectButton->setEnabled(ok); // ON when supported but NOT connected, OFF once connected. - _ui->upgradeButton->setEnabled( ok - && (_op->supported() & HardwareOperations::CompanionFeatures(HardwareOperations::FIRMWARE)) - && !_op->serial().isOpen()); + _ui->upgradeButton->setEnabled( + ok + && (_op->supported() & HardwareOperations::CompanionFeatures(HardwareOperations::FIRMWARE)) + && !_op->serial().isOpen()); // Only allow buttons when connected: ok &= _op->serial().isOpen(); - _ui->dateButton ->setEnabled(ok && _op->supported().testFlag(HardwareOperations::DATE)); - _ui->nameButton ->setEnabled(ok && _op->supported().testFlag(HardwareOperations::NAME)); - _ui->iconButton ->setEnabled(ok);// && _op->supported().testFlag(HardwareOperations::ICON)); + _ui->dateButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::DATE)); + _ui->nameButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::NAME)); + _ui->iconButton->setEnabled(ok); // && _op->supported().testFlag(HardwareOperations::ICON)); _ui->signalButton->setEnabled(ok && _op->supported().testFlag(HardwareOperations::SIGNAL_CHECK)); - _ui->closeButton ->setEnabled( ok ); + _ui->closeButton->setEnabled(ok); } ////////////////////////////////////////////////////////////////////////////// void MainWindow::dateSlot() { - Q_ASSERT( _op ); + Q_ASSERT(_op); try { QDateTime date = QDateTime::currentDateTime(); LOG_INFO(tr("Settings date & time...")); - _op->setDate( date ); - LOG_INFO( QString("Date set to %1") - .arg(date.toString("yyyy/MM/dd hh:mm:ss")) ); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + _op->setDate(date); + LOG_INFO(QString("Date set to %1").arg(date.toString("yyyy/MM/dd hh:mm:ss"))); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } - ////////////////////////////////////////////////////////////////////////////// void MainWindow::nameSlot() { - Q_ASSERT( _op ); + Q_ASSERT(_op); try { LOG_INFO(tr("Settings name...")); @@ -341,15 +326,14 @@ QString oldText; QSize size = _op->nameSize(); - for(int l=0; l<size.height(); ++l) { - QString line = oldName.left( size.width() ).leftJustified(size.width()); - if( line.contains("\n") ) { + for (int l = 0; l < size.height(); ++l) { + QString line = oldName.left(size.width()).leftJustified(size.width()); + if (line.contains("\n")) { line = line.section("\n", 0, 0); oldName = oldName.mid(line.length()); - } - else { + } else { oldName = oldName.mid(line.length()); - if( oldName[0] == '\n' ) + if (oldName[0] == '\n') oldName = oldName.mid(1); } oldText += line + "|\n"; @@ -357,21 +341,19 @@ //---- Ask user ------------------------------------------------------ - QInputDialog* d = new QInputDialog(this); + QInputDialog *d = new QInputDialog(this); d->setWindowTitle("Set Computer Name..."); d->setInputMode(QInputDialog::TextInput); d->setOptions(QInputDialog::UsePlainTextEditForTextInput); d->setTextValue(oldText); - QPlainTextEdit* edit = d->findChild<QPlainTextEdit*>(); + QPlainTextEdit *edit = d->findChild<QPlainTextEdit *>(); assert(edit); - edit->setStyleSheet( - "background-color: black;" - "color: green;" - "font: 14pt 'Courier New';" - ); + edit->setStyleSheet("background-color: black;" + "color: green;" + "font: 14pt 'Courier New';"); - if( d->exec() != QDialog::Accepted ) + if (d->exec() != QDialog::Accepted) return; QString newText = d->textValue(); @@ -380,23 +362,21 @@ //---- Reformat to single padded string ------------------------------ QStringList lines = newText.split("\n"); QString name; - for(int l=0; l<size.height(); ++l) { - if( l < lines.count() ) + for (int l = 0; l < size.height(); ++l) { + if (l < lines.count()) name += lines[l].leftJustified(size.width(), ' ', true); else name += QString(size.width(), ' '); } //---- Send result --------------------------------------------------- - _op->setName( name ); + _op->setName(name); _op->getIdentity(); - LOG_INFO( QString("Name set to '%1'") - .arg(_op->description().section(',', 2)).replace("\n", "|") ); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + LOG_INFO( + QString("Name set to '%1'").arg(_op->description().section(',', 2)).replace("\n", "|")); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } @@ -404,7 +384,7 @@ void MainWindow::iconSlot() { - Q_ASSERT( _op ); + Q_ASSERT(_op); try { LOG_INFO(tr("Settings icons...")); @@ -414,13 +394,11 @@ "Images (*.bmp);;" "BMP Image (*.bmp);;" "Anything (*.*)"); - if( ! fileName.isEmpty() ) + if (!fileName.isEmpty()) _op->setIcons(fileName); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } @@ -428,7 +406,7 @@ void MainWindow::upgradeSlot() { - Q_ASSERT( _op ); + Q_ASSERT(_op); try { LOG_INFO(tr("Upgrading firmware...")); @@ -437,27 +415,25 @@ "Hex File...", Settings::currentPath, _op->firmwareTemplate()); - if( hexFile.isEmpty() ) + if (hexFile.isEmpty()) return; Settings::currentPath = QFileInfo(hexFile).absoluteDir().path(); Settings::save(); - if( _op ) + if (_op) _op->upgradeFW(hexFile); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } ////////////////////////////////////////////////////////////////////////////// -void MainWindow::statusMessage(const QString& msg) +void MainWindow::statusMessage(const QString &msg) { - { // Move cursor to end of document. + { // Move cursor to end of document. QTextCursor c = _ui->console->textCursor(); c.movePosition(QTextCursor::End, QTextCursor::MoveAnchor); _ui->console->setTextCursor(c); @@ -476,23 +452,20 @@ ////////////////////////////////////////////////////////////////////////////// void MainWindow::on_signalButton_clicked() { - Q_ASSERT( _op ); + Q_ASSERT(_op); try { - LOG_INFO(tr("Request Bluetooth signal strength...")); - _op->getSignal(); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + LOG_INFO(tr("Request Bluetooth signal strength...")); + _op->getSignal(); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } - void MainWindow::on_editLog_clicked() { - EditLogDialog* eL = new EditLogDialog(this, _op); + EditLogDialog *eL = new EditLogDialog(this, _op); eL->exec(); delete eL; }
--- a/MainWindow.h Mon Jan 12 13:49:16 2026 +0000 +++ b/MainWindow.h Mon Jan 12 13:51:17 2026 +0000 @@ -58,8 +58,8 @@ class MainWindow : public QMainWindow { Q_OBJECT - Ui::MainWindow* _ui; ///< Compiled interface. - HardwareOperations* _op; ///< Driver for the connected dive computer. + Ui::MainWindow *_ui; ///< Compiled interface. + HardwareOperations *_op; ///< Driver for the connected dive computer. //------------------------------------------------------------------------ /// \brief Update buttons enable/disable state.
--- a/MainWindow.ui Mon Jan 12 13:49:16 2026 +0000 +++ b/MainWindow.ui Mon Jan 12 13:51:17 2026 +0000 @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>451</width> + <width>484</width> <height>418</height> </rect> </property>
--- a/OSTC2Operations.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC2Operations.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -39,12 +39,12 @@ #include "HexFile.h" #include "Utils/Log.h" -#define FIRMWARE_SIZE 0x17F40 +#define FIRMWARE_SIZE 0x17F40 #include <QApplication> #include <QProgressBar> #include <QRegularExpression> -extern QProgressBar* progress; +extern QProgressBar *progress; ////////////////////////////////////////////////////////////////////////////// @@ -77,13 +77,12 @@ QRegularExpression OSTC2Operations::portTemplate() const { #if defined(Q_OS_MAC) - return QRegularExpression("tty.OSTC[0-9]+.*", - QRegularExpression::CaseInsensitiveOption); + return QRegularExpression("tty.OSTC[0-9]+.*", QRegularExpression::CaseInsensitiveOption); #elif defined(Q_OS_LINUX) // Debian, Ubuntu, RedHat, CentOS, SUSE return QRegularExpression("ttyUSB.*"); // default: case-sensitive #elif defined(Q_OS_WIN) - return QRegularExpression("COM.*"); // default: case-sensitive + return QRegularExpression("COM.*"); // default: case-sensitive #endif } ////////////////////////////////////////////////////////////////////////////// @@ -105,8 +104,8 @@ HardwareOperations::CompanionFeatures OSTC2Operations::supported() const { // No ICON, no DUMPSCREEN. - return CompanionFeatures(PARAMETERS|DATE|NAME|FIRMWARE - |HELIUM_DIVE|CCR_DIVE|BLUETOOTH); + return CompanionFeatures(PARAMETERS | DATE | NAME | FIRMWARE | HELIUM_DIVE | CCR_DIVE + | BLUETOOTH); } ////////////////////////////////////////////////////////////////////////////// @@ -124,7 +123,7 @@ LOG_TRACE("Getting model..."); HardwareDescriptor hw = hardwareDescriptor(); - if( hw != HW_OSTC2_a && hw != HW_OSTC2_b && hw != HW_OSTC2_c ) + if (hw != HW_OSTC2_a && hw != HW_OSTC2_b && hw != HW_OSTC2_c) LOG_THROW("Not an OSTC2."); LOG_TRACE("Getting identity...");
--- a/OSTC2Operations.h Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC2Operations.h Mon Jan 12 13:51:17 2026 +0000 @@ -44,8 +44,7 @@ ////////////////////////////////////////////////////////////////////////////// /// \brief new OSTC2 (Bluetooth) is just an OSTC3 in a different package. -class OSTC2Operations - : public OSTC3Operations +class OSTC2Operations : public OSTC3Operations { /// \brief Returns "OSTC2" QString model() const override; @@ -60,7 +59,7 @@ void getIdentity() override; QStringList listPorts() const override; - // QRegExp portTemplate() const override; + // QRegExp portTemplate() const override; QRegularExpression portTemplate() const override; QString firmwareTemplate() const override;
--- a/OSTC2cOperations.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC2cOperations.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -48,7 +48,7 @@ #include <QDateTime> #include <QRegularExpression> -#define FIRMWARE_SIZE 0x17F40 +#define FIRMWARE_SIZE 0x17F40 // 64 bytes on Mk.2/2n/2c: #define FIRMWARE_BLOCK_SIZE 0x40 @@ -56,11 +56,10 @@ ////////////////////////////////////////////////////////////////////////////// OSTC2cOperations::OSTC2cOperations() - : HardwareOperations(), - _computerFirmware(0), - _computerSerial(0) -{ -} + : HardwareOperations() + , _computerFirmware(0) + , _computerSerial(0) +{} ////////////////////////////////////////////////////////////////////////////// @@ -78,13 +77,13 @@ _serial.purge(); _serial.writeByte('d'); int reply = _serial.readByte(); - if( reply != 'd' ) + if (reply != 'd') LOG_THROW("Write start"); - for(int a=4; a<256; ++a) { + for (int a = 4; a < 256; ++a) { _serial.writeByte(bank0[a]); reply = _serial.readByte(); - if( reply != bank0[a] ) + if (reply != bank0[a]) LOG_THROW("Write bank0 @ " << a); } @@ -111,23 +110,24 @@ try { readBank0(bank0); readBank1(bank1); - } catch(ReadTimeout) { + } catch (ReadTimeout) { LOG_THROW("No reply from OSTC Mk.2, 2n or 2c..."); } // Sanity check: - if( bank0[65] == 0xFF || bank1[1] > 99 || bank1[2] > 99 ) + if (bank0[65] == 0xFF || bank1[1] > 99 || bank1[2] > 99) LOG_THROW("Not an OSTC Mk.2, 2n or 2c..."); - _computerSerial = bank0[0] + bank0[1]*256; + _computerSerial = bank0[0] + bank0[1] * 256; _computerFirmware = bank1[1] * 100 + bank1[2]; - _customText = QString::fromLatin1((char*)bank0+65, 25).section('}', 0,0); + _customText = QString::fromLatin1((char *) bank0 + 65, 25).section('}', 0, 0); _description = QString("%1 #%2, v%3.%4, %5") - .arg(model()) - .arg(_computerSerial) - .arg(bank1[1]).arg(bank1[2], 2, 10, QChar('0')) - .arg( _customText ); + .arg(model()) + .arg(_computerSerial) + .arg(bank1[1]) + .arg(bank1[2], 2, 10, QChar('0')) + .arg(_customText); } int OSTC2cOperations::firmware() const @@ -162,12 +162,11 @@ QRegularExpression OSTC2cOperations::portTemplate() const { #if defined(Q_OS_MAC) - return QRegularExpression("tty.usbserial-.*", - QRegularExpression::CaseInsensitiveOption); + return QRegularExpression("tty.usbserial-.*", QRegularExpression::CaseInsensitiveOption); #elif defined(Q_OS_LINUX) return QRegularExpression("ttyUSB.*"); // default: case-sensitive #elif defined(Q_OS_WIN) - return QRegularExpression("COM.*"); // default: case-sensitive + return QRegularExpression("COM.*"); // default: case-sensitive #endif } QStringList OSTC2cOperations::listPorts() const @@ -192,8 +191,8 @@ HardwareOperations::CompanionFeatures OSTC2cOperations::supported() const { // No ICON. - return CompanionFeatures(PARAMETERS|DATE|NAME|DUMPSCREEN|FIRMWARE - |HELIUM_DIVE|CCR_DIVE); + return CompanionFeatures(PARAMETERS | DATE | NAME | DUMPSCREEN | FIRMWARE | HELIUM_DIVE + | CCR_DIVE); } ////////////////////////////////////////////////////////////////////////////// @@ -212,8 +211,7 @@ _serial.open(Settings::port, "OSTC2c"); getIdentity(); return true; - } - catch(const Exception& e){ + } catch (const Exception &e) { _serial.close(); LOG_THROW("Cannot connect " << Settings::port << ": " << e.what()); } @@ -227,7 +225,7 @@ return QSize(25, 1); } -void OSTC2cOperations::writeText(const QString& msg) +void OSTC2cOperations::writeText(const QString &msg) { // No hardware support for that. Just skip it, as it is done when // writting bank1... @@ -242,12 +240,12 @@ _serial.open(Settings::port, "OSTC2c"); _serial.writeByte(0xC1); - _serial.sleep(500); // 0.50 sec for bootloader to start. + _serial.sleep(500); // 0.50 sec for bootloader to start. //---- Send C1C1 to start upgrading firmware ----------------------------- unsigned char pic = 0; unsigned char ok = '?'; - for(int retry=0; retry < 10; ++retry) { + for (int retry = 0; retry < 10; ++retry) { _serial.writeByte(0xC1); _serial.sleep(5); _serial.writeByte(0xC1); @@ -255,31 +253,27 @@ try { pic = _serial.readByte(); - ok = _serial.readByte(); + ok = _serial.readByte(); break; - } - catch(const ReadTimeout&) { - if( retry == 9 ) + } catch (const ReadTimeout &) { + if (retry == 9) LOG_THROW("Cannot start firmware upgrade: timeout."); - LOG_INFO("Connecting OSTC2c (" << (retry+1) << "/10)..."); + LOG_INFO("Connecting OSTC2c (" << (retry + 1) << "/10)..."); } } //---- Check PIC type ---------------------------------------------------- LOG_TRACE("Pic = " << int(pic)); - if( ! pic ) + if (!pic) LOG_THROW("Cannot sync firmware upgrade. Cannot detect chip"); - if( pic != 0x57 - || ok != 'K' - ) - LOG_THROW( "Cannot sync firmware upgrade. Bad chip " << int(pic) << " " << ok); + if (pic != 0x57 || ok != 'K') + LOG_THROW("Cannot sync firmware upgrade. Bad chip " << int(pic) << " " << ok); - _serial.sleep(50); // Wait 0.050 sec here. + _serial.sleep(50); // Wait 0.050 sec here. return; - } - catch(const Exception& e) { + } catch (const Exception &e) { _serial.close(); LOG_THROW("Cannot connect " << Settings::port << ": " << e.what()); } @@ -290,7 +284,8 @@ bool OSTC2cOperations::disconnect(bool /*closing*/) { - if( ! _serial.isOpen() ) return false; + if (!_serial.isOpen()) + return false; LOG_TRACE("Disconnecting."); @@ -312,15 +307,15 @@ buffer[4] = date.date().day(); buffer[5] = date.date().year() % 100; - _serial.sleep(100); // Make sure last command is finished. + _serial.sleep(100); // Make sure last command is finished. _serial.purge(); _serial.writeByte('b'); // 0x62 unsigned char reply = _serial.readByte(); - if( reply != 'b' ) - LOG_THROW( "sync time" ); + if (reply != 'b') + LOG_THROW("sync time"); - _serial.writeBlock( buffer, sizeof buffer); + _serial.writeBlock(buffer, sizeof buffer); _serial.sleep(100); } @@ -328,13 +323,11 @@ void OSTC2cOperations::setName(const QString &newName) { - QByteArray padded = (newName + QString(25, '}')) - .left(25) - .toLatin1(); + QByteArray padded = (newName + QString(25, '}')).left(25).toLatin1(); byte bank0[256] = {0}; readBank0(bank0); - memcpy(bank0+65, padded.constData(), 25); + memcpy(bank0 + 65, padded.constData(), 25); writeBank0(bank0); // Then get the new identity: @@ -343,7 +336,7 @@ ////////////////////////////////////////////////////////////////////////////// -void OSTC2cOperations::setIcons(const QString &/*fileName*/) +void OSTC2cOperations::setIcons(const QString & /*fileName*/) { LOG_THROW("Not supported"); } @@ -354,42 +347,35 @@ { QImage image(320, 240, QImage::Format_RGB32); - //---- Send dump screen command ------------------------------------- + //---- Send dump screen command ------------------------------------- unsigned char reply; _serial.writeByte('l'); reply = _serial.readByte(); - if( reply != 'l' ) - LOG_THROW( "Dumpscreen command failed: " << (int)reply ); + if (reply != 'l') + LOG_THROW("Dumpscreen command failed: " << (int) reply); //---- Read image ---------------------------------------------------- int percent = 0; try { - for(int x=0; x<320; ++x) - { - int p = x/16; // 5% steps - if( p != percent ) - { - PROGRESS(p, 320/16); + for (int x = 0; x < 320; ++x) { + int p = x / 16; // 5% steps + if (p != percent) { + PROGRESS(p, 320 / 16); percent = p; } int pix = 0, count = 0; - for(int y=0; y<240; ++y, --count) - { - if( count <= 0 ) - { + for (int y = 0; y < 240; ++y, --count) { + if (count <= 0) { count = _serial.readByte(); - if( (count & 0x80) == 0 ) + if ((count & 0x80) == 0) pix = 0; - else if( (count & 0xC0) == 0xC0 ) - { + else if ((count & 0xC0) == 0xC0) { pix = 0xFFFF; count &= 0x3F; - } - else - { + } else { unsigned char bpix[2]; _serial.readBlock(bpix, 2); pix = (bpix[0] << 8) + bpix[1]; @@ -400,91 +386,93 @@ // Bit extension 5bits --> 8bits: // 12345123.45 = (12345 * 0b100001) / 4 // 12345612.3456 = (123456 * 0xb1000001) / 16 - int r = (31 & (pix >> 11)) * 255/31; - int g = (63 & (pix >> 5)) * 255/63; - int b = (31 & pix ) * 255/31; - image.setPixel(x, y, qRgb( r, g, b)); + int r = (31 & (pix >> 11)) * 255 / 31; + int g = (63 & (pix >> 5)) * 255 / 63; + int b = (31 & pix) * 255 / 31; + image.setPixel(x, y, qRgb(r, g, b)); } } - } - catch( ReadTimeout ) { + } catch (ReadTimeout) { LOG_THROW("Missing image data..."); } //---- Done ---------------------------------------------------------- PROGRESS_RESET(); - LOG_INFO( "Screen dumped." ); + LOG_INFO("Screen dumped."); return image; } ////////////////////////////////////////////////////////////////////////////// -void OSTC2cOperations::loadFirmware(HexFile& hex, const QString& fileName) const +void OSTC2cOperations::loadFirmware(HexFile &hex, const QString &fileName) const { hex.allocate(FIRMWARE_SIZE); hex.load(fileName); //---- Patch Firmware intialization GOTO --------------------------------- - memcpy((void*)(hex.data() + 0x17F38), // To bootloader vector - (void*)(hex.data() + 0x00000), // From fw reset code + memcpy((void *) (hex.data() + 0x17F38), // To bootloader vector + (void *) (hex.data() + 0x00000), // From fw reset code 8); // Up to 8 bytes... static unsigned char byteCode[8] = { - 0xA0, 0xEF, 0xBF, 0xF0, // goto 0x1F740 (bootloader 19k) - 0x00, 0x00, // nop - 0x00, 0x00 // nop + 0xA0, + 0xEF, + 0xBF, + 0xF0, // goto 0x1F740 (bootloader 19k) + 0x00, + 0x00, // nop + 0x00, + 0x00 // nop }; - memcpy((void*)(hex.data() + 0x00000), // To OSTC reset vector - (void*)(byteCode), // From go back to bootloader. + memcpy((void *) (hex.data() + 0x00000), // To OSTC reset vector + (void *) (byteCode), // From go back to bootloader. 8); // Up to 8 bytes... } ////////////////////////////////////////////////////////////////////////////// -static void -uploadBlock(Serial& serial, const HexFile& hex, size_t addr) +static void uploadBlock(Serial &serial, const HexFile &hex, size_t addr) { const unsigned char count = FIRMWARE_BLOCK_SIZE; - assert( 0 < count && count < 255 ); - assert((addr+count) <= FIRMWARE_SIZE ); + assert(0 < count && count < 255); + assert((addr + count) <= FIRMWARE_SIZE); unsigned char reply = 0; unsigned char header[4]; header[0] = 0x1F & (addr >> 16); - header[1] = 0xFF & (addr >> 8); + header[1] = 0xFF & (addr >> 8); header[2] = 0xFF & (addr); header[3] = count; unsigned char crc = header[0] + header[1] + header[2] + header[3]; - for(int i=0; i<count; ++i) - crc += hex.data()[addr+i]; + for (int i = 0; i < count; ++i) + crc += hex.data()[addr + i]; crc = -crc; // Sum should make zero. try { serial.writeBlock(header, sizeof header); - serial.writeBlock(hex.data()+addr, count); + serial.writeBlock(hex.data() + addr, count); serial.writeByte(crc); - } catch(...) { + } catch (...) { goto WriteFailed; } - serial.sleep(20); // 18msec for a FLASH row write, plus VAT. + serial.sleep(20); // 18msec for a FLASH row write, plus VAT. reply = serial.readByte(); - if( reply != 'K' ) - { + if (reply != 'K') { serial.close(); - LOG_THROW( QString("Bad checksum at 0x%1").arg((unsigned int)addr, 0, 16, QChar('0'))); + LOG_THROW(QString("Bad checksum at 0x%1").arg((unsigned int) addr, 0, 16, QChar('0'))); } return; WriteFailed: serial.close(); - LOG_THROW( QString("Write failed") ); + LOG_THROW(QString("Write failed")); } -void OSTC2cOperations::upgradeFW(const QString& fileName) +void OSTC2cOperations::upgradeFW(const QString &fileName) { //---- Load and check firmware --------------------------------------- LOG_TRACE("Loading firmware '" << fileName << "'."); @@ -497,11 +485,9 @@ //---- Let's do it ------------------------------------------------------- int percent = 0; - for(size_t addr = FIRMWARE_BLOCK_SIZE; addr < FIRMWARE_SIZE; addr += FIRMWARE_BLOCK_SIZE) - { - int p = int((addr*200.0f) / float(FIRMWARE_SIZE) + 0.5f); - if( p > percent ) - { + for (size_t addr = FIRMWARE_BLOCK_SIZE; addr < FIRMWARE_SIZE; addr += FIRMWARE_BLOCK_SIZE) { + int p = int((addr * 200.0f) / float(FIRMWARE_SIZE) + 0.5f); + if (p > percent) { PROGRESS(percent, 200); percent = p; } @@ -522,20 +508,20 @@ return; } -void OSTC2cOperations::getAllHeader(unsigned char* pBuffer) +void OSTC2cOperations::getAllHeader(unsigned char *pBuffer) { return; } -void OSTC2cOperations::writeAllHeader(unsigned char* pBuffer) +void OSTC2cOperations::writeAllHeader(unsigned char *pBuffer) { return; } -void OSTC2cOperations::getAllSamples(unsigned char* pBuffer) +void OSTC2cOperations::getAllSamples(unsigned char *pBuffer) { return; } -void OSTC2cOperations::writeAllSamples(unsigned char* pBuffer) +void OSTC2cOperations::writeAllSamples(unsigned char *pBuffer) { return; }
--- a/OSTC2cOperations.h Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC2cOperations.h Mon Jan 12 13:51:17 2026 +0000 @@ -45,11 +45,10 @@ ////////////////////////////////////////////////////////////////////////////// -class OSTC2cOperations - : public HardwareOperations +class OSTC2cOperations : public HardwareOperations { - int _computerFirmware; - int _computerSerial; + int _computerFirmware; + int _computerSerial; QString _customText; QString _description; @@ -95,21 +94,21 @@ void connectServiceMode() override; void writeText(const QString &msg) override; QSize nameSize() const override; - void setDate(const QDateTime& date) override; - void setName(const QString& newName) override; + void setDate(const QDateTime &date) override; + void setName(const QString &newName) override; void getSignal() override; - void getAllHeader(unsigned char* pBuffer) override; - void writeAllHeader(unsigned char* pBuffer) override; - void getAllSamples(unsigned char* pBuffer) override; - void writeAllSamples(unsigned char* pBuffer) override; + void getAllHeader(unsigned char *pBuffer) override; + void writeAllHeader(unsigned char *pBuffer) override; + void getAllSamples(unsigned char *pBuffer) override; + void writeAllSamples(unsigned char *pBuffer) override; - void setIcons(const QString& fileName) override; + void setIcons(const QString &fileName) override; QImage dumpScreen() const override; - void upgradeFW(const QString& fileName) override; - void loadFirmware(HexFile& hex, const QString& fileName) const override; + void upgradeFW(const QString &fileName) override; + void loadFirmware(HexFile &hex, const QString &fileName) const override; - bool disconnect(bool closing = false) override; + bool disconnect(bool closing = false) override; /// \} //////////////////////////////////////////////////////////////////////////
--- a/OSTC3Operations.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC3Operations.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -40,8 +40,8 @@ #include "Utils/Log.h" #include "Utils/ProgressEvent.h" +#include "HexFile.h" #include "SettingsDialog.h" -#include "HexFile.h" #include <QApplication> #include <QDateTime> @@ -49,30 +49,30 @@ #include <QRegularExpression> // Byte extration, compatible littleendian or bigendian. -#define LOW(x) ((unsigned char)((x) % 256)) -#define HIGH(x) ((unsigned char)((x / (1<<8)) % 256)) -#define UPPER(x) ((unsigned char)((x / (1<<16)) % 256)) -#define UP32(x) ((unsigned char)((x / (1<<24)) % 256)) +#define LOW(x) ((unsigned char) ((x) % 256)) +#define HIGH(x) ((unsigned char) ((x / (1 << 8)) % 256)) +#define UPPER(x) ((unsigned char) ((x / (1 << 16)) % 256)) +#define UP32(x) ((unsigned char) ((x / (1 << 24)) % 256)) -#define FIRMWARE_AREA 0x3E0000 -#define FIRMWARE_SIZE 0x01E000 // 120KB -#define FIRMWARE_BLOCK 0x1000 // 4KB +#define FIRMWARE_AREA 0x3E0000 +#define FIRMWARE_SIZE 0x01E000 // 120KB +#define FIRMWARE_BLOCK 0x1000 // 4KB ////////////////////////////////////////////////////////////////////////////// OSTC3Operations::OSTC3Operations() - : descriptionString(""), - emulatorName("OSTC3"), - _computerFirmware(0), - _computerSerial(0), - _connectMode(CLOSED_MODE) + : descriptionString("") + , emulatorName("OSTC3") + , _computerFirmware(0) + , _computerSerial(0) + , _connectMode(CLOSED_MODE) { memset(computerText, 0, sizeof computerText); } OSTC3Operations::~OSTC3Operations() { - if( _connectMode != CLOSED_MODE ) + if (_connectMode != CLOSED_MODE) disconnect(true); } @@ -87,51 +87,49 @@ bool OSTC3Operations::connect() { - LOG_TRACE( "Enter download mode..." ); + LOG_TRACE("Enter download mode..."); try { _connectMode = CLOSED_MODE; - _serial.open( Settings::port, emulatorName); - _serial.sleep(333); // Initial 1/3 sec. delay to first comm. + _serial.open(Settings::port, emulatorName); + _serial.sleep(333); // Initial 1/3 sec. delay to first comm. - for(int retry=0; retry < 10; ++retry) - { + for (int retry = 0; retry < 10; ++retry) { // Allow for 0.1sec extra delay try { _serial.writeByte(0xBB); - } catch(const WriteTimeout& ) { + } catch (const WriteTimeout &) { // Bluetooth not present: one can open the pseudo COM port, // but we will have a timeout on first write byte... - if( retry < 9 ) { - LOG_INFO("Cannot connect to " << Settings::port <<" (" << (retry+1) << "/10)..."); + if (retry < 9) { + LOG_INFO("Cannot connect to " << Settings::port << " (" << (retry + 1) + << "/10)..."); _serial.sleep(1000); continue; } - LOG_THROW("Cannot connect to " << model() <<"."); + LOG_THROW("Cannot connect to " << model() << "."); return false; } _serial.sleep(100); //---- Check acknowledge, w/o fatal timeouts. - unsigned char ok = 0; + unsigned char ok = 0; unsigned char echo = 0; try { echo = _serial.readByte(); // Already in connect() mode ??? - if( echo == 'M' ) + if (echo == 'M') break; ok = _serial.readByte(); - } - catch(const ReadTimeout&) { - LOG_INFO("Retry " << (retry+1) << "/10..."); + } catch (const ReadTimeout &) { + LOG_INFO("Retry " << (retry + 1) << "/10..."); } - if( echo != 0xBB || ok != 0x4D ) { // DOWNLOAD modes only. - if( retry < 9 ) - { + if (echo != 0xBB || ok != 0x4D) { // DOWNLOAD modes only. + if (retry < 9) { _serial.purge(); _serial.sleep(400); continue; @@ -148,8 +146,7 @@ LOG_TRACE("Connected."); _connectMode = DOWNLOAD_MODE; return true; - } - catch(const Exception& e) { + } catch (const Exception &e) { disconnect(); LOG_THROW("Port " << Settings::port << ": " << e.what()); } @@ -160,13 +157,14 @@ bool OSTC3Operations::disconnect(bool /*closing*/) { - if( _connectMode == CLOSED_MODE ) return false; + if (_connectMode == CLOSED_MODE) + return false; - descriptionString.clear(); // cleanup for interface updateStatus() + descriptionString.clear(); // cleanup for interface updateStatus() _connectMode = CLOSED_MODE; _serial.purge(); - _serial.writeByte(0xFF); // Exit communications, just in case... + _serial.writeByte(0xFF); // Exit communications, just in case... _serial.sleep(100); _serial.purge(); @@ -183,8 +181,8 @@ LOG_TRACE("Getting model..."); HardwareDescriptor hw = hardwareDescriptor(); - // if( hw != HW_OSTC3 ) - // LOG_THROW("Not an OSTC3."); + // if( hw != HW_OSTC3 ) + // LOG_THROW("Not an OSTC3."); LOG_TRACE("Getting identity..."); getCommonIdentity(); @@ -197,24 +195,25 @@ void OSTC3Operations::getCommonIdentity() { unsigned char echo = retryCommand(_serial, 'i'); // 0x69 - if( echo != 'i' ) + if (echo != 'i') LOG_THROW("Bad identity reply (1)"); unsigned char header[4 + 60 + 1] = {0}; _serial.readBlock(header, sizeof header); - if( header[64] != 0x4D ) // DOWNLOAD modes only. + if (header[64] != 0x4D) // DOWNLOAD modes only. LOG_THROW("Bad identity reply (2)"); - _computerSerial = header[0] + header[1]*256; + _computerSerial = header[0] + header[1] * 256; _computerFirmware = header[2] * 100 + header[3]; - memcpy(computerText, header+4, sizeof computerText); + memcpy(computerText, header + 4, sizeof computerText); - descriptionString = QString("%1 #%2, fw %3.%4, %5") - .arg(model()) - .arg(serialNumber(), 4, 10, QChar('0')) - .arg(firmware() / 100).arg(firmware() % 100, 2, 10, QChar('0')) - .arg( QString::fromLatin1((char*)(computerText), 60) - .replace(QChar('\0'), " ") ); + descriptionString + = QString("%1 #%2, fw %3.%4, %5") + .arg(model()) + .arg(serialNumber(), 4, 10, QChar('0')) + .arg(firmware() / 100) + .arg(firmware() % 100, 2, 10, QChar('0')) + .arg(QString::fromLatin1((char *) (computerText), 60).replace(QChar('\0'), " ")); } ////////////////////////////////////////////////////////////////////////////// @@ -243,7 +242,7 @@ ////////////////////////////////////////////////////////////////////////////// -void OSTC3Operations::writeText(const QString& msg) +void OSTC3Operations::writeText(const QString &msg) { QByteArray buffer = msg.leftJustified(16, ' ', true).toLatin1(); LOG_TRACE("Echoing string '" << buffer << "'"); @@ -251,14 +250,14 @@ // 2014-10-27 jDG: On OSTC3 v1.60, after an ERASE AREA, we do get // a spurious L here (instead of n)... unsigned char echo = retryCommand(_serial, 'n'); // 0x6E Echo string. - if( echo != 'n' ) + if (echo != 'n') LOG_THROW("Bad message reply (1)"); - _serial.writeBlock((const unsigned char*)buffer.data(), 16); - _serial.sleep(25); // Allow 25msec to display the message... + _serial.writeBlock((const unsigned char *) buffer.data(), 16); + _serial.sleep(25); // Allow 25msec to display the message... unsigned char ok = _serial.readByte(); - if( ok != 0x4C && ok != 0x4D ) // DOWNLOAD or SERVICE modes. + if (ok != 0x4C && ok != 0x4D) // DOWNLOAD or SERVICE modes. LOG_THROW("Bad message reply (2)"); } @@ -277,17 +276,17 @@ buffer[5] = date.date().year() % 100; unsigned char echo = retryCommand(_serial, 'b'); // 0x62 Sync date - if( echo != 'b' ) + if (echo != 'b') LOG_THROW("Bad clock reply (1)"); _serial.writeBlock(buffer, sizeof buffer); _serial.sleep(5); unsigned char ok = _serial.readByte(); - if( ok != 0x4D ) // DOWNLOAD mode only. + if (ok != 0x4D) // DOWNLOAD mode only. LOG_THROW("Bad clock reply (2)"); - writeText( "Set " + date.toString("MM/dd hh:mm") ); + writeText("Set " + date.toString("MM/dd hh:mm")); } ////////////////////////////////////////////////////////////////////////////// @@ -301,14 +300,14 @@ strncpy(buffer, newName.toLatin1().constData(), sizeof buffer); unsigned char echo = retryCommand(_serial, 'c'); // 0x63 Send custom text - if( echo != 'c' ) + if (echo != 'c') LOG_THROW("Bad text reply (1)"); - _serial.writeBlock((unsigned char*)buffer, sizeof buffer); + _serial.writeBlock((unsigned char *) buffer, sizeof buffer); _serial.sleep(5); unsigned char ok = _serial.readByte(); - if( ok != 0x4D ) // DOWNLOAD modes only. + if (ok != 0x4D) // DOWNLOAD modes only. LOG_THROW("Bad text reply (2)"); getIdentity(); @@ -331,12 +330,8 @@ ////////////////////////////////////////////////////////////////////////////// -static unsigned char ostc3SecretKey[16] = { - 241,233, 176, 48, - 69,111, 190, 85, - 255,231, 248, 49, - 19,108, 242,254 -}; +static unsigned char ostc3SecretKey[16] + = {241, 233, 176, 48, 69, 111, 190, 85, 255, 231, 248, 49, 19, 108, 242, 254}; ////////////////////////////////////////////////////////////////////////////// @@ -352,8 +347,8 @@ buffer[2] = LOW(addr); buffer[3] = LOW(size); - unsigned char reply = retryCommand(_serial, 'B'); // Command 'B' - if( reply != 0x42 ) + unsigned char reply = retryCommand(_serial, 'B'); // Command 'B' + if (reply != 0x42) LOG_THROW("eraseRange (1)"); _serial.writeBlock(buffer, 4); @@ -362,23 +357,21 @@ _serial.sleep(40 + size * 31); unsigned char ok = _serial.readByte(); - if( ok != 0x4c ) // SERVICE MODE acknowledge. + if (ok != 0x4c) // SERVICE MODE acknowledge. LOG_THROW("eraseRange (2)"); } ////////////////////////////////////////////////////////////////////////////// -void OSTC3Operations::writeBlock(unsigned int addr, - const unsigned char *data, - unsigned int size) +void OSTC3Operations::writeBlock(unsigned int addr, const unsigned char *data, unsigned int size) { unsigned char buffer[3]; buffer[0] = UPPER(addr); buffer[1] = HIGH(addr); buffer[2] = LOW(addr); - unsigned char reply = retryCommand(_serial, '0'); // 0x30 - if( reply != '0' ) + unsigned char reply = retryCommand(_serial, '0'); // 0x30 + if (reply != '0') LOG_THROW("startWrite"); _serial.writeBlock(buffer, sizeof buffer); @@ -391,14 +384,13 @@ _serial.sleep(1100); unsigned char ok = _serial.readByte(); - if( ok != 0x4c && ok != 0x4d ) // DOWNLOAD or SERVICE modes. + if (ok != 0x4c && ok != 0x4d) // DOWNLOAD or SERVICE modes. LOG_THROW("stopWrite"); } - ////////////////////////////////////////////////////////////////////////////// -void OSTC3Operations::readBlock(unsigned int addr, unsigned char* ptr, unsigned int size) +void OSTC3Operations::readBlock(unsigned int addr, unsigned char *ptr, unsigned int size) { unsigned char buffer[6]; buffer[0] = UPPER(addr); @@ -408,17 +400,17 @@ buffer[4] = HIGH(size); buffer[5] = LOW(size); - unsigned char reply = retryCommand(_serial, 0x20); // Command ' ' - if( reply != 0x20 ) + unsigned char reply = retryCommand(_serial, 0x20); // Command ' ' + if (reply != 0x20) LOG_THROW("readBytes"); _serial.writeBlock(buffer, sizeof buffer); - _serial.sleep(500); // Allow some time to start emitting... + _serial.sleep(500); // Allow some time to start emitting... _serial.readBlock(ptr, size); // Note: in that case, the OK byte is send AFTER the data block. unsigned char ok = _serial.readByte(); - if( ok != 0x4C ) // SERVICE modes only. + if (ok != 0x4C) // SERVICE modes only. LOG_THROW("readBytes (2)"); } @@ -434,18 +426,22 @@ // Compute magic checksum's checksum. buffer[4] = 0x55; - buffer[4] ^= buffer[0]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); - buffer[4] ^= buffer[1]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); - buffer[4] ^= buffer[2]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); - buffer[4] ^= buffer[3]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); + buffer[4] ^= buffer[0]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); + buffer[4] ^= buffer[1]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); + buffer[4] ^= buffer[2]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); + buffer[4] ^= buffer[3]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); - unsigned char reply = retryCommand(_serial, 0x50); // 'P' : send FW to bootloader - if( reply != 0x50 ) + unsigned char reply = retryCommand(_serial, 0x50); // 'P' : send FW to bootloader + if (reply != 0x50) LOG_THROW("Flashing start (1)"); _serial.writeBlock(buffer, sizeof buffer); - unsigned char ok = _serial.readByte(); - if( ok != 0x4C ) // SERVICE modes only. + unsigned char ok = _serial.readByte(); + if (ok != 0x4C) // SERVICE modes only. LOG_THROW("Flashing start (2)"); // NOTE: the device never return, because it always do a reset, @@ -477,44 +473,40 @@ QRegularExpression OSTC3Operations::portTemplate() const { #if defined(Q_OS_MAC) - return QRegularExpression("tty.usbserial-.*", - QRegularExpression::CaseInsensitiveOption); + return QRegularExpression("tty.usbserial-.*", QRegularExpression::CaseInsensitiveOption); #elif defined(Q_OS_LINUX) // Debian, Ubuntu, RedHat, CentOS, SUSE return QRegularExpression("ttyUSB.*"); // default: case-sensitive #elif defined(Q_OS_WIN) - return QRegularExpression("COM.*"); // default: case-sensitive + return QRegularExpression("COM.*"); // default: case-sensitive #endif } ////////////////////////////////////////////////////////////////////////////// void OSTC3Operations::connectServiceMode() { - LOG_TRACE( "Enter service mode..." ); + LOG_TRACE("Enter service mode..."); // NOTE: Service mode requires a special starting sequence, different from // the usual download mode state. // Also, the general acknowledge byte is changed to 0x4c 'L'. - assert( _connectMode != SERVICE_MODE ); + assert(_connectMode != SERVICE_MODE); - if( _connectMode == CLOSED_MODE ) - { - _serial.open( Settings::port, emulatorName); + if (_connectMode == CLOSED_MODE) { + _serial.open(Settings::port, emulatorName); _serial.sleep(333); // Initial 1/3 sec before trying service mode... } - for(int retry=0; retry < 10; ++retry) - { - unsigned char serviceMode[] = { 0xAA, 0xAB, 0xCD, 0xEF }; + for (int retry = 0; retry < 10; ++retry) { + unsigned char serviceMode[] = {0xAA, 0xAB, 0xCD, 0xEF}; try { _serial.writeBlock(serviceMode, sizeof serviceMode); - } - catch(const WriteTimeout&) { + } catch (const WriteTimeout &) { // Bluetooth not present: one can open the pseudo COM port, // but we will have a timeout on first write byte... - if( retry < 9 ) { - LOG_INFO("Cannot connect to " << Settings::port <<" (" << (retry+1) << "/10)..."); + if (retry < 9) { + LOG_INFO("Cannot connect to " << Settings::port << " (" << (retry + 1) << "/10)..."); _serial.sleep(1000); continue; } @@ -529,31 +521,30 @@ unsigned char echo = 0; try { echo = _serial.readByte(); + } catch (...) { } - catch(...) {} - if( echo != 0x4b ) { -serviceModeFailed: - if( retry < 9 ) - { + if (echo != 0x4b) { + serviceModeFailed: + if (retry < 9) { _serial.purge(); _serial.sleep(400); continue; } - LOG_THROW("Unable to enter " << model() <<" service mode"); + LOG_THROW("Unable to enter " << model() << " service mode"); } echo = _serial.readByte(); - if( echo != 0xAB ) + if (echo != 0xAB) goto serviceModeFailed; echo = _serial.readByte(); - if( echo != 0xCD ) + if (echo != 0xCD) goto serviceModeFailed; echo = _serial.readByte(); - if( echo != 0xEF ) + if (echo != 0xEF) goto serviceModeFailed; echo = _serial.readByte(); - if( echo != 0x4c ) // SERVICE modes only. + if (echo != 0x4c) // SERVICE modes only. goto serviceModeFailed; break; } @@ -583,14 +574,12 @@ LOG_INFO("Uploading firmware."); writeText(" Uploading..."); - for(int len = 0x00000; len < FIRMWARE_SIZE; len += FIRMWARE_BLOCK) - { + for (int len = 0x00000; len < FIRMWARE_SIZE; len += FIRMWARE_BLOCK) { unsigned char percent = int(len * 100.0f / FIRMWARE_SIZE + 0.5f); - writeText( QString(" Uploading %1%") - .arg(percent, 2) ); + writeText(QString(" Uploading %1%").arg(percent, 2)); PROGRESS(percent, 100); - writeBlock(FIRMWARE_AREA+len, hex.data()+len, FIRMWARE_BLOCK); + writeBlock(FIRMWARE_AREA + len, hex.data() + len, FIRMWARE_BLOCK); } PROGRESS(100, 100); @@ -598,24 +587,21 @@ LOG_INFO("Verify firmware."); writeText(" Verifying..."); { - unsigned char* buffer = new unsigned char[FIRMWARE_SIZE]; + unsigned char *buffer = new unsigned char[FIRMWARE_SIZE]; Q_CHECK_PTR(buffer); - for(int len = 0x00000; len < FIRMWARE_SIZE; len += FIRMWARE_BLOCK) - { + for (int len = 0x00000; len < FIRMWARE_SIZE; len += FIRMWARE_BLOCK) { unsigned char percent = int(len * 100.0f / FIRMWARE_SIZE + 0.5f); - writeText( QString(" Verifying %1%") - .arg(percent, 2) ); + writeText(QString(" Verifying %1%").arg(percent, 2)); PROGRESS(percent, 100); - readBlock(FIRMWARE_AREA+len, buffer+len, FIRMWARE_BLOCK); + readBlock(FIRMWARE_AREA + len, buffer + len, FIRMWARE_BLOCK); } PROGRESS(100, 100); qApp->processEvents(QEventLoop::ExcludeUserInputEvents, 10); - for(int i=0; i<FIRMWARE_SIZE; ++i) - if( buffer[i] != hex.data()[i] ) - { + for (int i = 0; i < FIRMWARE_SIZE; ++i) + if (buffer[i] != hex.data()[i]) { writeText(" Verify FAILED"); LOG_THROW("readback is different"); } @@ -627,7 +613,7 @@ //---- Flashing firmware ------------------------------------------------- LOG_INFO("Programming."); writeText(" Programming..."); - upgradeFirmware( hex.checksum() ); + upgradeFirmware(hex.checksum()); //---- Done -------------------------------------------------------------- // Low-level close, to avoid trying to send a 0xFF byte... @@ -637,7 +623,7 @@ PROGRESS_RESET(); } -void OSTC3Operations::loadFirmware(HexFile& hex, const QString& fileName) const +void OSTC3Operations::loadFirmware(HexFile &hex, const QString &fileName) const { hex.allocate(FIRMWARE_SIZE); hex.loadEncrypted(fileName, ostc3SecretKey); @@ -660,8 +646,7 @@ HardwareOperations::CompanionFeatures OSTC3Operations::supported() const { // No ICON, no DUMPSCREEN, no VPM - return CompanionFeatures(PARAMETERS|DATE|NAME|FIRMWARE - |HELIUM_DIVE|CCR_DIVE); + return CompanionFeatures(PARAMETERS | DATE | NAME | FIRMWARE | HELIUM_DIVE | CCR_DIVE); } ////////////////////////////////////////////////////////////////////////////// @@ -669,20 +654,20 @@ { return; } -void OSTC3Operations::getAllHeader(unsigned char* pBuffer) +void OSTC3Operations::getAllHeader(unsigned char *pBuffer) { return; } -void OSTC3Operations::writeAllHeader(unsigned char* pBuffer) +void OSTC3Operations::writeAllHeader(unsigned char *pBuffer) { return; } -void OSTC3Operations::getAllSamples(unsigned char* pBuffer) +void OSTC3Operations::getAllSamples(unsigned char *pBuffer) { return; } -void OSTC3Operations::writeAllSamples(unsigned char* pBuffer) +void OSTC3Operations::writeAllSamples(unsigned char *pBuffer) { return; }
--- a/OSTC3Operations.h Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC3Operations.h Mon Jan 12 13:51:17 2026 +0000 @@ -49,13 +49,12 @@ /// /// \sa OSTCSportOperations, OSTC2Operations, OSTC3pOperations, /// OSTC4Operations, OSTCcROperations. -class OSTC3Operations - : public HardwareOperations +class OSTC3Operations : public HardwareOperations { ////////////////////////////////////////////////////////////////////////// /// \{ \section Configuration management. - // QRegExp portTemplate() const override; + // QRegExp portTemplate() const override; QRegularExpression portTemplate() const override; QStringList listPorts() const override; QString model() const override; @@ -65,7 +64,6 @@ /// \} ////////////////////////////////////////////////////////////////////////// protected: - //------------------------------------------------------------------------ /// \brief Erase OSTC3 PROM memory. /// PROM memory should be erased beforeprogramming the new firmware. @@ -82,8 +80,7 @@ /// \param[in] data: Bytes to write. /// \param[in] size: Number of bytes to write. /// \throws if something goes wrong. - void writeBlock(unsigned int addr, - const unsigned char *data, unsigned int size); + void writeBlock(unsigned int addr, const unsigned char *data, unsigned int size); //------------------------------------------------------------------------ /// \brief Read-back a big block of bytes from OSTC3 RAM memory. @@ -92,7 +89,7 @@ /// \param[in] ptr : Where to store bytes read. /// \param[in] size: Number of bytes to read. /// \throws if something goes wrong. - void readBlock (unsigned int addr, unsigned char *ptr, unsigned int size); + void readBlock(unsigned int addr, unsigned char *ptr, unsigned int size); //------------------------------------------------------------------------ /// \brief Burn firmare. @@ -152,26 +149,26 @@ bool connect() override; bool disconnect(bool closing = false) override; - void setDate(const QDateTime& date) override; - void setName(const QString& newName) override; + void setDate(const QDateTime &date) override; + void setName(const QString &newName) override; void getSignal() override; - void getAllHeader(unsigned char* pBuffer) override; - void writeAllHeader(unsigned char* pBuffer) override; - void getAllSamples(unsigned char* pBuffer) override; - void writeAllSamples(unsigned char* pBuffer) override; - void setIcons(const QString& fileName) override; + void getAllHeader(unsigned char *pBuffer) override; + void writeAllHeader(unsigned char *pBuffer) override; + void getAllSamples(unsigned char *pBuffer) override; + void writeAllSamples(unsigned char *pBuffer) override; + void setIcons(const QString &fileName) override; QImage dumpScreen() const override; - void upgradeFW(const QString& fileName) override; + void upgradeFW(const QString &fileName) override; - void loadFirmware(HexFile& hex, const QString& fileName) const override; + void loadFirmware(HexFile &hex, const QString &fileName) const override; /// \} ////////////////////////////////////////////////////////////////////////// protected: - QString descriptionString; - QString emulatorName; - char computerText[60]; + QString descriptionString; + QString emulatorName; + char computerText[60]; virtual void getCommonIdentity(); @@ -184,9 +181,9 @@ protected: enum Mode { - CLOSED_MODE = 0, ///< Not yet open. - DOWNLOAD_MODE, ///< Open in normal mode. - SERVICE_MODE ///< Open in FIRMWARE UPGRADE mode. + CLOSED_MODE = 0, ///< Not yet open. + DOWNLOAD_MODE, ///< Open in normal mode. + SERVICE_MODE ///< Open in FIRMWARE UPGRADE mode. } _connectMode; };
--- a/OSTC3pOperations.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC3pOperations.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -36,8 +36,8 @@ ////////////////////////////////////////////////////////////////////////////// #include "OSTC3pOperations.h" +#include <QRegularExpression> #include "Utils/Log.h" -#include <QRegularExpression> ////////////////////////////////////////////////////////////////////////////// @@ -62,8 +62,8 @@ LOG_TRACE("Getting model..."); HardwareDescriptor hw = hardwareDescriptor(); -// if( hw != HW_OSTC3p_a && hw != HW_OSTC3p_b ) - // LOG_THROW("Not an OSTC3+."); + // if( hw != HW_OSTC3p_a && hw != HW_OSTC3p_b ) + // LOG_THROW("Not an OSTC3+."); LOG_TRACE("Getting identity..."); getCommonIdentity(); @@ -88,8 +88,8 @@ HardwareOperations::CompanionFeatures OSTC3pOperations::supported() const { // No ICON, no DUMPSCREEN, no VPM - return CompanionFeatures(PARAMETERS|DATE|NAME|FIRMWARE - |HELIUM_DIVE|CCR_DIVE|BLUETOOTH); + return CompanionFeatures(PARAMETERS | DATE | NAME | FIRMWARE | HELIUM_DIVE | CCR_DIVE + | BLUETOOTH); } #if 0 QRegExp OSTC3pOperations::portTemplate() const @@ -110,13 +110,12 @@ QRegularExpression OSTC3pOperations::portTemplate() const { #if defined(Q_OS_MAC) - return QRegularExpression("tty.OSTC[0-9][0-9]+.*", - QRegularExpression::CaseInsensitiveOption); + return QRegularExpression("tty.OSTC[0-9][0-9]+.*", QRegularExpression::CaseInsensitiveOption); #elif defined(Q_OS_LINUX) // Debian, Ubuntu, RedHat, CentOS, SUSE return QRegularExpression("ttyUSB.*"); // default: case-sensitive #elif defined(Q_OS_WIN) - return QRegularExpression("COM.*"); // default: case-sensitive + return QRegularExpression("COM.*"); // default: case-sensitive #endif }
--- a/OSTC3pOperations.h Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC3pOperations.h Mon Jan 12 13:51:17 2026 +0000 @@ -42,14 +42,13 @@ #include "OSTC3Operations.h" -class OSTC3pOperations - : public OSTC3Operations +class OSTC3pOperations : public OSTC3Operations { // Re-implemented various stuff QStringList listPorts() const override; HardwareOperations::CompanionFeatures supported() const override; QString firmwareTemplate() const override; - // QRegExp portTemplate() const override; + // QRegExp portTemplate() const override; QRegularExpression portTemplate() const override; QString model() const override; void getIdentity() override;
--- a/OSTCFrogOperations.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTCFrogOperations.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -36,8 +36,8 @@ #include "OSTCFrogOperations.h" +#include "Utils/Exception.h" #include "Utils/Log.h" -#include "Utils/Exception.h" #include "HexFile.h" #include "SettingsDialog.h" @@ -48,30 +48,29 @@ #include <QStringList> // Byte extration, compatible littleendian or bigendian. -#define LOW(x) ((unsigned char)((x) % 256)) -#define HIGH(x) ((unsigned char)((x / (1<<8)) % 256)) -#define UPPER(x) ((unsigned char)((x / (1<<16)) % 256)) -#define UP32(x) ((unsigned char)((x / (1<<24)) % 256)) +#define LOW(x) ((unsigned char) ((x) % 256)) +#define HIGH(x) ((unsigned char) ((x / (1 << 8)) % 256)) +#define UPPER(x) ((unsigned char) ((x / (1 << 16)) % 256)) +#define UP32(x) ((unsigned char) ((x / (1 << 24)) % 256)) -#define IMAGE_ROUNDING 1024 -#define FIRMWARE_AREA 0x3E0000 -#define FIRMWARE_SIZE 0x01D000 +#define IMAGE_ROUNDING 1024 +#define FIRMWARE_AREA 0x3E0000 +#define FIRMWARE_SIZE 0x01D000 -extern QProgressBar* progress; +extern QProgressBar *progress; ////////////////////////////////////////////////////////////////////////////// OSTCFrogOperations::OSTCFrogOperations() - : _firmware(0), - _serialNumber(0), - _isOpen(false), - _commandMode(false) -{ -} + : _firmware(0) + , _serialNumber(0) + , _isOpen(false) + , _commandMode(false) +{} OSTCFrogOperations::~OSTCFrogOperations() { - if( _isOpen ) + if (_isOpen) disconnect(true); } @@ -82,6 +81,7 @@ ////////////////////////////////////////////////////////////////////////////// //QRegExp OSTCFrogOperations::portTemplate() const +#if 0 QRegularExpression OSTCFrogOperations::portTemplate() const { #if defined(Q_OS_MAC) @@ -92,14 +92,25 @@ // a list of connected stuff... return QRegExp("rfcomm.*", Qt::CaseInsensitive); #elif defined(Q_OS_WIN) -// return QRegExp("COM.*", Qt::CaseSensitive); - return QRegularExpression( - "COM([0-9]+)", - QRegularExpression::CaseInsensitiveOption - ); + // return QRegExp("COM.*", Qt::CaseSensitive); + return QRegularExpression("COM([0-9]+)", QRegularExpression::CaseInsensitiveOption); #endif } - +#endif +QRegularExpression OSTCFrogOperations::portTemplate() const +{ +#if defined(Q_OS_MAC) + // Mac-spezifischer regulärer Ausdruck + return QRegularExpression("tty[.]frog.*", QRegularExpression::CaseInsensitiveOption); +#elif defined(Q_OS_LINUX) + // Linux-spezifischer regulärer Ausdruck für rfcomm + // Funktioniert für Debian, Ubuntu, und SUSE (wie von Google beschrieben) + return QRegularExpression("rfcomm.*", QRegularExpression::CaseInsensitiveOption); +#elif defined(Q_OS_WIN) + // Windows-spezifischer regulärer Ausdruck für COM-Ports + return QRegularExpression("COM([0-9]+)", QRegularExpression::CaseInsensitiveOption); +#endif +} QStringList OSTCFrogOperations::listPorts() const { return listBluetoothPorts(); @@ -129,34 +140,34 @@ HardwareOperations::CompanionFeatures OSTCFrogOperations::supported() const { // No ICON, no PARAMETER, no FIRMWARE, no DUMPSCREEN yet... - return CompanionFeatures(NAME|DATE); + return CompanionFeatures(NAME | DATE); } bool OSTCFrogOperations::connect() { try { //---- Open the serial port------------------------------------------- - LOG_TRACE( QString("Open port %1...").arg(Settings::port) ); + LOG_TRACE(QString("Open port %1...").arg(Settings::port)); _isOpen = false; //---- Execute the start protocol ------------------------------------ static char animation[] = "/-\\|"; int reply = 0; - for(int retry=0; retry < 30; ++retry) { - _serial.open( Settings::port, "Frog"); + for (int retry = 0; retry < 30; ++retry) { + _serial.open(Settings::port, "Frog"); _serial.sleep(100); _serial.purge(); _serial.writeByte(0xBB); try { reply = _serial.readByte(); - if( reply == 0x4D ) + if (reply == 0x4D) break; + } catch (...) { } - catch(...) {} - LOG_TRACE( QString("Starting... %1").arg(animation[retry % sizeof animation])); + LOG_TRACE(QString("Starting... %1").arg(animation[retry % sizeof animation])); } - if( reply != 0x4D ) + if (reply != 0x4D) LOG_THROW("Not started"); //---- Enquire about Frog id ----------------------------------------- @@ -165,8 +176,7 @@ //---- Everything is ok ---------------------------------------------- _isOpen = true; return true; - } - catch(const Exception& e) { + } catch (const Exception &e) { _serial.close(); LOG_THROW("Cannot connect " << Settings::port << ": " << e.what()); } @@ -181,7 +191,8 @@ bool OSTCFrogOperations::disconnect(bool /*closing*/) { - if( !_isOpen ) return false; + if (!_isOpen) + return false; _serial.purge(); _serial.writeByte(0xFF); @@ -190,7 +201,7 @@ _serial.purge(); _serial.close(); - _description.clear(); // cleanup for interface updateStatus() + _description.clear(); // cleanup for interface updateStatus() _isOpen = false; return true; @@ -204,40 +215,40 @@ void OSTCFrogOperations::beginCommands() { - Q_ASSERT( !_commandMode ); + Q_ASSERT(!_commandMode); static char animation[] = "/-\\|"; - for(int i=0;; ++i) - { - if( i == 100 ) // 20.0 sec loop ? + for (int i = 0;; ++i) { + if (i == 100) // 20.0 sec loop ? LOG_THROW("Bad reply to open command"); _serial.sleep(100); _serial.purge(); - _serial.writeByte(0xAA); // Start byte + _serial.writeByte(0xAA); // Start byte int reply = 0; try { reply = _serial.readByte(); - } catch(...) {} - if( reply == 0x4B ) + } catch (...) { + } + if (reply == 0x4B) goto Started; - LOG_TRACE(QString("Connecting %1") - .arg(animation[i%4])); + LOG_TRACE(QString("Connecting %1").arg(animation[i % 4])); _serial.sleep(200); continue; -Started: + Started: unsigned char buffer[] = "\xAA\xAB\xAC"; _serial.writeBlock(buffer, 3); try { unsigned char reply = _serial.readByte(); - if( reply == 0x4C ) { + if (reply == 0x4C) { _commandMode = true; return; } - } catch(...) {} + } catch (...) { + } _serial.sleep(200); } @@ -247,15 +258,15 @@ void OSTCFrogOperations::endCommands() { - Q_ASSERT( _commandMode ); + Q_ASSERT(_commandMode); _serial.sleep(100); _serial.purge(); - _serial.writeByte(0xFF); // Exit service mode + _serial.writeByte(0xFF); // Exit service mode _serial.sleep(10); unsigned char buffer = _serial.readByte(); - if( buffer != 0xFF ) + if (buffer != 0xFF) LOG_THROW("End failed"); _commandMode = false; @@ -266,42 +277,40 @@ void OSTCFrogOperations::eraseRange(unsigned int addr, unsigned int size) { - Q_ASSERT( _commandMode ); + Q_ASSERT(_commandMode); // Convert size to number of pages, rounded up. size = ((size + 4095) / 4096); - if( size < 256 || addr != 0x300000 ) - { + if (size < 256 || addr != 0x300000) { unsigned char buffer[4]; // Erase just the needed pages. buffer[0] = UPPER(addr); buffer[1] = HIGH(addr); buffer[2] = LOW(addr); buffer[3] = LOW(size); - _serial.writeByte(0x42); // Command + _serial.writeByte(0x42); // Command _serial.sleep(10); _serial.writeBlock(buffer, 4); // Wait (120/4)ms by block of 4K, plus 3% VAT to be sure. _serial.sleep(40 + size * 31); - } - else - { + } else { // Erase the whole 512KB of icon memory... _serial.writeByte(0x41); _serial.sleep(3000); } try { - (void)_serial.readByte(); - } catch(...) {} + (void) _serial.readByte(); + } catch (...) { + } } ////////////////////////////////////////////////////////////////////////////// void OSTCFrogOperations::startWrite(unsigned int addr) { - Q_ASSERT( _commandMode ); + Q_ASSERT(_commandMode); unsigned char buffer[3]; buffer[0] = UPPER(addr); @@ -319,23 +328,21 @@ void OSTCFrogOperations::stopWrite() { - Q_ASSERT( _commandMode ); + Q_ASSERT(_commandMode); _serial.flush(); _serial.sleep(200); // Should be > 100ms. unsigned char reply = _serial.readByte(); - if( reply != 0x4C ) + if (reply != 0x4C) LOG_THROW("stopWrite"); } ////////////////////////////////////////////////////////////////////////////// -void OSTCFrogOperations::readBytes(unsigned int addr, - unsigned char* ptr, - unsigned int size) +void OSTCFrogOperations::readBytes(unsigned int addr, unsigned char *ptr, unsigned int size) { - Q_ASSERT( _commandMode ); + Q_ASSERT(_commandMode); unsigned char buffer[6]; buffer[0] = UPPER(addr); @@ -352,11 +359,11 @@ _serial.sleep(10); unsigned int len = _serial.readBlock(ptr, size); - if( len < size ) + if (len < size) LOG_THROW("readBytes too short"); unsigned char reply = _serial.readByte(); - if( reply != 0x4C ) + if (reply != 0x4C) LOG_THROW("readBytes"); } @@ -370,52 +377,52 @@ { //---- get model HardwareDescriptor hw = hardwareDescriptor(); - if( hw != HW_UNKNOWN_OSTC && hw != HW_Frog ) + if (hw != HW_UNKNOWN_OSTC && hw != HW_Frog) LOG_THROW("Not a Frog."); //---- get identity - _serial.sleep(100); // Make sure last command is finished. + _serial.sleep(100); // Make sure last command is finished. _serial.purge(); _serial.writeByte('i'); // 0x63 - unsigned char buffer[1+2+2+13+1] = {0}; + unsigned char buffer[1 + 2 + 2 + 13 + 1] = {0}; unsigned len = _serial.readBlock(buffer, sizeof buffer); - if( len != sizeof buffer || buffer[0] != 'i' || buffer[18] != 0x4D ) + if (len != sizeof buffer || buffer[0] != 'i' || buffer[18] != 0x4D) LOG_THROW("get identity data"); - _serialNumber = buffer[1] + buffer[2]*256; - _firmware = buffer[3]*256 + buffer[4]; + _serialNumber = buffer[1] + buffer[2] * 256; + _firmware = buffer[3] * 256 + buffer[4]; - _description = QString("%1 #%2, v%3.%4, %5") - .arg(model()) - .arg(_serialNumber, 4, 10, QChar('0')) - .arg(_firmware / 256).arg(_firmware % 256) - .arg( QString::fromLatin1((char*)buffer+5, 13) - .replace(QChar('\0'), "") - .trimmed() ); + _description + = QString("%1 #%2, v%3.%4, %5") + .arg(model()) + .arg(_serialNumber, 4, 10, QChar('0')) + .arg(_firmware / 256) + .arg(_firmware % 256) + .arg(QString::fromLatin1((char *) buffer + 5, 13).replace(QChar('\0'), "").trimmed()); LOG_TRACE("Found " << _description); } ////////////////////////////////////////////////////////////////////////////// -void OSTCFrogOperations::writeText(const QString& _msg) +void OSTCFrogOperations::writeText(const QString &_msg) { // Pad to 15 chars: QByteArray ascii = (_msg + QString(15, QChar(' '))).left(15).toLatin1(); - _serial.sleep(100); // Make sure last command is finished. + _serial.sleep(100); // Make sure last command is finished. _serial.purge(); - _serial.writeByte('n'); // 0x6E + _serial.writeByte('n'); // 0x6E unsigned char reply = _serial.readByte(); - if( reply != 'n' ) + if (reply != 'n') LOG_THROW("message start"); - _serial.writeBlock((unsigned char *)ascii.constData(), 15); + _serial.writeBlock((unsigned char *) ascii.constData(), 15); reply = _serial.readByte(); - if( reply != 0x4D ) + if (reply != 0x4D) LOG_THROW("message end"); } @@ -431,17 +438,17 @@ buffer[4] = date.date().day(); buffer[5] = date.date().year() % 100; - _serial.sleep(100); // Make sure last command is finished. + _serial.sleep(100); // Make sure last command is finished. _serial.purge(); _serial.writeByte('b'); // 0x62 unsigned char reply = _serial.readByte(); - if( reply != 'b' ) + if (reply != 'b') LOG_THROW("sync time"); - _serial. writeBlock( buffer, sizeof buffer); + _serial.writeBlock(buffer, sizeof buffer); reply = _serial.readByte(); - if( reply != 0x4D ) + if (reply != 0x4D) LOG_THROW("sync time end"); writeText("Set " + date.toString("MM/dd hh:mm")); @@ -458,19 +465,19 @@ void OSTCFrogOperations::setName(const QString &newName) { - QByteArray padded = (newName+QString(13, QChar(' '))).left(13).toLatin1(); + QByteArray padded = (newName + QString(13, QChar(' '))).left(13).toLatin1(); - _serial.sleep(100); // Make sure last command is finished. + _serial.sleep(100); // Make sure last command is finished. _serial.purge(); - _serial.writeByte('c'); // 0x63 + _serial.writeByte('c'); // 0x63 unsigned char reply = _serial.readByte(); - if( reply != 'c' ) + if (reply != 'c') LOG_THROW("set custom text"); - _serial.writeBlock((unsigned char*)padded.constData(), 13); + _serial.writeBlock((unsigned char *) padded.constData(), 13); reply = _serial.readByte(); - if( reply != 0x4D ) + if (reply != 0x4D) LOG_THROW("custom text end"); // Re-read new name: @@ -480,7 +487,7 @@ ////////////////////////////////////////////////////////////////////////////// -void OSTCFrogOperations::setIcons(const QString &/*fileName*/) +void OSTCFrogOperations::setIcons(const QString & /*fileName*/) { // beginCommands(); // eraseRange(0x000000, 0x00000); @@ -488,7 +495,7 @@ // stopWrite(); // endCommands(); - LOG_THROW( "Set icons: Not yet implemented." ); + LOG_THROW("Set icons: Not yet implemented."); } int OSTCFrogOperations::firmware() const @@ -508,12 +515,8 @@ /////////////////////////////////////////////////////////////////////////////// -static unsigned char frogSecretKey[16] = { - 111, 85, 190, 69, - 108,254, 242, 19, - 231, 49, 248,255, - 233, 48, 176,241 -}; +static unsigned char frogSecretKey[16] + = {111, 85, 190, 69, 108, 254, 242, 19, 231, 49, 248, 255, 233, 48, 176, 241}; void OSTCFrogOperations::loadFirmware(HexFile &hex, const QString &fileName) const { @@ -545,18 +548,22 @@ // Compute magic checksum's checksum. buffer[4] = 0x55; - buffer[4] ^= buffer[0]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); - buffer[4] ^= buffer[1]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); - buffer[4] ^= buffer[2]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); - buffer[4] ^= buffer[3]; buffer[4] =(buffer[4]<<1 | buffer[4]>>7); + buffer[4] ^= buffer[0]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); + buffer[4] ^= buffer[1]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); + buffer[4] ^= buffer[2]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); + buffer[4] ^= buffer[3]; + buffer[4] = (buffer[4] << 1 | buffer[4] >> 7); - _serial.sleep(100); // Make sure last command is finished. + _serial.sleep(100); // Make sure last command is finished. _serial.purge(); _serial.writeByte('P'); // 0x50 unsigned char reply = _serial.readByte(); - if( reply != 'P' ) - LOG_THROW( "Programming start" ); + if (reply != 'P') + LOG_THROW("Programming start"); _serial.writeBlock(buffer, sizeof buffer); _serial.sleep(4000); @@ -565,10 +572,8 @@ // with ot without reprogramming... _serial.close(); _isOpen = false; - } - catch(const Exception& e) { - LOG_TRACE(QString("Cannot upgrade: <font color='red'>%1</font>") - .arg(e.what())); + } catch (const Exception &e) { + LOG_TRACE(QString("Cannot upgrade: <font color='red'>%1</font>").arg(e.what())); // Unknown state: so make a hard cleanup: _commandMode = false;
--- a/OSTCFrogOperations.h Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTCFrogOperations.h Mon Jan 12 13:51:17 2026 +0000 @@ -42,14 +42,13 @@ #include "HardwareOperations.h" -class OSTCFrogOperations - : public HardwareOperations +class OSTCFrogOperations : public HardwareOperations { - int _firmware; - int _serialNumber; + int _firmware; + int _serialNumber; QString _description; - bool _isOpen; - bool _commandMode; + bool _isOpen; + bool _commandMode; //---- Low level commands void beginCommands(); @@ -59,7 +58,6 @@ void stopWrite(); void readBytes(unsigned int addr, unsigned char *ptr, unsigned int size); - //---- Port management //QRegExp portTemplate() const override; QRegularExpression portTemplate() const override; @@ -71,15 +69,15 @@ void connectServiceMode() override; void getIdentity() override; void writeText(const QString &_msg) override; - void setDate(const QDateTime& date) override; + void setDate(const QDateTime &date) override; QSize nameSize() const override; - void setName(const QString& newName) override; - void setIcons(const QString& fileName) override; + void setName(const QString &newName) override; + void setIcons(const QString &fileName) override; int firmware() const override; int serialNumber() const override; QString customText() const override; - void loadFirmware(HexFile& hex, const QString& fileName) const override; - void upgradeFW(const QString& fileName) override; + void loadFirmware(HexFile &hex, const QString &fileName) const override; + void upgradeFW(const QString &fileName) override; QString firmwareTemplate() const override; bool disconnect(bool closing = false) override; QString model() const override;
--- a/OSTCSportOperations.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTCSportOperations.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -38,8 +38,8 @@ #include "Utils/Log.h" +#include <QRegularExpression> #include <QStringList> -#include <QRegularExpression> ////////////////////////////////////////////////////////////////////////////// @@ -67,12 +67,10 @@ QRegularExpression OSTCSportOperations::portTemplate() const { #if defined(Q_OS_MAC) - return QRegularExpression("tty.OSTCs.*", - QRegularExpression::CaseInsensitiveOption); + return QRegularExpression("tty.OSTCs.*", QRegularExpression::CaseInsensitiveOption); #elif defined(Q_OS_LINUX) // Debian, Ubuntu, SUSE, benötigt rfcomm-Paket - return QRegularExpression("rfcomm.*", - QRegularExpression::CaseInsensitiveOption); + return QRegularExpression("rfcomm.*", QRegularExpression::CaseInsensitiveOption); #elif defined(Q_OS_WIN) return QRegularExpression("COM.*"); // default: case-sensitive #endif @@ -85,20 +83,20 @@ LOG_TRACE("Getting model..."); HardwareDescriptor hw = hardwareDescriptor(); - if( hw != HW_UNKNOWN_OSTC && hw != HW_OSTCSport_a && hw != HW_OSTCSport_b ) - LOG_THROW( "Not an OSTC Sport." ); + if (hw != HW_UNKNOWN_OSTC && hw != HW_OSTCSport_a && hw != HW_OSTCSport_b) + LOG_THROW("Not an OSTC Sport."); LOG_TRACE("Getting identity..."); getCommonIdentity(); // OTC Sport fw is between 10.00 and 19.99 (coded 100x Hi + Lo) // and serial is between 10.000 and 19.999 - if( hw == HW_UNKNOWN_OSTC - && ( firmware() < 1000 || firmware() > 1999 - || serialNumber() < 10000 || serialNumber() > 20000) ) - LOG_THROW( "Not an OSTC Sport (fw " - << (firmware()/100) << "." << QString::asprintf("%02d", firmware()%100) << ", #" - << serialNumber() << ")."); + if (hw == HW_UNKNOWN_OSTC + && (firmware() < 1000 || firmware() > 1999 || serialNumber() < 10000 + || serialNumber() > 20000)) + LOG_THROW("Not an OSTC Sport (fw " << (firmware() / 100) << "." + << QString::asprintf("%02d", firmware() % 100) << ", #" + << serialNumber() << ")."); hw = HW_OSTCSport_a; LOG_TRACE("Found " << descriptionString); @@ -131,6 +129,5 @@ HardwareOperations::CompanionFeatures OSTCSportOperations::supported() const { // No ICON, no DUMPSCREEN, no HELIUM, no CCR - return CompanionFeatures(PARAMETERS|DATE|NAME|FIRMWARE - |BLUETOOTH); + return CompanionFeatures(PARAMETERS | DATE | NAME | FIRMWARE | BLUETOOTH); }
--- a/OSTCSportOperations.h Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTCSportOperations.h Mon Jan 12 13:51:17 2026 +0000 @@ -42,14 +42,13 @@ //#include <QRegExp> #include <QRegularExpression> -class OSTCSportOperations - : public OSTC3Operations +class OSTCSportOperations : public OSTC3Operations { -// QRegExp portTemplate() const override; + // QRegExp portTemplate() const override; QRegularExpression portTemplate() const override; QStringList listPorts() const override; QString firmwareTemplate() const override; - QSize nameSize() const override; + QSize nameSize() const override; void getIdentity() override; QString model() const override;
--- a/OSTC_CR_Operations.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC_CR_Operations.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -56,8 +56,7 @@ HardwareOperations::CompanionFeatures OSTCcROperations::supported() const { // No ICON, no DUMPSCREEN - return CompanionFeatures(PARAMETERS|DATE|NAME|FIRMWARE - |HELIUM_DIVE|CCR_DIVE); + return CompanionFeatures(PARAMETERS | DATE | NAME | FIRMWARE | HELIUM_DIVE | CCR_DIVE); } void OSTCcROperations::getIdentity() @@ -66,13 +65,13 @@ LOG_TRACE("Getting model..."); HardwareDescriptor hw = hardwareDescriptor(); - if( hw != HW_UNKNOWN_OSTC && hw != HW_OSTCcR_a && hw != HW_OSTCcR_b ) + if (hw != HW_UNKNOWN_OSTC && hw != HW_OSTCcR_a && hw != HW_OSTCcR_b) LOG_THROW("Not an OSTC cR."); LOG_TRACE("Getting identity..."); getCommonIdentity(); - if( hw == HW_UNKNOWN_OSTC && (firmware() > 0x0A00 || serialNumber() > 10000) ) + if (hw == HW_UNKNOWN_OSTC && (firmware() > 0x0A00 || serialNumber() > 10000)) LOG_THROW("Not an OSTC cR"); LOG_TRACE("Found " << descriptionString);
--- a/OSTC_CR_Operations.h Mon Jan 12 13:49:16 2026 +0000 +++ b/OSTC_CR_Operations.h Mon Jan 12 13:51:17 2026 +0000 @@ -44,8 +44,7 @@ ////////////////////////////////////////////////////////////////////////////// /// \brief Implementing various low-level operations for OSTC3-S8 dive computer -class OSTCcROperations - : public OSTC3Operations +class OSTCcROperations : public OSTC3Operations { /// \brief Returns "OSTC_cR" QString model() const override; @@ -57,7 +56,7 @@ /// \throws if something goes wrong. void getIdentity() override; - QString firmwareTemplate() const override; + QString firmwareTemplate() const override; ////////////////////////////////////////////////////////////////////////// public:
--- a/Settings.ui Mon Jan 12 13:49:16 2026 +0000 +++ b/Settings.ui Mon Jan 12 13:51:17 2026 +0000 @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>341</width> - <height>293</height> + <height>306</height> </rect> </property> <property name="windowTitle"> @@ -17,7 +17,7 @@ <item row="10" column="0" colspan="3"> <widget class="Line" name="line_3"> <property name="orientation"> - <enum>Qt::Horizontal</enum> + <enum>Qt::Orientation::Horizontal</enum> </property> </widget> </item> @@ -61,10 +61,10 @@ </sizepolicy> </property> <property name="textFormat"> - <enum>Qt::RichText</enum> + <enum>Qt::TextFormat::RichText</enum> </property> <property name="alignment"> - <set>Qt::AlignCenter</set> + <set>Qt::AlignmentFlag::AlignCenter</set> </property> <property name="openExternalLinks"> <bool>true</bool> @@ -77,7 +77,7 @@ <number>0</number> </property> <property name="insertPolicy"> - <enum>QComboBox::NoInsert</enum> + <enum>QComboBox::InsertPolicy::NoInsert</enum> </property> <item> <property name="text"> @@ -160,7 +160,7 @@ <item> <spacer name="horizontalSpacer_2"> <property name="orientation"> - <enum>Qt::Horizontal</enum> + <enum>Qt::Orientation::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> @@ -204,7 +204,7 @@ <string>Language:</string> </property> <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + <set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set> </property> </widget> </item> @@ -218,7 +218,7 @@ <item row="5" column="0" colspan="3"> <widget class="Line" name="line_4"> <property name="orientation"> - <enum>Qt::Horizontal</enum> + <enum>Qt::Orientation::Horizontal</enum> </property> </widget> </item> @@ -234,17 +234,17 @@ <string>Communication port:</string> </property> <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + <set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set> </property> </widget> </item> <item row="0" column="2"> <spacer name="horizontalSpacer"> <property name="orientation"> - <enum>Qt::Horizontal</enum> + <enum>Qt::Orientation::Horizontal</enum> </property> <property name="sizeType"> - <enum>QSizePolicy::Expanding</enum> + <enum>QSizePolicy::Policy::Expanding</enum> </property> <property name="sizeHint" stdset="0"> <size> @@ -257,7 +257,7 @@ <item row="14" column="0" colspan="3"> <widget class="Line" name="line"> <property name="orientation"> - <enum>Qt::Horizontal</enum> + <enum>Qt::Orientation::Horizontal</enum> </property> </widget> </item>
--- a/SettingsDialog.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/SettingsDialog.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -37,7 +37,7 @@ #include "SettingsDialog.h" #include "ui_Settings.h" -#include "MainWindow.h" // Needed to propagare retranslate() +#include "MainWindow.h" // Needed to propagare retranslate() #include "Utils/Log.h" @@ -50,9 +50,9 @@ #include <QTranslator> #ifdef Q_OS_WIN -# define NOMINMAX 1 -# include <Windows.h> -# undef NOMINMAX +#define NOMINMAX 1 +#include <Windows.h> +#undef NOMINMAX #endif #include "Export.h" @@ -70,14 +70,14 @@ bool EXPORT Settings::useFastMode = false; -extern QSettings* settings; +extern QSettings *settings; ////////////////////////////////////////////////////////////////////////////// -Settings::Settings(QWidget* parent, HardwareOperations *op) - : QDialog(parent), - _ui(new Ui::Settings), - _op(op) +Settings::Settings(QWidget *parent, HardwareOperations *op) + : QDialog(parent) + , _ui(new Ui::Settings) + , _op(op) { _ui->setupUi(this); reload(this); @@ -90,13 +90,12 @@ ////////////////////////////////////////////////////////////////////////////// -void Settings::reload(Settings* dialog) +void Settings::reload(Settings *dialog) { //---- Restore options from settings ------------------------------------- - language = settings->value("Interface/lang", - QLocale::system().name().right(2) ).toString(); - port = settings->value("OSTC/port", "").toString(); - currentPath = settings->value("OSTC/currentPath", "").toString(); + language = settings->value("Interface/lang", QLocale::system().name().right(2)).toString(); + port = settings->value("OSTC/port", "").toString(); + currentPath = settings->value("OSTC/currentPath", "").toString(); autoSetDateTime = settings->value("OSTC/autoSetDateTime", true).toBool(); forceFirmwareUpdate = settings->value("OSTC/forceFirmwareUpdate", false).toBool(); forceRTEUpdate = settings->value("OSTC/forceRTEUpdate", false).toBool(); @@ -106,77 +105,97 @@ setLanguage(); - if( !dialog ) + if (!dialog) return; //---- Update interface -------------------------------------------------- - if( language == "DE" ) dialog->_ui->languageMenu->setCurrentIndex(0); - if( language == "EN" ) dialog->_ui->languageMenu->setCurrentIndex(1); - if( language == "ES" ) dialog->_ui->languageMenu->setCurrentIndex(2); - if( language == "FR" ) dialog->_ui->languageMenu->setCurrentIndex(3); - if( language == "IT" ) dialog->_ui->languageMenu->setCurrentIndex(4); - if( language == "RU" ) dialog->_ui->languageMenu->setCurrentIndex(5); + if (language == "DE") + dialog->_ui->languageMenu->setCurrentIndex(0); + if (language == "EN") + dialog->_ui->languageMenu->setCurrentIndex(1); + if (language == "ES") + dialog->_ui->languageMenu->setCurrentIndex(2); + if (language == "FR") + dialog->_ui->languageMenu->setCurrentIndex(3); + if (language == "IT") + dialog->_ui->languageMenu->setCurrentIndex(4); + if (language == "RU") + dialog->_ui->languageMenu->setCurrentIndex(5); dialog->updatePortsSlot(); - dialog->_ui->autoSetDateTimeCB->setChecked( autoSetDateTime ); - dialog->_ui->forceFirmwareUpdate->setChecked( forceFirmwareUpdate ); - dialog->_ui->forceRTEUpdate->setChecked( forceRTEUpdate ); - dialog->_ui->forceFontlibUpdate->setChecked( forceFontlibUpdate ); - dialog->_ui->useFastMode->setChecked( useFastMode ); - + dialog->_ui->autoSetDateTimeCB->setChecked(autoSetDateTime); + dialog->_ui->forceFirmwareUpdate->setChecked(forceFirmwareUpdate); + dialog->_ui->forceRTEUpdate->setChecked(forceRTEUpdate); + dialog->_ui->forceFontlibUpdate->setChecked(forceFontlibUpdate); + dialog->_ui->useFastMode->setChecked(useFastMode); } ////////////////////////////////////////////////////////////////////////////// void Settings::languageSlot(int i) { - switch(i) { - case 0: language = "DE"; break; - case 1: language = "EN"; break; - case 2: language = "ES"; break; - case 3: language = "FR"; break; - case 4: language = "IT"; break; - case 5: language = "RU"; break; + switch (i) { + case 0: + language = "DE"; + break; + case 1: + language = "EN"; + break; + case 2: + language = "ES"; + break; + case 3: + language = "FR"; + break; + case 4: + language = "IT"; + break; + case 5: + language = "RU"; + break; } setLanguage(); } - void Settings::updatePortsSlot() { //---- search for possible ports ---------------------------------------- QStringList list; - if( _op ) { // Known driver type ? + if (_op) { // Known driver type ? list = _op->listPorts(); #ifndef Q_OS_LINUX - if( list.isEmpty() ) + if (list.isEmpty()) _ui->noPortLabel->setText( QString("<font color='red'>%1</font>: %2 - %3") .arg(tr("Warning")) .arg(tr("no port", "USB connection to OSTC not found")) .arg(tr("Did you installed the %1 driver ?") #ifdef Q_OS_WIN - .arg("<a href='http://www.ftdichip.com/Drivers/CDM/CDM%20v2.12.00%20WHQL%20Certified.zip'>FTDI VCP</a>"))); + .arg("<a " + "href='http://www.ftdichip.com/Drivers/CDM/" + "CDM%20v2.12.00%20WHQL%20Certified.zip'>FTDI VCP</a>"))); #elif defined(Q_OS_MACX) - .arg("<a href='http://www.ftdichip.com/drivers/VCP/MacOSX/FTDIUSBSerialDriver_v2_2_18.dmg'>FTDI VCP</a>"))); + .arg("<a " + "href='http://www.ftdichip.com/drivers/VCP/MacOSX/" + "FTDIUSBSerialDriver_v2_2_18.dmg'>FTDI VCP</a>"))); #else - .arg("USB"))); + .arg("USB"))); #endif else #endif _ui->noPortLabel->clear(); } - QString myPort = port + " (current)"; - if( ! port.isEmpty() ) + QString myPort = port + " (current)"; + if (!port.isEmpty()) list += myPort; list.sort(); _ui->portMenu->clear(); _ui->portMenu->addItems(list); - _ui->portMenu->setCurrentText( port.isEmpty() ? "" : myPort ); + _ui->portMenu->setCurrentText(port.isEmpty() ? "" : myPort); } ////////////////////////////////////////////////////////////////////////////// @@ -184,21 +203,20 @@ void Settings::setLanguage() { static QTranslator myappTranslator; - if( myappTranslator.load(":/Translations/companion_" + language) ) + if (myappTranslator.load(":/Translations/companion_" + language)) qApp->installTranslator(&myappTranslator); } void Settings::changeEvent(QEvent *e) { - if( e->type() == QEvent::LanguageChange ) - { + if (e->type() == QEvent::LanguageChange) { _ui->retranslateUi(this); // FIX: also update the warning text... updatePortsSlot(); // FIX: propagate to main windows. - if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) + if (MainWindow *main = dynamic_cast<MainWindow *>(parent())) main->retranslate(); } } @@ -220,9 +238,9 @@ void Settings::save() { - settings->setValue("Interface/lang", language); - settings->setValue("OSTC/port", port); - settings->setValue("OSTC/currentPath", currentPath); + settings->setValue("Interface/lang", language); + settings->setValue("OSTC/port", port); + settings->setValue("OSTC/currentPath", currentPath); settings->setValue("OSTC/autoSetDateTime", autoSetDateTime); settings->setValue("OSTC/forceFirmwareUpdate", forceFirmwareUpdate); settings->setValue("OSTC/forceRTEUpdate", forceRTEUpdate); @@ -236,7 +254,7 @@ void Settings::reject() { reload(this); - if( MainWindow* main = dynamic_cast<MainWindow*>(parent()) ) + if (MainWindow *main = dynamic_cast<MainWindow *>(parent())) main->retranslate(); QDialog::reject(); }
--- a/SettingsDialog.h Mon Jan 12 13:49:16 2026 +0000 +++ b/SettingsDialog.h Mon Jan 12 13:51:17 2026 +0000 @@ -41,7 +41,9 @@ ////////////////////////////////////////////////////////////////////////////// // Import Qt GUI -namespace Ui { class Settings; } +namespace Ui { +class Settings; +} #include <QDialog> @@ -51,17 +53,16 @@ ////////////////////////////////////////////////////////////////////////////// /// \brief Implement preference dialog for OSTC Companion. -class Settings - : public QDialog +class Settings : public QDialog { Q_OBJECT - Ui::Settings* _ui; - HardwareOperations* _op; + Ui::Settings *_ui; + HardwareOperations *_op; void changeEvent(QEvent *e); public: - Settings(QWidget* parent, HardwareOperations *op); + Settings(QWidget *parent, HardwareOperations *op); ~Settings(); static QString language;
--- a/editlogdialog.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/editlogdialog.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -1,7 +1,7 @@ #include "editlogdialog.h" +#include "MainWindow.h" // Needed to propagare retranslate() +#include "Utils/Log.h" #include "ui_LogEditor.h" -#include "MainWindow.h" // Needed to propagare retranslate() -#include "Utils/Log.h" #include "HardwareOperations.h" @@ -10,37 +10,35 @@ #include <QDir> #include <QLibraryInfo> #include <QPushButton> +#include <QTableWidget> #include <QTranslator> -#include <QTableWidget> - #ifdef Q_OS_WIN -# define NOMINMAX 1 -# include <Windows.h> -# undef NOMINMAX +#define NOMINMAX 1 +#include <Windows.h> +#undef NOMINMAX #endif #define HEADER2OFFSET 0x400 -EditLogDialog::EditLogDialog(QWidget* parent, HardwareOperations *op) - : QDialog(parent), - _ui(new Ui::editLogWnd), - _op(op) +EditLogDialog::EditLogDialog(QWidget *parent, HardwareOperations *op) + : QDialog(parent) + , _ui(new Ui::editLogWnd) + , _op(op) { uint32_t index, index2; uint32_t sizeY = 0; _ui->setupUi(this); - QTableWidget* headerView = _ui->SectorView; - QTableWidget* sampleView = _ui->SampleView; + QTableWidget *headerView = _ui->SectorView; + QTableWidget *sampleView = _ui->SampleView; _ui->textBrowser_2->setTabStopDistance( - QFontMetricsF(_ui->textBrowser_2->font()).horizontalAdvance(' ') * 4 - ); + QFontMetricsF(_ui->textBrowser_2->font()).horizontalAdvance(' ') * 4); headerView->horizontalHeader()->setMinimumSectionSize(8); headerView->verticalHeader()->setMinimumSectionSize(8); headerView->horizontalHeader()->setDefaultSectionSize(8); headerView->verticalHeader()->setDefaultSectionSize(8); - headerView->setColumnWidth(0,8); - headerView->setRowHeight(0,8); + headerView->setColumnWidth(0, 8); + headerView->setRowHeight(0, 8); headerView->horizontalHeader()->hide(); headerView->verticalHeader()->hide(); @@ -48,8 +46,8 @@ sampleView->verticalHeader()->setMinimumSectionSize(8); sampleView->horizontalHeader()->setDefaultSectionSize(8); sampleView->verticalHeader()->setDefaultSectionSize(8); - sampleView->setColumnWidth(0,8); - sampleView->setRowHeight(0,8); + sampleView->setColumnWidth(0, 8); + sampleView->setRowHeight(0, 8); sampleView->horizontalHeader()->hide(); sampleView->verticalHeader()->hide(); @@ -59,38 +57,30 @@ sampleView->setRowCount(12); sampleView->setColumnCount(16); - - HeaderBuffer = new unsigned char[0x8000*8 + 1]; // 64k Headerbuffer + lastDiveindex - SampleBuffer = new unsigned char[0xC00000 + 4]; // 12MB Samplebuffer + nextSampleAddr + HeaderBuffer = new unsigned char[0x8000 * 8 + 1]; // 64k Headerbuffer + lastDiveindex + SampleBuffer = new unsigned char[0xC00000 + 4]; // 12MB Samplebuffer + nextSampleAddr - headerView->resize(8*16+2,8*16+2); - sampleView->resize(8*16+2,8*12+2); - sizeY = (uint32_t)(headerView->geometry().width()) / 16; + headerView->resize(8 * 16 + 2, 8 * 16 + 2); + sampleView->resize(8 * 16 + 2, 8 * 12 + 2); + sizeY = (uint32_t) (headerView->geometry().width()) / 16; - if(sizeY < 8) - { + if (sizeY < 8) { sizeY = 8; } - for(index = 0; index <16; index++) - { - headerView->setColumnWidth(index,sizeY); - headerView->setRowHeight(index,sizeY); - for(index2 = 0; index2 < 16; index2++) - { - + for (index = 0; index < 16; index++) { + headerView->setColumnWidth(index, sizeY); + headerView->setRowHeight(index, sizeY); + for (index2 = 0; index2 < 16; index2++) { item[index * 16 + index2] = new QTableWidgetItem(" "); headerView->setItem(index, index2, item[index * 16 + index2]); } } - for(index = 0; index <12; index++) - { - sampleView->setColumnWidth(index,sizeY); - sampleView->setRowHeight(index,sizeY); - for(index2 = 0; index2 < 16; index2++) - { - + for (index = 0; index < 12; index++) { + sampleView->setColumnWidth(index, sizeY); + sampleView->setRowHeight(index, sizeY); + for (index2 = 0; index2 < 16; index2++) { sampleitem[index * 16 + index2] = new QTableWidgetItem(" "); sampleView->setItem(index, index2, sampleitem[index * 16 + index2]); } @@ -101,19 +91,16 @@ sampleView->show(); sampleView->setShowGrid(true); - } EditLogDialog::~EditLogDialog() { uint32_t index; - for(index = 0; index <256; index++) - { + for (index = 0; index < 256; index++) { delete item[index]; } - for(index = 0; index <192; index++) - { + for (index = 0; index < 192; index++) { delete sampleitem[index]; } delete _ui; @@ -121,7 +108,6 @@ delete SampleBuffer; } - void EditLogDialog::on_WriteAllHeader_clicked() { _op->writeAllHeader(HeaderBuffer); @@ -129,74 +115,59 @@ void EditLogDialog::on_pushButton_clicked() { - Q_ASSERT( _op ); + Q_ASSERT(_op); HeaderBuffer[0] = 0; try { - LOG_INFO(tr("Request All Headers...")); - _op->getAllHeader(HeaderBuffer); + LOG_INFO(tr("Request All Headers...")); + _op->getAllHeader(HeaderBuffer); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); - } - if(HeaderBuffer[0] != 0) - { + if (HeaderBuffer[0] != 0) { LOG_INFO(tr("Got something")); updateHeaderStatus(); } } - - -void EditLogDialog::on_HeaderUsage_valueChanged(int value) -{ - -} +void EditLogDialog::on_HeaderUsage_valueChanged(int value) {} void EditLogDialog::on_ReadAllSamples_clicked() { try { - LOG_INFO(tr("Request All Samples...")); - _op->getAllSamples(SampleBuffer); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + LOG_INFO(tr("Request All Samples...")); + _op->getAllSamples(SampleBuffer); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } void EditLogDialog::on_WriteAllSamples_clicked() { try { - LOG_INFO(tr("Request All Samples...")); - _op->writeAllSamples(SampleBuffer); - } - catch(const std::exception& e) { - LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") - .arg(tr("Error")) - .arg(e.what()) ); + LOG_INFO(tr("Request All Samples...")); + _op->writeAllSamples(SampleBuffer); + } catch (const std::exception &e) { + LOG_INFO( + QString("<bg><font color='red'>%1</font></color>: %2").arg(tr("Error")).arg(e.what())); } } void EditLogDialog::on_pushButton_2_clicked() { qint64 length; - QFile dumpFile; - dumpFile.setFileName("Log_Dump.bin"); - if( ! dumpFile.open(QIODevice::WriteOnly) ) - { - LOG_THROW( "Cannot create dump file " ); - } - else - { - length = 0x8000*8 + 1; - dumpFile.write((const char*)HeaderBuffer,length); + QFile dumpFile; + dumpFile.setFileName("Log_Dump.bin"); + if (!dumpFile.open(QIODevice::WriteOnly)) { + LOG_THROW("Cannot create dump file "); + } else { + length = 0x8000 * 8 + 1; + dumpFile.write((const char *) HeaderBuffer, length); length = 0xC00000 + 4; - dumpFile.write((const char*)SampleBuffer,length); + dumpFile.write((const char *) SampleBuffer, length); dumpFile.close(); } } @@ -204,18 +175,15 @@ void EditLogDialog::on_LoadDump_clicked() { qint64 length; - QFile dumpFile; - dumpFile.setFileName("Log_Dump.bin"); - if( ! dumpFile.open(QIODevice::ReadOnly) ) - { - LOG_THROW( "Cannot read dump file " ); - } - else - { - length = 0x8000*8 + 1; - dumpFile.read((char*)HeaderBuffer,length); + QFile dumpFile; + dumpFile.setFileName("Log_Dump.bin"); + if (!dumpFile.open(QIODevice::ReadOnly)) { + LOG_THROW("Cannot read dump file "); + } else { + length = 0x8000 * 8 + 1; + dumpFile.read((char *) HeaderBuffer, length); length = 0xC00000 + 4; - dumpFile.read((char*)SampleBuffer,length); + dumpFile.read((char *) SampleBuffer, length); dumpFile.close(); updateHeaderStatus(); @@ -225,186 +193,171 @@ void EditLogDialog::updateHeaderStatus() { - QProgressBar* w = _ui->HeaderUsage; - QTableWidget* sv = _ui->SectorView; - SLogbookHeader* LogInfo; - SSmallHeader* smallHeader; + QProgressBar *w = _ui->HeaderUsage; + QTableWidget *sv = _ui->SectorView; + SLogbookHeader *LogInfo; + SSmallHeader *smallHeader; unsigned char HeaderInUse = 0; uint32_t index, index2; uint32_t sampleStartAddr, sampleEndAddr, sampleLength; int row; int colum; - for(index = 0; index < 16; index++) - { - for(index2 = 0; index2 < 16; index2++) - { - if((HeaderBuffer[(0x800 * (index * 16 + index2 )) + HEADER2OFFSET] == 0xFA) - && (HeaderBuffer[(0x800 * (index * 16 + index2 )) + HEADER2OFFSET + 1] == 0xFA)) - { + for (index = 0; index < 16; index++) { + for (index2 = 0; index2 < 16; index2++) { + if ((HeaderBuffer[(0x800 * (index * 16 + index2)) + HEADER2OFFSET] == 0xFA) + && (HeaderBuffer[(0x800 * (index * 16 + index2)) + HEADER2OFFSET + 1] == 0xFA)) { HeaderInUse++; - LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (index*16+index2))+0x400); - sampleEndAddr = (LogInfo->profileLength[2]<<16) + (LogInfo->profileLength[1]<<8) + LogInfo->profileLength[0]; - if( sampleEndAddr == 0) - { - sv->item(index,index2)->setBackground(Qt::black); - } - else - { - LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (index*16+index2))); - sampleStartAddr = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; - smallHeader = (SSmallHeader*) &SampleBuffer[sampleStartAddr-0x100000]; - sampleLength = (smallHeader->profileLength[2] << 16)+ (smallHeader->profileLength[1] << 8) + smallHeader->profileLength[0]; - if(sampleLength == sampleEndAddr) // - sampleStartAddr)) + LogInfo = (SLogbookHeader *) (HeaderBuffer + (0x800 * (index * 16 + index2)) + + 0x400); + sampleEndAddr = (LogInfo->profileLength[2] << 16) + (LogInfo->profileLength[1] << 8) + + LogInfo->profileLength[0]; + if (sampleEndAddr == 0) { + sv->item(index, index2)->setBackground(Qt::black); + } else { + LogInfo = (SLogbookHeader *) (HeaderBuffer + (0x800 * (index * 16 + index2))); + sampleStartAddr = (LogInfo->pBeginProfileData[2] << 16) + + (LogInfo->pBeginProfileData[1] << 8) + + LogInfo->pBeginProfileData[0]; + smallHeader = (SSmallHeader *) &SampleBuffer[sampleStartAddr - 0x100000]; + sampleLength = (smallHeader->profileLength[2] << 16) + + (smallHeader->profileLength[1] << 8) + + smallHeader->profileLength[0]; + if (sampleLength == sampleEndAddr) // - sampleStartAddr)) { - sv->item(index,index2)->setBackground(Qt::green); - } - else { - sv->item(index,index2)->setBackground(Qt::red); + sv->item(index, index2)->setBackground(Qt::green); + } else { + sv->item(index, index2)->setBackground(Qt::red); } } - } - else - { - sv->item(index,index2)->setBackground(Qt::white); + } else { + sv->item(index, index2)->setBackground(Qt::white); } } } - row =(HeaderBuffer[(0x8000 * 8)])/16; - colum =(HeaderBuffer[(0x8000 * 8)] % 16); - sv->item(row,colum)->setBackground(Qt::blue); - w->setMaximum(256); - w->setValue(HeaderInUse); + row = (HeaderBuffer[(0x8000 * 8)]) / 16; + colum = (HeaderBuffer[(0x8000 * 8)] % 16); + sv->item(row, colum)->setBackground(Qt::blue); + w->setMaximum(256); + w->setValue(HeaderInUse); } - - - - -void EditLogDialog::on_SectorView_cellClicked(int row, int column) -{ - -} +void EditLogDialog::on_SectorView_cellClicked(int row, int column) {} void EditLogDialog::updateSampleStatus() { - uint8_t row,colum; + uint8_t row, colum; uint32_t index; - QTableWidget* sv = _ui->SampleView; - QProgressBar* w = _ui->SampleUsage; + QTableWidget *sv = _ui->SampleView; + QProgressBar *w = _ui->SampleUsage; uint8_t SamplesInUse = 0; - for(index = 0; index < 192; index++) - { + for (index = 0; index < 192; index++) { row = index / 16; - colum =index % 16; + colum = index % 16; - if(SampleBuffer[index * 0x10000] != 0xFF) /* used */ + if (SampleBuffer[index * 0x10000] != 0xFF) /* used */ { SamplesInUse++; - if(SampleBuffer[index * 0x10000 + 0xFFFF] == 0xFF) /* open */ - { - sv->item(row,colum)->setBackground(Qt::blue); - } - else + if (SampleBuffer[index * 0x10000 + 0xFFFF] == 0xFF) /* open */ { - sv->item(row,colum)->setBackground(Qt::green); /* closed */ + sv->item(row, colum)->setBackground(Qt::blue); + } else { + sv->item(row, colum)->setBackground(Qt::green); /* closed */ } - } - else - { - sv->item(row,colum)->setBackground(Qt::white); /* empty */ + } else { + sv->item(row, colum)->setBackground(Qt::white); /* empty */ } } w->setMaximum(192); w->setValue(SamplesInUse); } - - -void EditLogDialog::on_SectorView_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) +void EditLogDialog::on_SectorView_currentCellChanged(int currentRow, + int currentColumn, + int previousRow, + int previousColumn) { - SLogbookHeader* LogInfo; - SLogbookHeader* LogInfo2nd; - QTextEdit* tf = _ui->textBrowser_2; + SLogbookHeader *LogInfo; + SLogbookHeader *LogInfo2nd; + QTextEdit *tf = _ui->textBrowser_2; QString InfoText; - QTableWidget* sv = _ui->SampleView; + QTableWidget *sv = _ui->SampleView; uint32_t sampleAddrStart = 0; uint32_t sampleAddrEnd = 0; uint8_t rowidx, columidx; tf->setReadOnly(true); - LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (currentRow*16+currentColumn))); - LogInfo2nd = (SLogbookHeader*)(HeaderBuffer+(0x800 * (currentRow*16+currentColumn)) +0x400); + LogInfo = (SLogbookHeader *) (HeaderBuffer + (0x800 * (currentRow * 16 + currentColumn))); + LogInfo2nd = (SLogbookHeader *) (HeaderBuffer + (0x800 * (currentRow * 16 + currentColumn)) + + 0x400); updateSampleStatus(); - if(LogInfo->diveHeaderStart == 0xFAFA) - { - sampleAddrStart = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; - sampleAddrEnd = (LogInfo2nd->pEndProfileData[2]<<16) + (LogInfo2nd->pEndProfileData[1]<<8) + LogInfo2nd->pEndProfileData[0]; + if (LogInfo->diveHeaderStart == 0xFAFA) { + sampleAddrStart = (LogInfo->pBeginProfileData[2] << 16) + + (LogInfo->pBeginProfileData[1] << 8) + LogInfo->pBeginProfileData[0]; + sampleAddrEnd = (LogInfo2nd->pEndProfileData[2] << 16) + + (LogInfo2nd->pEndProfileData[1] << 8) + LogInfo2nd->pEndProfileData[0]; - // InfoText.sprintf("Header: %d \nNummer: %d\nSamplestart 0x%x\nSampleend 0x%x", currentRow*16+currentColumn, LogInfo->diveNumber,sampleAddrStart,sampleAddrEnd); - InfoText = QString::asprintf( - "Header: %d \nNummer: %d\nSamplestart 0x%x\nSampleend 0x%x", - currentRow*16 + currentColumn, - LogInfo->diveNumber, - sampleAddrStart, - sampleAddrEnd - ); - sampleAddrStart = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; - if(sampleAddrStart != 0) - { + // InfoText.sprintf("Header: %d \nNummer: %d\nSamplestart 0x%x\nSampleend 0x%x", currentRow*16+currentColumn, LogInfo->diveNumber,sampleAddrStart,sampleAddrEnd); + InfoText = QString::asprintf("Header: %d \nNummer: %d\nSamplestart 0x%x\nSampleend 0x%x", + currentRow * 16 + currentColumn, + LogInfo->diveNumber, + sampleAddrStart, + sampleAddrEnd); + sampleAddrStart = (LogInfo->pBeginProfileData[2] << 16) + + (LogInfo->pBeginProfileData[1] << 8) + LogInfo->pBeginProfileData[0]; + if (sampleAddrStart != 0) { sampleAddrStart -= 0x100000; /* substract memory offset */ - sampleAddrStart /= 0x10000; /* calc sector */ + sampleAddrStart /= 0x10000; /* calc sector */ sv->item(sampleAddrStart / 16, sampleAddrStart % 16)->setBackground(Qt::magenta); - } - else - { + } else { sv->item(0, 0)->setBackground(Qt::black); } - } - else - { + } else { InfoText = QString::asprintf("Empty"); } tf->setPlainText((InfoText)); } - - - - -void EditLogDialog::on_SampleView_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) +void EditLogDialog::on_SampleView_currentCellChanged(int currentRow, + int currentColumn, + int previousRow, + int previousColumn) { uint16_t sampleSector; uint8_t headerRow, headerColumn; - SLogbookHeader* LogInfo; - SLogbookHeader* LogInfo2nd; + SLogbookHeader *LogInfo; + SLogbookHeader *LogInfo2nd; uint32_t sectorStart, sectorEnd; uint32_t sampleAddrStart, sampleAddrEnd; - QTableWidget* headerView = _ui->SectorView; + QTableWidget *headerView = _ui->SectorView; sampleSector = currentRow * 16 + currentColumn; sectorStart = sampleSector * 0x10000 + 0x100000; - sectorEnd = sectorStart +0xFFFF; - if(SampleBuffer[sectorStart - 0x100000] != 0xFF) // is buffer used? + sectorEnd = sectorStart + 0xFFFF; + if (SampleBuffer[sectorStart - 0x100000] != 0xFF) // is buffer used? { updateHeaderStatus(); - for(headerRow = 0; headerRow < 16; headerRow++) - { - for(headerColumn = 0; headerColumn < 16; headerColumn++) - { - LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (headerRow*16+headerColumn))); - LogInfo2nd = (SLogbookHeader*)(HeaderBuffer+(0x800 * (headerRow*16+headerColumn)) +0x400); - sampleAddrStart = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; - sampleAddrEnd = (LogInfo2nd->pEndProfileData[2]<<16) + (LogInfo2nd->pEndProfileData[1]<<8) + LogInfo2nd->pEndProfileData[0]; + for (headerRow = 0; headerRow < 16; headerRow++) { + for (headerColumn = 0; headerColumn < 16; headerColumn++) { + LogInfo = (SLogbookHeader *) (HeaderBuffer + + (0x800 * (headerRow * 16 + headerColumn))); + LogInfo2nd = (SLogbookHeader *) (HeaderBuffer + + (0x800 * (headerRow * 16 + headerColumn)) + + 0x400); + sampleAddrStart = (LogInfo->pBeginProfileData[2] << 16) + + (LogInfo->pBeginProfileData[1] << 8) + + LogInfo->pBeginProfileData[0]; + sampleAddrEnd = (LogInfo2nd->pEndProfileData[2] << 16) + + (LogInfo2nd->pEndProfileData[1] << 8) + + LogInfo2nd->pEndProfileData[0]; - if(((sampleAddrStart >= sectorStart)&&(sampleAddrStart < sectorEnd) - || (sampleAddrEnd >= sectorStart)&&(sampleAddrEnd < sectorEnd))) - { + if (((sampleAddrStart >= sectorStart) && (sampleAddrStart < sectorEnd) + || (sampleAddrEnd >= sectorStart) && (sampleAddrEnd < sectorEnd))) { headerView->item(headerRow, headerColumn)->setBackground(Qt::magenta); } }
--- a/editlogdialog.h Mon Jan 12 13:49:16 2026 +0000 +++ b/editlogdialog.h Mon Jan 12 13:51:17 2026 +0000 @@ -28,7 +28,7 @@ #ifndef EDITLOGDIALOG_H #define EDITLOGDIALOG_H -#define NUM_GAS (5) /* number of selectable gases */ +#define NUM_GAS (5) /* number of selectable gases */ typedef struct { @@ -58,17 +58,18 @@ unsigned char tankDivisor; } SSmallHeader; -typedef struct{ -unsigned char active:1; -unsigned char first:1; -unsigned char deco:1; -unsigned char travel:1; -unsigned char senderCode:4; +typedef struct +{ + unsigned char active : 1; + unsigned char first : 1; + unsigned char deco : 1; + unsigned char travel : 1; + unsigned char senderCode : 4; } gasubit8_t; -typedef union{ -gasubit8_t ub; -unsigned char uw; +typedef union { + gasubit8_t ub; + unsigned char uw; } gasbit8_Type; typedef struct { @@ -87,77 +88,75 @@ typedef struct { unsigned short diveHeaderStart; - unsigned char pBeginProfileData[3]; - unsigned char pEndProfileData[3]; - unsigned char profileLength[3]; - unsigned char logbookProfileVersion; - unsigned char dateYear; - unsigned char dateMonth; - unsigned char dateDay; - unsigned char timeHour; - unsigned char timeMinute; - unsigned char extraPagesWithData; /* from here on: changes in order with respect to OSTC3 */ + unsigned char pBeginProfileData[3]; + unsigned char pEndProfileData[3]; + unsigned char profileLength[3]; + unsigned char logbookProfileVersion; + unsigned char dateYear; + unsigned char dateMonth; + unsigned char dateDay; + unsigned char timeHour; + unsigned char timeMinute; + unsigned char extraPagesWithData; /* from here on: changes in order with respect to OSTC3 */ unsigned short maxDepth; unsigned short diveTimeMinutes; - unsigned char diveTimeSeconds; - unsigned char samplingRate; - short minTemp; + unsigned char diveTimeSeconds; + unsigned char samplingRate; + short minTemp; unsigned short surfacePressure_mbar; unsigned short desaturationTime; SGasListLog gasordil[NUM_GAS]; - unsigned char firmwareVersionLow; - unsigned char firmwareVersionHigh; + unsigned char firmwareVersionLow; + unsigned char firmwareVersionHigh; unsigned short batteryVoltage; unsigned short cnsAtBeginning; - unsigned char gfAtBeginning; - unsigned char gfAtEnd; + unsigned char gfAtBeginning; + unsigned char gfAtEnd; unsigned short personalDiveCount; SSetpointLog setpoint[NUM_GAS]; unsigned short maxCNS; unsigned short averageDepth_mbar; unsigned short total_diveTime_seconds; - unsigned char salinity; - unsigned char gfLow_or_Vpm_conservatism; - unsigned char gfHigh; - unsigned char decoModel; - float n2Compartments[16]; - float heCompartments[16]; - unsigned char n2CompartDesatTime_min[16]; - unsigned char heCompartDesatTime_min[16]; + unsigned char salinity; + unsigned char gfLow_or_Vpm_conservatism; + unsigned char gfHigh; + unsigned char decoModel; + float n2Compartments[16]; + float heCompartments[16]; + unsigned char n2CompartDesatTime_min[16]; + unsigned char heCompartDesatTime_min[16]; unsigned short diveNumber; - unsigned char lastDecostop_m; - unsigned char CCRmode; - unsigned char diveMode; - unsigned char hwHudLastStatus; /* from here on identical to OSTC3 again */ + unsigned char lastDecostop_m; + unsigned char CCRmode; + unsigned char diveMode; + unsigned char hwHudLastStatus; /* from here on identical to OSTC3 again */ unsigned short hwHudBattery_mV; unsigned char batteryGaugeRegisters[6]; unsigned short diveHeaderEnd; } SLogbookHeader; - -namespace Ui { class editLogWnd; } +namespace Ui { +class editLogWnd; +} #include <QDialog> #include <QTableWidgetItem> class HardwareOperations; - - -class EditLogDialog - : public QDialog +class EditLogDialog : public QDialog { Q_OBJECT - Ui::editLogWnd* _ui; - HardwareOperations* _op; + Ui::editLogWnd *_ui; + HardwareOperations *_op; - unsigned char* HeaderBuffer; - unsigned char* SampleBuffer; - QTableWidgetItem* item[256]; - QTableWidgetItem* sampleitem[192]; + unsigned char *HeaderBuffer; + unsigned char *SampleBuffer; + QTableWidgetItem *item[256]; + QTableWidgetItem *sampleitem[192]; public: - EditLogDialog(QWidget* parent, HardwareOperations *op); + EditLogDialog(QWidget *parent, HardwareOperations *op); ~EditLogDialog(); private slots: @@ -173,10 +172,15 @@ void on_WriteAllSamples_clicked(); void on_SectorView_cellClicked(int row, int column); + void on_SectorView_currentCellChanged(int currentRow, + int currentColumn, + int previousRow, + int previousColumn); - void on_SectorView_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); - - void on_SampleView_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); + void on_SampleView_currentCellChanged(int currentRow, + int currentColumn, + int previousRow, + int previousColumn); }; #endif // EDITLOGDIALOG_H
--- a/main.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/main.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -46,11 +46,11 @@ #include "Utils/Log.h" #include <QApplication> +#include <QOperatingSystemVersion> #include <QSettings> #include <QSysInfo> -#include <QOperatingSystemVersion> -QSettings* settings = NULL; +QSettings *settings = NULL; ////////////////////////////////////////////////////////////////////////////// @@ -69,20 +69,21 @@ #if 0 #define LOG_TRACE(msg) \ do { \ - if(Log::minLevel <= Log::LEVEL_TRACE) { \ - std::ostringstream oss; \ - oss << msg; \ - LogAction(Log::LEVEL_TRACE, __FILE__, __LINE__, LOG_FUNCTION_) << oss.str(); \ + if (Log::minLevel <= Log::LEVEL_TRACE) { \ + std::ostringstream oss; \ + oss << msg; \ + LogAction(Log::LEVEL_TRACE, __FILE__, __LINE__, LOG_FUNCTION_) << oss.str(); \ } \ - } while(0) + } while (0) #endif #if 0 #define LOG_TRACE(msg) \ do { \ - if(Log::minLevel <= Log::LEVEL_TRACE) { \ - LogAction(Log::LEVEL_TRACE, __FILE__, __LINE__, LOG_FUNCTION_) << QString("%1").arg(msg); \ + if (Log::minLevel <= Log::LEVEL_TRACE) { \ + LogAction(Log::LEVEL_TRACE, __FILE__, __LINE__, LOG_FUNCTION_) \ + << QString("%1").arg(msg); \ } \ - } while(0) + } while (0) #endif #ifdef Q_OS_WIN32 @@ -112,21 +113,21 @@ } #endif #elif defined(Q_OS_MACX) - if( QSysInfo::macVersion() < 2 ) - LOG_TRACE(" MacOS 9" ); + if (QSysInfo::macVersion() < 2) + LOG_TRACE(" MacOS 9"); else - LOG_TRACE(" MacOS 10." << int(QSysInfo::macVersion()-2)); + LOG_TRACE(" MacOS 10." << int(QSysInfo::macVersion() - 2)); #elif defined(Q_OS_LINUX) LOG_TRACE(" Linux "); #else -# error Unknown OS not yet implemented +#error Unknown OS not yet implemented #endif - // LOG_TRACE(" Qt build " << QT_VERSION_STR << " (DLL " << qVersion() << ")"); - LOG_TRACE(QString(" Qt build %1 (DLL %2)").arg(QT_VERSION_STR).arg(qVersion())); + // LOG_TRACE(" Qt build " << QT_VERSION_STR << " (DLL " << qVersion() << ")"); + LOG_TRACE(QString(" Qt build %1 (DLL %2)").arg(QT_VERSION_STR).arg(qVersion())); //---- Initialize interface ---------------------------------------------- // Allow nice display on 4K screens: QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); QApplication a(argc, argv);
--- a/o3pack.cpp Mon Jan 12 13:49:16 2026 +0000 +++ b/o3pack.cpp Mon Jan 12 13:51:17 2026 +0000 @@ -7,18 +7,10 @@ #include "HexFile.h" ////////////////////////////////////////////////////////////////////////////// -static unsigned char frogSecretKey[16] = { - 111, 85, 190, 69, - 108,254, 242, 19, - 231, 49, 248,255, - 233, 48, 176,241 -}; -static unsigned char ostc3SecretKey[16] = { - 241,233, 176, 48, - 69,111, 190, 85, - 255,231, 248, 49, - 19,108, 242,254 -}; +static unsigned char frogSecretKey[16] + = {111, 85, 190, 69, 108, 254, 242, 19, 231, 49, 248, 255, 233, 48, 176, 241}; +static unsigned char ostc3SecretKey[16] + = {241, 233, 176, 48, 69, 111, 190, 85, 255, 231, 248, 49, 19, 108, 242, 254}; int main(int argc, char *argv[]) { @@ -31,19 +23,20 @@ bool force = false; bool ostc3 = true; - if( argc < 2 ) goto Usage; + if (argc < 2) + goto Usage; - if( QString(argv[1]).toLower() == "-frog" ) { + if (QString(argv[1]).toLower() == "-frog") { ostc3 = false; argc--, argv++; - } else if( QString(argv[1]).toLower() == "-ostc3" ) { + } else if (QString(argv[1]).toLower() == "-ostc3") { ostc3 = true; argc--, argv++; } - in = QDir::cleanPath(current.absoluteFilePath(argv[1])); + in = QDir::cleanPath(current.absoluteFilePath(argv[1])); out = QDir::cleanPath(current.absoluteFilePath(argv[2])); - if( argv[2] == QString("-f") && argc >= 3 ) { + if (argv[2] == QString("-f") && argc >= 3) { out = QDir::cleanPath(current.absoluteFilePath(argv[3])); force = true; } @@ -51,7 +44,7 @@ //---- Check parameters consistency -------------------------------------- { QFileInfo fi(in); - if( ! fi.exists() || ! fi.isReadable() ) { + if (!fi.exists() || !fi.isReadable()) { qWarning().nospace() << "Cannot read input file " << in; goto Usage; } @@ -59,13 +52,13 @@ { QFileInfo fo(out); - if( fo.exists() ) { - if( !force ) { + if (fo.exists()) { + if (!force) { qWarning().nospace() << "File " << out << " exists. Use -f to force overwrite."; goto Usage; } - if( !fo.isWritable() ) { + if (!fo.isWritable()) { qWarning().nospace() << "Cannot write to " << out << ". Protected file ?"; goto Usage; } @@ -75,7 +68,7 @@ //---- Load the HEX file ------------------------------------------------- { - QProgressBar* progress = new QProgressBar(0); + QProgressBar *progress = new QProgressBar(0); progress->setFormat("Loading %p%"); progress->show(); @@ -90,11 +83,10 @@ sprintf(sum, "%08X", hex.checksum()); qDebug() << "Checksum " << sum; - //---- Save encrypted HEX file ------------------------------------------- + //---- Save encrypted HEX file ------------------------------------------- progress->setFormat("Saving %p%"); hex.saveEncrypted(out, (ostc3 ? ostc3SecretKey : frogSecretKey), progress); - } - catch(const char* msg) { + } catch (const char *msg) { qWarning() << "Failed: " << msg; } @@ -106,7 +98,7 @@ Usage: qWarning() << "Usage:" << endl - << " " << QString(app.arguments()[0]).section('/', -1).section('\\',-1) + << " " << QString(app.arguments()[0]).section('/', -1).section('\\', -1) << "[-frog|-ostc3]" << " input.hex [-f] output.hex"; exit(-1);
