system/hardware/ cleanup (#38201)

* imei cleanup

* rm get_modem_version

* cpp cleanup

* that's not in the panda!
This commit is contained in:
Adeeb Shihadeh
2026-06-20 15:51:01 -07:00
committed by GitHub
parent f0f7b877c3
commit 3b4077d31b
10 changed files with 18 additions and 110 deletions
+6 -45
View File
@@ -1,7 +1,6 @@
#include "selfdrive/pandad/pandad.h"
#include <array>
#include <atomic>
#include <bitset>
#include <cassert>
#include <cerrno>
@@ -24,14 +23,6 @@
ExitHandler do_exit;
struct HwmonState {
std::atomic<uint32_t> voltage{0};
std::atomic<uint32_t> current{0};
std::atomic<bool> initialized{false};
};
HwmonState hwmon_state;
bool check_connected(Panda *panda) {
if (!panda->connected()) {
do_exit = true;
@@ -114,26 +105,6 @@ void can_recv(Panda *panda, PubMaster *pm) {
}
}
void hwmon_thread() {
util::set_thread_name("pandad_hwmon");
while (!do_exit) {
double read_time = millis_since_boot();
uint32_t voltage = Hardware::get_voltage();
uint32_t current = Hardware::get_current();
read_time = millis_since_boot() - read_time;
if (read_time > 50) {
LOGW("reading hwmon took %lfms", read_time);
}
hwmon_state.voltage.store(voltage);
hwmon_state.current.store(current);
hwmon_state.initialized.store(true);
util::sleep_for(500);
}
}
void fill_panda_state(cereal::PandaState::Builder &ps, cereal::PandaState::PandaType hw_type, const health_t &health) {
ps.setVoltage(health.voltage_pkt);
ps.setCurrent(health.current_pkt);
@@ -264,7 +235,8 @@ std::optional<bool> send_panda_states(PubMaster *pm, Panda *panda, bool is_onroa
}
void send_peripheral_state(Panda *panda, PubMaster *pm) {
if (!hwmon_state.initialized.load()) {
auto health_opt = panda->get_state();
if (!health_opt) {
return;
}
@@ -276,18 +248,9 @@ void send_peripheral_state(Panda *panda, PubMaster *pm) {
auto ps = evt.initPeripheralState();
ps.setPandaType(panda->hw_type);
ps.setVoltage(hwmon_state.voltage.load());
ps.setCurrent(hwmon_state.current.load());
// fall back to panda's voltage and current measurement
if (ps.getVoltage() == 0 && ps.getCurrent() == 0) {
auto health_opt = panda->get_state();
if (health_opt) {
health_t health = *health_opt;
ps.setVoltage(health.voltage_pkt);
ps.setCurrent(health.current_pkt);
}
}
health_t health = *health_opt;
ps.setVoltage(health.voltage_pkt);
ps.setCurrent(health.current_pkt);
uint16_t fan_speed_rpm = panda->get_fan_speed();
ps.setFanSpeedRpm(fan_speed_rpm);
@@ -399,9 +362,8 @@ void pandad_run(Panda *panda) {
const bool spoofing_started = getenv("STARTED") != nullptr;
const bool fake_send = getenv("FAKESEND") != nullptr;
// Start helper threads for event-driven sendcan and slow non-Panda reads.
// Start helper thread for event-driven sendcan.
std::thread send_thread(can_send_thread, panda, fake_send);
std::thread hardware_thread(hwmon_thread);
RateKeeper rk("pandad", 100);
SubMaster sm({"selfdriveState", "deviceState"});
@@ -457,7 +419,6 @@ void pandad_run(Panda *panda) {
}
send_thread.join();
hardware_thread.join();
}
void pandad_main_thread(std::string serial) {
+6 -7
View File
@@ -54,17 +54,16 @@ def register(show_spinner=False) -> str | None:
# Block until we get the imei
serial = HARDWARE.get_serial()
start_time = time.monotonic()
imei1: str | None = None
imei2: str | None = None
while imei1 is None and imei2 is None:
imei: str | None = None
while imei is None:
try:
imei1, imei2 = HARDWARE.get_imei(0), HARDWARE.get_imei(1)
imei = HARDWARE.get_imei()
except Exception:
cloudlog.exception("Error getting imei, trying again...")
time.sleep(1)
if time.monotonic() - start_time > 60 and show_spinner:
spinner.update(f"registering device - serial: {serial}, IMEI: ({imei1}, {imei2})")
spinner.update(f"registering device - serial: {serial}, IMEI: {imei}")
backoff = 0
start_time = time.monotonic()
@@ -74,7 +73,7 @@ def register(show_spinner=False) -> str | None:
cast(str, private_key), algorithm=jwt_algo)
cloudlog.info("getting pilotauth")
resp = api_get("v2/pilotauth/", method='POST', timeout=15,
imei=imei1, imei2=imei2, serial=serial, public_key=public_key, register_token=register_token)
imei=imei, imei2="", serial=serial, public_key=public_key, register_token=register_token)
if resp.status_code in (402, 403):
cloudlog.info(f"Unable to register device, got {resp.status_code}")
@@ -89,7 +88,7 @@ def register(show_spinner=False) -> str | None:
time.sleep(backoff)
if time.monotonic() - start_time > 60 and show_spinner:
spinner.update(f"registering device - serial: {serial}, IMEI: ({imei1}, {imei2})")
spinner.update(f"registering device - serial: {serial}, IMEI: {imei}")
if show_spinner:
spinner.close()
-4
View File
@@ -12,8 +12,6 @@ class HardwareNone {
public:
static std::string get_name() { return ""; }
static cereal::InitData::DeviceType get_device_type() { return cereal::InitData::DeviceType::UNKNOWN; }
static int get_voltage() { return 0; }
static int get_current() { return 0; }
static std::string get_serial() { return "cccccc"; }
@@ -24,6 +22,4 @@ public:
static void set_ir_power(int percentage) {}
static bool PC() { return false; }
static bool TICI() { return false; }
static bool AGNOS() { return false; }
};
+1 -13
View File
@@ -85,7 +85,7 @@ class HardwareBase(ABC):
def get_device_type(self):
pass
def get_imei(self, slot) -> str:
def get_imei(self) -> str:
return ""
def get_serial(self):
@@ -142,18 +142,12 @@ class HardwareBase(ABC):
def get_gpu_usage_percent(self):
return 0
def get_modem_version(self):
return None
def get_modem_temperatures(self):
return []
def initialize_hardware(self):
pass
def has_internal_panda(self) -> bool:
return False
def reset_internal_panda(self):
pass
@@ -163,11 +157,5 @@ class HardwareBase(ABC):
def get_modem_data_usage(self):
return -1, -1
def get_voltage(self) -> float:
return 0.
def get_current(self) -> float:
return 0.
def set_ir_power(self, percent: int):
pass
+1 -10
View File
@@ -17,7 +17,7 @@ from openpilot.common.filter_simple import FirstOrderFilter
from openpilot.common.params import Params
from openpilot.common.realtime import DT_HW
from openpilot.selfdrive.selfdrived.alertmanager import set_offroad_alert
from openpilot.system.hardware import HARDWARE, TICI, AGNOS, PC
from openpilot.system.hardware import HARDWARE, TICI, PC
from openpilot.system.loggerd.config import get_available_percent
from openpilot.system.statsd import statlog
from openpilot.common.swaglog import cloudlog
@@ -107,8 +107,6 @@ def hw_state_thread(end_event, hw_queue):
count = 0
prev_hw_state = None
modem_version = None
while not end_event.is_set():
# these are expensive calls. update every 10s
if (count % int(10. / DT_HW)) == 0:
@@ -118,13 +116,6 @@ def hw_state_thread(end_event, hw_queue):
if len(modem_temps) == 0 and prev_hw_state is not None:
modem_temps = prev_hw_state.modem_temps
# Log modem version once
if AGNOS and (modem_version is None):
modem_version = HARDWARE.get_modem_version()
if modem_version is not None:
cloudlog.event("modem version", version=modem_version)
tx, rx = HARDWARE.get_modem_data_usage()
hw_state = HardwareState(
-2
View File
@@ -9,6 +9,4 @@ public:
static std::string get_name() { return "pc"; }
static cereal::InitData::DeviceType get_device_type() { return cereal::InitData::DeviceType::PC; }
static bool PC() { return true; }
static bool TICI() { return util::getenv("TICI", 0) == 1; }
static bool AGNOS() { return util::getenv("TICI", 0) == 1; }
};
+2 -4
View File
@@ -1,12 +1,10 @@
from cereal import log
from openpilot.system.hardware.base import HardwareBase
NetworkType = log.DeviceState.NetworkType
class Pc(HardwareBase):
def get_device_type(self):
return "pc"
def get_network_type(self):
return NetworkType.wifi
# some stuff is gated on wifi, so just assume for now
return log.DeviceState.NetworkType.wifi
+1 -7
View File
@@ -1,6 +1,5 @@
#pragma once
#include <cstdlib>
#include <cassert>
#include <fstream>
#include <map>
@@ -22,7 +21,6 @@ public:
static cereal::InitData::DeviceType get_device_type() {
static const std::map<std::string, cereal::InitData::DeviceType> device_map = {
{"tici", cereal::InitData::DeviceType::TICI},
{"tizi", cereal::InitData::DeviceType::TIZI},
{"mici", cereal::InitData::DeviceType::MICI}
};
@@ -31,9 +29,6 @@ public:
return it->second;
}
static int get_voltage() { return std::atoi(util::read_file("/sys/class/hwmon/hwmon1/in1_input").c_str()); }
static int get_current() { return std::atoi(util::read_file("/sys/class/hwmon/hwmon1/curr1_input").c_str()); }
static std::string get_serial() {
static std::string serial("");
if (serial.empty()) {
@@ -54,8 +49,7 @@ public:
static void set_ir_power(int percent) {
auto device = get_device_type();
if (device == cereal::InitData::DeviceType::TICI ||
device == cereal::InitData::DeviceType::TIZI) {
if (device == cereal::InitData::DeviceType::TIZI) {
return;
}
+1 -9
View File
@@ -147,9 +147,7 @@ class Tici(HardwareBase):
def get_sim_lpa(self) -> LPABase:
return TiciLPA()
def get_imei(self, slot):
if slot != 0:
return ""
def get_imei(self):
return self.get_modem_state().get('imei', '')
def get_network_info(self):
@@ -233,9 +231,6 @@ class Tici(HardwareBase):
return super().get_network_metered(network_type)
def get_modem_version(self):
return self.get_modem_state().get('modem_version') or None
def get_modem_temperatures(self):
return self.get_modem_state().get('temperatures', [])
@@ -390,9 +385,6 @@ class Tici(HardwareBase):
ms = self.get_modem_state()
return ms.get('tx_bytes', -1), ms.get('rx_bytes', -1)
def has_internal_panda(self):
return True
def reset_internal_panda(self):
gpio_init(GPIO.STM_RST_N, True)
gpio_init(GPIO.STM_BOOT0, True)
@@ -1,9 +0,0 @@
#!/usr/bin/env python3
import numpy as np
from openpilot.system.hardware.tici.power_monitor import sample_power
if __name__ == '__main__':
print("measuring for 5 seconds")
for _ in range(3):
pwrs = sample_power()
print(f"mean {np.mean(pwrs):.2f} std {np.std(pwrs):.2f}")