From 694aae9c26efeb037c3f961f46af2ad8d9f10417 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Fri, 30 Jun 2023 17:26:39 +0200 Subject: [PATCH] Faster log retrieval (#1484) improve get_logs --- board/drivers/logging.h | 12 ++++++++---- board/main_comms.h | 7 ++++++- python/__init__.py | 8 +++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/board/drivers/logging.h b/board/drivers/logging.h index 117de587..28e42752 100644 --- a/board/drivers/logging.h +++ b/board/drivers/logging.h @@ -42,16 +42,20 @@ void logging_erase(void) { log_state.write_index = 0U; } -void logging_find_read_index(void) { +void logging_find_read_index(uint16_t last_id) { // Figure out the read index by the last empty slot - log_state.read_index = 0xFFFFU; + log_state.read_index = BANK_LOG_CAPACITY; for (uint16_t i = 0U; i < TOTAL_LOG_CAPACITY; i++) { - if (log_arr[i].id == 0xFFFFU) { + if (log_arr[i].id == last_id) { log_state.read_index = logging_next_index(i); } } } +void logging_init_read_index(void) { + return logging_find_read_index(0xFFFFU); +} + void logging_init(void) { COMPILE_TIME_ASSERT(sizeof(log_t) == 64U); COMPILE_TIME_ASSERT((LOGGING_FLASH_BASE_A + BANK_SIZE) == LOGGING_FLASH_BASE_B); @@ -67,7 +71,7 @@ void logging_init(void) { } } - logging_find_read_index(); + logging_init_read_index(); // At initialization, the read index should always be at the beginning of a bank // If not, clean slate diff --git a/board/main_comms.h b/board/main_comms.h index b5f758cb..c1591a06 100644 --- a/board/main_comms.h +++ b/board/main_comms.h @@ -493,8 +493,13 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) { // *** 0xfd: read logs case 0xfd: if (req->param1 == 1U) { - logging_find_read_index(); + logging_init_read_index(); } + + if (req->param2 != 0xFFFFU) { + logging_find_read_index(req->param2); + } + resp_len = logging_read(resp); break; default: diff --git a/python/__init__.py b/python/__init__.py index 705e62cf..ffa0b1be 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -1000,11 +1000,13 @@ class Panda: self._handle.controlWrite(Panda.REQUEST_OUT, 0xf7, int(enabled), 0, b'') # ****************** Logging ***************** - def get_logs(self, get_all=False): + def get_logs(self, last_id=None, get_all=False): + assert (last_id is None) or (0 <= last_id < 0xFFFF) + logs = [] - dat = self._handle.controlRead(Panda.REQUEST_IN, 0xfd, 1 if get_all else 0, 0, 0x40) + dat = self._handle.controlRead(Panda.REQUEST_IN, 0xfd, 1 if get_all else 0, last_id if last_id is not None else 0xFFFF, 0x40) while len(dat) > 0: if len(dat) == 0x40: logs.append(unpack_log(dat)) - dat = self._handle.controlRead(Panda.REQUEST_IN, 0xfd, 0, 0, 0x40) + dat = self._handle.controlRead(Panda.REQUEST_IN, 0xfd, 0, 0xFFFF, 0x40) return logs