Facebook
From Perl Panda, 5 Years ago, written in Python for S60.
Embed
Download Paste or View Raw
Hits: 208
  1. def GetFromQue(self): #pobieranie z kolejki
  2.     while self.RxBuf.empty() == False:
  3.         # emb.log('before GetFromQue',self.BytesInQueue)
  4.         if self.RxState == self.oenum.LOOKING_FOR_BEG:
  5.             self.RxFrame = ''
  6.             self.RxFrame = self.RxFrame + chr(self.RxBuf.get())
  7.             self.BytesInQueue = self.BytesInQueue - 1
  8.             if (ord(self.RxFrame[0]) != 0x06 and ord(self.RxFrame[0]) != 0x15 and ord(self.RxFrame[0]) != 0x02 and ord(
  9.                     self.RxFrame[0]) != 0x03 and ord(self.RxFrame[0]) != 0x3F):
  10.                 while self.RxBuf.empty() == False:  # trochę niep
  11.                     a = self.RxBuf.get()
  12.                     self.BytesInQueue = self.BytesInQueue - 1
  13.                     emb.log('?', a)
  14.                     if (a == 0x06 or a == 0x15 or a == 0x3F or a == 0x02 or a == 0x03):
  15.                         self.RxFrame = ''
  16.                         self.RxFrame = self.RxFrame + chr(a)
  17.                         break  # tuuuuuuuuuuuuuuuuuuuuuuu
  18.             if (ord(self.RxFrame[0]) == 0x06 or ord(self.RxFrame[0]) == 0x15):
  19.                 self.ReceiveFrame()
  20.                 # return
  21.             if (ord(self.RxFrame[0]) == 0x02 or ord(self.RxFrame[0]) == 0x03 or ord(self.RxFrame[0]) == 0x3F):
  22.                 self.RxState = self.oenum.LOOKING_FOR_LEN
  23.                 self.startTimer102(10)
  24.  
  25.         if self.RxState == self.oenum.LOOKING_FOR_LEN:
  26.             if self.RxBuf.empty() == False:
  27.                 self.RxFrame = self.RxFrame + chr(self.RxBuf.get())  # LEN or MS cought
  28.                 self.BytesInQueue = self.BytesInQueue - 1
  29.                 if (ord(self.RxFrame[0]) == 0x3F):
  30.                     self.RxState = self.oenum.LOOKING_FOR_BEG
  31.                     # self.startTimer102(10)
  32.                     self.stopTimer102()
  33.                     self.ReceiveFrame()
  34.                     # return
  35.                 else:  # a==0x02 or a==0x03:
  36.                     self.RxState = self.oenum.LOOKING_FOR_CC
  37.                     self.startTimer102(10)
  38.  
  39.         if self.RxState == self.oenum.LOOKING_FOR_CC:
  40.             if self.RxBuf.empty() == False:
  41.                 self.RxFrame = self.RxFrame + chr(self.RxBuf.get())  # CC cought
  42.                 self.BytesInQueue = self.BytesInQueue - 1
  43.                 if (ord(self.RxFrame[1]) != 0):
  44.                     self.RxState = self.oenum.DATA_COLLECTING
  45.                     self.startTimer102(10)
  46.                     self.Data_Collecting_i = ord(self.RxFrame[1])
  47.                 else:
  48.                     self.RxState = self.oenum.LOOKING_FOR_CHECK_1BYTE
  49.                     self.startTimer102(10)
  50.  
  51.         if self.RxState == self.oenum.DATA_COLLECTING:
  52.             while self.Data_Collecting_i:
  53.                 if self.RxBuf.empty() == False:
  54.                     self.RxFrame = self.RxFrame + chr(self.RxBuf.get())  # CC cought
  55.                     self.BytesInQueue = self.BytesInQueue - 1
  56.                     self.Data_Collecting_i = self.Data_Collecting_i - 1
  57.                     self.startTimer102(10)
  58.             # for i in range (0, ord(self.RxFrame[1])):
  59.             #    if self.RxBuf.empty()==False:
  60.             #       self.RxFrame=self.RxFrame+chr(self.RxBuf.get())# CC cought
  61.  
  62.             if ((len(self.RxFrame) - 3) == ord(self.RxFrame[1])):  # po co
  63.                 self.RxState = self.oenum.LOOKING_FOR_CHECK_1BYTE  # chyba tylko po to
  64.                 self.startTimer102(10)
  65.         if self.RxState == self.oenum.LOOKING_FOR_CHECK_1BYTE:
  66.             if self.RxBuf.empty() == False:
  67.                 self.RxFrame = self.RxFrame + chr(self.RxBuf.get())  # CHECK_1BYTE cought
  68.                 self.BytesInQueue = self.BytesInQueue - 1
  69.                 self.RxState = self.oenum.LOOKING_FOR_CHECK_2BYTE
  70.                 self.startTimer102(10)
  71.  
  72.         if self.RxState == self.oenum.LOOKING_FOR_CHECK_2BYTE:
  73.             if self.RxBuf.empty() == False:
  74.                 self.RxFrame = self.RxFrame + chr(self.RxBuf.get())  # CHECK_2BYTE cought
  75.                 self.BytesInQueue = self.BytesInQueue - 1
  76.                 CheckSum = 0x10000
  77.                 for i in range(1, 3 + ord(self.RxFrame[1])):
  78.                     CheckSum = CheckSum + ord(self.RxFrame[i])
  79.                 CheckSum = CheckSum - 0x10000
  80.                 if ((CheckSum % 256 == ord(self.RxFrame[ord(self.RxFrame[1]) + 3])) and (
  81.                         int(CheckSum / 256) == ord(self.RxFrame[ord(self.RxFrame[1]) + 4]))):
  82.                     self.stopTimer102()  # tu też co by zdazyc przetwarzac
  83.                     self.ReceiveFrame()
  84.                 else:
  85.                     emb.log('Fr Err')  # ,CheckSum%256,'i',self.RxFrame[ord(self.RxFrame[1])+3])
  86.                 self.RxState = self.oenum.LOOKING_FOR_BEG
  87.                 self.stopTimer102()