From 8a43f32fe1a91855259852ab11ba6fc9a1988df9 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 6 Jul 2020 11:10:26 +0300 Subject: [PATCH] URI json parse before source create --- applications/vision/src/main.cpp | 8 ++--- components/common/cpp/src/uri.cpp | 12 ++++--- .../src/sources/stereovideo/pylon.cpp | 31 +++++++++++++++++-- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/applications/vision/src/main.cpp b/applications/vision/src/main.cpp index 8f1c3a9cd..8d1b46c75 100644 --- a/applications/vision/src/main.cpp +++ b/applications/vision/src/main.cpp @@ -135,14 +135,12 @@ static void run(ftl::Configurable *root) { } } - Source *source = nullptr; - source = ftl::create<Source>(root, "source", net); if (file != "") { - //source->set("uri", file); ftl::URI uri(file); - uri.to_json(source->getConfig()); - source->set("uri", uri.getBaseURI()); + uri.to_json(root->getConfig()["source"]); } + Source *source = nullptr; + source = ftl::create<Source>(root, "source", net); ftl::stream::Sender *sender = ftl::create<ftl::stream::Sender>(root, "sender"); ftl::stream::Net *outstream = ftl::create<ftl::stream::Net>(root, "stream", net); diff --git a/components/common/cpp/src/uri.cpp b/components/common/cpp/src/uri.cpp index 71b6e195d..fdb8e046c 100644 --- a/components/common/cpp/src/uri.cpp +++ b/components/common/cpp/src/uri.cpp @@ -2,7 +2,7 @@ #include <nlohmann/json.hpp> // #include <filesystem> TODO When available #include <cstdlib> -//#include <loguru.hpp> +#include <loguru.hpp> #ifndef WIN32 #include <unistd.h> @@ -210,14 +210,18 @@ void URI::to_json(nlohmann::json &json) { size_t pos = 0; size_t lpos = 0; while ((pos = i.first.find('/', lpos)) != std::string::npos) { - current = &((*current)[i.first.substr(lpos, pos-lpos)]); + std::string subobj = i.first.substr(lpos, pos-lpos); + current = &((*current)[subobj]); lpos = pos+1; } + + std::string obj = i.first.substr(lpos); + auto p = nlohmann::json::parse(i.second, nullptr, false); if (!p.is_discarded()) { - (*current)[i.first.substr(lpos)] = p; + (*current)[obj] = p; } else { - (*current)[i.first.substr(lpos)] = i.second; + (*current)[obj] = i.second; } } } diff --git a/components/rgbd-sources/src/sources/stereovideo/pylon.cpp b/components/rgbd-sources/src/sources/stereovideo/pylon.cpp index 7bec885a7..2cdb05277 100644 --- a/components/rgbd-sources/src/sources/stereovideo/pylon.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/pylon.cpp @@ -11,6 +11,8 @@ #include <opencv2/imgproc.hpp> +#include <nlohmann/json.hpp> + using ftl::rgbd::detail::PylonDevice; using std::string; using ftl::codecs::Channel; @@ -26,22 +28,45 @@ PylonDevice::PylonDevice(nlohmann::json &config) Pylon::DeviceInfoList_t devices; inst.EnumerateDevices(devices); + int dev_left_num = 0; + std::string dev_left; + + if (getConfig()["device_left"].is_number()) { + dev_left = std::to_string(value("device_left",0)); + } else { + dev_left = value("device_left", std::string("default")); + } + + LOG(INFO) << "DEVICE LEFT: " << dev_left; + if (devices.size() == 0) { LOG(ERROR) << "No Pylon devices attached"; return; } else { + int i=0; for (auto d : devices) { - LOG(INFO) << " - found Pylon device - " << d.GetFullName() << "(" << d.GetModelName() << ")"; + if (std::string(d.GetSerialNumber()) == dev_left) { + dev_left_num = i; + } + + if (dev_left_num == i) { + LOG(INFO) << " - found Pylon device - " << d.GetSerialNumber() << "(" << d.GetModelName() << ") [primary]"; + } else { + LOG(INFO) << " - found Pylon device - " << d.GetSerialNumber() << "(" << d.GetModelName() << ")"; + } + + ++i; } } try { - lcam_ = new CBaslerUniversalInstantCamera( CTlFactory::GetInstance().CreateDevice(devices[0])); + lcam_ = new CBaslerUniversalInstantCamera( CTlFactory::GetInstance().CreateDevice(devices[dev_left_num])); lcam_->RegisterConfiguration( new Pylon::CSoftwareTriggerConfiguration, Pylon::RegistrationMode_ReplaceAll, Pylon::Cleanup_Delete); lcam_->Open(); if (devices.size() >= 2) { - rcam_ = new CBaslerUniversalInstantCamera( CTlFactory::GetInstance().CreateDevice(devices[1])); + int dev_right = (dev_left_num == 0) ? 1 : 0; + rcam_ = new CBaslerUniversalInstantCamera( CTlFactory::GetInstance().CreateDevice(devices[dev_right])); rcam_->RegisterConfiguration( new Pylon::CSoftwareTriggerConfiguration, Pylon::RegistrationMode_ReplaceAll, Pylon::Cleanup_Delete); rcam_->Open(); } -- GitLab