live_logreader to its own file (#31436)

own file
This commit is contained in:
Justin Newberry
2024-02-13 16:29:52 -05:00
committed by GitHub
parent 7f7f1fd21b
commit d6762c3035
3 changed files with 33 additions and 28 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ import codecs
from hexdump import hexdump
from cereal import log
from cereal.services import SERVICE_LIST
from openpilot.tools.lib.logreader import raw_live_logreader
from openpilot.tools.lib.live_logreader import raw_live_logreader
codecs.register_error("strict", codecs.backslashreplace_errors)
+31
View File
@@ -0,0 +1,31 @@
import os
from typing import List
from cereal import log as capnp_log, messaging
from cereal.services import SERVICE_LIST
from openpilot.tools.lib.logreader import LogIterable, RawLogIterable
ALL_SERVICES = list(SERVICE_LIST.keys())
def raw_live_logreader(services: List[str] = ALL_SERVICES, addr: str = '127.0.0.1') -> RawLogIterable:
if addr != "127.0.0.1":
os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
poller = messaging.Poller()
for m in services:
messaging.sub_sock(m, poller, addr=addr)
while True:
polld = poller.poll(100)
for sock in polld:
msg = sock.receive()
yield msg
def live_logreader(services: List[str] = ALL_SERVICES, addr: str = '127.0.0.1') -> LogIterable:
for m in raw_live_logreader(services, addr):
with capnp_log.Event.from_bytes(m) as evt:
yield evt
+1 -27
View File
@@ -16,8 +16,7 @@ import warnings
from typing import Dict, Iterable, Iterator, List, Type
from urllib.parse import parse_qs, urlparse
from cereal import log as capnp_log, messaging
from cereal.services import SERVICE_LIST
from cereal import log as capnp_log
from openpilot.common.swaglog import cloudlog
from openpilot.tools.lib.comma_car_segments import get_url as get_comma_segments_url
from openpilot.tools.lib.openpilotci import get_url
@@ -294,31 +293,6 @@ are uploaded or auto fallback to qlogs with '/a' selector at the end of the rout
return next(self.filter(msg_type), None)
ALL_SERVICES = list(SERVICE_LIST.keys())
def raw_live_logreader(services: List[str] = ALL_SERVICES, addr: str = '127.0.0.1') -> RawLogIterable:
if addr != "127.0.0.1":
os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
poller = messaging.Poller()
for m in services:
messaging.sub_sock(m, poller, addr=addr)
while True:
polld = poller.poll(100)
for sock in polld:
msg = sock.receive()
yield msg
def live_logreader(services: List[str] = ALL_SERVICES, addr: str = '127.0.0.1') -> LogIterable:
for m in raw_live_logreader(services, addr):
with capnp_log.Event.from_bytes(m) as evt:
yield evt
if __name__ == "__main__":
import codecs
# capnproto <= 0.8.0 throws errors converting byte data to string