slm_open_api_package 0.2.10__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 (37) hide show
  1. slm_api/CPB_example.py +74 -0
  2. slm_api/__init__.py +5 -0
  3. slm_api/enums/fast_log_intervals_enum.py +16 -0
  4. slm_api/enums/sequence_id_enum.py +352 -0
  5. slm_api/example_multi.py +78 -0
  6. slm_api/fast_log_example.py +172 -0
  7. slm_api/flac_example.py +164 -0
  8. slm_api/helpers/FigureHandler.py +65 -0
  9. slm_api/helpers/Leq.py +87 -0
  10. slm_api/helpers/__init__.py +5 -0
  11. slm_api/helpers/buffer.py +27 -0
  12. slm_api/helpers/data_handler.py +94 -0
  13. slm_api/helpers/fft.py +38 -0
  14. slm_api/helpers/flac_stream_2_samples.py +64 -0
  15. slm_api/helpers/https_requests.py +79 -0
  16. slm_api/helpers/measurment_handler.py +20 -0
  17. slm_api/helpers/sequence_handler.py +43 -0
  18. slm_api/helpers/stream_handler.py +105 -0
  19. slm_api/helpers/stream_handlers.py +434 -0
  20. slm_api/helpers/tmpFileStateMachine.py +93 -0
  21. slm_api/helpers/websocket_handler.py +12 -0
  22. slm_api/helpers/webxi_helper_functions.py +79 -0
  23. slm_api/helpers/webxi_root.pem +24 -0
  24. slm_api/mp3_example.py +165 -0
  25. slm_api/multi_device_flac.py +105 -0
  26. slm_api/multi_instrument_example.py +74 -0
  27. slm_api/screen_record_example.py +64 -0
  28. slm_api/webxi/README.md +25 -0
  29. slm_api/webxi/__init__.py +5 -0
  30. slm_api/webxi/webxi-header.ksy +32 -0
  31. slm_api/webxi/webxi-stream.ksy +342 -0
  32. slm_api/webxi/webxi_header.py +42 -0
  33. slm_api/webxi/webxi_stream.py +450 -0
  34. slm_open_api_package-0.2.10.dist-info/METADATA +206 -0
  35. slm_open_api_package-0.2.10.dist-info/RECORD +37 -0
  36. slm_open_api_package-0.2.10.dist-info/WHEEL +4 -0
  37. slm_open_api_package-0.2.10.dist-info/entry_points.txt +3 -0
