UpdatePTUDevCtrl/ismas/ismas_client.cpp
Gerhard Hoffmann 6caaae6d50 Add struct PSAInstalled.
Changed interface of updateOfPSASendVersion into
    QString updateOfPSASendVersion(PSAInstalled const &psa);

Re-implemented updateOfPSASendVersion().
2023-07-19 16:48:42 +02:00

415 lines
14 KiB
C++

#include "ismas/ismas_client.h"
#include <cstring>
#include <cstdio>
#if 0
# $1: EVENT: U0001 update finished: 100%
# U0002 reset TRG
# U0003 error
# U0010 for update process
# $2: PERCENT : "only for ISMAS: 0-100%",
# $3: RESULTCODE : "only for ISMAS",
# 0: Success
# 1: no Update nessesary
# 2: Backup failed
# 3: Package error/ Wrong package
# 4: Install Error
# $4: STEP : "running step (only for us): update_psa...",
# $5: STEP_RESULT : "error and result text",
# $6: VERSION : "opkg and conf info; what will be updated"
#
#endif
#include <QDateTime>
#include <QDebug>
QString IsmasClient::updateNewsToIsmas(char const *event,
int percent,
int resultCode,
char const *step,
char const *step_result,
char const *version) {
char buf[1024];
memset(buf, 0, sizeof(buf));
QString const ts = QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
snprintf(buf, sizeof(buf)-1,
"{"
"\"REASON\":\"SW_UP\","
"\"TIMESTAMP\":\"%s\","
"\"EVENT_ID\":\"0\","
"\"EVENT\":\"%s\","
"\"EVENTSTATE\":1,"
"\"PARAMETER\": {"
"\"PERCENT\" : %d,"
"\"RESULTCODE\" : %d,"
"\"STEP\" : \"%s\","
"\"STEP_RESULT\" : \"%s\","
"\"VERSION\" : \"%s\""
"}"
"}", ts.toStdString().c_str(), event, percent, resultCode,
step, step_result, version);
return buf;
}
QString IsmasClient::updateOfPSASendVersion(PSAInstalled const &psa) {
//static int const constexpr SIZE = 4096*8;
static char buf[4096*2];
memset(buf, 0, sizeof(buf));
QString const ts = QDateTime::currentDateTime().toString(Qt::ISODateWithMs);
QString sendVersionHash = "N/A";
// local data="#M=APISM#C=CMD_SENDVERSION#J=
snprintf(buf, sizeof(buf)-1,
"{"
"\"VERSION_INFO\" : {"
"\"CREATED\":\"%s\","
"\"HASH\":\"%s\""
"},"
"\"TARIFF\" : {"
"\"VERSION\" : \"%s\","
"\"PROJECT\" : \"%s\","
"\"ZONE\" : %d,"
"\"INFO\" : \"%s\","
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d,"
"\"LOADED\" : \"%s\""
"},"
"\"JSON\" : {"
"\"DC2C_CASH\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_CONF\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_DEVICE\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_01\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_02\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_03\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_04\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_05\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_06\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_07\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_08\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_09\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_10\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_11\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_12\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_13\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_14\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_15\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_16\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_17\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_18\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_19\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_20\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_21\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_22\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_23\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_24\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_25\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_26\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_27\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_28\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_29\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_30\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_31\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"},"
"\"DC2C_PRINT_32\" : {"
"\"BLOB\" : \"%s\","
"\"SIZE\" : %d"
"}"
"},"
"\"HARDWARE\" : {"
"\"DEVICES\" : [\"PTU5\", \"DC\", \"PRINTER\", \"BNA\"]"
"},"
"\"OS\" : {"
"\"Linux\": \"%s\""
"},"
"\"CONFIG\" : {"
"\"PTU5\" : {"
"\"CPU_SERIAL\" : \"%s\""
"},"
"\"DC\" : {"
"\"HW-VERSION\" : \"%s\","
"\"SW-VERSION\" : \"%s\","
"\"SIZE\" : %d,"
"\"GITBLOB\" : \"%s\","
"\"GITLASTCOMMIT\" : \"%s\""
"},"
"\"PRINTER\" : {"
"},"
"\"BNA\" : {"
"}"
"},"
"\"SOFTWARE\": {"
"\"RAUC\" : \"%s\","
"\"OPKG\" : \"%s\","
"\"ATBQT\" : {"
"\"VERSION\" : \"%s\""
"}"
"},"
"\"PLUGINS\" : {"
"\"libATBDeviceControllerPlugin.so\" : {"
"\"VERSION\" : \"%s\""
"},"
"\"libIngenicoISelf_CCPlugin.so\" : {"
"\"VERSION\" : \"%s\""
"},"
"\"libMOBILISIS_CalculatePricePlugin.so\" : {"
"\"VERSION\" : \"%s\""
"},"
"\"libMOBILISIS_CalculatePricePlugin_ConfigUi.so\" : {"
"\"VERSION\" : \"%s\""
"},"
"\"libPRM_CalculatePricePlugin.so\" : {"
"\"VERSION\" : \"%s\""
"},"
"\"libPRM_CalculatePricePlugin_ConfigUi.so\" : {"
"\"VERSION\" : \"%s\""
"},"
"\"libTCP_ZVT_CCPlugin.so\" : {"
"\"VERSION\" : \"%s\""
"}"
"}"
"}",
ts.toStdString().c_str(),
sendVersionHash.toStdString().c_str(),
psa.tariff.version.toStdString().c_str(),
psa.tariff.project.toStdString().c_str(),
psa.tariff.zone,
psa.tariff.info.toStdString().c_str(),
psa.tariff.blob.toStdString().c_str(),
psa.tariff.size,
psa.tariff.loadTime.toStdString().c_str(),
psa.cash.blob.toStdString().c_str(),
psa.cash.size,
psa.conf.blob.toStdString().c_str(),
psa.conf.size,
psa.device.blob.toStdString().c_str(),
psa.device.size,
psa.print[0].blob.toStdString().c_str(),
psa.print[0].size,
psa.print[1].blob.toStdString().c_str(),
psa.print[1].size,
psa.print[2].blob.toStdString().c_str(),
psa.print[2].size,
psa.print[3].blob.toStdString().c_str(),
psa.print[3].size,
psa.print[4].blob.toStdString().c_str(),
psa.print[4].size,
psa.print[5].blob.toStdString().c_str(),
psa.print[5].size,
psa.print[6].blob.toStdString().c_str(),
psa.print[6].size,
psa.print[7].blob.toStdString().c_str(),
psa.print[7].size,
psa.print[8].blob.toStdString().c_str(),
psa.print[8].size,
psa.print[9].blob.toStdString().c_str(),
psa.print[9].size,
psa.print[10].blob.toStdString().c_str(),
psa.print[10].size,
psa.print[11].blob.toStdString().c_str(),
psa.print[11].size,
psa.print[12].blob.toStdString().c_str(),
psa.print[12].size,
psa.print[13].blob.toStdString().c_str(),
psa.print[13].size,
psa.print[14].blob.toStdString().c_str(),
psa.print[14].size,
psa.print[15].blob.toStdString().c_str(),
psa.print[15].size,
psa.print[16].blob.toStdString().c_str(),
psa.print[16].size,
psa.print[17].blob.toStdString().c_str(),
psa.print[17].size,
psa.print[18].blob.toStdString().c_str(),
psa.print[18].size,
psa.print[19].blob.toStdString().c_str(),
psa.print[19].size,
psa.print[20].blob.toStdString().c_str(),
psa.print[20].size,
psa.print[21].blob.toStdString().c_str(),
psa.print[21].size,
psa.print[22].blob.toStdString().c_str(),
psa.print[22].size,
psa.print[23].blob.toStdString().c_str(),
psa.print[23].size,
psa.print[24].blob.toStdString().c_str(),
psa.print[24].size,
psa.print[25].blob.toStdString().c_str(),
psa.print[25].size,
psa.print[26].blob.toStdString().c_str(),
psa.print[26].size,
psa.print[27].blob.toStdString().c_str(),
psa.print[27].size,
psa.print[28].blob.toStdString().c_str(),
psa.print[28].size,
psa.print[29].blob.toStdString().c_str(),
psa.print[29].size,
psa.print[30].blob.toStdString().c_str(),
psa.print[30].size,
psa.print[31].blob.toStdString().c_str(),
psa.print[31].size,
psa.hw.linuxVersion.toStdString().c_str(),
psa.hw.cpuSerial.toStdString().c_str(),
psa.dc.versionHW.toStdString().c_str(),
psa.dc.versionSW.toStdString().c_str(),
psa.dc.size,
psa.dc.gitBlob.toStdString().c_str(),
psa.dc.gitLastCommit.toStdString().c_str(),
psa.sw.raucVersion.toStdString().c_str(),
psa.sw.opkgVersion.toStdString().c_str(),
psa.sw.atbQTVersion.toStdString().c_str(),
psa.pluginVersion.deviceController.toStdString().c_str(),
psa.pluginVersion.ingenicoISelfCC.toStdString().c_str(),
psa.pluginVersion.mobilisisCalculatePrice.toStdString().c_str(),
psa.pluginVersion.mobilisisCalculatePriceConfigUi.toStdString().c_str(),
psa.pluginVersion.prmCalculatePrice.toStdString().c_str(),
psa.pluginVersion.prmCalculatePriceConfigUi.toStdString().c_str(),
psa.pluginVersion.tcpZVT.toStdString().c_str());
printf("buf=%s\n", buf);
return buf;
}
QString IsmasClient::updateOfPSAActivated() {
return updateNewsToIsmas("U0010",
1,
0,
"activated",
"detected WAIT state",
"1.0.0");
}
QString IsmasClient::updateOfPSASucceeded() {
return updateNewsToIsmas("U0001",
100,
0,
"update_succeeded",
"",
"1.0.0");
}
QString IsmasClient::setUpdatesAvailable() {
return updateNewsToIsmas("U0099",
10,
0,
"set_updates_available",
"",
"");
}
bool checkForAvailableUpdates();