Compare commits

..

No commits in common. "3fc8562a2b33fea259f6d9b378828f3ae15ca435" and "bdef3ff652e250b1735b45a688dc8220219a563c" have entirely different histories.

6 changed files with 108 additions and 278 deletions

View File

@ -33,8 +33,6 @@ QMAKE_CXXFLAGS += -C
QMAKE_CXXFLAGS += -O2 -O QMAKE_CXXFLAGS += -O2 -O
QMAKE_CXXFLAGS += -g QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy QMAKE_CXXFLAGS += -Wno-deprecated-copy
# QMAKE_CXXFLAGS += -fsanitize=address
# QMAKE_CXXFLAGS += -fno-omit-frame-pointer
QMAKE_LFLAGS += -Wl,-e,main QMAKE_LFLAGS += -Wl,-e,main

View File

@ -104,121 +104,11 @@ void DownloadThread::run() {
m_hw->dcDownloadRequestAck(); m_hw->dcDownloadRequestAck();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): DOWNLOAD THREAD STARTED:"; << "DownloadThread::run(): DOWNLOAD THREAD STARTED:";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName(); << " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
QDateTime const start = QDateTime::currentDateTime();
#if 1
QFile fn(m_hw->dcDownloadFileName());
if (!fn.exists()) {
// output via CONSOLE() etc
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName() << "DOES NOT EXIST";;
} else {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): DC-CONTROLLER SW-VERSION BEFORE"
<< m_hw->dc_getSWversion();
// load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) {
uint16_t const totalBlocks = (((ba.size())%64)==0) ? (ba.size()/64) : (ba.size()/64)+1;
m_hw->dcDownloadSetTotalBlockNumber(totalBlocks);
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
m_hw->dc_autoRequest(true); // turn auto-request setting on
m_hw->request_DC2_HWversion();
m_hw->request_DC2_SWversion();
QThread::sleep(1);
// m_hw->dc_autoRequest(false); // turn auto-request setting on
resetDeviceController();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): RESET DEVICE-CONTROLLER";
if (startBootloader()) {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): STARTED BOOT-LOADER";
m_hw->dc_autoRequest(false);// turn auto-request setting off for
// download of binary dc
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): TOTAL NUMBER OF FIRMWARE BLOCKS" << totalBlocks;
int currentBlock = 0; // download of binary dc
DownloadResult res = DownloadResult::OK;
while (res != DownloadResult::ERROR && currentBlock < totalBlocks) {
if ((res = sendNextAddress(currentBlock)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, currentBlock)) != DownloadResult::ERROR) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): currentBlockNumber ..." << currentBlock;
currentBlock += 1;
}
}
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< QString("DownloadThread::run(): last 64-byte block %1").arg(currentBlock);
int const rest = ba.size() % 64;
int const offset = ba.size() - rest;
char const *startAddress = ba.constData() + offset;
if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest);
qCritical() << "DownloadThread::run(): ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
} else {
m_hw->bl_sendLastBlock();
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
// QThread::msleep(250);
}
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
stopBootloader(); // stop bootloader several times: if it
QThread::sleep(1); // is not stopped, then the PSA has to be
}
// restarted manually (!!!)
stopBootloader();
QThread::sleep(1);
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs)
<< "DownloadThread::run(): STOPPED BOOT-LOADER";
stopBootloader(); // there is no harm in stopping the bootloader even
// if it was not started at all
m_hw->dc_autoRequest(true);
}
#else // test
// load binary device controller file into memory // load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName()); QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) { if (ba.size() > 0) {
@ -228,9 +118,9 @@ void DownloadThread::run() {
// fill last block of data to be sent with 0xFF // fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF)); ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size(); << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks; << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
m_hw->dc_autoRequest(true); // turn auto-request setting on m_hw->dc_autoRequest(true); // turn auto-request setting on
@ -241,46 +131,70 @@ void DownloadThread::run() {
resetDeviceController(); resetDeviceController();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): RESET DEVICE-CONTROLLER"; << "DownloadThread::run(): RESET DEVICE-CONTROLLER";
QThread::sleep(1); QThread::sleep(1);
if (startBootloader()) { if (startBootloader()) {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STARTED BOOT-LOADER"; << "DownloadThread::run(): STARTED BOOT-LOADER";
m_hw->dc_autoRequest(false);// turn auto-request setting off for m_hw->dc_autoRequest(false);// turn auto-request setting off for
// download of binary dc // download of binary dc
#if 0
int currentBlock = 0; // download of binary dc
DownloadResult res = DownloadResult::OK;
qCritical() << "64-byte block " << currentBlock;
while (res != DownloadResult::ERROR && currentBlock < totalBlocks) {
if ((res = sendNextAddress(currentBlock)) != DownloadResult::ERROR) {
if ((res = sendNextDataBlock(ba, currentBlock)) != DownloadResult::ERROR) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
currentBlock += 1;
}
}
}
qCritical() << "DownloadThread::run(): last 64-byte block %04d" << currentBlock;
int const rest = ba.size() % 64;
int const offset = ba.size() - rest;
char const *startAddress = ba.constData() + offset;
if (rest > 0) {
// SHOULD NEVER HAPPEN !!!
uint8_t local[66];
memset(local, 0xFF, sizeof(local));
memcpy(local, startAddress, rest);
qCritical() << "DownloadThread::run(): ERROR SEND REMAINING" << rest << "BYTES";
m_hw->bl_sendDataBlock(64, local);
} else {
m_hw->bl_sendLastBlock();
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
// QThread::msleep(250);
}
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
#else
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) { for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock); m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock; qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
QThread::msleep(250); QThread::msleep(250);
} }
#endif
m_hw->dc_autoRequest(true); // turn auto-request setting on again m_hw->dc_autoRequest(true); // turn auto-request setting on again
} }
stopBootloader(); // there is no harm in stopping the bootloader even stopBootloader(); // there is no harm in stopping the bootloader even
// if it was not started at all // if it was not started at all
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STOPPED BOOT-LOADER"; << "DownloadThread::run(): STOPPED BOOT-LOADER";
} }
#endif
m_hw->dcDownloadSetRunning(false); m_hw->dcDownloadSetRunning(false);
m_hw->dcDownloadSetFinished(true); m_hw->dcDownloadSetFinished(true);
QDateTime const end = QDateTime::currentDateTime(); qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
quint64 secs = start.secsTo(end); << "DOWNLOAD THREAD FINISHED";
QString runtime;
if (secs % 60) {
runtime = QString("%1min %2s").arg(secs / 60).arg(secs % 60);
} else {
runtime = QString("%1min").arg((secs / 60) + 1);
}
qCritical() << end.time().toString(Qt::ISODateWithMs)
<< QString("DOWNLOAD THREAD FINISHED (RUNTIME %1)")
.arg(runtime);
// the object deletes itself ! This is the last line in run(). // the object deletes itself ! This is the last line in run().
// Never touch the object after this statement // Never touch the object after this statement
@ -304,6 +218,7 @@ DownloadThread::sendNextAddress(int bNum) const {
int noAnswerCount = 0; int noAnswerCount = 0;
int errorCount = 0; int errorCount = 0;
if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) { if ( bNum==0 || bNum==1024 || bNum==2048 || bNum==3072 || bNum==4096 ) {
// qDebug() << "addr-block" << bNum << "...";
while (noAnswerCount <= 250) { while (noAnswerCount <= 250) {
m_hw->bl_sendAddress(bNum); m_hw->bl_sendAddress(bNum);
QThread::msleep(100); QThread::msleep(100);
@ -342,6 +257,9 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
memcpy(local, binary.constData() + bAddr, 64); memcpy(local, binary.constData() + bAddr, 64);
local[64] = local[65] = 0x00; local[64] = local[65] = 0x00;
// QByteArray b((const char *)(&local[0]), 64);
// qCritical() << "SNDB" << bNum << b.size() << b.toHex();
while (noAnswerCount <= 250) { while (noAnswerCount <= 250) {
m_hw->bl_sendDataBlock(64, local); m_hw->bl_sendDataBlock(64, local);
QThread::msleep(10); QThread::msleep(10);
@ -354,7 +272,9 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
} }
} else { } else {
// qInfo() << "data for block" << bNum << "OK"; // qInfo() << "data for block" << bNum << "OK";
// TODO: hier ins shared mem schreiben
// TODO: hier ins shared mem schreiben
return res; return res;
} }
} else { } else {
@ -366,65 +286,64 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
} }
bool DownloadThread::startBootloader() const { bool DownloadThread::startBootloader() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader..."; << "starting bootloader...";
int nTry = 5; int nTry = 5;
while (--nTry >= 0) { while (--nTry >= 0) {
m_hw->bl_startBL(); m_hw->bl_startBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bl_startBL() ..." << nTry; qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_startBL() ..." << nTry;
QThread::msleep(500); QThread::msleep(1000);
m_hw->bl_checkBL(); m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bl_checkBL() ..." << nTry; qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
QThread::msleep(500); QThread::msleep(1000);
if (m_hw->bl_isUp()) { if (m_hw->bl_isUp()) {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bootloader... isUP" << nTry; qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bootloader... isUP" << nTry;
return true; return true;
} else { } else {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bootloader not up (" << nTry << ")"; << "bootloader not up (" << nTry << ")";
} }
} }
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader FAILED"; << "starting bootloader FAILED";
return false; return false;
} }
bool DownloadThread::stopBootloader() const { bool DownloadThread::stopBootloader() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader..."; << "stopping bootloader...";
int nTry = 5; int nTry = 5;
while (--nTry >= 0) { while (--nTry >= 0) {
m_hw->bl_stopBL(); m_hw->bl_stopBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bl_stopBL() ..."; << "bl_stopBL() ...";
QThread::msleep(500); QThread::msleep(500);
m_hw->bl_checkBL(); m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) << "bl_checkBL() ..." << nTry; qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
if (!m_hw->bl_isUp()) { if (!m_hw->bl_isUp()) {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader OK"; << "stopping bootloader OK";
return true; return true;
} }
} }
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader FAILED"; << "stopping bootloader FAILED";
return false; return false;
} }
bool DownloadThread::resetDeviceController() const { bool DownloadThread::resetDeviceController() const {
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller..."; << "resetting device controller...";
m_hw->bl_rebootDC(); m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader // wait maximally 3 seconds, before starting bootloader
QThread::sleep(1); QThread::sleep(1);
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller...OK"; << "resetting device controller...OK";
return true; return true;
} }
QByteArray DownloadThread::loadBinaryDCFile(QString filename) const { QByteArray DownloadThread::loadBinaryDCFile(QString filename) const {
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODateWithMs) qDebug() << "loading dc binary" << filename << "...";
<< "loading dc binary" << filename << "...";
QFile file(filename); // closed in destructor call QFile file(filename); // closed in destructor call
if (!file.exists()) { if (!file.exists()) {

View File

@ -2640,23 +2640,12 @@ void hwapi::bl_openBinary(void) const
void hwapi::bl_sendDataBlock(uint8_t length, uint8_t *buffer) const void hwapi::bl_sendDataBlock(uint8_t length, uint8_t *buffer) const
{ {
// send 64 byte from bin file // send 64 byte from bin file
// gh, 09/02/2024: extend sendBuf. Buffer sometimes too small, sendLen=81 uint8_t LL=length, sendBuf[80], sendLen;
uint8_t LL=length, sendBuf[80+32], sendLen;
if (LL>64) LL=64; if (LL>64) LL=64;
memset(sendBuf, 0, sizeof(sendBuf)); tslib_strclr(sendBuf,0,80);
sendLen=dcBL_prepareDC_BLcmd(0x22, LL, buffer, sendBuf); // pack into protocol frame sendLen=dcBL_prepareDC_BLcmd(0x22, LL, buffer, sendBuf); // pack into protocol frame
// qCritical() << "(" __func__ << ":" << __LINE__ << ") sendLen=" << sendLen
// << ":" << QByteArray((const char *)sendBuf, sendLen);
sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes sendWRcmd_setSendBlock160(sendLen, sendBuf); // send 140 bytes
// if (sendLen > 80) {
// qCritical() << "(" << __func__ << ":" << __LINE__ << ")"
// << QByteArray((const char *)&sendBuf[80], 32).toHex(':');
// }
delay(100); delay(100);
} }

View File

@ -8,7 +8,6 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <cmath> #include <cmath>
#include <algorithm>
ReportingThread::ReportingThread(hwapi *hw) ReportingThread::ReportingThread(hwapi *hw)
: m_hw(hw) : m_hw(hw)
@ -100,27 +99,14 @@ void ReportingThread::run() {
#endif #endif
uint16_t totalBlocks = m_hw->dcDownloadGetTotalBlockNumber(); uint16_t const totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
cnt = 10;
while(--cnt > 0 && totalBlocks == 0) {
totalBlocks = m_hw->dcDownloadGetTotalBlockNumber();
qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
<< QString("line=%1 TOTAL BLOCKS=%2 (%3)")
.arg(__LINE__).arg(totalBlocks).arg(cnt);
QThread::sleep(1);
}
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << __PRETTY_FUNCTION__ qCritical() << QDateTime::currentDateTime() << "TOTAL BLOCKS" << totalBlocks;
<< QString("line=%1 TOTAL BLOCKS=%2").arg(__LINE__).arg(totalBlocks);
if (totalBlocks) { if (totalBlocks) {
QDateTime const start = QDateTime::currentDateTime(); QDateTime const start = QDateTime::currentDateTime();
uint16_t currentBlockNumber = 0; uint16_t currentBlockNumber = 0;
uint16_t prevBlockNumber = ~0; uint16_t prevBlockNumber = ~0;
uint64_t estimatedMinutesLeftMax = ~0ULL;
uint64_t estimatedSecondsLeftMax = ~0ULL;
uint64_t estimatedMinutesLeftPrev = 0;
uint64_t estimatedSecondsLeftPrev = 0;
while (m_hw->dcDownloadGetRunning()) { while (m_hw->dcDownloadGetRunning()) {
currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber(); currentBlockNumber = m_hw->dcDownloadGetCurrentBlockNumber();
@ -128,48 +114,24 @@ void ReportingThread::run() {
double durationSecs = start.secsTo(QDateTime::currentDateTime()); double durationSecs = start.secsTo(QDateTime::currentDateTime());
double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs; double const timeAveragePerBlock = (currentBlockNumber > 0) ? (durationSecs / currentBlockNumber) : durationSecs;
uint64_t estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber))); long estimatedSecondsLeft = lround((timeAveragePerBlock * (totalBlocks - currentBlockNumber)));
uint64_t estimatedMinutesLeft = long estimatedMinutesLeft =
((estimatedSecondsLeft % 60) == 0) ? ((estimatedSecondsLeft % 60) == 0) ?
(estimatedSecondsLeft / 60) : (estimatedSecondsLeft / 60) :
((estimatedSecondsLeft + 60) / 60); ((estimatedSecondsLeft + 60) / 60);
estimatedSecondsLeft = (estimatedSecondsLeft % 60); estimatedSecondsLeft = (estimatedSecondsLeft % 60);
if ((estimatedMinutesLeft <= estimatedMinutesLeftMax) double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
|| (estimatedSecondsLeft <= estimatedSecondsLeftMax)) { report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)")
estimatedMinutesLeftMax = estimatedMinutesLeft; .arg(totalBlocks)
estimatedSecondsLeftMax = estimatedSecondsLeft; .arg(currentBlockNumber)
estimatedMinutesLeftPrev = estimatedMinutesLeft; .arg(percent, 0, 'f', 2)
estimatedSecondsLeftPrev = estimatedSecondsLeft; .arg(estimatedMinutesLeft)
.arg(estimatedSecondsLeft, 2);
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0; qCritical() << m_hw << "RT report" << report;
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)")
.arg(totalBlocks)
.arg(currentBlockNumber)
.arg(percent, 0, 'f', 2)
.arg(estimatedMinutesLeft)
.arg(estimatedSecondsLeft, 2);
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) emit m_hw->hwapi_reportDCDownloadStatus(report);
<< QString("line=%1: RT report").arg(__LINE__) << report;
emit m_hw->hwapi_reportDCDownloadStatus(report);
} else {
double percent = ((double)currentBlockNumber / (double)totalBlocks) * 100.0;
report = QString(": total blocks %1, current block %2 [%3] (est. time left: %4min %5s)")
.arg(totalBlocks)
.arg(currentBlockNumber)
.arg(percent, 0, 'f', 2)
.arg(estimatedMinutesLeftPrev)
.arg(estimatedSecondsLeftPrev, 2);
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< QString("line=%1: RT report").arg(__LINE__) << report;
emit m_hw->hwapi_reportDCDownloadStatus(report);
}
prevBlockNumber = currentBlockNumber; prevBlockNumber = currentBlockNumber;
} }
@ -188,7 +150,7 @@ void ReportingThread::run() {
} }
} }
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << __PRETTY_FUNCTION__ qCritical() << QDateTime::currentDateTime() << __PRETTY_FUNCTION__
<< QString("line=%1 REPORT THREAD ABOUT TO FINISH").arg(__LINE__); << QString("line=%1 REPORT THREAD ABOUT TO FINISH").arg(__LINE__);
cnt = 10; cnt = 10;

