Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSK Fixes Sample #216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ struct CarParams {

wheelSpeedFactor @63 :Float32; # Multiplier on wheels speeds to computer actual speeds

secOCKey @74 :Data;

struct SafetyConfig {
safetyModel @0 :SafetyModel;
safetyParam @3 :UInt16;
Expand Down
1 change: 1 addition & 0 deletions common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"RecordFrontLock", PERSISTENT}, // for the internal fleet
{"ReplayControlsState", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION},
{"RouteCount", PERSISTENT},
{"SecOCKey", PERSISTENT},
{"SnoozeUpdate", CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION},
{"SshEnabled", PERSISTENT},
{"TermsVersion", PERSISTENT},
Expand Down
3 changes: 2 additions & 1 deletion selfdrive/car/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def controls_update(self, CS: car.CarState, CC: car.CarControl):
# send car controls over can
now_nanos = self.can_log_mono_time if REPLAY else int(time.monotonic() * 1e9)
self.last_actuators_output, can_sends = self.CI.apply(CC, now_nanos, self.frogpilot_toggles)
self.pm.send('sendcan', can_list_to_can_capnp(can_sends, msgtype='sendcan', valid=CS.canValid))
result = can_list_to_can_capnp(can_sends, msgtype='sendcan', valid=CS.canValid)
self.pm.send('sendcan', result)
Comment on lines +177 to +178
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this is unnecessary. This was part of me debugging why can_list_to_capnp was failing (it was the missing t value in secoc.py)


self.CC_prev = CC

Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/secoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def add_mac(key, trip_cnt, reset_cnt, msg_cnt, msg):
# TODO: clean up conversion to and from hex

addr, payload, bus = msg
addr, t, payload, bus = msg
reset_flag = reset_cnt & 0b11
msg_cnt_flag = msg_cnt & 0b11
payload = payload[:4]
Expand All @@ -30,7 +30,7 @@ def add_mac(key, trip_cnt, reset_cnt, msg_cnt, msg):
msg = payload.hex() + msg_cnt_rst_flag + mac
payload = bytes.fromhex(msg)

return (addr, payload, bus)
return (addr, t, payload, bus)

def build_sync_mac(key, trip_cnt, reset_cnt, id_=0xf):
id_ = struct.pack('>H', id_) # 16
Expand Down
6 changes: 3 additions & 3 deletions selfdrive/car/toyota/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def update(self, CC, CS, now_nanos, frogpilot_toggles):
self.secoc_lta_message_counter = 0
self.secoc_prev_reset_counter = CS.secoc_synchronization['RESET_CNT']

expected_mac = build_sync_mac(self.secoc_key, int(CS.secoc_synchronization['TRIP_CNT']), int(CS.secoc_synchronization['RESET_CNT']))
expected_mac = build_sync_mac(self.CP.secOCKey, int(CS.secoc_synchronization['TRIP_CNT']), int(CS.secoc_synchronization['RESET_CNT']))
if int(CS.secoc_synchronization['AUTHENTICATOR']) != expected_mac and self.secoc_mismatch_counter < 100:
self.secoc_mismatch_counter += 1

