Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/commaai/opendbc into faw-…
Browse files Browse the repository at this point in the history
…hongqi-hs5
  • Loading branch information
jyoung8607 committed Oct 22, 2022
2 parents b28d0ad + 4e9acc8 commit 6994f10
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ COPY SConstruct .
COPY ./site_scons /project/site_scons
COPY . /project/opendbc

RUN rm -rf /project/opendbc/.git
RUN rm -rf /project/opendbc/.git && \
rm -rf /project/cereal/.git
RUN scons -c && scons -j$(nproc)
11 changes: 11 additions & 0 deletions can/common_dbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ struct DBC {
std::vector<Val> vals;
};

typedef struct ChecksumState {
int checksum_size;
int counter_size;
int checksum_start_bit;
int counter_start_bit;
bool little_endian;
SignalType checksum_type;
unsigned int (*calc_checksum)(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
} ChecksumState;

DBC* dbc_parse(const std::string& dbc_path);
DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, ChecksumState *checksum = nullptr);
const DBC* dbc_lookup(const std::string& dbc_name);
std::vector<std::string> get_dbc_names();
33 changes: 13 additions & 20 deletions can/dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ inline std::string& trim(std::string& s, const char* t = " \t\n\r\f\v") {
return s.erase(0, s.find_first_not_of(t));
}

typedef struct ChecksumState {
int checksum_size;
int counter_size;
int checksum_start_bit;
int counter_start_bit;
bool little_endian;
SignalType checksum_type;
unsigned int (*calc_checksum)(uint32_t address, const Signal &sig, const std::vector<uint8_t> &d);
} ChecksumState;

