|
- import serial
- import datetime
- import bitarray
- import bitarray.util
-
- s = serial.Serial("/dev/ttyAMA0", baudrate=100000, parity=serial.PARITY_ODD, stopbits = serial.STOPBITS_TWO, bytesize=serial.EIGHTBITS)
-
- counter = 0
-
- synchronized = False
- last_t = datetime.datetime.now()
- while not synchronized:
- rx = s.read(1)
- t = datetime.datetime.now()
- delta_t = (t-last_t).microseconds
- last_t = t
-
- if delta_t > 1000 and rx == b'\x0f':
- counter += 1
- if counter > 2:
- synchronized = True
- s.read(24)
-
- print("Synchronized!\n\n")
-
- while True:
- rx=s.read(25)
-
- if rx[0] != 15 or rx[24] != 0:
- print("Invalid frame!")
-
- flags = int(rx[23])
-
- ba = bitarray.bitarray(endian='little')
- ba.frombytes(rx[1:22])
-
- channel = []
- for i in range(0, 15):
- channel.append(bitarray.util.ba2int(ba[i*11:i*11 + 11]))
-
- print(" ".join([str(x) for x in channel]), " " * 20, end="\r")
-
|