pyxcp 0.23.0__cp313-cp313-win_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.

Potentially problematic release.


This version of pyxcp might be problematic. Click here for more details.

Files changed (134) hide show
  1. pyxcp/__init__.py +20 -0
  2. pyxcp/aml/EtasCANMonitoring.a2l +82 -0
  3. pyxcp/aml/EtasCANMonitoring.aml +67 -0
  4. pyxcp/aml/XCP_Common.aml +408 -0
  5. pyxcp/aml/XCPonCAN.aml +78 -0
  6. pyxcp/aml/XCPonEth.aml +33 -0
  7. pyxcp/aml/XCPonFlx.aml +113 -0
  8. pyxcp/aml/XCPonSxI.aml +66 -0
  9. pyxcp/aml/XCPonUSB.aml +106 -0
  10. pyxcp/aml/ifdata_CAN.a2l +20 -0
  11. pyxcp/aml/ifdata_Eth.a2l +11 -0
  12. pyxcp/aml/ifdata_Flx.a2l +94 -0
  13. pyxcp/aml/ifdata_SxI.a2l +13 -0
  14. pyxcp/aml/ifdata_USB.a2l +81 -0
  15. pyxcp/asam/__init__.py +0 -0
  16. pyxcp/asam/types.py +131 -0
  17. pyxcp/asamkeydll.c +116 -0
  18. pyxcp/asamkeydll.sh +2 -0
  19. pyxcp/checksum.py +732 -0
  20. pyxcp/cmdline.py +52 -0
  21. pyxcp/config/__init__.py +1113 -0
  22. pyxcp/config/legacy.py +120 -0
  23. pyxcp/constants.py +47 -0
  24. pyxcp/cpp_ext/__init__.py +0 -0
  25. pyxcp/cpp_ext/bin.hpp +104 -0
  26. pyxcp/cpp_ext/blockmem.hpp +58 -0
  27. pyxcp/cpp_ext/cpp_ext.cp310-win_arm64.pyd +0 -0
  28. pyxcp/cpp_ext/cpp_ext.cp311-win_arm64.pyd +0 -0
  29. pyxcp/cpp_ext/cpp_ext.cp312-win_arm64.pyd +0 -0
  30. pyxcp/cpp_ext/cpp_ext.cp313-win_arm64.pyd +0 -0
  31. pyxcp/cpp_ext/daqlist.hpp +206 -0
  32. pyxcp/cpp_ext/event.hpp +67 -0
  33. pyxcp/cpp_ext/extension_wrapper.cpp +100 -0
  34. pyxcp/cpp_ext/helper.hpp +280 -0
  35. pyxcp/cpp_ext/mcobject.hpp +246 -0
  36. pyxcp/cpp_ext/tsqueue.hpp +46 -0
  37. pyxcp/daq_stim/__init__.py +232 -0
  38. pyxcp/daq_stim/optimize/__init__.py +67 -0
  39. pyxcp/daq_stim/optimize/binpacking.py +41 -0
  40. pyxcp/daq_stim/scheduler.cpp +62 -0
  41. pyxcp/daq_stim/scheduler.hpp +75 -0
  42. pyxcp/daq_stim/stim.cp310-win_arm64.pyd +0 -0
  43. pyxcp/daq_stim/stim.cp311-win_arm64.pyd +0 -0
  44. pyxcp/daq_stim/stim.cp312-win_arm64.pyd +0 -0
  45. pyxcp/daq_stim/stim.cp313-win_arm64.pyd +0 -0
  46. pyxcp/daq_stim/stim.cpp +13 -0
  47. pyxcp/daq_stim/stim.hpp +604 -0
  48. pyxcp/daq_stim/stim_wrapper.cpp +50 -0
  49. pyxcp/dllif.py +100 -0
  50. pyxcp/errormatrix.py +878 -0
  51. pyxcp/examples/conf_can.toml +19 -0
  52. pyxcp/examples/conf_can_user.toml +16 -0
  53. pyxcp/examples/conf_can_vector.json +11 -0
  54. pyxcp/examples/conf_can_vector.toml +11 -0
  55. pyxcp/examples/conf_eth.toml +9 -0
  56. pyxcp/examples/conf_nixnet.json +20 -0
  57. pyxcp/examples/conf_socket_can.toml +12 -0
  58. pyxcp/examples/conf_sxi.json +9 -0
  59. pyxcp/examples/conf_sxi.toml +7 -0
  60. pyxcp/examples/run_daq.py +163 -0
  61. pyxcp/examples/xcp_policy.py +60 -0
  62. pyxcp/examples/xcp_read_benchmark.py +38 -0
  63. pyxcp/examples/xcp_skel.py +49 -0
  64. pyxcp/examples/xcp_unlock.py +38 -0
  65. pyxcp/examples/xcp_user_supplied_driver.py +44 -0
  66. pyxcp/examples/xcphello.py +78 -0
  67. pyxcp/examples/xcphello_recorder.py +107 -0
  68. pyxcp/master/__init__.py +9 -0
  69. pyxcp/master/errorhandler.py +442 -0
  70. pyxcp/master/master.py +2047 -0
  71. pyxcp/py.typed +0 -0
  72. pyxcp/recorder/__init__.py +101 -0
  73. pyxcp/recorder/build_clang.cmd +1 -0
  74. pyxcp/recorder/build_clang.sh +2 -0
  75. pyxcp/recorder/build_gcc.cmd +1 -0
  76. pyxcp/recorder/build_gcc.sh +2 -0
  77. pyxcp/recorder/build_gcc_arm.sh +2 -0
  78. pyxcp/recorder/converter/__init__.py +450 -0
  79. pyxcp/recorder/lz4.c +2829 -0
  80. pyxcp/recorder/lz4.h +879 -0
  81. pyxcp/recorder/lz4hc.c +2041 -0
  82. pyxcp/recorder/lz4hc.h +413 -0
  83. pyxcp/recorder/mio.hpp +1714 -0
  84. pyxcp/recorder/reader.hpp +139 -0
  85. pyxcp/recorder/reco.py +277 -0
  86. pyxcp/recorder/recorder.rst +0 -0
  87. pyxcp/recorder/rekorder.cp310-win_arm64.pyd +0 -0
  88. pyxcp/recorder/rekorder.cp311-win_arm64.pyd +0 -0
  89. pyxcp/recorder/rekorder.cp312-win_arm64.pyd +0 -0
  90. pyxcp/recorder/rekorder.cp313-win_arm64.pyd +0 -0
  91. pyxcp/recorder/rekorder.cpp +59 -0
  92. pyxcp/recorder/rekorder.hpp +274 -0
  93. pyxcp/recorder/setup.py +41 -0
  94. pyxcp/recorder/test_reko.py +34 -0
  95. pyxcp/recorder/unfolder.hpp +1332 -0
  96. pyxcp/recorder/wrap.cpp +189 -0
  97. pyxcp/recorder/writer.hpp +302 -0
  98. pyxcp/scripts/__init__.py +0 -0
  99. pyxcp/scripts/pyxcp_probe_can_drivers.py +20 -0
  100. pyxcp/scripts/xcp_examples.py +64 -0
  101. pyxcp/scripts/xcp_fetch_a2l.py +40 -0
  102. pyxcp/scripts/xcp_id_scanner.py +19 -0
  103. pyxcp/scripts/xcp_info.py +144 -0
  104. pyxcp/scripts/xcp_profile.py +27 -0
  105. pyxcp/scripts/xmraw_converter.py +31 -0
  106. pyxcp/stim/__init__.py +0 -0
  107. pyxcp/tests/test_asam_types.py +24 -0
  108. pyxcp/tests/test_binpacking.py +186 -0
  109. pyxcp/tests/test_can.py +1324 -0
  110. pyxcp/tests/test_checksum.py +95 -0
  111. pyxcp/tests/test_daq.py +193 -0
  112. pyxcp/tests/test_daq_opt.py +426 -0
  113. pyxcp/tests/test_frame_padding.py +156 -0
  114. pyxcp/tests/test_master.py +2006 -0
  115. pyxcp/tests/test_transport.py +81 -0
  116. pyxcp/tests/test_utils.py +30 -0
  117. pyxcp/timing.py +60 -0
  118. pyxcp/transport/__init__.py +10 -0
  119. pyxcp/transport/base.py +440 -0
  120. pyxcp/transport/base_transport.hpp +0 -0
  121. pyxcp/transport/can.py +556 -0
  122. pyxcp/transport/eth.py +219 -0
  123. pyxcp/transport/sxi.py +135 -0
  124. pyxcp/transport/transport_wrapper.cpp +0 -0
  125. pyxcp/transport/usb_transport.py +213 -0
  126. pyxcp/types.py +1000 -0
  127. pyxcp/utils.py +128 -0
  128. pyxcp/vector/__init__.py +0 -0
  129. pyxcp/vector/map.py +82 -0
  130. pyxcp-0.23.0.dist-info/LICENSE +165 -0
  131. pyxcp-0.23.0.dist-info/METADATA +107 -0
  132. pyxcp-0.23.0.dist-info/RECORD +134 -0
  133. pyxcp-0.23.0.dist-info/WHEEL +4 -0
  134. pyxcp-0.23.0.dist-info/entry_points.txt +9 -0
