-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwfm.py
278 lines (244 loc) · 8.23 KB
/
wfm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
from ctypes import *
from enum import IntEnum
class WfmHdrSetType(IntEnum):
SINGLE_WAVEFORM = 0
FASTFRAME = 1
class WfmHdrDataType(IntEnum):
SCALAR_MEAS = 0
SCALAR_CONST = 1
VECTOR = 2
INVALID = 4
WFMDB = 5
DIGITAL = 6
class WfmHdrSummaryFrame(IntEnum):
OFF = 0
AVERAGE = 1
ENVELOPE = 2
class WfmHdrPixmapDsyFormat(IntEnum):
INVALID = 0
YT = 1
XY = 2
XYZ = 3
class WfmExpDimDescInfoFormat(IntEnum):
INT16 = 0
INT32 = 1
UINT32 = 2
UINT64 = 3
FP32 = 4
FP64 = 5
# WFM v.3 exclusive from here on
UINT8 = 6 # INVALID_FORMAT in other versions
INT8 = 7
UNKNOWN = 8
INVALID_FORMAT = 9
class WfmExpDimDescInfoStorageType(IntEnum):
SAMPLE = 0
MIN_MAX = 1
VERT_HIST = 2
HOR_HIST = 3
ROW_ORDER = 4
COLUMN_ORDER = 5
INVALID_STORAGE = 6
class WfmExpDimDescInfoNullValue(Union):
_pack_ = 1
_fields_ = [
('sRange', c_int16),
('lRange', c_int32),
('fRange', c_float),
]
class WfmTimeBaseInfoSweep(IntEnum):
ROLL = 0
SAMPLE = 1
ET = 2
INVALID = 3
class WfmTimeBaseInfoType(IntEnum):
TIME = 0
SPECTRAL_MAG = 1
SPECTRAL_PHASE = 2
INVALID = 3
class WfmCurveSpecChecksumType(IntEnum):
NO_CHECKSUM = 0
CRC16 = 1
SUM16 = 2
CRC32 = 3
SUM32 = 4
class WfmStaticFileInfo(Structure):
_pack_ = 1
_fields_ = [
('ByteOrderVerification', c_uint16),
('VersionNumber', c_char * 8),
('ByteCountDigits', c_uint8),
('BytesRemaining', c_int32),
('BytesPerPoint', c_uint8),
('CurveBufferOffset', c_int32),
('HorizontalZoomScaleFactor', c_int32),
('HorizontalZoomPosition', c_float),
('VerticalZoomScaleFactor', c_double),
('VerticalZoomPosition', c_float),
('Label', c_char * 32),
('NFastFrames', c_uint32),
('HdrSize', c_uint16),
]
class WfmReferenceFileData(Structure):
_pack_ = 1
_fields_ = [
('_SetType', c_uint32),
('WfmCnt', c_uint32),
('AcquisitionCounter', c_uint64),
('TransactionCounter', c_uint64),
('SlotID', c_uint32),
('IsStatic', c_int32),
('UpdateSpecCount', c_uint32),
('ImpDimRefCount', c_uint32),
('ExpDimRefCount', c_uint32),
('_DataType', c_uint32),
('GeneralPurposeCounter', c_uint64),
('AccumulatedWfmCount', c_uint32),
('TargetAccumulationCount', c_uint32),
('CurveRefCount', c_uint32),
('NFastFramesRequested', c_uint32),
('NFastFramesAcquired', c_uint32),
('_SummaryFrame', c_uint16),
('_PixmapDsyFormat', c_uint32),
('PixmapMaxValue', c_uint64),
]
@property
def SetType(self):
return WfmHdrSetType(self._SetType)
@property
def DataType(self):
return WfmHdrDataType(self._DataType)
@property
def SummaryFrame(self):
return WfmHdrSummaryFrame(self._SummaryFrame)
@property
def PixmapDsyFormat(self):
return WfmHdrPixmapDsyFormat(self._PixmapDsyFormat)
class WfmDimUserView(Structure):
_pack_ = 1
_fields_ = [
('Scale', c_double),
('Units', c_char * 20),
('Offset', c_double),
('PointDensity', c_double),
('HRef', c_double),
('TrigDelay', c_double),
]
class WfmExpDim(Structure):
_pack_ = 1
_fields_ = [
('Scale', c_double),
('Offset', c_double),
('Size', c_uint32),
('Units', c_char * 20),
('ExtentMin', c_double),
('ExtentMax', c_double),
('Resolution', c_double),
('RefPoint', c_double),
('_Format', c_uint32),
('_StorageType', c_uint32),
('NullValue', WfmExpDimDescInfoNullValue),
('OverRange', c_uint32),
('UnderRange', c_uint32),
('HighRange', c_uint32),
('LowRange', c_uint32),
('UserView', WfmDimUserView),
]
@property
def Format(self):
return WfmExpDimDescInfoFormat(self._Format)
@property
def StorageType(self):
return WfmExpDimDescInfoStorageType(self._StorageType)
class WfmImpDim(Structure):
_pack_ = 1
_fields_ = [
('Scale', c_double),
('Offset', c_double),
('Size', c_uint32),
('Units', c_char * 20),
('ExtentMin', c_double),
('ExtentMax', c_double),
('Resolution', c_double),
('RefPoint', c_double),
('Spacing', c_int32),
('UserView', WfmDimUserView),
]
class WfmTimeBaseInfo(Structure):
_pack_ = 1
_fields_ = [
('RealPointSpacing', c_uint32),
('_Sweep', c_uint32),
('_Type', c_uint32),
]
@property
def Sweep(self):
return WfmTimeBaseInfoSweep(self._Sweep)
@property
def Type(self):
return WfmTimeBaseInfoType(self._Type)
class WfmUpdateSpec(Structure):
_pack_ = 1
_fields_ = [
('RealPointOffset', c_uint32),
('TTOffset', c_double),
('FracSec', c_double),
('GMTSec', c_int32),
]
class WfmCurveSpec(Structure):
_pack_ = 1
_fields_ = [
('StateFlags', c_uint32),
('_ChecksumType', c_uint32),
('Checksum', c_int16),
('PrechargeStart', c_uint32),
('DataStart', c_uint32),
('PostchargeStart', c_uint32),
('PostchargeStop', c_uint32),
('CurveBufferEnd', c_uint32),
]
@property
def ChecksumType(self):
return WfmCurveSpecChecksumType(self._ChecksumType)
class WfmHdr(Structure):
_pack_ = 1
_fields_ = [
('Ref', WfmReferenceFileData),
('ExpDim1', WfmExpDim),
('ExpDim2', WfmExpDim),
('ImpDim1', WfmImpDim),
('ImpDim2', WfmImpDim),
('TimeBaseInfo1', WfmTimeBaseInfo),
('TimeBaseInfo2', WfmTimeBaseInfo),
('UpdateSpec', WfmUpdateSpec),
('CurveSpec', WfmCurveSpec),
]
class WfmFastFrames(Structure):
_pack_ = 1
_fields_ = [
# len = StaticFileInfo.NFastFrames
('UpdateSpecs', POINTER(WfmUpdateSpec)),
# len = StaticFileInfo.NFastFrames
('CurveSpecs', POINTER(WfmCurveSpec)),
]
# TODO wrap with class that has OOB
class Wfm(Structure):
_pack_ = 1
_fields_ = [
('_Static', POINTER(WfmStaticFileInfo)),
('_Hdr', POINTER(WfmHdr)),
('_FastFrames', POINTER(WfmFastFrames)),
# len = (StaticFileInfo.NFastFrames + 1) * Hdr.CurveSpec.PostchargeStop
('CurveBuffer', c_char_p),
('Checksum', c_uint64),
('Size', c_uint64),
]
@property
def Static(self) -> WfmStaticFileInfo:
return self._Static.contents
@property
def Hdr(self) -> WfmHdr:
return self._Hdr.contents
@property
def FastFrames(self) -> WfmFastFrames:
return self._FastFrames.contents