All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 #include <iostream>
45 #include <iomanip>
46 
47 namespace rcg
48 {
49 
50 namespace
51 {
52 
60 const char *getAccessMode(const GenApi::INode *node)
61 {
62  switch (node->GetAccessMode())
63  {
64  case GenApi::NI:
65  return "(NI)";
66 
67  case GenApi::NA:
68  return "(NA)";
69 
70  case GenApi::WO:
71  return "(WO)";
72 
73  case GenApi::RO:
74  return "(RO)";
75 
76  case GenApi::RW:
77  return "(RW)";
78 
80  return "(undefined access mode)";
81 
83  return "(cycle detection)";
84 
85  default:
86  return "(unknown)";
87  }
88 }
89 
90 }
91 
92 std::string formatValue(GenApi::IInteger *node, int64_t value)
93 {
95 
96  switch (node->GetRepresentation())
97  {
98  case GenApi::HexNumber:
99  out << "0x" << std::hex << value;
100  break;
101 
102  case GenApi::IPV4Address:
103  out << ((value>>24)&0xff) << '.' << ((value>>16)&0xff) << '.'
104  << ((value>>8)&0xff) << '.' << (value&0xff);
105  break;
106 
107  case GenApi::MACAddress:
108  out << std::hex << ((value>>40)&0xff) << ':' << ((value>>32)&0xff) << ':'
109  << ((value>>24)&0xff) << ':' << ((value>>16)&0xff) << ':'
110  << ((value>>8)&0xff) << ':' << (value&0xff);
111  break;
112 
113  default:
114  out << value;
115  break;
116  }
117 
118  return out.str();
119 }
120 
121 void printNode(const std::string &prefix, GenApi::INode *node, int depth, bool show_enum_list)
122 {
123  if (node != 0 && node->GetAccessMode() != GenApi::NI)
124  {
125  switch (node->GetPrincipalInterfaceType())
126  {
127  case GenApi::intfIValue:
128  std::cout << prefix << "Value: " << node->GetName() << " " << getAccessMode(node)
129  << std::endl;
130  break;
131 
132  case GenApi::intfIBase:
133  std::cout << prefix << "Base: " << node->GetName() << " " << getAccessMode(node)
134  << std::endl;
135  break;
136 
138  {
139  std::cout << prefix << "Integer: " << node->GetName() << " "
140  << getAccessMode(node) << " ";
141 
142  GenApi::IInteger *p=dynamic_cast<GenApi::IInteger *>(node);
143 
144  if (GenApi::IsReadable(p))
145  {
146  std::cout << "[" << formatValue(p, p->GetMin()) << ", "
147  << formatValue(p, p->GetMax()) << "]: ";
148  std::cout << formatValue(p, p->GetValue()) << " " << p->GetUnit();
149  }
150 
151  std::cout << std::endl;
152  }
153  break;
154 
156  {
157  std::cout << prefix << "Boolean: " << node->GetName() << " " << getAccessMode(node);
158 
159  GenApi::IBoolean *p=dynamic_cast<GenApi::IBoolean *>(node);
160 
161  if (GenApi::IsReadable(p))
162  {
163  std::cout << ": " << p->GetValue();
164  }
165 
166  std::cout << std::endl;
167  }
168  break;
169 
171  std::cout << prefix << "Command: " << node->GetName() << " " << getAccessMode(node)
172  << std::endl;
173  break;
174 
175  case GenApi::intfIFloat:
176  {
177  std::cout << prefix << "Float: " << node->GetName() << " " << getAccessMode(node)
178  << " ";
179 
180  GenApi::IFloat *p=dynamic_cast<GenApi::IFloat *>(node);
181 
182  if (GenApi::IsReadable(p))
183  {
184  std::cout << "[" << p->GetMin() << ", "
185  << p->GetMax() << "]: "
186  << p->GetValue() << " " << p->GetUnit();
187  }
188 
189  std::cout << std::endl;
190  }
191  break;
192 
193  case GenApi::intfIString:
194  {
195  std::cout << prefix << "String: " << node->GetName() << " " << getAccessMode(node)
196  << ": ";
197 
198  GenApi::IString *p=dynamic_cast<GenApi::IString *>(node);
199 
200  if (GenApi::IsReadable(p))
201  {
202  std::cout << p->GetValue();
203  }
204 
205  std::cout << std::endl;
206  }
207  break;
208 
210  {
211  GenApi::IRegister *p=dynamic_cast<GenApi::IRegister *>(node);
212 
213  if (p)
214  {
215  int len=static_cast<int>(p->GetLength());
216 
217  std::cout << prefix << "Register: " << node->GetName() << "[" << len << "] "
218  << getAccessMode(node) << ": " << std::hex;
219 
220  if (GenApi::IsReadable(p))
221  {
222  uint8_t buffer[32];
223  p->Get(buffer, std::min(len, 32));
224 
225  for (int i=0; i<len && i<32; i++)
226  {
227  std::cout << std::setfill('0') << std::setw(2) << static_cast<int>(buffer[i]);
228  }
229 
230  if (len > 32)
231  {
232  std::cout << "...";
233  }
234  }
235 
236  std::cout << std::dec << std::endl;
237  }
238  }
239 
240  break;
241 
243  {
244  std::cout << prefix << "Category: " << node->GetName() << " "
245  << getAccessMode(node) << std::endl;
246 
247  if (depth > 0)
248  {
249  GenApi::ICategory *root=dynamic_cast<GenApi::ICategory *>(node);
250 
251  if (root != 0)
252  {
253  GenApi::FeatureList_t feature;
254  root->GetFeatures(feature);
255 
256  for (size_t i=0; i<feature.size(); i++)
257  {
258  printNode(prefix+" ", feature[i]->GetNode(), depth-1, show_enum_list);
259  }
260  }
261  }
262  }
263  break;
264 
266  {
267  std::cout << prefix << "Enumeration: " << node->GetName() << " " << getAccessMode(node)
268  << ' ';
269 
270  GenApi::IEnumeration *p=dynamic_cast<GenApi::IEnumeration *>(node);
271 
272  if (p != nullptr)
273  {
274  std::cout << '[';
275 
276  if (show_enum_list)
277  {
279  p->GetSymbolics(list);
280 
281  for (size_t i=0; i<list.size(); i++)
282  {
283  if (i > 0)
284  {
285  std::cout << ' ';
286  }
287 
288  std::cout << list[i];
289  }
290  }
291  else
292  {
293  std::cout << "...";
294  }
295 
296  std::cout << "]: ";
297 
298  if (GenApi::IsReadable(p->GetAccessMode()) && p->GetCurrentEntry() != 0)
299  {
300  std::cout << p->GetCurrentEntry()->GetSymbolic();
301  }
302  }
303 
304  std::cout << std::endl;
305  }
306  break;
307 
309  std::cout << prefix << "EnumEntry: " << node->GetName() << " " << getAccessMode(node)
310  << std::endl;
311  break;
312 
313  case GenApi::intfIPort:
314  std::cout << prefix << "Port: " << node->GetName() << " " << getAccessMode(node)
315  << std::endl;
316  break;
317 
318  default:
319  break;
320  }
321  }
322 }
323 
324 bool printNodemap(const std::shared_ptr<GenApi::CNodeMapRef> &nodemap, const char root[],
325  int depth, bool show_enum_list)
326 {
327  GenApi::INode *p=nodemap->_GetNode(root);
328  bool ret=false;
329 
330  if (p)
331  {
332  printNode(std::string(" "), p, depth, show_enum_list);
333  ret=true;
334  }
335 
336  return ret;
337 }
338 
339 }
GENAPI_NAMESPACE::IInteger
GENICAM_INTERFACE IInteger
Interface for integer properties.
Definition: IFloat.h:114
GENAPI_NAMESPACE::intfIString
@ intfIString
IString interface.
Definition: Types.h:196
GENAPI_NAMESPACE::intfIBoolean
@ intfIBoolean
IBoolean interface.
Definition: Types.h:193
GENAPI_NAMESPACE::intfIBase
@ intfIBase
IBase interface.
Definition: Types.h:191
GENAPI_NAMESPACE::intfIRegister
@ intfIRegister
IRegister interface.
Definition: Types.h:197
GENAPI_NAMESPACE::_CycleDetectAccesMode
@ _CycleDetectAccesMode
used internally for AccessMode cycle detection
Definition: Types.h:62
GENAPI_NAMESPACE::intfIInteger
@ intfIInteger
IInteger interface.
Definition: Types.h:192
GENAPI_NAMESPACE::IBoolean
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBoolean
Interface for Boolean properties.
Definition: IBoolean.h:61
rcg
Definition: buffer.cc:47
GENAPI_NAMESPACE::intfIValue
@ intfIValue
IValue interface.
Definition: Types.h:190
GENAPI_NAMESPACE::HexNumber
@ HexNumber
Hex number in an edit control.
Definition: Types.h:94
GENAPI_NAMESPACE::intfIEnumEntry
@ intfIEnumEntry
IEnumEntry interface.
Definition: Types.h:200
GENAPI_NAMESPACE::NI
@ NI
Not implemented.
Definition: Types.h:56
GENAPI_NAMESPACE::IPV4Address
@ IPV4Address
IP-Address.
Definition: Types.h:95
GENAPI_NAMESPACE::IRegister
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IRegister
Interface for registers.
Definition: IRegister.h:61
GENAPI_NAMESPACE::RO
@ RO
Read Only.
Definition: Types.h:59
GENAPI_NAMESPACE::intfIFloat
@ intfIFloat
IFloat interface.
Definition: Types.h:195
rcg::printNodemap
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:324
GENAPI_NAMESPACE::intfIEnumeration
@ intfIEnumeration
IEnumeration interface.
Definition: Types.h:199
GENAPI_NAMESPACE::GetNode
virtual INode * GetNode(const GENICAM_NAMESPACE::gcstring &Name) const =0
Retrieves the node from the central map by Name.
GENAPI_NAMESPACE::intfIPort
@ intfIPort
IPort interface.
Definition: Types.h:201
GENAPI_NAMESPACE::IEnumeration
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
Definition: IEnumeration.h:60
GENAPI_NAMESPACE::IsReadable
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
Definition: INode.h:178
GENAPI_NAMESPACE::RW
@ RW
Read and Write.
Definition: Types.h:60
GENAPI_NAMESPACE::IFloat
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
Definition: IFloat.h:60
GENAPI_NAMESPACE::INode
GENICAM_INTERFACE INode
Interface common to all nodes.
Definition: ICategory.h:51
GENAPI_NAMESPACE::intfICommand
@ intfICommand
ICommand interface.
Definition: Types.h:194
GENAPI_NAMESPACE::WO
@ WO
Write Only.
Definition: Types.h:58
std::ostringstream::str
std::string str()
GENAPI_NAMESPACE::intfICategory
@ intfICategory
ICategory interface.
Definition: Types.h:198
rcg::printNode
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:121
GENAPI_NAMESPACE::IString
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IString
Interface for string properties.
Definition: IString.h:61
rcg::formatValue
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:92
int64_t
__int64 int64_t
Definition: config-win32.h:21
std::ostringstream
Definition: Portability.hh:42
GENAPI_NAMESPACE::_UndefinedAccesMode
@ _UndefinedAccesMode
Object is not yet initialized.
Definition: Types.h:61
nodemap_out.h
GENAPI_NAMESPACE::ICategory
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT ICategory
Gives access to a category node.
Definition: ICategory.h:66
GENAPI_NAMESPACE::MACAddress
@ MACAddress
MAC-Address.
Definition: Types.h:96
GENAPI_NAMESPACE::StringList_t
GENICAM_NAMESPACE::gcstring_vector StringList_t
A list of strings.
Definition: Types.h:149
GENAPI_NAMESPACE::NA
@ NA
Not available.
Definition: Types.h:57


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11