pyxcp/config/legacy.py ADDED
@@ -0,0 +1,120 @@
1
+ from collections import defaultdict
2
+
3
+ from traitlets.config import LoggingConfigurable
4
+ from traitlets.config.loader import Config
5
+
6
+
7
+ LEGACY_KEYWORDS = {
8
+ # General
9
+ "LOGLEVEL": "General.loglevel",
10
+ "DISABLE_ERROR_HANDLING": "General.disable_error_handling",
11
+ "SEED_N_KEY_DLL": "General.seed_n_key_dll",
12
+ "SEED_N_KEY_DLL_SAME_BIT_WIDTH": "General.seed_n_key_dll_same_bit_width",
13
+ "DISCONNECT_RESPONSE_OPTIONAL": "General.disconnect_response_optional",
14
+ # Transport
15
+ "TRANSPORT": "Transport.layer",
16
+ "CREATE_DAQ_TIMESTAMPS": "Transport.create_daq_timestamps",
17
+ "TIMEOUT": "Transport.timeout",
18
+ "ALIGNMENT": "Transport.alignment",
19
+ # Eth
20
+ "HOST": "Transport.Eth.host",
21
+ "PORT": "Transport.Eth.port",
22
+ "PROTOCOL": "Transport.Eth.protocol",
23
+ "IPV6": "Transport.Eth.ipv6",
24
+ "TCP_NODELAY": "Transport.Eth.tcp_nodelay",
25
+ # Usb
26
+ "SERIAL_NUMBER": "Transport.Usb.serial_number",
27
+ "CONFIGURATION_NUMBER": "Transport.Usb.configuration_number",
28
+ "INTERFACE_NUMBER": "Transport.Usb.interface_number",
29
+ "COMMAND_ENDPOINT_NUMBER": "Transport.Usb.out_ep_number",
30
+ "REPLY_ENDPOINT_NUMBER": "Transport.Usb.in_ep_number",
31
+ "VENDOR_ID": "Transport.Usb.vendor_id",
32
+ "PRODUCT_ID": "Transport.Usb.product_id",
33
+ "LIBRARY": "Transport.Usb.library",
34
+ # Can
35
+ "CAN_DRIVER": "Transport.Can.interface",
36
+ "CHANNEL": "Transport.Can.channel",
37
+ "MAX_DLC_REQUIRED": "Transport.Can.max_dlc_required",
38
+ # "MAX_CAN_FD_DLC": "Transport.Can.max_can_fd_dlc",
39
+ "PADDING_VALUE": "Transport.Can.padding_value",
40
+ "CAN_USE_DEFAULT_LISTENER": "Transport.Can.use_default_listener",
41
+ # Swap master and slave IDs. (s. https://github.com/christoph2/pyxcp/issues/130)
42
+ "CAN_ID_SLAVE": "Transport.Can.can_id_master",
43
+ "CAN_ID_MASTER": "Transport.Can.can_id_slave",
44
+ "CAN_ID_BROADCAST": "Transport.Can.can_id_broadcast",
45
+ "BITRATE": "Transport.Can.bitrate",
46
+ "RECEIVE_OWN_MESSAGES": "Transport.Can.receive_own_messages",
47
+ "POLL_INTERVAL": "Transport.Can.poll_interval",
48
+ "FD": "Transport.Can.fd",
49
+ "DATA_BITRATE": "Transport.Can.data_bitrate",
50
+ "ACCEPT_VIRTUAL": "Transport.Can.Kvaser.accept_virtual",
51
+ "SJW": "Transport.Can.sjw_abr",
52
+ "TSEG1": "Transport.Can.tseg1_abr",
53
+ "TSEG2": "Transport.Can.tseg2_abr",
54
+ "TTY_BAUDRATE": "Transport.Can.SlCan.ttyBaudrate",
55
+ "UNIQUE_HARDWARE_ID": "Transport.Can.Ixxat.unique_hardware_id",
56
+ "RX_FIFO_SIZE": "Transport.Can.Ixxat.rx_fifo_size",
57
+ "TX_FIFO_SIZE": "Transport.Can.Ixxat.tx_fifo_size",
58
+ "DRIVER_MODE": "Transport.Can.Kvaser.driver_mode",
59
+ "NO_SAMP": "Transport.Can.Kvaser.no_samp",
60
+ "SINGLE_HANDLE": "Transport.Can.Kvaser.single_handle",
61
+ "USE_SYSTEM_TIMESTAMP": "Transport.Can.Neovi.use_system_timestamp",
62
+ "OVERRIDE_LIBRARY_NAME": "Transport.Can.Neovi.override_library_name",
63
+ "BAUDRATE": "Transport.Can.Serial.baudrate",
64
+ "SLEEP_AFTER_OPEN": "Transport.Can.SlCan.sleep_after_open",
65
+ "DEVICE_NUMBER": "Transport.Can.Systec.device_number",
66
+ "RX_BUFFER_ENTRIES": "Transport.Can.Systec.rx_buffer_entries",
67
+ "TX_BUFFER_ENTRIES": "Transport.Can.Systec.tx_buffer_entries",
68
+ "FLAGS": "Transport.Can.Usb2Can.flags",
69
+ "APP_NAME": "Transport.Can.Vector.app_name",
70
+ "RX_QUEUE_SIZE": "Transport.Can.Vector.rx_queue_size",
71
+ }
72
+
73
+
74
+ def nested_dict_update(d: dict, key: str, value) -> None:
75
+ root, *path, key = key.split(".")
76
+ sub_dict = d[root]
77
+ for part in path:
78
+ if part not in sub_dict:
79
+ sub_dict[part] = defaultdict(dict)
80
+ sub_dict = sub_dict[part]
81
+ sub_dict[key] = value
82
+
83
+
84
+ def convert_config(legacy_config: dict, logger: LoggingConfigurable) -> Config:
85
+ interface_name = None
86
+ resolv = []
87
+ d = defaultdict(dict)
88
+ for key, value in legacy_config.items():
89
+ key = key.upper()
90
+ item = LEGACY_KEYWORDS.get(key)
91
+ if item is None:
92
+ logger.warning(f"Unknown keyword {key!r} in config file")
93
+ continue
94
+ if key == "CAN_DRIVER":
95
+ value = value.lower()
96
+ interface_name = value
97
+ if key in ("SERIAL", "LOG_ERRORS", "STATE", "RTSCTS"):
98
+ resolv.append((key, value))
99
+ else:
100
+ nested_dict_update(d=d, key=item, value=value)
101
+ for key, value in resolv:
102
+ if key == "SERIAL":
103
+ if interface_name == "neovi":
104
+ d["Transport.Can.Neovi.serial"] = value
105
+ elif interface_name == "vector":
106
+ d["Transport.Can.Vector.serial"] = value
107
+ elif key == "LOG_ERRORS":
108
+ if interface_name == "nican":
109
+ d["Transport.Can.NiCan.log_errors"] = value
110
+ elif key == "STATE":
111
+ if interface_name == "pcan":
112
+ d["Transport.Can.PCan.state"] = value
113
+ elif interface_name == "systec":
114
+ d["Transport.Can.Systec.state"] = value
115
+ elif key == "RTSCTS":
116
+ if interface_name == "serial":
117
+ d["Transport.Can.Serial.rtscts"] = value
118
+ elif interface_name == "slcan":
119
+ d["Transport.Can.SlCan.rtscts"] = value
120
+ return Config(d)
pyxcp/constants.py ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env python
2
+ import struct
3
+ from typing import Any, Callable
4
+
5
+
6
+ PackerType = Callable[[int], bytes]
7
+ UnpackerType = Callable[[bytes], tuple[Any, ...]]
8
+
9
+
10
+ def makeBytePacker(byteorder: str = "@") -> PackerType:
11
+ """"""
12
+ return struct.Struct(f"{byteorder}B").pack
13
+
14
+
15
+ def makeByteUnpacker(byteorder: str = "@") -> UnpackerType:
16
+ """"""
17
+ return struct.Struct(f"{byteorder}B").unpack
18
+
19
+
20
+ def makeWordPacker(byteorder: str = "@") -> PackerType:
21
+ """"""
22
+ return struct.Struct(f"{byteorder}H").pack
23
+
24
+
25
+ def makeWordUnpacker(byteorder: str = "@") -> UnpackerType:
26
+ """"""
27
+ return struct.Struct(f"{byteorder}H").unpack
28
+
29
+
30
+ def makeDWordPacker(byteorder: str = "@") -> PackerType:
31
+ """"""
32
+ return struct.Struct(f"{byteorder}I").pack
33
+
34
+
35
+ def makeDWordUnpacker(byteorder: str = "@") -> UnpackerType:
36
+ """"""
37
+ return struct.Struct(f"{byteorder}I").unpack
38
+
39
+
40
+ def makeDLongPacker(byteorder: str = "@") -> PackerType:
41
+ """"""
42
+ return struct.Struct(f"{byteorder}Q").pack
43
+
44
+
45
+ def makeDLongUnpacker(byteorder: str = "@") -> UnpackerType:
46
+ """"""
47
+ return struct.Struct(f"{byteorder}Q").unpack
File without changes
pyxcp/cpp_ext/bin.hpp ADDED
@@ -0,0 +1,104 @@
1
+
2
+ #if !defined(__BIN_HPP)
3
+ #define __BIN_HPP
4
+
5
+ #include <cstdint>
6
+ #include <iostream>
7
+ #include <map>
8
+ #include <optional>
9
+ #include <string>
10
+ #include <vector>
11
+
12
+ #include "mcobject.hpp"
13
+
14
+ class Bin {
15
+ public:
16
+
17
+ Bin(std::uint16_t size) : m_size(size), m_residual_capacity(size) {
18
+ }
19
+
20
+ Bin(std::uint16_t size, uint16_t residual_capacity, const std::vector<McObject>& entries) :
21
+ m_size(size), m_residual_capacity(residual_capacity), m_entries(entries) {
22
+ }
23
+
24
+ void append(const McObject& bin) {
25
+ m_entries.emplace_back(bin);
26
+ }
27
+
28
+ void set_entries(std::vector<McObject>&& entries) {
29
+ m_entries = std::move(entries);
30
+ }
31
+
32
+ std::uint16_t get_size() const {
33
+ return m_size;
34
+ }
35
+
36
+ void set_size(const std::uint16_t size) {
37
+ m_size = size;
38
+ }
39
+
40
+ std::uint16_t get_residual_capacity() const {
41
+ return m_residual_capacity;
42
+ }
43
+
44
+ void set_residual_capacity(const std::uint16_t residual_capacity) {
45
+ m_residual_capacity = residual_capacity;
46
+ }
47
+
48
+ const std::vector<McObject>& get_entries() const {
49
+ return m_entries;
50
+ }
51
+
52
+ bool operator==(const Bin& other) const {
53
+ return (m_size == other.m_size) && (m_residual_capacity == other.m_residual_capacity) && (m_entries == other.m_entries);
54
+ }
55
+
56
+ std::string dumps() const {
57
+ std::stringstream ss;
58
+
59
+ ss << to_binary(m_size);
60
+ ss << to_binary(m_residual_capacity);
61
+
62
+ std::size_t entries_size = m_entries.size();
63
+ ss << to_binary(entries_size);
64
+ for (const auto& entry : m_entries) {
65
+ ss << entry.dumps();
66
+ }
67
+
68
+ return ss.str();
69
+ }
70
+
71
+ private:
72
+
73
+ std::uint16_t m_size;
74
+ std::uint16_t m_residual_capacity;
75
+ std::vector<McObject> m_entries{};
76
+ };
77
+
78
+ std::string bin_entries_to_string(const std::vector<McObject>& entries);
79
+
80
+ std::string to_string(const Bin& obj) {
81
+ std::stringstream ss;
82
+
83
+ ss << "Bin(residual_capacity=" << obj.get_residual_capacity() << ", entries=[" << bin_entries_to_string(obj.get_entries())
84
+ << "])";
85
+ return ss.str();
86
+ }
87
+
88
+ std::string bin_entries_to_string(const std::vector<McObject>& entries) {
89
+ std::stringstream ss;
90
+
91
+ for (const auto& entry : entries) {
92
+ ss << to_string(entry) << ",\n ";
93
+ }
94
+ return ss.str();
95
+ }
96
+
97
+ #if 0
98
+
99
+ @property
100
+ def __len__(self) -> int:
101
+ return len(self.entries)
102
+ #endif
103
+
104
+ #endif // __BIN_HPP
@@ -0,0 +1,58 @@
1
+
2
+ #ifndef __BLOCKMEM_HPP
3
+ #define __BLOCKMEM_HPP
4
+
5
+ #include <array>
6
+ #include <cstdint>
7
+ #include <mutex>
8
+
9
+ /*
10
+ *
11
+ * Super simplicistic block memory manager.
12
+ *
13
+ */
14
+ template<typename T, int _IS, int _NB>
15
+ class BlockMemory {
16
+ public:
17
+
18
+ using mem_block_t = std::array<T, _IS>;
19
+
20
+ constexpr explicit BlockMemory() noexcept : m_memory{ nullptr }, m_allocation_count{ 0 } {
21
+ m_memory = new T[_IS * _NB];
22
+ }
23
+
24
+ ~BlockMemory() noexcept {
25
+ if (m_memory) {
26
+ delete[] m_memory;
27
+ }
28
+ }
29
+
30
+ BlockMemory(const BlockMemory&) = delete;
31
+
32
+ constexpr T* acquire() noexcept {
33
+ const std::scoped_lock lock(m_mtx);
34
+
35
+ if (m_allocation_count >= _NB) {
36
+ return nullptr;
37
+ }
38
+ T* ptr = reinterpret_cast<T*>(m_memory + (m_allocation_count * _IS));
39
+ m_allocation_count++;
40
+ return ptr;
41
+ }
42
+
43
+ constexpr void release() noexcept {
44
+ const std::scoped_lock lock(m_mtx);
45
+ if (m_allocation_count == 0) {
46
+ return;
47
+ }
48
+ m_allocation_count--;
49
+ }
50
+
51
+ private:
52
+
53
+ T* m_memory;
54
+ std::uint32_t m_allocation_count;
55
+ std::mutex m_mtx;
56
+ };
57
+
58
+ #endif // __BLOCKMEM_HPP
@@ -0,0 +1,206 @@
1
+
2
+ #if !defined(__DAQ_LIST_HPP)
3
+ #define __DAQ_LIST_HPP
4
+
5
+ #include "bin.hpp"
6
+ #include "helper.hpp"
7
+ #include "mcobject.hpp"
8
+
9
+ using flatten_odts_t = std::vector<std::vector<std::tuple<std::string, std::uint32_t, std::uint8_t, std::uint16_t, std::int16_t>>>;
10
+
11
+ class DaqList {
12
+ public:
13
+
14
+ using daq_list_initialzer_t = std::tuple<std::string, std::uint32_t, std::uint16_t, std::string>;
15
+
16
+ DaqList(
17
+ std::string_view meas_name, std::uint16_t event_num, bool stim, bool enable_timestamps,
18
+ const std::vector<daq_list_initialzer_t>& measurements, std::uint8_t priority=0x00, std::uint8_t prescaler=0x01
19
+ ) :
20
+ m_name(meas_name), m_event_num(event_num), m_priority(priority), m_prescaler(prescaler), m_stim(stim), m_enable_timestamps(enable_timestamps) {
21
+ for (const auto& measurement : measurements) {
22
+ auto const& [name, address, ext, dt_name] = measurement;
23
+ m_measurements.emplace_back(McObject(name, address, static_cast<std::uint8_t>(ext), 0, dt_name));
24
+ }
25
+ }
26
+
27
+ bool get_enable_timestamps() const {
28
+ return m_enable_timestamps;
29
+ }
30
+
31
+ const std::string& get_name() const {
32
+ return m_name;
33
+ }
34
+
35
+ std::uint16_t get_event_num() const {
36
+ return m_event_num;
37
+ }
38
+
39
+ std::uint8_t get_priority() const {
40
+ return m_priority;
41
+ }
42
+
43
+ std::uint8_t get_prescaler() const {
44
+ return m_prescaler;
45
+ }
46
+
47
+ void set_event_num(std::uint16_t event_num) {
48
+ m_event_num = event_num;
49
+ }
50
+
51
+ bool get_stim() const {
52
+ return m_stim;
53
+ }
54
+
55
+ const std::vector<McObject>& get_measurements() const {
56
+ return m_measurements;
57
+ }
58
+
59
+ const std::vector<Bin>& get_measurements_opt() const {
60
+ return m_measurements_opt;
61
+ }
62
+
63
+ const std::vector<std::string>& get_header_names() const {
64
+ return m_header_names;
65
+ }
66
+
67
+ const std::vector<std::tuple<std::string, std::string>>& get_headers() const noexcept {
68
+ return m_headers;
69
+ }
70
+
71
+ std::uint16_t get_odt_count() const {
72
+ return m_odt_count;
73
+ }
74
+
75
+ std::uint16_t get_total_entries() const {
76
+ return m_total_entries;
77
+ }
78
+
79
+ std::uint16_t get_total_length() const {
80
+ return m_total_length;
81
+ }
82
+
83
+ const flatten_odts_t& get_flatten_odts() const {
84
+ return m_flatten_odts;
85
+ }
86
+
87
+ void set_measurements_opt(const std::vector<Bin>& measurements_opt) {
88
+ m_measurements_opt = measurements_opt;
89
+ auto odt_count = 0u;
90
+ auto total_entries = 0u;
91
+ auto total_length = 0u;
92
+ for (const auto& bin : measurements_opt) {
93
+ odt_count++;
94
+ std::vector<std::tuple<std::string, std::uint32_t, std::uint8_t, std::uint16_t, std::int16_t>> flatten_odt{};
95
+ for (const auto& mc_obj : bin.get_entries()) {
96
+ for (const auto& component : mc_obj.get_components()) {
97
+ m_header_names.emplace_back(component.get_name());
98
+ flatten_odt.emplace_back(
99
+ component.get_name(), component.get_address(), component.get_ext(), component.get_length(),
100
+ component.get_type_index()
101
+ );
102
+ m_headers.emplace_back(component.get_name(), TYPE_MAP_REV.at(component.get_type_index()));
103
+ total_entries++;
104
+ total_length += component.get_length();
105
+ }
106
+ }
107
+ m_flatten_odts.emplace_back(flatten_odt);
108
+ }
109
+ m_odt_count = odt_count;
110
+ m_total_entries = total_entries;
111
+ m_total_length = total_length;
112
+ }
113
+
114
+ std::string dumps() const {
115
+ std::stringstream ss;
116
+
117
+ ss << to_binary(m_name);
118
+ ss << to_binary(m_event_num);
119
+ ss << to_binary(m_stim);
120
+ ss << to_binary(m_enable_timestamps);
121
+
122
+ ss << to_binary(m_odt_count);
123
+ ss << to_binary(m_total_entries);
124
+ ss << to_binary(m_total_length);
125
+
126
+ std::size_t meas_size = m_measurements.size();
127
+ ss << to_binary(meas_size);
128
+ for (const auto& mc_obj : m_measurements) {
129
+ ss << mc_obj.dumps();
130
+ }
131
+ std::size_t meas_opt_size = m_measurements_opt.size();
132
+ ss << to_binary(meas_opt_size);
133
+ for (const auto& mc_obj : m_measurements_opt) {
134
+ ss << mc_obj.dumps();
135
+ }
136
+ std::size_t hname_size = m_header_names.size();
137
+ ss << to_binary(hname_size);
138
+ for (const auto& hdr_obj : m_header_names) {
139
+ ss << to_binary(hdr_obj);
140
+ }
141
+ /////
142
+ std::size_t odt_size = m_flatten_odts.size();
143
+ ss << to_binary(odt_size);
144
+ for (const auto& odt : m_flatten_odts) {
145
+ ss << to_binary(odt.size());
146
+ for (const auto& odt_entry : odt) {
147
+ const auto& [name, address, ext, size, type_index] = odt_entry;
148
+ ss << to_binary(name);
149
+ ss << to_binary(address);
150
+ ss << to_binary(ext);
151
+ ss << to_binary(size);
152
+ ss << to_binary(type_index);
153
+ }
154
+ }
155
+ return ss.str();
156
+ }
157
+
158
+ std::string to_string() const {
159
+ std::stringstream ss;
160
+
161
+ ss << "DaqList(";
162
+ ss << "name=\"" << m_name << "\", ";
163
+ ss << "event_num=" << static_cast<std::uint16_t>(m_event_num) << ", ";
164
+ ss << "stim=" << bool_to_string(m_stim) << ", ";
165
+ ss << "enable_timestamps" << bool_to_string(m_enable_timestamps) << ", ";
166
+ ss << "measurements=[\n";
167
+ for (const auto& meas : m_measurements) {
168
+ ss << ::to_string(meas) << ",\n";
169
+ }
170
+ ss << "],\n";
171
+ ss << "measurements_opt=[\n";
172
+ for (const auto& meas : m_measurements_opt) {
173
+ ss << ::to_string(meas) << ",\n";
174
+ }
175
+ ss << "],\n";
176
+ ss << "header_names=[\n";
177
+ for (const auto& header : m_header_names) {
178
+ ss << "\"" << header << "\",";
179
+ }
180
+ ss << "\n]";
181
+ ss << ")";
182
+ return ss.str();
183
+ }
184
+
185
+ static void loads(std::string_view buffer) {
186
+ }
187
+
188
+ private:
189
+
190
+ std::string m_name;
191
+ std::uint16_t m_event_num;
192
+ std::uint8_t m_priority;
193
+ std::uint8_t m_prescaler;
194
+ bool m_stim;
195
+ bool m_enable_timestamps;
196
+ std::vector<McObject> m_measurements;
197
+ std::vector<Bin> m_measurements_opt;
198
+ std::vector<std::string> m_header_names;
199
+ std::vector<std::tuple<std::string, std::string>> m_headers;
200
+ std::uint16_t m_odt_count;
201
+ std::uint16_t m_total_entries;
202
+ std::uint16_t m_total_length;
203
+ flatten_odts_t m_flatten_odts;
204
+ };
205
+
206
+ #endif // __DAQ_LIST_HPP
@@ -0,0 +1,67 @@
1
+
2
+ #ifndef __EVENT_HPP
3
+ #define __EVENT_HPP
4
+
5
+ #include <atomic>
6
+ #include <condition_variable>
7
+ #include <mutex>
8
+
9
+ class Event {
10
+ public:
11
+
12
+ Event(const Event& other) noexcept {
13
+ std::scoped_lock lock(other.m_mtx);
14
+ m_flag = other.m_flag;
15
+ }
16
+
17
+ ~Event() = default;
18
+ Event() = default;
19
+
20
+ void signal() noexcept {
21
+ std::scoped_lock lock(m_mtx);
22
+ m_flag = true;
23
+ m_cond.notify_one();
24
+ }
25
+
26
+ void wait() noexcept {
27
+ std::unique_lock lock(m_mtx);
28
+ m_cond.wait(lock, [this] { return m_flag; });
29
+ m_flag = false;
30
+ }
31
+
32
+ bool state() const noexcept {
33
+ std::scoped_lock lock(m_mtx);
34
+ return m_flag;
35
+ }
36
+
37
+ private:
38
+
39
+ mutable std::mutex m_mtx{};
40
+ bool m_flag{ false };
41
+ std::condition_variable m_cond{};
42
+ };
43
+
44
+ #if 0
45
+ class Spinlock {
46
+ public:
47
+
48
+ Spinlock() : m_flag(ATOMIC_FLAG_INIT) {
49
+ }
50
+
51
+ ~Spinlock() = default;
52
+
53
+ void lock() {
54
+ while (m_flag.test_and_set()) {
55
+ }
56
+ }
57
+
58
+ void unlock() {
59
+ m_flag.clear();
60
+ }
61
+
62
+ private:
63
+ std::atomic_flag m_flag;
64
+ };
65
+ #endif
66
+
67
+ #endif // __EVENT_HPP