Kobuki 1.0.0
C++ API for the Kobuki research robot
Loading...
Searching...
No Matches
version_info.hpp
Go to the documentation of this file.
1
9/*****************************************************************************
10** Ifdefs
11*****************************************************************************/
12
13#ifndef KOBUKI_CORE_VERSION_HPP_
14#define KOBUKI_CORE_VERSION_HPP_
15
16/*****************************************************************************
17** Includes
18*****************************************************************************/
19
20#include <iostream>
21#include <string>
22#include <sstream>
23#include <stdint.h>
24#include <vector>
25
26#include "macros.hpp"
27
28/*****************************************************************************
29** Namespaces
30*****************************************************************************/
31
32namespace kobuki {
33
34/*****************************************************************************
35** Interfaces
36*****************************************************************************/
40class kobuki_PUBLIC VersionInfo {
41public:
42 VersionInfo(const uint32_t &fw, const uint32_t &hw, const uint32_t udid0_, const uint32_t udid1_, const uint32_t udid2_ ) :
43 firmware(fw),
44 hardware(hw),
45 software(0),
46 udid0(udid0_),
47 udid1(udid1_),
48 udid2(udid2_)
49 {}
50 const uint32_t firmware;
51 const uint32_t hardware;
52 const uint32_t software;
53 const uint32_t udid0;
54 const uint32_t udid1;
55 const uint32_t udid2;
56
57 static int majorVersion(const uint32_t &version) {
58 return ((version & 0x00FF0000) >> 16);
59 }
60
61 static int minorVersion(const uint32_t &version) {
62 return ((version & 0x0000FF00) >> 8);
63 }
64
65 static int patchVersion(const uint32_t &version) {
66 return (version & 0x000000FF);
67 }
68
69 static std::string toString(const uint32_t &version)
70 {
71 // Convert an unsigned int into a string of type <major>.<minor>.<patch>; first byte is ignored
72 std::stringstream ss;
73 ss << majorVersion(version) << "." << minorVersion(version) << "." << patchVersion(version);
74 return std::string(ss.str());
75 }
76
77 static std::string toString(const std::vector<uint32_t> &versions)
78 {
79 std::stringstream ss;
80 std::size_t number_versions = versions.size();
81 for(std::size_t i = 0; i < number_versions; ++i) {
82 ss << VersionInfo::toString(versions[i]);
83 if (i != (number_versions - 1)) {
84 ss << " / ";
85 }
86 }
87 return std::string(ss.str());
88 }
89
90 static std::string toString(const uint32_t &udid0, const uint32_t &udid1, const uint32_t &udid2)
91 {
92 // Convert three udid unsigned integers into a string of type <udid0>-<udid1>-<udid2>
93 std::stringstream ss;
94 ss << udid0 << "-" << udid1 << "-" << udid2;
95 return std::string(ss.str());
96 }
97
98 static std::string getSoftwareVersion();
99};
100
101} // namespace kobuki
102#endif /* KOBUKI_CORE_VERSION_HPP_ */
Definition version_info.hpp:40
Macros for kobuki_core.