summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2025-11-12 15:06:42 +0100
committerNikita Kostovsky <nikita@kostovsky.me>2025-11-12 15:06:42 +0100
commit5e2c92325605919ad06ab634add74b7e58d21727 (patch)
tree27f69c0e33d135fb908c3cd6d6f8614dfa1da307
parentc12766412cfbdbbe16b7d75ae2d82c1550a346ef (diff)
show valid image and profile counters
-rw-r--r--ImageViewer.qml13
-rw-r--r--Main.qml9
-rw-r--r--main.cpp79
3 files changed, 82 insertions, 19 deletions
diff --git a/ImageViewer.qml b/ImageViewer.qml
index c5ed863..186faeb 100644
--- a/ImageViewer.qml
+++ b/ImageViewer.qml
@@ -1,5 +1,6 @@
import QtQuick
import QtQuick.Controls
+import QtQuick.Controls.Material
Page {
id: root
@@ -7,6 +8,18 @@ Page {
implicitWidth: 550
implicitHeight: 300
+ Label {
+ id: fpsLabel
+
+ anchors {
+ top: parent.top
+ topMargin: 8 * 2
+ horizontalCenter: parent.horizontalCenter
+ }
+
+ color: Material.accent
+ }
+
contentItem: Control {
id: container
diff --git a/Main.qml b/Main.qml
index 1faaaf0..665cd4f 100644
--- a/Main.qml
+++ b/Main.qml
@@ -25,7 +25,8 @@ ApplicationWindow {
// // qhttpserver
// readonly property string apiRoot: "http://rpi5:8081/v1"
- readonly property string apiRoot: "http://rpizero:8081/v1"
+ // readonly property string apiRoot: "http://rpizero:8081/v1"
+ readonly property string apiRoot: "http://radxa:8081/v1"
Shortcut {
sequence: "ctrl+q"
@@ -612,7 +613,8 @@ ApplicationWindow {
topMargin: 8 * 2
horizontalCenter: parent.horizontalCenter
}
- text: pixelsQmlCustomPlot.fps
+ // text: pixelsQmlCustomPlot.fps
+ text: typeof(pixelsPacketCounter) !== "undefined" ? pixelsPacketCounter : "N/A"
color: Material.accent
}
@@ -634,7 +636,8 @@ ApplicationWindow {
topMargin: 8 * 2
horizontalCenter: parent.horizontalCenter
}
- text: profileQmlCustomPlot.fps
+ // text: profileQmlCustomPlot.fps
+ text: typeof(profilePacketCounter) !== "undefined" ? profilePacketCounter : "N/A"
color: Material.accent
}
diff --git a/main.cpp b/main.cpp
index 4633272..c228b2c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -32,6 +32,9 @@ int main(
pixelsPlot->setOpenGl(true);
#endif
+ uint32_t pixelsPacketCounter{0};
+ uint32_t profilePacketCounter{0};
+
auto profilePlot = new QCustomPlot();
#ifdef QCUSTOMPLOT_USE_OPENGL
profilePlot->setOpenGl(true);
@@ -85,8 +88,10 @@ int main(
// QNetworkRequest pixelsRequest(QUrl("http://rpi5:8081/v1/pixels"));
// QNetworkRequest profileRequest(QUrl("http://rpi5:8081/v1/profile"));
- QNetworkRequest pixelsRequest(QUrl("http://rpizero:8081/v1/pixels"));
- QNetworkRequest profileRequest(QUrl("http://rpizero:8081/v1/profile"));
+ // QNetworkRequest pixelsRequest(QUrl("http://rpizero:8081/v1/pixels"));
+ // QNetworkRequest profileRequest(QUrl("http://rpizero:8081/v1/profile"));
+ QNetworkRequest pixelsRequest(QUrl("http://radxa:8081/v1/pixels"));
+ QNetworkRequest profileRequest(QUrl("http://radxa:8081/v1/profile"));
auto manager = new QNetworkAccessManager(&app);
QTimer pixelsAutoRestartTimer(&app);
@@ -103,11 +108,33 @@ int main(
manager->get(profileRequest);
});
+ QTimer fpsTimer(&app);
+ fpsTimer.setInterval(1000);
+ fpsTimer.setSingleShot(false);
+ QObject::connect(&fpsTimer, &QTimer::timeout, [&]() {
+ engine.rootContext()->setContextProperty(
+ "pixelsPacketCounter",
+ pixelsPacketCounter
+ );
+ engine.rootContext()->setContextProperty(
+ "profilePacketCounter",
+ profilePacketCounter
+ );
+ pixelsPacketCounter = 0;
+ profilePacketCounter = 0;
+ });
+ fpsTimer.start();
+
QObject::connect(
- manager, &QNetworkAccessManager::finished, [&](QNetworkReply *reply) {
+ manager,
+ &QNetworkAccessManager::finished,
+ [&](QNetworkReply* reply) {
// qDebug() << "replyFinished";
- if (reply->error()) {
- // qDebug() << "replyFinished:" << reply->errorString();
+ QElapsedTimer t;
+ t.start();
+ if (reply->error())
+ {
+ qDebug() << "replyFinished with error:" << reply->errorString();
// qDebug() << "url was:" << reply->request().url();
reply->deleteLater();
@@ -116,7 +143,10 @@ int main(
if (reply->url().toString().endsWith("pixels")) {
// qDebug() << "got pixels";
- auto json = QJsonDocument::fromJson(reply->readAll()).object();
+ ++pixelsPacketCounter;
+ const auto ra = reply->readAll();
+ const auto doc = QJsonDocument::fromJson(ra);
+ auto json = doc.object();
auto jsonPixels = json["pixels"].toArray();
auto encoderPosition = json["encoderPosition"].toInteger();
auto measurementCounter = json["measurementCounter"].toInteger();
@@ -124,7 +154,12 @@ int main(
// y_profile.clear();
- for (int i = 0; i < jsonPixels.count(); ++i) {
+ qDebug() << "pc" << jsonPixels.count() << json.isEmpty()
+ << doc.isObject();
+ // qDebug().noquote() << QString::fromUtf8(ra);
+
+ for (int i = 0; i < jsonPixels.count(); ++i)
+ {
y_pixels[i] = jsonPixels.at(i).toDouble();
}
@@ -135,15 +170,18 @@ int main(
size_t min_diff_idx = 0;
qreal avg_diff{0.};
- for (size_t i = 0; i < y_pixels.count(); ++i) {
+ for (size_t i = 0; i < y_pixels.count(); ++i)
+ {
y_diff[i] = y_pixels.at(i) - prev_y_profile.at(i);
- if (y_diff.at(i) > max_diff) {
+ if (y_diff.at(i) > max_diff)
+ {
max_diff = y_diff.at(i);
max_diff_idx = i;
}
- if (y_diff.at(i) < min_diff) {
+ if (y_diff.at(i) < min_diff)
+ {
min_diff = y_diff.at(i);
min_diff_idx = i;
}
@@ -187,10 +225,13 @@ int main(
= engine.rootObjects().first()->findChild<QmlCustomPlot *>(
"pixelsCustomPlot");
- if (!pixelsCustomPlot) {
+ if (!pixelsCustomPlot)
+ {
qWarning() << "no pixelsCustomPlot";
- } else {
- // qDebug() << "set lines. count is" << lines.count();
+ }
+ else
+ {
+ qDebug() << "set lines. count is" << lines.count();
// pixelsCustomPlot->setLines(lines);
}
@@ -218,6 +259,7 @@ int main(
prev_y_profile = y_pixels;
} else if (reply->url().toString().endsWith("profile")) {
+ ++profilePacketCounter;
auto json = QJsonDocument::fromJson(reply->readAll()).object();
auto jsonProfile = json["profile"].toObject();
auto jsonPointsMm = jsonProfile["pointsMm"].toArray();
@@ -225,11 +267,13 @@ int main(
QList<qreal> x_profile(size_t(img_width), 0.);
QList<qreal> y_profile(size_t(img_width), 0.);
- for (int i = 0; i < jsonPointsMm.count(); ++i) {
+ for (int i = 0; i < jsonPointsMm.count(); ++i)
+ {
const auto x = jsonPointsMm.at(i).toArray()[0].toDouble();
const auto z = jsonPointsMm.at(i).toArray()[1].toDouble();
- if (qFuzzyIsNull(z) || std::isnan(z)) {
+ if (qFuzzyIsNull(z) || std::isnan(z))
+ {
// x_profile[i] = 0;
y_profile[i] = 0;
continue;
@@ -249,7 +293,10 @@ int main(
}
reply->deleteLater();
- });
+
+ qDebug() << "reply processed for" << t.nsecsElapsed() / 1000 << "(us)";
+ }
+ );
manager->get(pixelsRequest);
pixelsAutoRestartTimer.start();