network_sensor_enumerator.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  */
35 
36 #ifdef USE_GLOG
37 #include <glog/logging.h>
38 #else
39 #include <aditof/log.h>
40 #endif
41 
42 using namespace aditof;
43 
45  : m_ip(ip) {}
46 
48 
50  Status status = Status::OK;
51 
52  extern std::vector<std::string> m_connectionList;
53  int sensorIndex = -1, i = 0;
54  for (i = 0; i < m_connectionList.size(); i++) {
55  if (m_connectionList.at(i) == m_ip) {
56  sensorIndex = i;
57  break;
58  }
59  }
60 
61  if (sensorIndex == -1) {
62  sensorIndex = m_connectionList.size();
63  m_connectionList.emplace_back(m_ip);
64  }
65 
66  LOG(INFO) << "Looking for sensors over network: " << m_ip;
67 
68  std::unique_ptr<Network> net(new Network(sensorIndex));
69 
70  if (net->ServerConnect(m_ip) != 0) {
71  LOG(WARNING) << "Server Connect Failed";
72  net.reset(nullptr);
73  return Status::UNREACHABLE;
74  }
75 
76  net->send_buff[sensorIndex].set_func_name("FindSensors");
77  net->send_buff[sensorIndex].set_expect_reply(true);
78 
79  if (net->SendCommand() != 0) {
80  LOG(WARNING) << "Send Command Failed";
82  }
83 
84  if (net->recv_server_data() != 0) {
85  LOG(WARNING) << "Receive Data Failed";
86  return Status::GENERIC_ERROR;
87  }
88 
89  if (net->recv_buff[sensorIndex].server_status() !=
90  payload::ServerStatus::REQUEST_ACCEPTED) {
91  LOG(WARNING) << "API execution on Target Failed";
92  return Status::GENERIC_ERROR;
93  }
94 
95  const payload::ServerResponse &msg = net->recv_buff[sensorIndex];
96  const payload::SensorsInfo &pbSensorsInfo = msg.sensors_info();
97 
98  m_imageSensorsInfo = pbSensorsInfo.image_sensors().name();
99 
100  m_kernelVersion = msg.card_image_version().kernelversion();
101  m_sdVersion = msg.card_image_version().sdversion();
102  m_uBootVersion = msg.card_image_version().ubootversion();
103 
104  status = static_cast<Status>(net->recv_buff[sensorIndex].status());
105 
106  return status;
107 }
108 
110  std::vector<std::shared_ptr<DepthSensorInterface>> &depthSensors) {
111 
112  depthSensors.clear();
113 
114  auto sensor =
115  std::make_shared<NetworkDepthSensor>(m_imageSensorsInfo, m_ip);
116  depthSensors.emplace_back(sensor);
117 
118  return Status::OK;
119 }
120 
123  uBootVersion = m_uBootVersion;
124  return aditof::Status::OK;
125 }
126 
129  kernelVersion = m_kernelVersion;
130  return aditof::Status::OK;
131 }
132 
135  sdVersion = m_sdVersion;
136  return aditof::Status::OK;
137 }
INFO
const int INFO
Definition: log_severity.h:59
NetworkSensorEnumerator::~NetworkSensorEnumerator
~NetworkSensorEnumerator()
NetworkSensorEnumerator::m_sdVersion
std::string m_sdVersion
Definition: network_sensor_enumerator.h:62
NetworkSensorEnumerator::m_kernelVersion
std::string m_kernelVersion
Definition: network_sensor_enumerator.h:61
NetworkSensorEnumerator::searchSensors
virtual aditof::Status searchSensors() override
Do a search for the available sensors.
Definition: network_sensor_enumerator.cpp:49
NetworkSensorEnumerator::getSdVersion
virtual aditof::Status getSdVersion(std::string &sdVersion) const override
Get the SD card image version on the embedded system that the camera is attached to.
Definition: network_sensor_enumerator.cpp:134
NetworkSensorEnumerator::NetworkSensorEnumerator
NetworkSensorEnumerator(const std::string &ip)
Definition: network_sensor_enumerator.cpp:44
log.h
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
WARNING
const int WARNING
Definition: log_severity.h:59
NetworkSensorEnumerator::getDepthSensors
virtual aditof::Status getDepthSensors(std::vector< std::shared_ptr< aditof::DepthSensorInterface >> &depthSensors) override
Definition: network_sensor_enumerator.cpp:109
NetworkSensorEnumerator::getUbootVersion
virtual aditof::Status getUbootVersion(std::string &uBootVersion) const override
Get the U-Boot version that is installed on the embedded system that the camera is attached to.
Definition: network_sensor_enumerator.cpp:122
network_sensor_enumerator.h
aditof
Namespace aditof.
Definition: adsd_errs.h:40
google::protobuf::util::error::OK
@ OK
Definition: status.h:47
NetworkSensorEnumerator::m_ip
std::string m_ip
Definition: network_sensor_enumerator.h:56
m_connectionList
std::vector< std::string > m_connectionList
Definition: network.cpp:87
google::protobuf::util::error::INVALID_ARGUMENT
@ INVALID_ARGUMENT
Definition: status.h:50
NetworkSensorEnumerator::getKernelVersion
virtual aditof::Status getKernelVersion(std::string &kernelVersion) const override
Get the kernel version that is installed on the embedded system that the camera is attached to.
Definition: network_sensor_enumerator.cpp:128
aditof::Status
Status
Status of any operation that the TOF sdk performs.
Definition: status_definitions.h:48
Network
Definition: network.h:50
i
int i
Definition: gmock-matchers_test.cc:764
LOG
#define LOG(x)
Definition: sdk/include/aditof/log.h:72
aditof::Status::OK
@ OK
Success.
NetworkSensorEnumerator::m_uBootVersion
std::string m_uBootVersion
Definition: network_sensor_enumerator.h:60
network.h
network_depth_sensor.h
NetworkSensorEnumerator::m_imageSensorsInfo
std::string m_imageSensorsInfo
Definition: network_sensor_enumerator.h:57


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