Support override of tx_complete

This commit is contained in:
Alex Forencich
2021-01-04 22:42:53 -08:00
parent aa97848450
commit a73c0b734e
2 changed files with 12 additions and 8 deletions

View File

@@ -55,21 +55,23 @@ class GmiiFrame:
else:
self.data = bytearray(data)
self.error = error
if tx_complete is not None:
self.tx_complete = tx_complete
@classmethod
def from_payload(cls, payload, min_len=60):
def from_payload(cls, payload, min_len=60, tx_complete=None):
payload = bytearray(payload)
if len(payload) < min_len:
payload.extend(bytearray(min_len-len(payload)))
payload.extend(struct.pack('<L', zlib.crc32(payload)))
return cls.from_raw_payload(payload)
return cls.from_raw_payload(payload, tx_complete=tx_complete)
@classmethod
def from_raw_payload(cls, payload):
def from_raw_payload(cls, payload, tx_complete=None):
data = bytearray(ETH_PREAMBLE)
data.extend(payload)
return cls(data)
return cls(data, tx_complete=tx_complete)
def get_preamble_len(self):
return self.data.index(EthPre.SFD)+1