Skip to content

Commit

Permalink
Merge commit 'd03ae519e9bcc516e127593a4274b4212c70b732' into subaru-c…
Browse files Browse the repository at this point in the history
…ommunity
  • Loading branch information
martinl committed Jun 25, 2023
2 parents e515032 + d03ae51 commit 8e58b58
Show file tree
Hide file tree
Showing 22 changed files with 776 additions and 295 deletions.
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- --check-hidden
- --builtins clear,rare,informal,usage,code,names,en-GB_to_en-US
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
rev: v1.3.0
hooks:
- id: mypy
- repo: https://github.com/PyCQA/flake8
Expand All @@ -37,6 +37,11 @@ repos:
exclude: 'site_scons/'
args:
- --disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,E1136
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.15.0
hooks:
- id: cython-lint
- id: double-quote-cython-strings
- repo: https://github.com/cpplint/cpplint
rev: 1.6.1
hooks:
Expand Down
26 changes: 16 additions & 10 deletions bmw_e9x_e8x.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ BO_ 170 AccPedal: 8 DME
SG_ CruisePedalInactive : 55|1@0+ (1,0) [0|1] "" XXX
SG_ ThrottlelPressed : 50|1@0+ (1,0) [0|1] "" XXX
SG_ AcceleratorPedalPressed : 52|1@0+ (1,0) [0|7] "" XXX
SG_ AcceleratorPedalPercentage : 16|16@1+ (0.01,0) [0|100] "" XXX
SG_ AcceleratorPedalPercentage : 16|16@1+ (0.04,0) [0|100] "" XXX
SG_ Counter_170 : 8|4@1+ (1,0) [0|15] "" XXX
SG_ EngineSpeed : 32|16@1- (0.25,0) [0|65535] "U/min" XXX
SG_ EngineSpeed : 32|16@1+ (0.25,0) [0|8000] "rpm" XXX
SG_ Checksum_170 : 0|8@1- (1,0) [0|65535] "" XXX

BO_ 404 CruiseControl: 4 SZL
Expand Down Expand Up @@ -98,10 +98,10 @@ BO_ 201 SteeringWheelAngle_DSC: 8 SZL
SG_ SteeringPosition : 0|16@1- (0.0428316886,0) [-600|600] "deg" DSC

BO_ 206 WheelSpeeds: 8 DSC
SG_ Wheel1 : 0|16@1- (0.0643699,0) [0|255] "kph" XXX
SG_ Wheel2 : 16|16@1- (0.0643699,0) [0|255] "kph" XXX
SG_ Wheel4 : 48|16@1- (0.0643699,0) [0|255] "kph" XXX
SG_ Wheel3 : 32|16@1- (0.0643699,0) [0|255] "kph" XXX
SG_ Wheel_FL : 0|16@1- (0.0625,0) [0|255] "kph" XXX
SG_ Wheel_FR : 16|16@1- (0.0625,0) [0|255] "kph" XXX
SG_ Wheel_RL : 32|16@1- (0.0625,0) [0|255] "kph" XXX
SG_ Wheel_RR : 48|16@1- (0.0625,0) [0|255] "kph" XXX

BO_ 884 WheelToleranceAdjustment: 8 DSC

Expand Down Expand Up @@ -141,6 +141,10 @@ BO_ 182 DynamicCruiseControlTorqueDemand: 8 DSC

BO_ 186 TransmissionData: 8 EGS
SG_ Counter_186 : 48|4@1+ (1,0) [0|14] "" XXX
SG_ Shifting : 4|1@1+ (1,0) [0|15] "" XXX
SG_ OutputShaftSpeed : 24|16@1- (0.125,0) [0|255] "rpm" XXX
SG_ GearRatio : 8|8@1+ (0.05,0) [0|255] "" XXX
SG_ GearTar : 0|4@1+ (1,-4) [0|255] "" XXX
SG_ Checksum_186 : 40|8@1+ (1,0) [0|15] "" XXX

BO_ 191 RequestedWheelTorqueDriveTrain: 8 LDM
Expand Down Expand Up @@ -198,6 +202,7 @@ BO_ 408 GearSelectorSwitch: 8 GWS
BO_ 422 DistanceRoute: 8 DSC

BO_ 436 InstrumentClusterStatus_KOMBI: 8 CCC
SG_ HandbrakeActive : 41|1@1+ (1,0) [0|3] "" XXX

BO_ 464 EngineData: 8 DME
SG_ RPM_IDLG_TAR : 56|8@1+ (5,0) [0|1270] "1/min" XXX
Expand All @@ -206,7 +211,7 @@ BO_ 464 EngineData: 8 DME
SG_ AIP_ENG : 24|8@1+ (2,598) [600|1106] "hPa" XXX
SG_ ST_SW_WAUP : 22|2@1+ (1,0) [0|0] "" XXX
SG_ ST_ENG_RUN : 20|2@1+ (1,0) [0|0] "" XXX
SG_ Counter_464 : 16|4@0+ (1,0) [0|14] "" XXX
SG_ Counter_464 : 16|4@1+ (1,0) [0|14] "" XXX
SG_ TEMP_EOI : 8|8@1+ (1,-48) [0|0] "C" XXX
SG_ TEMP_ENG : 0|8@1+ (1,-48) [0|0] "C" XXX

