IRSOL
C++ code implementing socket server for interacting with Baumer camera.
discovery.cpp
Go to the documentation of this file.
1
3
4#include "irsol/logging.hpp"
5#include "irsol/macros.hpp"
6
7#include <tabulate/table.hpp>
8
9using namespace std;
10
11namespace irsol {
12namespace camera {
13namespace internal {
14std::map<FeaturePermissions, std::vector<NeoAPI::Feature*>>
15extractCameraFeatures(NeoAPI::Cam& cam)
16{
17 std::map<internal::FeaturePermissions, std::vector<NeoAPI::Feature*>> featurePermissionsMap;
18
19 uint64_t featureCount = 0;
20 for(auto& f : cam.GetFeatureList()) {
21 IRSOL_LOG_TRACE("Feature: {0:s}", f.GetName().c_str());
22 auto isAvailable = f.IsAvailable();
23 auto isReadable = f.IsReadable();
24 auto isWritable = f.IsWritable();
25 internal::FeaturePermissions permissions = {isAvailable, isReadable, isWritable};
26 if(featurePermissionsMap.find(permissions) == featurePermissionsMap.cend()) {
27 featurePermissionsMap[permissions] = std::vector<NeoAPI::Feature*>();
28 }
29 featurePermissionsMap[permissions].push_back(&f);
30 featureCount++;
31 }
32
33 IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START // Disable unused variable warning
34 for(auto& [_, features] : featurePermissionsMap)
35 {
37 std::sort(features.begin(), features.end(), [](NeoAPI::Feature* a, NeoAPI::Feature* b) {
38 return std::string(a->GetName()) < std::string(b->GetName());
39 });
40 }
41
42 IRSOL_LOG_INFO("Loaded {0:d} camera features", featureCount);
43 return featurePermissionsMap;
44}
45}
46std::string
48{
49 const auto& featurePermissionsMap =
51 tabulate::Table table;
52 table.add_row({"Feature Name", "Available", "Readable", "Writable"});
53
54 for(const auto& [permissions, features] : featurePermissionsMap) {
55 for(const auto* feature : features) {
56 table.add_row({feature->GetName().c_str(),
57 permissions.isAvailable() ? "yes" : "no",
58 permissions.isReadable() ? "yes" : "no",
59 permissions.isWritable() ? "yes" : "no"});
60 }
61 }
62
63 // Optional formatting:
64 table.column(0).format().font_align(tabulate::FontAlign::right);
65 table.column(1).format().font_align(tabulate::FontAlign::center);
66 table.column(2).format().font_align(tabulate::FontAlign::center);
67 table.column(3).format().font_align(tabulate::FontAlign::center);
68
69 return table.str();
70}
71} // namespace camera
72} // namespace irsol
High-level wrapper around the NeoAPI camera for synchronized access.
Definition interface.hpp:61
NeoAPI::Cam & getNeoCam()
Access the underlying NeoAPI camera instance.
Utility function for discovering the features that are available in a camera.
#define IRSOL_LOG_INFO(...)
Logs an info-level message using the default logger.
Definition logging.hpp:92
#define IRSOL_LOG_TRACE(...)
Logs a trace-level message using the default logger.
Definition logging.hpp:90
Logging utilities and configuration for the irsol library.
Common portability and diagnostic macros for the irsol library.
#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START
Begins a diagnostic suppression block for unused structured binding variables.
Definition macros.hpp:68
#define IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_END
Ends a diagnostic suppression block started with IRSOL_SUPPRESS_UNUSED_STRUCTURED_BINDING_START.
Definition macros.hpp:69
std::map< FeaturePermissions, std::vector< NeoAPI::Feature * > > extractCameraFeatures(NeoAPI::Cam &cam)
Extracts and groups camera features by their permissions.
Definition discovery.cpp:15
std::string discoverCameraFeatures(Interface &cam)
Discovers all camera features and their permissions.
Definition discovery.cpp:47
Encapsulates the permissions of a camera feature.
Definition discovery.hpp:40