From 46fce4dd5632dc180637d171e4fe855bb5527b34 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Tue, 23 Mar 2021 14:26:43 +0000 Subject: [PATCH] Fixes --- can/common.cc | 2 +- can/common_pyx_setup.py | 94 +++++++++++++++++++++++++++++++++++++++++ can/dbc_template.cc | 2 +- can/packer.cc | 3 +- can/parser_pyx.pyx | 2 +- can/process_dbc.py | 4 +- 6 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 can/common_pyx_setup.py diff --git a/can/common.cc b/can/common.cc index 2dc7db0..879b820 100644 --- a/can/common.cc +++ b/can/common.cc @@ -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; diff --git a/can/common_pyx_setup.py b/can/common_pyx_setup.py new file mode 100644 index 0000000..a729984 --- /dev/null +++ b/can/common_pyx_setup.py @@ -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") diff --git a/can/dbc_template.cc b/can/dbc_template.cc index 63cb5e8..25b2365 100644 --- a/can/dbc_template.cc +++ b/can/dbc_template.cc @@ -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, diff --git a/can/packer.cc b/can/packer.cc index b9b65db..f586c13 100644 --- a/can/packer.cc +++ b/can/packer.cc @@ -106,8 +106,9 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector &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"); } diff --git a/can/parser_pyx.pyx b/can/parser_pyx.pyx index 39f00a5..3df8af6 100644 --- a/can/parser_pyx.pyx +++ b/can/parser_pyx.pyx @@ -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 = {} diff --git a/can/process_dbc.py b/can/process_dbc.py index 44a0c36..80e277e 100755 --- a/can/process_dbc.py +++ b/can/process_dbc.py @@ -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