Repository navigation
Expand file tree
/
Copy pathobject_spy_message.cpp
More file actions
576 lines (559 loc) · 29.3 KB
/
Copy pathobject_spy_message.cpp
File metadata and controls
576 lines (559 loc) · 29.3 KB
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#include "object_spy_message.h"
size_t spy_message_extra_data_length(const icsSpyMessage& msg)
{
if (msg.Protocol == SPY_PROTOCOL_A2B || msg.Protocol == SPY_PROTOCOL_ETHERNET ||
msg.Protocol == SPY_PROTOCOL_SPI || msg.Protocol == SPY_PROTOCOL_WBMS)
return (msg.NumberBytesHeader << 8) | msg.NumberBytesData;
return msg.NumberBytesData;
}
bool spy_message_validate_extra_data(const spy_message_object* obj)
{
if (obj->msg.ExtraDataPtr && spy_message_extra_data_length(obj->msg) > obj->extraDataCapacity) {
PyErr_SetString(PyExc_ValueError, "ExtraDataPtr length exceeds its buffer capacity");
return false;
}
return true;
}
void spy_message_record_received_extra_data(PyObject* o)
{
spy_message_object* obj = (spy_message_object*)o;
// The DLL owns the pointer; its original reported length is the readable bound.
obj->extraDataCapacity = obj->msg.ExtraDataPtr ? spy_message_extra_data_length(obj->msg) : 0;
obj->noExtraDataPtrCleanup = true;
}
static int spy_message_object_alloc(spy_message_object* self, PyObject* args, PyObject* kwds)
{
(void)args;
(void)kwds;
memset(&self->msg, 0, sizeof(self->msg));
self->noExtraDataPtrCleanup = false;
self->extraDataCapacity = 0;
return 0;
}
static void spy_message_object_dealloc(spy_message_object* self)
{
if ((!self->noExtraDataPtrCleanup && self->msg.ExtraDataPtrEnabled && self->msg.ExtraDataPtr != NULL) ||
(!self->noExtraDataPtrCleanup && self->msg.Protocol == SPY_PROTOCOL_ETHERNET &&
self->msg.ExtraDataPtr != NULL)) {
// Clean up the ExtraDataPtr if we can
// Ethernet protocol uses the ExtraDataPtrEnabled reversed internally so do a double check here
delete[] (unsigned char*)self->msg.ExtraDataPtr;
self->msg.ExtraDataPtr = NULL;
self->msg.ExtraDataPtrEnabled = 0;
}
Py_TYPE(self)->tp_free((PyObject*)self);
}
// Validates that value is a tuple of at most max_length ints and copies the
// elements into dest. Returns the tuple length, or -1 with an exception set.
// dest is only written on success.
static Py_ssize_t _copy_byte_tuple(PyObject* value, PyObject* attr_name, unsigned char* dest, Py_ssize_t max_length)
{
if (!PyTuple_Check(value)) {
PyErr_Format(PyExc_AttributeError,
"'%.50s' object attribute '%U' needs to be a tuple",
MODULE_NAME "." SPY_MESSAGE_OBJECT_NAME,
attr_name);
return -1;
}
Py_ssize_t length = PyTuple_Size(value);
if (length > max_length) {
PyErr_Format(
PyExc_ValueError, "'%U' accepts at most %zd bytes (got %zd)", attr_name, max_length, length);
return -1;
}
unsigned char temp[8] = { 0 };
for (Py_ssize_t i = 0; i < length; ++i) {
PyObject* item = PyTuple_GetItem(value, i);
if (!item)
return -1;
long byte = PyLong_AsLong(item);
if (byte == -1 && PyErr_Occurred())
return -1;
temp[i] = (unsigned char)byte;
}
memcpy(dest, temp, (size_t)length);
return length;
}
static PyObject* spy_message_object_getattr(PyObject* o, PyObject* attr_name)
{
#if PY_MAJOR_VERSION >= 3
if (!PyUnicode_Check(attr_name)) {
#else
if (!PyString_Check(attr_name)) {
#endif
PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", attr_name->ob_type->tp_name);
return NULL;
}
if (PyUnicode_CompareWithASCIIString(attr_name, "Data") == 0) {
spy_message_object* obj = (spy_message_object*)o;
PyObject* temp = Py_BuildValue("(i,i,i,i,i,i,i,i)",
obj->msg.Data[0],
obj->msg.Data[1],
obj->msg.Data[2],
obj->msg.Data[3],
obj->msg.Data[4],
obj->msg.Data[5],
obj->msg.Data[6],
obj->msg.Data[7]);
PyObject* data = PyTuple_GetSlice(temp, 0, obj->msg.NumberBytesData);
Py_DECREF(temp);
return data;
} else if (PyUnicode_CompareWithASCIIString(attr_name, "AckBytes") == 0) {
spy_message_object* obj = (spy_message_object*)o;
return Py_BuildValue("(i,i,i,i,i,i,i,i)",
obj->msg.AckBytes[0],
obj->msg.AckBytes[1],
obj->msg.AckBytes[2],
obj->msg.AckBytes[3],
obj->msg.AckBytes[4],
obj->msg.AckBytes[5],
obj->msg.AckBytes[6],
obj->msg.AckBytes[7]);
} else if (PyUnicode_CompareWithASCIIString(attr_name, "Header") == 0) {
spy_message_j1850_object* obj = (spy_message_j1850_object*)o;
PyObject* temp =
Py_BuildValue("(i,i,i,i)", obj->msg.Header[0], obj->msg.Header[1], obj->msg.Header[2], obj->msg.Header[3]);
PyObject* data = PyTuple_GetSlice(temp, 0, obj->msg.NumberBytesHeader);
Py_DECREF(temp);
return data;
} else if (PyUnicode_CompareWithASCIIString(attr_name, "ExtraDataPtr") == 0) {
if (!spy_message_validate_extra_data((spy_message_object*)o))
return NULL;
spy_message_j1850_object* obj = (spy_message_j1850_object*)o;
unsigned char* ExtraDataPtr = (unsigned char*)obj->msg.ExtraDataPtr;
bool extra_data_ptr_enabled = obj->msg.ExtraDataPtrEnabled != 0;
// Ethernet protocol uses the ExtraDataPtrEnabled reversed internally
if ((obj->msg.Protocol == SPY_PROTOCOL_ETHERNET ||
obj->msg.Protocol == SPY_PROTOCOL_SPI ||
obj->msg.Protocol == SPY_PROTOCOL_WBMS)
&& obj->msg.ExtraDataPtr != NULL) {
extra_data_ptr_enabled = true;
}
size_t actual_size = spy_message_extra_data_length(((spy_message_object*)o)->msg);
if (extra_data_ptr_enabled && actual_size && obj->msg.ExtraDataPtr) {
PyObject* tuple = PyTuple_New(actual_size);
for (int i = 0; i < actual_size; ++i) {
PyTuple_SET_ITEM(tuple, i, PyLong_FromLong(ExtraDataPtr[i]));
}
return tuple;
} else {
Py_RETURN_NONE;
}
} else {
return PyObject_GenericGetAttr(o, attr_name);
}
}
static int spy_message_object_setattr_impl(PyObject* o, PyObject* name, PyObject* value)
{
// tp_setattro receives NULL for deletion. Let descriptors reject deletion
// before any custom setter inspects the value or changes message storage.
if (value == NULL)
return PyObject_GenericSetAttr(o, name, value);
spy_message_object* obj = (spy_message_object*)o;
if (PyUnicode_CompareWithASCIIString(name, "Data") == 0) {
Py_ssize_t length = _copy_byte_tuple(value, name, obj->msg.Data, sizeof(obj->msg.Data));
if (length < 0)
return -1;
obj->msg.NumberBytesData = static_cast<uint8_t>(length);
return 0;
} else if (PyUnicode_CompareWithASCIIString(name, "AckBytes") == 0) {
if (_copy_byte_tuple(value, name, obj->msg.AckBytes, sizeof(obj->msg.AckBytes)) < 0)
return -1;
return 0;
} else if (PyUnicode_CompareWithASCIIString(name, "Header") == 0) {
spy_message_j1850_object* j1850_obj = (spy_message_j1850_object*)obj;
Py_ssize_t length = _copy_byte_tuple(value, name, j1850_obj->msg.Header, sizeof(j1850_obj->msg.Header));
if (length < 0)
return -1;
obj->msg.NumberBytesHeader = static_cast<uint8_t>(length);
return 0;
} else if (PyUnicode_CompareWithASCIIString(name, "ExtraDataPtr") == 0) {
if (!PyTuple_Check(value)) {
PyErr_Format(PyExc_AttributeError,
"'%.50s' object attribute '%U' needs to be a tuple",
MODULE_NAME "." SPY_MESSAGE_OBJECT_NAME,
name);
return -1;
}
// Some newer protocols are packing the length into NumberBytesHeader also so lets handle it here...
bool packs_length = obj->msg.Protocol == SPY_PROTOCOL_A2B || obj->msg.Protocol == SPY_PROTOCOL_ETHERNET ||
obj->msg.Protocol == SPY_PROTOCOL_SPI || obj->msg.Protocol == SPY_PROTOCOL_WBMS;
Py_ssize_t length = PyTuple_Size(value);
Py_ssize_t max_length = packs_length ? 0xFFFF : 0xFF;
if (length > max_length) {
PyErr_Format(PyExc_ValueError,
"'%U' accepts at most %zd bytes for this protocol (got %zd)",
name,
max_length,
length);
return -1;
}
// Validate and copy into a fresh buffer before touching the message.
unsigned char* buffer = new unsigned char[length > 0 ? (size_t)length : 1];
for (Py_ssize_t i = 0; i < length; ++i) {
PyObject* data = PyTuple_GetItem(value, i);
long byte = data ? PyLong_AsLong(data) : -1;
if (!data || (byte == -1 && PyErr_Occurred())) {
delete[] buffer;
return -1;
}
buffer[i] = (unsigned char)byte;
}
// Never delete[] a buffer this extension didn't allocate (e.g. DLL-owned
// pointers on received messages flagged with noExtraDataPtrCleanup).
if (obj->msg.ExtraDataPtr != NULL && !obj->noExtraDataPtrCleanup)
delete[] (unsigned char*)obj->msg.ExtraDataPtr;
obj->msg.ExtraDataPtr = buffer;
obj->extraDataCapacity = (size_t)length;
if (packs_length)
obj->msg.NumberBytesHeader = static_cast<uint8_t>(length >> 8);
obj->msg.NumberBytesData = static_cast<uint8_t>(length & 0xFF);
if (obj->msg.Protocol != SPY_PROTOCOL_ETHERNET)
obj->msg.ExtraDataPtrEnabled = 1;
obj->noExtraDataPtrCleanup = false;
return 0;
} else if (PyUnicode_CompareWithASCIIString(name, "ExtraDataPtrEnabled") == 0) {
long enabled = PyLong_AsLong(value);
if (enabled == -1 && PyErr_Occurred()) {
PyErr_Clear(); // let PyObject_GenericSetAttr report the type error
return PyObject_GenericSetAttr(o, name, value);
}
// Make sure we clean up here so we don't memory leak
if ((!obj->noExtraDataPtrCleanup && enabled != 1 && obj->msg.ExtraDataPtrEnabled == 1) ||
(!obj->noExtraDataPtrCleanup && enabled != 1 && obj->msg.Protocol == SPY_PROTOCOL_ETHERNET)) {
if (obj->msg.ExtraDataPtr != NULL) {
delete[] (unsigned char*)obj->msg.ExtraDataPtr;
obj->msg.ExtraDataPtr = NULL;
obj->extraDataCapacity = 0;
}
} else if (enabled != 0 && obj->msg.Protocol == SPY_PROTOCOL_ETHERNET) {
// Ethernet always needs to be set to 0
return 0;
}
return PyObject_GenericSetAttr(o, name, value);
} else {
return PyObject_GenericSetAttr(o, name, value);
}
}
static int spy_message_object_setattr(PyObject* o, PyObject* name, PyObject* value)
{
// Subclass deletion descriptors may execute Python. Never include them in
// a native-message rollback transaction.
if (!value)
return PyObject_GenericSetAttr(o, name, value);
// These assignments can reinterpret or enlarge the payload length. Roll back
// the complete native message, including Data/Header bytes, on failure.
bool scalar_length = PyUnicode_CompareWithASCIIString(name, "NumberBytesData") == 0 ||
PyUnicode_CompareWithASCIIString(name, "NumberBytesHeader") == 0 ||
PyUnicode_CompareWithASCIIString(name, "Protocol") == 0;
bool data = PyUnicode_CompareWithASCIIString(name, "Data") == 0;
bool header = PyUnicode_CompareWithASCIIString(name, "Header") == 0;
bool changes_length = scalar_length || data || header;
// __index__ can execute arbitrary Python, including replacing the payload.
// Finish all such conversions BEFORE snapshotting the message for rollback.
PyObject* normalized = NULL;
if (value && scalar_length) {
normalized = PyNumber_Index(value);
if (!normalized)
return -1;
long byte = PyLong_AsLong(normalized);
if ((byte == -1 && PyErr_Occurred()) || byte < 0 || byte > 255) {
Py_DECREF(normalized);
if (!PyErr_Occurred())
PyErr_SetString(PyExc_ValueError, "Message length and protocol fields must be in range 0..255");
return -1;
}
// Reject truncation rather than letting T_UBYTE issue a warning inside
// the transaction: a user warning hook can also replace the payload.
} else if (value && (data || header) && PyTuple_Check(value) &&
PyTuple_Size(value) <= (data ? 8 : 4)) {
normalized = PyTuple_New(PyTuple_Size(value));
if (!normalized)
return -1;
for (Py_ssize_t i = 0; i < PyTuple_Size(value); ++i) {
PyObject* byte = PyNumber_Index(PyTuple_GetItem(value, i));
if (!byte) {
Py_DECREF(normalized);
return -1;
}
PyTuple_SET_ITEM(normalized, i, byte);
}
}
spy_message_object* obj = (spy_message_object*)o;
icsSpyMessage original = obj->msg;
int result = 0;
if (scalar_length) {
// These native fields, like Data/Header, must not dispatch subclass
// descriptors inside the transaction: they can replace/free payloads.
unsigned char byte = (unsigned char)PyLong_AsLong(normalized);
if (PyUnicode_CompareWithASCIIString(name, "NumberBytesData") == 0)
obj->msg.NumberBytesData = byte;
else if (PyUnicode_CompareWithASCIIString(name, "NumberBytesHeader") == 0)
obj->msg.NumberBytesHeader = byte;
else {
obj->msg.Protocol = byte;
if (byte == SPY_PROTOCOL_ETHERNET)
obj->msg.ExtraDataPtrEnabled = 0;
}
} else {
result = spy_message_object_setattr_impl(o, name, normalized ? normalized : value);
}
Py_XDECREF(normalized);
if (result == 0 && changes_length && obj->msg.ExtraDataPtr &&
spy_message_extra_data_length(obj->msg) > obj->extraDataCapacity) {
// Restore before allocating the exception: cyclic-GC finalizers may
// execute Python during allocation and must see the committed state.
obj->msg = original;
PyErr_SetString(PyExc_ValueError, "ExtraDataPtr length exceeds its buffer capacity");
return -1;
}
return result;
}
static PyMemberDef spy_message_object_members[] = {
{ "StatusBitField", T_UINT, offsetof(spy_message_object, msg.StatusBitField), 0, "StatusBitField" },
{ "StatusBitField2", T_UINT, offsetof(spy_message_object, msg.StatusBitField2), 0, "StatusBitField2" },
{ "TimeHardware",
T_UINT,
offsetof(spy_message_object, msg.TimeHardware),
0,
"Hardware time stamp. The TimeStamp is reset on device open" },
{ "TimeHardware2",
T_UINT,
offsetof(spy_message_object, msg.TimeHardware2),
0,
"Hardware time stamp. The TimeStamp is reset on device open" },
{ "TimeSystem",
T_UINT,
offsetof(spy_message_object, msg.TimeSystem),
0,
"TimeSystem is loaded with the value received from the timeGetTime call in the WIN32 multimedia API." },
{ "TimeSystem2",
T_UINT,
offsetof(spy_message_object, msg.TimeSystem2),
0,
"TimeSystem is loaded with the value received from the timeGetTime call in the WIN32 multimedia API." },
{ "TimeStampHardwareID",
T_UBYTE,
offsetof(spy_message_object, msg.TimeStampHardwareID),
0,
"This is an identifier of what type of hardware timestamp is used. Since neoVI's timestamp is always the same, "
"this doesn't change." },
{ "TimeStampSystemID",
T_UBYTE,
offsetof(spy_message_object, msg.TimeStampSystemID),
0,
"This is an identifier of what type of system timestamp is used. Since WIN32 neoVI's timestamp is always the "
"same, "
"from the timeGetTime API, this doesn't change." },
{ "NetworkID",
T_UBYTE,
offsetof(spy_message_object, msg.NetworkID),
0,
"This value is used to identify which network this message was received on." },
{ "NodeID", T_UBYTE, offsetof(spy_message_object, msg.NodeID), 0, "Not Used" },
{ "Protocol",
T_UBYTE,
offsetof(spy_message_object, msg.Protocol),
0,
"Valid values are SPY_PROTOCOL_CAN, SPY_PROTOCOL_J1850VPW, and SPY_PROTOCOL_ISO9141." },
{ "MessagePieceID", T_UBYTE, offsetof(spy_message_object, msg.MessagePieceID), 0, "Not Used" },
{ "ExtraDataPtrEnabled", T_UBYTE, offsetof(spy_message_object, msg.ExtraDataPtrEnabled), 0, "" },
{ "NumberBytesHeader",
T_UBYTE,
offsetof(spy_message_object, msg.NumberBytesHeader),
0,
" Used for J1850/ISO messages. It indicates how many bytes are stored in the Header(1 to 4) array." },
{ "NumberBytesData",
T_UBYTE,
offsetof(spy_message_object, msg.NumberBytesData),
0,
"Holds the number of bytes in the Data(1 to 8) array or the number of bytes in a CAN remote frame (The DLC)." },
{ "NetworkID2",
T_UBYTE,
offsetof(spy_message_object, msg.NetworkID2),
0,
"This value is used to identify which network this message was received on." },
{ "DescriptionID", T_SHORT, offsetof(spy_message_object, msg.DescriptionID), 0, "Not Used" },
{ "ArbIDOrHeader", T_UINT, offsetof(spy_message_object, msg.ArbIDOrHeader), 0, "" },
// Data, AckBytes and ExtraDataPtr are handled by tp_getattro/tp_setattro;
// a member entry here would expose a descriptor that reinterprets raw
// struct memory as a PyObject*.
{ "StatusBitField3", T_UINT, offsetof(spy_message_object, msg.StatusBitField3), 0, "StatusBitField3" },
{ "StatusBitField4", T_UINT, offsetof(spy_message_object, msg.StatusBitField4), 0, "StatusBitField4" },
{ "MiscData", T_UBYTE, offsetof(spy_message_object, msg.MiscData), 0, "" },
{ "noExtraDataPtrCleanup",
T_BOOL,
offsetof(spy_message_object, noExtraDataPtrCleanup),
0,
"Tells Python to not clean up ExtraDataPtrMemory, If this is enabled. Ignore, if unsure." },
{ NULL, 0, 0, 0, NULL },
};
static PyMemberDef spy_message_j1850_object_members[] = {
{ "StatusBitField", T_UINT, offsetof(spy_message_j1850_object, msg.StatusBitField), 0, "StatusBitField" },
{ "StatusBitField2", T_UINT, offsetof(spy_message_j1850_object, msg.StatusBitField2), 0, "StatusBitField2" },
{ "TimeHardware",
T_UINT,
offsetof(spy_message_j1850_object, msg.TimeHardware),
0,
"Hardware time stamp. The TimeStamp is reset on device open" },
{ "TimeHardware2",
T_UINT,
offsetof(spy_message_j1850_object, msg.TimeHardware2),
0,
"Hardware time stamp. The TimeStamp is reset on device open" },
{ "TimeSystem",
T_UINT,
offsetof(spy_message_j1850_object, msg.TimeSystem),
0,
"TimeSystem is loaded with the value received from the timeGetTime call in the WIN32 multimedia API." },
{ "TimeSystem2",
T_UINT,
offsetof(spy_message_j1850_object, msg.TimeSystem2),
0,
"TimeSystem is loaded with the value received from the timeGetTime call in the WIN32 multimedia API." },
{ "TimeStampHardwareID",
T_UBYTE,
offsetof(spy_message_j1850_object, msg.TimeStampHardwareID),
0,
"This is an identifier of what type of hardware timestamp is used. Since neoVI's timestamp is always the same, "
"this doesn't change." },
{ "TimeStampSystemID",
T_UBYTE,
offsetof(spy_message_j1850_object, msg.TimeStampSystemID),
0,
"This is an identifier of what type of system timestamp is used. Since WIN32 neoVI's timestamp is always the "
"same, "
"from the timeGetTime API, this doesn't change." },
{ "NetworkID",
T_UBYTE,
offsetof(spy_message_j1850_object, msg.NetworkID),
0,
"This value is used to identify which network this message was received on." },
{ "NodeID", T_UBYTE, offsetof(spy_message_j1850_object, msg.NodeID), 0, "Not Used" },
{ "Protocol",
T_UBYTE,
offsetof(spy_message_j1850_object, msg.Protocol),
0,
"Valid values are SPY_PROTOCOL_CAN, SPY_PROTOCOL_J1850VPW, and SPY_PROTOCOL_ISO9141." },
{ "MessagePieceID", T_UBYTE, offsetof(spy_message_j1850_object, msg.MessagePieceID), 0, "Not Used" },
{ "ExtraDataPtrEnabled", T_UBYTE, offsetof(spy_message_j1850_object, msg.ExtraDataPtrEnabled), 0, "" },
{ "NumberBytesHeader",
T_UBYTE,
offsetof(spy_message_j1850_object, msg.NumberBytesHeader),
0,
" Used for J1850/ISO messages. It indicates how many bytes are stored in the Header(1 to 4) array." },
{ "NumberBytesData",
T_UBYTE,
offsetof(spy_message_j1850_object, msg.NumberBytesData),
0,
"Holds the number of bytes in the Data(1 to 8) array or the number of bytes in a CAN remote frame (The DLC)." },
{ "NetworkID2",
T_UBYTE,
offsetof(spy_message_j1850_object, msg.NetworkID2),
0,
"This value is used to identify which network this message was received on." },
{ "DescriptionID", T_SHORT, offsetof(spy_message_j1850_object, msg.DescriptionID), 0, "Not Used" },
// Header, Data, AckBytes and ExtraDataPtr are handled by
// tp_getattro/tp_setattro; a member entry here would expose a descriptor
// that reinterprets raw struct memory as a PyObject*.
{ "StatusBitField3", T_UINT, offsetof(spy_message_j1850_object, msg.StatusBitField3), 0, "StatusBitField3" },
{ "StatusBitField4", T_UINT, offsetof(spy_message_j1850_object, msg.StatusBitField4), 0, "StatusBitField4" },
{ "MiscData", T_UBYTE, offsetof(spy_message_j1850_object, msg.MiscData), 0, "" },
{ "noExtraDataPtrCleanup",
T_BOOL,
offsetof(spy_message_j1850_object, noExtraDataPtrCleanup),
0,
"Tells Python to not clean up ExtraDataPtrMemory, If this is enabled. Ignore, if unsure." },
{ NULL, 0, 0, 0, NULL },
};
PyTypeObject spy_message_object_type = {
PyVarObject_HEAD_INIT(NULL, 0) MODULE_NAME "." SPY_MESSAGE_OBJECT_NAME, /* tp_name */
sizeof(spy_message_object), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)spy_message_object_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
spy_message_object_getattr, /* tp_getattro */
spy_message_object_setattr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
SPY_MESSAGE_OBJECT_NAME " object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
spy_message_object_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)spy_message_object_alloc, /* tp_init */
};
PyTypeObject spy_message_j1850_object_type = {
PyVarObject_HEAD_INIT(NULL, 0) MODULE_NAME "." SPY_MESSAGE_J1850_OBJECT_NAME, /* tp_name */
sizeof(spy_message_j1850_object), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)spy_message_object_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
spy_message_object_getattr, /* tp_getattro */
spy_message_object_setattr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
SPY_MESSAGE_J1850_OBJECT_NAME " object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
spy_message_j1850_object_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)spy_message_object_alloc, /* tp_init */
};
bool setup_spy_message_object(PyObject* module)
{
// spy_message_object_type.ob_type = &PyType_Type;
spy_message_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready(&spy_message_object_type) < 0) {
return false;
}
Py_INCREF(&spy_message_object_type);
PyModule_AddObject(module, SPY_MESSAGE_OBJECT_NAME, (PyObject*)&spy_message_object_type);
spy_message_j1850_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready(&spy_message_j1850_object_type) < 0) {
return false;
}
Py_INCREF(&spy_message_j1850_object_type);
PyModule_AddObject(module, SPY_MESSAGE_J1850_OBJECT_NAME, (PyObject*)&spy_message_j1850_object_type);
return true;
}