Check m_hw before its use
This commit is contained in:
parent
d64b029a2d
commit
4477647acf
@ -118,7 +118,7 @@ Update::Update(Worker *worker,
|
|||||||
, m_sys_areDCdataValid(false) {
|
, m_sys_areDCdataValid(false) {
|
||||||
|
|
||||||
if (!m_hw) {
|
if (!m_hw) {
|
||||||
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin loaded ???";
|
qCritical() << "(" << __func__ << ":" << __LINE__ << ") m_hw == nullptr -> ca-slave plugin not loaded";
|
||||||
} else {
|
} else {
|
||||||
int tries = 20;
|
int tries = 20;
|
||||||
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
|
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
|
||||||
@ -185,33 +185,37 @@ void Update::onReportDCDownloadFailure(QString const &errorMsg) {
|
|||||||
|
|
||||||
// br is a index into a table, used for historical reasons.
|
// br is a index into a table, used for historical reasons.
|
||||||
bool Update::openSerial(int br, QString baudrate, QString comPort) const {
|
bool Update::openSerial(int br, QString baudrate, QString comPort) const {
|
||||||
qDebug() << "opening serial" << br << baudrate << comPort << "...";
|
if (m_hw) {
|
||||||
if (m_hw->dc_openSerial(br, baudrate, comPort, 1) == true) { // 1 for connect
|
qDebug() << "opening serial" << br << baudrate << comPort << "...";
|
||||||
Utils::printInfoMsg(
|
if (m_hw->dc_openSerial(br, baudrate, comPort, 1) == true) { // 1 for connect
|
||||||
|
Utils::printInfoMsg(
|
||||||
|
QString("OPENING SERIAL %1").arg(br)
|
||||||
|
+ " " + baudrate + " " + comPort + "...OK");
|
||||||
|
|
||||||
|
// m_hw->dc_autoRequest(true);
|
||||||
|
m_hw->dc_autoRequest(false);
|
||||||
|
QThread::sleep(1);
|
||||||
|
|
||||||
|
Utils::printInfoMsg(QString("IS PORT OPEN %1").arg(m_hw->dc_isPortOpen()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::printCriticalErrorMsg(
|
||||||
QString("OPENING SERIAL %1").arg(br)
|
QString("OPENING SERIAL %1").arg(br)
|
||||||
+ " " + baudrate + " " + comPort + "...OK");
|
+ " " + baudrate + " " + comPort + "...FAILED");
|
||||||
|
|
||||||
// m_hw->dc_autoRequest(true);
|
|
||||||
m_hw->dc_autoRequest(false);
|
|
||||||
QThread::sleep(1);
|
|
||||||
|
|
||||||
Utils::printInfoMsg(QString("IS PORT OPEN %1").arg(m_hw->dc_isPortOpen()));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::printCriticalErrorMsg(
|
|
||||||
QString("OPENING SERIAL %1").arg(br)
|
|
||||||
+ " " + baudrate + " " + comPort + "...FAILED");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update::closeSerial() const {
|
void Update::closeSerial() const {
|
||||||
qInfo() << "CLOSED SERIAL" << m_baudrate << m_serialInterface;
|
qInfo() << "CLOSED SERIAL" << m_baudrate << m_serialInterface;
|
||||||
m_hw->dc_closeSerial();
|
if (m_hw) {
|
||||||
|
m_hw->dc_closeSerial();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Update::isSerialOpen() const {
|
bool Update::isSerialOpen() const {
|
||||||
return m_hw->dc_isPortOpen();
|
return m_hw ? m_hw->dc_isPortOpen() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -390,78 +394,88 @@ bool Update::downloadJson(enum FileTypeJson type,
|
|||||||
int templateIdx,
|
int templateIdx,
|
||||||
QString jsFileToSendToDC) const {
|
QString jsFileToSendToDC) const {
|
||||||
|
|
||||||
m_hw->dc_autoRequest(true); // downloading Json needs the AutoEmission flag
|
|
||||||
qDebug() << "SET AUTO-REQUEST=TRUE";
|
|
||||||
QThread::sleep(1); // make sure the auto-request flag is acknowledged
|
|
||||||
|
|
||||||
QStringList lst;
|
|
||||||
bool ready = false;
|
|
||||||
int nTry = 25;
|
|
||||||
while ((ready = m_hw->sys_ready4sending()) == false) {
|
|
||||||
QThread::msleep(200);
|
|
||||||
if (--nTry <= 0) {
|
|
||||||
QString msg("SYS NOT READY FOR SENDING AFTER 5 SECONDS");
|
|
||||||
Utils::printCriticalErrorMsg(msg);
|
|
||||||
lst << msg;
|
|
||||||
|
|
||||||
if (m_worker) {
|
|
||||||
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
QString msg;
|
if (m_hw) {
|
||||||
lst.clear();
|
m_hw->dc_autoRequest(true); // downloading Json needs the AutoEmission flag
|
||||||
if (ready) {
|
qDebug() << "SET AUTO-REQUEST=TRUE";
|
||||||
QFile file(jsFileToSendToDC);
|
QThread::sleep(1); // make sure the auto-request flag is acknowledged
|
||||||
QFileInfo fi(jsFileToSendToDC); // max. size of template file is 800 bytes
|
|
||||||
if (file.exists()) {
|
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
|
||||||
if (fi.size() > 0 && fi.size() <= 800) {
|
|
||||||
QByteArray ba = file.readAll();
|
|
||||||
// kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer
|
|
||||||
// nrOfTemplate=1...32 if kindOfFile==6
|
|
||||||
// content = content of the Json file, max 800byte ascii signs
|
|
||||||
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
|
|
||||||
templateIdx,
|
|
||||||
(uint8_t *)ba.data())) {
|
|
||||||
|
|
||||||
/*
|
QStringList lst;
|
||||||
* Note: the machine id is contained in DC2C_conf.json.
|
bool ready = false;
|
||||||
* The idea was to use this to check if the download of
|
int nTry = 25;
|
||||||
* the json-file was correct. It did not work, as the
|
while ((ready = m_hw->sys_ready4sending()) == false) {
|
||||||
* update of the PSA (to reflect a change in the
|
QThread::msleep(200);
|
||||||
* machine id) did not happen immediately.
|
if (--nTry <= 0) {
|
||||||
*
|
QString msg("SYS NOT READY FOR SENDING AFTER 5 SECONDS");
|
||||||
m_hw->dc_autoRequest(true);
|
Utils::printCriticalErrorMsg(msg);
|
||||||
QThread::msleep(500);
|
lst << msg;
|
||||||
|
|
||||||
// testing
|
if (m_worker) {
|
||||||
m_hw->request_ReadbackMachineID();
|
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
||||||
QThread::msleep(500);
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t data[64];
|
QString msg;
|
||||||
memset(data, 0x00, sizeof(data));
|
lst.clear();
|
||||||
uint8_t length = 0;
|
if (ready) {
|
||||||
|
QFile file(jsFileToSendToDC);
|
||||||
|
QFileInfo fi(jsFileToSendToDC); // max. size of template file is 800 bytes
|
||||||
|
if (file.exists()) {
|
||||||
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
|
if (fi.size() > 0 && fi.size() <= 800) {
|
||||||
|
QByteArray ba = file.readAll();
|
||||||
|
// kindOfFile: 1=config, 2=device, 3=cash, 4=serial, 5=time, 6=printer
|
||||||
|
// nrOfTemplate=1...32 if kindOfFile==6
|
||||||
|
// content = content of the Json file, max 800byte ascii signs
|
||||||
|
if (m_hw->sys_sendJsonFileToDc((uint8_t)(type),
|
||||||
|
templateIdx,
|
||||||
|
(uint8_t *)ba.data())) {
|
||||||
|
|
||||||
m_hw->readback_machineIDdata(&length, data);
|
/*
|
||||||
|
* Note: the machine id is contained in DC2C_conf.json.
|
||||||
|
* The idea was to use this to check if the download of
|
||||||
|
* the json-file was correct. It did not work, as the
|
||||||
|
* update of the PSA (to reflect a change in the
|
||||||
|
* machine id) did not happen immediately.
|
||||||
|
*
|
||||||
|
m_hw->dc_autoRequest(true);
|
||||||
|
QThread::msleep(500);
|
||||||
|
|
||||||
QThread::msleep(500);
|
// testing
|
||||||
|
m_hw->request_ReadbackMachineID();
|
||||||
|
QThread::msleep(500);
|
||||||
|
|
||||||
QByteArray ba((const char*)data, length);
|
uint8_t data[64];
|
||||||
|
memset(data, 0x00, sizeof(data));
|
||||||
|
uint8_t length = 0;
|
||||||
|
|
||||||
qCritical() << length << "MACHINE ID =" << ba.toHex(':');
|
m_hw->readback_machineIDdata(&length, data);
|
||||||
*/
|
|
||||||
|
|
||||||
if (m_worker) {
|
QThread::msleep(500);
|
||||||
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
|
||||||
|
QByteArray ba((const char*)data, length);
|
||||||
|
|
||||||
|
qCritical() << length << "MACHINE ID =" << ba.toHex(':');
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (m_worker) {
|
||||||
|
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = true;
|
||||||
|
} else {
|
||||||
|
msg = QString("ERROR SEND JSON-FILE %1 TO DC").arg(file.fileName());
|
||||||
|
Utils::printCriticalErrorMsg(msg);
|
||||||
|
lst << msg;
|
||||||
|
if (m_worker) {
|
||||||
|
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst)
|
||||||
|
<< Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
|
||||||
} else {
|
} else {
|
||||||
msg = QString("ERROR SEND JSON-FILE %1 TO DC").arg(file.fileName());
|
msg = QString("SIZE OF %1 TOO BIG (%2 BYTES)").arg(jsFileToSendToDC).arg(fi.size());
|
||||||
Utils::printCriticalErrorMsg(msg);
|
Utils::printCriticalErrorMsg(msg);
|
||||||
lst << msg;
|
lst << msg;
|
||||||
if (m_worker) {
|
if (m_worker) {
|
||||||
@ -470,16 +484,17 @@ bool Update::downloadJson(enum FileTypeJson type,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg = QString("SIZE OF %1 TOO BIG (%2 BYTES)").arg(jsFileToSendToDC).arg(fi.size());
|
msg = QString("CAN NOT OPEN ") + jsFileToSendToDC + " FOR READING";
|
||||||
Utils::printCriticalErrorMsg(msg);
|
Utils::printCriticalErrorMsg(msg);
|
||||||
lst << msg;
|
lst << msg;
|
||||||
|
|
||||||
if (m_worker) {
|
if (m_worker) {
|
||||||
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst)
|
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst)
|
||||||
<< Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
<< Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg = QString("CAN NOT OPEN ") + jsFileToSendToDC + " FOR READING";
|
msg = QString(jsFileToSendToDC) + " DOES NOT EXIST";
|
||||||
Utils::printCriticalErrorMsg(msg);
|
Utils::printCriticalErrorMsg(msg);
|
||||||
lst << msg;
|
lst << msg;
|
||||||
|
|
||||||
@ -488,21 +503,12 @@ bool Update::downloadJson(enum FileTypeJson type,
|
|||||||
<< Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
<< Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
msg = QString(jsFileToSendToDC) + " DOES NOT EXIST";
|
|
||||||
Utils::printCriticalErrorMsg(msg);
|
|
||||||
lst << msg;
|
|
||||||
|
|
||||||
if (m_worker) {
|
|
||||||
m_worker->ISMAS(lst) << (m_worker->GUI(lst) << (m_worker->CONSOLE(lst)
|
|
||||||
<< Worker::UPDATE_STEP::DOWNLOAD_FILES_TO_PSA_HARDWARE));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m_hw->dc_autoRequest(false);
|
m_hw->dc_autoRequest(false);
|
||||||
qDebug() << "SET AUTO-REQUEST=FALSE";
|
qDebug() << "SET AUTO-REQUEST=FALSE";
|
||||||
QThread::sleep(1); // make sure the auto-request flag is acknowledged
|
QThread::sleep(1); // make sure the auto-request flag is acknowledged
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -558,24 +564,26 @@ void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStringList Update::getDcSoftAndHardWareVersion() {
|
QStringList Update::getDcSoftAndHardWareVersion() {
|
||||||
m_hw->dc_autoRequest(true);
|
if (m_hw) {
|
||||||
QThread::sleep(1); // make sure the timer-slots are active
|
m_hw->dc_autoRequest(true);
|
||||||
|
QThread::sleep(1); // make sure the timer-slots are active
|
||||||
|
|
||||||
for (int i=0; i < 3; ++i) { // send explicit reuests to get
|
for (int i=0; i < 3; ++i) { // send explicit reuests to get
|
||||||
// current SW/HW-versions
|
// current SW/HW-versions
|
||||||
m_hw->request_DC2_SWversion();
|
m_hw->request_DC2_SWversion();
|
||||||
m_hw->request_DC2_HWversion();
|
m_hw->request_DC2_HWversion();
|
||||||
QThread::sleep(1);
|
QThread::sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString const &hwVersion = m_hw->dc_getHWversion().toLower().trimmed();
|
QString const &hwVersion = m_hw->dc_getHWversion().toLower().trimmed();
|
||||||
QString const &swVersion = m_hw->dc_getSWversion().toLower().trimmed();
|
QString const &swVersion = m_hw->dc_getSWversion().toLower().trimmed();
|
||||||
|
|
||||||
m_hw->dc_autoRequest(false);
|
m_hw->dc_autoRequest(false);
|
||||||
QThread::sleep(1); // make sure the timer-slots are inactive
|
QThread::sleep(1); // make sure the timer-slots are inactive
|
||||||
|
|
||||||
if (!hwVersion.isEmpty() && !swVersion.isEmpty()) {
|
if (!hwVersion.isEmpty() && !swVersion.isEmpty()) {
|
||||||
return QStringList() << hwVersion << swVersion;
|
return QStringList() << hwVersion << swVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QStringList() << "DC HW-version not available"
|
return QStringList() << "DC HW-version not available"
|
||||||
@ -665,6 +673,11 @@ bool Update::checkDownloadedJsonVersions(QStringList const& jsonFileNames) {
|
|||||||
}
|
}
|
||||||
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
bool Update::doUpdate(int &displayIndex, QStringList const &filesToWorkOn) {
|
||||||
|
|
||||||
|
if (!m_hw) {
|
||||||
|
Utils::printInfoMsg("CA-PLUGIN NOT LOADED");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int tries = 20;
|
int tries = 20;
|
||||||
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
|
while ((m_sys_areDCdataValid = m_hw->sys_areDCdataValid()) == false) {
|
||||||
// must deliver 'true', only then are all data from hwapi valid
|
// must deliver 'true', only then are all data from hwapi valid
|
||||||
|
Loading…
Reference in New Issue
Block a user