2021-12-16 15:31:53 +01:00
|
|
|
from abc import abstractmethod, ABC
|
2021-02-23 17:04:10 +01:00
|
|
|
from collections import namedtuple
|
2021-12-28 12:07:00 -05:00
|
|
|
from typing import Dict
|
2020-08-26 14:57:17 +02:00
|
|
|
|
2022-03-09 11:36:52 +01:00
|
|
|
from cereal import log
|
|
|
|
|
|
2021-11-23 16:08:20 -08:00
|
|
|
ThermalConfig = namedtuple('ThermalConfig', ['cpu', 'gpu', 'mem', 'bat', 'ambient', 'pmic'])
|
2022-03-09 11:36:52 +01:00
|
|
|
NetworkType = log.DeviceState.NetworkType
|
|
|
|
|
|
2020-09-17 13:36:42 +02:00
|
|
|
|
2021-12-16 15:31:53 +01:00
|
|
|
class HardwareBase(ABC):
|
2020-09-17 13:36:42 +02:00
|
|
|
@staticmethod
|
2021-12-28 12:07:00 -05:00
|
|
|
def get_cmdline() -> Dict[str, str]:
|
2020-09-17 13:36:42 +02:00
|
|
|
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}
|
|
|
|
|
|
2020-12-02 15:20:57 +01:00
|
|
|
@staticmethod
|
|
|
|
|
def read_param_file(path, parser, default=0):
|
|
|
|
|
try:
|
|
|
|
|
with open(path) as f:
|
|
|
|
|
return parser(f.read())
|
|
|
|
|
except Exception:
|
|
|
|
|
return default
|
|
|
|
|
|
2020-12-17 11:45:41 -08:00
|
|
|
@abstractmethod
|
|
|
|
|
def reboot(self, reason=None):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def uninstall(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2020-12-18 04:17:12 -08:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_os_version(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-01-22 20:02:48 -08:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_device_type(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2020-08-26 14:57:17 +02:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_sound_card_online(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
2022-04-21 12:27:45 -04:00
|
|
|
def get_imei(self, slot) -> str:
|
2020-08-26 14:57:17 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def get_serial(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def get_subscriber_info(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-05-17 13:10:08 +02:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_network_info(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2020-08-26 14:57:17 +02:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_network_type(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def get_sim_info(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def get_network_strength(self, network_type):
|
|
|
|
|
pass
|
2020-12-02 15:20:57 +01:00
|
|
|
|
2022-03-09 11:36:52 +01:00
|
|
|
def get_network_metered(self, network_type) -> bool:
|
|
|
|
|
return network_type not in (NetworkType.none, NetworkType.wifi, NetworkType.ethernet)
|
|
|
|
|
|
2022-02-07 16:55:16 +01:00
|
|
|
@staticmethod
|
2022-02-08 12:07:11 +01:00
|
|
|
def set_bandwidth_limit(upload_speed_kbps: int, download_speed_kbps: int) -> None:
|
2022-02-07 16:55:16 +01:00
|
|
|
pass
|
|
|
|
|
|
2020-12-02 15:20:57 +01:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_usb_present(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def get_current_power_draw(self):
|
|
|
|
|
pass
|
2021-02-23 17:04:10 +01:00
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def shutdown(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def get_thermal_config(self):
|
|
|
|
|
pass
|
2021-02-24 15:25:06 +01:00
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def set_screen_brightness(self, percentage):
|
|
|
|
|
pass
|
2021-04-12 01:40:58 -07:00
|
|
|
|
2021-10-15 17:19:45 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_screen_brightness(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-04-12 01:40:58 -07:00
|
|
|
@abstractmethod
|
2021-07-14 15:53:39 +02:00
|
|
|
def set_power_save(self, powersave_enabled):
|
2021-04-12 01:40:58 -07:00
|
|
|
pass
|
2021-06-29 22:55:18 +02:00
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
def get_gpu_usage_percent(self):
|
|
|
|
|
pass
|
2021-07-12 15:52:09 +02:00
|
|
|
|
|
|
|
|
def get_modem_version(self):
|
2022-04-05 14:29:07 -07:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def get_modem_nv(self):
|
|
|
|
|
return None
|
2021-07-14 15:53:39 +02:00
|
|
|
|
2021-09-21 14:40:05 +02:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_modem_temperatures(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-10-06 20:32:22 -07:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_nvme_temperatures(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-07-14 15:53:39 +02:00
|
|
|
@abstractmethod
|
|
|
|
|
def initialize_hardware(self):
|
|
|
|
|
pass
|
2021-07-14 16:16:45 +02:00
|
|
|
|
2022-04-11 15:33:58 -07:00
|
|
|
def configure_modem(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-07-14 16:16:45 +02:00
|
|
|
@abstractmethod
|
|
|
|
|
def get_networks(self):
|
|
|
|
|
pass
|
2022-04-26 11:02:40 -07:00
|
|
|
|
|
|
|
|
def reset_internal_panda(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def recover_internal_panda(self):
|
|
|
|
|
pass
|