Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addr = 1
- addr_broad = 0
- e_conectata = 0
- e_master = 0
- '''
- 87asmnfsf
- '''
- def decodare_mesaj(mesaj):
- if mesaj[1] == chr(addr) or mesaj[1] == chr(addr_broad):
- date = mesaj[1:]
- return date
- else:
- return
- def decode_ctrl(ctrl):
- if(ctrl[0] == 0): #info
- n_s = ctrl&13 >> 1
- pf = ctrl&16
- mesaj = ["Cadru de tip Informatie cu:\nN(S) = ", "{0:b}".format(n_s), "\nN(R) = ", "{0:b}".format(n_r), "\nP/F = ", str(pf)]
- mesaj = ''.join(mesaj)
- print(mesaj)
- elif(ctrl[0] == 1 and ctrl[1] == 1): #nenumerotate
- mm = ((ctrl>>5) << 2 ) | ((ctrl&12) >> 2)
- pf = ctrl&16
- mesaj = ["Cadru de tip Nenumerotate cu:\nMM = ", "{0:b}".format(mm), "\nP/F = ", str(pf)]
- mesaj = ''.join(mesaj)
- print(mesaj)
- def receptionare_mesaj():
- #time.sleep(1)
- ans = sPort.readline()
- ans = ans.decode("utf-8")
- if ans[0] == chr(0x7E) and ans[1] == chr(addr) or ans[1] == chr(addr_broad):
- #
- ctrl = ans[2]
- decode_ctrl(ctrl)
- #if(ans == decodare_mesaj(ans)):
- # print(decodare_mesaj(ans))
- def trimitere_date(date, dst):
- mesaj = [str(delimitator), str(dst), str(addr), date, '\n']
- mesaj = ''.join(mesaj)
- mesaj_unicode=mesaj.encode("utf-8")
- print(mesaj)
- # sPort.write(mesaj_unicode)
- class Cadru:
- delimitator = chr(0x7E)
- adresa = 0
- control = chr(0)
- date = str(0)
- def trimite(self):
- mesaj = [str(self.delimitator), chr(self.adresa), chr(self.control), self.date, str(self.delimitator)]
- mesaj = ''.join(mesaj)
- mesaj_unicode=mesaj.encode("utf-8")
- print(mesaj)
- # sPort.write(mesaj_unicode)
- def Informatie(self, pf, k, j):
- self.control = 0 | ((k&7) << 1) | ((pf&1) << 4) | ((j&7) << 5)
- def Nenumerotate(self, pf, m):
- 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