mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
Logging (#1445)
* try 1 * some fixes * fix some misra * first poc working * more things * more misra fixes * fix misra * add rate limiting * fix misra * add some unit tests through libpanda * add more tests and fix some stuff * fix misra again * add startup log hitl test * list * don't fail on wrong timestamps * improvements * fix tests * expected logs test? * not sure why this passed * oh, it doesn't reset * only show last few * guess at expected logs * needs this * ugh * reduce compiler warnings * adjust expected logs * this is correct * is it really 1? * min max * reduce spam in SPI test * some cleanup
This commit is contained in:
@@ -122,6 +122,24 @@ def ensure_can_health_packet_version(fn):
|
||||
return fn(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
def parse_timestamp(dat):
|
||||
a = struct.unpack("HBBBBBB", dat)
|
||||
if a[0] == 0:
|
||||
return None
|
||||
|
||||
try:
|
||||
return datetime.datetime(a[0], a[1], a[2], a[4], a[5], a[6])
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
def unpack_log(dat):
|
||||
return {
|
||||
'id': struct.unpack("H", dat[:2])[0],
|
||||
'timestamp': parse_timestamp(dat[2:10]),
|
||||
'uptime': struct.unpack("I", dat[10:14])[0],
|
||||
'msg': bytes(dat[14:]).decode('utf-8', 'ignore').strip('\x00'),
|
||||
}
|
||||
|
||||
class ALTERNATIVE_EXPERIENCE:
|
||||
DEFAULT = 0
|
||||
DISABLE_DISENGAGE_ON_GAS = 1
|
||||
@@ -941,8 +959,7 @@ class Panda:
|
||||
|
||||
def get_datetime(self):
|
||||
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xa0, 0, 0, 8)
|
||||
a = struct.unpack("HBBBBBB", dat)
|
||||
return datetime.datetime(a[0], a[1], a[2], a[4], a[5], a[6])
|
||||
return parse_timestamp(dat)
|
||||
|
||||
# ****************** Timer *****************
|
||||
def get_microsecond_timer(self):
|
||||
@@ -973,3 +990,13 @@ class Panda:
|
||||
# ****************** Debug *****************
|
||||
def set_green_led(self, enabled):
|
||||
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf7, int(enabled), 0, b'')
|
||||
|
||||
# ****************** Logging *****************
|
||||
def get_logs(self, get_all=False):
|
||||
logs = []
|
||||
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xfd, 1 if get_all else 0, 0, 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)
|
||||
return logs
|
||||
|
||||
Reference in New Issue
Block a user