Compare commits

...

3 Commits

3 changed files with 68 additions and 41 deletions

View File

@ -104,10 +104,11 @@ void DownloadThread::run() {
m_hw->dcDownloadRequestAck();
qCritical() << "DownloadThread::run(): DOWNLOAD THREAD STARTED:";
qCritical() << " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): DOWNLOAD THREAD STARTED:";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< " DownloadThread::run(): Filename:" << m_hw->dcDownloadFileName();
#if 1
// load binary device controller file into memory
QByteArray ba = loadBinaryDCFile(m_hw->dcDownloadFileName());
if (ba.size() > 0) {
@ -117,15 +118,29 @@ void DownloadThread::run() {
// fill last block of data to be sent with 0xFF
ba = ba.leftJustified(totalBlocks*64, (char)(0xFF));
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): TOTAL NUMBER OF BYTES TO SEND TO DC" << ba.size();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): TOTAL NUMBER OF BLOCKS" << totalBlocks;
m_hw->dc_autoRequest(true); // turn auto-request setting on
resetDeviceController();
m_hw->request_DC2_HWversion();
m_hw->request_DC2_SWversion();
QThread::sleep(1);
resetDeviceController();
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): RESET DEVICE-CONTROLLER";
QThread::sleep(1);
if (startBootloader()) {
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STARTED BOOT-LOADER";
m_hw->dc_autoRequest(false);// turn auto-request setting off for
// download of binary dc
#if 0
int currentBlock = 0; // download of binary dc
DownloadResult res = DownloadResult::OK;
@ -160,34 +175,26 @@ void DownloadThread::run() {
// QThread::msleep(250);
}
qCritical() << "DownloadThread::run(): last result" << (int)sendStatus(m_hw->bl_wasSendingDataOK());
#else
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
QThread::msleep(250);
}
#endif
m_hw->dc_autoRequest(true); // turn auto-request setting on again
}
stopBootloader(); // there is no harm in stopping the bootloader even
} // if it was not started at all
#else
// 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));
for (uint16_t currentBlock = 0; currentBlock <= totalBlocks; ++currentBlock) {
m_hw->dcDownloadSetCurrentBlockNumber(currentBlock);
qCritical() << "DownloadThread::run(): currentBlockNumber" << currentBlock;
QThread::msleep(250);
}
// if it was not started at all
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DownloadThread::run(): STOPPED BOOT-LOADER";
}
#endif
m_hw->dcDownloadSetRunning(false);
m_hw->dcDownloadSetFinished(true);
qCritical() << QDateTime::currentDateTime().toString(Qt::ISODate) + "DOWNLOAD THREAD FINISHED";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "DOWNLOAD THREAD FINISHED";
// the object deletes itself ! This is the last line in run().
// Never touch the object after this statement
@ -279,46 +286,59 @@ DownloadThread::sendNextDataBlock(QByteArray const &binary, int bNum) const {
}
bool DownloadThread::startBootloader() const {
qDebug() << "starting bootloader...";
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader...";
int nTry = 5;
while (--nTry >= 0) {
m_hw->bl_startBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_startBL() ..." << nTry;
QThread::msleep(1000);
m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
QThread::msleep(1000);
if (m_hw->bl_isUp()) {
qInfo() << "starting bootloader...OK";
QThread::msleep(1000);
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bootloader... isUP" << nTry;
return true;
} else {
qCritical() << "bootloader not up (" << nTry << ")";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bootloader not up (" << nTry << ")";
}
}
qCritical() << "starting bootloader...FAILED";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "starting bootloader FAILED";
return false;
}
bool DownloadThread::stopBootloader() const {
qDebug() << "stopping bootloader...";
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader...";
int nTry = 5;
while (--nTry >= 0) {
m_hw->bl_stopBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "bl_stopBL() ...";
QThread::msleep(500);
m_hw->bl_checkBL();
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate) << "bl_checkBL() ..." << nTry;
if (!m_hw->bl_isUp()) {
qInfo() << "stopping bootloader...OK";
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader OK";
return true;
}
}
qCritical() << "stopping bootloader...FAILED";
qCritical() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "stopping bootloader FAILED";
return false;
}
bool DownloadThread::resetDeviceController() const {
qDebug() << "resetting device controller...";
qDebug() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller...";
m_hw->bl_rebootDC();
// wait maximally 3 seconds, before starting bootloader
QThread::sleep(1);
qInfo() << "resetting device controller...OK";
qInfo() << QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "resetting device controller...OK";
return true;
}

View File

@ -23,7 +23,8 @@ ReportingThread::~ReportingThread() {
void ReportingThread::run() {
qCritical()
<< QDateTime::currentDateTime() << "START REPORT THREAD"
<< QDateTime::currentDateTime().time().toString(Qt::ISODate)
<< "START REPORT THREAD"
<< "(PART OF APPLICATION" << QCoreApplication::applicationName() << ")";
static QString report("");
@ -32,9 +33,9 @@ void ReportingThread::run() {
while (!m_hw->dcDownloadGetRunning()) {
if (--cnt > 0) {
report = QString("%1 waiting for download to start %2")
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
.arg(QDateTime::currentDateTime().time().toString(Qt::ISODate))
.arg(cnt);
qCritical() << __LINE__ << "STATUS" << report;
qCritical() << "(" << __func__ << ":" << __LINE__ << ") STATUS" << report;
emit m_hw->hwapi_reportDCDownloadStatus(report);
QThread::sleep(1);
} else break;

View File

@ -64,7 +64,8 @@ bool indat_isMdbOn()
void gpi_storeHWver(QString text)
{
if (qstrlen(SharedMem::read()->indat_HWversion) == 0) {
QString hwVersion((char const *)SharedMem::read()->indat_HWversion);
if (hwVersion != text) {
char const *p = text.toUtf8().constData();
if (qstrlen(p) > 0) {
memset(SharedMem::write()->indat_HWversion, 0, versionBufferLen);
@ -72,6 +73,8 @@ void gpi_storeHWver(QString text)
qMin((uint)versionBufferLen, qstrlen(p)) - 1);
}
}
qCritical() << "HW TEXT" << epi_loadHWver();
}
QString epi_loadHWver(void)
@ -80,8 +83,9 @@ QString epi_loadHWver(void)
}
void gpi_storeSWver(QString text)
{
if (qstrlen(SharedMem::read()->indat_SWversion) == 0) {
{
QString swVersion((char const *)SharedMem::read()->indat_SWversion);
if (swVersion != text) {
char const *p = text.toUtf8().constData();
if (qstrlen(p) > 0) {
memset(SharedMem::write()->indat_SWversion, 0, versionBufferLen);
@ -89,6 +93,8 @@ void gpi_storeSWver(QString text)
qMin((uint)versionBufferLen, qstrlen(p)) - 1);
}
}
qCritical() << "SW TEXT" << epi_loadSWver();
}
QString epi_loadSWver(void)