summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorNikita Kostovsky <nikita@kostovsky.me>2025-02-28 23:28:12 +0100
committerNikita Kostovsky <nikita@kostovsky.me>2025-02-28 23:28:12 +0100
commitfe81095bf011786ee5303549abc8debb22cddcf8 (patch)
treec0b77e9d1b6a6682cb0fe7a3bc03617660377387 /src/main.cpp
parenta554cb955012adc51ab0d82af32206fd38a88da8 (diff)
got 480 fps with pixels calc
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp93
1 files changed, 68 insertions, 25 deletions
diff --git a/src/main.cpp b/src/main.cpp
index fd5bd79..e05262a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,4 +1,5 @@
#include <chrono>
+#include <csignal>
#include <errno.h>
#include <fstream>
#include <iostream>
@@ -11,6 +12,7 @@
#include "calibration.h"
#include "camera/innomakerov9281.h"
#include "camera/ov9281.h"
+#include "camera/veyeimx287m.h"
#include "dumps.h"
#include "fuck_intel.h"
#include "genetic_algos.h"
@@ -134,7 +136,17 @@ bool initLaser();
int main(int argc, char* argv[])
{
+ auto sigHandler = [](int s) {
+ std::cout << "got signal " << s << std::endl;
+ std::signal(s, SIG_DFL);
+ qApp->quit();
+ };
+
+ std::signal(SIGINT, sigHandler);
+ std::signal(SIGTERM, sigHandler);
+
QCoreApplication app(argc, argv);
+ // QTimer::singleShot(4000, qApp, &QCoreApplication::quit);
QList<QFuture<void>> initializers;
@@ -366,7 +378,8 @@ int main(int argc, char* argv[])
#endif
// const auto cameras = cm->cameras();
// const auto cameras = OV9281::search(cm);
- const auto cameras = InnoMakerOV9281::search();
+ // const auto cameras = InnoMakerOV9281::search();
+ const auto cameras = VeyeIMX287m::search();
// const auto cameras =
if (cameras.empty())
@@ -405,31 +418,60 @@ int main(int argc, char* argv[])
}
QHttpServer qHttpServer;
- qHttpServer.route("/v1/sensor/image", [&]() {
+ auto httpGetImage = [&]() -> QHttpServerResponse {
+ // return QHttpServerResponse::StatusCode::ServiceUnavailable;
// std::cout << "http: image" << std::endl << std::flush;
// FILE *f = fopen("/tmp/img.pgm", "w");
// static bool save = false;
+ auto cam = dynamic_cast<VeyeIMX287m *>(camera.get());
+
+ if (!cam) {
+ qDebug() << "NO CAM";
+ return QHttpServerResponse::StatusCode::ServiceUnavailable;
+ }
+
+ Image img;
+ // yeaah
+ ::img = &img;
+ if (!cam->getImage(img)) {
+ qDebug() << "cannot get image";
+ return QHttpServerResponse::StatusCode::ServiceUnavailable;
+ }
pgm_save(::img);
// save = false;
std::lock_guard<std::mutex> lg(pgm_image_mtx);
// qDebug() << "mutex locked";
// qDebug() << "image saved to array";
- return QByteArray((const char*) pgm_image, pgm_image_size);
- });
- qHttpServer.route("/v1/sensor/image2", [&]() {
- // std::cout << "http: image2" << std::endl;
- pgm_save(::img);
-
- std::lock_guard<std::mutex> lg(pgm_image_mtx);
- // qDebug() << "image2";
- return QByteArray((const char*) pgm_image, pgm_image_size);
- });
+ return QHttpServerResponse{QByteArray((const char *) pgm_image, pgm_image_size),
+ QHttpServerResponse::StatusCode::Ok};
+ };
+ qHttpServer.route("/v1/sensor/image", httpGetImage);
+ qHttpServer.route("/v1/sensor/image2", httpGetImage);
// qHttpServer.route("/v1/sensor/exposureTimeUs", [&]() {
// // std::lock_guard<std::mutex> lg(pgm_image_mtx);
// return "123";
// });
- qHttpServer.route("/v1/pixels", [&]() {
+ qHttpServer.route("/v1/pixels", [&]() -> QHttpServerResponse {
// std::cout << "http: pixels" << std::endl;
+ // return QHttpServerResponse::StatusCode::ServiceUnavailable;
+
+ auto cam = dynamic_cast<VeyeIMX287m *>(camera.get());
+
+ if (!cam) {
+ qDebug() << "NO CAM";
+ return QHttpServerResponse::StatusCode::ServiceUnavailable;
+ }
+
+ Image img;
+ // yeaah
+ ::img = &img;
+ if (!cam->getImage(img)) {
+ qDebug() << "cannot get image";
+ return QHttpServerResponse::StatusCode::ServiceUnavailable;
+ }
+
+ ::pixels = img.pixels();
+
std::lock_guard<std::mutex> lg(pgm_image_mtx);
QJsonArray pixels;
@@ -444,8 +486,8 @@ int main(int argc, char* argv[])
json["pixels"] = pixels;
// json["encoderPosition"] = qint64{encoder.position()};
// FIXME: get prom pixels struct
- json["measurementCounter"] = qint64{img->counters.measurementCounter};
- json["timestampUs"] = qint64(img->counters.timestampUs);
+ json["measurementCounter"] = qint64{img.counters.measurementCounter};
+ json["timestampUs"] = qint64(img.counters.timestampUs);
const auto lines = pixelsToLines(::pixels);
@@ -466,6 +508,7 @@ int main(int argc, char* argv[])
qHttpServer.route("/v1/profile", [&]() -> QHttpServerResponse {
// std::cout << "http: profile" << std::endl;
+ return QHttpServerResponse::StatusCode::ServiceUnavailable;
std::lock_guard<std::mutex> lg(pgm_image_mtx);
if (!::calibrationTableZ || !::calibrationTableX)
@@ -672,16 +715,16 @@ int main(int argc, char* argv[])
qDebug() << "listen: " << qHttpServer.listen(QHostAddress::Any, 8081);
- QFuture<void> future = QtConcurrent::run([]() {
- Port port(8080);
- Address addr(Ipv4::any(), port);
+ // QFuture<void> future = QtConcurrent::run([]() {
+ // Port port(8080);
+ // Address addr(Ipv4::any(), port);
- HttpService httpService(addr);
+ // HttpService httpService(addr);
- size_t threads_count = 1;
- httpService.init(threads_count);
- httpService.start();
- });
+ // size_t threads_count = 1;
+ // httpService.init(threads_count);
+ // httpService.start();
+ // });
////////////////////////////////////////////////////////////////////////////
std::clog << std::flush;
@@ -694,8 +737,8 @@ int main(int argc, char* argv[])
auto result = app.exec();
- future.cancel();
- future.waitForFinished();
+ // future.cancel();
+ // future.waitForFinished();
// for (auto& [fd, mem] : mappedBuffers_)
// {