Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. addr = 1
  2. addr_broad = 0
  3.  
  4. e_conectata = 0
  5. e_master = 0
  6.  
  7. '''
  8. 87asmnfsf
  9.  
  10. '''
  11.  
  12. def decodare_mesaj(mesaj):
  13. if mesaj[1] == chr(addr) or mesaj[1] == chr(addr_broad):
  14. date = mesaj[1:]
  15. return date
  16. else:
  17. return
  18.  
  19. def decode_ctrl(ctrl):
  20. if(ctrl[0] == 0): #info
  21. n_s = ctrl&13 >> 1
  22. pf = ctrl&16
  23.  
  24. mesaj = ["Cadru de tip Informatie cu:\nN(S) = ", "{0:b}".format(n_s), "\nN(R) = ", "{0:b}".format(n_r), "\nP/F = ", str(pf)]
  25. mesaj = ''.join(mesaj)
  26.  
  27. print(mesaj)
  28. elif(ctrl[0] == 1 and ctrl[1] == 1): #nenumerotate
  29. mm = ((ctrl>>5) << 2 ) | ((ctrl&12) >> 2)
  30. pf = ctrl&16
  31.  
  32. mesaj = ["Cadru de tip Nenumerotate cu:\nMM = ", "{0:b}".format(mm), "\nP/F = ", str(pf)]
  33. mesaj = ''.join(mesaj)
  34.  
  35. print(mesaj)
  36.  
  37.  
  38.  
  39. def receptionare_mesaj():
  40. #time.sleep(1)
  41. ans = sPort.readline()
  42. ans = ans.decode("utf-8")
  43.  
  44. if ans[0] == chr(0x7E) and ans[1] == chr(addr) or ans[1] == chr(addr_broad):
  45. #
  46. ctrl = ans[2]
  47. decode_ctrl(ctrl)
  48.  
  49.  
  50. #if(ans == decodare_mesaj(ans)):
  51. # print(decodare_mesaj(ans))
  52.  
  53.  
  54. def trimitere_date(date, dst):
  55. mesaj = [str(delimitator), str(dst), str(addr), date, '\n']
  56. mesaj = ''.join(mesaj)
  57. mesaj_unicode=mesaj.encode("utf-8")
  58. print(mesaj)
  59. # sPort.write(mesaj_unicode)
  60.  
  61.  
  62.  
  63. class Cadru:
  64. delimitator = chr(0x7E)
  65. adresa = 0
  66. control = chr(0)
  67. date = str(0)
  68.  
  69.  
  70. def trimite(self):
  71. mesaj = [str(self.delimitator), chr(self.adresa), chr(self.control), self.date, str(self.delimitator)]
  72. mesaj = ''.join(mesaj)
  73. mesaj_unicode=mesaj.encode("utf-8")
  74. print(mesaj)
  75. # sPort.write(mesaj_unicode)
  76.  
  77. def Informatie(self, pf, k, j):
  78. self.control = 0 | ((k&7) << 1) | ((pf&1) << 4) | ((j&7) << 5)
  79.  
  80. def Nenumerotate(self, pf, m):
  81. self.control = 1 | (1<<1) | ((m&3) << 2) | ((pf&1) << 4) | (((m&28)>>2) << 5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement