libvisiontransfer  7.1.0
deviceinfo.h
1 /*******************************************************************************
2  * Copyright (c) 2019 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  };
53 
54  enum NetworkProtocol {
55  PROTOCOL_TCP,
56  PROTOCOL_UDP
57  };
58 
62  DeviceInfo(): ip(""), protocol(PROTOCOL_TCP), fwVersion(""), model(SCENESCAN),
63  compatible(false) {
64  }
65 
77  DeviceInfo(const char* ip, NetworkProtocol protocol, const char* fwVersion,
78  DeviceModel model, bool compatible)
79  : ip(ip), protocol(protocol), fwVersion(fwVersion), model(model),
80  compatible(compatible) {
81  }
82 
86  DeviceInfo(const char* ip, NetworkProtocol protocol, const char* fwVersion,
87  DeviceModel model, bool compatible, const DeviceStatus& status)
88  : ip(ip), protocol(protocol), fwVersion(fwVersion), model(model),
89  compatible(compatible), status(status){
90  }
91 
96  std::string getIpAddress() const {return ip;}
97 
104  NetworkProtocol getNetworkProtocol() const {return protocol;}
105 
114  std::string getFirmwareVersion() const {return fwVersion;}
115 
122  DeviceModel getModel() const {return model;}
123 
127  DeviceStatus getStatus() const { return status; }
128 
133  bool isCompatible() const {return compatible;}
134 
141  std::string toString() const {
142  return ip + "; SceneScan" + (model == SCENESCAN_PRO ? " Pro" : "")
143  + "; " + fwVersion + "; " + (compatible ? "compatible" : "incompatible");
144  }
145 
149  bool operator == (const DeviceInfo& other) const {
150  return ip == other.ip && protocol == other.protocol && fwVersion == other.fwVersion
151  && model == other.model && compatible == other.compatible;
152  }
153 
154 private:
155  std::string ip;
156  NetworkProtocol protocol;
157  std::string fwVersion;
158  DeviceModel model;
159  bool compatible;
160  // Extended device status / health info
161  DeviceStatus status;
162 };
163 
164 } // namespace
165 
166 #endif
DeviceModel getModel() const
Gets the model identifier of the discovered device.
Definition: deviceinfo.h:122
std::string getIpAddress() const
Gets the IP address of the device.
Definition: deviceinfo.h:96
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:77
std::string toString() const
Converts this object to a printable string.
Definition: deviceinfo.h:141
std::string getFirmwareVersion() const
Gets the firmware version of the device.
Definition: deviceinfo.h:114
DeviceStatus getStatus() const
Return the status / health as reported by the device.
Definition: deviceinfo.h:127
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:86
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:133
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:62
NetworkProtocol getNetworkProtocol() const
Gets the network protocol of the device.
Definition: deviceinfo.h:104
Nerian Vision Technologies