Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- # Time begins in 2013
- borealis_epoch = 1357023600
- # Every modem IMEI shares this TAC
- iridium_tac = '30023406'
- def encode_uid(date: datetime, imei: str) -> int:
- """
- Encode a flight date and IMEI into a decodeable UID
- :param date: The start date of the flight
- :param imei: The IMEI of the modem
- :return: A flight UID
- Borealis Snowflake
- ------------------
- The UID is a snowflake in the structure:
- Date IMEI
- 111111111111111111111111111111111111111 111111111111111111111111
- 63 23 0
- +======+=========+==============================+================================+
- | Data | Bits | Description | Obtaining |
- +======+=========+==============================+================================+
- | Date | 63 - 24 | Seconds since Borealis Epoch | (snowflake >> 24) + 1357023600 |
- +------+---------+------------------------------+--------------------------------+
- | IMEI | 23 - 0 | Last 7 digits of IMEI | snowflake & 0x7ffffff |
- +------+---------+------------------------------+--------------------------------+
- """
- time = int(date.timestamp()) - borealis_epoch
- snr = int(imei[8:])
- return (time << 24) | snr
- def extract_date(uid: int) -> datetime:
- return datetime.fromtimestamp((uid >> 24) + borealis_epoch)
- def extract_imei(uid: int) -> str:
- return iridium_tac + str(uid & 0x7ffffff).zfill(7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement