Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. from datetime import datetime
  2.  
  3. # Time begins in 2013
  4. borealis_epoch = 1357023600
  5.  
  6. # Every modem IMEI shares this TAC
  7. iridium_tac = '30023406'
  8.  
  9.  
  10. def encode_uid(date: datetime, imei: str) -> int:
  11. """
  12. Encode a flight date and IMEI into a decodeable UID
  13.  
  14. :param date: The start date of the flight
  15. :param imei: The IMEI of the modem
  16. :return: A flight UID
  17.  
  18. Borealis Snowflake
  19. ------------------
  20. The UID is a snowflake in the structure:
  21.  
  22. Date IMEI
  23. 111111111111111111111111111111111111111 111111111111111111111111
  24. 63 23 0
  25.  
  26. +======+=========+==============================+================================+
  27. | Data | Bits | Description | Obtaining |
  28. +======+=========+==============================+================================+
  29. | Date | 63 - 24 | Seconds since Borealis Epoch | (snowflake >> 24) + 1357023600 |
  30. +------+---------+------------------------------+--------------------------------+
  31. | IMEI | 23 - 0 | Last 7 digits of IMEI | snowflake & 0x7ffffff |
  32. +------+---------+------------------------------+--------------------------------+
  33. """
  34. time = int(date.timestamp()) - borealis_epoch
  35. snr = int(imei[8:])
  36. return (time << 24) | snr
  37.  
  38.  
  39. def extract_date(uid: int) -> datetime:
  40. return datetime.fromtimestamp((uid >> 24) + borealis_epoch)
  41.  
  42.  
  43. def extract_imei(uid: int) -> str:
  44. return iridium_tac + str(uid & 0x7ffffff).zfill(7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement