benchlab-pytools 3.0.0__py3-none-any.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.
Files changed (184) hide show
  1. benchlab/__init__.py +14 -0
  2. benchlab/__main__.py +21 -0
  3. benchlab/config/README.md +325 -0
  4. benchlab/config/__init__.py +9 -0
  5. benchlab/config/config_client.py +631 -0
  6. benchlab/config/config_manager.py +495 -0
  7. benchlab/config/config_tool.py +358 -0
  8. benchlab/config/diff.py +163 -0
  9. benchlab/config/examples/complete_config.json +56 -0
  10. benchlab/config/examples/rgb_lighting.json +24 -0
  11. benchlab/config/examples/simple_fan.json +32 -0
  12. benchlab/config/schema.py +138 -0
  13. benchlab/core/README.md +154 -0
  14. benchlab/core/__init__.py +78 -0
  15. benchlab/core/config.py +145 -0
  16. benchlab/core/datasource.py +1209 -0
  17. benchlab/core/datasource_manager.py +418 -0
  18. benchlab/core/device_registry.py +206 -0
  19. benchlab/core/discovery.py +92 -0
  20. benchlab/core/infrastructure.py +309 -0
  21. benchlab/core/process_manager.py +356 -0
  22. benchlab/core/retry.py +85 -0
  23. benchlab/core/shared_serial.py +235 -0
  24. benchlab/core/statistics.py +224 -0
  25. benchlab/csv_log/README.md +206 -0
  26. benchlab/csv_log/__init__.py +5 -0
  27. benchlab/csv_log/csv_logger_enhanced.py +416 -0
  28. benchlab/csv_log/message_batcher.py +361 -0
  29. benchlab/csv_log/requirements.txt +3 -0
  30. benchlab/csv_log/smart_retry.py +466 -0
  31. benchlab/graph/README.md +117 -0
  32. benchlab/graph/__init__.py +5 -0
  33. benchlab/graph/app.py +353 -0
  34. benchlab/graph/requirements.txt +2 -0
  35. benchlab/graph/runner.py +42 -0
  36. benchlab/graph/ui.py +288 -0
  37. benchlab/hwinfo/README.md +135 -0
  38. benchlab/hwinfo/__init__.py +5 -0
  39. benchlab/hwinfo/hwinfo_export.py +386 -0
  40. benchlab/hwinfo/requirements.txt +1 -0
  41. benchlab/launcher.py +387 -0
  42. benchlab/link/.env.EXAMPLE +10 -0
  43. benchlab/link/README.md +172 -0
  44. benchlab/link/__init__.py +1 -0
  45. benchlab/link/link_main.py +479 -0
  46. benchlab/main.py +462 -0
  47. benchlab/menu.py +729 -0
  48. benchlab/menu_classic.py +410 -0
  49. benchlab/mqtt/README.md +201 -0
  50. benchlab/mqtt/__init__.py +5 -0
  51. benchlab/mqtt/mqtt.config_template +2 -0
  52. benchlab/mqtt/mqtt_publisher.py +540 -0
  53. benchlab/mqtt/requirements.txt +3 -0
  54. benchlab/prefs.py +67 -0
  55. benchlab/restapi/.env.example +17 -0
  56. benchlab/restapi/__init__.py +5 -0
  57. benchlab/restapi/favicon.ico +0 -0
  58. benchlab/restapi/readme.md +202 -0
  59. benchlab/restapi/requirements.txt +5 -0
  60. benchlab/restapi/telemetry_api.py +808 -0
  61. benchlab/sources.py +515 -0
  62. benchlab/tools.py +147 -0
  63. benchlab/tui/README.md +266 -0
  64. benchlab/tui/__init__.py +5 -0
  65. benchlab/tui/config.py +477 -0
  66. benchlab/tui/requirements.txt +2 -0
  67. benchlab/tui/tui_core.py +1298 -0
  68. benchlab/tui/tui_main.py +418 -0
  69. benchlab/vu/README.md +64 -0
  70. benchlab/vu/VU-Server/NOTICE.md +13 -0
  71. benchlab/vu/VU-Server/README.md +80 -0
  72. benchlab/vu/VU-Server/Running_from_source_on_linux.md +97 -0
  73. benchlab/vu/VU-Server/__init__.py +0 -0
  74. benchlab/vu/VU-Server/assets/vu1_hello_world.png +0 -0
  75. benchlab/vu/VU-Server/community_applications.md +13 -0
  76. benchlab/vu/VU-Server/config.yaml +9 -0
  77. benchlab/vu/VU-Server/database.py +256 -0
  78. benchlab/vu/VU-Server/dial_driver.py +534 -0
  79. benchlab/vu/VU-Server/dials/Comms_Hub_Gauge.py +78 -0
  80. benchlab/vu/VU-Server/dials/Comms_Hub_Server.py +100 -0
  81. benchlab/vu/VU-Server/dials/__init__.py +0 -0
  82. benchlab/vu/VU-Server/dials/base_logger.py +100 -0
  83. benchlab/vu/VU-Server/installer/inc/icon.ico +0 -0
  84. benchlab/vu/VU-Server/installer/install.nsi +148 -0
  85. benchlab/vu/VU-Server/make_version.py +40 -0
  86. benchlab/vu/VU-Server/pylintrc +628 -0
  87. benchlab/vu/VU-Server/requirements.txt +9 -0
  88. benchlab/vu/VU-Server/serial_driver.py +244 -0
  89. benchlab/vu/VU-Server/server.py +670 -0
  90. benchlab/vu/VU-Server/server_config.py +255 -0
  91. benchlab/vu/VU-Server/server_dial_handler.py +334 -0
  92. benchlab/vu/VU-Server/vu_notifications.py +24 -0
  93. benchlab/vu/VU-Server/www/android-chrome-192x192.png +0 -0
  94. benchlab/vu/VU-Server/www/android-chrome-512x512.png +0 -0
  95. benchlab/vu/VU-Server/www/apple-touch-icon.png +0 -0
  96. benchlab/vu/VU-Server/www/assets/css/demo.css +291 -0
  97. benchlab/vu/VU-Server/www/assets/css/demo.min.css +9 -0
  98. benchlab/vu/VU-Server/www/assets/css/demo.rtl.css +276 -0
  99. benchlab/vu/VU-Server/www/assets/css/demo.rtl.min.css +9 -0
  100. benchlab/vu/VU-Server/www/assets/css/tabler-flags.css +1084 -0
  101. benchlab/vu/VU-Server/www/assets/css/tabler-flags.min.css +9 -0
  102. benchlab/vu/VU-Server/www/assets/css/tabler-flags.rtl.css +1084 -0
  103. benchlab/vu/VU-Server/www/assets/css/tabler-flags.rtl.min.css +9 -0
  104. benchlab/vu/VU-Server/www/assets/css/tabler-payments.css +528 -0
  105. benchlab/vu/VU-Server/www/assets/css/tabler-payments.min.css +9 -0
  106. benchlab/vu/VU-Server/www/assets/css/tabler-payments.rtl.css +528 -0
  107. benchlab/vu/VU-Server/www/assets/css/tabler-payments.rtl.min.css +9 -0
  108. benchlab/vu/VU-Server/www/assets/css/tabler-social.css +10 -0
  109. benchlab/vu/VU-Server/www/assets/css/tabler-social.min.css +8 -0
  110. benchlab/vu/VU-Server/www/assets/css/tabler-social.rtl.css +10 -0
  111. benchlab/vu/VU-Server/www/assets/css/tabler-social.rtl.min.css +8 -0
  112. benchlab/vu/VU-Server/www/assets/css/tabler-vendors.css +1504 -0
  113. benchlab/vu/VU-Server/www/assets/css/tabler-vendors.min.css +9 -0
  114. benchlab/vu/VU-Server/www/assets/css/tabler-vendors.rtl.css +1504 -0
  115. benchlab/vu/VU-Server/www/assets/css/tabler-vendors.rtl.min.css +9 -0
  116. benchlab/vu/VU-Server/www/assets/css/tabler.css +25813 -0
  117. benchlab/vu/VU-Server/www/assets/css/tabler.min.css +13 -0
  118. benchlab/vu/VU-Server/www/assets/css/tabler.rtl.css +25777 -0
  119. benchlab/vu/VU-Server/www/assets/css/tabler.rtl.min.css +13 -0
  120. benchlab/vu/VU-Server/www/assets/css/theme.min.css +261 -0
  121. benchlab/vu/VU-Server/www/assets/img/header.png +0 -0
  122. benchlab/vu/VU-Server/www/assets/img/logo.png +0 -0
  123. benchlab/vu/VU-Server/www/assets/js/dark-theme.js +35 -0
  124. benchlab/vu/VU-Server/www/assets/js/dark-theme.min.js +9 -0
  125. benchlab/vu/VU-Server/www/assets/js/demo.js +132 -0
  126. benchlab/vu/VU-Server/www/assets/js/demo.min.js +9 -0
  127. benchlab/vu/VU-Server/www/assets/js/jquery.min.js +2 -0
  128. benchlab/vu/VU-Server/www/assets/js/tabler.esm.js +7482 -0
  129. benchlab/vu/VU-Server/www/assets/js/tabler.esm.min.js +15 -0
  130. benchlab/vu/VU-Server/www/assets/js/tabler.js +7543 -0
  131. benchlab/vu/VU-Server/www/assets/js/tabler.min.js +15 -0
  132. benchlab/vu/VU-Server/www/assets/js/vu1_api.js +68 -0
  133. benchlab/vu/VU-Server/www/assets/js/vu1_gui_api_key_settings.js +167 -0
  134. benchlab/vu/VU-Server/www/assets/js/vu1_gui_api_keys.js +138 -0
  135. benchlab/vu/VU-Server/www/assets/js/vu1_gui_dial.js +179 -0
  136. benchlab/vu/VU-Server/www/assets/js/vu1_gui_home.js +60 -0
  137. benchlab/vu/VU-Server/www/assets/js/vu1_gui_root.js +125 -0
  138. benchlab/vu/VU-Server/www/favicon-16x16.png +0 -0
  139. benchlab/vu/VU-Server/www/favicon-32x32.png +0 -0
  140. benchlab/vu/VU-Server/www/favicon.ico +0 -0
  141. benchlab/vu/VU-Server/www/favicon.png +0 -0
  142. benchlab/vu/VU-Server/www/index.html +47 -0
  143. benchlab/vu/VU-Server/www/views/api_keys.html +151 -0
  144. benchlab/vu/VU-Server/www/views/dial.html +286 -0
  145. benchlab/vu/VU-Server/www/views/footer.html +27 -0
  146. benchlab/vu/VU-Server/www/views/header.html +86 -0
  147. benchlab/vu/VU-Server/www/views/key_settings.html +132 -0
  148. benchlab/vu/VU-Server/www/views/start.html +124 -0
  149. benchlab/vu/__init__.py +5 -0
  150. benchlab/vu/assets/Barlow-Bold.ttf +0 -0
  151. benchlab/vu/assets/bl_dial_144x200.png +0 -0
  152. benchlab/vu/assets/bl_logo_144x200.png +0 -0
  153. benchlab/vu/devices.py +166 -0
  154. benchlab/vu/requirements.txt +24 -0
  155. benchlab/vu/sensors.py +18 -0
  156. benchlab/vu/vu_dial.config_template +90 -0
  157. benchlab/vu/vu_logo_gen.py +97 -0
  158. benchlab/vu/vu_server.config_template +5 -0
  159. benchlab/vu/vu_server_config.py +40 -0
  160. benchlab/vu/vu_server_manager.py +192 -0
  161. benchlab/vu/vu_tui.py +919 -0
  162. benchlab/vu/vu_updater.py +540 -0
  163. benchlab/wigidash/README.md +182 -0
  164. benchlab/wigidash/__init__.py +5 -0
  165. benchlab/wigidash/assets/Inter-Bold.ttf +0 -0
  166. benchlab/wigidash/assets/Inter.ttf +0 -0
  167. benchlab/wigidash/assets/benchlab.png +0 -0
  168. benchlab/wigidash/benchlab_fleet.py +150 -0
  169. benchlab/wigidash/benchlab_graph.py +517 -0
  170. benchlab/wigidash/benchlab_overview.py +426 -0
  171. benchlab/wigidash/benchlab_telemetry.py +105 -0
  172. benchlab/wigidash/benchlab_ui.py +190 -0
  173. benchlab/wigidash/benchlab_utils.py +182 -0
  174. benchlab/wigidash/requirements.txt +9 -0
  175. benchlab/wigidash/wigidash_device.py +541 -0
  176. benchlab/wigidash/wigidash_manager.py +342 -0
  177. benchlab/wigidash/wigidash_session.py +355 -0
  178. benchlab/wigidash/wigidash_usb.py +247 -0
  179. benchlab/wigidash/wigidash_widget.py +88 -0
  180. benchlab_pytools-3.0.0.dist-info/METADATA +239 -0
  181. benchlab_pytools-3.0.0.dist-info/RECORD +184 -0
  182. benchlab_pytools-3.0.0.dist-info/WHEEL +4 -0
  183. benchlab_pytools-3.0.0.dist-info/entry_points.txt +2 -0
  184. benchlab_pytools-3.0.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,202 @@
1
+ # BenchLab FastAPI Telemetry Server
2
+
3
+ A lightweight, cross-platform REST API server for BenchLab telemetry data collection and monitoring.
4
+
5
+ ## Features
6
+
7
+ ### ✨ Core Improvements
8
+ - **Cross-platform device discovery** - Automatically detects BenchLab devices on Windows, Linux, and macOS
9
+ - **Robust error handling** - Comprehensive error handling and logging for production use
10
+ - **Configuration management** - Environment-based configuration with validation
11
+ - **Health monitoring** - Built-in health check and status endpoints
12
+ - **CORS support** - Ready for web client integration
13
+
14
+ ### 🚀 Performance Enhancements
15
+ - **Efficient data streaming** - WebSocket support for real-time telemetry updates
16
+ - **Configurable polling** - Adjustable sensor read intervals (minimum 0.1s)
17
+ - **History management** - Configurable history buffer with pagination
18
+ - **Connection pooling** - Optimized serial connection management
19
+
20
+ ### 🛡️ Reliability Features
21
+ - **Graceful shutdown** - Proper cleanup of threads and connections
22
+ - **Device reconnection** - Automatic handling of device disconnects/reconnects
23
+ - **Validation** - Input validation and configuration checks
24
+ - **Logging** - Structured logging with configurable levels
25
+
26
+ ## Quick Start
27
+
28
+ ### 1. Installation
29
+ ```bash
30
+ pip install -r requirements.txt
31
+ ```
32
+
33
+ ### 2. Configuration
34
+ Optionally create a `.env` file in `benchlab/restapi/` to override defaults (see Configuration Options below). All settings also work as plain environment variables.
35
+
36
+ ### 3. Run the Server
37
+ ```bash
38
+ python -m benchlab -fastapi
39
+ ```
40
+
41
+ You can also run the module directly:
42
+ ```bash
43
+ python -m benchlab.restapi.telemetry_api
44
+ ```
45
+
46
+ The server will start on `http://0.0.0.0:8000` by default (configurable via `API_HOST`/`API_PORT`).
47
+
48
+ ## API Endpoints
49
+
50
+ ### Device Management
51
+ - `GET /devices` - List all connected devices (uid, port, firmware, variant, VendorId, ProductId, connected)
52
+ - `GET /device/{uid}/info` - Get device information (returns mock info with 404-style defaults if the uid isn't known, for test convenience)
53
+ - `GET /device/{uid}/status` - Get detailed status for a specific device (port, connected, last_update, client_count, history_count, latest_telemetry, info)
54
+ - `POST /scan` - Trigger an immediate device scan (discovers new devices, marks disconnected ones) without restarting the server
55
+
56
+ ### Telemetry Data
57
+ - `GET /device/{uid}/telemetry` - Get latest telemetry snapshot for a device
58
+ - `GET /device/{uid}/telemetry/{sensor}` - Get a single sensor's latest value
59
+ - `GET /device/{uid}/history?limit=100` - Get telemetry history (most recent `limit` entries, capped by `MAX_HISTORY_LIMIT`); response includes `device_id`, `data`, `count`, `total_available`
60
+ - `GET /device/{uid}/sensors` - List available sensor keys for a device
61
+
62
+ ### Real-time Streaming
63
+ - `WebSocket /device/{uid}/stream` - Real-time telemetry updates, pushed as each device's reader thread reads new sensor data
64
+
65
+ ### Monitoring
66
+ - `GET /health` - Basic health check (status, platform, timestamp, connected_devices, total_clients)
67
+ - `GET /status` - Detailed server status for all devices
68
+ - `GET /favicon.ico` - Server favicon
69
+
70
+ All endpoints for an unknown `{uid}` return `404` (except `/device/{uid}/info`, which returns mock placeholder data instead).
71
+
72
+ A background scanner thread re-scans for new/disconnected devices every `SCAN_INTERVAL` seconds automatically, in addition to the manual `POST /scan` endpoint.
73
+
74
+ ## Configuration Options
75
+
76
+ | Variable | Default | Description |
77
+ |----------|---------|-------------|
78
+ | `API_HOST` | `0.0.0.0` | Server bind address |
79
+ | `API_PORT` | `8000` | Server port (1-65535) |
80
+ | `LOG_LEVEL` | `INFO` | Logging level |
81
+ | `POLL_INTERVAL` | `1.0` | Sensor read interval in seconds (min 0.1) |
82
+ | `HISTORY_LENGTH` | `10` | Number of history entries per device |
83
+ | `MAX_HISTORY_LIMIT` | `1000` | Max history limit for API requests |
84
+ | `SCAN_INTERVAL` | `30` | Device discovery scan interval in seconds |
85
+ | `CORS_ORIGINS` | `*` | Comma-separated allowed CORS origins. Credentialed requests are only allowed when explicit origins are set (wildcard + credentials is rejected by browsers) |
86
+
87
+ ## Cross-Platform Support
88
+
89
+ The server automatically detects and works with BenchLab devices across different platforms:
90
+
91
+ - **Windows**: COM1-COM9 ports
92
+ - **Linux**: `/dev/ttyUSB*`, `/dev/ttyACM*`, `/dev/ttyS*` ports
93
+ - **macOS**: `/dev/tty.*` ports
94
+
95
+ ## Testing
96
+
97
+ Run the test suite to verify the server functionality:
98
+ ```bash
99
+ python -m pytest benchlab/restapi/test_server.py
100
+ ```
101
+
102
+ This tests:
103
+ - Server startup and configuration
104
+ - API endpoint registration
105
+ - Cross-platform device detection
106
+ - Error handling and validation
107
+
108
+ ## Usage Examples
109
+
110
+ ### Get Device List
111
+ ```bash
112
+ curl http://localhost:8000/devices
113
+ ```
114
+
115
+ ### Get Latest Telemetry
116
+ ```bash
117
+ curl http://localhost:8000/device/ABC123/telemetry
118
+ ```
119
+
120
+ ### Get Sensor History
121
+ ```bash
122
+ curl "http://localhost:8000/device/ABC123/history?limit=50"
123
+ ```
124
+
125
+ ### Real-time Streaming (WebSocket)
126
+ ```javascript
127
+ const ws = new WebSocket('ws://localhost:8000/device/ABC123/stream');
128
+ ws.onmessage = (event) => {
129
+ const data = JSON.parse(event.data);
130
+ console.log('Telemetry update:', data);
131
+ };
132
+ ```
133
+
134
+ ## Production Deployment
135
+
136
+ ### Docker Support
137
+ The server is designed for containerization:
138
+ ```dockerfile
139
+ FROM python:3.9-slim
140
+ COPY requirements.txt .
141
+ RUN pip install -r requirements.txt
142
+ COPY . .
143
+ CMD ["python", "-m", "benchlab.restapi.telemetry_api"]
144
+ ```
145
+
146
+ ### Systemd Service (Linux)
147
+ Create `/etc/systemd/system/benchlab-api.service`:
148
+ ```ini
149
+ [Unit]
150
+ Description=BenchLab Telemetry API
151
+ After=network.target
152
+
153
+ [Service]
154
+ Type=simple
155
+ User=benchlab
156
+ WorkingDirectory=/opt/benchlab
157
+ ExecStart=/usr/bin/python3 -m benchlab.restapi.telemetry_api
158
+ Restart=always
159
+
160
+ [Install]
161
+ WantedBy=multi-user.target
162
+ ```
163
+
164
+ ## Troubleshooting
165
+
166
+ ### Common Issues
167
+
168
+ 1. **No devices found**
169
+ - Check USB connections
170
+ - Verify device firmware
171
+ - Check serial port permissions
172
+
173
+ 2. **Permission errors**
174
+ - On Linux, add user to `dialout` group: `sudo usermod -a -G dialout $USER`
175
+ - Restart terminal or reboot after group changes
176
+
177
+ 3. **Port binding errors**
178
+ - Check if port is already in use
179
+ - Try a different port in configuration
180
+
181
+ ### Logging
182
+ Enable debug logging for troubleshooting:
183
+ ```bash
184
+ LOG_LEVEL=DEBUG python -m benchlab -fastapi
185
+ ```
186
+
187
+ ## Development
188
+
189
+ ### Adding New Endpoints
190
+ 1. Add the endpoint function in `telemetry_api.py`
191
+ 2. Use FastAPI decorators (`@app.get`, `@app.post`, etc.)
192
+ 3. Add proper error handling and validation
193
+ 4. Update this README with new endpoints
194
+
195
+ ### Testing Changes
196
+ 1. Run the test suite: `python test_server.py`
197
+ 2. Test manually with curl or a REST client
198
+ 3. Verify WebSocket functionality
199
+
200
+ ## License
201
+
202
+ This project is part of the BenchLab suite. See the main project license for details.
@@ -0,0 +1,5 @@
1
+ fastapi==0.111.1
2
+ uvicorn[standard]==0.24.0
3
+ pyserial>=3.5
4
+ python-dotenv==1.1.1
5
+ pydantic>=2.0.0 # For better data validation