Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2eeb6a8
Create ocelot_can.dbc
ReFil Jan 29, 2021
2a9c799
Update ocelot_can.dbc
ReFil Jan 30, 2021
b0136d5
smart chassis can addition
ReFil Jan 30, 2021
c04e270
add HIM
ReFil Jan 30, 2021
2f47983
Update ocelot_can.dbc
ReFil Jan 31, 2021
b85bad2
Update ocelot_can.dbc
ReFil Feb 15, 2021
3ccd122
fix syntax errors
ReFil Feb 19, 2021
03b188c
formatting
ReFil Feb 26, 2021
dea6172
New checksum functions
ReFil Feb 27, 2021
412a14d
fixes and more data
ReFil Mar 2, 2021
c4fb640
Update ocelot_can.dbc
ReFil Mar 6, 2021
58bb055
Fixes, new CRC
ReFil Mar 7, 2021
ee793c2
Update ocelot_can.dbc
ReFil Mar 19, 2021
46fce4d
Fixes
ReFil Mar 23, 2021
c12e7c3
Update ocelot_can.dbc
ReFil Mar 25, 2021
48a8b04
Update fron arnepilot
ReFil Apr 26, 2021
839c2a0
Update ocelot_can.dbc
ReFil May 4, 2021
12a0051
Update ocelot_can.dbc
ReFil May 6, 2021
525ba53
ocelot_controls
Feb 21, 2022
4c014cf
cleanup steering messages
Feb 21, 2022
7f7d1aa
fix steering status size
Feb 21, 2022
7fc4b0c
fix sizes again
Feb 21, 2022
b1d3a96
ocelot steering bytes
Feb 23, 2022
7994ffa
unify actuators and ocelot
Feb 23, 2022
d3a564a
Removed unused enum
dzid26 Feb 28, 2022
da723ec
Torque sensor in seperate message
dzid26 Feb 28, 2022
ef3e79d
Physical ranges torque and angle. 2 exponent factors. Steering veloci…
dzid26 Feb 28, 2022
7c2315a
A signal with more than 8 (or 16) bits should lie on a (two-)byte limit.
dzid26 Feb 28, 2022
ccb3ffa
DBC tools save extra space
dzid26 Jul 25, 2022
551be74
Shortened names
dzid26 Jul 25, 2022
4cc03f7
Steering signals
dzid26 Aug 5, 2022
2771cbb
Checksum description
dzid26 Aug 9, 2022
44b7dce
A signal with more than 8 (or 16) bits should lie on a (two-)byte limit.
dzid26 Nov 10, 2022
6266294
RelativeControl replaced with more generic AngleControl for clarity
dzid26 Nov 10, 2022
fe342e9
Removed driver torque message
dzid26 Nov 10, 2022
649e0b8
Crc description
dzid26 Mar 30, 2023
9c4b5a1
Revert "A signal with more than 8 (or 16) bits should lie on a (two-)…
dzid26 Mar 30, 2023
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
14 changes: 14 additions & 0 deletions can/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l) {

// Static lookup table for fast computation of CRC8 poly 0x2F, aka 8H2F/AUTOSAR
uint8_t crc8_lut_8h2f[256];
uint8_t crc8_lut_1d[256];

void gen_crc_lookup_table(uint8_t poly, uint8_t crc_lut[]) {
uint8_t crc;
Expand All @@ -90,6 +91,7 @@ void init_crc_lookup_tables() {
// At init time, set up static lookup tables for fast CRC computation.

gen_crc_lookup_table(0x2F, crc8_lut_8h2f); // CRC-8 8H2F/AUTOSAR for Volkswagen
gen_crc_lookup_table(0x1D, crc8_lut_1d); // CRC-8 SAE-j18650 for Retropilot
}

unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l) {
Expand Down Expand Up @@ -190,6 +192,18 @@ unsigned int pedal_checksum(uint64_t d, int l) {
return crc;
}

unsigned int ocelot_checksum(uint64_t d, int l) {
uint8_t crc = 0xFF; // Standard init value for CRC8

// CRC the payload, skipping over the first byte where the CRC lives.
for (int i = 1; i < l; i++) {
crc ^= (d >> (i*8)) & 0xFF;
crc = crc8_lut_1d[crc] ^ crc << 8 ;
}
crc = crc ^ 0xFF; //final xor

return crc;
}

uint64_t read_u64_be(const uint8_t* v) {
return (((uint64_t)v[0] << 56)
Expand Down
1 change: 1 addition & 0 deletions can/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l);
void init_crc_lookup_tables();
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l);
unsigned int pedal_checksum(uint64_t d, int l);
unsigned int ocelot_checksum(uint64_t d, int l);
uint64_t read_u64_be(const uint8_t* v);
uint64_t read_u64_le(const uint8_t* v);

Expand Down
4 changes: 3 additions & 1 deletion can/common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ cdef extern from "common_dbc.h":
VOLKSWAGEN_CHECKSUM,
VOLKSWAGEN_COUNTER,
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM
CHRYSLER_CHECKSUM,
OCELOT_CHECKSUM,
OCELOT_COUNTER

cdef struct Signal:
const char* name
Expand Down
2 changes: 2 additions & 0 deletions can/common_dbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ enum SignalType {
VOLKSWAGEN_COUNTER,
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM,
OCELOT_CHECKSUM,
OCELOT_COUNTER,
};

struct Signal {
Expand Down
94 changes: 94 additions & 0 deletions can/common_pyx_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import os
import subprocess
import sysconfig
import platform
from distutils.core import Extension, setup # pylint: disable=import-error,no-name-in-module

from Cython.Build import cythonize
from Cython.Distutils import build_ext


ANNOTATE = os.getenv('ANNOTATE') is not None
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../"))


def get_ext_filename_without_platform_suffix(filename):
name, ext = os.path.splitext(filename)
ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')

if ext_suffix == ext:
return filename

ext_suffix = ext_suffix.replace(ext, '')
idx = name.find(ext_suffix)

if idx == -1:
return filename
else:
return name[:idx] + ext


class BuildExtWithoutPlatformSuffix(build_ext):
def get_ext_filename(self, ext_name):
filename = super().get_ext_filename(ext_name)
return get_ext_filename_without_platform_suffix(filename)


extra_compile_args = ["-std=c++1z", "-Wno-nullability-completeness"]
ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() # pylint: disable=unexpected-keyword-arg
if ARCH == "aarch64":
extra_compile_args += ["-Wno-deprecated-register"]

if platform.system() == "Darwin":
libdbc = "libdbc.dylib"
else:
libdbc = "libdbc.so"

extra_link_args = [os.path.join(BASEDIR, 'opendbc', 'can', libdbc)]
include_dirs = [
BASEDIR,
os.path.join(BASEDIR, 'phonelibs'),
]

# Build CAN Parser

setup(name='CAN parser',
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
ext_modules=cythonize(
Extension(
"parser_pyx",
language="c++",
sources=['parser_pyx.pyx'],
extra_compile_args=extra_compile_args,
include_dirs=include_dirs,
extra_link_args=extra_link_args,
),
nthreads=4,
annotate=ANNOTATE
),
)

if platform.system() == "Darwin":
os.system("install_name_tool -change opendbc/can/libdbc.dylib " + BASEDIR + "/opendbc/can/libdbc.dylib parser_pyx.so")


# Build CAN Packer

setup(name='CAN packer',
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
ext_modules=cythonize(
Extension(
"packer_pyx",
language="c++",
sources=['packer_pyx.pyx'],
extra_compile_args=extra_compile_args,
include_dirs=include_dirs,
extra_link_args=extra_link_args,
),
nthreads=4,
annotate=ANNOTATE
),
)

if platform.system() == "Darwin":
os.system("install_name_tool -change opendbc/can/libdbc.dylib " + BASEDIR + "/opendbc/can/libdbc.dylib packer_pyx.so")
4 changes: 4 additions & 0 deletions can/dbc_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const Signal sigs_{{address}}[] = {
.type = SignalType::PEDAL_CHECKSUM,
{% elif address in [512, 513] and sig.name == "COUNTER_PEDAL" %}
.type = SignalType::PEDAL_COUNTER,
{% elif checksum_type == "ocelot" and sig.name == "CHECKSUM" %}
.type = SignalType::OCELOT_CHECKSUM,
{% elif checksum_type == "ocelot" and sig.name == "COUNTER" %}
.type = SignalType::OCELOT_COUNTER,
{% else %}
.type = SignalType::DEFAULT,
{% endif %}
Expand Down
8 changes: 6 additions & 2 deletions can/packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
}
auto sig = sig_it->second;

if ((sig.type != SignalType::HONDA_COUNTER) && (sig.type != SignalType::VOLKSWAGEN_COUNTER)) {
if ((sig.type != SignalType::HONDA_COUNTER) && (sig.type != SignalType::VOLKSWAGEN_COUNTER) && (sig.type != SignalType::OCELOT_COUNTER)) {
WARN("COUNTER signal type not valid\n");
}

Expand Down Expand Up @@ -105,7 +105,11 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
unsigned int chksm = chrysler_checksum(address, ReverseBytes(ret), message_lookup[address].size);
ret = set_value(ret, sig, chksm);
} else {
} else if (sig.type == SignalType::OCELOT_CHECKSUM) {
unsigned int chksm = ocelot_checksum(ReverseBytes(ret), message_lookup[address].size);
ret = set_value(ret, sig, chksm);
}
else {
//WARN("CHECKSUM signal type not valid\n");
}
}
Expand Down
9 changes: 9 additions & 0 deletions can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ bool MessageState::parse(uint64_t sec, uint16_t ts_, uint8_t * dat) {
if (!update_counter_generic(tmp, sig.b2)) {
return false;
}
} else if (sig.type == SignalType::OCELOT_CHECKSUM) {
if (ocelot_checksum(dat_le, size) != tmp) {
INFO("0x%X OCELOT CHECKSUM FAIL\n", address);
return false;
}
} else if (sig.type == SignalType::OCELOT_COUNTER) {
if (!update_counter_generic(tmp, sig.b2)) {
return false;
}
}

vals[i] = tmp * sig.factor + sig.offset;
Expand Down
2 changes: 1 addition & 1 deletion can/parser_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ cdef class CANDefine():
self.dbc = dbc_lookup(dbc_name)
if not self.dbc:
raise RuntimeError("Can't lookup" + dbc_name)

num_vals = self.dbc[0].num_vals

address_to_msg_name = {}
Expand Down
7 changes: 7 additions & 0 deletions can/process_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def process(in_fn, out_fn):
checksum_start_bit = 7
counter_start_bit = None
little_endian = False
elif can_dbc.name.startswith(("ocelot_")):
checksum_type = "ocelot"
checksum_size = 8
counter_size = 4
checksum_start_bit = 0
counter_start_bit = 0
little_endian = True
else:
checksum_type = None
checksum_size = None
Expand Down
129 changes: 129 additions & 0 deletions ocelot_can.dbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
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_: EPAS HIM EON IBST SAS EPAS TOYOTASAS

VAL_TABLE_ BRAKEMODE 3 "Reserved" 2 "Position Control" 1 "Relative Control" 0 "Disengadged" ;
VAL_TABLE_ STATUS 5 "FAULT_TIMEOUT" 4 "FAULT_STARTUP" 3 "FAULT_SCE" 2 "FAULT_SEND" 1 "FAULT_BAD_CHECKSUM" 0 "NO_FAULT" ;
VAL_TABLE_ STEERINGMODE 3 "Reserved" 2 "Position Control" 1 "Torque Control" 0 "Disengadged" ;
VAL_TABLE_ YESNO 1 "Yes" 0 "No" ;

BO_ 741 STEERING_COMMAND: 5 EON
SG_ REQUESTED_STEER_TORQUE : 29|11@1- (0.5,0) [-512|511.5] "Nm" EPAS
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" EPAS
SG_ REQUESTED_STEER_ANGLE : 14|15@1- (0.1,0) [-1638.4|1638.3] "deg" EPAS
SG_ STEER_MODE : 12|2@1+ (1,0) [0|3] "" EPAS
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" EPAS

BO_ 608 STEERING_STATUS: 5 EPAS
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" EON
SG_ STATUS : 12|4@1+ (1,0) [0|15] "" EON
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" EON
SG_ STEERING_TORQUE_EPS : 29|11@1- (0.8,0) [-819.2|818.4] "Nm" EON
SG_ STEERING_TORQUE_DRIVER : 18|11@1- (0.8,0) [-819.2|818.4] "Nm" EON
SG_ STEERING_OK : 16|1@1+ (1,0) [0|1] "" EON

BO_ 527 BRAKE_STATUS: 5 IBST
SG_ BRAKE_PEDAL_POSITION : 20|12@1+ (0.015625,-5) [-5|47] "mm" EON
SG_ BRAKE_APPLIED : 18|1@1+ (1,0) [0|1] "" EON
SG_ DRIVER_BRAKE_APPLIED : 17|1@1+ (1,0) [0|1] "" EON
SG_ BRAKE_OK : 16|1@1+ (1,0) [0|1] "" EON
SG_ STATUS : 12|4@1+ (1,0) [0|15] "" EON
SG_ EXT_STATUS1 : 32|4@1+ (1,0) [0|15] "" EON
SG_ EXT_STATUS2 : 36|4@1+ (1,0) [0|15] "" EON
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" EON
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" EON

BO_ 526 BRAKE_COMMAND: 6 EON
SG_ BRAKE_POSITION_COMMAND : 32|12@1+ (0.015625,-5) [-5|47] "mm" IBST
SG_ BRAKE_RELATIVE_COMMAND : 16|16@1+ (0.0078125,-252) [-252|252] "" IBST
SG_ BRAKE_MODE : 12|2@1+ (1,0) [0|3] "" IBST
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" IBST
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" IBST

BO_ 870 CURRENT_STATE: 4 EON
SG_ ENABLED : 8|1@1+ (1,0) [0|0] "" HIM
SG_ SET_SPEED : 16|8@1+ (1,0) [0|255] "mph" HIM
SG_ CURRENT_SPEED : 24|8@1+ (1,0) [0|255] "kph" IBST
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" HIM

BO_ 869 HIM_CTRLS: 3 HIM
SG_ SPEEDDN_BTN : 11|1@1+ (1,0) [0|0] "" EON
SG_ SPEEDUP_BTN : 10|1@1+ (1,0) [0|0] "" EON
SG_ CANCEL_BTN : 9|1@1+ (1,0) [0|0] "" EON
SG_ SET_BTN : 8|1@1+ (1,0) [0|0] "" EON
SG_ STATE : 12|4@1+ (1,0) [0|15] "" EON
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" EON

BO_ 1059 TOYOTA_STEERING_ANGLE_SENSOR3: 1 TOYOTASAS

BO_ 1222 TOYOTA_STEERING_ANGLE_SENSOR2: 8 TOYOTASAS

BO_ 37 TOYOTA_STEERING_ANGLE_SENSOR1: 8 TOYOTASAS
SG_ TOYOTA_STEER_RATE : 35|12@0- (1,0) [-2000|2000] "deg/s" EON
SG_ TOYOTA_STEER_FRACTION : 39|4@0- (0.1,0) [-0.7|0.7] "deg" EON
SG_ TOYOTA_STEER_ANGLE : 3|12@0- (1.5,0) [-500|500] "deg" EON

BO_ 512 GAS_COMMAND: 6 EON
SG_ GAS_COMMAND : 8|16@1+ (0.275676,-33.3567) [0|1] "" PED
SG_ GAS_COMMAND2 : 24|16@1+ (0.13629,-32.71) [0|1] "" PED
SG_ ENABLE : 47|1@1+ (1,0) [0|1] "" PED
SG_ COUNTER : 40|4@1+ (1,0) [0|15] "" PED
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" PED

BO_ 513 GAS_SENSOR: 6 PED
SG_ PED_GAS : 8|16@1+ (0.275676,-33.3567) [0|1] "" EON
SG_ PED_GAS2 : 24|16@1+ (0.13629,-32.71) [0|1] "" EON
SG_ STATE : 44|4@1+ (1,0) [0|15] "" EON
SG_ COUNTER : 40|4@1+ (1,0) [0|15] "" EON
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" EON

VAL_ 527 IBOOSTER_BRAKE_APPLIED 1 "Yes" 0 "No" ;
VAL_ 527 BRAKE_OK 1 "Yes" 0 "No" ;
VAL_ 527 STATUS 5 "FAULT_TIMEOUT" 4 "FAULT_STARTUP" 3 "FAULT_SCE" 2 "FAULT_SEND" 1 "FAULT_BAD_CHECKSUM" 0 "NO_FAULT" ;
VAL_ 526 BRAKE_MODE 3 "Reserved" 2 "Position Control" 1 "Relative Control" 0 "Disengadged" ;

VAL_ 741 STEER_MODE 3 "Reserved" 2 "Position Control" 1 "Torque Control" 0 "Disengadged" ;
VAL_ 608 STATUS 5 "FAULT_TIMEOUT" 4 "FAULT_STARTUP" 3 "FAULT_SCE" 2 "FAULT_SEND" 1 "FAULT_BAD_CHECKSUM" 0 "NO_FAULT" ;
VAL_ 608 STEERING_OK 1 "Yes" 0 "No" ;
VAL_ 870 ENABLED 1 "Yes" 0 "No" ;
VAL_ 869 STATE 5 "FAULT_TIMEOUT" 4 "FAULT_STARTUP" 3 "FAULT_SCE" 2 "FAULT_SEND" 1 "FAULT_BAD_CHECKSUM" 0 "NO_FAULT" ;
VAL_ 869 SPEEDUP_BTN 1 "Yes" 0 "No" ;
VAL_ 869 SPEEDDN_BTN 1 "Yes" 0 "No" ;
VAL_ 869 CANCEL_BTN 1 "Yes" 0 "No" ;
VAL_ 869 SET_BTN 1 "Yes" 0 "No" ;

VAL_ 512 ENABLE 1 "Yes" 0 "No" ;
VAL_ 513 STATE 5 "FAULT_TIMEOUT" 4 "FAULT_STARTUP" 3 "FAULT_SCE" 2 "FAULT_SEND" 1 "FAULT_BAD_CHECKSUM" 0 "NO_FAULT" ;
Loading