deviceinfo.cc
Go to the documentation of this file.
1 /*
2  * rcdiscover - the network discovery tool for Roboception devices
3  *
4  * Copyright (c) 2017 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 "deviceinfo.h"
37 
38 #include <sstream>
39 
40 namespace rcdiscover
41 {
42 
43 namespace
44 {
45 
46 /*
47  Extract at most len bytes from p as characters and returns them as string.
48  Extraction ends if a null byte is encountered or if len bytes have been
49  extracted.
50 
51  @param p Pointer to byte array.
52  @param len Maximum number of bytes to extract.
53  @return Extracted string.
54 */
55 
56 std::string extract(const uint8_t *p, size_t len)
57 {
58  std::ostringstream out;
59 
60  while (*p != 0 && len > 0)
61  {
62  out << static_cast<char>(*p);
63 
64  p++;
65  len--;
66  }
67 
68  return out.str();
69 }
70 
71 }
72 
73 DeviceInfo::DeviceInfo(std::string iface_name) :
74  iface_name(std::move(iface_name))
75 {
76  clear();
77 }
78 
79 void DeviceInfo::set(const uint8_t *raw, size_t len)
80 {
81  // clear stored information
82 
83  clear();
84 
85  // extract information
86 
87  if (len >= 4)
88  {
89  major=(static_cast<int>(raw[0])<<8)|raw[1];
90  minor=(static_cast<int>(raw[2])<<8)|raw[3];
91  }
92 
93  if (len >= 16)
94  {
95  mac=0;
96  for (int i=0; i<6; i++) mac=(mac<<8)|raw[10+i];
97  }
98 
99  if (len >= 40)
100  {
101  ip=0;
102  for (int i=0; i<4; i++) ip=(ip<<8)|raw[36+i];
103  }
104 
105  if (len >= 56)
106  {
107  subnet=0;
108  for (int i=0; i<4; i++) subnet=(subnet<<8)|raw[52+i];
109  }
110 
111  if (len >= 72)
112  {
113  gateway=0;
114  for (int i=0; i<4; i++) gateway=(gateway<<8)|raw[68+i];
115  }
116 
117  if (len >= 104) manufacturer_name=extract(raw+72, 32);
118  if (len >= 136) model_name=extract(raw+104, 32);
119  if (len >= 168) device_version=extract(raw+136, 32);
120  if (len >= 216) manufacturer_info=extract(raw+168, 48);
121  if (len >= 232) serial_number=extract(raw+216, 16);
122  if (len >= 248) user_name=extract(raw+232, 16);
123 }
124 
126 {
127  major=minor=0;
128  mac=0;
129  ip=0;
130  subnet=0;
131  gateway=0;
132 
133  manufacturer_name.erase();
134  model_name.erase();
135  device_version.erase();
136  manufacturer_info.erase();
137  serial_number.erase();
138  user_name.erase();
139 }
140 
141 }
std::string manufacturer_info
Definition: deviceinfo.h:197
std::string manufacturer_name
Definition: deviceinfo.h:194
void clear()
Clears all information.
Definition: deviceinfo.cc:125
std::string device_version
Definition: deviceinfo.h:196
std::string model_name
Definition: deviceinfo.h:195
std::string user_name
Definition: deviceinfo.h:199
DeviceInfo(std::string iface_name)
Definition: deviceinfo.cc:73
std::string serial_number
Definition: deviceinfo.h:198
void set(const uint8_t *raw, size_t len)
Extracts the RAW GigE Vision information according to the given DISCOVERY_ACK package.
Definition: deviceinfo.cc:79


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Sun Apr 18 2021 02:16:32