master
ReFil 2021-03-23 14:26:43 +00:00
parent ee793c2129
commit 46fce4dd56
6 changed files with 101 additions and 6 deletions

View File

@ -69,7 +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_d5[256];
uint8_t crc8_lut_1d[256];
void gen_crc_lookup_table(uint8_t poly, uint8_t crc_lut[]) {
uint8_t crc;

View File

@ -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")

View File

@ -37,7 +37,7 @@ const Signal sigs_{{address}}[] = {
.type = SignalType::PEDAL_CHECKSUM,
{% elif address in [512, 513] and sig.name == "COUNTER_PEDAL" %}
.type = SignalType::PEDAL_COUNTER,
{% if checksum_type == "ocelot" and sig.name == "CHECKSUM" %}
{% elif checksum_type == "ocelot" and sig.name == "CHECKSUM" %}
.type = SignalType::OCELOT_CHECKSUM,
{% elif checksum_type == "ocelot" and sig.name == "COUNTER" %}
.type = SignalType::OCELOT_COUNTER,

View File

@ -106,8 +106,9 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
unsigned int chksm = chrysler_checksum(address, ReverseBytes(ret), message_lookup[address].size);
ret = set_value(ret, sig, chksm);
} else if (sig.type == SignalType::OCELOT_CHECKSUM) {
unsigned int chksm = chrysler_checksum(ret, message_lookup[address].size);
unsigned int chksm = ocelot_checksum(ret, message_lookup[address].size);
ret = set_value(ret, sig, chksm);
}
else {
//WARN("CHECKSUM signal type not valid\n");
}

View File

@ -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 = {}

View File

@ -61,12 +61,12 @@ def process(in_fn, out_fn):
checksum_start_bit = 7
counter_start_bit = None
little_endian = False
elif can_dbc.name.startswith(("ocelot_")):
elif can_dbc.name.startswith(("ocelot_")):
checksum_type = "ocelot"
checksum_size = 8
counter_size = 4
checksum_start_bit = 0
counter_start_bit = 4
counter_start_bit = 0
little_endian = True
else:
checksum_type = None