From 1cd6ca467d0549db55bf65aeb896ca8f6c299c3c Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Fri, 14 Mar 2025 01:40:26 +0800 Subject: [PATCH] pandad: forward debug logs to cloudlog (#34859) forward debug logs to cloudlog --- selfdrive/pandad/panda.cc | 19 +++++++++++++++++++ selfdrive/pandad/panda.h | 2 ++ selfdrive/pandad/pandad.cc | 8 ++++++++ 3 files changed, 29 insertions(+) diff --git a/selfdrive/pandad/panda.cc b/selfdrive/pandad/panda.cc index 7b5fc9a999..93e139f0ec 100644 --- a/selfdrive/pandad/panda.cc +++ b/selfdrive/pandad/panda.cc @@ -66,6 +66,25 @@ void Panda::set_alternative_experience(uint16_t alternative_experience) { handle->control_write(0xdf, alternative_experience, 0); } +std::string Panda::serial_read(int port_number) { + std::string ret; + char buffer[USBPACKET_MAX_SIZE] = {}; + + while (true) { + int bytes_read = handle->control_read(0xe0, port_number, 0, (unsigned char *)buffer, USBPACKET_MAX_SIZE); + if (bytes_read <= 0) { + break; + } + ret.append(buffer, bytes_read); + } + + return ret; +} + +void Panda::set_uart_baud(int uart, int rate) { + handle->control_write(0xe4, uart, int(rate / 300)); +} + cereal::PandaState::PandaType Panda::get_hw_type() { unsigned char hw_query[1] = {0}; diff --git a/selfdrive/pandad/panda.h b/selfdrive/pandad/panda.h index 6ae2c77755..5cbce44f28 100644 --- a/selfdrive/pandad/panda.h +++ b/selfdrive/pandad/panda.h @@ -64,6 +64,8 @@ public: cereal::PandaState::PandaType get_hw_type(); void set_safety_model(cereal::CarParams::SafetyModel safety_model, uint16_t safety_param=0U); void set_alternative_experience(uint16_t alternative_experience); + std::string serial_read(int port_number = 0); + void set_uart_baud(int uart, int rate); void set_fan_speed(uint16_t fan_speed); uint16_t get_fan_speed(); void set_ir_pwr(uint16_t ir_pwr); diff --git a/selfdrive/pandad/pandad.cc b/selfdrive/pandad/pandad.cc index e6ef4a4072..db7dd387e0 100644 --- a/selfdrive/pandad/pandad.cc +++ b/selfdrive/pandad/pandad.cc @@ -452,6 +452,14 @@ void pandad_run(std::vector &pandas) { send_peripheral_state(peripheral_panda, &pm); } + // Forward logs from pandas to cloudlog if available + for (auto *panda : pandas) { + std::string log = panda->serial_read(); + if (!log.empty()) { + LOGD("%s", log.c_str()); + } + } + rk.keepTime(); }