system_impl.cpp
Go to the documentation of this file.
1 /*
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2019, Analog Devices, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #include "system_impl.h"
35 #include "camera_itof.h"
36 #include <aditof/camera.h>
37 #include <algorithm>
38 
39 #ifdef USE_GLOG
40 #include <glog/logging.h>
41 #else
42 #include <aditof/log.h>
43 #endif
44 
45 #include "aditof/version.h"
46 
47 #ifdef HAS_NETWORK
48 //#include <lws_config.h>
49 #include <zmq.hpp>
50 #endif
51 
52 using namespace aditof;
53 
54 static std::vector<std::shared_ptr<Camera>>
55 buildCameras(std::unique_ptr<SensorEnumeratorInterface> enumerator,
56  const std::string &netLinkTest = {}) {
57 
58  std::vector<std::shared_ptr<Camera>> cameras;
59  std::vector<std::shared_ptr<DepthSensorInterface>> depthSensors;
60  std::string uboot;
61  std::string kernel;
62  std::string sd_ver;
63 
64  enumerator->getDepthSensors(depthSensors);
65  enumerator->getUbootVersion(uboot);
66  enumerator->getKernelVersion(kernel);
67  enumerator->getSdVersion(sd_ver);
68 
69  for (const auto &dSensor : depthSensors) {
70  std::shared_ptr<Camera> camera = std::make_shared<CameraItof>(
71  dSensor, uboot, kernel, sd_ver, netLinkTest);
72  cameras.emplace_back(camera);
73  }
74 
75  return cameras;
76 }
77 
79 
80 SystemImpl::~SystemImpl() = default;
81 
82 Status
83 SystemImpl::getCameraList(std::vector<std::shared_ptr<Camera>> &cameraList,
84  const std::string &uri) const {
85 
86 #if HAS_NETWORK
87  static bool logged = false;
88  int major, minor, patch;
89  zmq_version(&major, &minor, &patch);
90  if (!logged) {
91  LOG(INFO) << "SDK built with zmq version:" << major << "." << minor
92  << "." << patch;
93  logged = true;
94  }
95 #endif
96 
97  cameraList.clear();
98 
99  if (uri.compare(0, 3, "ip:") == 0) {
100  std::string ip(uri, 3);
101  return getCameraListAtIp(cameraList, ip);
102  }
103 
104  std::unique_ptr<SensorEnumeratorInterface> sensorEnumerator;
105 #ifdef HAS_OFFLINE
106  DLOG(INFO) << "Creating offline sensor.";
108  if (!sensorEnumerator) {
109  LOG(ERROR) << "Could not create OfflineSensorEnumerator";
110  return Status::GENERIC_ERROR;
111  }
112 #elif defined(NXP) || defined(NVIDIA)
114  if (!sensorEnumerator) {
115  LOG(ERROR) << "Could not create TargetSensorEnumerator";
116  return Status::GENERIC_ERROR;
117  }
118 #else
120  if (!sensorEnumerator) {
121  LOG(ERROR) << "Could not create UsbSensorEnumerator";
122  return Status::GENERIC_ERROR;
123  }
124 #endif
125 
126  Status status = sensorEnumerator->searchSensors();
127  if (status == Status::OK) {
128  cameraList = buildCameras(std::move(sensorEnumerator));
129  }
130 
131  return Status::OK;
132 }
133 
134 Status
135 SystemImpl::getCameraListAtIp(std::vector<std::shared_ptr<Camera>> &cameraList,
136  const std::string &ip) const {
137  int netLinkFlag = ip.find(":");
138  std::string onlyIp = ip;
139  std::string netLinkTest;
140  if (netLinkFlag != -1) {
141  netLinkTest = ip.substr(netLinkFlag + 1, ip.size());
142  onlyIp.erase(netLinkFlag);
143  }
144  std::unique_ptr<SensorEnumeratorInterface> sensorEnumerator =
146 
147  if (!sensorEnumerator) {
148  LOG(ERROR) << "Network interface is not enabled."
149  "Please rebuild the SDK "
150  "with the option WITH_NETWORK=on";
151  return Status::GENERIC_ERROR;
152  }
153  Status status = sensorEnumerator->searchSensors();
154  if (status == Status::OK) {
155  cameraList = buildCameras(std::move(sensorEnumerator), netLinkTest);
156  }
157 
158  return status;
159 }
INFO
const int INFO
Definition: log_severity.h:59
zmq_version
ZMQ_EXPORT void zmq_version(int *major_, int *minor_, int *patch_)
Definition: zmq.cpp:88
system_impl.h
ERROR
const int ERROR
Definition: log_severity.h:60
aditof::Status::GENERIC_ERROR
@ GENERIC_ERROR
An error occured but there are no details available.
log.h
SystemImpl::getCameraList
aditof::Status getCameraList(std::vector< std::shared_ptr< aditof::Camera >> &cameraList, const std::string &uri) const
Definition: system_impl.cpp:83
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
DLOG
#define DLOG(x)
Definition: sdk/include/aditof/log.h:73
zmq.hpp
aditof::SensorEnumeratorFactory::buildUsbSensorEnumerator
static std::unique_ptr< SensorEnumeratorInterface > buildUsbSensorEnumerator()
Definition: sensor_enumerator_factory.cpp:62
aditof::SensorEnumeratorFactory::buildOfflineSensorEnumerator
static std::unique_ptr< SensorEnumeratorInterface > buildOfflineSensorEnumerator()
Definition: sensor_enumerator_factory.cpp:82
aditof
Namespace aditof.
Definition: adsd_errs.h:40
SystemImpl::SystemImpl
SystemImpl()
Definition: system_impl.cpp:78
buildCameras
static std::vector< std::shared_ptr< Camera > > buildCameras(std::unique_ptr< SensorEnumeratorInterface > enumerator, const std::string &netLinkTest={})
Definition: system_impl.cpp:55
sensor_enumerator_interface.h
major
int major
Definition: gl3w.c:93
camera_itof.h
sensor_enumerator_factory.h
aditof::Status
Status
Status of any operation that the TOF sdk performs.
Definition: status_definitions.h:48
minor
int minor
Definition: gl3w.c:93
camera.h
LOG
#define LOG(x)
Definition: sdk/include/aditof/log.h:72
aditof::Status::OK
@ OK
Success.
SystemImpl::getCameraListAtIp
aditof::Status getCameraListAtIp(std::vector< std::shared_ptr< aditof::Camera >> &cameraList, const std::string &ip) const
Definition: system_impl.cpp:135
SystemImpl::~SystemImpl
~SystemImpl()
aditof::SensorEnumeratorFactory::buildTargetSensorEnumerator
static std::unique_ptr< SensorEnumeratorInterface > buildTargetSensorEnumerator()
Factory method to create an enumerator to look for sensors on target. Factory method will return null...
Definition: sensor_enumerator_factory.cpp:53
aditof::SensorEnumeratorFactory::buildNetworkSensorEnumerator
static std::unique_ptr< SensorEnumeratorInterface > buildNetworkSensorEnumerator(const std::string &ip)
Definition: sensor_enumerator_factory.cpp:71


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59