Expand All @@ -221,7 +226,7 @@ BO_ 200 SteeringWheelAngle_slow: 6 SZL

BO_ 466 TransmissionDataDisplay: 8 EGS
SG_ ShiftLeverMode : 32|2@1+ (1,0) [0|3] "" XXX
SG_ GearRelated_TBD : 12|4@1+ (1,0) [0|15] "" XXX
SG_ GearAct : 12|4@1+ (1,-4) [0|15] "" XXX
SG_ Counter_466 : 28|4@1+ (1,0) [0|14] "" XXX
SG_ ShiftLeverPosition : 0|4@1+ (1,0) [0|8] "" XXX
SG_ xFF : 40|8@1+ (1,0) [0|255] "" XXX
Expand Down Expand Up @@ -720,6 +725,7 @@ BO_ 843 Seat_back_lock_status_FA: 8 SM_FA
BO_ 845 Status_seat_back_lock_BF: 8 SM_BF

BO_ 847 Status_contact_handbrake: 8 JBBF
SG_ Handbrake_push : 0|2@1+ (1,0) [0|3] "" XXX

BO_ 858 Appointment_Condition_Based_Service: 8 CCC

Expand Down Expand Up @@ -853,7 +859,6 @@ BO_ 996 Configuration_rear_view_camera_CKM: 8 CCC
CM_ SG_ 170 ThrottlelPressed "Active when accelerator pedal pressed or cruise control: drives";
CM_ SG_ 170 AcceleratorPedalPressed "Active only when driver actually presses the pedal";
CM_ SG_ 170 AcceleratorPedalPercentage "ToDo Factor to be adjusted";

CM_ SG_ 404 plus1mph_request "Appears when +1mph/kph stalk is depressed";
CM_ SG_ 404 minus1mph_request "Appears when -1mph/kph stalk is depressed";
CM_ SG_ 404 Cancel_request_up_stalk "Appears when cancel stalk (up) is depressed";
Expand All @@ -871,7 +876,8 @@ CM_ SG_ 169 ALIV_TORQ_2_DME "Counter TORQ_2";
CM_ SG_ 182 TORQ_TAR_DSC "torque target DSC";

CM_ SG_ 403 CruiseControlSetpointSpeed "Speed target - unit depends on locale";

CM_ SG_ 186 GearTar "Values corresponds to forward gears. TBD Add enums for park, reverse";
CM_ SG_ 466 GearAct "TransmissionDataDisplay";
CM_ SG_ 414 DSC_full_off "0x4 enabling, 0xA enabled. TBD";

CM_ SG_ 416 YawRate "Lateral Acceleration";
Expand Down
5 changes: 1 addition & 4 deletions can/common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t
from libcpp cimport bool
from libcpp.map cimport map
from libcpp.string cimport string
from libcpp.vector cimport vector
from libcpp.unordered_set cimport unordered_set


ctypedef unsigned int (*calc_checksum_type)(uint32_t, const Signal&, const vector[uint8_t] &)
Expand Down Expand Up @@ -54,7 +52,6 @@ cdef extern from "common_dbc.h":
uint32_t address
string name


cdef struct MessageParseOptions:
uint32_t address
int check_frequency
Expand All @@ -72,7 +69,7 @@ cdef extern from "common_dbc.h":


cdef extern from "common.h":
cdef const DBC* dbc_lookup(const string);
cdef const DBC* dbc_lookup(const string)

cdef cppclass CANParser:
bool can_valid
Expand Down
4 changes: 3 additions & 1 deletion can/dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include <sstream>
#include <vector>
#include <mutex>
#include <cstring>
#include <iterator>
#include <cstring>
#include <clocale>

#include "opendbc/can/common.h"
#include "opendbc/can/common_dbc.h"
Expand Down Expand Up @@ -106,6 +107,7 @@ DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, Ch
std::map<uint32_t, std::vector<Signal>> signals;
DBC* dbc = new DBC;
dbc->name = dbc_name;
std::setlocale(LC_NUMERIC, "C");

// used to find big endian LSB from MSB and size
std::vector<int> be_bits;
Expand Down
8 changes: 3 additions & 5 deletions can/packer_pyx.pyx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# distutils: language = c++
# cython: c_string_encoding=ascii, language_level=3

from libc.stdint cimport uint8_t, uint32_t, uint64_t
from libc.stdint cimport uint8_t
from libcpp.vector cimport vector
from libcpp.map cimport map
from libcpp.string cimport string
from libcpp cimport bool
from posix.dlfcn cimport dlopen, dlsym, RTLD_LAZY

from .common cimport CANPacker as cpp_CANPacker
from .common cimport dbc_lookup, SignalPackValue, DBC
Expand Down Expand Up @@ -36,7 +34,7 @@ cdef class CANPacker:
cdef SignalPackValue spv

for name, value in values.iteritems():
spv.name = name.encode('utf8')
spv.name = name.encode("utf8")
spv.value = value
values_thing.push_back(spv)