Expand Down Expand Up @@ -151,7 +151,7 @@ def update(self, CC, CS, now_nanos, frogpilot_toggles):
steer_command = toyotacan.create_steer_command(self.packer, apply_steer, apply_steer_req)
if self.CP.flags & ToyotaFlags.SECOC.value:
# TODO: check if this slow and needs to be done by the CANPacker
steer_command = add_mac(self.secoc_key,
steer_command = add_mac(self.CP.secOCKey,
int(CS.secoc_synchronization['TRIP_CNT']),
int(CS.secoc_synchronization['RESET_CNT']),
self.secoc_lka_message_counter,
Expand All @@ -174,7 +174,7 @@ def update(self, CC, CS, now_nanos, frogpilot_toggles):

if self.CP.flags & ToyotaFlags.SECOC.value:
lta_steer_2 = toyotacan.create_lta_steer_command_2(self.packer, self.frame // 2)
lta_steer_2 = add_mac(self.secoc_key,
lta_steer_2 = add_mac(self.CP.secOCKey,
int(CS.secoc_synchronization['TRIP_CNT']),
int(CS.secoc_synchronization['RESET_CNT']),
self.secoc_lta_message_counter,
Expand Down
9 changes: 6 additions & 3 deletions selfdrive/car/toyota/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class CarState(CarStateBase):
def __init__(self, CP):
super().__init__(CP)
can_define = CANDefine(DBC[CP.carFingerprint]["pt"])
self.shifter_values = can_define.dv["GEAR_PACKET"]["GEAR"]
self.eps_torque_scale = EPS_SCALE[CP.carFingerprint] / 100.
self.cluster_speed_hyst_gap = CV.KPH_TO_MS / 2.
self.cluster_min_speed = CV.KPH_TO_MS / 2.
Expand Down Expand Up @@ -237,8 +236,12 @@ def update(self, cp, cp_cam, CC, frogpilot_toggles):

fp_ret.dashboardSpeedLimit = calculate_speed_limit(cp_cam, frogpilot_toggles)

fp_ret.ecoGear = cp.vl["GEAR_PACKET"]['ECON_ON'] == 1
fp_ret.sportGear = cp.vl["GEAR_PACKET"]['SPORT_ON_2' if self.CP.flags & ToyotaFlags.NO_DSU else 'SPORT_ON'] == 1
if self.CP.flags & ToyotaFlags.SECOC.value:
fp_ret.ecoGear = False
fp_ret.sportGear = False
else:
fp_ret.ecoGear = cp.vl["GEAR_PACKET"]['ECON_ON'] == 1
fp_ret.sportGear = cp.vl["GEAR_PACKET"]['SPORT_ON_2' if self.CP.flags & ToyotaFlags.NO_DSU else 'SPORT_ON'] == 1

if self.CP.carFingerprint != CAR.TOYOTA_PRIUS_V:
self.lkas_previously_enabled = self.lkas_enabled
Expand Down
13 changes: 12 additions & 1 deletion selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from cereal import car, custom
from panda import Panda
from panda.python import uds
from openpilot.common.params import Params
from openpilot.selfdrive.car.toyota.values import Ecu, CAR, DBC, ToyotaFlags, CarControllerParams, TSS2_CAR, RADAR_ACC_CAR, NO_DSU_CAR, \
MIN_ACC_SPEED, EPS_SCALE, UNSUPPORTED_DSU_CAR, NO_STOP_TIMER_CAR, ANGLE_CONTROL_CAR, STOP_AND_GO_CAR
from openpilot.selfdrive.car import create_button_events, get_safety_config
Expand Down Expand Up @@ -29,7 +30,7 @@ def _get_params(ret, candidate, fingerprint, car_fw, disable_openpilot_long, exp
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_TOYOTA_ALT_BRAKE

if ret.flags & ToyotaFlags.SECOC.value:
ret.secOcRequired = True
# ret.secOcRequired = True
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this was for. Doesn't look like any code used it when I did a find-in-all-files search for secOcRequired so I've just commented it out to get FrogPilot running.

ret.safetyConfigs[0].safetyParam |= Panda.FLAG_TOYOTA_SECOC

if candidate in ANGLE_CONTROL_CAR:
Expand Down Expand Up @@ -147,6 +148,16 @@ def _get_params(ret, candidate, fingerprint, car_fw, disable_openpilot_long, exp
# to a negative value, so it won't matter.
ret.minEnableSpeed = -1. if (candidate in STOP_AND_GO_CAR or ret.enableGasInterceptor) else MIN_ACC_SPEED

# Read SecOC key from param
if ret.flags & ToyotaFlags.SECOC.value:
key = Params().get("SecOCKey", encoding='utf8')

# TODO: show warning, and handle setting key in CI
if key is None:
key = "0" * 32

ret.secOCKey = bytes.fromhex(key.strip())

tune = ret.longitudinalTuning
if candidate in TSS2_CAR:
tune.kpV = [0.0]
Expand Down
Loading