2021-12-16 07:31:53 -07:00
|
|
|
from abc import abstractmethod, ABC
|
2021-02-23 09:04:10 -07:00
|
|
|
from collections import namedtuple
|
2021-12-28 10:07:00 -07:00
|
|
|
from typing import Dict
|
2020-08-26 06:57:17 -06:00
|
|
|
|
2022-03-09 03:36:52 -07:00
|
|
|
from cereal import log
|
|
|
|
|
2021-11-23 17:08:20 -07:00
|
|
|
ThermalConfig = namedtuple('ThermalConfig', ['cpu', 'gpu', 'mem', 'bat', 'ambient', 'pmic'])
|
2022-03-09 03:36:52 -07:00
|
|
|
NetworkType = log.DeviceState.NetworkType
|
|
|
|
|
2020-09-17 05:36:42 -06:00
|
|
|
|
2021-12-16 07:31:53 -07:00
|
|
|
class HardwareBase(ABC):
|
2020-09-17 05:36:42 -06:00
|
|
|
@staticmethod
|
2021-12-28 10:07:00 -07:00
|
|
|
def get_cmdline() -> Dict[str, str]:
|
2020-09-17 05:36:42 -06: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 07:20:57 -07: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 12:45:41 -07:00
|
|
|
@abstractmethod
|
|
|
|
def reboot(self, reason=None):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def uninstall(self):
|
|
|
|
pass
|
|
|
|
|
2020-12-18 05:17:12 -07:00
|
|
|
@abstractmethod
|
|
|
|
def get_os_version(self):
|
|
|
|
pass
|
|
|
|
|
2021-01-22 21:02:48 -07:00
|
|
|
@abstractmethod
|
|
|
|
def get_device_type(self):
|
|
|
|
pass
|
|
|
|
|
2020-08-26 06:57:17 -06:00
|
|
|
@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
|
|
|
|
|
2021-05-17 05:10:08 -06:00
|
|
|
@abstractmethod
|
|
|
|
def get_network_info(self):
|
|
|
|
pass
|
|
|
|
|
2020-08-26 06:57:17 -06: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 07:20:57 -07:00
|
|
|
|
2022-03-09 03:36:52 -07:00
|
|
|
def get_network_metered(self, network_type) -> bool:
|
|
|
|
return network_type not in (NetworkType.none, NetworkType.wifi, NetworkType.ethernet)
|
|
|
|
|
2022-02-07 08:55:16 -07:00
|
|
|
@staticmethod
|
2022-02-08 04:07:11 -07:00
|
|
|
def set_bandwidth_limit(upload_speed_kbps: int, download_speed_kbps: int) -> None:
|
2022-02-07 08:55:16 -07:00
|
|
|
pass
|
|
|
|
|
2020-12-02 07:20:57 -07:00
|
|
|
@abstractmethod
|
|
|
|
def get_battery_capacity(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_battery_status(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_battery_current(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_battery_voltage(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_battery_charging(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set_battery_charging(self, on):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_usb_present(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_current_power_draw(self):
|
|
|
|
pass
|
2021-02-23 09:04:10 -07:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def shutdown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_thermal_config(self):
|
|
|
|
pass
|
2021-02-24 07:25:06 -07:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set_screen_brightness(self, percentage):
|
|
|
|
pass
|
2021-04-12 02:40:58 -06:00
|
|
|
|
2021-10-15 18:19:45 -06:00
|
|
|
@abstractmethod
|
|
|
|
def get_screen_brightness(self):
|
|
|
|
pass
|
|
|
|
|
2021-04-12 02:40:58 -06:00
|
|
|
@abstractmethod
|
2021-07-14 07:53:39 -06:00
|
|
|
def set_power_save(self, powersave_enabled):
|
2021-04-12 02:40:58 -06:00
|
|
|
pass
|
2021-06-29 14:55:18 -06:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_gpu_usage_percent(self):
|
|
|
|
pass
|
2021-07-12 07:52:09 -06:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_modem_version(self):
|
|
|
|
pass
|
2021-07-14 07:53:39 -06:00
|
|
|
|
2021-09-21 06:40:05 -06:00
|
|
|
@abstractmethod
|
|
|
|
def get_modem_temperatures(self):
|
|
|
|
pass
|
|
|
|
|
2021-10-06 21:32:22 -06:00
|
|
|
@abstractmethod
|
|
|
|
def get_nvme_temperatures(self):
|
|
|
|
pass
|
|
|
|
|
2021-07-14 07:53:39 -06:00
|
|
|
@abstractmethod
|
|
|
|
def initialize_hardware(self):
|
|
|
|
pass
|
2021-07-14 08:16:45 -06:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_networks(self):
|
|
|
|
pass
|