libvisiontransfer  8.3.0
deviceinfo.h
1 /*******************************************************************************
2  * Copyright (c) 2020 Nerian Vision 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  };
54 
55  enum NetworkProtocol {
56  PROTOCOL_TCP,
57  PROTOCOL_UDP
58  };
59 
63  DeviceInfo(): ip(""), protocol(PROTOCOL_TCP), fwVersion(""), model(SCENESCAN),
64  compatible(false) {
65  }
66 
78  DeviceInfo(const char* ip, NetworkProtocol protocol, const char* fwVersion,
79  DeviceModel model, bool compatible)
80  : ip(ip), protocol(protocol), fwVersion(fwVersion), model(model),
81  compatible(compatible) {
82  }
83 
87  DeviceInfo(const char* ip, NetworkProtocol protocol, const char* fwVersion,
88  DeviceModel model, bool compatible, const DeviceStatus& status)
89  : ip(ip), protocol(protocol), fwVersion(fwVersion), model(model),
90  compatible(compatible), status(status){
91  }
92 
97  std::string getIpAddress() const {return ip;}
98 
105  NetworkProtocol getNetworkProtocol() const {return protocol;}
106 
115  std::string getFirmwareVersion() const {return fwVersion;}
116 
124  DeviceModel getModel() const {return model;}
125 
129  DeviceStatus getStatus() const { return status; }
130 
135  bool isCompatible() const {return compatible;}
136 
143  std::string toString() const {
144  std::string ret = ip + "; ";
145  switch(model) {
146  case SCENESCAN_PRO: ret += "SceneScan Pro"; break;
147  case SCENESCAN: ret += "SceneScan"; break;
148  case SCARLET: ret += "Scarlet"; break;
149  default: ret += "Unknown"; break;
150  }
151 
152  ret += "; " + fwVersion + "; " + (compatible ? "compatible" : "incompatible");
153  return ret;
154  }
155 
159  bool operator == (const DeviceInfo& other) const {
160  return ip == other.ip && protocol == other.protocol && fwVersion == other.fwVersion
161  && model == other.model && compatible == other.compatible;
162  }
163 
164 private:
165  std::string ip;
166  NetworkProtocol protocol;
167  std::string fwVersion;
168  DeviceModel model;
169  bool compatible;
170  // Extended device status / health info
171  DeviceStatus status;
172 };
173 
174 } // namespace
175 
176 #endif
DeviceModel getModel() const
Gets the model identifier of the discovered device.
Definition: deviceinfo.h:124
std::string getIpAddress() const
Gets the IP address of the device.
Definition: deviceinfo.h:97
DeviceInfo(const char *ip, NetworkProtocol protocol, const char *fwVersion, DeviceModel model, bool compatible)
Constructs an object by initializing all members with data from the given parameters.
Definition: deviceinfo.h:78
std::string toString() const
Converts this object to a printable string.
Definition: deviceinfo.h:143
std::string getFirmwareVersion() const
Gets the firmware version of the device.
Definition: deviceinfo.h:115
DeviceStatus getStatus() const
Return the status / health as reported by the device.
Definition: deviceinfo.h:129
DeviceInfo(const char *ip, NetworkProtocol protocol, const char *fwVersion, DeviceModel model, bool compatible, const DeviceStatus &status)
Construct DeviceInfo with pre-initialized DeviceStatus field, for received health reports...
Definition: deviceinfo.h:87
Aggregates information about a discovered device.
Definition: deviceinfo.h:47
bool isCompatible() const
Returns true if the device is compatible with this API version.
Definition: deviceinfo.h:135
Representation of the current device status / health. Useful for addressing issues with peripherals o...
Definition: deviceinfo.h:26
DeviceInfo()
Constructs an empty object with default information.
Definition: deviceinfo.h:63
NetworkProtocol getNetworkProtocol() const
Gets the network protocol of the device.
Definition: deviceinfo.h:105
Nerian Vision Technologies