Tici hardware abstraction layer (#2183)

* rename android hardware

* add tici class

* elif

* read correct serial number

* Update release files

* Get IMEI

* Refactor AT command

* move get_cmdline into base class

* Remove unused import

* Small cleanup
old-commit-hash: c90cb1b529
commatwo_master
Willem Melching 5 years ago committed by GitHub
parent 398796a010
commit d455516765
  1. 5
      common/hardware.py
  2. 0
      common/hardware_android.py
  3. 7
      common/hardware_base.py
  4. 58
      common/hardware_tici.py
  5. 3
      release/files_common

@ -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())

@ -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

@ -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

@ -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

Loading…
Cancel
Save