Working
This commit is contained in:
parent
2ef21af66f
commit
afb7842d60
@ -102,7 +102,7 @@ class Main:
|
|||||||
if expectFrameDelimiter:
|
if expectFrameDelimiter:
|
||||||
decodedByte = self.decodeByte(True)
|
decodedByte = self.decodeByte(True)
|
||||||
if decodedByte != FRAME_DELIMITER:
|
if decodedByte != FRAME_DELIMITER:
|
||||||
raise ValueError('Expecting a frame delimiter, found {}'.format(decodedByte))
|
raise ValueError('Expecting a frame delimiter, found {} at position {}'.format(decodedByte, position))
|
||||||
self._log.info('Found frame delimiter')
|
self._log.info('Found frame delimiter')
|
||||||
|
|
||||||
decodedByte = self.decodeByte(False)
|
decodedByte = self.decodeByte(False)
|
||||||
@ -120,6 +120,7 @@ class Main:
|
|||||||
def decodeByte(self, expectFrameDelimiter=False):
|
def decodeByte(self, expectFrameDelimiter=False):
|
||||||
# Decodes a byte (to be used _after_ the first frame delimiter was found)
|
# Decodes a byte (to be used _after_ the first frame delimiter was found)
|
||||||
decodedByte = 0
|
decodedByte = 0
|
||||||
|
consecutiveOnes = 0
|
||||||
for x in range(8):
|
for x in range(8):
|
||||||
value = self.decodeBit()
|
value = self.decodeBit()
|
||||||
|
|
||||||
@ -131,9 +132,11 @@ class Main:
|
|||||||
# Add the read bit in the least significant position
|
# Add the read bit in the least significant position
|
||||||
if value:
|
if value:
|
||||||
decodedByte = decodedByte + 128 #10000000
|
decodedByte = decodedByte + 128 #10000000
|
||||||
|
consecutiveOnes = consecutiveOnes + 1
|
||||||
|
else:
|
||||||
|
consecutiveOnes = 0
|
||||||
|
|
||||||
if decodedByte == 248 and not expectFrameDelimiter: # 248 = 11111000
|
if consecutiveOnes == 5 and not expectFrameDelimiter:
|
||||||
self._log.info("Here")
|
|
||||||
# We found 5 1s: ignore next 0: has been added to avoid a real 01111110 byte to be interpreted as frame delimiter
|
# We found 5 1s: ignore next 0: has been added to avoid a real 01111110 byte to be interpreted as frame delimiter
|
||||||
if self.decodeBit():
|
if self.decodeBit():
|
||||||
# Should be 0!
|
# Should be 0!
|
||||||
|
Loading…
Reference in New Issue
Block a user