Copied from ATBQT app.
Added slots requestAvailableIsmasUpdates(), sendCmdSendVersionToIsmas() and sendUpdateInfoToIsmas().
This commit is contained in:
parent
9ca758ecd3
commit
cd1c92a7db
@ -34,12 +34,9 @@ ApismClient::ApismClient(QObject *eventReceiver, ATBHMIconfig *config, Persisten
|
||||
this, &ApismClient::onReceivedResponse);
|
||||
connect(apismTcpRequestResponseClient, &ApismTcpClient::responseTimeout,
|
||||
this, &ApismClient::onRequestResponseClientResponseTimeout);
|
||||
|
||||
connect(apismTcpSendClient, &ApismTcpClient::responseTimeout,
|
||||
this, &ApismClient::onSendClientResponseTimeout);
|
||||
|
||||
|
||||
|
||||
// not needed as APISM closes the socket after we send data, so readyRead()
|
||||
// might not even fire
|
||||
// connect(&m_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
|
||||
@ -53,18 +50,10 @@ ApismClient::ApismClient(QObject *eventReceiver, ATBHMIconfig *config, Persisten
|
||||
ApismClient::~ApismClient() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ApismClient::restartApism()
|
||||
{
|
||||
void ApismClient::restartApism() {
|
||||
QProcess::startDetached("/bin/systemctl", {"restart", "apism"});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//void ApismClient::onReadyRead() { // parse APISM response
|
||||
// QByteArray data = m_socket.readAll();
|
||||
// qCritical() << "APISM-RESPONSE = (" << endl << data << endl << ")";
|
||||
@ -399,6 +388,58 @@ void ApismClient::sendEvent(const ATBMachineEvent* machineEvent)
|
||||
|
||||
}
|
||||
|
||||
void ApismClient::requestAvailableIsmasUpdates() {
|
||||
QByteArray data = "#M=APISM #C=REQ_ISMASParameter #J={}";
|
||||
this->currentRequest = ISMAS::REQUEST::ISMAS_PARAMETER;
|
||||
this->apismTcpRequestResponseClient->sendData(data);
|
||||
}
|
||||
|
||||
void ApismClient::sendCmdSendVersionToIsmas(QString const &msg) {
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
qCritical() << "INVALID JSON MSG: PARSING FAILED:"
|
||||
<< parseError.error << parseError.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.isObject()) {
|
||||
qCritical() << "FILE IS NOT A JSON OBJECT!";
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data = "#M=APISM#C=CMD_SENDVERSION#J=";
|
||||
data += document.toJson(QJsonDocument::Compact);
|
||||
|
||||
printf("data=%s\n", QString(data).toStdString().c_str());
|
||||
|
||||
this->currentRequest = ISMAS::REQUEST::NO_REQUEST;
|
||||
this->apismTcpSendClient->sendData(data);
|
||||
|
||||
}
|
||||
|
||||
void ApismClient::sendUpdateInfoToIsmas(QString const &msg) {
|
||||
QJsonParseError parseError;
|
||||
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
|
||||
if (parseError.error != QJsonParseError::NoError) {
|
||||
qCritical() << "INVALID JSON MSG: PARSING FAILED:"
|
||||
<< parseError.error << parseError.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.isObject()) {
|
||||
qCritical() << "FILE IS NOT A JSON OBJECT!";
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data = "#M=APISM#C=CMD_EVENT#J=";
|
||||
data += document.toJson(QJsonDocument::Compact);
|
||||
|
||||
printf("data=%s\n", QString(data).toStdString().c_str());
|
||||
|
||||
this->currentRequest = ISMAS::REQUEST::NO_REQUEST;
|
||||
this->apismTcpSendClient->sendData(data);
|
||||
}
|
||||
|
||||
void ApismClient::sendState(const QString & state, const QString & msg)
|
||||
{
|
||||
@ -443,7 +484,7 @@ void ApismClient::sendState(const QString & state, const QString & msg)
|
||||
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
void ApismClient::sendMininformStartRequest(const VendingData* vendingData)
|
||||
{
|
||||
this->currentRequest = ISMAS::REQUEST::START;
|
||||
@ -467,7 +508,6 @@ void ApismClient::sendMininformStartRequest(const VendingData* vendingData)
|
||||
|
||||
QScopedPointer<MininFormTransferData> transferData(new MininFormTransferData());
|
||||
|
||||
#if 0
|
||||
transferData->startAction.uid = vendingData->getParameter("START_UID").toJsonValue();
|
||||
this->currentRequestUid = vendingData->getParameter("START_UID").toString();
|
||||
transferData->startAction.insert("UID", transferData->startAction.uid);
|
||||
@ -543,19 +583,18 @@ void ApismClient::sendMininformStopRequest(const VendingData* vendingData)
|
||||
data += jsonDoc.toJson(QJsonDocument::Compact);
|
||||
|
||||
this->apismTcpRequestResponseClient->sendData(data);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void ApismClient::sendSelfTest()
|
||||
{
|
||||
void ApismClient::sendSelfTest() {
|
||||
qDebug() << "SENDING APISM-SELF-TEST";
|
||||
this->currentRequest = ISMAS::REQUEST::SELF;
|
||||
|
||||
QByteArray data = "#M=APISM#C=REQ_SELF#J={}";
|
||||
|
||||
this->apismTcpRequestResponseClient->sendData(data);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void ApismClient::sendMininformPingRequest()
|
||||
{
|
||||
this->currentRequest = ISMAS::REQUEST::PING;
|
||||
@ -564,11 +603,15 @@ void ApismClient::sendMininformPingRequest()
|
||||
|
||||
this->apismTcpRequestResponseClient->sendData(data);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void ApismClient::onReceivedResponse(QByteArray response) {
|
||||
if (this->currentRequest == ISMAS::REQUEST::NO_REQUEST &&
|
||||
response == "RECORD SAVED") { // sent by APISM to indicate that record
|
||||
return; // has been saved in DB
|
||||
}
|
||||
|
||||
void ApismClient::onReceivedResponse(QByteArray response)
|
||||
{
|
||||
// get the root object
|
||||
QJsonParseError jsonParseError;
|
||||
QJsonDocument responseDoc = QJsonDocument::fromJson(response, &jsonParseError);
|
||||
@ -581,11 +624,10 @@ void ApismClient::onReceivedResponse(QByteArray response)
|
||||
}
|
||||
|
||||
QJsonObject rootObject = responseDoc.object();
|
||||
|
||||
QStringList rootObjectKeys = rootObject.keys();
|
||||
|
||||
// DEBUG
|
||||
qCritical() << "ApismClient::onReceivedResponse(): objects: " << rootObjectKeys;
|
||||
qDebug() << "ApismClient::onReceivedResponse(): objects: " << rootObjectKeys;
|
||||
// results to:
|
||||
// ApismClient::onReceivedResponse(): objects: ("REQ_START#60044_Response", "Response")
|
||||
|
||||
@ -604,6 +646,9 @@ void ApismClient::onReceivedResponse(QByteArray response)
|
||||
else
|
||||
if(rootObjectKeys.indexOf(QRegularExpression("^REQ_PING.*")) >= 0) {
|
||||
this->private_handleReqPingResponse(rootObject["PING"].toObject());
|
||||
} else
|
||||
if(rootObjectKeys.indexOf(QRegularExpression("^REQ_ISMASPARAMETER.*")) >= 0) {
|
||||
this->private_handleIsmasParameterResponse(rootObject);
|
||||
}
|
||||
else {
|
||||
qCritical() << "ApismClient::onReceivedResponse() for unknown Request: ";
|
||||
@ -634,6 +679,10 @@ void ApismClient::handleISMASResponseError()
|
||||
case ISMAS::REQUEST::SELF:
|
||||
emit this->sendReqSelfResponse(nsApismInterface::RESULT_STATE::ERROR_BACKEND, QJsonObject());
|
||||
break;
|
||||
case ISMAS::REQUEST::ISMAS_PARAMETER:
|
||||
// TODO
|
||||
// emit
|
||||
break;
|
||||
}
|
||||
this->currentRequest = ISMAS::REQUEST::NO_REQUEST;
|
||||
}
|
||||
@ -672,6 +721,8 @@ void ApismClient::onRequestResponseClientResponseTimeout()
|
||||
case ISMAS::REQUEST::SELF:
|
||||
emit this->sendReqSelfResponse(nsApismInterface::RESULT_STATE::ERROR_TIMEOUT, QJsonObject());
|
||||
break;
|
||||
case ISMAS::REQUEST::ISMAS_PARAMETER:
|
||||
break;
|
||||
}
|
||||
|
||||
this->currentRequest = ISMAS::REQUEST::NO_REQUEST;
|
||||
@ -698,6 +749,10 @@ void ApismClient::private_handleReqPingResponse(QJsonObject response)
|
||||
emit this->sendMininformPingResponse(nsApismInterface::RESULT_STATE::SUCCESS, response);
|
||||
}
|
||||
|
||||
void ApismClient::private_handleIsmasParameterResponse(QJsonObject response) {
|
||||
emit this->ismasResponseAvailable(response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -722,6 +777,9 @@ QDebug operator<< (QDebug debug, ISMAS::REQUEST request)
|
||||
case ISMAS::REQUEST::SELF:
|
||||
debug << QString("ISMAS::REQUEST::SELF");
|
||||
break;
|
||||
case ISMAS::REQUEST::ISMAS_PARAMETER:
|
||||
debug << QString("ISMAS::REQUEST::ISMASPARAMETER");
|
||||
break;
|
||||
}
|
||||
return debug;
|
||||
}
|
||||
@ -744,6 +802,9 @@ QString& operator<< (QString& str, ISMAS::REQUEST request)
|
||||
case ISMAS::REQUEST::SELF:
|
||||
str = QString("ISMAS::REQUEST::SELF");
|
||||
break;
|
||||
case ISMAS::REQUEST::ISMAS_PARAMETER:
|
||||
str = QString("ISMAS::REQUEST::ISMASPARAMETER");
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
@ -53,22 +53,21 @@ public:
|
||||
public slots:
|
||||
void sendSelfTest();
|
||||
void sendTransaction(const VendingData* vendingData);
|
||||
void sendAccount(const QHash<QString, QVariant> &accountDataHash);
|
||||
void sendEvent(const ATBMachineEvent* machineEvent);
|
||||
// void sendAccount(const QHash<QString, QVariant> &accountDataHash);
|
||||
//void sendEvent(const ATBMachineEvent* machineEvent);
|
||||
|
||||
void sendState(const QString & state, const QString & msg);
|
||||
void sendUpdateInfoToIsmas(QString const &msg);
|
||||
void sendCmdSendVersionToIsmas(QString const &msg);
|
||||
void requestAvailableIsmasUpdates();
|
||||
|
||||
|
||||
void sendMininformStartRequest(const VendingData* vendingData);
|
||||
void sendMininformStopRequest(const VendingData* vendingData);
|
||||
void sendMininformPingRequest();
|
||||
//void sendMininformStartRequest(const VendingData* vendingData);
|
||||
//void sendMininformStopRequest(const VendingData* vendingData);
|
||||
//void sendMininformPingRequest();
|
||||
|
||||
void restartApism();
|
||||
|
||||
#ifdef USE_SZEGED_START_STOP
|
||||
|
||||
#endif
|
||||
|
||||
signals:
|
||||
// public signals:
|
||||
void sendTransactionRespones(nsApismInterface::RESULT_STATE result);
|
||||
@ -80,6 +79,8 @@ signals:
|
||||
void sendMininformPingResponse(nsApismInterface::RESULT_STATE result, QJsonObject response);
|
||||
void sendReqSelfResponse(nsApismInterface::RESULT_STATE result, QJsonObject response);
|
||||
|
||||
void ismasResponseAvailable(QJsonObject ismasResponse);
|
||||
|
||||
|
||||
private slots:
|
||||
// void onSocketError(QAbstractSocket::SocketError socketError);
|
||||
@ -110,6 +111,7 @@ private:
|
||||
void private_handlePingResponse(QJsonObject response);
|
||||
void private_handleReqSelfResponse(QJsonObject response);
|
||||
void private_handleReqPingResponse(QJsonObject response);
|
||||
void private_handleIsmasParameterResponse(QJsonObject response);
|
||||
|
||||
void handleISMASResponseError();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user