summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp139
1 files changed, 71 insertions, 68 deletions
diff --git a/main.cpp b/main.cpp
index 377fc84..34719ef 100644
--- a/main.cpp
+++ b/main.cpp
@@ -59,93 +59,96 @@ int main(int argc, char *argv[])
manager->get(request);
});
- QObject::connect(manager, &QNetworkAccessManager::finished,
- [&](QNetworkReply *reply) {
- // qDebug() << "replyFinished";
- if (reply->error()) {
- qDebug() << "replyFinished:" << reply->errorString();
- return;
- }
+ QObject::connect(manager, &QNetworkAccessManager::finished, [&](QNetworkReply *reply) {
+ // qDebug() << "replyFinished";
+ if (reply->error()) {
+ qDebug() << "replyFinished:" << reply->errorString();
+ reply->deleteLater();
- auto json = QJsonDocument::fromJson(reply->readAll())
- .object();
- auto jsonPixels = json["pixels"].toArray();
- auto encoderPosition = json["encoderPosition"].toInteger();
- auto measurementCounter = json["measurementCounter"].toInteger();
- auto timestampUs = json["timestampUs"].toInteger();
+ return;
+ }
- // y_profile.clear();
+ auto json = QJsonDocument::fromJson(reply->readAll())
+ .object();
+ auto jsonPixels = json["pixels"].toArray();
+ auto encoderPosition = json["encoderPosition"].toInteger();
+ auto measurementCounter = json["measurementCounter"].toInteger();
+ auto timestampUs = json["timestampUs"].toInteger();
- for (int i = 0; i < jsonPixels.count(); ++i) {
- y_profile[i] = jsonPixels.at(i).toDouble();
- }
+ // y_profile.clear();
- QVector<qreal> y_diff(y_profile.count());
- qreal max_diff { 0. };
- qreal min_diff { 1000000. };
- size_t max_diff_idx = 0;
- size_t min_diff_idx = 0;
- qreal avg_diff { 0. };
+ for (int i = 0; i < jsonPixels.count(); ++i) {
+ y_profile[i] = jsonPixels.at(i).toDouble();
+ }
- for (size_t i = 0; i < y_profile.count(); ++i) {
- y_diff[i] = y_profile.at(i) - prev_y_profile.at(i);
+ QVector<qreal> y_diff(y_profile.count());
+ qreal max_diff { 0. };
+ qreal min_diff { 1000000. };
+ size_t max_diff_idx = 0;
+ size_t min_diff_idx = 0;
+ qreal avg_diff { 0. };
- if (y_diff.at(i) > max_diff) {
- max_diff = y_diff.at(i);
- max_diff_idx = i;
- }
+ for (size_t i = 0; i < y_profile.count(); ++i) {
+ y_diff[i] = y_profile.at(i) - prev_y_profile.at(i);
- if (y_diff.at(i) < min_diff) {
- min_diff = y_diff.at(i);
- min_diff_idx = i;
- }
+ if (y_diff.at(i) > max_diff) {
+ max_diff = y_diff.at(i);
+ max_diff_idx = i;
+ }
- avg_diff += fabs(y_diff.at(i));
- }
+ if (y_diff.at(i) < min_diff) {
+ min_diff = y_diff.at(i);
+ min_diff_idx = i;
+ }
- avg_diff /= y_diff.size();
+ avg_diff += fabs(y_diff.at(i));
+ }
- // for (size_t i = 0; i < y_profile.size(); ++i) {
- // if
- // }
+ avg_diff /= y_diff.size();
- // // const auto max_diff = std::max_element(y_diff.begin(), y_diff.end());
- // const auto avg_diff = std::accumulate(y_diff.begin(), y_diff.end(), 0.0) / y_diff.size();
- std::sort(y_diff.begin(), y_diff.end());
- const auto median_diff = y_diff.at(y_diff.size() * 3 / 4);
+ // for (size_t i = 0; i < y_profile.size(); ++i) {
+ // if
+ // }
- // if (qFuzzyIsNull(max_diff)) {
- // qDebug() << "max_diff is null";
+ // // const auto max_diff = std::max_element(y_diff.begin(), y_diff.end());
+ // const auto avg_diff = std::accumulate(y_diff.begin(), y_diff.end(), 0.0) / y_diff.size();
+ std::sort(y_diff.begin(), y_diff.end());
+ const auto median_diff = y_diff.at(y_diff.size() * 3 / 4);
- // static bool done = [&]() -> bool {
- // for (const auto & y : y_profile) {
- // qDebug() << y;
- // }
- // return true;
- // }();
+ // if (qFuzzyIsNull(max_diff)) {
+ // qDebug() << "max_diff is null";
- // manager->get(request);
+ // static bool done = [&]() -> bool {
+ // for (const auto & y : y_profile) {
+ // qDebug() << y;
+ // }
+ // return true;
+ // }();
- // return;
- // }
+ // manager->get(request);
- graph->setData(x_profile, y_profile);
+ // return;
+ // }
- engine.rootContext()->setContextProperty("max_diff", max_diff);
- engine.rootContext()->setContextProperty("max_diff_idx", int(max_diff_idx));
- engine.rootContext()->setContextProperty("min_diff", min_diff);
- engine.rootContext()->setContextProperty("min_diff_idx", int(min_diff_idx));
- engine.rootContext()->setContextProperty("avg_diff", avg_diff);
- engine.rootContext()->setContextProperty("median_diff", median_diff);
- engine.rootContext()->setContextProperty("encoderPosition", encoderPosition);
- engine.rootContext()->setContextProperty("measurementCounter", measurementCounter);
- engine.rootContext()->setContextProperty("timestampUs", timestampUs);
+ graph->setData(x_profile, y_profile);
- manager->get(request);
- pixelsAutoRestartTimer.start();
+ engine.rootContext()->setContextProperty("max_diff", max_diff);
+ engine.rootContext()->setContextProperty("max_diff_idx", int(max_diff_idx));
+ engine.rootContext()->setContextProperty("min_diff", min_diff);
+ engine.rootContext()->setContextProperty("min_diff_idx", int(min_diff_idx));
+ engine.rootContext()->setContextProperty("avg_diff", avg_diff);
+ engine.rootContext()->setContextProperty("median_diff", median_diff);
+ engine.rootContext()->setContextProperty("encoderPosition", encoderPosition);
+ engine.rootContext()->setContextProperty("measurementCounter", measurementCounter);
+ engine.rootContext()->setContextProperty("timestampUs", timestampUs);
- prev_y_profile = y_profile;
- });
+ manager->get(request);
+ pixelsAutoRestartTimer.start();
+
+ prev_y_profile = y_profile;
+
+ reply->deleteLater();
+ });
manager->get(request);
pixelsAutoRestartTimer.start();