aboutsummaryrefslogtreecommitdiffstats
path: root/sample/telemetry-cloud-app
diff options
context:
space:
mode:
authorAndrey Shamanin <andrei.shamanin@orioninc.com>2020-10-16 16:08:27 +0300
committerAndrey Shamanin <andrei.shamanin@orioninc.com>2020-10-19 15:41:37 +0300
commit2d66933b9bf25af66696b097283109c8a6e87151 (patch)
tree92a0bc61822540d5175a87d643fcca24d4acb216 /sample/telemetry-cloud-app
parentaee2ff16cc87a939e68aa2900e23d6705dda5408 (diff)
Bug-AGL: SPEC-3645 Signed-off-by: Andrey Shamanin <andrei.shamanin@orioninc.com> Change-Id: Ie165a50e7975a8e6f25b259be1679a9689414148
Diffstat (limited to 'sample/telemetry-cloud-app')
-rwxr-xr-xsample/telemetry-cloud-app/app/TelemetryWorker.cpp17
-rwxr-xr-xsample/telemetry-cloud-app/app/TelemetryWorker.h4
-rwxr-xr-xsample/telemetry-cloud-app/app/main.cpp35
-rwxr-xr-xsample/telemetry-cloud-app/app/mainwindow.cpp14
-rwxr-xr-xsample/telemetry-cloud-app/app/mainwindow.h1
-rwxr-xr-xsample/telemetry-cloud-app/app/ui_mainwindow.h16
6 files changed, 74 insertions, 13 deletions
diff --git a/sample/telemetry-cloud-app/app/TelemetryWorker.cpp b/sample/telemetry-cloud-app/app/TelemetryWorker.cpp
index c277d2b..5dd0eb4 100755
--- a/sample/telemetry-cloud-app/app/TelemetryWorker.cpp
+++ b/sample/telemetry-cloud-app/app/TelemetryWorker.cpp
@@ -15,6 +15,7 @@
*/
#include "TelemetryWorker.h"
+#include "mainwindow.h"
#include <QDebug>
#include <nlohmann/json.hpp>
#include <time.h>
@@ -23,6 +24,8 @@
#include <libcloudproxy.h>
/*
+Used coordinates:
+
left up: 56.327 43.981
right up: 56.327 44.03
right bottom: 56.3 44.03
@@ -33,9 +36,6 @@ top: 56.329702 44.021352
diff -0.008028 -0.014969
coeff lon/lat = 1,8646
-
-
-https://gps-coordinates.org/distance-between-coordinates.php
*/
@@ -97,6 +97,7 @@ void TelemetryWorker::send()
nlohmann::json jmsg{
{"tele_ver", "1.0"},
+ {"client_id", "009a82af-a9f8-4dd9-b67b-558f1267958e"},
{"lat", lat},
{"lon", lon},
{"alt", (size_t)(alt + drand(0, 10))},
@@ -105,12 +106,18 @@ void TelemetryWorker::send()
};
{
- //WARN: remove
const auto& msg{jmsg.dump()};
qDebug() << "TelemetryWorker: " << msg.c_str();
}
if (cloudproxyclient)
- qDebug() << "TelemetryWorker: cloud sendMessage result: " << cloudproxyclient->sendMessage(jmsg.dump());
+ {
+ int res = cloudproxyclient->sendMessage(CloudType::Azure, jmsg.dump());
+ qDebug() << "TelemetryWorker: cloud sendMessage result: " << res;
+
+ MainWindow* window = qobject_cast<MainWindow*>(parent());
+ if (window)
+ window->updateSendStatus(res == 0);
+ }
}
diff --git a/sample/telemetry-cloud-app/app/TelemetryWorker.h b/sample/telemetry-cloud-app/app/TelemetryWorker.h
index 11210cb..5df65c6 100755
--- a/sample/telemetry-cloud-app/app/TelemetryWorker.h
+++ b/sample/telemetry-cloud-app/app/TelemetryWorker.h
@@ -37,8 +37,8 @@ private:
CloudProxyClient* cloudproxyclient{nullptr};
int direction{0};
- const double init_lat{56.306};
- const double init_lon{44.070};
+ const double init_lat{56.321674};
+ const double init_lon{44.006383};
double lat{init_lat};
double lon{init_lon};
double alt{300.0};
diff --git a/sample/telemetry-cloud-app/app/main.cpp b/sample/telemetry-cloud-app/app/main.cpp
index ca053ad..aa629ef 100755
--- a/sample/telemetry-cloud-app/app/main.cpp
+++ b/sample/telemetry-cloud-app/app/main.cpp
@@ -31,7 +31,7 @@ CloudProxyClient* g_cloudproxyclient{nullptr};
int main(int argc, char *argv[])
{
- QString graphic_role = QString("telemetrycloud");
+ QString graphic_role{"telemetrycloud"};
QApplication app(argc, argv);
app.setDesktopFileName(graphic_role);
@@ -64,13 +64,44 @@ int main(int argc, char *argv[])
g_cloudproxyclient = new CloudProxyClient();
g_cloudproxyclient->init(port, token.c_str());
+ g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_SendMessageConfirmation, [&window](json_object* object){
+ qDebug("CloudProxyClient::Event_SendMessageConfirmation: object ptr %p", object);
+
+ const char* str = object ? json_object_to_json_string_ext(object, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY) : "<obj_null>";
+ if (!str)
+ str = "<empty>";
+ qDebug("Event_SendMessageConfirmation: %s", str);
+
+ json_object *j_obj;
+
+ const char* cloud_type{nullptr};
+ if(!json_object_object_get_ex(object, "cloud_type", &j_obj) ||
+ (cloud_type = json_object_get_string(j_obj)) == nullptr)
+ {
+ qDebug("Can't read cloud_type");
+ return;
+ }
+
+ if(!json_object_object_get_ex(object, "result", &j_obj))
+ {
+ qDebug("Can't read confirmation result");
+ return;
+ }
+
+ bool result = (bool)json_object_get_boolean(j_obj);
+ if (!result)
+ window->updateSendStatus(false);
+
+ qDebug("Application received confirmation result from %s : %s", cloud_type, (result ? "true" : "false"));
+ });
+
g_cloudproxyclient->set_event_handler(CloudProxyClient::Event_ReceivedMessage, [&window](json_object* object){
qDebug("CloudProxyClient::Event_ReceivedMessage: object ptr %p", object);
const char* str = object ? json_object_to_json_string_ext(object, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY) : "<obj_null>";
if (!str)
str = "<empty>";
- qDebug("Event_SendMessageConfirmation: %s", str);
+ qDebug("Event_ReceivedMessage: %s", str);
json_object *event_data;
const char* data_str{nullptr};
diff --git a/sample/telemetry-cloud-app/app/mainwindow.cpp b/sample/telemetry-cloud-app/app/mainwindow.cpp
index 2e8796c..1038d1a 100755
--- a/sample/telemetry-cloud-app/app/mainwindow.cpp
+++ b/sample/telemetry-cloud-app/app/mainwindow.cpp
@@ -64,10 +64,22 @@ void MainWindow::updateState(QVariant recvMsg)
qDebug() << "Can't parse incomming message: " << ex.what();
}
- QString str = QString::asprintf("Cloud info: %s", cloud_msg.c_str());
+ QString str = QString::asprintf("Cloud message: %s", cloud_msg.c_str());
ui->stateLabel->setText(str);
}
+void MainWindow::updateSendStatus(bool status)
+{
+ static bool init{false}, prev{false};
+ if (!init || prev != status)
+ {
+ init = true;
+ prev = status;
+ QString str = QString::asprintf("Connection status: %s", (status ? "OK" : "ERROR"));
+ ui->sendStatusLabel->setText(str);
+ }
+}
+
void MainWindow::startMsgButtonClick()
{
qDebug() << "MainWindow::startMsgButtonClick()";
diff --git a/sample/telemetry-cloud-app/app/mainwindow.h b/sample/telemetry-cloud-app/app/mainwindow.h
index ce21845..6e36638 100755
--- a/sample/telemetry-cloud-app/app/mainwindow.h
+++ b/sample/telemetry-cloud-app/app/mainwindow.h
@@ -39,6 +39,7 @@ public:
public slots:
void updateState(QVariant recvMsg);
+ void updateSendStatus(bool status);
private slots:
void startMsgButtonClick();
diff --git a/sample/telemetry-cloud-app/app/ui_mainwindow.h b/sample/telemetry-cloud-app/app/ui_mainwindow.h
index 5dbcbd5..6a24c62 100755
--- a/sample/telemetry-cloud-app/app/ui_mainwindow.h
+++ b/sample/telemetry-cloud-app/app/ui_mainwindow.h
@@ -36,6 +36,7 @@ class Ui_MainWindow
public:
QWidget *centralWidget{nullptr};
QPushButton *startMsgButton{nullptr};
+ QLabel *sendStatusLabel{nullptr};
QLabel *stateLabel{nullptr};
void setupUi(double scale_factor, QMainWindow *MainWindow)
@@ -54,9 +55,16 @@ public:
startMsgButton->setGeometry(QRect((540-242/2)*scale_factor, 20*scale_factor, 242*scale_factor, 64*scale_factor));
startMsgButton->setStyleSheet(style);
- stateLabel = new QLabel(centralWidget);
- stateLabel->setObjectName(QString::fromUtf8("label"));
- stateLabel->setGeometry(QRect(40*scale_factor, 180*scale_factor, 1000*scale_factor, 420*scale_factor));
+ sendStatusLabel = new QLabel(centralWidget);
+ sendStatusLabel->setObjectName(QString::fromUtf8("sendStatusLabel"));
+ sendStatusLabel->setGeometry(QRect(40*scale_factor, 180*scale_factor, 1000*scale_factor, 80*scale_factor));
+ sendStatusLabel->setWordWrap(false);
+ sendStatusLabel->setAlignment(Qt::AlignTop);
+ sendStatusLabel->setStyleSheet(style);
+
+ stateLabel = new QLabel(centralWidget);
+ stateLabel->setObjectName(QString::fromUtf8("stateLabel"));
+ stateLabel->setGeometry(QRect(40*scale_factor, 280*scale_factor, 1000*scale_factor, 420*scale_factor));
stateLabel->setWordWrap(true);
stateLabel->setAlignment(Qt::AlignTop);
stateLabel->setStyleSheet(style);
@@ -74,6 +82,8 @@ public:
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
startMsgButton->setText(QApplication::translate("MainWindow", "Start", nullptr));
+ sendStatusLabel->setText(QApplication::translate("MainWindow", "Connection status: None", nullptr));
+ stateLabel->setText(QApplication::translate("MainWindow", "Cloud message:", nullptr));
} // retranslateUi
};