some simplifications
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
__javascript__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
|
||||||
|
|||||||
+9
-7
@@ -38,6 +38,8 @@ class TinyFrame:
|
|||||||
|
|
||||||
self.reset_parser()
|
self.reset_parser()
|
||||||
|
|
||||||
|
self._CKSUM_BYTES = None # will be updated on first compose / accept
|
||||||
|
|
||||||
def reset_parser(self):
|
def reset_parser(self):
|
||||||
# parser state: SOF, ID, LEN, TYPE, HCK, PLD, PCK
|
# parser state: SOF, ID, LEN, TYPE, HCK, PLD, PCK
|
||||||
self.ps = 'SOF'
|
self.ps = 'SOF'
|
||||||
@@ -50,8 +52,7 @@ class TinyFrame:
|
|||||||
# received frame
|
# received frame
|
||||||
self.rf = TF_Msg()
|
self.rf = TF_Msg()
|
||||||
|
|
||||||
@property
|
def _calc_cksum_bytes(self):
|
||||||
def _CKSUM_BYTES(self):
|
|
||||||
if self.CKSUM_TYPE == 'none' or self.CKSUM_TYPE is None:
|
if self.CKSUM_TYPE == 'none' or self.CKSUM_TYPE is None:
|
||||||
return 0
|
return 0
|
||||||
elif self.CKSUM_TYPE == 'xor':
|
elif self.CKSUM_TYPE == 'xor':
|
||||||
@@ -84,10 +85,6 @@ class TinyFrame:
|
|||||||
else:
|
else:
|
||||||
raise Exception("Bad cksum type!")
|
raise Exception("Bad cksum type!")
|
||||||
|
|
||||||
@property
|
|
||||||
def _SOF_BYTES(self):
|
|
||||||
return 1 if self.USE_SOF_BYTE else 0
|
|
||||||
|
|
||||||
def _gen_frame_id(self):
|
def _gen_frame_id(self):
|
||||||
"""
|
"""
|
||||||
Get a new frame ID
|
Get a new frame ID
|
||||||
@@ -131,9 +128,11 @@ class TinyFrame:
|
|||||||
|
|
||||||
frame_id can be an ID of an existing session, None for a new session.
|
frame_id can be an ID of an existing session, None for a new session.
|
||||||
"""
|
"""
|
||||||
|
if self._CKSUM_BYTES is None:
|
||||||
|
self._CKSUM_BYTES = self._calc_cksum_bytes()
|
||||||
|
|
||||||
if pld is None:
|
if pld is None:
|
||||||
pld = b''
|
pld = bytearray()
|
||||||
|
|
||||||
if id is None:
|
if id is None:
|
||||||
id = self._gen_frame_id()
|
id = self._gen_frame_id()
|
||||||
@@ -165,6 +164,9 @@ class TinyFrame:
|
|||||||
def accept_byte(self, b):
|
def accept_byte(self, b):
|
||||||
# TODO this seems ripe for rewrite to avoid repetitive code
|
# TODO this seems ripe for rewrite to avoid repetitive code
|
||||||
|
|
||||||
|
if self._CKSUM_BYTES is None:
|
||||||
|
self._CKSUM_BYTES = self._calc_cksum_bytes()
|
||||||
|
|
||||||
if self.ps == 'SOF':
|
if self.ps == 'SOF':
|
||||||
if self.USE_SOF_BYTE:
|
if self.USE_SOF_BYTE:
|
||||||
if b != self.SOF_BYTE:
|
if b != self.SOF_BYTE:
|
||||||
|
|||||||
Reference in New Issue
Block a user