Hardware abstraction class (#2080)
* hardware abstraction class
* De Morgan
* Rename pc hardware class
* Fix sound card in controlsd
* Pc get sim info
* fix hardware in test
* two more
* No more random imei on android
* no randomness on android
* Need to return something that looks like imei for registration to work
* Return proper network strength
* Unused import
* Bug fixes + gpsd is only android
old-commit-hash: c7152d5419
commatwo_master
parent
93926b0cd2
commit
16fe1bb2ad
18 changed files with 390 additions and 299 deletions
@ -1,10 +1,10 @@ |
|||||||
import os |
import os |
||||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) |
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) |
||||||
|
|
||||||
from common.android import ANDROID |
from common.hardware import PC |
||||||
if ANDROID: |
if PC: |
||||||
PERSIST = "/persist" |
|
||||||
PARAMS = "/data/params" |
|
||||||
else: |
|
||||||
PERSIST = os.path.join(BASEDIR, "persist") |
PERSIST = os.path.join(BASEDIR, "persist") |
||||||
PARAMS = os.path.join(BASEDIR, "persist", "params") |
PARAMS = os.path.join(BASEDIR, "persist", "params") |
||||||
|
else: |
||||||
|
PERSIST = "/persist" |
||||||
|
PARAMS = "/data/params" |
||||||
|
@ -1,4 +1,54 @@ |
|||||||
import os |
import os |
||||||
|
import random |
||||||
|
from typing import cast |
||||||
|
|
||||||
|
from cereal import log |
||||||
|
from common.android import Android |
||||||
|
from common.hardware_base import HardwareBase |
||||||
|
|
||||||
EON = os.path.isfile('/EON') |
EON = os.path.isfile('/EON') |
||||||
TICI = os.path.isfile('/TICI') |
TICI = os.path.isfile('/TICI') |
||||||
|
PC = not (EON or TICI) |
||||||
|
ANDROID = EON |
||||||
|
|
||||||
|
|
||||||
|
NetworkType = log.ThermalData.NetworkType |
||||||
|
NetworkStrength = log.ThermalData.NetworkStrength |
||||||
|
|
||||||
|
|
||||||
|
class Pc(HardwareBase): |
||||||
|
def get_sound_card_online(self): |
||||||
|
return True |
||||||
|
|
||||||
|
def get_imei(self, slot): |
||||||
|
return "%015d" % random.randint(0, 1 << 32) |
||||||
|
|
||||||
|
def get_serial(self): |
||||||
|
return "cccccccc" |
||||||
|
|
||||||
|
def get_subscriber_info(self): |
||||||
|
return "" |
||||||
|
|
||||||
|
def reboot(self, reason=None): |
||||||
|
print("REBOOT!") |
||||||
|
|
||||||
|
def get_network_type(self): |
||||||
|
return NetworkType.none |
||||||
|
|
||||||
|
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 |
||||||
|
|
||||||
|
|
||||||
|
if EON: |
||||||
|
HARDWARE = cast(HardwareBase, Android()) |
||||||
|
else: |
||||||
|
HARDWARE = cast(HardwareBase, Pc()) |
||||||
|
@ -0,0 +1,34 @@ |
|||||||
|
from abc import abstractmethod |
||||||
|
|
||||||
|
class HardwareBase: |
||||||
|
@abstractmethod |
||||||
|
def get_sound_card_online(self): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def get_imei(self, slot): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def get_serial(self): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def get_subscriber_info(self): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def reboot(self, reason=None): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def get_network_type(self): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def get_sim_info(self): |
||||||
|
pass |
||||||
|
|
||||||
|
@abstractmethod |
||||||
|
def get_network_strength(self, network_type): |
||||||
|
pass |
Loading…
Reference in new issue