forked from commaai/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ae851c
commit fec4d03
Showing
19 changed files
with
355 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from collections.abc import Callable | ||
|
||
import cereal.messaging as messaging | ||
from openpilot.selfdrive.car import gen_empty_fingerprint | ||
|
||
FRAME_FINGERPRINT = 25 # 0.25s | ||
|
||
|
||
def get_one_can(logcan): | ||
while True: | ||
can = messaging.recv_one_retry(logcan) | ||
if len(can.can) > 0: | ||
return can | ||
|
||
|
||
def can_fingerprint(next_can: Callable) -> tuple[str | None, dict[int, dict]]: | ||
finger = gen_empty_fingerprint() | ||
frame = 0 | ||
done = False | ||
|
||
while not done: | ||
a = next_can() | ||
|
||
for can in a.can: | ||
# The fingerprint dict is generated for all buses, this way the car interface | ||
# can use it to detect a (valid) multipanda setup and initialize accordingly | ||
if can.src < 128: | ||
if can.src not in finger: | ||
finger[can.src] = {} | ||
finger[can.src][can.address] = len(can.dat) | ||
|
||
# bail if we've been waiting for more than 2s | ||
done = frame > 100 | ||
|
||
frame += 1 | ||
|
||
return finger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from openpilot.selfdrive.car.isotp_parallel_query import IsoTpParallelQuery | ||
from openpilot.common.swaglog import cloudlog | ||
|
||
EXT_DIAG_REQUEST = b'\x10\x07' | ||
EXT_DIAG_RESPONSE = b'\x50\x07' | ||
|
||
WRITE_DATA_REQUEST = b'\x2e' | ||
WRITE_DATA_RESPONSE = b'\x68' | ||
|
||
RADAR_TRACKS_CONFIG = b"\x00\x00\x00\x01\x00\x01" | ||
|
||
|
||
def enable_radar_tracks(logcan, sendcan, bus=0, addr=0x7d0, config_data_id=b'\x01\x42', timeout=0.1, retry=10, debug=False): | ||
cloudlog.warning("radar_tracks: enabling ...") | ||
|
||
for i in range(retry): | ||
try: | ||
query = IsoTpParallelQuery(sendcan, logcan, bus, [addr], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug) | ||
|
||
for _, _ in query.get_data(timeout).items(): | ||
cloudlog.warning("radar_tracks: reconfigure radar to output radar points ...") | ||
|
||
query = IsoTpParallelQuery(sendcan, logcan, bus, [addr], | ||
[WRITE_DATA_REQUEST + config_data_id + RADAR_TRACKS_CONFIG], | ||
[WRITE_DATA_RESPONSE], debug=debug) | ||
query.get_data(0) | ||
|
||
cloudlog.warning("radar_tracks: successfully enabled") | ||
return True | ||
|
||
except Exception as e: | ||
cloudlog.exception(f"radar_tracks exception: {e}") | ||
|
||
cloudlog.error(f"radar_tracks retry ({i + 1}) ...") | ||
cloudlog.error(f"radar_tracks: failed") | ||
return False | ||
|
||
|
||
if __name__ == "__main__": | ||
import time | ||
import cereal.messaging as messaging | ||
sendcan = messaging.pub_sock('sendcan') | ||
logcan = messaging.sub_sock('can') | ||
time.sleep(1) | ||
|
||
enabled = enable_radar_tracks(logcan, sendcan, bus=0, addr=0x7d0, config_data_id=b'\x01\x42', timeout=0.1, debug=False) | ||
print(f"enabled: {enabled}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.