Expand All @@ -48,7 +46,7 @@ cdef class CANPacker:
addr = name_or_addr
size = self.address_to_size[name_or_addr]
else:
addr, size = self.name_to_address_and_size[name_or_addr.encode('utf8')]
addr, size = self.name_to_address_and_size[name_or_addr.encode("utf8")]

cdef vector[uint8_t] val = self.pack(addr, values)
return [addr, 0, (<char *>&val[0])[:size], bus]
22 changes: 10 additions & 12 deletions can/parser_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ from cython.operator cimport dereference as deref, preincrement as preinc
from libcpp.string cimport string
from libcpp.vector cimport vector
from libcpp.unordered_set cimport unordered_set
from libc.stdint cimport uint32_t, uint64_t, uint16_t
from libcpp cimport bool
from libc.stdint cimport uint32_t
from libcpp.map cimport map

from .common cimport CANParser as cpp_CANParser
from .common cimport SignalParseOptions, MessageParseOptions, dbc_lookup, SignalValue, DBC

import os
import numbers
from collections import defaultdict

Expand Down Expand Up @@ -46,7 +44,7 @@ cdef class CANParser:

for i in range(self.dbc[0].msgs.size()):
msg = self.dbc[0].msgs[i]
name = msg.name.decode('utf8')
name = msg.name.decode("utf8")

msg_name_to_address[name] = msg.address
self.address_to_msg_name[msg.address] = name
Expand All @@ -61,9 +59,9 @@ cdef class CANParser:
for i in range(len(signals)):
s = signals[i]
if not isinstance(s[1], numbers.Number):
if name not in msg_name_to_address:
if s[1] not in msg_name_to_address:
print(msg_name_to_address)
raise RuntimeError(f"could not find message {repr(name)} in DBC {self.dbc_name}")
raise RuntimeError(f"could not find message {repr(s[1])} in DBC {self.dbc_name}")
s = (s[0], msg_name_to_address[s[1]])
signals[i] = s

Expand All @@ -72,7 +70,7 @@ cdef class CANParser:
if not isinstance(c[0], numbers.Number):
if c[0] not in msg_name_to_address:
print(msg_name_to_address)
raise RuntimeError(f"could not find message {repr(name)} in DBC {self.dbc_name}")
raise RuntimeError(f"could not find message {repr(c[0])} in DBC {self.dbc_name}")
c = (msg_name_to_address[c[0]], c[1])
checks[i] = c

Expand All @@ -81,7 +79,7 @@ cdef class CANParser:
signal_addrs = {s[1] for s in signals}
unchecked = signal_addrs - checked_addrs
if len(unchecked):
err_msg = ', '.join(f"{self.address_to_msg_name[addr].decode()} ({hex(addr)})" for addr in unchecked)
err_msg = ", ".join(f"{self.address_to_msg_name[addr].decode()} ({hex(addr)})" for addr in unchecked)
raise RuntimeError(f"Unchecked addrs: {err_msg}")

cdef vector[SignalParseOptions] signal_options_v
Expand All @@ -106,7 +104,7 @@ cdef class CANParser:

def update_strings(self, strings, sendcan=False):
for v in self.vl_all.values():
for l in v.values():
for l in v.values(): # no-cython-lint
l.clear()

cdef vector[SignalValue] new_vals
Expand Down Expand Up @@ -154,7 +152,7 @@ cdef class CANDefine():

for i in range(self.dbc[0].msgs.size()):
msg = self.dbc[0].msgs[i]
name = msg.name.decode('utf8')
name = msg.name.decode("utf8")
address = msg.address
address_to_msg_name[address] = name

Expand All @@ -163,8 +161,8 @@ cdef class CANDefine():
for i in range(self.dbc[0].vals.size()):
val = self.dbc[0].vals[i]

sgname = val.name.decode('utf8')
def_val = val.def_val.decode('utf8')
sgname = val.name.decode("utf8")
def_val = val.def_val.decode("utf8")
address = val.address
msgname = address_to_msg_name[address]

Expand Down
7 changes: 7 additions & 0 deletions generator/honda/honda_civic_ex_2022_can.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ BO_ 401 GEARBOX: 8 PCM
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" EON
SG_ CHECKSUM : 59|4@0+ (1,0) [0|15] "" EON

BO_ 419 GEARBOX_ALT: 8 PCM
SG_ GEAR : 7|8@0+ (1,0) [0|255] "" EON
SG_ GEAR_SHIFTER : 29|6@0+ (1,0) [0|63] "" EON
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" EON
SG_ CHECKSUM : 59|4@0+ (1,0) [0|3] "" EON

BO_ 432 STANDSTILL: 7 VSA
SG_ WHEELS_MOVING : 12|1@0+ (1,0) [0|1] "" EON
SG_ BRAKE_ERROR_1 : 11|1@0+ (1,0) [0|1] "" EON
Expand Down Expand Up @@ -87,3 +93,4 @@ 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";
VAL_ 419 GEAR_SHIFTER 32 "D" 16 "N" 8 "R" 4 "P" 0 "B" ;
Loading

0 comments on commit 8e58b58

Please sign in to comment.