uC chip interface arduino  0.9.0
A interface for async and neuromrphic IC testing
Loading...
Searching...
No Matches
packet.py
Go to the documentation of this file.
2# This file is part of the Firmware project to interface with small Async or Neuromorphic chips
3# Copyright (C) 2022-2023 Ole Richter - University of Groningen
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18
19import logging
20import struct
21from .header import *
22
23
24class Packet:
25 """
26 Packet class to be used as a base class for all packets acting as an interface.
27 it contains the static method from_bytearray to construct a packet from a bytearray
28 and chooses the correct packet type depending on the header
29 """
30 def __init__(self):
31 self._header = 0
32 self._exec_time = 0
33 self.check_and_log()
34
35 @classmethod
36 def from_bytearray(cls, byte_array):
37 """ method to construct a packet from a bytearray
38 depending on the header the correct packet type is returned
39 @param byte_array: (bytearray) the bytearray to construct the packet from
40 @return: the constructed packet of the coresponing sub type
41 """
42 try:
43 unpacked = struct.unpack("<BII", byte_array)
44 # from pyhton 3.12 the in operator can be used to do the same check
45 # until then:
46 try:
47 header = Data32bitHeader(unpacked[0]);
48 logging.debug("detected: Data32bit : "+ str(header))
49 return Data32bitPacket.from_bytearray(byte_array)
50 except ValueError:
51 try:
52 header = DataI2CHeader(unpacked[0]);
53 logging.debug("detected: DataI2C : "+ str(header))
54 return DataI2CPacket.from_bytearray(byte_array)
55 except ValueError:
56 try:
57 header = PinHeader(unpacked[0]);
58 logging.debug("detected: Pin : "+ str(header))
59 return PinPacket.from_bytearray(byte_array)
60 except ValueError:
61 try:
62 header = ConfigMainHeader(unpacked[0]);
63 logging.debug("detected: Config Main : "+ str(header))
64 return ConfigPacket.from_bytearray(byte_array)
65 except ValueError:
66 try:
67 header = ErrorHeader(unpacked[0]);
68 logging.debug("detected: Error : "+ str(header))
69 return ErrorPacket.from_bytearray(byte_array)
70 except ValueError:
71 logging.error("Header "+ str(unpacked[0]) +" is not a valid header, Packet:" + str(byte_array) +" "+ str(unpacked[0]) +" "+ str(unpacked[1]) +" "+ str(unpacked[2]))
72 raise ValueError("Header "+ str(unpacked[0]) +" is not a valid header")
73 except Exception as e:
74 logging.error(e)
75 def header(self):
76 """getter method for the header attribute
77
78 :return: the header of the packet
79 :rtype: EnumInt entry or int
80 """
81 return self._header
82 def time(self):
83 """getter method for the time attribute
84
85 :return: the time of execution of the packet
86 :rtype: EnumInt entry or int
87 """
88 return self._exec_time
89
90 def set_header(self, header):
91 """setter method for the header attribute
92 @param header: (byte/uint_8) the header of the packet
93 """
94 if (header < 256 and header >= 0 and isinstance(header, int)):
95 self._header=header
96 else:
97 logging.error("header "+str(header)+" is not a valid header")
98
99 def set_exec_time(self, time):
100 """setter method for the execution time attribute
101 @param time: (uint_32) the time of execution of the packet
102 """
103 if (time < 2**32 and time >= 0 and isinstance(time, int)):
104 self._exec_time=time
105 else:
106 logging.error("exec_time "+str(time)+" is not a valid unsigned integer of 4 bytes")
107
108 def to_bytearray(self):
109 """ placeholder for converting the package to a bytearray
110 @return: the packet as a bytearray
111 """
112 logging.warning("the method to_bytearray needs to be implemented by the child class")
113
114 def check_and_log(self):
115 """check_and_log
116 logs the packet if the header is in the logging lists
117 """
118 if self._header in LOGGING_WARNING_LIST:
119 logging.warning(str(self))
120 if self._header in LOGGING_INFO_LIST:
121 logging.info(str(self))
122 #if self._header in LOGGING_ERROR_LIST:
123 # logging.error(str(self))
124
126 """ The Data32bitPacket is used to send 32bit data instructions to the uC
127 all availible instructions are defined in the Data32bitHeader
128 """
129
130 def __init__(self, header, value=0, time=0):
131 """ constructor for the Data32bitPacket
132 @param header: (Data32bitHeader) the header of the packet
133 @param value: (uint_32) the value to be sent (optional, default = 0)
134 @param time: (uint_32) the time of execution of the packet (optional, default = 0)
135 """
136 self.set_headerset_header(header)
137 self.set_value(value)
138 self.set_exec_time(time)
139 self.check_and_log()
140
141 def value(self):
142 """ getter method for the value attribute
143 @return: the value of the packet
144 """
145 return self._value
146
147 def set_header(self, header):
148 if (header in Data32bitHeader):
149 self._header_header=header
150 else:
151 logging.error("header "+str(header)+" is not a valid header")
152
153 def set_value(self, value):
154 if (value < 2**32 and value >= 0 and isinstance(value, int)):
155 self._value=value
156 else:
157 logging.error("value "+str(value)+" is not a valid unsigned integer of 4 bytes")
158
159 def to_bytearray(self):
160 return struct.pack("<BII", self._header_header, self._exec_time, self._value)
161
162 def __str__(self):
163 return "[Packet]: data 32bit: header = "+ str(self._header_header) +", value = "+ str(self._value) + ", at time = "+ str(self._exec_time) +"us"
164
165 @classmethod
166 def from_bytearray(self, byte_array):
167 """
168 constructs a Data32bitPacket from a bytearray
169 @param byte_array: 9 byte bytearray to construct the Packet from
170 @return: Data32bitPacket
171 @raise Exception: if package construction fails
172 """
173 unpacked = struct.unpack("<BII", byte_array)
174 return Data32bitPacket(header=Data32bitHeader(unpacked[0]),
175 value = unpacked[2],
176 time = unpacked[1])
177
178
180 """ The DataI2CPacket is used for I2C communication
181 and all types which need 3x 8bit values instread of 1x 32bit value
182 all availible instructions are defined in the DataI2CHeader
183 """
184 def __init__(self, header, device_address, register_address, read=False, value=0, time=0):
185 self.set_headerset_header(header)
186 self.set_value(value)
187 self.set_exec_time(time)
188 self.set_device_address(device_address)
189 self.set_register_address(register_address)
190 self.set_read(read)
191 self.check_and_log()
192
193 def value(self):
194 """ getter method for the value attribute
195 @return: the value of the packet
196 """
197 return self._value_ls+ self._value_ms<<8
198
199 def read(self):
200 """ getter method for the 1bit read/write attribute
201 @return: the read flag of the i2c packet
202 """
203 return self._read
204
205 def device_address(self):
206 """ getter method for the 7bit device_address attribute
207 @return: the device_address of the i2c packet
208 """
209 return self._device_address
210
212 """ getter method for the 8bit register_address attribute
213 @return: the register_address of the i2c packet
214 """
215 return self._register_address
216
217 def set_header(self, header):
218 """ setter method for the header attribute
219 @param header: (DataI2CHeader or uint8) the header of the packet
220 """
221 if (header in DataI2CHeader):
222 self._header_header=header
223 else:
224 logging.error("header "+str(header)+" is not a valid header")
225
226 def set_value(self, value):
227 """ setter method for the value attribute
228 @param value: (uint_16) the value to be sent
229 """
230 if (value < 2**16 and value >= 0 and isinstance(value, int)):
231 self._value_ls = value & 0xF
232 self._value_ms= value >> 8
233 else:
234 logging.error("value "+str(value)+" is not a valid unsigned integer of 2 byte")
235
236 def set_device_address(self, value):
237 """ setter method for the 7bit device address attribute
238 @param value: (uint_8) the 7bit device address to be sent to
239 """
240 if (value < 2**7 and value >= 0 and isinstance(value, int)):
241 self._device_address = value
242 else:
243 logging.error("device_address "+str(value)+" is not a valid unsigned integer of 7 bit")
244
245 def set_read(self, value):
246 """ setter method for the 1bit read/write attribute
247 @param value: (bool) the read flag of the i2c packet
248 """
249 if value:
250 self._read = 1
251 else:
252 self._read = 0
253 def set_register_address(self, value):
254 """ setter method for the 8bit register address attribute
255 @param value: (uint_8) the 8bit register address to be sent to
256 """
257 if (value < 2**8 and value >= 0 and isinstance(value, int)):
258 self._register_address = value
259 else:
260 logging.error("register_address "+str(value)+" is not a valid unsigned integer of 8 bit")
261 def to_bytearray(self):
262 """ method to convert the packet to a bytearray in the correct format of <header><exec_time><addess+read><value ms/ls>
263 @return: the packet as a bytearray
264 """
265 return struct.pack("<BIBBBB", self._header_header, self._exec_time, self._device_address<<1+self._read ,self._register_address,self._value_ms,self._value_ls)
266
267 def __str__(self):
268 return "[Packet]: data i2c: header = "+ str(self._header_header) +",device_address = "+ str(self._device_address) +",register address = "+ str(self._register_address) +",read = "+ str(self._read) +", value = "+ str(self._value_ls+(self._value_ms<<8)) + ", at time = "+ str(self._exec_time) +"us"
269
270 @classmethod
271 def from_bytearray(self, byte_array):
272 """
273 constructs a DataI2CPacket from a bytearray
274 @param byte_array: 9 byte bytearray to construct the Packet from
275 @return: DataI2CPacket
276 @raise Exception: if package construction fails
277 """
278 unpacked = struct.unpack("<BIBBBB", byte_array)
279 print(unpacked)
280 print((unpacked[4] << 8) | unpacked[5])
281 return DataI2CPacket(header=DataI2CHeader(unpacked[0]),
282 device_address=unpacked[2]>>1,
283 register_address=unpacked[3], read=unpacked[2] & 0x1, value=((unpacked[4] << 8) | unpacked[5]),
284 time = unpacked[1])
285
286
287"""
288value: (int) 0 to set pin LOW, 1 to set pin HIGH.
289"""
291 """ The PinPacket is used to comunicate pin instructions with the uC
292 all availible instructions are defined in the PinHeader
293 """
294 def __init__(self, header, pin_id, value=0, time=0):
295 """ constructor for the PinPacket
296 @param header: (PinHeader or UINT8) the header of the packet
297 @param pin_id: (uint_8) the pin id to be adressed
298 @param value: (uint_8) the value to be sent (optional, default = 0) - 0 to set pin LOW, (>=) 1 to set pin HIGH.
299 @param time: (uint_32) the time of execution of the packet (optional, default = 0)
300 """
301 self.set_headerset_header(header)
302 self.set_pin_id(pin_id)
303 self.set_value(value)
304 self.set_exec_time(time)
305 self.check_and_log()
306
307 def pin_id(self):
308 """ getter method for the pin_id attribute
309 @return: the pin_id of the pin
310 """
311 return self._pin_id
312
313 def value(self):
314 """ getter method for the value attribute
315 @return: the value of the pin
316 """
317 return self._value
318
319 def set_header(self, header):
320 """ setter method for the header attribute
321 @param header: (PinHeader or uint8) the header of the packet
322 """
323 if (header in PinHeader):
324 self._header_header=header
325 else:
326 logging.error("header "+str(header)+" is not a valid header")
327
328 def set_pin_id(self, pin_id):
329 """ setter method for the pin_id attribute
330 @param pin_id: (uint_8) the pin id to be adressed
331 """
332 if (pin_id < 55 and pin_id >= 0 and isinstance(pin_id, int)):
333 self._pin_id=pin_id
334 else:
335 logging.error("di "+str(pin_id)+" is not a valid unsigned integer of 1 byte + id < 55")
336
337
338 def set_value(self, value):
339 """ setter method for the pin value attribute
340 @param value: (uint_8) the value
341 """
342 if (value < 2**8 and value >= 0 and isinstance(value, int)):
343 self._value=value
344 else:
345 logging.error("value "+str(value)+" is not a valid unsigned integer of 1 byte")
346
347 def to_bytearray(self):
348 """ method to convert the packet to a bytearray in the correct format of <header><exec_time><pin_id><value>
349 @return: the packet as a bytearray
350 """
351 return struct.pack("<BIBBBB", self._header_header, self._exec_time, self._pin_id, self._value,0,0)
352
353 def __str__(self):
354 return "[Packet]: pin: header = "+ str(self._header_header) +", pin_id = "+ str(self._pin_id) + ", value = "+ str(self._value) + ", at time = "+ str(self._exec_time) +"us"
355
356 @classmethod
357 def from_bytearray(self, byte_array):
358 """
359 constructs a PinPacket from a bytearray
360 @param byte_array: 9 byte bytearray to construct the Packet from
361 @return: PinPacket
362 @raise Exception: if package construction fails
363 """
364 unpacked = struct.unpack("<BIBBBB", byte_array)
365 return PinPacket(header=PinHeader(unpacked[0]),
366 pin_id = unpacked[2],
367 value = unpacked[3],
368 time = unpacked[1])
369
370
371"""
372header: (ConfigMainHeader) what's to be configured (e.g. PIN, SPI,...).
373config_header: (ConfigSubHeader) configuration properties.
374"""
376 """ The ConfigPacket is used to cumunicate configuration instructions with the uC
377 all availible instructions are defined in the ConfigMainHeader and ConfigSubHeader
378 """
379 def __init__(self, header, config_header, value=0, time=0):
380 self.set_headerset_header(header)
381 self.set_config_header(config_header)
382 self.set_value(value)
383 self.set_exec_time(time)
384 self.check_and_log()
385
386 def value(self):
387 """ getter method for the value attribute
388 @return: the value
389 """
390 return self._value
391
392 def config_header(self):
393 """ getter method for the sub instruction config_header attribute
394 @return: the config_sub_header
395 """
396 return self._config_header
397
398 def set_header(self, header):
399 """ setter method for the header attribute
400 @param header: (ConfigMainHeader or uint8) the header of the packet
401 """
402 if (header in ConfigMainHeader):
403 self._header_header=header
404 else:
405 logging.error("header "+str(header)+" is not a valid header")
406
407 def set_config_header(self, config_header):
408 """ setter method for the sub instruction config_header attribute
409 @param config_header: (ConfigSubHeader or uint8) the config_sub_header
410 """
411 if (config_header in ConfigSubHeader):
412 self._config_header=config_header
413 else:
414 logging.error("config sub header "+str(header)+" is not a valid header")
415
416 def set_value(self, value):
417 """ setter method for the value attribute
418 @param value: (uint_8) the value
419 """
420 if (value < 2**8 and value >= 0 and isinstance(value, int)):
421 self._value=value
422 else:
423 logging.error("value "+str(value)+" is not a valid unsigned integer of 1 byte")
424
425 def to_bytearray(self):
426 """ method to convert the packet to a bytearray in the correct format of <header><exec_time><config_header><value>
427 @return: the packet as a bytearray
428 """
429 return struct.pack("<BIBBBB", self._header_header, self._exec_time, self._config_header ,self._value,0,0)
430
431 def __str__(self):
432 return "[Packet]: config: header = "+ str(self._header_header) +", config = "+ str(self._config_header) + ", value = "+ str(self._value) + ", at time = "+ str(self._exec_time) +"us"
433
434 @classmethod
435 def from_bytearray(self, byte_array):
436 """
437 constructs a ConfigPacket from a bytearray
438 @param byte_array: 9 byte bytearray to construct the Packet from
439 @return: ConfigPacket
440 @raise Exception: if package construction fails
441 """
442 unpacked = struct.unpack("<BIBBBB", byte_array)
443 return ConfigPacket(header=ConfigMainHeader(unpacked[0]),
444 config_header = ConfigSubHeader(unpacked[2]),
445 value = unpacked[3],
446 time = unpacked[1])
447
448
449
451 """ The ErrorPacket is used by the uC to send errors to the API
452 all availible errors are defined in the ErrorHeader
453 """
454 def __init__(self, header, original_header, value=0, original_sub_header=0, skip_header_matching=False, print_errors=True):
455 """ constructor for the ErrorPacket
456 @param header: (ErrorHeader or uint8) the header indicating the error
457 @param original_header: (uint_8) the original header of the packet causing the error
458 @param value: (uint_32) the value associated (optional, default = 0)
459 @param original_sub_header: (uint_8) the original sub header causeing the error (optional, default = 0) in case of a config
460 @param skip_header_matching: (bool) if the causing headers should be converted into human readable objects (optional, default = False)
461 @param print_errors: (bool) if the error should be logged (optional, default = True)
462 """
463 self.set_headerset_header(header)
464 if self._header_header == ErrorHeader.OUT_ALIGN_SUCCESS_VERSION:
465 self.set_org_header(original_header, True)
466 self.set_value(value)
467 self.set_org_sub_header(original_sub_header, True)
468 else:
469 self.set_org_header(original_header)
470 self.set_org_sub_header(original_sub_header)
471 self.set_value(value)
472 if (print_errors):
473 logging.error(self.__str__())
474 self.check_and_log()
475
476 def value(self):
477 """ getter method for the value attribute
478 @return: the value
479 """
480 return self._value
481
483 """ getter method for the original header attribute
484 @return: the original header causing the error
485 """
486 return self._org_header
487
489 """ getter method for the original sub header attribute
490 @return: the original sub header causing the error
491 """
492 return self._org_sub_header
493
494 def set_header(self, header):
495 """ setter method for the header attribute
496 @param header: (ErrorHeader or uint8) the header indicating the error
497 """
498 if (header in ErrorHeader):
499 self._header_header=header
500 else:
501 logging.error("header "+str(header)+" is not a valid header")
502
503 def set_org_header(self, header, skip_header_matching=False):
504 """ setter method for the original header attribute
505 @param header: (uint_8) the original header of the packet causing the error
506 @param skip_header_matching: (bool) if the causing headers should be converted into human readable objects (optional, default = False)
507 """
508 if skip_header_matching:
509 self._org_header = header
510 else:
511 # find the header in human readable form
512 try:
513 self._org_header = Data32bitHeader(header);
514 except ValueError:
515 try:
516 self._org_header = DataI2CHeader(header);
517 except ValueError:
518 try:
519 self._org_header = PinHeader(header);
520 except ValueError:
521 try:
522 self._org_header = ConfigMainHeader(header);
523 except ValueError:
524 try:
525 self._org_header = ErrorHeader(header);
526 except ValueError:
527 logging.error("source Header "+ str(header) +" is not a valid header,")
528 self._org_header = None;
529
530 def set_org_sub_header(self, header,skip_header_matching=False):
531 """ setter method for the original sub header attribute
532 @param header: (uint_8) the original sub header causeing the error
533 @param skip_header_matching: (bool) if the causing headers should be converted into human readable objects (optional, default = False)
534 """
535 if skip_header_matching:
536 self._org_sub_header = header
537 else:
538 # find the header in human readable form, start with config sub header, and only if that fails try the other headers - not unique
539 try:
540 self._org_sub_header = ConfigSubHeader(header);
541 except ValueError:
542 try:
543 self._org_sub_header = Data32bitHeader(header);
544 except ValueError:
545 try:
546 self._org_sub_header = DataI2CHeader(header);
547 except ValueError:
548 try:
549 self._org_sub_header = PinHeader(header);
550 except ValueError:
551 try:
552 self._org_sub_header = ConfigMainHeader(header);
553 except ValueError:
554 try:
555 self._org_sub_header = ErrorHeader(header);
556 except ValueError:
557 logging.error("source Sub Header "+ str(header) +" is not a valid header,")
558 self._org_sub_header = None;
559
560
561 def set_value(self, value):
562 """ setter method for the value attribute
563 @param value: (uint_32) the value associated
564 """
565 if (value < 2**32 and value >= 0 and isinstance(value, int)):
566 self._value=value
567 else:
568 logging.error("value "+str(value)+" is not a valid unsigned integer of 1 byte")
569 def __str__(self):
570 return "[uC Error]: "+ str(self._header_header) +" caused by "+ str(self._org_header)+ " with value "+ str(self._value) + ": " + str(self._header_header.__doc__)
571
572 def to_bytearray(self):
573 """ method to convert the packet to a bytearray in the correct format of <header><exec_time><org_header><value><org_sub_header>
574 @return: the packet as a bytearray
575 """
576 return struct.pack("<BBIBBB", self._header_header, self._org_header, self._value,self._org_sub_header,0,0)
577
578 @classmethod
579 def from_bytearray(self, byte_array):
580 """
581 constructs a ErrorPacket from a bytearray
582 @param byte_array: 9 byte bytearray to construct the Packet from
583 @return: ErrorPacket
584 @raise Exception: if package construction fails
585 """
586 unpacked = struct.unpack("<BBIBBB", byte_array)
587 return ErrorPacket(header=ErrorHeader(unpacked[0]),
588 original_header = unpacked[1],
589 value = unpacked[2],
590 original_sub_header = unpacked[3])
591
ConfigMainHeader are all command headers used in ConfigPacket in conjunction with ConfigSubHeader.
Definition: header.py:389
ConfigSubHeader are all command headers used in ConfigPacket in conjunction with ConfigMainHeader.
Definition: header.py:688
Data32bitHeader are all command headers used in Data32bitPacket.
Definition: header.py:36
DataI2CHeader are all command headers used in DataI2CPacket.
Definition: header.py:324
ErrorHeader are all command headers used in ErrorPacket.
Definition: header.py:581
PinHeader are all command headers used in PinPacket.
Definition: header.py:277
The ConfigPacket is used to cumunicate configuration instructions with the uC all availible instructi...
Definition: packet.py:375
def config_header(self)
getter method for the sub instruction config_header attribute
Definition: packet.py:392
def value(self)
getter method for the value attribute
Definition: packet.py:386
def set_header(self, header)
setter method for the header attribute
Definition: packet.py:398
def to_bytearray(self)
method to convert the packet to a bytearray in the correct format of <header><exec_time><config_heade...
Definition: packet.py:425
def from_bytearray(self, byte_array)
constructs a ConfigPacket from a bytearray
Definition: packet.py:435
def set_value(self, value)
setter method for the value attribute
Definition: packet.py:416
def set_config_header(self, config_header)
setter method for the sub instruction config_header attribute
Definition: packet.py:407
def __init__(self, header, config_header, value=0, time=0)
Definition: packet.py:379
The Data32bitPacket is used to send 32bit data instructions to the uC all availible instructions are ...
Definition: packet.py:125
def value(self)
getter method for the value attribute
Definition: packet.py:141
def set_header(self, header)
setter method for the header attribute
Definition: packet.py:147
def to_bytearray(self)
placeholder for converting the package to a bytearray
Definition: packet.py:159
def from_bytearray(self, byte_array)
constructs a Data32bitPacket from a bytearray
Definition: packet.py:166
def set_value(self, value)
Definition: packet.py:153
def __init__(self, header, value=0, time=0)
constructor for the Data32bitPacket
Definition: packet.py:130
The DataI2CPacket is used for I2C communication and all types which need 3x 8bit values instread of 1...
Definition: packet.py:179
def set_read(self, value)
setter method for the 1bit read/write attribute
Definition: packet.py:245
def value(self)
getter method for the value attribute
Definition: packet.py:193
def set_header(self, header)
setter method for the header attribute
Definition: packet.py:217
def set_device_address(self, value)
setter method for the 7bit device address attribute
Definition: packet.py:236
def to_bytearray(self)
method to convert the packet to a bytearray in the correct format of <header><exec_time><addess+read>...
Definition: packet.py:261
def device_address(self)
getter method for the 7bit device_address attribute
Definition: packet.py:205
def read(self)
getter method for the 1bit read/write attribute
Definition: packet.py:199
def __init__(self, header, device_address, register_address, read=False, value=0, time=0)
Definition: packet.py:184
def from_bytearray(self, byte_array)
constructs a DataI2CPacket from a bytearray
Definition: packet.py:271
def register_address(self)
getter method for the 8bit register_address attribute
Definition: packet.py:211
def set_value(self, value)
setter method for the value attribute
Definition: packet.py:226
def set_register_address(self, value)
setter method for the 8bit register address attribute
Definition: packet.py:253
The ErrorPacket is used by the uC to send errors to the API all availible errors are defined in the E...
Definition: packet.py:450
def original_sub_header(self)
getter method for the original sub header attribute
Definition: packet.py:488
def __init__(self, header, original_header, value=0, original_sub_header=0, skip_header_matching=False, print_errors=True)
constructor for the ErrorPacket
Definition: packet.py:454
def set_org_header(self, header, skip_header_matching=False)
setter method for the original header attribute
Definition: packet.py:503
def value(self)
getter method for the value attribute
Definition: packet.py:476
def set_header(self, header)
setter method for the header attribute
Definition: packet.py:494
def set_org_sub_header(self, header, skip_header_matching=False)
setter method for the original sub header attribute
Definition: packet.py:530
def to_bytearray(self)
method to convert the packet to a bytearray in the correct format of <header><exec_time><org_header><...
Definition: packet.py:572
def from_bytearray(self, byte_array)
constructs a ErrorPacket from a bytearray
Definition: packet.py:579
def original_header(self)
getter method for the original header attribute
Definition: packet.py:482
def set_value(self, value)
setter method for the value attribute
Definition: packet.py:561
Packet class to be used as a base class for all packets acting as an interface.
Definition: packet.py:24
def set_header(self, header)
setter method for the header attribute
Definition: packet.py:90
def to_bytearray(self)
placeholder for converting the package to a bytearray
Definition: packet.py:108
def check_and_log(self)
check_and_log logs the packet if the header is in the logging lists
Definition: packet.py:114
def time(self)
getter method for the time attribute
Definition: packet.py:82
def from_bytearray(cls, byte_array)
method to construct a packet from a bytearray depending on the header the correct packet type is retu...
Definition: packet.py:36
def __init__(self)
Definition: packet.py:30
def set_exec_time(self, time)
setter method for the execution time attribute
Definition: packet.py:99
The PinPacket is used to comunicate pin instructions with the uC all availible instructions are defin...
Definition: packet.py:290
def pin_id(self)
getter method for the pin_id attribute
Definition: packet.py:307
def set_pin_id(self, pin_id)
setter method for the pin_id attribute
Definition: packet.py:328
def value(self)
getter method for the value attribute
Definition: packet.py:313
def __init__(self, header, pin_id, value=0, time=0)
constructor for the PinPacket
Definition: packet.py:294
def set_header(self, header)
setter method for the header attribute
Definition: packet.py:319
def to_bytearray(self)
method to convert the packet to a bytearray in the correct format of <header><exec_time><pin_id>
Definition: packet.py:347
def from_bytearray(self, byte_array)
constructs a PinPacket from a bytearray
Definition: packet.py:357
def set_value(self, value)
setter method for the pin value attribute
Definition: packet.py:338