Mercurial > public > ostc_companion
diff OSTC4Operations.cpp @ 5:115cfa4a3239 default tip
Added icon upload function for OSTC 4/5
For the upload the same process as the one for the firmware update is used => CRC functionality has been copied from the ostc_pack SW
| author | Ideenmodellierer |
|---|---|
| date | Tue, 30 Dec 2025 21:41:02 +0100 |
| parents | e30f00f760d3 |
| children |
line wrap: on
line diff
--- a/OSTC4Operations.cpp Sun Nov 30 18:37:32 2025 +0100 +++ b/OSTC4Operations.cpp Tue Dec 30 21:41:02 2025 +0100 @@ -38,6 +38,7 @@ #include <QRegularExpression> #include "OSTC4Operations.h" + #include "Utils/Log.h" #include "Utils/Exception.h" #include "Utils/ProgressEvent.h" @@ -64,9 +65,21 @@ HardwareOperations::CompanionFeatures OSTC4Operations::supported() const { - // No ICON, no DUMPSCREEN - return CompanionFeatures(PARAMETERS|DATE|NAME|FIRMWARE - |HELIUM_DIVE|CCR_DIVE|BLUETOOTH|VPM_MODEL|SIGNAL_CHECK); + // No DUMPSCREEN + + CompanionFeatures features; + features |= PARAMETERS; + features |= DATE; + features |= NAME; + features |= FIRMWARE; + features |= HELIUM_DIVE; + features |= CCR_DIVE; + features |= BLUETOOTH; + features |= VPM_MODEL; + features |= SIGNAL_CHECK; + features |= ICON; + + return features; } QString OSTC4Operations::firmwareTemplate() const @@ -188,6 +201,7 @@ : fileChecksum(0,0) { emulatorName = "OSTC4/5"; + m_crcWrapper = new CrcWrapper(nullptr); } ////////////////////////////////////////////////////////////////////////////// @@ -202,18 +216,131 @@ LOG_INFO("Please wait for OSTC4/5 to complete installation..."); } +#define SWAP4BYTES(x) \ +uint( (((x) & 0x000000FF) << 24) \ + | (((x) & 0x0000FF00) << 8) \ + | (((x) & 0x00FF0000) >> 8) \ + | (((x) & 0xFF000000) >> 24)) + +void OSTC4Operations::setIcons(const QString &fileName) +{ + int size; + int blockSize; + int transferDelay; + unsigned char echo; + + FirmwareOSTC4 header; + + unsigned char buf3offset[4]; + unsigned char bufVersion[4]; + uint32_t checksum = 0; + uint32_t width = 0; + uint32_t height = 0; + + blockSize = FIRMWARE_BLOCK; + transferDelay = FIRMWARE_BLOCK_DELAY; + + try + { + bmp = std::make_unique<BmpToArray>(fileName); + } + catch (const std::exception& e) + { + std::cerr << "Fehler beim Laden: " << e.what() << '\n'; + } + + QByteArray bin = bmp->getTransferBytes(); + bmp->getImageXY(&width, &height); + + if(bin.size() < 200000) + { + buf3offset[0] = 0x20; + buf3offset[1] = 0x00; + buf3offset[2] = 0x00; + buf3offset[3] = 0x00; + bufVersion[0] = 1; + bufVersion[1] = 0; + bufVersion[2] = 0; + bufVersion[3] = 0; + + header.type = 0x20; + /* original header shallnot be modifieded => split image size information into 5 bytes */ + header.dummy5 = width; /* low byte */ + header.dummy6 = height; /* low byte */ + header.dummy7 = (width >> 8) & 0x0000000F; /* shifted high nibble */ + header.dummy7 |= (height >> 4) & 0x000000F0; /* shifted high nibble */ + + header.length = SWAP4BYTES(bin.size()); + header.checksum = bin.size() + (256*256*256*header.type) + (256*256* header.dummy5) + (256*header.dummy6) + header.dummy7; + + checksum = SWAP4BYTES(m_crcWrapper->CRC_CalcBlockCRC(reinterpret_cast<uint32_t*>(bin.data()), bin.size() / 4)); + + //---- Upload icon ----------------------------------------------- + const int steps = 3 + (bin.size()+blockSize-1) / blockSize; + int step = 0; + PROGRESS(step++, steps); + + LOG_INFO(QString(" uploading icon size %1 bytes").arg(bin.size())); + writeText( QString("Upload Icon") ); + + //---- Command + PROGRESS(step++, steps); + echo = retryCommand(_serial, 'o'); // 0x6F upload icon + if( echo != 'o' ) + LOG_THROW("Bad OSTC4/5 icon upload."); + + //---- Header + PROGRESS(step++, steps); + _serial.writeBlock((uchar*)&header, sizeof header); + _serial.sleep(500); + //---- Data + for(int len = 0x00000; len < bin.size(); len += blockSize) + { + if(transferDelay) + { + _serial.sleep(transferDelay); // 15 msec between 64B blocks... + } + PROGRESS(step++, steps); + + size = qMin(blockSize, + bin.size() - len); + + LOG_TRACE("Fill " << size); + _serial.writeBlock((uchar*)bin.data()+len, (unsigned int)size); + } + _serial.writeBlock((uchar*)&checksum, 4); + PROGRESS(steps, steps); // 100% + + //---- Wait acknowledge ---------------------------------------------- + PROGRESS_THROTTLE(); + + for(int wait=0; wait<2*60; ++wait) // Up to 2 min... + { + try { + unsigned char reply = _serial.readByte(); + if( reply == 0x4D ) + break; + } + catch( const ReadTimeout&) {} + } + + LOG_INFO(" icon uploaded."); + } + else + { + LOG_THROW("Image to large. Must be < 200k."); + } + PROGRESS_RESET(); +} + + + ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// /// FIRMWARE UPGRADE /// ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -#define SWAP4BYTES(x) \ - uint( (((x) & 0x000000FF) << 24) \ - | (((x) & 0x0000FF00) << 8) \ - | (((x) & 0x00FF0000) >> 8) \ - | (((x) & 0xFF000000) >> 24)) - ////////////////////////////////////////////////////////////////////////////// void OSTC4Operations::openFirmware(const QString &fileName, bool dryRun)
