robotpy-native-telemetry 2027.0.0a7__py3-none-win_amd64.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.
@@ -0,0 +1,22 @@
1
+ # This file is automatically generated, DO NOT EDIT
2
+ # fmt: off
3
+
4
+ import native.wpiutil._init_robotpy_native_wpiutil
5
+
6
+ def __load_library():
7
+ from os.path import abspath, join, dirname, exists
8
+ from ctypes import cdll
9
+
10
+ root = abspath(dirname(__file__))
11
+
12
+ lib_path = join(root, 'lib', 'telemetry.dll')
13
+
14
+ try:
15
+ return cdll.LoadLibrary(lib_path)
16
+ except FileNotFoundError:
17
+ if not exists(lib_path):
18
+ raise FileNotFoundError("telemetry.dll was not found on your system. Is this package correctly installed?")
19
+ raise Exception("telemetry.dll could not be loaded. Do you have Visual Studio C++ Redistributible installed?")
20
+
21
+ __lib = __load_library()
22
+
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2009-2026 FIRST and other WPILib contributors
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * Neither the name of FIRST, WPILib, nor the names of other WPILib
12
+ contributors may be used to endorse or promote products derived from
13
+ this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY FIRST AND OTHER WPILIB CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
18
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
19
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,70 @@
1
+ // Copyright (c) FIRST and other WPILib contributors.
2
+ // Open Source Software; you can modify and/or share it under the terms of
3
+ // the WPILib BSD license file in the root directory of this project.
4
+
5
+ #pragma once
6
+
7
+ #include <memory>
8
+
9
+ #include "wpi/telemetry/TelemetryBackend.hpp"
10
+
11
+ namespace wpi::telemetry {
12
+
13
+ /** A telemetry backend that discards all logged data. */
14
+ class DiscardTelemetryBackend : public TelemetryBackend {
15
+ public:
16
+ /**
17
+ * Create an entry for the given path.
18
+ *
19
+ * @param path full name
20
+ * @return telemetry entry
21
+ */
22
+ std::shared_ptr<TelemetryEntry> GetEntry(std::string_view path) override;
23
+
24
+ /**
25
+ * Returns whether there is a data schema already registered with the given
26
+ * name. This does NOT perform a check as to whether the schema has already
27
+ * been published by another node on the network.
28
+ *
29
+ * @param schemaName Name (the string passed as the data type for topics using
30
+ * this schema)
31
+ * @return True if schema already registered
32
+ */
33
+ bool HasSchema(std::string_view schemaName) const override;
34
+
35
+ /**
36
+ * Registers a data schema. Data schemas provide information for how a
37
+ * certain data type string can be decoded. The type string of a data schema
38
+ * indicates the type of the schema itself (e.g. "protobuf" for protobuf
39
+ * schemas, "struct" for struct schemas, etc). In NetworkTables, schemas are
40
+ * published just like normal topics, with the name being generated from the
41
+ * provided name: "/.schema/<name>". Duplicate calls to this function with
42
+ * the same name are silently ignored.
43
+ *
44
+ * @param schemaName Name (the string passed as the data type for topics using
45
+ * this schema)
46
+ * @param type Type of schema (e.g. "protobuf", "struct", etc)
47
+ * @param schema Schema data
48
+ */
49
+ void AddSchema(std::string_view schemaName, std::string_view type,
50
+ std::span<const uint8_t> schema) override;
51
+
52
+ /**
53
+ * Registers a data schema. Data schemas provide information for how a
54
+ * certain data type string can be decoded. The type string of a data schema
55
+ * indicates the type of the schema itself (e.g. "protobuf" for protobuf
56
+ * schemas, "struct" for struct schemas, etc). In NetworkTables, schemas are
57
+ * published just like normal topics, with the name being generated from the
58
+ * provided name: "/.schema/<name>". Duplicate calls to this function with
59
+ * the same name are silently ignored.
60
+ *
61
+ * @param schemaName Name (the string passed as the data type for topics using
62
+ * this schema)
63
+ * @param type Type of schema (e.g. "protobuf", "struct", etc)
64
+ * @param schema Schema data
65
+ */
66
+ void AddSchema(std::string_view schemaName, std::string_view type,
67
+ std::string_view schema) override;
68
+ };
69
+
70
+ } // namespace wpi::telemetry
@@ -0,0 +1,208 @@
1
+ // Copyright (c) FIRST and other WPILib contributors.
2
+ // Open Source Software; you can modify and/or share it under the terms of
3
+ // the WPILib BSD license file in the root directory of this project.
4
+
5
+ #pragma once
6
+
7
+ #include <stdint.h>
8
+
9
+ #include <memory>
10
+ #include <optional>
11
+ #include <string>
12
+ #include <utility>
13
+ #include <variant>
14
+ #include <vector>
15
+
16
+ #include "wpi/telemetry/TelemetryBackend.hpp"
17
+ #include "wpi/util/StringMap.hpp"
18
+ #include "wpi/util/mutex.hpp"
19
+
20
+ namespace wpi::telemetry {
21
+
22
+ /**
23
+ * A telemetry backend that saves logged data to an array for unit testing
24
+ * purposes. Logging is thread-safe, but callers must quiesce or externally
25
+ * synchronize logging while inspecting references or pointers returned by
26
+ * this class.
27
+ */
28
+ class MockTelemetryBackend : public TelemetryBackend {
29
+ public:
30
+ /** Value for KeepDuplicate() action. */
31
+ struct KeepDuplicatesValue {
32
+ bool value = true;
33
+ };
34
+
35
+ /** Value for SetProperty() action. */
36
+ struct SetPropertyValue {
37
+ std::string key;
38
+ std::string value;
39
+ };
40
+
41
+ /** Value for LogString() action. */
42
+ struct LogStringValue {
43
+ std::string value;
44
+ std::string typeString;
45
+ };
46
+
47
+ /** Value for LogBooleanArray() action. */
48
+ struct LogBooleanArrayValue {
49
+ std::vector<int> value;
50
+ };
51
+
52
+ /** Value for LogRaw() action. */
53
+ struct LogRawValue {
54
+ std::vector<uint8_t> value;
55
+ std::string typeString;
56
+ };
57
+
58
+ /** A logged action. */
59
+ struct Action {
60
+ template <typename T>
61
+ Action(std::string_view path_, T value_, int64_t timestamp_ = 0)
62
+ : path{path_}, value{std::move(value_)}, timestamp{timestamp_} {}
63
+
64
+ std::string path;
65
+ std::variant<KeepDuplicatesValue, SetPropertyValue, bool, int16_t, int32_t,
66
+ int64_t, float, double, LogStringValue, LogBooleanArrayValue,
67
+ std::vector<int16_t>, std::vector<int32_t>,
68
+ std::vector<int64_t>, std::vector<float>, std::vector<double>,
69
+ std::vector<std::string>, LogRawValue>
70
+ value;
71
+ int64_t timestamp = 0;
72
+ };
73
+
74
+ struct Schema {
75
+ std::string type;
76
+ std::vector<uint8_t> schemaBytes;
77
+ std::string schemaString;
78
+ };
79
+
80
+ MockTelemetryBackend();
81
+
82
+ ~MockTelemetryBackend() override;
83
+
84
+ /**
85
+ * Get logged actions.
86
+ *
87
+ * @return Logged actions
88
+ */
89
+ const std::vector<Action>& GetActions() const { return m_actions; }
90
+
91
+ /**
92
+ * Clear logged actions.
93
+ */
94
+ void Clear();
95
+
96
+ /**
97
+ * Get the last action for a particular path.
98
+ *
99
+ * @param path path
100
+ * @return Pointer to action, or nullptr if no update to that path
101
+ */
102
+ const Action* GetLastAction(std::string_view path) const {
103
+ std::scoped_lock lock{m_mutex};
104
+ return GetLastActionImpl(path);
105
+ }
106
+
107
+ /**
108
+ * Get the last action for a particular path.
109
+ *
110
+ * @param path path
111
+ * @return Action value, or empty if no update to that path
112
+ */
113
+ template <typename T>
114
+ std::optional<T> GetLastValue(std::string_view path) const {
115
+ std::scoped_lock lock{m_mutex};
116
+ auto* action = GetLastActionImpl(path);
117
+ if (!action || !std::holds_alternative<T>(action->value)) {
118
+ return std::nullopt;
119
+ }
120
+ return std::get<T>(action->value);
121
+ }
122
+
123
+ /**
124
+ * Get schema.
125
+ *
126
+ * @param schemaName schema name
127
+ * @return Schema, or nullptr if no match
128
+ */
129
+ const Schema* GetSchema(std::string_view schemaName) {
130
+ std::scoped_lock lock{m_mutex};
131
+ auto it = m_schemas.find(schemaName);
132
+ if (it == m_schemas.end()) {
133
+ return nullptr;
134
+ }
135
+ return &it->second;
136
+ }
137
+
138
+ /**
139
+ * Create an entry for the given path.
140
+ *
141
+ * @param path full name
142
+ * @return telemetry entry
143
+ */
144
+ std::shared_ptr<TelemetryEntry> GetEntry(std::string_view path) override;
145
+
146
+ /**
147
+ * Removes an entry for the given path.
148
+ *
149
+ * @param path normalized full name
150
+ */
151
+ void RemoveEntry(std::string_view path) override;
152
+
153
+ /**
154
+ * Returns whether there is a data schema already registered with the given
155
+ * name. This does NOT perform a check as to whether the schema has already
156
+ * been published by another node on the network.
157
+ *
158
+ * @param schemaName Name (the string passed as the data type for topics using
159
+ * this schema)
160
+ * @return True if schema already registered
161
+ */
162
+ bool HasSchema(std::string_view schemaName) const override;
163
+
164
+ /**
165
+ * Registers a data schema. Data schemas provide information for how a
166
+ * certain data type string can be decoded. The type string of a data schema
167
+ * indicates the type of the schema itself (e.g. "protobuf" for protobuf
168
+ * schemas, "struct" for struct schemas, etc). In NetworkTables, schemas are
169
+ * published just like normal topics, with the name being generated from the
170
+ * provided name: "/.schema/<name>". Duplicate calls to this function with
171
+ * the same name are silently ignored.
172
+ *
173
+ * @param schemaName Name (the string passed as the data type for topics using
174
+ * this schema)
175
+ * @param type Type of schema (e.g. "protobuf", "struct", etc)
176
+ * @param schema Schema data
177
+ */
178
+ void AddSchema(std::string_view schemaName, std::string_view type,
179
+ std::span<const uint8_t> schema) override;
180
+
181
+ /**
182
+ * Registers a data schema. Data schemas provide information for how a
183
+ * certain data type string can be decoded. The type string of a data schema
184
+ * indicates the type of the schema itself (e.g. "protobuf" for protobuf
185
+ * schemas, "struct" for struct schemas, etc). In NetworkTables, schemas are
186
+ * published just like normal topics, with the name being generated from the
187
+ * provided name: "/.schema/<name>". Duplicate calls to this function with
188
+ * the same name are silently ignored.
189
+ *
190
+ * @param schemaName Name (the string passed as the data type for topics using
191
+ * this schema)
192
+ * @param type Type of schema (e.g. "protobuf", "struct", etc)
193
+ * @param schema Schema data
194
+ */
195
+ void AddSchema(std::string_view schemaName, std::string_view type,
196
+ std::string_view schema) override;
197
+
198
+ private:
199
+ const Action* GetLastActionImpl(std::string_view path) const;
200
+
201
+ class Entry;
202
+ mutable wpi::util::mutex m_mutex;
203
+ wpi::util::StringMap<std::shared_ptr<Entry>> m_entries;
204
+ wpi::util::StringMap<Schema> m_schemas;
205
+ std::vector<Action> m_actions;
206
+ };
207
+
208
+ } // namespace wpi::telemetry
@@ -0,0 +1,110 @@
1
+ // Copyright (c) FIRST and other WPILib contributors.
2
+ // Open Source Software; you can modify and/or share it under the terms of
3
+ // the WPILib BSD license file in the root directory of this project.
4
+
5
+ #pragma once
6
+
7
+ #include <stdint.h>
8
+
9
+ #include <initializer_list>
10
+ #include <memory>
11
+ #include <span>
12
+ #include <string_view>
13
+ #include <vector>
14
+
15
+ #include "wpi/telemetry/TelemetryBackend.hpp"
16
+ #include "wpi/util/StringMap.hpp"
17
+ #include "wpi/util/mutex.hpp"
18
+
19
+ namespace wpi::telemetry {
20
+
21
+ /**
22
+ * A telemetry backend that forwards logged data to multiple child backends.
23
+ */
24
+ class MultiTelemetryBackend : public TelemetryBackend {
25
+ public:
26
+ /** Constructs a telemetry backend with no child backends. */
27
+ MultiTelemetryBackend();
28
+
29
+ /**
30
+ * Constructs a telemetry backend that forwards to multiple child backends.
31
+ *
32
+ * @param backends child backends
33
+ */
34
+ explicit MultiTelemetryBackend(
35
+ std::span<const std::shared_ptr<TelemetryBackend>> backends);
36
+
37
+ /**
38
+ * Constructs a telemetry backend that forwards to multiple child backends.
39
+ *
40
+ * @param backends child backends
41
+ */
42
+ explicit MultiTelemetryBackend(
43
+ std::vector<std::shared_ptr<TelemetryBackend>> backends);
44
+
45
+ /**
46
+ * Constructs a telemetry backend that forwards to multiple child backends.
47
+ *
48
+ * @param backends child backends
49
+ */
50
+ MultiTelemetryBackend(
51
+ std::initializer_list<std::shared_ptr<TelemetryBackend>> backends);
52
+
53
+ ~MultiTelemetryBackend() override;
54
+
55
+ /**
56
+ * Create an entry for the given path.
57
+ *
58
+ * @param path full name
59
+ * @return telemetry entry
60
+ */
61
+ std::shared_ptr<TelemetryEntry> GetEntry(std::string_view path) override;
62
+
63
+ /**
64
+ * Removes an entry for the given path.
65
+ *
66
+ * @param path normalized full name
67
+ */
68
+ void RemoveEntry(std::string_view path) override;
69
+
70
+ /**
71
+ * Returns whether every child backend has a data schema already registered
72
+ * with the given name.
73
+ *
74
+ * @param schemaName Name (the string passed as the data type for topics using
75
+ * this schema)
76
+ * @return True if every child backend already has the schema
77
+ */
78
+ bool HasSchema(std::string_view schemaName) const override;
79
+
80
+ /**
81
+ * Registers a data schema with every child backend.
82
+ *
83
+ * @param schemaName Name (the string passed as the data type for topics using
84
+ * this schema)
85
+ * @param type Type of schema (e.g. "protobuf", "struct", etc)
86
+ * @param schema Schema data
87
+ */
88
+ void AddSchema(std::string_view schemaName, std::string_view type,
89
+ std::span<const uint8_t> schema) override;
90
+
91
+ /**
92
+ * Registers a data schema with every child backend.
93
+ *
94
+ * @param schemaName Name (the string passed as the data type for topics using
95
+ * this schema)
96
+ * @param type Type of schema (e.g. "protobuf", "struct", etc)
97
+ * @param schema Schema data
98
+ */
99
+ void AddSchema(std::string_view schemaName, std::string_view type,
100
+ std::string_view schema) override;
101
+
102
+ private:
103
+ class Entry;
104
+
105
+ std::vector<std::shared_ptr<TelemetryBackend>> m_backends;
106
+ wpi::util::mutex m_mutex;
107
+ wpi::util::StringMap<std::shared_ptr<Entry>> m_entries;
108
+ };
109
+
110
+ } // namespace wpi::telemetry