diff --git a/common/hardware.py b/common/hardware.py index d255219560..67d0c44d19 100644 --- a/common/hardware.py +++ b/common/hardware.py @@ -3,7 +3,8 @@ import random from typing import cast from cereal import log -from common.android import Android +from common.hardware_android import Android +from common.hardware_tici import Tici from common.hardware_base import HardwareBase EON = os.path.isfile('/EON') @@ -50,5 +51,7 @@ class Pc(HardwareBase): if EON: HARDWARE = cast(HardwareBase, Android()) +elif TICI: + HARDWARE = cast(HardwareBase, Tici()) else: HARDWARE = cast(HardwareBase, Pc()) diff --git a/common/android.py b/common/hardware_android.py similarity index 100% rename from common/android.py rename to common/hardware_android.py diff --git a/common/hardware_base.py b/common/hardware_base.py index d5cc08253b..24bb52a5e6 100644 --- a/common/hardware_base.py +++ b/common/hardware_base.py @@ -1,6 +1,13 @@ from abc import abstractmethod + class HardwareBase: + @staticmethod + def get_cmdline(): + with open('/proc/cmdline') as f: + cmdline = f.read() + return {kv[0]: kv[1] for kv in [s.split('=') for s in cmdline.split(' ')] if len(kv) == 2} + @abstractmethod def get_sound_card_online(self): pass diff --git a/common/hardware_tici.py b/common/hardware_tici.py new file mode 100644 index 0000000000..223bfc1ccc --- /dev/null +++ b/common/hardware_tici.py @@ -0,0 +1,58 @@ +import serial + +from common.hardware_base import HardwareBase +from cereal import log + + +NetworkType = log.ThermalData.NetworkType +NetworkStrength = log.ThermalData.NetworkStrength + + +def run_at_command(cmd, timeout=0.1): + with serial.Serial("/dev/ttyUSB2", timeout=timeout) as ser: + ser.write(cmd + b"\r\n") + ser.readline() # Modem echos request + return ser.readline().decode().rstrip() + + +class Tici(HardwareBase): + def get_sound_card_online(self): + return True + + def get_imei(self, slot): + if slot != 0: + return "" + + for _ in range(10): + try: + imei = run_at_command(b"AT+CGSN") + if len(imei) == 15: + return imei + except serial.SerialException: + pass + + raise RuntimeError("Error getting IMEI") + + def get_serial(self): + return self.get_cmdline()['androidboot.serialno'] + + def get_subscriber_info(self): + return "" + + def reboot(self, reason=None): + print("REBOOT!") + + def get_network_type(self): + return NetworkType.wifi + + def get_sim_info(self): + return { + 'sim_id': '', + 'mcc_mnc': None, + 'network_type': ["Unknown"], + 'sim_state': ["ABSENT"], + 'data_connected': False + } + + def get_network_strength(self, network_type): + return NetworkStrength.unknown diff --git a/release/files_common b/release/files_common index 3389ae1a4f..4c02823899 100644 --- a/release/files_common +++ b/release/files_common @@ -17,8 +17,9 @@ apk/ai.comma*.apk common/.gitignore common/__init__.py -common/android.py common/hardware.py +common/hardware_android.py +common/hardware_tici.py common/hardware_base.py common/gpio.py common/realtime.py