Skip to content

Commit

Permalink
Merge branch 'master' into faw-hongqi-hs5
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoung8607 committed Oct 16, 2022
2 parents 9adaf4b + dde0ff6 commit b28d0ad
Show file tree
Hide file tree
Showing 23 changed files with 1,123 additions and 283 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ repos:
- id: check-yaml
- id: check-merge-conflict
- id: check-symlinks
- repo: https://github.com/codespell-project/codespell
rev: v2.2.1
hooks:
- id: codespell
exclude: '\.dbc$'
args:
- --check-hidden
- --builtins clear,rare,informal,usage,code,names,en-GB_to_en-US
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
hooks:
Expand Down
14 changes: 8 additions & 6 deletions can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ int64_t get_raw_value(const std::vector<uint8_t> &msg, const Signal &sig) {
int msb = (int)(sig.msb / 8) == i ? sig.msb : (i+1)*8 - 1;
int size = msb - lsb + 1;

uint8_t d = (msg[i] >> (lsb - (i*8))) & ((1ULL << size) - 1);
uint64_t d = (msg[i] >> (lsb - (i*8))) & ((1ULL << size) - 1);
ret |= d << (bits - size);

bits -= size;
Expand Down Expand Up @@ -127,7 +127,7 @@ CANParser::CANParser(int abus, const std::string& dbc_name,
}

state.size = msg->size;
assert(state.size < 64); // max signal size is 64 bytes
assert(state.size <= 64); // max signal size is 64 bytes

// track checksums and counters for this message
for (const auto& sig : msg->sigs) {
Expand Down Expand Up @@ -287,10 +287,12 @@ void CANParser::UpdateValid(uint64_t sec) {
const bool missing = state.last_seen_nanos == 0;
const bool timed_out = (sec - state.last_seen_nanos) > state.check_threshold;
if (state.check_threshold > 0 && (missing || timed_out)) {
if (missing) {
LOGE("0x%X MISSING", state.address);
} else if (show_missing) {
LOGE("0x%X TIMEOUT", state.address);
if (show_missing && !bus_timeout) {
if (missing) {
LOGE("0x%X NOT SEEN", state.address);
} else if (timed_out) {
LOGE("0x%X TIMED OUT", state.address);
}
}
_valid = false;
}
Expand Down
9 changes: 9 additions & 0 deletions can/tests/test.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ BO_ 228 STEERING_CONTROL: 5 EON
SG_ COUNTER : 37|2@0+ (1,0) [0|3] "" EPS
SG_ CHECKSUM : 35|4@0+ (1,0) [0|15] "" EPS

BO_ 316 Brake_Status: 8 XXX
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
SG_ Signal1 : 12|46@1+ (1,0) [0|1] "" XXX
SG_ ES_Brake : 58|1@1+ (1,0) [0|1] "" XXX
SG_ Signal2 : 59|3@1+ (1,0) [0|1] "" XXX
SG_ Brake : 62|1@1+ (1,0) [0|1] "" XXX
SG_ Signal3 : 63|1@1+ (1,0) [0|1] "" XXX

BO_ 245 CAN_FD_MESSAGE: 32 XXX
SG_ COUNTER : 7|8@0+ (1,0) [0|1] "" XXX
SG_ SIGNED : 22|16@0- (1,0) [0|1] "" XXX
Expand Down
42 changes: 22 additions & 20 deletions can/tests/test_packer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,41 @@ def test_packer_parser(self):
("STEER_TORQUE", "STEERING_CONTROL"),
("STEER_TORQUE_REQUEST", "STEERING_CONTROL"),

("Signal1", "Brake_Status"),

("COUNTER", "CAN_FD_MESSAGE"),
("64_BIT_LE", "CAN_FD_MESSAGE"),
("64_BIT_BE", "CAN_FD_MESSAGE"),
("SIGNED", "CAN_FD_MESSAGE"),
]
checks = [("STEERING_CONTROL", 0), ("CAN_FD_MESSAGE", 0)]

packer = CANPacker(TEST_DBC)
parser = CANParser(TEST_DBC, signals, checks, 0)
parser = CANParser(TEST_DBC, signals, [], 0, enforce_checks=False)

for steer in range(-256, 255):
for active in (1, 0):
v1 = {
"STEER_TORQUE": steer,
"STEER_TORQUE_REQUEST": active,
}
m1 = packer.make_can_msg("STEERING_CONTROL", 0, v1)

v2 = {
"SIGNED": steer,
"64_BIT_LE": random.randint(0, 100),
"64_BIT_BE": random.randint(0, 100),
values = {
"STEERING_CONTROL": {
"STEER_TORQUE": steer,
"STEER_TORQUE_REQUEST": active,
},
"Brake_Status": {
"Signal1": 61042322657536.0,
},
"CAN_FD_MESSAGE": {
"SIGNED": steer,
"64_BIT_LE": random.randint(0, 100),
"64_BIT_BE": random.randint(0, 100),
},
}
m2 = packer.make_can_msg("CAN_FD_MESSAGE", 0, v2)

bts = can_list_to_can_capnp([m1, m2])
msgs = [packer.make_can_msg(k, 0, v) for k, v in values.items()]
bts = can_list_to_can_capnp(msgs)
parser.update_string(bts)

for key, val in v1.items():
self.assertAlmostEqual(parser.vl["STEERING_CONTROL"][key], val)

for key, val in v2.items():
self.assertAlmostEqual(parser.vl["CAN_FD_MESSAGE"][key], val)
for k, v in values.items():
for key, val in v.items():
self.assertAlmostEqual(parser.vl[k][key], val)

# also check address
for sig in ("STEER_TORQUE", "STEER_TORQUE_REQUEST", "COUNTER", "CHECKSUM"):
Expand Down Expand Up @@ -173,7 +175,7 @@ def test_scale_offset(self):
self.assertAlmostEqual(parser.vl["VSA_STATUS"]["USER_BRAKE"], brake)

def test_subaru(self):
# Subuaru is little endian
# Subaru is little endian

dbc_file = "subaru_global_2017_generated"

Expand Down
3 changes: 2 additions & 1 deletion ford_lincoln_base_pt.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,8 @@ BO_ 984 IPMA_Data: 8 IPMA_ADAS
SG_ DasStats_D_Dsply : 47|2@0+ (1,0) [0|3] "SED" GWM
SG_ DasWarn_D_Dsply : 44|2@0+ (1,0) [0|3] "SED" GWM
SG_ AhbHiBeam_D_Rq : 59|2@0+ (1,0) [0|3] "SED" GWM
SG_ Set_Me_X1 : 63|4@0+ (1,0) [0|15] "" XXX
SG_ Passthru_63 : 63|4@0+ (1,0) [0|15] "" XXX
SG_ Passthru_48 : 48|1@0+ (1,0) [0|1] "" XXX

BO_ 985 IPMA_Data2: 8 IPMA_ADAS
SG_ LdwChime_B_Rq : 34|1@0+ (1,0) [0|1] "SED" GWM
Expand Down
3 changes: 3 additions & 0 deletions generator/gm/gm_global_a_powertrain.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ BO_ 388 PSCMStatus: 8 K43_PSCM
SG_ LKADriverAppldTrq : 50|11@0- (0.01,0) [-10.24|10.23] "Nm" NEO
SG_ LKATorqueDelivered : 18|11@0- (0.01,0) [0|1] "" NEO
SG_ LKATotalTorqueDelivered : 2|11@0- (0.01,0) [-10.24|10.23] "Nm" NEO
SG_ RollingCounter : 38|4@0+ (1,0) [0|15] "" XXX
SG_ PSCMStatusChecksum : 33|10@0+ (1,0) [0|1023] "" XXX

BO_ 417 AcceleratorPedal: 7 XXX
SG_ AcceleratorPedal : 55|8@0+ (1,0) [0|0] "" NEO
Expand Down Expand Up @@ -267,6 +269,7 @@ CM_ BU_ K114B_HPCM "Hybrid Powertrain Control Module";
CM_ BU_ NEO "Comma NEO";
CM_ BU_ K124_ASCM "Active Safety Control Module";
CM_ SG_ 381 MSG17D_AccPower "Need to investigate";
CM_ BO_ 190 "Length varies from 6 to 8 bytes by car";
CM_ SG_ 190 GasPedalAndAcc "ACC baseline is 62";
CM_ SG_ 352 Ignition "Non-zero when ignition is on";
CM_ SG_ 451 GasPedalAndAcc2 "ACC baseline is 62";
Expand Down
6 changes: 3 additions & 3 deletions generator/honda/honda_civic_ex_2022_can.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ BO_ 432 STANDSTILL: 7 VSA
BO_ 456 ACC_CONTROL: 8 XXX
SG_ ACCEL_COMMAND : 7|12@0- (0.01,0) [0|0] "m/s^2" XXX
SG_ CONTROL_OFF : 8|1@0+ (1,0) [0|1] "" XXX
SG_ STANDSTILL : 9|1@0+ (1,0) [0|1] "" XXX
SG_ CONTROL_ON : 10|1@0+ (1,0) [0|1] "" XXX
SG_ BOH : 23|1@0+ (1,0) [0|1] "" XXX
SG_ AEB_STATUS : 33|1@1+ (1,0) [0|7] "" XXX
Expand Down Expand Up @@ -69,9 +70,8 @@ BO_ 254913108 LKAS_HUD_2: 8 ADAS
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" XXX
SG_ CHECKSUM : 59|4@0+ (1,0) [0|15] "" XXX

CM_ BO 456 "not sure which bit enables cruise";
CM_ SG_ 456 ACCEL_COMMAND "seems to be m/s^2? need to verify";
CM_ SG_ 456 BOH "could be cruise standstill?";
CM_ BO_ 456 "not sure which bit enables cruise";
CM_ SG_ 456 STANDSTILL "set to 1 when camera requests -4.0 m/s^2";

VAL_ 401 GEAR_SHIFTER 32 "L" 16 "S" 8 "D" 4 "N" 2 "R" 1 "P";
VAL_ 401 GEAR 7 "L" 10 "S" 4 "D" 3 "N" 2 "R" 1 "P";
2 changes: 2 additions & 0 deletions generator/hyundai/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hyundai_kia_mando_front_radar.dbc
hyundai_kia_mando_corner_radar.dbc
170 changes: 170 additions & 0 deletions generator/hyundai/hyundai_kia_mando_corner_radar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#!/usr/bin/env python3
from collections import namedtuple
import os

if __name__ == "__main__":
dbc_name = os.path.basename(__file__).replace(".py", ".dbc")
hyundai_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(hyundai_path, dbc_name), "w") as f:
f.write("""
VERSION ""
NS_ :
NS_DESC_
CM_
BA_DEF_
BA_
VAL_
CAT_DEF_
CAT_
FILTER
BA_DEF_DEF_
EV_DATA_
ENVVAR_DATA_
SGTYPE_
SGTYPE_VAL_
BA_DEF_SGTYPE_
BA_SGTYPE_
SIG_TYPE_REF_
VAL_TABLE_
SIG_GROUP_
SIG_VALTYPE_
SIGTYPE_VALTYPE_
BO_TX_BU_
BA_DEF_REL_
BA_REL_
BA_DEF_DEF_REL_
BU_SG_REL_
BU_EV_REL_
BU_BO_REL_
SG_MUL_VAL_
BS_:
BU_: XXX
""")

for a in [0x100, 0x200]:
f.write(f"""
BO_ {a} RADAR_POINTS_METADATA_0x{a:x}: 64 RADAR
SG_ SIGNAL_1 : 0|32@1+ (1,0) [0|255] "" XXX
SG_ SIGNAL_2 : 32|32@1+ (1,0) [0|65535] "" XXX
SG_ SIGNAL_3 : 64|4@1+ (1,0) [0|15] "" XXX
SG_ SIGNAL_4 : 68|4@1+ (1,0) [0|15] "" XXX
SG_ RADAR_POINT_COUNT : 72|8@1+ (1,0) [0|255] "" XXX
SG_ SIGNAL_6 : 80|7@1+ (0.015625,0) [0|3] "" XXX
SG_ SIGNAL_7 : 87|1@1+ (1,0) [0|1] "" XXX
SG_ SIGNAL_8 : 88|3@1+ (1,0) [0|7] "" XXX
SG_ SIGNAL_9 : 91|5@1+ (0.0625,0) [0|31] "" XXX
SG_ SIGNAL_10 : 96|8@1+ (1,0) [0|255] "" XXX
SG_ SIGNAL_11 : 104|7@1+ (0.015625,0) [0|127] "" XXX
SG_ SIGNAL_12 : 111|2@1+ (1,0) [0|65535] "" XXX
SG_ SIGNAL_13 : 113|7@1+ (0.015625,0) [0|127] "" XXX
SG_ SIGNAL_14 : 120|7@1+ (0.015625,0) [0|127] "" XXX
SG_ SIGNAL_15 : 127|3@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_16 : 130|2@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_17 : 133|2@0+ (1,0) [0|3] "" XXX
SG_ SIGNAL_18 : 134|1@0+ (1,0) [0|3] "" XXX
SG_ SIGNAL_19 : 135|3@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_20 : 138|8@1+ (1,0) [0|63] "" XXX
SG_ SIGNAL_21 : 146|2@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_22 : 148|1@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_23 : 149|4@1+ (1,0) [0|7] "" XXX
SG_ SIGNAL_24 : 153|1@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_25 : 154|2@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_26 : 157|2@0+ (1,0) [0|3] "" XXX
SG_ SIGNAL_27 : 158|7@1+ (0.125,0) [0|3] "" XXX
SG_ SIGNAL_28 : 165|7@1+ (0.015625,0) [0|31] "" XXX
SG_ SIGNAL_29 : 172|7@1+ (0.125,0) [0|3] "" XXX
SG_ SIGNAL_30 : 179|7@1+ (0.015625,0) [0|1] "" XXX
SG_ SIGNAL_31 : 186|4@1+ (1,0) [0|7] "" XXX
SG_ SIGNAL_32 : 190|14@1+ (0.015625,0) [0|15] "" XXX
SG_ SIGNAL_33 : 204|11@1+ (0.03125,0) [0|8191] "" XXX
SG_ SIGNAL_34 : 215|2@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_35 : 217|7@1+ (1,0) [0|127] "" XXX
SG_ SIGNAL_36 : 224|6@1+ (1,0) [0|63] "" XXX
SG_ SIGNAL_37 : 230|6@1+ (0.2,0) [0|31] "" XXX
SG_ SIGNAL_38 : 236|6@1+ (0.2,0) [0|7] "" XXX
SG_ SIGNAL_39 : 242|8@1+ (1,-90) [0|255] "" XXX
SG_ SIGNAL_40 : 250|6@1+ (1,0) [0|63] "" XXX
SG_ SIGNAL_41 : 256|8@1+ (0.25,0) [0|255] "" XXX
SG_ SIGNAL_42 : 264|3@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_43 : 267|12@1+ (0.01,0) [0|31] "" XXX
SG_ SIGNAL_44 : 279|32@1+ (1,0) [0|63] "" XXX
SG_ SIGNAL_45 : 311|1@1+ (1,0) [0|1] "" XXX
SG_ SIGNAL_46 : 312|2@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_47 : 314|32@1+ (1,0) [0|255] "" XXX
SG_ SIGNAL_48 : 346|6@1+ (1,0) [0|63] "" XXX
SG_ SIGNAL_49 : 352|7@1+ (0.25,0) [0|127] "" XXX
SG_ SIGNAL_50 : 359|6@1+ (0.03125,0) [0|31] "" XXX
SG_ SIGNAL_51 : 365|10@1+ (0.125,0) [0|3] "" XXX
SG_ SIGNAL_52 : 375|10@1+ (0.125,0) [0|63] "" XXX
SG_ SIGNAL_53 : 385|7@1+ (1,0) [0|127] "" XXX
SG_ SIGNAL_54 : 392|7@1+ (1,0) [0|127] "" XXX
SG_ SIGNAL_55 : 399|8@1+ (0.00390625,0) [0|31] "" XXX
SG_ SIGNAL_56 : 407|10@1+ (0.125,0) [0|63] "" XXX
SG_ SIGNAL_57 : 417|1@1+ (1,0) [0|3] "" XXX
SG_ SIGNAL_58 : 418|1@1+ (1,0) [0|3] "" XXX
""")

# radar points are sent at 20 Hz in groups of 1 to 13 messages
# each message has 5 radar points for a total of 65 points max
# each radar point is 101 bits so the alignment is not consistent
RadarPointSignal = namedtuple("RadarPointSignal", ["name", "start", "length", "scale", "offset"])
radar_point_signals = (
RadarPointSignal("DISTANCE", 7, 14, 1/64, 0),
RadarPointSignal("", 21, 2, 1, 0),
RadarPointSignal("", 23, 8, 1/512, -127/512),
RadarPointSignal("REL_VELOCITY", 31, 13, 1/32, -66),
RadarPointSignal("", 44, 2, 1, 0),
RadarPointSignal("", 46, 2, 1, 0),
RadarPointSignal("AZIMUTH", 48, 12, 1/512, -2047/512),
RadarPointSignal("", 60, 2, 1, 0),
RadarPointSignal("", 62, 1, 1, 0),
RadarPointSignal("", 63, 7, 1, 0),
RadarPointSignal("", 70, 1, 1, 0),
RadarPointSignal("", 71, 6, 1, 0),
RadarPointSignal("", 77, 2, 1, 0),
RadarPointSignal("", 79, 8, 1/512, -127/512),
RadarPointSignal("", 87, 1, 1, 0),
RadarPointSignal("", 88, 2, 1, 0),
RadarPointSignal("", 90, 3, 1, 0),
# last 15 bits are controlled by LAYOUT_ID (seems to always zero, so below is layout 0)
RadarPointSignal("", 93, 6, 1, 0),
RadarPointSignal("", 99, 8, 1, 0),
RadarPointSignal("", 107, 1, 1, 0),
)
radar_point_bit_count = sum([s.length for s in radar_point_signals])

for a in [0x101, 0x201]:
f.write(f"""
BO_ {a} RADAR_POINTS_0x{a:x}: 64 RADAR
SG_ MESSAGE_ID : 0|5@1+ (1,0) [0|31] "" XXX
SG_ LAYOUT_ID : 5|2@1+ (1,0) [0|3] "" XXX
""")
bit_idx = radar_point_signals[0].start
for i in range(5):
signal_idx = 1
for sig in radar_point_signals:
if sig.name:
sig_name = f"POINT_{i+1}_{sig.name}"
else:
sig_name = f"POINT_{i+1}_SIGNAL_{signal_idx}"
signal_idx += 1

sig_start_idx = i * radar_point_bit_count + sig.start
assert bit_idx == sig_start_idx, f"signal overlap or gap!!! {bit_idx} != {sig_start_idx}"
min_val = round(sig.offset, 10)
max_val = round((2**sig.length - 1) * sig.scale + sig.offset, 10)

f.write(f" SG_ {sig_name} : {sig_start_idx}|{sig.length}@1+ ({sig.scale},{sig.offset}) [{min_val}|{max_val}] \"\" XXX\n")
bit_idx += sig.length

# checksum is across a group of 0x100/200 and 0x101/201 messages (no checksums inside the other messages)
# ccitt_crc16 = mkCrcFun(0x11021, initCrc=0xffff, xorOut=0x0000, rev=False)
for a in [0x104, 0x204]:
f.write(f"""
BO_ {a} RADAR_POINTS_CHECKSUM_0x{a:x}: 3 RADAR
SG_ CRC16 : 0|16@1+ (1,0) [0|65535] "" XXX
""")
Loading

0 comments on commit b28d0ad

Please sign in to comment.