ChecksumState* get_checksum(const std::string& dbc_name) {
ChecksumState* s = nullptr;
if (startswith(dbc_name, {"honda_", "acura_"})) {
Expand Down Expand Up @@ -109,14 +99,7 @@ void set_signal_type(Signal& s, ChecksumState* chk, const std::string& dbc_name,
}
}

DBC* dbc_parse(const std::string& dbc_path) {
std::ifstream infile(dbc_path);
if (!infile) return nullptr;

const std::string dbc_name = std::filesystem::path(dbc_path).filename();

std::unique_ptr<ChecksumState> checksum(get_checksum(dbc_name));

DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, ChecksumState *checksum) {
uint32_t address = 0;
std::set<uint32_t> address_set;
std::set<std::string> msg_name_set;
Expand All @@ -136,7 +119,7 @@ DBC* dbc_parse(const std::string& dbc_path) {
int line_num = 0;
std::smatch match;
// TODO: see if we can speed up the regex statements in this loop, SG_ is specifically the slowest
while (std::getline(infile, line)) {
while (std::getline(stream, line)) {
line = trim(line);
line_num += 1;
if (startswith(line, "BO_ ")) {
Expand Down Expand Up @@ -170,7 +153,7 @@ DBC* dbc_parse(const std::string& dbc_path) {
sig.is_signed = match[offset + 5].str() == "-";
sig.factor = std::stod(match[offset + 6].str());
sig.offset = std::stod(match[offset + 7].str());
set_signal_type(sig, checksum.get(), dbc_name, line_num);
set_signal_type(sig, checksum, dbc_name, line_num);
if (sig.is_little_endian) {
sig.lsb = sig.start_bit;
sig.msb = sig.start_bit + sig.size - 1;
Expand Down Expand Up @@ -215,6 +198,16 @@ DBC* dbc_parse(const std::string& dbc_path) {
return dbc;
}

DBC* dbc_parse(const std::string& dbc_path) {
std::ifstream infile(dbc_path);
if (!infile) return nullptr;

const std::string dbc_name = std::filesystem::path(dbc_path).filename();

std::unique_ptr<ChecksumState> checksum(get_checksum(dbc_name));
return dbc_parse_from_stream(dbc_name, infile, checksum.get());
}

const std::string get_dbc_root_path() {
char *basedir = std::getenv("BASEDIR");
if (basedir != NULL) {
Expand Down
71 changes: 64 additions & 7 deletions hyundai_canfd.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ BO_ 53 ACCELERATOR: 32 XXX
SG_ GEAR : 192|3@1+ (1,0) [0|7] "" XXX
SG_ ACCELERATOR_PEDAL : 40|8@1+ (1,0) [0|255] "" XXX

BO_ 64 GEAR_ALT: 32 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ GEAR : 32|3@1+ (1,0) [0|7] "" XXX

BO_ 69 GEAR: 24 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
Expand Down Expand Up @@ -72,12 +77,13 @@ BO_ 96 ESP_STATUS: 32 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ ESP_DISABLED : 42|3@1+ (1,0) [0|63] "" XXX
SG_ BRAKE_POSITION : 128|10@1+ (1,0) [0|65535] "" XXX
SG_ BRAKE_PRESSURE : 128|10@1+ (1,0) [0|65535] "" XXX
SG_ BRAKE_PRESSED : 148|1@1+ (1,0) [0|3] "" XXX

BO_ 101 BRAKE: 32 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ BRAKE_POSITION : 40|16@1- (1,0) [0|65535] "" XXX
SG_ BRAKE_PRESSED : 57|1@1+ (1,0) [0|3] "" XXX

BO_ 160 WHEEL_SPEEDS: 24 XXX
Expand All @@ -98,6 +104,12 @@ BO_ 234 MDPS: 24 XXX
SG_ STEERING_ANGLE : 96|16@1- (-0.1,0) [0|255] "deg" XXX
SG_ STEERING_ANGLE_2 : 128|16@1- (-0.1,0) [0|65535] "deg" XXX

BO_ 256 ACCELERATOR_BRAKE_ALT: 32 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ BRAKE_PRESSED : 32|1@1+ (1,0) [0|1] "" XXX
SG_ ACCELERATOR_PEDAL_PRESSED : 176|1@1+ (1,0) [0|1] "" XXX

BO_ 261 ACCELERATOR_ALT: 32 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
Expand Down Expand Up @@ -132,11 +144,24 @@ BO_ 304 GEAR_SHIFTER: 16 XXX
SG_ GEAR : 64|3@1+ (1,0) [0|7] "" XXX
SG_ KNOB_POSITION : 40|3@1+ (1,0) [0|3] "" XXX

BO_ 373 SCC1: 24 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ ACCEL_REQ : 48|13@1- (1,0) [0|1023] "" XXX
SG_ CRUISE_ACTIVE : 68|1@0+ (1,0) [0|1] "" XXX
BO_ 373 TCS: 24 XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ NEW_SIGNAL_1 : 80|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_2 : 74|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_3 : 76|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_4 : 24|7@1+ (1,0) [0|127] "" XXX
SG_ aBasis : 32|11@1+ (0.01,-10.23) [0|7] "m/s^2" XXX
SG_ NEW_SIGNAL_5 : 72|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_6 : 128|4@1+ (1,0) [0|15] "" XXX
SG_ NEW_SIGNAL_7 : 135|2@0+ (1,0) [0|3] "" XXX
SG_ PROBABLY_EQUIP : 136|2@1+ (1,0) [0|3] "" XXX
SG_ AEB_EQUIP_MAYBE : 96|1@0+ (1,0) [0|1] "" XXX
SG_ EQUIP_MAYBE : 64|1@0+ (1,0) [0|1] "" XXX
SG_ DriverBraking : 81|1@0+ (1,0) [0|1] "" XXX
SG_ DriverBrakingLowSens : 84|1@1+ (1,0) [0|1] "" XXX
SG_ ACC_REQ : 68|1@0+ (1,0) [0|1] "" XXX
SG_ ACCEL_REF_ACC : 48|11@1- (1,0) [0|1023] "" XXX

BO_ 352 ADRV_0x160: 16 ADRV
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
Expand Down Expand Up @@ -468,14 +493,46 @@ BO_ 1043 BLINKERS: 8 XXX
BO_ 1240 CLUSTER_INFO: 8 XXX
SG_ DISTANCE_UNIT : 0|1@1+ (1,0) [0|1] "" XXX

BO_ 442 BLINDSPOTS_REAR_CORNERS: 24 XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ NEW_SIGNAL_1 : 31|2@0+ (1,0) [0|3] "" XXX
SG_ NEW_SIGNAL_2 : 96|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_3 : 54|6@0+ (1,0) [0|63] "" XXX
SG_ NEW_SIGNAL_4 : 46|2@0+ (1,0) [0|3] "" XXX
SG_ NEW_SIGNAL_5 : 42|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_6 : 32|2@1+ (1,0) [0|3] "" XXX
SG_ NEW_SIGNAL_7 : 24|1@0+ (1,0) [0|1] "" XXX

BO_ 874 BLINDSPOTS_FRONT_CORNER_2: 16 XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX

BO_ 485 BLINDSPOTS_FRONT_CORNER_1: 16 XXX
SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX
SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX
SG_ NEW_SIGNAL_1 : 108|2@0+ (1,0) [0|3] "" XXX
SG_ NEW_SIGNAL_2 : 96|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_3 : 88|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_4 : 80|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_5 : 31|2@0+ (1,0) [0|3] "" XXX
SG_ NEW_SIGNAL_6 : 24|1@0+ (1,0) [0|1] "" XXX
SG_ NEW_SIGNAL_7 : 32|2@1+ (1,0) [0|3] "" XXX
SG_ NEW_SIGNAL_8 : 47|8@0+ (1,0) [0|255] "" XXX
SG_ NEW_SIGNAL_9 : 55|8@0+ (1,0) [0|255] "" XXX

CM_ SG_ 96 BRAKE_PRESSURE "User applied brake pedal pressure. Ramps from computer applied pressure on falling edge of cruise. Cruise cancels if !=0";
CM_ SG_ 101 BRAKE_POSITION "User applied brake pedal position, max is ~700. Signed on some vehicles";
CM_ SG_ 352 SET_ME_9 "has something to do with AEB settings";
CM_ SG_ 373 DriverBraking "Likely derived from BRAKE->BRAKE_POSITION";
CM_ SG_ 373 DriverBrakingLowSens "Higher threshold version of DriverBraking";
CM_ SG_ 373 PROBABLY_EQUIP "aeb equip?";
CM_ SG_ 961 COUNTER_ALT "only increments on change";
CM_ SG_ 1041 COUNTER_ALT "only increments on change";
CM_ SG_ 1043 COUNTER_ALT "only increments on change";

VAL_ 53 GEAR 0 "P" 5 "D" 6 "N" 7 "R" ;
VAL_ 64 GEAR 0 "P" 5 "D" 6 "N" 7 "R" ;
VAL_ 69 GEAR 0 "P" 5 "D" 6 "N" 7 "R" ;
VAL_ 80 LKA_ICON 0 "hidden" 1 "grey" 2 "green" 3 "flashing green" ;
VAL_ 80 LKA_MODE 1 "warning only" 2 "assist" 6 "off" ;
Expand All @@ -486,4 +543,4 @@ VAL_ 304 GEAR 1 "P" 2 "R" 3 "N" 4 "D" ;
VAL_ 352 AEB_SETTING 1 "off" 2 "warning only" 3 "active assist" ;
VAL_ 416 CRUISE_STATUS 0 "cruise_inactive" 2 "cruise_active" 4 "driver_override" ;
VAL_ 426 CRUISE_BUTTONS 0 "none" 1 "res_accel" 2 "set_decel" 3 "gap_distance" 4 "pause_resume" ;
VAL_ 463 CRUISE_BUTTONS 0 "none" 1 "res_accel" 2 "set_decel" 3 "gap_distance" 4 "pause_resume" ;
VAL_ 463 CRUISE_BUTTONS 0 "none" 1 "res_accel" 2 "set_decel" 3 "gap_distance" 4 "pause_resume" ;
Loading

0 comments on commit 6994f10

Please sign in to comment.