def GetFromQue(self): #pobieranie z kolejki
while self.RxBuf.empty() == False:
# emb.log('before GetFromQue',self.BytesInQueue)
if self.RxState == self.oenum.LOOKING_FOR_BEG:
self.RxFrame = ''
self.RxFrame = self.RxFrame + chr(self.RxBuf.get())
self.BytesInQueue = self.BytesInQueue - 1
if (ord(self.RxFrame[0]) != 0x06 and ord(self.RxFrame[0]) != 0x15 and ord(self.RxFrame[0]) != 0x02 and ord(
self.RxFrame[0]) != 0x03 and ord(self.RxFrame[0]) != 0x3F):
while self.RxBuf.empty() == False: # trochę niep
a = self.RxBuf.get()
self.BytesInQueue = self.BytesInQueue - 1
emb.log('?', a)
if (a == 0x06 or a == 0x15 or a == 0x3F or a == 0x02 or a == 0x03):
self.RxFrame = ''
self.RxFrame = self.RxFrame + chr(a)
break # tuuuuuuuuuuuuuuuuuuuuuuu
if (ord(self.RxFrame[0]) == 0x06 or ord(self.RxFrame[0]) == 0x15):
self.ReceiveFrame()
# return
if (ord(self.RxFrame[0]) == 0x02 or ord(self.RxFrame[0]) == 0x03 or ord(self.RxFrame[0]) == 0x3F):
self.RxState = self.oenum.LOOKING_FOR_LEN
self.startTimer102(10)
if self.RxState == self.oenum.LOOKING_FOR_LEN:
if self.RxBuf.empty() == False:
self.RxFrame = self.RxFrame + chr(self.RxBuf.get()) # LEN or MS cought
self.BytesInQueue = self.BytesInQueue - 1
if (ord(self.RxFrame[0]) == 0x3F):
self.RxState = self.oenum.LOOKING_FOR_BEG
# self.startTimer102(10)
self.stopTimer102()
self.ReceiveFrame()
# return
else: # a==0x02 or a==0x03:
self.RxState = self.oenum.LOOKING_FOR_CC
self.startTimer102(10)
if self.RxState == self.oenum.LOOKING_FOR_CC:
if self.RxBuf.empty() == False:
self.RxFrame = self.RxFrame + chr(self.RxBuf.get()) # CC cought
self.BytesInQueue = self.BytesInQueue - 1
if (ord(self.RxFrame[1]) != 0):
self.RxState = self.oenum.DATA_COLLECTING
self.startTimer102(10)
self.Data_Collecting_i = ord(self.RxFrame[1])
else:
self.RxState = self.oenum.LOOKING_FOR_CHECK_1BYTE
self.startTimer102(10)
if self.RxState == self.oenum.DATA_COLLECTING:
while self.Data_Collecting_i:
if self.RxBuf.empty() == False:
self.RxFrame = self.RxFrame + chr(self.RxBuf.get()) # CC cought
self.BytesInQueue = self.BytesInQueue - 1
self.Data_Collecting_i = self.Data_Collecting_i - 1
self.startTimer102(10)
# for i in range (0, ord(self.RxFrame[1])):
# if self.RxBuf.empty()==False:
# self.RxFrame=self.RxFrame+chr(self.RxBuf.get())# CC cought
if ((len(self.RxFrame) - 3) == ord(self.RxFrame[1])): # po co
self.RxState = self.oenum.LOOKING_FOR_CHECK_1BYTE # chyba tylko po to
self.startTimer102(10)
if self.RxState == self.oenum.LOOKING_FOR_CHECK_1BYTE:
if self.RxBuf.empty() == False:
self.RxFrame = self.RxFrame + chr(self.RxBuf.get()) # CHECK_1BYTE cought
self.BytesInQueue = self.BytesInQueue - 1
self.RxState = self.oenum.LOOKING_FOR_CHECK_2BYTE
self.startTimer102(10)
if self.RxState == self.oenum.LOOKING_FOR_CHECK_2BYTE:
if self.RxBuf.empty() == False:
self.RxFrame = self.RxFrame + chr(self.RxBuf.get()) # CHECK_2BYTE cought
self.BytesInQueue = self.BytesInQueue - 1
CheckSum = 0x10000
for i in range(1, 3 + ord(self.RxFrame[1])):
CheckSum = CheckSum + ord(self.RxFrame[i])
CheckSum = CheckSum - 0x10000
if ((CheckSum % 256 == ord(self.RxFrame[ord(self.RxFrame[1]) + 3])) and (
int(CheckSum / 256) == ord(self.RxFrame[ord(self.RxFrame[1]) + 4]))):
self.stopTimer102() # tu też co by zdazyc przetwarzac
self.ReceiveFrame()
else:
emb.log('Fr Err') # ,CheckSum%256,'i',self.RxFrame[ord(self.RxFrame[1])+3])
self.RxState = self.oenum.LOOKING_FOR_BEG
self.stopTimer102()