libvisiontransfer  10.6.0
deviceinfo.h
1 /*******************************************************************************
2  * Copyright (c) 2023 Allied Vision Technologies GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef VISIONTRANSFER_DEVICEINFO_H
16 #define VISIONTRANSFER_DEVICEINFO_H
17 
18 #include <string>
19 
20 namespace visiontransfer {
21 
26 class DeviceStatus {
27 public:
28  DeviceStatus()
29  : lastFps(0.0), jumboSize(0), currentCaptureSource(""), validStatus(false) { }
30  DeviceStatus(double lastFps, unsigned int jumboSize, const std::string& currentCaptureSource)
31  : lastFps(lastFps), jumboSize(jumboSize), currentCaptureSource(currentCaptureSource), validStatus(true) { }
32  bool isValid() const { return validStatus; }
33  double getLastFps() const { return lastFps; }
34  unsigned int getJumboMtu() const { return jumboSize; }
35  unsigned int getJumboFramesEnabled() const { return jumboSize > 0; }
36  std::string getCurrentCaptureSource() const { return currentCaptureSource; }
37 private:
38  double lastFps; // Most recent FPS report, or 0.0 if N/A
39  unsigned int jumboSize; // Jumbo MTU, or 0 if Jumbo mode disabled
40  std::string currentCaptureSource; // for targeted instructions
41  bool validStatus; // whether the status record contains actual data
42 };
43 
47 class DeviceInfo {
48 public:
49  enum DeviceModel {
50  SCENESCAN,
51  SCENESCAN_PRO,
52  SCARLET,
53  RUBY
54  };
55 
56  enum NetworkProtocol {
57  PROTOCOL_TCP,
58  PROTOCOL_UDP
59  };
60 
64  DeviceInfo(): ip(""), protocol(PROTOCOL_TCP), fwVersion(""), model(SCENESCAN),
65  compatible(false) {
66  }
67 
79  DeviceInfo(const char* ip, NetworkProtocol protocol, const char* fwVersion,
80  DeviceModel model, bool compatible)
81  : ip(ip), protocol(protocol), fwVersion(fwVersion), model(model),
82  compatible(compatible) {
83  }
84 
88  DeviceInfo(const char* ip, NetworkProtocol protocol, const char* fwVersion,
89  DeviceModel model, bool compatible, const DeviceStatus& status)
90  : ip(ip), protocol(protocol), fwVersion(fwVersion), model(model),
91  compatible(compatible), status(status){
92  }
93 
98  std::string getIpAddress() const {return ip;}
99 
106  NetworkProtocol getNetworkProtocol() const {return protocol;}
107 
116  std::string getFirmwareVersion() const {return fwVersion;}
117 
125  DeviceModel getModel() const {return model;}
126 
130  DeviceStatus getStatus() const { return status; }
131 
136  bool isCompatible() const {return compatible;}
137 
144  std::string toString() const {
145  std::string ret = ip + "; ";
146  switch(model) {
147  case SCENESCAN_PRO: ret += "SceneScan Pro"; break;
148  case SCENESCAN: ret += "SceneScan"; break;
149  case SCARLET: ret += "Scarlet"; break;
150  case RUBY: ret += "Ruby"; break;
151  default: ret += "Unknown"; break;
152  }
153 
154  ret += "; " + fwVersion + "; " + (compatible ? "compatible" : "incompatible");
155  return ret;
156  }
157 
161  bool operator == (const DeviceInfo& other) const {
162  return ip == other.ip && protocol == other.protocol && fwVersion == other.fwVersion
163  && model == other.model && compatible == other.compatible;
164  }
165 
166 private:
167  std::string ip;
168  NetworkProtocol protocol;
169  std::string fwVersion;
170  DeviceModel model;
171  bool compatible;
172  // Extended device status / health info
173  DeviceStatus status;
174 };
175 
176 } // namespace
177 
178 #endif
visiontransfer::DeviceInfo::toString
std::string toString() const
Converts this object to a printable string.
Definition: deviceinfo.h:156
visiontransfer::DeviceInfo::getNetworkProtocol
NetworkProtocol getNetworkProtocol() const
Gets the network protocol of the device.
Definition: deviceinfo.h:118
visiontransfer::DeviceInfo::isCompatible
bool isCompatible() const
Returns true if the device is compatible with this API version.
Definition: deviceinfo.h:148
visiontransfer::DeviceInfo::getStatus
DeviceStatus getStatus() const
Return the status / health as reported by the device.
Definition: deviceinfo.h:142
visiontransfer::DeviceInfo
Aggregates information about a discovered device.
Definition: deviceinfo.h:59
visiontransfer::DeviceInfo::DeviceInfo
DeviceInfo()
Constructs an empty object with default information.
Definition: deviceinfo.h:76
visiontransfer::DeviceInfo::getModel
DeviceModel getModel() const
Gets the model identifier of the discovered device.
Definition: deviceinfo.h:137
visiontransfer::DeviceInfo::getFirmwareVersion
std::string getFirmwareVersion() const
Gets the firmware version of the device.
Definition: deviceinfo.h:128
visiontransfer::DeviceInfo::getIpAddress
std::string getIpAddress() const
Gets the IP address of the device.
Definition: deviceinfo.h:110
visiontransfer::DeviceInfo::operator==
bool operator==(const DeviceInfo &other) const
Comparison operator for comparing two DeviceInfo objects.
Definition: deviceinfo.h:173
visiontransfer::DeviceStatus
Representation of the current device status / health. Useful for addressing issues with peripherals o...
Definition: deviceinfo.h:38
Allied Vision