Mercurial > public > ostc_companion
comparison editlogdialog.cpp @ 1:0b3630a29ad8
Initial version based on previous repository.
Project was ported to QT6 and in now cmake based.
| author | Ideenmodellierer <tiefenrauscher@web.de> |
|---|---|
| date | Thu, 27 Nov 2025 18:40:28 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:76ccd6ce50c0 | 1:0b3630a29ad8 |
|---|---|
| 1 #include "editlogdialog.h" | |
| 2 #include "ui_LogEditor.h" | |
| 3 #include "MainWindow.h" // Needed to propagare retranslate() | |
| 4 #include "Utils/Log.h" | |
| 5 | |
| 6 #include "HardwareOperations.h" | |
| 7 | |
| 8 #include <QApplication> | |
| 9 #include <QDialogButtonBox> | |
| 10 #include <QDir> | |
| 11 #include <QLibraryInfo> | |
| 12 #include <QPushButton> | |
| 13 #include <QTranslator> | |
| 14 #include <QTableWidget> | |
| 15 | |
| 16 | |
| 17 #ifdef Q_OS_WIN | |
| 18 # define NOMINMAX 1 | |
| 19 # include <Windows.h> | |
| 20 # undef NOMINMAX | |
| 21 #endif | |
| 22 #define HEADER2OFFSET 0x400 | |
| 23 | |
| 24 EditLogDialog::EditLogDialog(QWidget* parent, HardwareOperations *op) | |
| 25 : QDialog(parent), | |
| 26 _ui(new Ui::editLogWnd), | |
| 27 _op(op) | |
| 28 { | |
| 29 uint32_t index, index2; | |
| 30 uint32_t sizeY = 0; | |
| 31 _ui->setupUi(this); | |
| 32 QTableWidget* headerView = _ui->SectorView; | |
| 33 QTableWidget* sampleView = _ui->SampleView; | |
| 34 | |
| 35 _ui->textBrowser_2->setTabStopDistance( | |
| 36 QFontMetricsF(_ui->textBrowser_2->font()).horizontalAdvance(' ') * 4 | |
| 37 ); | |
| 38 headerView->horizontalHeader()->setMinimumSectionSize(8); | |
| 39 headerView->verticalHeader()->setMinimumSectionSize(8); | |
| 40 headerView->horizontalHeader()->setDefaultSectionSize(8); | |
| 41 headerView->verticalHeader()->setDefaultSectionSize(8); | |
| 42 headerView->setColumnWidth(0,8); | |
| 43 headerView->setRowHeight(0,8); | |
| 44 headerView->horizontalHeader()->hide(); | |
| 45 headerView->verticalHeader()->hide(); | |
| 46 | |
| 47 sampleView->horizontalHeader()->setMinimumSectionSize(8); | |
| 48 sampleView->verticalHeader()->setMinimumSectionSize(8); | |
| 49 sampleView->horizontalHeader()->setDefaultSectionSize(8); | |
| 50 sampleView->verticalHeader()->setDefaultSectionSize(8); | |
| 51 sampleView->setColumnWidth(0,8); | |
| 52 sampleView->setRowHeight(0,8); | |
| 53 sampleView->horizontalHeader()->hide(); | |
| 54 sampleView->verticalHeader()->hide(); | |
| 55 | |
| 56 headerView->setRowCount(16); | |
| 57 headerView->setColumnCount(16); | |
| 58 | |
| 59 sampleView->setRowCount(12); | |
| 60 sampleView->setColumnCount(16); | |
| 61 | |
| 62 | |
| 63 HeaderBuffer = new unsigned char[0x8000*8 + 1]; // 64k Headerbuffer + lastDiveindex | |
| 64 SampleBuffer = new unsigned char[0xC00000 + 4]; // 12MB Samplebuffer + nextSampleAddr | |
| 65 | |
| 66 headerView->resize(8*16+2,8*16+2); | |
| 67 sampleView->resize(8*16+2,8*12+2); | |
| 68 sizeY = (uint32_t)(headerView->geometry().width()) / 16; | |
| 69 | |
| 70 if(sizeY < 8) | |
| 71 { | |
| 72 sizeY = 8; | |
| 73 } | |
| 74 | |
| 75 for(index = 0; index <16; index++) | |
| 76 { | |
| 77 headerView->setColumnWidth(index,sizeY); | |
| 78 headerView->setRowHeight(index,sizeY); | |
| 79 for(index2 = 0; index2 < 16; index2++) | |
| 80 { | |
| 81 | |
| 82 item[index * 16 + index2] = new QTableWidgetItem(" "); | |
| 83 headerView->setItem(index, index2, item[index * 16 + index2]); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 for(index = 0; index <12; index++) | |
| 88 { | |
| 89 sampleView->setColumnWidth(index,sizeY); | |
| 90 sampleView->setRowHeight(index,sizeY); | |
| 91 for(index2 = 0; index2 < 16; index2++) | |
| 92 { | |
| 93 | |
| 94 sampleitem[index * 16 + index2] = new QTableWidgetItem(" "); | |
| 95 sampleView->setItem(index, index2, sampleitem[index * 16 + index2]); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 headerView->show(); | |
| 100 headerView->setShowGrid(true); | |
| 101 | |
| 102 sampleView->show(); | |
| 103 sampleView->setShowGrid(true); | |
| 104 | |
| 105 } | |
| 106 | |
| 107 EditLogDialog::~EditLogDialog() | |
| 108 { | |
| 109 uint32_t index; | |
| 110 | |
| 111 for(index = 0; index <256; index++) | |
| 112 { | |
| 113 delete item[index]; | |
| 114 } | |
| 115 for(index = 0; index <192; index++) | |
| 116 { | |
| 117 delete sampleitem[index]; | |
| 118 } | |
| 119 delete _ui; | |
| 120 delete HeaderBuffer; | |
| 121 delete SampleBuffer; | |
| 122 } | |
| 123 | |
| 124 | |
| 125 void EditLogDialog::on_WriteAllHeader_clicked() | |
| 126 { | |
| 127 _op->writeAllHeader(HeaderBuffer); | |
| 128 } | |
| 129 | |
| 130 void EditLogDialog::on_pushButton_clicked() | |
| 131 { | |
| 132 Q_ASSERT( _op ); | |
| 133 | |
| 134 HeaderBuffer[0] = 0; | |
| 135 | |
| 136 try { | |
| 137 LOG_INFO(tr("Request All Headers...")); | |
| 138 _op->getAllHeader(HeaderBuffer); | |
| 139 } | |
| 140 catch(const std::exception& e) { | |
| 141 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") | |
| 142 .arg(tr("Error")) | |
| 143 .arg(e.what()) ); | |
| 144 } | |
| 145 if(HeaderBuffer[0] != 0) | |
| 146 { | |
| 147 LOG_INFO(tr("Got something")); | |
| 148 updateHeaderStatus(); | |
| 149 } | |
| 150 } | |
| 151 | |
| 152 | |
| 153 | |
| 154 void EditLogDialog::on_HeaderUsage_valueChanged(int value) | |
| 155 { | |
| 156 | |
| 157 } | |
| 158 | |
| 159 void EditLogDialog::on_ReadAllSamples_clicked() | |
| 160 { | |
| 161 try { | |
| 162 LOG_INFO(tr("Request All Samples...")); | |
| 163 _op->getAllSamples(SampleBuffer); | |
| 164 } | |
| 165 catch(const std::exception& e) { | |
| 166 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") | |
| 167 .arg(tr("Error")) | |
| 168 .arg(e.what()) ); | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 void EditLogDialog::on_WriteAllSamples_clicked() | |
| 173 { | |
| 174 try { | |
| 175 LOG_INFO(tr("Request All Samples...")); | |
| 176 _op->writeAllSamples(SampleBuffer); | |
| 177 } | |
| 178 catch(const std::exception& e) { | |
| 179 LOG_INFO( QString("<bg><font color='red'>%1</font></color>: %2") | |
| 180 .arg(tr("Error")) | |
| 181 .arg(e.what()) ); | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 void EditLogDialog::on_pushButton_2_clicked() | |
| 186 { | |
| 187 qint64 length; | |
| 188 QFile dumpFile; | |
| 189 dumpFile.setFileName("Log_Dump.bin"); | |
| 190 if( ! dumpFile.open(QIODevice::WriteOnly) ) | |
| 191 { | |
| 192 LOG_THROW( "Cannot create dump file " ); | |
| 193 } | |
| 194 else | |
| 195 { | |
| 196 length = 0x8000*8 + 1; | |
| 197 dumpFile.write((const char*)HeaderBuffer,length); | |
| 198 length = 0xC00000 + 4; | |
| 199 dumpFile.write((const char*)SampleBuffer,length); | |
| 200 dumpFile.close(); | |
| 201 } | |
| 202 } | |
| 203 | |
| 204 void EditLogDialog::on_LoadDump_clicked() | |
| 205 { | |
| 206 qint64 length; | |
| 207 QFile dumpFile; | |
| 208 dumpFile.setFileName("Log_Dump.bin"); | |
| 209 if( ! dumpFile.open(QIODevice::ReadOnly) ) | |
| 210 { | |
| 211 LOG_THROW( "Cannot read dump file " ); | |
| 212 } | |
| 213 else | |
| 214 { | |
| 215 length = 0x8000*8 + 1; | |
| 216 dumpFile.read((char*)HeaderBuffer,length); | |
| 217 length = 0xC00000 + 4; | |
| 218 dumpFile.read((char*)SampleBuffer,length); | |
| 219 dumpFile.close(); | |
| 220 | |
| 221 updateHeaderStatus(); | |
| 222 updateSampleStatus(); | |
| 223 } | |
| 224 } | |
| 225 | |
| 226 void EditLogDialog::updateHeaderStatus() | |
| 227 { | |
| 228 QProgressBar* w = _ui->HeaderUsage; | |
| 229 QTableWidget* sv = _ui->SectorView; | |
| 230 SLogbookHeader* LogInfo; | |
| 231 SSmallHeader* smallHeader; | |
| 232 unsigned char HeaderInUse = 0; | |
| 233 uint32_t index, index2; | |
| 234 uint32_t sampleStartAddr, sampleEndAddr, sampleLength; | |
| 235 int row; | |
| 236 int colum; | |
| 237 | |
| 238 for(index = 0; index < 16; index++) | |
| 239 { | |
| 240 for(index2 = 0; index2 < 16; index2++) | |
| 241 { | |
| 242 if((HeaderBuffer[(0x800 * (index * 16 + index2 )) + HEADER2OFFSET] == 0xFA) | |
| 243 && (HeaderBuffer[(0x800 * (index * 16 + index2 )) + HEADER2OFFSET + 1] == 0xFA)) | |
| 244 { | |
| 245 HeaderInUse++; | |
| 246 LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (index*16+index2))+0x400); | |
| 247 sampleEndAddr = (LogInfo->profileLength[2]<<16) + (LogInfo->profileLength[1]<<8) + LogInfo->profileLength[0]; | |
| 248 if( sampleEndAddr == 0) | |
| 249 { | |
| 250 sv->item(index,index2)->setBackground(Qt::black); | |
| 251 } | |
| 252 else | |
| 253 { | |
| 254 LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (index*16+index2))); | |
| 255 sampleStartAddr = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; | |
| 256 smallHeader = (SSmallHeader*) &SampleBuffer[sampleStartAddr-0x100000]; | |
| 257 sampleLength = (smallHeader->profileLength[2] << 16)+ (smallHeader->profileLength[1] << 8) + smallHeader->profileLength[0]; | |
| 258 if(sampleLength == sampleEndAddr) // - sampleStartAddr)) | |
| 259 { | |
| 260 sv->item(index,index2)->setBackground(Qt::green); | |
| 261 } | |
| 262 else { | |
| 263 sv->item(index,index2)->setBackground(Qt::red); | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 } | |
| 268 else | |
| 269 { | |
| 270 sv->item(index,index2)->setBackground(Qt::white); | |
| 271 } | |
| 272 } | |
| 273 } | |
| 274 row =(HeaderBuffer[(0x8000 * 8)])/16; | |
| 275 colum =(HeaderBuffer[(0x8000 * 8)] % 16); | |
| 276 sv->item(row,colum)->setBackground(Qt::blue); | |
| 277 w->setMaximum(256); | |
| 278 w->setValue(HeaderInUse); | |
| 279 } | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 void EditLogDialog::on_SectorView_cellClicked(int row, int column) | |
| 286 { | |
| 287 | |
| 288 } | |
| 289 | |
| 290 void EditLogDialog::updateSampleStatus() | |
| 291 { | |
| 292 uint8_t row,colum; | |
| 293 uint32_t index; | |
| 294 QTableWidget* sv = _ui->SampleView; | |
| 295 QProgressBar* w = _ui->SampleUsage; | |
| 296 uint8_t SamplesInUse = 0; | |
| 297 | |
| 298 for(index = 0; index < 192; index++) | |
| 299 { | |
| 300 row = index / 16; | |
| 301 colum =index % 16; | |
| 302 | |
| 303 if(SampleBuffer[index * 0x10000] != 0xFF) /* used */ | |
| 304 { | |
| 305 SamplesInUse++; | |
| 306 if(SampleBuffer[index * 0x10000 + 0xFFFF] == 0xFF) /* open */ | |
| 307 { | |
| 308 sv->item(row,colum)->setBackground(Qt::blue); | |
| 309 } | |
| 310 else | |
| 311 { | |
| 312 sv->item(row,colum)->setBackground(Qt::green); /* closed */ | |
| 313 } | |
| 314 } | |
| 315 else | |
| 316 { | |
| 317 sv->item(row,colum)->setBackground(Qt::white); /* empty */ | |
| 318 } | |
| 319 } | |
| 320 w->setMaximum(192); | |
| 321 w->setValue(SamplesInUse); | |
| 322 } | |
| 323 | |
| 324 | |
| 325 | |
| 326 void EditLogDialog::on_SectorView_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) | |
| 327 { | |
| 328 SLogbookHeader* LogInfo; | |
| 329 SLogbookHeader* LogInfo2nd; | |
| 330 QTextEdit* tf = _ui->textBrowser_2; | |
| 331 QString InfoText; | |
| 332 QTableWidget* sv = _ui->SampleView; | |
| 333 uint32_t sampleAddrStart = 0; | |
| 334 uint32_t sampleAddrEnd = 0; | |
| 335 uint8_t rowidx, columidx; | |
| 336 | |
| 337 tf->setReadOnly(true); | |
| 338 | |
| 339 LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (currentRow*16+currentColumn))); | |
| 340 LogInfo2nd = (SLogbookHeader*)(HeaderBuffer+(0x800 * (currentRow*16+currentColumn)) +0x400); | |
| 341 | |
| 342 updateSampleStatus(); | |
| 343 | |
| 344 if(LogInfo->diveHeaderStart == 0xFAFA) | |
| 345 { | |
| 346 sampleAddrStart = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; | |
| 347 sampleAddrEnd = (LogInfo2nd->pEndProfileData[2]<<16) + (LogInfo2nd->pEndProfileData[1]<<8) + LogInfo2nd->pEndProfileData[0]; | |
| 348 | |
| 349 // InfoText.sprintf("Header: %d \nNummer: %d\nSamplestart 0x%x\nSampleend 0x%x", currentRow*16+currentColumn, LogInfo->diveNumber,sampleAddrStart,sampleAddrEnd); | |
| 350 InfoText = QString::asprintf( | |
| 351 "Header: %d \nNummer: %d\nSamplestart 0x%x\nSampleend 0x%x", | |
| 352 currentRow*16 + currentColumn, | |
| 353 LogInfo->diveNumber, | |
| 354 sampleAddrStart, | |
| 355 sampleAddrEnd | |
| 356 ); | |
| 357 sampleAddrStart = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; | |
| 358 if(sampleAddrStart != 0) | |
| 359 { | |
| 360 sampleAddrStart -= 0x100000; /* substract memory offset */ | |
| 361 sampleAddrStart /= 0x10000; /* calc sector */ | |
| 362 sv->item(sampleAddrStart / 16, sampleAddrStart % 16)->setBackground(Qt::magenta); | |
| 363 } | |
| 364 else | |
| 365 { | |
| 366 sv->item(0, 0)->setBackground(Qt::black); | |
| 367 } | |
| 368 } | |
| 369 else | |
| 370 { | |
| 371 InfoText = QString::asprintf("Empty"); | |
| 372 } | |
| 373 tf->setPlainText((InfoText)); | |
| 374 } | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 void EditLogDialog::on_SampleView_currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) | |
| 381 { | |
| 382 uint16_t sampleSector; | |
| 383 uint8_t headerRow, headerColumn; | |
| 384 SLogbookHeader* LogInfo; | |
| 385 SLogbookHeader* LogInfo2nd; | |
| 386 uint32_t sectorStart, sectorEnd; | |
| 387 uint32_t sampleAddrStart, sampleAddrEnd; | |
| 388 QTableWidget* headerView = _ui->SectorView; | |
| 389 | |
| 390 sampleSector = currentRow * 16 + currentColumn; | |
| 391 sectorStart = sampleSector * 0x10000 + 0x100000; | |
| 392 sectorEnd = sectorStart +0xFFFF; | |
| 393 if(SampleBuffer[sectorStart - 0x100000] != 0xFF) // is buffer used? | |
| 394 { | |
| 395 updateHeaderStatus(); | |
| 396 for(headerRow = 0; headerRow < 16; headerRow++) | |
| 397 { | |
| 398 for(headerColumn = 0; headerColumn < 16; headerColumn++) | |
| 399 { | |
| 400 LogInfo = (SLogbookHeader*)(HeaderBuffer+(0x800 * (headerRow*16+headerColumn))); | |
| 401 LogInfo2nd = (SLogbookHeader*)(HeaderBuffer+(0x800 * (headerRow*16+headerColumn)) +0x400); | |
| 402 sampleAddrStart = (LogInfo->pBeginProfileData[2]<<16) + (LogInfo->pBeginProfileData[1]<<8) + LogInfo->pBeginProfileData[0]; | |
| 403 sampleAddrEnd = (LogInfo2nd->pEndProfileData[2]<<16) + (LogInfo2nd->pEndProfileData[1]<<8) + LogInfo2nd->pEndProfileData[0]; | |
| 404 | |
| 405 if(((sampleAddrStart >= sectorStart)&&(sampleAddrStart < sectorEnd) | |
| 406 || (sampleAddrEnd >= sectorStart)&&(sampleAddrEnd < sectorEnd))) | |
| 407 { | |
| 408 headerView->item(headerRow, headerColumn)->setBackground(Qt::magenta); | |
| 409 } | |
| 410 } | |
| 411 } | |
| 412 } | |
| 413 } |
