Added signals

void sendCmdSendVersionToIsmas(QString);
    void sendCmdEventToIsmas(QString);
and associated slots:
    void onSendCmdSendVersionToIsmas(QString);
    void onSendCmdEventToIsmas(QString);
Implemented slots.
This commit is contained in:
Gerhard Hoffmann 2023-07-19 16:53:45 +02:00
parent 1bdae56342
commit 2b934f6baf
2 changed files with 38 additions and 28 deletions

View File

@ -36,6 +36,8 @@ ApismClient::ApismClient(QObject *eventReceiver, ATBHMIconfig *config, Persisten
this, &ApismClient::onRequestResponseClientResponseTimeout); this, &ApismClient::onRequestResponseClientResponseTimeout);
connect(apismTcpSendClient, &ApismTcpClient::responseTimeout, connect(apismTcpSendClient, &ApismTcpClient::responseTimeout,
this, &ApismClient::onSendClientResponseTimeout); this, &ApismClient::onSendClientResponseTimeout);
connect(this, SIGNAL(sendCmdSendVersionToIsmas(QString)),
this, SLOT(onSendCmdSendVersionToIsmas(QString)));
// not needed as APISM closes the socket after we send data, so readyRead() // not needed as APISM closes the socket after we send data, so readyRead()
// might not even fire // might not even fire
@ -395,31 +397,7 @@ void ApismClient::requestAvailableIsmasUpdates() {
this->apismTcpRequestResponseClient->sendData(data); this->apismTcpRequestResponseClient->sendData(data);
} }
void ApismClient::sendCmdSendVersionToIsmas(QString const &msg) { void ApismClient::onSendCmdEventToIsmas(QString 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::emulateUpdatesAvailable(QString const &msg) {
QJsonParseError parseError; QJsonParseError parseError;
QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError)); QJsonDocument document(QJsonDocument::fromJson(msg.toUtf8(), &parseError));
if (parseError.error != QJsonParseError::NoError) { if (parseError.error != QJsonParseError::NoError) {
@ -436,12 +414,36 @@ void ApismClient::emulateUpdatesAvailable(QString const &msg) {
QByteArray data = "#M=APISM#C=CMD_EVENT#J="; QByteArray data = "#M=APISM#C=CMD_EVENT#J=";
data += document.toJson(QJsonDocument::Compact); data += document.toJson(QJsonDocument::Compact);
qDebug() << "EMULATE UPDATES AVAILABLE" << QString(data).toStdString().c_str(); this->currentRequest = ISMAS::REQUEST::NO_REQUEST;
this->apismTcpSendClient->sendData(data);
}
void ApismClient::onSendCmdSendVersionToIsmas(QString 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);
this->currentRequest = ISMAS::REQUEST::NO_REQUEST; this->currentRequest = ISMAS::REQUEST::NO_REQUEST;
this->apismTcpSendClient->sendData(data); this->apismTcpSendClient->sendData(data);
} }
void ApismClient::emulateUpdatesAvailable(QString const &msg) {
qDebug() << "EMULATE UPDATES AVAILABLE. MSG=" << msg;
onSendCmdEventToIsmas(msg);
}
void ApismClient::sendState(const QString & state, const QString & msg) void ApismClient::sendState(const QString & state, const QString & msg)
{ {
qCritical() << "ApismClient::sendState(): "; qCritical() << "ApismClient::sendState(): ";
@ -607,6 +609,9 @@ void ApismClient::sendMininformPingRequest()
void ApismClient::onReceivedResponse(QByteArray response) { void ApismClient::onReceivedResponse(QByteArray response) {
qCritical() << "RECEIVED ------> " << response;
if (this->currentRequest == ISMAS::REQUEST::NO_REQUEST && if (this->currentRequest == ISMAS::REQUEST::NO_REQUEST &&
response == "RECORD SAVED") { // sent by APISM to indicate that record response == "RECORD SAVED") { // sent by APISM to indicate that record
return; // has been saved in DB return; // has been saved in DB

View File

@ -50,6 +50,9 @@ public:
quint32 getLastError(); quint32 getLastError();
const QString & getLastErrorDescription(); const QString & getLastErrorDescription();
ApismTcpClient* getApismTcpSendClient() { return apismTcpSendClient; }
public slots: public slots:
void sendSelfTest(); void sendSelfTest();
void sendTransaction(const VendingData* vendingData); void sendTransaction(const VendingData* vendingData);
@ -58,7 +61,8 @@ public slots:
void sendState(const QString & state, const QString & msg); void sendState(const QString & state, const QString & msg);
void emulateUpdatesAvailable(QString const &msg); void emulateUpdatesAvailable(QString const &msg);
void sendCmdSendVersionToIsmas(QString const &msg); void onSendCmdSendVersionToIsmas(QString);
void onSendCmdEventToIsmas(QString);
void requestAvailableIsmasUpdates(); void requestAvailableIsmasUpdates();
@ -80,7 +84,8 @@ signals:
void sendReqSelfResponse(nsApismInterface::RESULT_STATE result, QJsonObject response); void sendReqSelfResponse(nsApismInterface::RESULT_STATE result, QJsonObject response);
void ismasResponseAvailable(QJsonObject ismasResponse); void ismasResponseAvailable(QJsonObject ismasResponse);
void sendCmdSendVersionToIsmas(QString);
void sendCmdEventToIsmas(QString);
private slots: private slots:
// void onSocketError(QAbstractSocket::SocketError socketError); // void onSocketError(QAbstractSocket::SocketError socketError);