pyxcp 0.23.8__cp313-cp313-macosx_11_0_arm64.whl → 0.25.7__cp313-cp313-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyxcp/__init__.py +1 -1
- pyxcp/cmdline.py +14 -29
- pyxcp/config/__init__.py +1257 -1258
- pyxcp/cpp_ext/aligned_buffer.hpp +168 -0
- pyxcp/cpp_ext/bin.hpp +7 -6
- pyxcp/cpp_ext/cpp_ext.cpython-310-darwin.so +0 -0
- pyxcp/cpp_ext/cpp_ext.cpython-311-darwin.so +0 -0
- pyxcp/cpp_ext/cpp_ext.cpython-312-darwin.so +0 -0
- pyxcp/cpp_ext/cpp_ext.cpython-313-darwin.so +0 -0
- pyxcp/cpp_ext/daqlist.hpp +241 -73
- pyxcp/cpp_ext/extension_wrapper.cpp +123 -15
- pyxcp/cpp_ext/framing.hpp +360 -0
- pyxcp/cpp_ext/helper.hpp +280 -280
- pyxcp/cpp_ext/mcobject.hpp +248 -246
- pyxcp/cpp_ext/sxi_framing.hpp +332 -0
- pyxcp/daq_stim/__init__.py +145 -67
- pyxcp/daq_stim/optimize/binpacking.py +2 -2
- pyxcp/daq_stim/scheduler.cpp +8 -8
- pyxcp/errormatrix.py +2 -2
- pyxcp/examples/run_daq.py +5 -4
- pyxcp/examples/xcp_policy.py +6 -6
- pyxcp/examples/xcp_read_benchmark.py +2 -2
- pyxcp/examples/xcp_skel.py +1 -2
- pyxcp/examples/xcp_unlock.py +10 -12
- pyxcp/examples/xcp_user_supplied_driver.py +1 -2
- pyxcp/examples/xcphello.py +2 -15
- pyxcp/examples/xcphello_recorder.py +2 -2
- pyxcp/master/__init__.py +1 -0
- pyxcp/master/errorhandler.py +134 -4
- pyxcp/master/master.py +823 -252
- pyxcp/recorder/.idea/.gitignore +8 -0
- pyxcp/recorder/.idea/misc.xml +4 -0
- pyxcp/recorder/.idea/modules.xml +8 -0
- pyxcp/recorder/.idea/recorder.iml +6 -0
- pyxcp/recorder/.idea/sonarlint/issuestore/3/8/3808afc69ac1edb9d760000a2f137335b1b99728 +7 -0
- pyxcp/recorder/.idea/sonarlint/issuestore/9/a/9a2aa4db38d3115ed60da621e012c0efc0172aae +0 -0
- pyxcp/recorder/.idea/sonarlint/issuestore/b/4/b49006702b459496a8e8c94ebe60947108361b91 +0 -0
- pyxcp/recorder/.idea/sonarlint/issuestore/index.pb +7 -0
- pyxcp/recorder/.idea/sonarlint/securityhotspotstore/3/8/3808afc69ac1edb9d760000a2f137335b1b99728 +0 -0
- pyxcp/recorder/.idea/sonarlint/securityhotspotstore/9/a/9a2aa4db38d3115ed60da621e012c0efc0172aae +0 -0
- pyxcp/recorder/.idea/sonarlint/securityhotspotstore/b/4/b49006702b459496a8e8c94ebe60947108361b91 +0 -0
- pyxcp/recorder/.idea/sonarlint/securityhotspotstore/index.pb +7 -0
- pyxcp/recorder/.idea/vcs.xml +10 -0
- pyxcp/recorder/__init__.py +96 -98
- pyxcp/recorder/converter/__init__.py +4 -10
- pyxcp/recorder/reader.hpp +138 -139
- pyxcp/recorder/reco.py +1 -0
- pyxcp/recorder/rekorder.cpython-310-darwin.so +0 -0
- pyxcp/recorder/rekorder.cpython-311-darwin.so +0 -0
- pyxcp/recorder/rekorder.cpython-312-darwin.so +0 -0
- pyxcp/recorder/rekorder.cpython-313-darwin.so +0 -0
- pyxcp/recorder/rekorder.hpp +274 -274
- pyxcp/recorder/unfolder.hpp +1354 -1319
- pyxcp/recorder/wrap.cpp +184 -183
- pyxcp/recorder/writer.hpp +302 -302
- pyxcp/scripts/xcp_daq_recorder.py +54 -0
- pyxcp/scripts/xcp_fetch_a2l.py +2 -2
- pyxcp/scripts/xcp_id_scanner.py +1 -2
- pyxcp/scripts/xcp_info.py +66 -51
- pyxcp/scripts/xcp_profile.py +1 -2
- pyxcp/tests/test_daq.py +1 -1
- pyxcp/tests/test_framing.py +262 -0
- pyxcp/tests/test_master.py +210 -100
- pyxcp/tests/test_transport.py +138 -42
- pyxcp/timing.py +1 -1
- pyxcp/transport/__init__.py +8 -5
- pyxcp/transport/base.py +70 -180
- pyxcp/transport/can.py +58 -7
- pyxcp/transport/eth.py +32 -15
- pyxcp/transport/hdf5_policy.py +167 -0
- pyxcp/transport/sxi.py +126 -52
- pyxcp/transport/transport_ext.cpython-310-darwin.so +0 -0
- pyxcp/transport/transport_ext.cpython-311-darwin.so +0 -0
- pyxcp/transport/transport_ext.cpython-312-darwin.so +0 -0
- pyxcp/transport/transport_ext.cpython-313-darwin.so +0 -0
- pyxcp/transport/transport_ext.hpp +214 -0
- pyxcp/transport/transport_wrapper.cpp +249 -0
- pyxcp/transport/usb_transport.py +47 -31
- pyxcp/types.py +0 -13
- pyxcp/{utils.py → utils/__init__.py} +1 -2
- pyxcp/utils/cli.py +78 -0
- {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info}/METADATA +4 -2
- pyxcp-0.25.7.dist-info/RECORD +158 -0
- {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info}/WHEEL +1 -1
- pyxcp/examples/conf_sxi.json +0 -9
- pyxcp/examples/conf_sxi.toml +0 -7
- pyxcp-0.23.8.dist-info/RECORD +0 -135
- {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info}/entry_points.txt +0 -0
- {pyxcp-0.23.8.dist-info → pyxcp-0.25.7.dist-info/licenses}/LICENSE +0 -0
pyxcp/cpp_ext/helper.hpp
CHANGED
|
@@ -1,280 +1,280 @@
|
|
|
1
|
-
|
|
2
|
-
#if !defined(__HELPER_HPP)
|
|
3
|
-
#define __HELPER_HPP
|
|
4
|
-
|
|
5
|
-
#if defined(_WIN32) || defined(_WIN64)
|
|
6
|
-
|
|
7
|
-
#else
|
|
8
|
-
#include <sys/time.h>
|
|
9
|
-
#include <time.h>
|
|
10
|
-
#endif
|
|
11
|
-
|
|
12
|
-
#include <bit>
|
|
13
|
-
#include <chrono>
|
|
14
|
-
#include <iostream>
|
|
15
|
-
#include <map>
|
|
16
|
-
#include <utility>
|
|
17
|
-
#include <variant>
|
|
18
|
-
|
|
19
|
-
#if __has_include(<version>)
|
|
20
|
-
#include <version> // Needed for feature testing.
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
#ifdef __has_include
|
|
24
|
-
#if __has_include(<stdfloat>)
|
|
25
|
-
#include <stdfloat>
|
|
26
|
-
#endif
|
|
27
|
-
#if defined(__STDCPP_BFLOAT16_T__)
|
|
28
|
-
#define HAS_BFLOAT16 (1)
|
|
29
|
-
#else
|
|
30
|
-
#define HAS_BFLOAT16 (0)
|
|
31
|
-
#endif
|
|
32
|
-
|
|
33
|
-
#if defined(__STDCPP_FLOAT16_T__)
|
|
34
|
-
#define HAS_FLOAT16 (1)
|
|
35
|
-
#else
|
|
36
|
-
#define HAS_FLOAT16 (0)
|
|
37
|
-
#endif
|
|
38
|
-
#else
|
|
39
|
-
#define HAS_FLOAT16 (0)
|
|
40
|
-
#define HAS_BFLOAT16 (0)
|
|
41
|
-
#endif
|
|
42
|
-
|
|
43
|
-
constexpr std::endian target_byteorder() {
|
|
44
|
-
return std::endian::native;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
template<typename... Args>
|
|
48
|
-
constexpr void DBG_PRINTN(Args &&...args) noexcept {
|
|
49
|
-
((std::cout << std::forward<Args>(args) << " "), ...);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// NOTE: C++23 has std::byteswap()
|
|
53
|
-
constexpr auto _bswap(std::uint64_t v) noexcept {
|
|
54
|
-
return ((v & UINT64_C(0x0000'0000'0000'00FF)) << 56) | ((v & UINT64_C(0x0000'0000'0000'FF00)) << 40) |
|
|
55
|
-
((v & UINT64_C(0x0000'0000'00FF'0000)) << 24) | ((v & UINT64_C(0x0000'0000'FF00'0000)) << 8) |
|
|
56
|
-
((v & UINT64_C(0x0000'00FF'0000'0000)) >> 8) | ((v & UINT64_C(0x0000'FF00'0000'0000)) >> 24) |
|
|
57
|
-
((v & UINT64_C(0x00FF'0000'0000'0000)) >> 40) | ((v & UINT64_C(0xFF00'0000'0000'0000)) >> 56);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
constexpr auto _bswap(std::uint32_t v) noexcept {
|
|
61
|
-
return ((v & UINT32_C(0x0000'00FF)) << 24) | ((v & UINT32_C(0x0000'FF00)) << 8) | ((v & UINT32_C(0x00FF'0000)) >> 8) |
|
|
62
|
-
((v & UINT32_C(0xFF00'0000)) >> 24);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
constexpr auto _bswap(std::uint16_t v) noexcept {
|
|
66
|
-
return ((v & UINT16_C(0x00FF)) << 8) | ((v & UINT16_C(0xFF00)) >> 8);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
template<typename T>
|
|
70
|
-
inline std::string to_binary(const T &value) {
|
|
71
|
-
std::string result;
|
|
72
|
-
|
|
73
|
-
auto ptr = reinterpret_cast<const std::string::value_type *>(&value);
|
|
74
|
-
for (std::size_t idx = 0; idx < sizeof(T); ++idx) {
|
|
75
|
-
auto ch = ptr[idx];
|
|
76
|
-
result.push_back(ch);
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
template<>
|
|
82
|
-
inline std::string to_binary<std::string>(const std::string &value) {
|
|
83
|
-
std::string result;
|
|
84
|
-
|
|
85
|
-
auto ptr = reinterpret_cast<const std::string::value_type *>(value.c_str());
|
|
86
|
-
const std::size_t length = std::size(value);
|
|
87
|
-
|
|
88
|
-
// We are using Pascal strings as serialization format.
|
|
89
|
-
auto len_bin = to_binary(length);
|
|
90
|
-
std::copy(len_bin.begin(), len_bin.end(), std::back_inserter(result));
|
|
91
|
-
for (std::size_t idx = 0; idx < length; ++idx) {
|
|
92
|
-
auto ch = ptr[idx];
|
|
93
|
-
result.push_back(ch);
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
inline auto bool_to_string(bool value) {
|
|
99
|
-
return (value == true) ? "True" : "False";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
inline auto byte_order_to_string(int value) {
|
|
103
|
-
switch (value) {
|
|
104
|
-
case 0:
|
|
105
|
-
return "INTEL";
|
|
106
|
-
case 1:
|
|
107
|
-
return "MOTOROLA";
|
|
108
|
-
default:
|
|
109
|
-
return "<UNKNOWN>";
|
|
110
|
-
}
|
|
111
|
-
return "<UNKNOWN>";
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
template<typename K, typename V>
|
|
115
|
-
static std::map<V, K> reverse_map(const std::map<K, V> &m) {
|
|
116
|
-
std::map<V, K> result;
|
|
117
|
-
for (const auto &[k, v] : m) {
|
|
118
|
-
result[v] = k;
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
enum class TimestampType : std::uint8_t {
|
|
124
|
-
ABSOLUTE_TS,
|
|
125
|
-
RELATIVE_TS
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
class TimestampInfo {
|
|
129
|
-
public:
|
|
130
|
-
|
|
131
|
-
TimestampInfo(const TimestampInfo &) = default;
|
|
132
|
-
TimestampInfo(TimestampInfo &&) = default;
|
|
133
|
-
TimestampInfo &operator=(const TimestampInfo &) = default;
|
|
134
|
-
TimestampInfo &operator=(TimestampInfo &&) = default;
|
|
135
|
-
virtual ~TimestampInfo() {}
|
|
136
|
-
|
|
137
|
-
TimestampInfo() : m_timestamp_ns(0), m_timezone{}, m_utc_offset(0), m_dst_offset(0) {
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
TimestampInfo(std::uint64_t timestamp_ns, const std::string &timezone, std::int16_t utc_offset, std::int16_t dst_offset) :
|
|
141
|
-
m_timestamp_ns(timestamp_ns), m_timezone(timezone), m_utc_offset(utc_offset), m_dst_offset(dst_offset) {
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
explicit TimestampInfo(std::uint64_t timestamp_ns) : m_timestamp_ns(timestamp_ns) {
|
|
145
|
-
#if defined(_WIN32) || defined(_WIN64)
|
|
146
|
-
m_timezone = std::chrono::current_zone()->name();
|
|
147
|
-
#else
|
|
148
|
-
tzset();
|
|
149
|
-
m_timezone = tzname[0];
|
|
150
|
-
|
|
151
|
-
#endif // _WIN32 || _WIN64
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
std::string get_timezone() const noexcept {
|
|
155
|
-
return m_timezone;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
void set_timezone(const std::string &value) noexcept {
|
|
159
|
-
m_timezone = value;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
std::uint64_t get_timestamp_ns() const noexcept {
|
|
163
|
-
return m_timestamp_ns;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
void set_utc_offset(std::int16_t value) noexcept {
|
|
167
|
-
m_utc_offset = value;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
std::int16_t get_utc_offset() const noexcept {
|
|
171
|
-
return m_utc_offset;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
void set_dst_offset(std::int16_t value) noexcept {
|
|
175
|
-
m_dst_offset = value;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
std::int16_t get_dst_offset() const noexcept {
|
|
179
|
-
return m_dst_offset;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
std::string to_string() const noexcept {
|
|
183
|
-
std::stringstream ss;
|
|
184
|
-
ss << "TimestamInfo(\n";
|
|
185
|
-
ss << "\ttimestamp_ns=" << m_timestamp_ns << ",\n";
|
|
186
|
-
ss << "\ttimezone=\"" << m_timezone << "\",\n";
|
|
187
|
-
ss << "\tutc_offset=" << m_utc_offset << ",\n";
|
|
188
|
-
ss << "\tdst_offset=" << m_dst_offset << "\n";
|
|
189
|
-
ss << ");";
|
|
190
|
-
return ss.str();
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
virtual void dummy() const noexcept {};
|
|
194
|
-
|
|
195
|
-
private:
|
|
196
|
-
|
|
197
|
-
std::uint64_t m_timestamp_ns;
|
|
198
|
-
std::string m_timezone{};
|
|
199
|
-
std::int16_t m_utc_offset{ 0 };
|
|
200
|
-
std::int16_t m_dst_offset{ 0 };
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
class Timestamp {
|
|
204
|
-
public:
|
|
205
|
-
|
|
206
|
-
explicit Timestamp(TimestampType ts_type) : m_type(ts_type) {
|
|
207
|
-
m_initial = absolute();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
Timestamp(const Timestamp &) = default;
|
|
211
|
-
Timestamp(Timestamp &&) = default;
|
|
212
|
-
|
|
213
|
-
std::uint64_t get_value() const noexcept {
|
|
214
|
-
if (m_type == TimestampType::ABSOLUTE_TS) {
|
|
215
|
-
return absolute();
|
|
216
|
-
} else if (m_type == TimestampType::RELATIVE_TS) {
|
|
217
|
-
return relative();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
std::uint64_t get_initial_value() const noexcept {
|
|
222
|
-
return m_initial;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
std::uint64_t absolute() const noexcept {
|
|
226
|
-
std::uint64_t current;
|
|
227
|
-
|
|
228
|
-
#if defined(_WIN32) || defined(_WIN64)
|
|
229
|
-
current = std::chrono::duration_cast<std::chrono::nanoseconds>(m_clk.now().time_since_epoch()).count();
|
|
230
|
-
#else
|
|
231
|
-
// On MacOS `clock_gettime_nsec_np` could be used.
|
|
232
|
-
timespec ts;
|
|
233
|
-
clock_gettime(CLOCK_REALTIME, &ts);
|
|
234
|
-
current = static_cast<std::uint64_t>(ts.tv_sec) * 1'000'000'000 + ts.tv_nsec;
|
|
235
|
-
#endif // _WIN32 || _WIN64
|
|
236
|
-
return current;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
std::uint64_t relative() const noexcept {
|
|
240
|
-
return absolute() - m_initial;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
private:
|
|
244
|
-
|
|
245
|
-
TimestampType m_type;
|
|
246
|
-
#if defined(_WIN32) || defined(_WIN64)
|
|
247
|
-
std::chrono::utc_clock m_clk;
|
|
248
|
-
#else
|
|
249
|
-
|
|
250
|
-
#endif // _WIN32 || _WIN64
|
|
251
|
-
std::uint64_t m_initial;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
template<typename T, typename V>
|
|
255
|
-
T variant_get(V&& value) {
|
|
256
|
-
|
|
257
|
-
T result;
|
|
258
|
-
|
|
259
|
-
const T* value_ptr = std::get_if<T>(&value);
|
|
260
|
-
if (value_ptr == nullptr) {
|
|
261
|
-
result = T{};
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
result = *value_ptr;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return result;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
#if 0
|
|
271
|
-
inline void sleep_ms(std::uint64_t milliseconds) {
|
|
272
|
-
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
inline void sleep_ns(std::uint64_t nanoseconds) {
|
|
276
|
-
std::this_thread::sleep_for(std::chrono::nanoseconds(nanoseconds));
|
|
277
|
-
}
|
|
278
|
-
#endif
|
|
279
|
-
|
|
280
|
-
#endif // __HELPER_HPP
|
|
1
|
+
|
|
2
|
+
#if !defined(__HELPER_HPP)
|
|
3
|
+
#define __HELPER_HPP
|
|
4
|
+
|
|
5
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
6
|
+
|
|
7
|
+
#else
|
|
8
|
+
#include <sys/time.h>
|
|
9
|
+
#include <time.h>
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include <bit>
|
|
13
|
+
#include <chrono>
|
|
14
|
+
#include <iostream>
|
|
15
|
+
#include <map>
|
|
16
|
+
#include <utility>
|
|
17
|
+
#include <variant>
|
|
18
|
+
|
|
19
|
+
#if __has_include(<version>)
|
|
20
|
+
#include <version> // Needed for feature testing.
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
#ifdef __has_include
|
|
24
|
+
#if __has_include(<stdfloat>)
|
|
25
|
+
#include <stdfloat>
|
|
26
|
+
#endif
|
|
27
|
+
#if defined(__STDCPP_BFLOAT16_T__)
|
|
28
|
+
#define HAS_BFLOAT16 (1)
|
|
29
|
+
#else
|
|
30
|
+
#define HAS_BFLOAT16 (0)
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#if defined(__STDCPP_FLOAT16_T__)
|
|
34
|
+
#define HAS_FLOAT16 (1)
|
|
35
|
+
#else
|
|
36
|
+
#define HAS_FLOAT16 (0)
|
|
37
|
+
#endif
|
|
38
|
+
#else
|
|
39
|
+
#define HAS_FLOAT16 (0)
|
|
40
|
+
#define HAS_BFLOAT16 (0)
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
constexpr std::endian target_byteorder() {
|
|
44
|
+
return std::endian::native;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
template<typename... Args>
|
|
48
|
+
constexpr void DBG_PRINTN(Args &&...args) noexcept {
|
|
49
|
+
((std::cout << std::forward<Args>(args) << " "), ...);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// NOTE: C++23 has std::byteswap()
|
|
53
|
+
constexpr auto _bswap(std::uint64_t v) noexcept {
|
|
54
|
+
return ((v & UINT64_C(0x0000'0000'0000'00FF)) << 56) | ((v & UINT64_C(0x0000'0000'0000'FF00)) << 40) |
|
|
55
|
+
((v & UINT64_C(0x0000'0000'00FF'0000)) << 24) | ((v & UINT64_C(0x0000'0000'FF00'0000)) << 8) |
|
|
56
|
+
((v & UINT64_C(0x0000'00FF'0000'0000)) >> 8) | ((v & UINT64_C(0x0000'FF00'0000'0000)) >> 24) |
|
|
57
|
+
((v & UINT64_C(0x00FF'0000'0000'0000)) >> 40) | ((v & UINT64_C(0xFF00'0000'0000'0000)) >> 56);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
constexpr auto _bswap(std::uint32_t v) noexcept {
|
|
61
|
+
return ((v & UINT32_C(0x0000'00FF)) << 24) | ((v & UINT32_C(0x0000'FF00)) << 8) | ((v & UINT32_C(0x00FF'0000)) >> 8) |
|
|
62
|
+
((v & UINT32_C(0xFF00'0000)) >> 24);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
constexpr auto _bswap(std::uint16_t v) noexcept {
|
|
66
|
+
return ((v & UINT16_C(0x00FF)) << 8) | ((v & UINT16_C(0xFF00)) >> 8);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
template<typename T>
|
|
70
|
+
inline std::string to_binary(const T &value) {
|
|
71
|
+
std::string result;
|
|
72
|
+
|
|
73
|
+
auto ptr = reinterpret_cast<const std::string::value_type *>(&value);
|
|
74
|
+
for (std::size_t idx = 0; idx < sizeof(T); ++idx) {
|
|
75
|
+
auto ch = ptr[idx];
|
|
76
|
+
result.push_back(ch);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
template<>
|
|
82
|
+
inline std::string to_binary<std::string>(const std::string &value) {
|
|
83
|
+
std::string result;
|
|
84
|
+
|
|
85
|
+
auto ptr = reinterpret_cast<const std::string::value_type *>(value.c_str());
|
|
86
|
+
const std::size_t length = std::size(value);
|
|
87
|
+
|
|
88
|
+
// We are using Pascal strings as serialization format.
|
|
89
|
+
auto len_bin = to_binary(length);
|
|
90
|
+
std::copy(len_bin.begin(), len_bin.end(), std::back_inserter(result));
|
|
91
|
+
for (std::size_t idx = 0; idx < length; ++idx) {
|
|
92
|
+
auto ch = ptr[idx];
|
|
93
|
+
result.push_back(ch);
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
inline auto bool_to_string(bool value) {
|
|
99
|
+
return (value == true) ? "True" : "False";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
inline auto byte_order_to_string(int value) {
|
|
103
|
+
switch (value) {
|
|
104
|
+
case 0:
|
|
105
|
+
return "INTEL";
|
|
106
|
+
case 1:
|
|
107
|
+
return "MOTOROLA";
|
|
108
|
+
default:
|
|
109
|
+
return "<UNKNOWN>";
|
|
110
|
+
}
|
|
111
|
+
return "<UNKNOWN>";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
template<typename K, typename V>
|
|
115
|
+
static std::map<V, K> reverse_map(const std::map<K, V> &m) {
|
|
116
|
+
std::map<V, K> result;
|
|
117
|
+
for (const auto &[k, v] : m) {
|
|
118
|
+
result[v] = k;
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
enum class TimestampType : std::uint8_t {
|
|
124
|
+
ABSOLUTE_TS,
|
|
125
|
+
RELATIVE_TS
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
class TimestampInfo {
|
|
129
|
+
public:
|
|
130
|
+
|
|
131
|
+
TimestampInfo(const TimestampInfo &) = default;
|
|
132
|
+
TimestampInfo(TimestampInfo &&) = default;
|
|
133
|
+
TimestampInfo &operator=(const TimestampInfo &) = default;
|
|
134
|
+
TimestampInfo &operator=(TimestampInfo &&) = default;
|
|
135
|
+
virtual ~TimestampInfo() {}
|
|
136
|
+
|
|
137
|
+
TimestampInfo() : m_timestamp_ns(0), m_timezone{}, m_utc_offset(0), m_dst_offset(0) {
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
TimestampInfo(std::uint64_t timestamp_ns, const std::string &timezone, std::int16_t utc_offset, std::int16_t dst_offset) :
|
|
141
|
+
m_timestamp_ns(timestamp_ns), m_timezone(timezone), m_utc_offset(utc_offset), m_dst_offset(dst_offset) {
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
explicit TimestampInfo(std::uint64_t timestamp_ns) : m_timestamp_ns(timestamp_ns) {
|
|
145
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
146
|
+
m_timezone = std::chrono::current_zone()->name();
|
|
147
|
+
#else
|
|
148
|
+
tzset();
|
|
149
|
+
m_timezone = tzname[0];
|
|
150
|
+
|
|
151
|
+
#endif // _WIN32 || _WIN64
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
std::string get_timezone() const noexcept {
|
|
155
|
+
return m_timezone;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
void set_timezone(const std::string &value) noexcept {
|
|
159
|
+
m_timezone = value;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
std::uint64_t get_timestamp_ns() const noexcept {
|
|
163
|
+
return m_timestamp_ns;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
void set_utc_offset(std::int16_t value) noexcept {
|
|
167
|
+
m_utc_offset = value;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
std::int16_t get_utc_offset() const noexcept {
|
|
171
|
+
return m_utc_offset;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
void set_dst_offset(std::int16_t value) noexcept {
|
|
175
|
+
m_dst_offset = value;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
std::int16_t get_dst_offset() const noexcept {
|
|
179
|
+
return m_dst_offset;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
std::string to_string() const noexcept {
|
|
183
|
+
std::stringstream ss;
|
|
184
|
+
ss << "TimestamInfo(\n";
|
|
185
|
+
ss << "\ttimestamp_ns=" << m_timestamp_ns << ",\n";
|
|
186
|
+
ss << "\ttimezone=\"" << m_timezone << "\",\n";
|
|
187
|
+
ss << "\tutc_offset=" << m_utc_offset << ",\n";
|
|
188
|
+
ss << "\tdst_offset=" << m_dst_offset << "\n";
|
|
189
|
+
ss << ");";
|
|
190
|
+
return ss.str();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
virtual void dummy() const noexcept {};
|
|
194
|
+
|
|
195
|
+
private:
|
|
196
|
+
|
|
197
|
+
std::uint64_t m_timestamp_ns;
|
|
198
|
+
std::string m_timezone{};
|
|
199
|
+
std::int16_t m_utc_offset{ 0 };
|
|
200
|
+
std::int16_t m_dst_offset{ 0 };
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
class Timestamp {
|
|
204
|
+
public:
|
|
205
|
+
|
|
206
|
+
explicit Timestamp(TimestampType ts_type) : m_type(ts_type) {
|
|
207
|
+
m_initial = absolute();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
Timestamp(const Timestamp &) = default;
|
|
211
|
+
Timestamp(Timestamp &&) = default;
|
|
212
|
+
|
|
213
|
+
std::uint64_t get_value() const noexcept {
|
|
214
|
+
if (m_type == TimestampType::ABSOLUTE_TS) {
|
|
215
|
+
return absolute();
|
|
216
|
+
} else if (m_type == TimestampType::RELATIVE_TS) {
|
|
217
|
+
return relative();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
std::uint64_t get_initial_value() const noexcept {
|
|
222
|
+
return m_initial;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
std::uint64_t absolute() const noexcept {
|
|
226
|
+
std::uint64_t current;
|
|
227
|
+
|
|
228
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
229
|
+
current = std::chrono::duration_cast<std::chrono::nanoseconds>(m_clk.now().time_since_epoch()).count();
|
|
230
|
+
#else
|
|
231
|
+
// On MacOS `clock_gettime_nsec_np` could be used.
|
|
232
|
+
timespec ts;
|
|
233
|
+
clock_gettime(CLOCK_REALTIME, &ts);
|
|
234
|
+
current = static_cast<std::uint64_t>(ts.tv_sec) * 1'000'000'000 + ts.tv_nsec;
|
|
235
|
+
#endif // _WIN32 || _WIN64
|
|
236
|
+
return current;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
std::uint64_t relative() const noexcept {
|
|
240
|
+
return absolute() - m_initial;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private:
|
|
244
|
+
|
|
245
|
+
TimestampType m_type;
|
|
246
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
247
|
+
std::chrono::utc_clock m_clk;
|
|
248
|
+
#else
|
|
249
|
+
|
|
250
|
+
#endif // _WIN32 || _WIN64
|
|
251
|
+
std::uint64_t m_initial;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
template<typename T, typename V>
|
|
255
|
+
T variant_get(V&& value) {
|
|
256
|
+
|
|
257
|
+
T result;
|
|
258
|
+
|
|
259
|
+
const T* value_ptr = std::get_if<T>(&value);
|
|
260
|
+
if (value_ptr == nullptr) {
|
|
261
|
+
result = T{};
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
result = *value_ptr;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
#if 0
|
|
271
|
+
inline void sleep_ms(std::uint64_t milliseconds) {
|
|
272
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
inline void sleep_ns(std::uint64_t nanoseconds) {
|
|
276
|
+
std::this_thread::sleep_for(std::chrono::nanoseconds(nanoseconds));
|
|
277
|
+
}
|
|
278
|
+
#endif
|
|
279
|
+
|
|
280
|
+
#endif // __HELPER_HPP
|