nodemap_out.cc
Go to the documentation of this file.
1 /*
2  * This file is part of the rc_genicam_api package.
3  *
4  * Copyright (c) 2023 Roboception GmbH
5  * All rights reserved
6  *
7  * Author: Heiko Hirschmueller
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include "nodemap_out.h"
37 
38 #include <iostream>
39 
40 #ifdef USE_NCURSES
41 #include <ncurses.h>
42 #endif
43 
44 namespace rcg
45 {
46 
47 namespace
48 {
49 
57 const char *getAccessMode(const GenApi::INode *node)
58 {
59  switch (node->GetAccessMode())
60  {
61  case GenApi::NI:
62  return "(NI)";
63 
64  case GenApi::NA:
65  return "(NA)";
66 
67  case GenApi::WO:
68  return "(WO)";
69 
70  case GenApi::RO:
71  return "(RO)";
72 
73  case GenApi::RW:
74  return "(RW)";
75 
77  return "(undefined access mode)";
78 
80  return "(cycle detection)";
81 
82  default:
83  return "(unknown)";
84  }
85 }
86 
87 }
88 
89 std::string formatValue(GenApi::IInteger *node, int64_t value)
90 {
92 
93  switch (node->GetRepresentation())
94  {
95  case GenApi::HexNumber:
96  out << "0x" << std::hex << value;
97  break;
98 
100  out << ((value>>24)&0xff) << '.' << ((value>>16)&0xff) << '.'
101  << ((value>>8)&0xff) << '.' << (value&0xff);
102  break;
103 
104  case GenApi::MACAddress:
105  out << std::hex << ((value>>40)&0xff) << ':' << ((value>>32)&0xff) << ':'
106  << ((value>>24)&0xff) << ':' << ((value>>16)&0xff) << ':'
107  << ((value>>8)&0xff) << ':' << (value&0xff);
108  break;
109 
110  default:
111  out << value;
112  break;
113  }
114 
115  return out.str();
116 }
117 
118 void printNode(const std::string &prefix, GenApi::INode *node, int depth, bool show_enum_list)
119 {
120  if (node != 0 && node->GetAccessMode() != GenApi::NI)
121  {
122  switch (node->GetPrincipalInterfaceType())
123  {
124  case GenApi::intfIValue:
125  std::cout << prefix << "Value: " << node->GetName() << " " << getAccessMode(node)
126  << std::endl;
127  break;
128 
129  case GenApi::intfIBase:
130  std::cout << prefix << "Base: " << node->GetName() << " " << getAccessMode(node)
131  << std::endl;
132  break;
133 
135  {
136  std::cout << prefix << "Integer: " << node->GetName() << " "
137  << getAccessMode(node) << " ";
138 
139  GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
140 
141  if (GenApi::IsReadable(p))
142  {
143  std::cout << "[" << formatValue(p, p->GetMin()) << ", "
144  << formatValue(p, p->GetMax()) << "]: ";
145  std::cout << formatValue(p, p->GetValue()) << " " << p->GetUnit();
146  }
147 
148  std::cout << std::endl;
149  }
150  break;
151 
153  {
154  std::cout << prefix << "Boolean: " << node->GetName() << " " << getAccessMode(node);
155 
156  GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
157 
158  if (GenApi::IsReadable(p))
159  {
160  std::cout << ": " << p->GetValue();
161  }
162 
163  std::cout << std::endl;
164  }
165  break;
166 
168  std::cout << prefix << "Command: " << node->GetName() << " " << getAccessMode(node)
169  << std::endl;
170  break;
171 
172  case GenApi::intfIFloat:
173  {
174  std::cout << prefix << "Float: " << node->GetName() << " " << getAccessMode(node)
175  << " ";
176 
177  GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
178 
179  if (GenApi::IsReadable(p))
180  {
181  std::cout << "[" << p->GetMin() << ", "
182  << p->GetMax() << "]: "
183  << p->GetValue() << " " << p->GetUnit();
184  }
185 
186  std::cout << std::endl;
187  }
188  break;
189 
190  case GenApi::intfIString:
191  {
192  std::cout << prefix << "String: " << node->GetName() << " " << getAccessMode(node)
193  << ": ";
194 
195  GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
196 
197  if (GenApi::IsReadable(p))
198  {
199  std::cout << p->GetValue();
200  }
201 
202  std::cout << std::endl;
203  }
204  break;
205 
207  std::cout << prefix << "Register: " << node->GetName() << " " << getAccessMode(node)
208  << std::endl;
209  break;
210 
212  {
213  std::cout << prefix << "Category: " << node->GetName() << " "
214  << getAccessMode(node) << std::endl;
215 
216  if (depth > 0)
217  {
218  GenApi::ICategory *root=dynamic_cast<GenApi::ICategory *>(node);
219 
220  if (root != 0)
221  {
222  GenApi::FeatureList_t feature;
223  root->GetFeatures(feature);
224 
225  for (size_t i=0; i<feature.size(); i++)
226  {
227  printNode(prefix+" ", feature[i]->GetNode(), depth-1, show_enum_list);
228  }
229  }
230  }
231  }
232  break;
233 
235  {
236  std::cout << prefix << "Enumeration: " << node->GetName() << " " << getAccessMode(node)
237  << ' ';
238 
239  GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
240 
241  if (p != nullptr)
242  {
243  std::cout << '[';
244 
245  if (show_enum_list)
246  {
248  p->GetSymbolics(list);
249 
250  for (size_t i=0; i<list.size(); i++)
251  {
252  if (i > 0)
253  {
254  std::cout << ' ';
255  }
256 
257  std::cout << list[i];
258  }
259  }
260  else
261  {
262  std::cout << "...";
263  }
264 
265  std::cout << "]: ";
266 
267  if (GenApi::IsReadable(p->GetAccessMode()) && p->GetCurrentEntry() != 0)
268  {
269  std::cout << p->GetCurrentEntry()->GetSymbolic();
270  }
271  }
272 
273  std::cout << std::endl;
274  }
275  break;
276 
278  std::cout << prefix << "EnumEntry: " << node->GetName() << " " << getAccessMode(node)
279  << std::endl;
280  break;
281 
282  case GenApi::intfIPort:
283  std::cout << prefix << "Port: " << node->GetName() << " " << getAccessMode(node)
284  << std::endl;
285  break;
286 
287  default:
288  break;
289  }
290  }
291 }
292 
293 bool printNodemap(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char root[],
294  int depth, bool show_enum_list)
295 {
296  GenApi::INode *p=nodemap->_GetNode(root);
297  bool ret=false;
298 
299  if (p)
300  {
301  printNode(std::string(" "), p, depth, show_enum_list);
302  ret=true;
303  }
304 
305  return ret;
306 }
307 
308 }
Hex number in an edit control.
Definition: Types.h:94
IFloat interface.
Definition: Types.h:195
ICommand interface.
Definition: Types.h:194
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBoolean
Interface for Boolean properties.
Definition: IBoolean.h:61
IPort interface.
Definition: Types.h:201
GENICAM_INTERFACE IInteger
Interface for integer properties.
Definition: IFloat.h:114
IBase interface.
Definition: Types.h:191
virtual INode * GetNode(const GENICAM_NAMESPACE::gcstring &Name) const =0
Retrieves the node from the central map by Name.
__int64 int64_t
Definition: config-win32.h:21
used internally for AccessMode cycle detection
Definition: Types.h:62
std::string str()
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
void printNode(const std::string &prefix, GenApi::INode *node, int depth, bool show_enum_list)
Recursive printing of nodes to standard out.
Definition: nodemap_out.cc:118
IString interface.
Definition: Types.h:196
IBoolean interface.
Definition: Types.h:193
IValue interface.
Definition: Types.h:190
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:60
ICategory interface.
Definition: Types.h:198
Not implemented.
Definition: Types.h:56
Read Only.
Definition: Types.h:59
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT ICategory
Gives access to a category node.
Definition: ICategory.h:66
Not available.
Definition: Types.h:57
Write Only.
Definition: Types.h:58
IEnumeration interface.
Definition: Types.h:199
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IString
Interface for string properties.
Definition: IString.h:61
Definition: buffer.cc:47
Object is not yet initialized.
Definition: Types.h:61
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition: IFloat.h:60
GENICAM_INTERFACE INode
Interface common to all nodes.
Definition: ICategory.h:51
bool printNodemap(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char root[], int depth, bool show_enum_list)
Printing of nodemap, starting at given root node.
Definition: nodemap_out.cc:293
Read and Write.
Definition: Types.h:60
std::string formatValue(GenApi::IInteger *node, int64_t value)
Takes an integer value and formats it according to the specification in the node. ...
Definition: nodemap_out.cc:89
GENICAM_NAMESPACE::gcstring_vector StringList_t
A list of strings.
Definition: Types.h:149
IRegister interface.
Definition: Types.h:197
IEnumEntry interface.
Definition: Types.h:200
IInteger interface.
Definition: Types.h:192


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Sun Jun 18 2023 02:43:55