slm_api/CPB_example.py ADDED
@@ -0,0 +1,74 @@
1
+ import threading
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ from matplotlib.animation import FuncAnimation
5
+
6
+ from slm_api.helpers.stream_handlers import WebXiStreamHandler
7
+ from slm_api.helpers import webxi_helper_functions as webxi_helper
8
+ from slm_api.enums.sequence_id_enum import SequenceIdEnums
9
+ from slm_api.helpers.data_handler import CsvDataHandler,PickleDataHandler,JsonDataHandler,MultiDataHandler, DataHandler
10
+
11
+
12
+ host = webxi_helper.set_host(__file__)
13
+ # sequence_names = ["LAeq"]
14
+ cpb_sequence_names = ["CPBLAeq"]
15
+
16
+
17
+ sequenceID= SequenceIdEnums.CPBLAeq.value
18
+
19
+ class PrintHandler(DataHandler):
20
+ def handle(self, value, **data ):
21
+ print(f"{value}")
22
+
23
+
24
+ class FigureHandler:
25
+
26
+ def __init__(self, dataHandler):
27
+ self.dataHandler = dataHandler
28
+ self.fig, self.ax = plt.subplots(1,1, figsize=(10,5))
29
+ self.CPBFreq = dataHandler.calcFreqBands()
30
+ self.freq = [(i.replace("000.0","k")).replace(".0", "") for i in [str(i) for i in self.CPBFreq]]
31
+ self.ln = self.ax.bar(self.freq, np.zeros(len(self.freq)), width=.99)
32
+ self.ax.set_ylim(bottom=-20, top=120)
33
+ self.ax.grid(axis='y')
34
+ self.ax.set_ylabel("dB [SPL]")
35
+ self.ax.set_xlabel("Frequency band [Hz]")
36
+ self.fig.autofmt_xdate()
37
+ self.fig.tight_layout()
38
+ self.fig.canvas.mpl_connect('close_event', on_close)
39
+
40
+ def _update(self, i):
41
+ for rect, h in zip(self.ln.patches, self.dataHandler.CPB_values):
42
+ rect.set_height(h)
43
+
44
+ def startAnimation(self):
45
+ self.ani = FuncAnimation(self.fig, self._update, interval=1000)
46
+
47
+ def on_close(event):
48
+ streamer.stopStream()
49
+ streamer.data_handler.close()
50
+
51
+
52
+ if __name__ == "__main__":
53
+ # turns off all CPB freq weights
54
+ webxi_helper.turn_off_CPB_freq_weight(host)
55
+
56
+ # turns on the CPB freq weight we want to use, in this case A weight
57
+ webxi_helper.turn_on_CPB_freq_weight(host, ["A"])
58
+
59
+ # turns on the CPB eq we want to use
60
+ webxi_helper.turn_on_cpb_leq(host, cpb_sequence_names)
61
+
62
+ streamer = WebXiStreamHandler(host,
63
+ sequenceID=sequenceID,
64
+ mode="cpb",
65
+ sequenceNames=cpb_sequence_names,
66
+ saving_path=r"./saved_data/test_file",
67
+ saving="json")
68
+ # streamer.setDataHandler(JsonDataHandler(r"C:\Users\SKREBSVINGAA\csv_test\csv_test.txt"))
69
+ streamer.setDataHandler(PrintHandler())
70
+
71
+ fig = FigureHandler(streamer)
72
+ threading.Thread(target=streamer.startStream, daemon=True).start()
73
+ fig.startAnimation()
74
+ plt.show()
slm_api/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Top-level package for slm_api (submodules are not auto-imported)."""
2
+
3
+
4
+ def main() -> None:
5
+ print("Hello from open-api-package!")
@@ -0,0 +1,16 @@
1
+ from enum import Enum
2
+
3
+ class FastLogInterval(Enum):
4
+ """ControlBBFastLoggingInterval enum indices (member value = device index, name = ms/sample)."""
5
+ interval_1ms = 0
6
+ interval_2ms = 1
7
+ interval_4ms = 2
8
+ interval_8ms = 3
9
+ interval_16ms = 4
10
+ interval_32ms = 5
11
+ interval_63ms = 6
12
+ interval_125ms = 7
13
+ interval_250ms = 8
14
+ interval_500ms = 9
15
+ interval_1000ms = 10
16
+
@@ -0,0 +1,352 @@
1
+ from enum import Enum
2
+
3
+ class SequenceIdEnums(Enum):
4
+ MeasurementCounter = 0
5
+ ElapsedTime = 1
6
+ StartTime = 2
7
+ LatchedOverload = 3
8
+ Overload = 4
9
+ Underrange = 5
10
+
11
+ LAeq = 6
12
+ LCeq = 7
13
+ LZeq = 8
14
+ LBeq = 9
15
+
16
+ LAIeq = 11
17
+
18
+ LAFmax = 12
19
+ LCFmax = 13
20
+ LZFmax = 14
21
+ LBFmax = 15
22
+
23
+ LASmax = 16
24
+ LCSmax = 17
25
+ LZSmax = 18
26
+ LBSmax = 19
27
+
28
+ LAImax = 20
29
+
30
+ LAFmin = 21
31
+ LCFmin = 22
32
+ LZFmin = 23
33
+ LBFmin = 24
34
+
35
+ LASmin = 25
36
+ LCSmin = 26
37
+ LZSmin = 27
38
+ LBSmin = 28
39
+
40
+ LApeak = 29
41
+ LCpeak = 30
42
+ LZpeak = 31
43
+ LBpeak = 32
44
+
45
+ LAFTeq = 34
46
+
47
+ CPBLAeq = 35
48
+ CPBLCeq = 36
49
+ CPBLZeq = 37
50
+ CPBLBeq = 38
51
+
52
+ CPBLAFmax = 40
53
+ CPBLCFmax = 41
54
+ CPBLZFmax = 42
55
+ CPBLBFmax = 43
56
+
57
+ CPBLASmax = 45
58
+ CPBLCSmax = 46
59
+ CPBLZSmax = 47
60
+ CPBLBSmax = 48
61
+
62
+ CPBLAFmin = 50
63
+ CPBLCFmin = 51
64
+ CPBLZFmin = 52
65
+ CPBLBFmin = 53
66
+
67
+ CPBLASmin = 55
68
+ CPBLCSmin = 56
69
+ CPBLZSmin = 57
70
+ CPBLBSmin = 58
71
+
72
+ LAF250ms = 60
73
+ LCF250ms = 61
74
+ LZF250ms = 62
75
+ LBF250ms = 63
76
+
77
+ LAS250ms = 64
78
+ LCS250ms = 65
79
+ LZS250ms = 66
80
+ LBS250ms = 67
81
+
82
+ LAF = 68
83
+ LCF = 69
84
+ LZF = 70
85
+ LBF = 71
86
+
87
+ LAS = 72
88
+ LCS = 73
89
+ LZS = 74
90
+ LBS = 75
91
+
92
+ CPBLAF = 76
93
+ CPBLCF = 77
94
+ CPBLZF = 78
95
+ CPBLBF = 79
96
+
97
+ CPBLAS = 81
98
+ CPBLCS = 82
99
+ CPBLZS = 83
100
+ CPBLBS = 84
101
+
102
+ LavS4 = 86
103
+ LavS5 = 87
104
+
105
+ L10 = 90
106
+
107
+ LAE = 91
108
+ LCE = 92
109
+ LZE = 93
110
+ LBE = 94
111
+
112
+ LApeak1s = 96
113
+ LCpeak1s = 97
114
+ LZpeak1s = 98
115
+ LBpeak1s = 99
116
+
117
+ LN1 = 101
118
+ LN2 = 102
119
+ LN3 = 103
120
+ LN4 = 104
121
+ LN5 = 105
122
+ CPBLN1 = 106
123
+ CPBLN2 = 107
124
+ CPBLN3 = 108
125
+ CPBLN4 = 109
126
+ CPBLN5 = 110
127
+
128
+ FastLAeq = 111
129
+ FastLCeq = 112
130
+ FastLZeq = 113
131
+ FastLBeq = 114
132
+
133
+ FastLAF = 115
134
+ FastLCF = 116
135
+ FastLZF = 117
136
+ FastLBF = 118
137
+
138
+ FastLAS = 119
139
+ FastLCS = 120
140
+ FastLZS = 121
141
+ FastLBS = 122
142
+
143
+ FastCPBLAeq = 123
144
+ FastCPBLCeq = 124
145
+ FastCPBLZeq = 125
146
+ FastCPBLBeq = 126
147
+
148
+ FastCPBLAF = 127
149
+ FastCPBLCF = 128
150
+ FastCPBLZF = 129
151
+ FastCPBLBF = 130
152
+
153
+ FastCPBLAS = 131
154
+ FastCPBLCS = 132
155
+ FastCPBLZS = 133
156
+ FastCPBLBS = 134
157
+
158
+ LAS125ms = 135
159
+ LCS125ms = 136
160
+ LZS125ms = 137
161
+ LBS125ms = 138
162
+
163
+ StopTime = 140
164
+
165
+ Latitude = 141
166
+ Longitude = 142
167
+ SerialNumber = 143
168
+ HWVersion = 144
169
+ SWVersion = 145
170
+ TimeZoneGMT = 146
171
+ Transducer = 147
172
+ Sensitivity = 148
173
+ Calibrated = 149
174
+ NoneValue = 150
175
+
176
+ LoggingIntervalTime = 151
177
+ BBFastLoggingIntervalTime = 152
178
+ CPBFastLoggingIntervalTime = 153
179
+ # Special enums for Sound Encoding
180
+ MP3PeriodTime = 154
181
+ FLACPeriodTime = 155
182
+ MP3Signal = 156
183
+ FLACSignal = 157
184
+
185
+ LAFSPL = 158
186
+ LCFSPL = 159
187
+ LZFSPL = 160
188
+ LBFSPL = 161
189
+ LASSPL = 162
190
+ LCSSPL = 163
191
+ LZSSPL = 164
192
+ LBSSPL = 165
193
+
194
+ LAI = 166
195
+ LAI250ms = 167
196
+ Altitude = 168
197
+ LatitudePrecision = 169
198
+ LongitudePrecision = 170
199
+ AltitudePrecision = 171
200
+ SLMTime = 172
201
+ CPBLAeq2nd = 173
202
+ CPBLCeq2nd = 174
203
+ CPBLZeq2nd = 175
204
+ CPBLBeq2nd = 176
205
+
206
+ CPBLAFmax2nd = 178
207
+ CPBLCFmax2nd = 179
208
+ CPBLZFmax2nd = 180
209
+ CPBLBFmax2nd = 181
210
+
211
+ CPBLASmax2nd = 183
212
+ CPBLCSmax2nd = 184
213
+ CPBLZSmax2nd = 185
214
+ CPBLBSmax2nd = 186
215
+
216
+ CPBLAFmin2nd = 188
217
+ CPBLCFmin2nd = 189
218
+ CPBLZFmin2nd = 190
219
+ CPBLBFmin2nd = 191
220
+
221
+ CPBLASmin2nd = 193
222
+ CPBLCSmin2nd = 194
223
+ CPBLZSmin2nd = 195
224
+ CPBLBSmin2nd = 196
225
+
226
+ CPBLAF2nd = 198
227
+ CPBLCF2nd = 199
228
+ CPBLZF2nd = 200
229
+ CPBLBF2nd = 201
230
+
231
+ CPBLAS2nd = 203
232
+ CPBLCS2nd = 204
233
+ CPBLZS2nd = 205
234
+ CPBLBS2nd = 206
235
+
236
+ StatLAeq = 208
237
+ StatLAF = 209
238
+ StatLAS = 210
239
+ StatCPBLAF = 211
240
+ StatCPBLCF = 212
241
+ StatCPBLZF = 213
242
+ StatCPBLBF = 214
243
+
244
+ StatCPBLAS = 216
245
+ StatCPBLCS = 217
246
+ StatCPBLZS = 218
247
+ StatCPBLBS = 219
248
+
249
+ BBStatLoggingIntervalTime = 221
250
+ CPBStatLoggingIntervalTime = 222
251
+
252
+ WindDirection = 223
253
+ WindSpeed = 224
254
+ WindDirectionAvg = 225
255
+ WindDirectionMin = 226
256
+ WindDirectionMax = 227
257
+ WindSpeedAvg = 228
258
+ WindSpeedMin = 229
259
+ WindSpeedMax = 230
260
+ Temperature = 231
261
+ Humidity = 232
262
+ Pressure = 233
263
+ Rainfall = 234
264
+
265
+ CICStatus = 235
266
+ CIC125Hz = 236
267
+ CIC1000Hz = 237
268
+ CIC4000Hz = 238
269
+ CPBEDT = 239
270
+ CPBT20 = 240
271
+ CPBT30 = 241
272
+ LAeqTaiSIL = 242
273
+ LCeqTaiSIL = 243
274
+ LZeqTaiSIL = 244
275
+ LBeqTaiSIL = 245
276
+
277
+ StatCPBLAeq = 247
278
+ StatCPBLCeq = 248
279
+ StatCPBLZeq = 249
280
+ StatCPBLBeq = 250
281
+
282
+ GeneratorOnSamplesStart = 252
283
+ FastCPBLAeq2nd = 253
284
+ FastCPBLCeq2nd = 254
285
+ FastCPBLZeq2nd = 255
286
+ FastCPBLBeq2nd = 256
287
+ FastCPBLAF2nd = 257
288
+ FastCPBLCF2nd = 258
289
+ FastCPBLZF2nd = 259
290
+ FastCPBLBF2nd = 260
291
+ FastCPBLAS2nd = 261
292
+ FastCPBLCS2nd = 262
293
+ FastCPBLZS2nd = 263
294
+ FastCPBLBS2nd = 264
295
+ GeneratorOnSamplesEnd = 265
296
+ DecayLength = 266
297
+ StdDev = 267
298
+ CICRunning = 268
299
+ LinearVibration = 269
300
+ PeakVibration = 270
301
+ Peak1sVibration = 271
302
+ FmaxVibration = 272
303
+ SmaxVibration = 273
304
+ FminVibration = 274
305
+ SminVibration = 275
306
+ TPeakVibration = 276
307
+ PeakPeakVibration = 277
308
+ CrestfactorVibration = 278
309
+ FVibration = 279
310
+ SVibration = 280
311
+ FVibration250ms = 281
312
+ SVibration250ms = 282
313
+ CPBLinearVibration = 283
314
+ CPBFmaxVibration = 284
315
+ CPBSmaxVibration = 285
316
+ CPBFminVibration = 286
317
+ CPBSminVibration = 287
318
+ CPBFVibration = 288
319
+ CPBSVibration = 289
320
+ FastLinearVibration = 290
321
+ FastFVibration = 291
322
+ FastSVibration = 292
323
+ FastCPBLinearVibration = 293
324
+ FastCPBFVibration = 294
325
+ FastCPBSVibration = 295
326
+ LinearVibration2nd = 296
327
+ PeakVibration2nd = 297
328
+ Peak1sVibration2nd = 298
329
+ FmaxVibration2nd = 299
330
+ SmaxVibration2nd = 300
331
+ FminVibration2nd = 301
332
+ SminVibration2nd = 302
333
+ TPeakVibration2nd = 303
334
+ PeakPeakVibration2nd = 304
335
+ CrestfactorVibration2nd = 305
336
+ FVibration2nd = 306
337
+ SVibration2nd = 307
338
+ FVibration250ms2nd = 308
339
+ SVibration250ms2nd = 309
340
+ LAeqMov = 310
341
+ LAeqMovMax = 311
342
+ LCeqMov = 312
343
+ LCeqMovMax = 313
344
+ LAeqMov2nd = 314
345
+ LAeqMovMax2nd = 315
346
+ LCeqMov2nd = 316
347
+ LCeqMovMax2nd = 317
348
+ DeltaLeqMov = 318
349
+ DeltaLeqMovMax = 319
350
+ DeltaLeqMov2nd = 320
351
+ DeltaLeqMovMax2nd = 321
352
+ ScreenImage = 322
@@ -0,0 +1,78 @@
1
+ # This example will show how to stream multiple sequences at the same time using the same stream
2
+ # For this example enable the wanted sequences on the device
3
+ import threading
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+ from matplotlib.animation import FuncAnimation
7
+
8
+ from slm_api.helpers import webxi_helper_functions as webxi_helper
9
+ from slm_api.helpers import stream_handlers as sh
10
+ from slm_api.helpers.data_handler import DataHandler, MultiDataHandler
11
+
12
+ # UseHttps(use_https=False)
13
+
14
+ host = webxi_helper.set_host(__file__)
15
+
16
+ # This example will stream LAeq. Add more names to the list to plot several sequences at once.
17
+ # Incase of error make sure the sequences are enabled on the SLM.
18
+ sequenceNames = ["LAeq", "LCeq", "LAF"]
19
+
20
+ class PrintHandler(DataHandler):
21
+ def handle(self, *, name, value, **data):
22
+ print(f"{name}: {value}")
23
+
24
+
25
+ class FigHandler(DataHandler):
26
+ """Plot raw multi-sequence values received from the stream."""
27
+
28
+ def __init__(self, sequence_names, buffer_size=101):
29
+ self.buffers = {
30
+ name: np.full(buffer_size, np.nan)
31
+ for name in sequence_names
32
+ }
33
+ self.fig, self.ax = plt.subplots(1,1)
34
+ axis = np.arange(-(buffer_size - 1), 1, 1)
35
+ self.ln = []
36
+ for name in sequence_names:
37
+ self.ln.append((self.ax.plot(axis, self.buffers[name], label=name))[0])
38
+ self.ax.set_xlim(left=np.min(axis), right=np.max(axis))
39
+ self.ax.set_ylim(bottom=00, top=100)
40
+ self.ax.set_xlabel("Time [s]")
41
+ self.ax.set_ylabel("dB [SPL]")
42
+ self.ax.set_title('Instantaneous')
43
+ self.ax.grid()
44
+ self.fig.autofmt_xdate()
45
+ self.fig.tight_layout()
46
+ self.fig.canvas.mpl_connect('close_event', on_close)
47
+ self.fig.canvas.setWindowTitle('LAeq example')
48
+
49
+ def handle(self, *, name, value, **data):
50
+ self.buffers[name] = np.append(self.buffers[name][1:], value)
51
+
52
+ def _update(self, i):
53
+ for line, name in zip(self.ln, sequenceNames):
54
+ line.set_ydata(self.buffers[name])
55
+
56
+ def startAnimation(self):
57
+ self.ani = FuncAnimation(self.fig, self._update, interval=1000)
58
+
59
+
60
+ def on_close(event):
61
+ streamer.stopStream()
62
+
63
+ if __name__ == "__main__":
64
+ # turns off all BB freq weights to prevent interference
65
+ webxi_helper.turn_off_bb_freq_weight(host)
66
+
67
+ # turns on the wanted BB freq weights for this example
68
+ webxi_helper.turn_on_bb_freq_weight(host, ["A", "C"])
69
+
70
+ # sets the sequences to true. You can add or remove sequences at the top of the file.
71
+ webxi_helper.turn_on_bb_leq(host, sequenceNames)
72
+
73
+ streamer = sh.WebXiStreamHandler(host=host, sequenceNames=sequenceNames, mode="multi", saving="json", saving_path=f"./saved_data/test")
74
+ fig = FigHandler(sequenceNames)
75
+ streamer.setDataHandler(MultiDataHandler(PrintHandler(), fig))
76
+ fig.startAnimation()
77
+ threading.Thread(target=streamer.startStream, daemon=True).start()
78
+ plt.show()
@@ -0,0 +1,172 @@
1
+ """
2
+ 18. Stream FastLAF (Sequence 115)
3
+ -----------------------------------
4
+ Streams the FastLAF (LAeq) broadband Leq value from sequence 115
5
+ and pretty-prints each received value to the terminal.
6
+
7
+ Sequence 115 properties:
8
+ Name: FastLAF
9
+ LocalName: LAeq
10
+ FunctionType: BroadbandLeq
11
+ DataType: Int16
12
+ Scale: 0.01
13
+ Weighting: A
14
+ AveragingMode: Linear
15
+ Unit: dB re 20uPa
16
+ """
17
+
18
+ import asyncio
19
+ import time
20
+ import requests
21
+ from datetime import datetime
22
+
23
+ # Modules to convert webxi data
24
+ import slm_api.webxi.webxi_stream as webxiStream
25
+
26
+ # Reuse existing help functions
27
+ import slm_api.helpers.stream_handler as stream
28
+ import slm_api.helpers.measurment_handler as meas
29
+ import slm_api.helpers.sequence_handler as seq
30
+ import slm_api.helpers.websocket_handler as webSocket
31
+ from slm_api.helpers.stream_handlers import WebXiStreamHandler
32
+ from slm_api.helpers.data_handler import DataHandler
33
+
34
+ from slm_api.helpers.stream_handler import *
35
+ from slm_api.helpers import webxi_helper_functions as webxi_helper
36
+ # enums
37
+ from slm_api.enums.sequence_id_enum import SequenceIdEnums
38
+ from slm_api.enums.fast_log_intervals_enum import FastLogInterval
39
+
40
+ # ---------- Configuration ----------
41
+ host = webxi_helper.set_host(__file__)
42
+
43
+
44
+ SCALE = 0.01 # Raw Int16 value * SCALE = dB
45
+
46
+ # WebXi header timestamps are 64-bit fixed-point seconds since the Unix epoch
47
+ # (Q32.32): upper 32 bits = whole seconds, lower 32 bits = fraction of a second.
48
+ WEBXI_TICKS_PER_SECOND = 2 ** 32
49
+
50
+
51
+ FAST_LOGGING_INTERVAL_MS = FastLogInterval.interval_1000ms.value
52
+ SEQUENCE_ID = SequenceIdEnums.FastLAF.value
53
+
54
+ class PrintDataHandler(DataHandler):
55
+ def handle(self, timestamp, name, local, value, unit):
56
+ print(f"{timestamp}{name} ({local}): {value:7.2f} {unit}")
57
+
58
+
59
+
60
+ # def webxi_time_to_epoch(header_time):
61
+ # """Convert a WebXi header time (Q32.32 fixed-point) to Unix epoch seconds."""
62
+ # return header_time / WEBXI_TICKS_PER_SECOND
63
+
64
+
65
+ # def get_fast_logging_interval_s(host):
66
+ # """Read the configured broadband fast-logging interval and return it in seconds."""
67
+ # enum = requests.get(host + "/WebXi/Applications/SLM/Setup/ControlBBFastLoggingInterval").json()
68
+ # if enum not in FAST_LOGGING_INTERVAL_MS:
69
+ # raise ValueError(f"Unexpected ControlBBFastLoggingInterval value: {enum!r}")
70
+ # return FAST_LOGGING_INTERVAL_MS[enum] / 1000.0
71
+
72
+
73
+ # def get_sequence_info(host, sequence_id):
74
+ # """Fetch and validate sequence 115 from the device."""
75
+ # seq_id, sequence = seq.get_sequence(host, sequence_id)
76
+ # return seq_id, sequence
77
+
78
+
79
+ # def print_data(message, seq_id, sequence, interval_s):
80
+ # """Decode a websocket message and pretty-print each value with its own timestamp."""
81
+ # package = webxiStream.WebxiStream.from_bytes(message)
82
+ # if package.header.message_type != webxiStream.WebxiStream.Header.EMessageType.e_sequence_data:
83
+ # return
84
+
85
+ # # The header time is the time of the first sample; fall back to wall clock if
86
+ # # it is not in the expected Q32.32 format/epoch.
87
+ # start = webxi_time_to_epoch(package.header.time)
88
+ # if abs(start - time.time()) > 86400:
89
+ # start = time.time()
90
+
91
+ # # A 1-second package batches many fast-logged samples.
92
+ # samples = []
93
+ # for block in package.content.sequence_blocks:
94
+ # if block.sequence_id != seq_id:
95
+ # continue
96
+ # # Determine vector length from sequence metadata or byte count
97
+ # vector_length = sequence.get("VectorLength", None)
98
+ # if vector_length is None and sequence["DataType"] == "Int16":
99
+ # vector_length = len(block.values) // 2
100
+ # raw = stream.data_type_conv(sequence["DataType"], block.values, vector_length if vector_length and vector_length > 1 else None)
101
+ # if isinstance(raw, list):
102
+ # samples.extend(v * SCALE for v in raw)
103
+ # else:
104
+ # samples.append(raw * SCALE)
105
+
106
+ # if not samples:
107
+ # return
108
+
109
+ # name = sequence.get('Name', 'FastLAeq')
110
+ # local = sequence.get('LocalName', 'LAeq')
111
+ # unit = sequence.get('Unit', 'dB re 20uPa')
112
+ # for n, v in enumerate(samples):
113
+ # timestamp = datetime.fromtimestamp(start + n * interval_s).strftime("%H:%M:%S.%f")[:-3]
114
+ # print(f"[{timestamp}] {name} ({local}): {v:7.2f} {unit}")
115
+ # print(f" >> {len(samples)} sample(s) in this rx block")
116
+
117
+
118
+ # async def main():
119
+ # # Retrieve sequence metadata from device
120
+ # seq_id, sequence = get_sequence_info(host, SEQUENCE_ID)
121
+
122
+ # interval_s = get_fast_logging_interval_s(host)
123
+
124
+ # print("=" * 60)
125
+ # print(f" Streaming: {sequence.get('Name', 'FastLAeq')}")
126
+ # print(f" Sequence: {SEQUENCE_ID}")
127
+ # print(f" Weighting: {sequence.get('AcousticalWeighting', 'A')}")
128
+ # print(f" Unit: {sequence.get('Unit', 'dB re 20uPa')}")
129
+ # print(f" Interval: {interval_s * 1000:.0f} ms/sample")
130
+ # print("=" * 60)
131
+
132
+ # STREAM_NAME = "FastLAeqStream"
133
+
134
+ # # Setup websocket stream for sequence 115
135
+ # uri = stream.setup_stream(host, [seq_id], STREAM_NAME)
136
+
137
+ # # Start measurement (no-op if already running)
138
+ # meas.start_pause_measurement(host, True)
139
+
140
+ # # Stream and print values until interrupted (Ctrl+C)
141
+ # msg_func = lambda msg: print_data(msg, seq_id, sequence, interval_s)
142
+ # try:
143
+ # await webSocket.next_async_websocket(uri, msg_func)
144
+ # finally:
145
+ # # Delete the stream from the device
146
+ # stream_id = stream.get_stream_ID(host, STREAM_NAME)
147
+ # if stream_id is not None:
148
+ # response = requests.delete(f"{host}/WebXi/Streams/{stream_id}")
149
+ # print(f"\nStream deleted (status {response.status_code})")
150
+
151
+
152
+ if __name__ == "__main__":
153
+
154
+ try:
155
+ streamer = WebXiStreamHandler(host,
156
+ sequenceID = SEQUENCE_ID,
157
+ mode="fast_logging",
158
+ fast_logging_interval=FAST_LOGGING_INTERVAL_MS,
159
+ saving="csv",
160
+ saving_path=r"C:\Users\SKREBSVINGAA\csv_test\csv_test.txt")
161
+ streamer.setDataHandler(PrintDataHandler())
162
+
163
+
164
+ streamer.startStream()
165
+ # asyncio.run(main())
166
+ except KeyboardInterrupt:
167
+ # streamID = get_stream_ID(host, streamer.streamName)
168
+ streamer.data_handler.close()
169
+ delete_stream(host, streamer.streamName)
170
+ meas.stop_measurement(host)
171
+ print("\nStream stopped by user.")
172
+