View File

@ -684,7 +684,6 @@ bool T_runProc::bl_isUp(void)
for (nn=0; nn<160; nn++) receivedData[nn]=0; for (nn=0; nn<160; nn++) receivedData[nn]=0;
LL=epi_getRawRecLength(); LL=epi_getRawRecLength();
if (LL>0) if (LL>0)
{ {
epi_getRawReceivedData(receivedData); epi_getRawReceivedData(receivedData);
@ -697,24 +696,13 @@ bool T_runProc::bl_isUp(void)
//epi_clrRawReceivedString(); //epi_clrRawReceivedString();
return true; return true;
} }
// response to "start BL"
// response to "start BL" { 2, 101, 48, 223, 131, 3} if (receivedData[0]==2 && receivedData[1]==101 && receivedData[2]==48 &&
static uint8_t const cmp[6] = {0x02, 0x65, 0x30, 0xdf, 0x83, 0x03}; receivedData[3]==223 && receivedData[4] ==131 )
{
if (LL >= 6 && LL <= 13) { qDebug() << "hwapi_bl_isUp: got BL response to start";
// (1) "02:63:34:35:62:33:03:02:65:30:df:83:03" //epi_clrRawReceivedString();
// (2) "02:65:30:df:83:03" return true;
// qCritical() << "(" << __func__ << ":" << __LINE__
// << ") CHECK" << QByteArray((char const*)receivedData, LL).toHex(':');
for (int i=0; i <= LL-6; ++i) {
if (memcmp(cmp, &receivedData[i], 6) == 0) {
qCritical() << "(" << __func__ << ":" << __LINE__
<< ") BL RESPONSE to bl_start(): BOOTLOADER IS UP";
return true;
}
}
} }
} }
return false; return false;

