Mercurial > public > ostc_companion
comparison HexFile.h @ 8:21ce6187d32e
Minor changes done by automatic style checker
| author | Ideenmodellierer |
|---|---|
| date | Mon, 12 Jan 2026 13:51:17 +0000 |
| parents | 0b3630a29ad8 |
| children |
comparison
equal
deleted
inserted
replaced
| 7:0969ef86c42d | 8:21ce6187d32e |
|---|---|
| 37 // 2012-02-12 : [jDG] Creation for Frog Companion firmware upload. | 37 // 2012-02-12 : [jDG] Creation for Frog Companion firmware upload. |
| 38 // 2012-09-22 : [jDG] Updated for OSTC Companion (OSTC3). | 38 // 2012-09-22 : [jDG] Updated for OSTC Companion (OSTC3). |
| 39 // 2014-07-07 : [jDG] Cleanups for Subsurface google-summer-of-code. | 39 // 2014-07-07 : [jDG] Cleanups for Subsurface google-summer-of-code. |
| 40 // 2014-07-25 : [jDG] BSD 2-clause license. | 40 // 2014-07-25 : [jDG] BSD 2-clause license. |
| 41 | 41 |
| 42 #include <QFile> | |
| 42 #include <QtGlobal> | 43 #include <QtGlobal> |
| 43 #include <QFile> | |
| 44 | 44 |
| 45 class QProgressBar; | 45 class QProgressBar; |
| 46 | 46 |
| 47 ///////////////////////////////////////////////////////////////////////////// | 47 ///////////////////////////////////////////////////////////////////////////// |
| 48 /// \brief Read .hex file in "Intel HEX" format. | 48 /// \brief Read .hex file in "Intel HEX" format. |
| 49 /// | 49 /// |
| 50 /// \note that OSTC3 firmware is NOT distributed in Intel HEX format, | 50 /// \note that OSTC3 firmware is NOT distributed in Intel HEX format, |
| 51 /// but is first flatened, then encrypted, then written back | 51 /// but is first flatened, then encrypted, then written back |
| 52 /// in a similar looking format. | 52 /// in a similar looking format. |
| 53 class HexFile | 53 class HexFile |
| 54 { | 54 { |
| 55 QFile _file; | 55 QFile _file; |
| 56 size_t _memSize; | 56 size_t _memSize; |
| 57 size_t _baseAddress; ///< Base for extended address modes. | 57 size_t _baseAddress; ///< Base for extended address modes. |
| 58 | 58 |
| 59 unsigned char* _buffer; | 59 unsigned char *_buffer; |
| 60 | 60 |
| 61 /// \brief Read and interpret on line of the HEX file. | 61 /// \brief Read and interpret on line of the HEX file. |
| 62 void readLine(); | 62 void readLine(); |
| 63 | 63 |
| 64 public: | 64 public: |
| 70 bool allocate(size_t memSize, unsigned char fill = 0xFF); | 70 bool allocate(size_t memSize, unsigned char fill = 0xFF); |
| 71 bool sqwiz(size_t newMemSize); | 71 bool sqwiz(size_t newMemSize); |
| 72 | 72 |
| 73 /// \brief Load the .hex file into the internal buffer. | 73 /// \brief Load the .hex file into the internal buffer. |
| 74 /// \return TRUE is ok, FAlSE if some error occurs. | 74 /// \return TRUE is ok, FAlSE if some error occurs. |
| 75 void load(const QString& fileName); | 75 void load(const QString &fileName); |
| 76 | 76 |
| 77 /// \brief Return a pointer to the loaded data. | 77 /// \brief Return a pointer to the loaded data. |
| 78 const unsigned char* data() const; | 78 const unsigned char *data() const; |
| 79 | 79 |
| 80 /// \brief Returns the 4 bytes checksum of the loaded data. | 80 /// \brief Returns the 4 bytes checksum of the loaded data. |
| 81 /// | 81 /// |
| 82 /// This is a simple Adler32 checksum: The lower 16bits are the sum of | 82 /// This is a simple Adler32 checksum: The lower 16bits are the sum of |
| 83 /// all the bytes (modulo 65536). And the second 16bits are the sum of | 83 /// all the bytes (modulo 65536). And the second 16bits are the sum of |
| 84 /// the running sum itself (also modulo 65536). | 84 /// the running sum itself (also modulo 65536). |
| 85 unsigned int checksum() const; | 85 unsigned int checksum() const; |
| 86 | 86 |
| 87 /// \brief Save to encrypted HEX file. | 87 /// \brief Save to encrypted HEX file. |
| 88 void saveEncrypted(const QString& fileName, unsigned char secretKey[16]); | 88 void saveEncrypted(const QString &fileName, unsigned char secretKey[16]); |
| 89 | 89 |
| 90 /// \brief Reload encrypted HEX file. | 90 /// \brief Reload encrypted HEX file. |
| 91 void loadEncrypted(const QString& fileName, unsigned char secretKey[16]); | 91 void loadEncrypted(const QString &fileName, unsigned char secretKey[16]); |
| 92 }; | 92 }; |
