Mech-Eye API Reference 2.1.4-alpha
API reference documentation for Mech-Eye 3D Laser Profiler
All Classes Functions Variables Enumerations Enumerator Pages
api_util.h
1/*******************************************************************************
2 *BSD 3-Clause License
3 *
4 *Copyright (c) 2016-2023, Mech-Mind Robotics
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
33#pragma once
34#include <iostream>
35#include <set>
36#include <utility>
37#include "ErrorStatus.h"
38#include "CommonTypes.h"
39#include "Profiler.h"
40#include "ProfilerInfo.h"
41
45inline void showError(const mmind::eye::ErrorStatus& status)
46{
47 if (status.isOK())
48 return;
49 std::cout << "Error Code : " << status.errorCode
50 << ", Error Description: " << status.errorDescription << std::endl;
51}
52
56inline bool isNumber(const std::string& str)
57{
58 for (char it : str) {
59 if (it < '0' || it > '9')
60 return false;
61 }
62 return true;
63}
64
68inline void printProfilerInfo(const mmind::eye::ProfilerInfo& profilerInfo)
69{
70 std::cout << "........................................." << std::endl;
71 std::cout << "Profiler Model Name: " << profilerInfo.model << std::endl;
72 std::cout << "Controller Serial Number: " << profilerInfo.controllerSN << std::endl;
73 std::cout << "Sensor Head Serial Number: " << profilerInfo.sensorSN << std::endl;
74 std::cout << "Profiler IP Address: " << profilerInfo.ipAddress << std::endl;
75 std::cout << "Profiler IP Subnet Mask: " << profilerInfo.subnetMask << std::endl;
76 std::cout << "Profiler IP Assignment Method: "
77 << mmind::eye::ipAssignmentMethodToString(profilerInfo.ipAssignmentMethod)
78 << std::endl;
79 std::cout << "Hardware Version: "
80 << "V" << profilerInfo.hardwareVersion.toString() << std::endl;
81 std::cout << "Firmware Version: "
82 << "V" << profilerInfo.firmwareVersion.toString() << std::endl;
83 std::cout << "........................................." << std::endl;
84 std::cout << std::endl;
85}
86
90inline bool findAndConnect(mmind::eye::Profiler& profiler)
91{
92 std::cout << "Find Mech-Eye 3D Laser Profilers..." << std::endl;
93 std::vector<mmind::eye::ProfilerInfo> profilerInfoList =
95
96 if (profilerInfoList.empty()) {
97 std::cout << "No Mech-Eye 3D Laser Profiler found." << std::endl;
98 return false;
99 }
100
101 for (int i = 0; i < profilerInfoList.size(); i++) {
102 std::cout << "Mech-Eye 3D Laser profiler index : " << i << std::endl;
103 printProfilerInfo(profilerInfoList[i]);
104 }
105
106 std::cout << "Please enter the profiler index you want to connect: ";
107 unsigned inputIndex = 0;
108
109 while (true) {
110 std::string str;
111 std::cin >> str;
112 if (isNumber(str) && atoi(str.c_str()) < profilerInfoList.size()) {
113 inputIndex = atoi(str.c_str());
114 break;
115 }
116 std::cout << "Input invalid! Please enter the profiler index you want to connect: ";
117 }
118
120 status = profiler.connect(profilerInfoList[inputIndex]);
121
122 if (!status.isOK()) {
123 showError(status);
124 return false;
125 }
126
127 std::cout << "Connect Mech-Eye 3D Laser Profiler Successfully." << std::endl;
128 return true;
129}
130
131inline bool confirmCapture()
132{
133 std::cout << "Do you want the profiler to capture image ? Please input y/n to confirm: "
134 << std::endl;
135 while (true) {
136 std::string confirmStr;
137 std::cin >> confirmStr;
138 if (confirmStr == "y") {
139 return true;
140 } else if (confirmStr == "n") {
141 std::cout << "program ends!" << std::endl;
142 return false;
143 } else {
144 std::cout << "Please input y/n again!" << std::endl;
145 }
146 }
147}
Represents a Mech-Eye 3D Laser Profiler device.
Definition Profiler.h:22
static MMIND_API_EXPORT std::vector< ProfilerInfo > discoverProfilers()
Discovers all available laser profilers.
MMIND_API_EXPORT ErrorStatus connect(const ProfilerInfo &info, unsigned int timeoutMs=5000)
Connects to a laser profiler by its information.
std::string toString() const
Converts a Version object to string.
Definition Version.h:67
The types of errors.
Definition ErrorStatus.h:11
std::string errorDescription
Definition ErrorStatus.h:77
bool isOK() const
Returns true if the operation succeeded.
Definition ErrorStatus.h:67
The information of the laser profiler.
Version hardwareVersion
The version of the hardware. The hardware cannot be upgraded.
Version firmwareVersion
The version of the firmware. The firmware can be upgraded.
std::string subnetMask
Subnet mask.
IpAssignmentMethod ipAssignmentMethod
IP address assignment method.
std::string model
Laser profiler model.
std::string controllerSN
Controller serial number.
std::string sensorSN
Sensor head serial number.
std::string ipAddress
IP address of the laser profiler.