View File

@ -6,8 +6,6 @@
#include "shared_mem_buffer.h" #include "shared_mem_buffer.h"
#include "datei.h" #include "datei.h"
#include <QTextCodec>
// gpi: grafical access to PI: access from external devices over device controller FOR GUI // gpi: grafical access to PI: access from external devices over device controller FOR GUI
// epi: external access from GUI to PI: FOR external devices (DC) // epi: external access from GUI to PI: FOR external devices (DC)
@ -66,64 +64,40 @@ bool indat_isMdbOn()
void gpi_storeHWver(QString text) void gpi_storeHWver(QString text)
{ {
QString prev(QByteArray(SharedMem::read()->indat_HWversion, versionBufferLen-1)); QString hwVersion((char const *)SharedMem::read()->indat_HWversion);
prev = prev.trimmed(); if (hwVersion != text) {
char const *p = text.toUtf8().constData();
QString const textTruncated = text.mid(0, qMin(versionBufferLen-1, text.size())).trimmed(); if (qstrlen(p) > 0) {
if (textTruncated.startsWith("DC2C", Qt::CaseInsensitive)
&& textTruncated != prev) {
QTextCodec *codec = QTextCodec::codecForName("Windows-1252");
QString string = codec->toUnicode(textTruncated.toUtf8());
if (!string.isEmpty()) {
memset(SharedMem::write()->indat_HWversion, 0, versionBufferLen); memset(SharedMem::write()->indat_HWversion, 0, versionBufferLen);
char *p = (char *)SharedMem::write()->indat_HWversion; memcpy(SharedMem::write()->indat_HWversion, p,
char *q = (char *)string.constData(); qMin((uint)versionBufferLen, qstrlen(p)) - 1);
for (int i=0; i < qMin(versionBufferLen, string.size()); ++i) {
int const j = (sizeof(QChar) == 2) ? i*2 : i;
if (q[j]) {
*p++ = q[j];
}
}
} }
qCritical() << "Changed" << hwVersion << "to" << epi_loadHWver();
} }
} }
QString epi_loadHWver(void) QString epi_loadHWver(void)
{ {
QString text(SharedMem::read()->indat_HWversion); return QString((char const*)SharedMem::read()->indat_HWversion);
return text.mid(0, qMin(versionBufferLen-1, text.size())).trimmed();
} }
void gpi_storeSWver(QString text) void gpi_storeSWver(QString text)
{ {
QString prev(QByteArray(SharedMem::read()->indat_SWversion, 12)); QString swVersion((char const *)SharedMem::read()->indat_SWversion);
prev = prev.trimmed(); if (swVersion != text) {
char const *p = text.toUtf8().constData();
QString const textTruncated = text.mid(0, qMin(12, text.size())).trimmed(); if (qstrlen(p) > 0) {
if (textTruncated.startsWith("DC2C", Qt::CaseInsensitive)
&& textTruncated != prev) {
QTextCodec *codec = QTextCodec::codecForName("Windows-1252");
QString string = codec->toUnicode(textTruncated.toUtf8());
if (!string.isEmpty()) {
memset(SharedMem::write()->indat_SWversion, 0, versionBufferLen); memset(SharedMem::write()->indat_SWversion, 0, versionBufferLen);
char *p = (char *)SharedMem::write()->indat_SWversion; memcpy(SharedMem::write()->indat_SWversion, p,
char *q = (char *)string.constData(); qMin((uint)versionBufferLen, qstrlen(p)) - 1);
for (int i=0; i < qMin(versionBufferLen, string.size()); ++i) {
int const j = (sizeof(QChar) == 2) ? i*2 : i;
if (q[j]) {
*p++ = q[j];
}
}
} }
qCritical() << "Changed" << swVersion << "to" << epi_loadSWver();
} }
} }
QString epi_loadSWver(void) QString epi_loadSWver(void)
{ {
QString text(SharedMem::read()->indat_SWversion); return QString((char const*)SharedMem::read()->indat_SWversion);
return text.mid(0, qMin(12, text.size())).trimmed();
} }
void gpi_storeDCstate(QString text) void gpi_storeDCstate(QString text)
@ -2203,8 +2177,8 @@ void gpi_storeRawReceivedData(uint8_t RdDlen, uint8_t *receivedData)
SharedMem::write()->Sdata_LengthRawData=lrd; SharedMem::write()->Sdata_LengthRawData=lrd;
for (nn=0; nn<lrd; nn++) for (nn=0; nn<lrd; nn++)
SharedMem::write()->Sdata_rawData[nn]=receivedData[nn]; SharedMem::write()->Sdata_rawData[nn]=receivedData[nn];
//qDebug()<<"dcBL got data"<< Sdata_LengthRawData << "bytes :)"; //qDebug()<<"dcBL got data"<< Sdata_LengthRawData << "bytes :)";
} }
uint8_t epi_getRawReceivedData(uint8_t *receivedData) uint8_t epi_getRawReceivedData(uint8_t *receivedData)