pull/33215/head
Shane Smiskol 9 months ago
parent 24a07352b1
commit d97a786979
  1. 13
      selfdrive/car/car_helpers.py
  2. 12
      selfdrive/car/card.py

@ -9,19 +9,11 @@ from openpilot.selfdrive.car.fingerprints import eliminate_incompatible_cars, al
from openpilot.selfdrive.car.vin import get_vin, is_valid_vin, VIN_UNKNOWN from openpilot.selfdrive.car.vin import get_vin, is_valid_vin, VIN_UNKNOWN
from openpilot.selfdrive.car.fw_versions import get_fw_versions_ordered, get_present_ecus, match_fw_to_car from openpilot.selfdrive.car.fw_versions import get_fw_versions_ordered, get_present_ecus, match_fw_to_car
from openpilot.selfdrive.car.mock.values import CAR as MOCK from openpilot.selfdrive.car.mock.values import CAR as MOCK
import cereal.messaging as messaging
from openpilot.selfdrive.car import gen_empty_fingerprint from openpilot.selfdrive.car import gen_empty_fingerprint
FRAME_FINGERPRINT = 100 # 1s FRAME_FINGERPRINT = 100 # 1s
def get_one_can(logcan):
while True:
can = messaging.recv_one_retry(logcan)
if len(can.can) > 0:
return can
def load_interfaces(brand_names): def load_interfaces(brand_names):
ret = {} ret = {}
for brand_name in brand_names: for brand_name in brand_names:
@ -138,9 +130,8 @@ def fingerprint(logcan, sendcan, set_obd_multiplexing, num_pandas, cached_params
# CAN fingerprint # CAN fingerprint
# drain CAN socket so we get the latest messages # drain CAN socket so we get the latest messages
# messaging.drain_sock_raw(logcan) logcan.drain()
logcan() car_fingerprint, finger = can_fingerprint(logcan.get_one_can)
car_fingerprint, finger = can_fingerprint(lambda: get_one_can(logcan))
exact_match = True exact_match = True
source = car.CarParams.FingerprintSource.can source = car.CarParams.FingerprintSource.can

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import time import time
from types import SimpleNamespace
import cereal.messaging as messaging import cereal.messaging as messaging
@ -15,7 +16,7 @@ from openpilot.common.swaglog import cloudlog, ForwardingHandler
from openpilot.selfdrive.pandad import can_list_to_can_capnp from openpilot.selfdrive.pandad import can_list_to_can_capnp
from openpilot.selfdrive.car import DT_CTRL, carlog, make_can_msg from openpilot.selfdrive.car import DT_CTRL, carlog, make_can_msg
from openpilot.selfdrive.car.fw_versions import ObdCallback from openpilot.selfdrive.car.fw_versions import ObdCallback
from openpilot.selfdrive.car.car_helpers import get_car, get_one_can from openpilot.selfdrive.car.car_helpers import get_car
from openpilot.selfdrive.car.interfaces import CarInterfaceBase from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.controls.lib.events import Events from openpilot.selfdrive.controls.lib.events import Events
@ -38,6 +39,13 @@ def obd_callback(params: Params) -> ObdCallback:
return set_obd_multiplexing return set_obd_multiplexing
def get_one_can(logcan):
while True:
can = messaging.recv_one_retry(logcan)
if len(can.can) > 0:
return can
def can_recv_callbacks(logcan: messaging.SubSocket, sendcan: messaging.PubSocket): def can_recv_callbacks(logcan: messaging.SubSocket, sendcan: messaging.PubSocket):
def can_recv(wait_for_one: bool = False) -> list[list[int, bytes, int]]: # call rx/tx? def can_recv(wait_for_one: bool = False) -> list[list[int, bytes, int]]: # call rx/tx?
can_packets = messaging.drain_sock(logcan, wait_for_one=wait_for_one) can_packets = messaging.drain_sock(logcan, wait_for_one=wait_for_one)
@ -46,7 +54,7 @@ def can_recv_callbacks(logcan: messaging.SubSocket, sendcan: messaging.PubSocket
def can_send(msg: list[int, bytes, int]) -> None: def can_send(msg: list[int, bytes, int]) -> None:
sendcan.send(can_list_to_can_capnp([msg], msgtype='sendcan')) sendcan.send(can_list_to_can_capnp([msg], msgtype='sendcan'))
return can_recv, can_send return SimpleNamespace(drain=can_recv, get_one_can=lambda: get_one_can(logcan)), SimpleNamespace(send=can_send)
class Car: class Car:

Loading…
Cancel
Save