You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
969B

  1. import serial
  2. import datetime
  3. import bitarray
  4. import bitarray.util
  5. s = serial.Serial("/dev/ttyAMA0", baudrate=100000, parity=serial.PARITY_ODD, stopbits = serial.STOPBITS_TWO, bytesize=serial.EIGHTBITS)
  6. counter = 0
  7. synchronized = False
  8. last_t = datetime.datetime.now()
  9. while not synchronized:
  10. rx = s.read(1)
  11. t = datetime.datetime.now()
  12. delta_t = (t-last_t).microseconds
  13. last_t = t
  14. if delta_t > 1000 and rx == b'\x0f':
  15. counter += 1
  16. if counter > 2:
  17. synchronized = True
  18. s.read(24)
  19. print("Synchronized!\n\n")
  20. while True:
  21. rx=s.read(25)
  22. if rx[0] != 15 or rx[24] != 0:
  23. print("Invalid frame!")
  24. flags = int(rx[23])
  25. ba = bitarray.bitarray(endian='little')
  26. ba.frombytes(rx[1:22])
  27. channel = []
  28. for i in range(0, 15):
  29. channel.append(bitarray.util.ba2int(ba[i*11:i*11 + 11]))
  30. print(" ".join([str(x) for x in channel]), " " * 20, end="\r")