Compare commits
11 Commits
0933274c82
...
improve-is
Author | SHA1 | Date | |
---|---|---|---|
05b68f21c2 | |||
9ca394db46 | |||
0d268a1d9d | |||
da102b5ed0 | |||
7031c0e349 | |||
c528ce377d | |||
5e7c848fca | |||
3165d77f49 | |||
f0d2d5f958 | |||
1da4c3b224 | |||
f1cedbf1d5 |
@@ -20,7 +20,11 @@ EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
|
||||
INCLUDEINTERFACES=/opt/ptu5/opt/DCLibraries/include
|
||||
}
|
||||
|
||||
INCLUDEPATH += plugins $${INCLUDEINTERFACES} $${_PRO_FILE_PWD_}/../UpdatePTUDevCtrl
|
||||
INCLUDEPATH += \
|
||||
plugins \
|
||||
$${INCLUDEINTERFACES} \
|
||||
$${_PRO_FILE_PWD_}/../UpdatePTUDevCtrl \
|
||||
$${_PRO_FILE_PWD_}/../../ATBUpdateTool/common/include
|
||||
|
||||
CONFIG += c++17
|
||||
|
||||
@@ -76,12 +80,14 @@ SOURCES += \
|
||||
main.cpp \
|
||||
../UpdatePTUDevCtrl/message_handler.cpp \
|
||||
../UpdatePTUDevCtrl/commandline_parser.cpp \
|
||||
update.cpp
|
||||
update.cpp \
|
||||
../../ATBUpdateTool/common/src/System.cpp
|
||||
|
||||
HEADERS += \
|
||||
../UpdatePTUDevCtrl/message_handler.h \
|
||||
../UpdatePTUDevCtrl/commandline_parser.h \
|
||||
update.h
|
||||
update.h \
|
||||
../../ATBUpdateTool/common/include/System.h
|
||||
|
||||
OTHER_FILES += \
|
||||
ATBDownloadDCJsonFiles.ini
|
||||
|
@@ -230,6 +230,64 @@ bool Update::doUpdate(QStringList const &filesToWorkOn) {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool Update::checkDownloadedJsonVersions(QStringList const& jsonFileNames) {
|
||||
for (QStringList::size_type i=0; i < jsonFileNames.size(); ++i) {
|
||||
|
||||
uint8_t jsonNr = 0;
|
||||
|
||||
QString const &fName = jsonFileNames[i];
|
||||
|
||||
if (fName.endsWith("conf.json")) {
|
||||
jsonNr = 1;
|
||||
} else
|
||||
if (fName.endsWith("device.json")) {
|
||||
jsonNr = 2;
|
||||
} else
|
||||
if (fName.endsWith("cash.json")) {
|
||||
jsonNr = 3;
|
||||
} else {
|
||||
QRegularExpressionMatch match;
|
||||
static const QRegularExpression re("^(.*print)([0-3][0-9])\\.json\\s*$");
|
||||
int idx = fName.indexOf(re, 0, &match);
|
||||
if (idx != -1) {
|
||||
QString captured = match.captured(match.lastCapturedIndex());
|
||||
bool ok = false;
|
||||
int n = captured.toInt(&ok);
|
||||
if (ok) {
|
||||
jsonNr = n + 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonNr != 0) {
|
||||
#if 0
|
||||
m_hw->sys_requestJsonVersions(jsonNr);
|
||||
QThread::msleep(500);
|
||||
|
||||
char buf[64];
|
||||
memset(buf, 0x00, sizeof(buf));
|
||||
m_hw->sys_getJsonVersions(jsonNr, buf);
|
||||
buf[sizeof(buf)-1] = '\0';
|
||||
|
||||
QString const installedVersion(buf);
|
||||
QString const fileVersion = getFileVersion(jsonFileNames[i]);
|
||||
|
||||
qCritical() << "installed version:" << installedVersion;
|
||||
qCritical() << " file version:" << fileVersion;
|
||||
|
||||
if (installedVersion == fileVersion) {
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
qCritical() << "CANNOT FIND JSON-NR FOR" << fName;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Update::downloadJson(enum FileTypeJson type,
|
||||
int templateIdx,
|
||||
QString jsFileToSendToDC) const {
|
||||
|
@@ -66,6 +66,8 @@ public:
|
||||
bool downloadJson(enum FileTypeJson type, int templateIdx,
|
||||
QString jsFileToSendToDC) const;
|
||||
|
||||
|
||||
bool checkDownloadedJsonVersions(QStringList const& jsonFileNames);
|
||||
/*
|
||||
bool checkDownloadedJsonVersions(QStringList const& jsonFileNames);
|
||||
|
||||
|
@@ -116,7 +116,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
# 1.4.5 : In case a new branch has been created in a remote
|
||||
# customer-repository (e.g. origin/zg1/zone101), then fetch/pull
|
||||
# this branch before switching to this now locally existen branch.
|
||||
VERSION="1.4.5"
|
||||
# : Improve output of GUI/Console and messages sent to ISMAS.
|
||||
VERSION="1.4.6"
|
||||
# PLANNED TODOS:
|
||||
# 1: Das Repository wird repariert bwz. neu geklont. Unabhaengig vom WAIT.
|
||||
# 2: Wenn der WAIT-Button aktiv ist, dann wird ein Repository repariert (neu
|
||||
|
@@ -384,7 +384,7 @@ QString IsmasClient::errorBackendNotConnected(QString const &info,
|
||||
QString const &version) {
|
||||
return updateNewsToIsmas("U0003",
|
||||
m_progressInPercent,
|
||||
RESULT_CODE::INSTALL_ERROR,
|
||||
RESULT_CODE::ISMAS_NO_CONNECTION_ERROR,
|
||||
"CHECK BACKEND CONNECTIVITY",
|
||||
info.toStdString().c_str(),
|
||||
version.toStdString().c_str());
|
||||
@@ -394,7 +394,7 @@ QString IsmasClient::errorGitClone(QString const &info,
|
||||
QString const &version) {
|
||||
return updateNewsToIsmas("U0003",
|
||||
m_progressInPercent,
|
||||
RESULT_CODE::INSTALL_ERROR,
|
||||
RESULT_CODE::GIT_CLONE_ERROR,
|
||||
"CLONE CUSTOMER REPOSITORY FAILED",
|
||||
info.toStdString().c_str(),
|
||||
version.toStdString().c_str());
|
||||
@@ -442,7 +442,7 @@ QString IsmasClient::updateTriggerSet(QString const &info, QString const &versio
|
||||
QString IsmasClient::errorUpdateTrigger(QString const &info, QString const &version) {
|
||||
return updateNewsToIsmas("U0003",
|
||||
m_progressInPercent,
|
||||
RESULT_CODE::INSTALL_ERROR,
|
||||
RESULT_CODE::ISMAS_TRIGGER_ERROR,
|
||||
"CHECK UPDATE TRIGGER",
|
||||
info.toStdString().c_str(),
|
||||
version.toStdString().c_str());
|
||||
|
@@ -145,13 +145,47 @@ public:
|
||||
DIRECT_PORT = 7778
|
||||
};
|
||||
|
||||
|
||||
enum RESULT_CODE {
|
||||
SUCCESS=0,
|
||||
// if between 00:00 - 04:00 Wait-button state not WAIT, then we assume
|
||||
// that's an automatic nightly (not-necessary) update
|
||||
NO_UPDATE_NECESSARY=1,
|
||||
BACKUP_FAILED=2,
|
||||
WRONG_PACKAGE=3,
|
||||
INSTALL_ERROR=4};
|
||||
// if APISM reports the ISMAS is not available (15x, 6s delay each)
|
||||
ISMAS_NO_CONNECTION_ERROR=2,
|
||||
// if not within 00:00-04:00 and WAIT-button was not in state WAIT
|
||||
ISMAS_TRIGGER_ERROR=3,
|
||||
// cloning git repo. not possible
|
||||
GIT_CLONE_ERROR=4,
|
||||
// pulling from remote git server not possible
|
||||
GIT_PULL_ERROR=5,
|
||||
// fetching from remote git server not possible
|
||||
GIT_FETCH_ERROR=6,
|
||||
// merging fetched data not possible
|
||||
GIT_MERGE_ERROR=7,
|
||||
// check sanity of local customer-repository failed
|
||||
GIT_CHECK_REPOSITORY_ERROR=8,
|
||||
// switch/checkout of branch (i.e. zone) on error
|
||||
GIT_SWITCH_BRANCH_ERROR=9,
|
||||
// fetch/pull of new branch failed. the new branch was not available
|
||||
// when installing via SD-card followed by intial clone during the
|
||||
// update process.
|
||||
GIT_FETCH_NEW_BRANCH_ERROR=10,
|
||||
// error computing git-blob hash-value
|
||||
GIT_HASH_ERROR=11,
|
||||
// update for general json files failed.
|
||||
JSON_FILES_UPDATE_ERROR=12,
|
||||
// error downloading config-json-files to device controller
|
||||
JSON_FILES_DOWNLOAD_ERROR=13,
|
||||
// error downloading device-controller
|
||||
DC_DOWNLOAD_ERROR=14,
|
||||
// error rsyncing json/ini-files to local filesystem
|
||||
RSYN_ERROR=15,
|
||||
// HASH_VALUE_ERROR=14,
|
||||
// HW_COMPATIBILITY_ERROR=15,
|
||||
OPKG_COMMANDS_ERROR=16,
|
||||
// CLEANUP_ERROR=18,
|
||||
UPDATE_IN_ERROR_STATE=99
|
||||
};
|
||||
|
||||
enum REASON {
|
||||
TIME_TRIGGERED = 0,
|
||||
|
@@ -26,11 +26,21 @@
|
||||
#define SERIAL_PORT "ttyUSB0"
|
||||
#endif
|
||||
|
||||
#define _ISMAS_DONE "U0001" // 100%
|
||||
#define _ISMAS_SET_WAIT_OK "U0002" // empty WAIT-button ("")
|
||||
/*
|
||||
Note:
|
||||
! After U0002 immer ein CMD_SENDVERSION
|
||||
! Only U0002 and U0003 finish the Update process.
|
||||
! U0001: Update finished but not activated
|
||||
! U0002: Update finished and activated
|
||||
! U0003: Update finished but FAILed.
|
||||
*/
|
||||
|
||||
#define _ISMAS_DONE "U0001" // 100%, Check: Resultcode: 0
|
||||
#define _ISMAS_SET_WAIT_OK "U0002" // empty WAIT-button (""), ResultCode: 0
|
||||
#define _ISMAS_FAILURE "U0003" // FAIL
|
||||
#define _ISMAS_CONTINUE "U0010" // %-values
|
||||
#define _ISMAS_CONTINUE "U0010" // %-values: Update laeuft, Resultcodes entsprechend laufender Schritt
|
||||
#define _ISMAS_RESET_WAIT "ISMAS" // reset WAIT-button to "WAIT"
|
||||
#define _ISMAS_TEST_TRIGGER "U0099" // check the WAIT-button
|
||||
|
||||
#define _STARTED (1)
|
||||
#define _CHECK_ISMAS_TRIGGER (2)
|
||||
@@ -739,7 +749,7 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0010",
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_CHECKOUT_REPOSITORY_SUCCESS,
|
||||
IsmasClient::RESULT_CODE::SUCCESS,
|
||||
smap[UPDATE_STEP::CHECK_REPOSITORY],
|
||||
@@ -755,9 +765,9 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0010",
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_CHECKOUT_REPOSITORY_FAILURE,
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
IsmasClient::RESULT_CODE::GIT_SWITCH_BRANCH_ERROR,
|
||||
smap[UPDATE_STEP::CHECKOUT_REPOSITORY],
|
||||
QString("REPOSITORY %1 and BRANCH %2 ***NOT OK***")
|
||||
.arg(instance->m_customerRepository)
|
||||
@@ -774,7 +784,7 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0010",
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_CHECK_SANITY_SUCCESS,
|
||||
IsmasClient::RESULT_CODE::SUCCESS,
|
||||
smap[UPDATE_STEP::CHECK_SANITY],
|
||||
@@ -790,9 +800,9 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0010",
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_CHECK_SANITY_FAILURE,
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
IsmasClient::RESULT_CODE::GIT_CHECK_REPOSITORY_ERROR,
|
||||
smap[UPDATE_STEP::CHECK_SANITY],
|
||||
QString("SANITY OF %1 and BRANCH %2 ***NOT*** OK")
|
||||
.arg(instance->m_customerRepository)
|
||||
@@ -801,21 +811,21 @@ private:
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
} break;
|
||||
case UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS:
|
||||
case UPDATE_STEP::REPOSITORY_RECOVERED_SUCCESS: {
|
||||
ismasClient.setProgressInPercent(_REPOSITORY_RECOVERED_SUCCESS);
|
||||
break;
|
||||
case UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE:
|
||||
} break;
|
||||
case UPDATE_STEP::REPOSITORY_RECOVERED_FAILURE: {
|
||||
ismasClient.setProgressInPercent(_REPOSITORY_RECOVERED_FAILURE);
|
||||
break;
|
||||
case UPDATE_STEP::CLONE_REPOSITORY:
|
||||
} break;
|
||||
case UPDATE_STEP::CLONE_REPOSITORY: {
|
||||
ismasClient.setProgressInPercent(_CLONE_REPOSITORY);
|
||||
break;
|
||||
} break;
|
||||
case UPDATE_STEP::CLONE_REPOSITORY_SUCCESS: {
|
||||
ismasClient.setProgressInPercent(_CLONE_REPOSITORY_SUCCESS);
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0010",
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_CLONE_REPOSITORY_SUCCESS,
|
||||
IsmasClient::RESULT_CODE::SUCCESS,
|
||||
smap[UPDATE_STEP::CLONE_REPOSITORY],
|
||||
@@ -831,9 +841,9 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0003",
|
||||
_ISMAS_CONTINUE, // U0010 -> even on error: U0002/3 are sent only once
|
||||
_CLONE_REPOSITORY_FAILURE,
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
IsmasClient::RESULT_CODE::GIT_CLONE_ERROR,
|
||||
smap[UPDATE_STEP::CHECKOUT_REPOSITORY],
|
||||
QString("CLONING REPOSITORY %1 OR CHECKING OUT BRANCH %2 FAILED")
|
||||
.arg(instance->m_customerRepository)
|
||||
@@ -845,7 +855,7 @@ private:
|
||||
case UPDATE_STEP::CHECKOUT_REPOSITORY:
|
||||
ismasClient.setProgressInPercent(_CHECKOUT_REPOSITORY);
|
||||
break;
|
||||
case UPDATE_STEP::CHECKOUT_REPOSITORY_SUCCESS:
|
||||
case UPDATE_STEP::CHECKOUT_REPOSITORY_SUCCESS: {
|
||||
ismasClient.setProgressInPercent(_CHECKOUT_REPOSITORY_SUCCESS);
|
||||
ismasClient.sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
@@ -854,49 +864,95 @@ private:
|
||||
.arg(instance->m_customerRepository)
|
||||
.arg(instance->m_gc.branchName()),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A"));
|
||||
break;
|
||||
case UPDATE_STEP::CHECKOUT_REPOSITORY_FAILURE:
|
||||
} break;
|
||||
case UPDATE_STEP::CHECKOUT_REPOSITORY_FAILURE: {
|
||||
ismasClient.setProgressInPercent(_CHECKOUT_REPOSITORY_FAILURE);
|
||||
break;
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
_ISMAS_CONTINUE, // U0010 -> even on error: U0002/3 are sent only once
|
||||
_CHECKOUT_REPOSITORY_FAILURE,
|
||||
IsmasClient::RESULT_CODE::GIT_SWITCH_BRANCH_ERROR,
|
||||
smap[UPDATE_STEP::CHECKOUT_REPOSITORY],
|
||||
QString("%1: CHECKING OUT BRANCH %2 FAILED")
|
||||
.arg(instance->m_customerRepository)
|
||||
.arg(instance->m_gc.branchName()).toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
} break;
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER: {
|
||||
ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER);
|
||||
break;
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS:
|
||||
} break;
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_SUCCESS: {
|
||||
ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER_SUCCESS);
|
||||
ismasClient.sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateTriggerSet("ISMAS TRIGGER SET",
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A"));
|
||||
break;
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE:
|
||||
} break;
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_WRONG_VALUE: {
|
||||
ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER_WRONG_VALUE);
|
||||
break;
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE: {
|
||||
ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER_FAILURE);
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0003",
|
||||
_CHECK_ISMAS_TRIGGER_FAILURE,
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
_ISMAS_TEST_TRIGGER, // U0099
|
||||
_CHECK_ISMAS_TRIGGER_WRONG_VALUE,
|
||||
IsmasClient::RESULT_CODE::ISMAS_TRIGGER_ERROR,
|
||||
smap[UPDATE_STEP::CHECK_ISMAS_TRIGGER],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
} break;
|
||||
case UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER:
|
||||
case UPDATE_STEP::CHECK_ISMAS_TRIGGER_FAILURE: {
|
||||
ismasClient.setProgressInPercent(_CHECK_ISMAS_TRIGGER_FAILURE);
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
_ISMAS_TEST_TRIGGER, // U0099
|
||||
_CHECK_ISMAS_TRIGGER_FAILURE,
|
||||
IsmasClient::RESULT_CODE::ISMAS_TRIGGER_ERROR,
|
||||
smap[UPDATE_STEP::CHECK_ISMAS_TRIGGER],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
} break;
|
||||
case UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER: {
|
||||
ismasClient.setProgressInPercent(_INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER);
|
||||
break;
|
||||
case UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER,
|
||||
IsmasClient::RESULT_CODE::SUCCESS,
|
||||
smap[UPDATE_STEP::INITIAL_CLONE_WITHOUT_ACTIVE_ISMAS_TRIGGER],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
} break;
|
||||
case UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER: {
|
||||
ismasClient.setProgressInPercent(_INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER);
|
||||
break;
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER,
|
||||
IsmasClient::RESULT_CODE::SUCCESS,
|
||||
smap[UPDATE_STEP::INITIAL_CLONE_WITH_ACTIVE_ISMAS_TRIGGER],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
ismasClient.sendRequestReceiveResponse(
|
||||
IsmasClient::APISM::DB_PORT, ismasUpdateNews);
|
||||
} break;
|
||||
case UPDATE_STEP::PULL_NEW_BRANCH: {
|
||||
ismasClient.setProgressInPercent(_PULL_NEW_BRANCH);
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0010",
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_PULL_NEW_BRANCH,
|
||||
IsmasClient::RESULT_CODE::SUCCESS,
|
||||
smap[UPDATE_STEP::CHECKOUT_BRANCH],
|
||||
@@ -911,9 +967,9 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0003",
|
||||
_ISMAS_CONTINUE, // U0010 -> even on error: U0002/3 are sent only once
|
||||
_PULL_NEW_BRANCH_FAILURE,
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
IsmasClient::RESULT_CODE::GIT_PULL_ERROR,
|
||||
smap[UPDATE_STEP::CHECKOUT_BRANCH],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
@@ -926,7 +982,7 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0010",
|
||||
_ISMAS_CONTINUE, // U0010
|
||||
_PULL_NEW_BRANCH_SUCCESS,
|
||||
IsmasClient::RESULT_CODE::SUCCESS,
|
||||
smap[UPDATE_STEP::CHECKOUT_BRANCH],
|
||||
@@ -969,9 +1025,9 @@ private:
|
||||
QString const &ismasUpdateNews =
|
||||
QString("#M=APISM#C=CMD_EVENT#J=") +
|
||||
ismasClient.updateNewsToIsmas(
|
||||
"U0003",
|
||||
_ISMAS_FAILURE, // U0003
|
||||
_CHECKOUT_BRANCH_FAILURE,
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
IsmasClient::RESULT_CODE::GIT_SWITCH_BRANCH_ERROR,
|
||||
smap[UPDATE_STEP::CHECKOUT_BRANCH],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
@@ -1133,7 +1189,7 @@ private:
|
||||
ismasClient.updateNewsToIsmas(
|
||||
_ISMAS_FAILURE,
|
||||
ismasClient.getProgressInPercent(),
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
IsmasClient::RESULT_CODE::OPKG_COMMANDS_ERROR,
|
||||
smap[step],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
@@ -1281,7 +1337,7 @@ private:
|
||||
ismasClient.updateNewsToIsmas(
|
||||
_ISMAS_FAILURE,
|
||||
ismasClient.getProgressInPercent(),
|
||||
IsmasClient::RESULT_CODE::INSTALL_ERROR,
|
||||
IsmasClient::RESULT_CODE::UPDATE_IN_ERROR_STATE,
|
||||
smap[UPDATE_STEP::UPDATE_FINALIZE],
|
||||
instance->m_ismasMsg.join(' ').toStdString().c_str(),
|
||||
instance->m_versionInfo.size() >= 1 ? instance->m_versionInfo.at(0).toUtf8().constData() : "N/A");
|
||||
|
55
common/include/System.h
Normal file
55
common/include/System.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef SYSTEM_H
|
||||
#define SYSTEM_H
|
||||
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class System : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
explicit System(QObject *parent = 0);
|
||||
|
||||
static QString errorMsg;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
static bool checkForSDCard();
|
||||
static bool umountSDCard();
|
||||
|
||||
static bool checkForUSBStick();
|
||||
static QString getUSBMountPath();
|
||||
static QString getUSBDeviceName();
|
||||
static bool umountUSBStick();
|
||||
|
||||
static bool test_mount(const QString& dev, const QString &mountpoint);
|
||||
static bool test_dir(const QString& dir);
|
||||
|
||||
static quint32 getFreeDiskSpace(const QString& dev);
|
||||
static quint32 getFreeDiskSpaceSDCard();
|
||||
static bool isSDCardWritable();
|
||||
static quint32 getFreeDiskSpaceUSBStick();
|
||||
static bool isUSBStickWritable();
|
||||
|
||||
static quint8 createLogFileBackup(const QString & targzfile, const QString &filelistfile = "");
|
||||
static QString getSDCardMountPath();
|
||||
static QString getSDCardDeviceName();
|
||||
|
||||
static QString getUniqueDeviceId();
|
||||
|
||||
static QString getErrorMessage();
|
||||
|
||||
static QString readStringFromFile(const QString & filename);
|
||||
static int readIntFromFile(const QString & filename);
|
||||
|
||||
static QString getPTU4SerialNumber();
|
||||
static QString getPTU4MACAddress();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SYSTEM_H
|
647
common/src/System.cpp
Normal file
647
common/src/System.cpp
Normal file
@@ -0,0 +1,647 @@
|
||||
#include "System.h"
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
#include <QProcess>
|
||||
#include <QRegExp>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
//#include "version.h"
|
||||
|
||||
|
||||
QString System::errorMsg = "";
|
||||
|
||||
System::System(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function to return error message.
|
||||
*
|
||||
*/
|
||||
QString System::getErrorMessage()
|
||||
{
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function to check if a writable SD-card is in the cardslot.
|
||||
*
|
||||
* This function only checks a certain path or a mount entry. It does not mount
|
||||
* a SD-card, this must be provided by the OS (automounter).
|
||||
*
|
||||
* returns 1 if a SD-card is available, 0 otherwise.
|
||||
*/
|
||||
bool System::checkForSDCard()
|
||||
{
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if (!test_mount(getSDCardDeviceName(), getSDCardMountPath())) {
|
||||
qDebug() << "check for SD-card failed: \n"
|
||||
<< " device name is: " << getSDCardDeviceName()
|
||||
<< " mount path is: " << getSDCardMountPath();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function for umount sd-card.
|
||||
*
|
||||
*/
|
||||
bool System::umountSDCard()
|
||||
{
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
QString commandString = "umount " + getSDCardMountPath();
|
||||
|
||||
process.start(commandString);
|
||||
if (!process.waitForStarted()) {
|
||||
errorMsg = "System::umountSDCard(): ERROR: waitForStarted()";
|
||||
return false;
|
||||
}
|
||||
if (!process.waitForFinished(600000)) {
|
||||
errorMsg = "System::umountSDCard(): ERROR: " + process.errorString();
|
||||
qDebug() << errorMsg;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
QByteArray bytes = process.readAll();
|
||||
QStringList lines = QString(bytes).split("\n");
|
||||
foreach (QString line, lines) {
|
||||
qDebug() << "System::umountSDCard() line: " << line;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function for umount usb-stick.
|
||||
*
|
||||
*/
|
||||
bool System::umountUSBStick()
|
||||
{
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
return true;
|
||||
#endif
|
||||
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
QString commandString = "umount " + getUSBMountPath();
|
||||
|
||||
process.start(commandString);
|
||||
if (!process.waitForStarted()) {
|
||||
errorMsg = "System::umountUSBStick(): ERROR: waitForStarted()";
|
||||
return false;
|
||||
}
|
||||
if (!process.waitForFinished(600000)) {
|
||||
errorMsg = "System::umountUSBStick(): ERROR: " + process.errorString();
|
||||
qDebug() << errorMsg;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
QByteArray bytes = process.readAll();
|
||||
QStringList lines = QString(bytes).split("\n");
|
||||
foreach (QString line, lines) {
|
||||
qDebug() << "System::umountUSBStick() line: " << line;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* test, if a certain device is already mounted
|
||||
*
|
||||
* e.g. a mounted SD-card on PTU4:
|
||||
* - device is '/dev/mmcblk0p1'
|
||||
* - mount path is '/media/mmcblk0p1'
|
||||
*
|
||||
* e.g. a mounted USB-Stick on PTU4:
|
||||
* - device is '/dev/sda'
|
||||
* - mount path is '/media/sda'
|
||||
*/
|
||||
bool System::test_mount(const QString& dev, const QString& mountpoint)
|
||||
{
|
||||
bool mounted = false;
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
qDebug() << "System::test_mount() dev = " << dev;
|
||||
qDebug() << "System::test_mount() mountpoint = " << mountpoint;
|
||||
|
||||
//normalize mountpoint: (mountpoint is without trailing '/')
|
||||
QString tmp_mountpoint = QString(mountpoint).remove(QRegExp("/*$"));
|
||||
|
||||
QString commandString = "mount";
|
||||
|
||||
process.start(commandString);
|
||||
if (!process.waitForStarted()) {
|
||||
errorMsg = "System::test_mount(): ERROR: waitForStarted()";
|
||||
return false;
|
||||
}
|
||||
if (!process.waitForFinished(600000)) {
|
||||
errorMsg = "System::test_mount(): ERROR: " + process.errorString();
|
||||
qDebug() << errorMsg;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
QByteArray bytes = process.readAll();
|
||||
QStringList lines = QString(bytes).split("\n");
|
||||
foreach (QString line, lines) {
|
||||
//qDebug() << "System::test_mount() line: " << line;
|
||||
|
||||
//if (line.contains(dev)) qDebug() << "System::test_mount() line contains dev";
|
||||
//if (line.contains(tmp_mountpoint)) qDebug() << "System::test_mount() line contains mountpoint";
|
||||
|
||||
if (line.contains(dev) && line.contains(tmp_mountpoint)) {
|
||||
qDebug() << "System::test_mount(): " << dev << " is mounted on " << tmp_mountpoint;
|
||||
mounted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return mounted;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* test, if a certain directory is existing and readable
|
||||
*/
|
||||
bool System::test_dir(const QString& dir)
|
||||
{
|
||||
QFileInfo fileInfo(dir);
|
||||
if (! fileInfo.isDir() ) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool System::checkForUSBStick()
|
||||
{
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
if (QFileInfo(getUSBMountPath()).isDir())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
#endif
|
||||
|
||||
if (getUSBMountPath().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief SupportSystem::getUSBMountPath
|
||||
* @return path where a USB storage device is mounted.
|
||||
*
|
||||
* Note, do not return an empty string ("") here because a calling method (which could not be
|
||||
* identified till now) is relying on this!
|
||||
*/
|
||||
QString System::getUSBMountPath()
|
||||
{
|
||||
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
return QDir::homePath().append("/APconfigTest/USB");
|
||||
#endif
|
||||
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
QStringList mountLine;
|
||||
|
||||
qDebug() << "System::getUSBMountPath()";
|
||||
|
||||
QRegExp devRegExp = QRegExp("dev/sd*", Qt::CaseSensitive, QRegExp::WildcardUnix);
|
||||
QRegExp mountRegExp = QRegExp("media/sd*", Qt::CaseSensitive, QRegExp::WildcardUnix);
|
||||
|
||||
QString commandString = "mount";
|
||||
|
||||
process.start(commandString);
|
||||
if (!process.waitForStarted()) {
|
||||
errorMsg = "System::getUSBMountPath(): ERROR: waitForStarted()";
|
||||
return "";
|
||||
}
|
||||
if (!process.waitForFinished(600000)) {
|
||||
errorMsg = "System::getUSBMountPath(): ERROR: " + process.errorString();
|
||||
qDebug() << errorMsg;
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
QByteArray bytes = process.readAll();
|
||||
QStringList lines = QString(bytes).split("\n");
|
||||
foreach (QString line, lines) {
|
||||
qDebug() << "System::getUSBMountPath() line: " << line;
|
||||
|
||||
if (line.contains(devRegExp) && line.contains(mountRegExp)) {
|
||||
|
||||
qDebug() << " -> this line is a usb storage device mount" << line;
|
||||
|
||||
mountLine = line.split(' ');
|
||||
if (mountLine.size() > 3) {
|
||||
qDebug() << "System::getUSBMountPath(): " << mountLine.at(0) << " is mounted on " << mountLine.at(2);
|
||||
return mountLine.at(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "System::getUSBMountPath() no mounted usb device found!";
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function to check if a mounted sd-card is writable.
|
||||
*
|
||||
* Note: the caller must ensure (e.g. by calling checkForSDCard()) that a
|
||||
* sd-card is mounted.
|
||||
*
|
||||
*/
|
||||
bool System::isSDCardWritable()
|
||||
{
|
||||
QFileInfo fi(getSDCardMountPath());
|
||||
|
||||
if(fi.isDir() && fi.isWritable()) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* static function to check if a mounted usb-stick is writable.
|
||||
*
|
||||
* Note: the caller must ensure (e.g. by calling checkForUSBStick()) that a
|
||||
* usb-stick is mounted.
|
||||
*
|
||||
*/
|
||||
bool System::isUSBStickWritable()
|
||||
{
|
||||
QFileInfo fi(getUSBMountPath());
|
||||
|
||||
if(fi.isDir() && fi.isWritable()) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* wrapper function for getting free space on a sd-card on ptu
|
||||
*
|
||||
*/
|
||||
quint32 System::getFreeDiskSpaceSDCard()
|
||||
{
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
return getFreeDiskSpace("/home/siegert/server1home");
|
||||
#endif
|
||||
return getFreeDiskSpace(getSDCardMountPath());
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* wrapper function for getting free space on a usb storage device on ptu
|
||||
*
|
||||
*/
|
||||
quint32 System::getFreeDiskSpaceUSBStick()
|
||||
{
|
||||
#if defined (ARCH_DesktopLinux)
|
||||
return getFreeDiskSpace("/home/siegert/server1home");
|
||||
#endif
|
||||
return getFreeDiskSpace(getUSBMountPath());
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function to read free disk space
|
||||
*
|
||||
* example output of 'df' command on ptu:
|
||||
* # df
|
||||
* Filesystem 1K-blocks Used Available Use% Mounted on
|
||||
* ubi0:rootfs 111704 78940 32764 71% /
|
||||
* devtmpfs 62072 0 62072 0% /dev
|
||||
* tmpfs 62332 0 62332 0% /dev/shm
|
||||
* tmpfs 62332 416 61916 1% /tmp
|
||||
* tmpfs 62332 24 62308 1% /run
|
||||
* ubi0:data 222260 5892 216368 3% /opt
|
||||
* tmpfs 62332 0 62332 0% /media
|
||||
* /dev/mmcblk0p1 3878912 87360 3791552 3% /media/mmcblk0p1
|
||||
*
|
||||
* in this case, if we want to get the free space on the sd-card the methode should
|
||||
* be called:
|
||||
* getFreeDiskSpace("/dev/mmcblk0p1")
|
||||
* the result should be:
|
||||
* 3791552
|
||||
*
|
||||
*/
|
||||
quint32 System::getFreeDiskSpace(const QString& dev)
|
||||
{
|
||||
quint32 availableSpace = 0;
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
//qDebug() << "System::getFreeDiskSpace() dev = " << dev;
|
||||
|
||||
QString commandString = "df";
|
||||
|
||||
process.start(commandString);
|
||||
if (!process.waitForStarted()) {
|
||||
errorMsg = "System::getFreeDiskSpace(): ERROR: waitForStarted()";
|
||||
return availableSpace;
|
||||
}
|
||||
if (!process.waitForFinished(600000)) {
|
||||
errorMsg = "System::getFreeDiskSpace(): ERROR: " + process.errorString();
|
||||
qDebug() << errorMsg;
|
||||
return availableSpace;
|
||||
}
|
||||
else {
|
||||
QByteArray bytes = process.readAll();
|
||||
QStringList lines = QString(bytes).split("\n");
|
||||
foreach (QString line, lines) {
|
||||
//qDebug() << "System::getFreeDiskSpace() line: " << line;
|
||||
|
||||
|
||||
|
||||
if (line.contains(dev)) {
|
||||
//qDebug() << "System::getFreeDiskSpace() line contains dev";
|
||||
|
||||
QStringList processResultLine = line.split(' ', QString::SkipEmptyParts);
|
||||
if (processResultLine.size() >= 4) {
|
||||
bool ok;
|
||||
availableSpace = processResultLine.at(3).toLong(&ok);
|
||||
if (!ok) {
|
||||
return 0;
|
||||
}
|
||||
qDebug() << "System::getFreeDiskSpace() availableSpace = " << availableSpace;
|
||||
}
|
||||
else {
|
||||
return availableSpace;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return availableSpace;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function to create a backup of logfiles
|
||||
*
|
||||
* 'targzfile' is an absolute filename for ar tar.gz file wich will be created
|
||||
* 'filelistfile' is an absolute filename of a file containing all names of files
|
||||
* which should be backed up.
|
||||
*
|
||||
* returns:
|
||||
* 1 on success
|
||||
* 0 on failure
|
||||
*
|
||||
*/
|
||||
quint8 System::createLogFileBackup(const QString & targzfile, const QString &filelistfile)
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
qDebug() << "System::createLogFileBackup() targzfile = " << targzfile;
|
||||
qDebug() << "System::createLogFileBackup() filelistfile = " << filelistfile;
|
||||
|
||||
QString commandString = "tar hczvf " + targzfile + " -T " + filelistfile;
|
||||
|
||||
qDebug() << "System::createLogFileBackup() tar command:" << commandString;
|
||||
|
||||
process.start(commandString);
|
||||
if (!process.waitForStarted()) {
|
||||
errorMsg = "System::createLogFileBackup(): ERROR: waitForStarted()";
|
||||
return 1;
|
||||
}
|
||||
if (!process.waitForFinished(600000)) {
|
||||
errorMsg = "System::createLogFileBackup(): ERROR: " + process.errorString();
|
||||
qDebug() << errorMsg;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
// DEBUG
|
||||
//QByteArray bytes = process.readAll();
|
||||
//QStringList lines = QString(bytes).split("\n");
|
||||
//foreach (QString line, lines) {
|
||||
// qDebug() << "System::createLogFileBackup() line: " << line;
|
||||
//}
|
||||
}
|
||||
|
||||
QString resultMessage;
|
||||
QProcess::ExitStatus exitStatus = process.exitStatus();
|
||||
int exitCode = process.exitCode();
|
||||
|
||||
if (exitStatus == QProcess::CrashExit) {
|
||||
resultMessage = "local backup program crashed";
|
||||
qCritical() << resultMessage;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
||||
/**
|
||||
* note for exit codes of process tar:
|
||||
* see: http://www.gnu.org/software/tar/manual/html_section/tar_19.html#Synopsis
|
||||
*
|
||||
* tar returns exitCode 2 if some files in logFileList could not be read (e.g. if they are not existing)
|
||||
* however, tar-archive is created although!
|
||||
* This means success for our needs!
|
||||
*/
|
||||
|
||||
if ( (exitCode != 0) && (exitCode != 2) && (exitStatus == QProcess::NormalExit) ) {
|
||||
resultMessage = "Local Backup file \"" + targzfile + "\" with exit code = " + QString::number(exitCode);
|
||||
qCritical() << resultMessage;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
resultMessage = "Local Backup file \"" + targzfile + "\" was created successfully.";
|
||||
qCritical() << resultMessage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* get SD-card mount path.
|
||||
*/
|
||||
QString System::getSDCardMountPath()
|
||||
{
|
||||
#if defined (ARCH_PTU4)
|
||||
return "/media/mmcblk0p1";
|
||||
#elif defined (ARCH_PTU5)
|
||||
return "/media/mmcblk0p1";
|
||||
#elif defined (ARCH_DesktopLinux)
|
||||
// DEBUG / TEST:
|
||||
return "/home/siegert/APconfigTest";
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* get SD-card device name.
|
||||
*/
|
||||
QString System::getSDCardDeviceName()
|
||||
{
|
||||
#if defined (ARCH_PTU4)
|
||||
return "/dev/mmcblk0p1";
|
||||
#elif defined (ARCH_PTU5)
|
||||
return "/dev/mmcblk0p1";
|
||||
#elif defined (ARCH_DesktopLinux)
|
||||
return "/dev/sdf1";
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* static function to build and return a unique device id.
|
||||
* This id consists currently only of the mac-address of network device eth0.
|
||||
*/
|
||||
QString System::getUniqueDeviceId()
|
||||
{
|
||||
QString filename = "/sys/class/net/eth0/address";
|
||||
QString result;
|
||||
|
||||
QFile file(filename);
|
||||
if(!file.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "System::getUniqueDeviceId() could not open file: " << filename;
|
||||
result = "0";
|
||||
}
|
||||
else {
|
||||
QTextStream in(&file);
|
||||
result = in.readLine(20);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
result.remove(':');
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString System::readStringFromFile(const QString & filename)
|
||||
{
|
||||
#if defined (ARCH_PTU4)
|
||||
QFileInfo fileinfo(filename);
|
||||
#else
|
||||
QFileInfo fileinfo(QDir::homePath() + filename);
|
||||
#endif
|
||||
if (! fileinfo.isReadable() ) {
|
||||
qDebug() << "System::readStringFromFile(): \"" << filename << "\" is not readable";
|
||||
return "";
|
||||
}
|
||||
|
||||
#if defined (ARCH_PTU4)
|
||||
QFile file(filename);
|
||||
#else
|
||||
QFile file(QDir::homePath() + filename);
|
||||
#endif
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug() << "System::readStringFromFile() cannot open file: " << filename;
|
||||
return "";
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
|
||||
QString stringValue = in.readLine(100);
|
||||
qDebug() << "System::readStringFromFile() stringValue = " << stringValue;
|
||||
|
||||
file.close();
|
||||
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
|
||||
int System::readIntFromFile(const QString & filename)
|
||||
{
|
||||
bool ok;
|
||||
int result = (int)readStringFromFile(filename).toInt(&ok);
|
||||
|
||||
if (!ok) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* read ptu internal data
|
||||
*
|
||||
*/
|
||||
QString System::getPTU4SerialNumber()
|
||||
{
|
||||
return readStringFromFile("/sys/bus/i2c/devices/0-0050/SNO");
|
||||
}
|
||||
|
||||
QString System::getPTU4MACAddress()
|
||||
{
|
||||
return readStringFromFile("/sys/bus/i2c/devices/0-0050/MAC");
|
||||
}
|
||||
|
Reference in New Issue
Block a user