comparison 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
comparison
equal deleted inserted replaced
4:e30f00f760d3 5:115cfa4a3239
36 ////////////////////////////////////////////////////////////////////////////// 36 //////////////////////////////////////////////////////////////////////////////
37 #include <QSettings> 37 #include <QSettings>
38 #include <QRegularExpression> 38 #include <QRegularExpression>
39 #include "OSTC4Operations.h" 39 #include "OSTC4Operations.h"
40 40
41
41 #include "Utils/Log.h" 42 #include "Utils/Log.h"
42 #include "Utils/Exception.h" 43 #include "Utils/Exception.h"
43 #include "Utils/ProgressEvent.h" 44 #include "Utils/ProgressEvent.h"
44 45
45 extern QSettings* settings; 46 extern QSettings* settings;
62 return "OSTC 4/5"; 63 return "OSTC 4/5";
63 } 64 }
64 65
65 HardwareOperations::CompanionFeatures OSTC4Operations::supported() const 66 HardwareOperations::CompanionFeatures OSTC4Operations::supported() const
66 { 67 {
67 // No ICON, no DUMPSCREEN 68 // No DUMPSCREEN
68 return CompanionFeatures(PARAMETERS|DATE|NAME|FIRMWARE 69
69 |HELIUM_DIVE|CCR_DIVE|BLUETOOTH|VPM_MODEL|SIGNAL_CHECK); 70 CompanionFeatures features;
71 features |= PARAMETERS;
72 features |= DATE;
73 features |= NAME;
74 features |= FIRMWARE;
75 features |= HELIUM_DIVE;
76 features |= CCR_DIVE;
77 features |= BLUETOOTH;
78 features |= VPM_MODEL;
79 features |= SIGNAL_CHECK;
80 features |= ICON;
81
82 return features;
70 } 83 }
71 84
72 QString OSTC4Operations::firmwareTemplate() const 85 QString OSTC4Operations::firmwareTemplate() const
73 { 86 {
74 return "ostc4*.bin"; 87 return "ostc4*.bin";
186 199
187 OSTC4Operations::OSTC4Operations() 200 OSTC4Operations::OSTC4Operations()
188 : fileChecksum(0,0) 201 : fileChecksum(0,0)
189 { 202 {
190 emulatorName = "OSTC4/5"; 203 emulatorName = "OSTC4/5";
204 m_crcWrapper = new CrcWrapper(nullptr);
191 } 205 }
192 206
193 ////////////////////////////////////////////////////////////////////////////// 207 //////////////////////////////////////////////////////////////////////////////
194 208
195 void OSTC4Operations::upgradeFW(const QString &fileName) 209 void OSTC4Operations::upgradeFW(const QString &fileName)
200 openFirmware(fileName, false); 214 openFirmware(fileName, false);
201 215
202 LOG_INFO("Please wait for OSTC4/5 to complete installation..."); 216 LOG_INFO("Please wait for OSTC4/5 to complete installation...");
203 } 217 }
204 218
219 #define SWAP4BYTES(x) \
220 uint( (((x) & 0x000000FF) << 24) \
221 | (((x) & 0x0000FF00) << 8) \
222 | (((x) & 0x00FF0000) >> 8) \
223 | (((x) & 0xFF000000) >> 24))
224
225 void OSTC4Operations::setIcons(const QString &fileName)
226 {
227 int size;
228 int blockSize;
229 int transferDelay;
230 unsigned char echo;
231
232 FirmwareOSTC4 header;
233
234 unsigned char buf3offset[4];
235 unsigned char bufVersion[4];
236 uint32_t checksum = 0;
237 uint32_t width = 0;
238 uint32_t height = 0;
239
240 blockSize = FIRMWARE_BLOCK;
241 transferDelay = FIRMWARE_BLOCK_DELAY;
242
243 try
244 {
245 bmp = std::make_unique<BmpToArray>(fileName);
246 }
247 catch (const std::exception& e)
248 {
249 std::cerr << "Fehler beim Laden: " << e.what() << '\n';
250 }
251
252 QByteArray bin = bmp->getTransferBytes();
253 bmp->getImageXY(&width, &height);
254
255 if(bin.size() < 200000)
256 {
257 buf3offset[0] = 0x20;
258 buf3offset[1] = 0x00;
259 buf3offset[2] = 0x00;
260 buf3offset[3] = 0x00;
261 bufVersion[0] = 1;
262 bufVersion[1] = 0;
263 bufVersion[2] = 0;
264 bufVersion[3] = 0;
265
266 header.type = 0x20;
267 /* original header shallnot be modifieded => split image size information into 5 bytes */
268 header.dummy5 = width; /* low byte */
269 header.dummy6 = height; /* low byte */
270 header.dummy7 = (width >> 8) & 0x0000000F; /* shifted high nibble */
271 header.dummy7 |= (height >> 4) & 0x000000F0; /* shifted high nibble */
272
273 header.length = SWAP4BYTES(bin.size());
274 header.checksum = bin.size() + (256*256*256*header.type) + (256*256* header.dummy5) + (256*header.dummy6) + header.dummy7;
275
276 checksum = SWAP4BYTES(m_crcWrapper->CRC_CalcBlockCRC(reinterpret_cast<uint32_t*>(bin.data()), bin.size() / 4));
277
278 //---- Upload icon -----------------------------------------------
279 const int steps = 3 + (bin.size()+blockSize-1) / blockSize;
280 int step = 0;
281 PROGRESS(step++, steps);
282
283 LOG_INFO(QString(" uploading icon size %1 bytes").arg(bin.size()));
284 writeText( QString("Upload Icon") );
285
286 //---- Command
287 PROGRESS(step++, steps);
288 echo = retryCommand(_serial, 'o'); // 0x6F upload icon
289 if( echo != 'o' )
290 LOG_THROW("Bad OSTC4/5 icon upload.");
291
292 //---- Header
293 PROGRESS(step++, steps);
294 _serial.writeBlock((uchar*)&header, sizeof header);
295 _serial.sleep(500);
296 //---- Data
297 for(int len = 0x00000; len < bin.size(); len += blockSize)
298 {
299 if(transferDelay)
300 {
301 _serial.sleep(transferDelay); // 15 msec between 64B blocks...
302 }
303 PROGRESS(step++, steps);
304
305 size = qMin(blockSize,
306 bin.size() - len);
307
308 LOG_TRACE("Fill " << size);
309 _serial.writeBlock((uchar*)bin.data()+len, (unsigned int)size);
310 }
311 _serial.writeBlock((uchar*)&checksum, 4);
312 PROGRESS(steps, steps); // 100%
313
314 //---- Wait acknowledge ----------------------------------------------
315 PROGRESS_THROTTLE();
316
317 for(int wait=0; wait<2*60; ++wait) // Up to 2 min...
318 {
319 try {
320 unsigned char reply = _serial.readByte();
321 if( reply == 0x4D )
322 break;
323 }
324 catch( const ReadTimeout&) {}
325 }
326
327 LOG_INFO(" icon uploaded.");
328 }
329 else
330 {
331 LOG_THROW("Image to large. Must be < 200k.");
332 }
333 PROGRESS_RESET();
334 }
335
336
337
205 ////////////////////////////////////////////////////////////////////////////// 338 //////////////////////////////////////////////////////////////////////////////
206 ////////////////////////////////////////////////////////////////////////////// 339 //////////////////////////////////////////////////////////////////////////////
207 /// FIRMWARE UPGRADE /// 340 /// FIRMWARE UPGRADE ///
208 ////////////////////////////////////////////////////////////////////////////// 341 //////////////////////////////////////////////////////////////////////////////
209 ////////////////////////////////////////////////////////////////////////////// 342 //////////////////////////////////////////////////////////////////////////////
210
211 #define SWAP4BYTES(x) \
212 uint( (((x) & 0x000000FF) << 24) \
213 | (((x) & 0x0000FF00) << 8) \
214 | (((x) & 0x00FF0000) >> 8) \
215 | (((x) & 0xFF000000) >> 24))
216 343
217 ////////////////////////////////////////////////////////////////////////////// 344 //////////////////////////////////////////////////////////////////////////////
218 345
219 void OSTC4Operations::openFirmware(const QString &fileName, bool dryRun) 346 void OSTC4Operations::openFirmware(const QString &fileName, bool dryRun)
220 { 347 {