Skip to content

Commit

Permalink
Merge pull request #997 from hacklint/relaxed_j1939
Browse files Browse the repository at this point in the history
Warn and relax global j1939 if non-extended IDs present
  • Loading branch information
danielhrisca authored Apr 17, 2024
2 parents 31838b2 + 6ff52f7 commit 8101f14
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/asammdf/mdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4755,6 +4755,14 @@ def _extract_can_logging(
messages = {(message.arbitration_id.id, message.arbitration_id.extended): message for message in dbc}

global_is_j1939 = dbc.attributes.get("ProtocolType", "").lower() == "j1939"
not_extended = [msg for msg in dbc if not msg.arbitration_id.extended]
if global_is_j1939 and not_extended:
logger.warning(
f"Not all j1939 messages in <{dbc_name}> seem to use extended addressing. Disabling global j1939 flag..."
)
for msg in not_extended:
logger.warning(f" {msg} with id {msg.arbitration_id}")
global_is_j1939 = False # Relax req on j1939 adressing

j1939_messages = {
(
Expand Down
117 changes: 117 additions & 0 deletions test/almost-J1939.dbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
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_: VCM


BO_ 2364540158 EEC1: 8 Vector__XXX
SG_ EngineSpeed : 24|16@1+ (0.125,0) [0|8031.875] "rpm" Vector__XXX

BO_ 2566844926 CCVS1: 8 Vector__XXX
SG_ WheelBasedVehicleSpeed : 8|16@1+ (0.00390625,0) [0|250.996] "km/h" Vector__XXX

BO_ 1791 VCM_NetVer_C01: 8 VCM
SG_ VCMNetVer_C01_Major : 8|16@1+ (1,0) [0|65535] "Not Applicable" Vector__XXX
SG_ VCMNetVer_C01_Patch : 40|16@1+ (1,0) [0|65535] "Not Applicable" Vector__XXX
SG_ VCMNetVer_C01_NetID : 0|8@1+ (1,0) [0|255] "NotApplicable" Vector__XXX
SG_ VCMNetVer_C01_Minor : 24|16@1+ (1,0) [0|65535] "Not Applicable" Vector__XXX
SG_ VCMNetVer_C01_Dirty : 56|8@1+ (1,0) [0|255] "NotApplicable" Vector__XXX


CM_ BO_ 2364540158 "Electronic Engine Controller 1";
CM_ SG_ 2364540158 EngineSpeed "Actual engine speed which is calculated over a minimum crankshaft angle of 720 degrees divided by the number of cylinders.…";
CM_ BO_ 2566844926 "Cruise Control/Vehicle Speed 1";
CM_ SG_ 2566844926 WheelBasedVehicleSpeed "Wheel-Based Vehicle Speed: Speed of the vehicle as calculated from wheel or tailshaft speed.";
CM_ BO_ 1791 "Version stuff";
CM_ SG_ 1791 VCMNetVer_C01_Major "Version stuff";
CM_ SG_ 1791 VCMNetVer_C01_Patch "Version stuff";
CM_ SG_ 1791 VCMNetVer_C01_NetID "Version stuff";
CM_ SG_ 1791 VCMNetVer_C01_Minor "Version stuff";
CM_ SG_ 1791 VCMNetVer_C01_Dirty "Version stuff";
BA_DEF_ SG_ "SPN" INT 0 524287;
BA_DEF_ BO_ "VFrameFormat" ENUM "StandardCAN","ExtendedCAN","reserved","J1939PG";
BA_DEF_ BO_ "GenMsgSendType" ENUM "Cyclic","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed","IfActive","NoMsgSendType","NotUsed";
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 0;
BA_DEF_ "DatabaseVersion" STRING ;
BA_DEF_ "BusType" STRING ;
BA_DEF_ "ProtocolType" STRING ;
BA_DEF_ "DatabaseCompiler" STRING ;
BA_DEF_ SG_ "GenSigCycleTimeActive" INT 0 0;
BA_DEF_ SG_ "GenSigCycleTime" INT 0 0;
BA_DEF_ SG_ "GenSigStartValue" INT 0 0;
BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType","NotUsed","NotUsed","NotUsed","NotUsed","NotUsed";

BA_DEF_DEF_ "SPN" 0;
BA_DEF_DEF_ "VFrameFormat" "J1939PG";
BA_DEF_DEF_ "DatabaseVersion" "";
BA_DEF_DEF_ "BusType" "";
BA_DEF_DEF_ "ProtocolType" "";
BA_DEF_DEF_ "DatabaseCompiler" "";
BA_DEF_DEF_ "GenMsgSendType" "Cyclic";
BA_DEF_DEF_ "GenMsgCycleTime" 0;
BA_DEF_DEF_ "GenSigCycleTimeActive" 0;
BA_DEF_DEF_ "GenSigCycleTime" 0;
BA_DEF_DEF_ "GenSigSendType" "Cyclic";
BA_DEF_DEF_ "GenSigStartValue" 0;

BA_ "ProtocolType" "J1939";
BA_ "BusType" "CAN";
BA_ "DatabaseCompiler" "CSS ELECTRONICS (WWW.CSSELECTRONICS.COM)";
BA_ "DatabaseVersion" "1.0.0";
BA_ "VFrameFormat" BO_ 2364540158 3;
BA_ "VFrameFormat" BO_ 2566844926 3;
BA_ "VFrameFormat" BO_ 1791 0;
BA_ "GenMsgSendType" BO_ 1791 0;
BA_ "GenMsgCycleTime" BO_ 1791 1000;
BA_ "SPN" SG_ 2364540158 EngineSpeed 190;
BA_ "SPN" SG_ 2566844926 WheelBasedVehicleSpeed 84;
BA_ "GenSigSendType" SG_ 1791 VCMNetVer_C01_Major 0;
BA_ "GenSigCycleTime" SG_ 1791 VCMNetVer_C01_Major 100;
BA_ "GenSigCycleTimeActive" SG_ 1791 VCMNetVer_C01_Major 100;
BA_ "GenSigStartValue" SG_ 1791 VCMNetVer_C01_Major 2;
BA_ "GenSigSendType" SG_ 1791 VCMNetVer_C01_Patch 0;
BA_ "GenSigCycleTime" SG_ 1791 VCMNetVer_C01_Patch 100;
BA_ "GenSigCycleTimeActive" SG_ 1791 VCMNetVer_C01_Patch 100;
BA_ "GenSigSendType" SG_ 1791 VCMNetVer_C01_NetID 0;
BA_ "GenSigCycleTime" SG_ 1791 VCMNetVer_C01_NetID 100;
BA_ "GenSigCycleTimeActive" SG_ 1791 VCMNetVer_C01_NetID 100;
BA_ "GenSigStartValue" SG_ 1791 VCMNetVer_C01_NetID 1;
BA_ "GenSigSendType" SG_ 1791 VCMNetVer_C01_Minor 0;
BA_ "GenSigCycleTime" SG_ 1791 VCMNetVer_C01_Minor 100;
BA_ "GenSigCycleTimeActive" SG_ 1791 VCMNetVer_C01_Minor 100;
BA_ "GenSigStartValue" SG_ 1791 VCMNetVer_C01_Minor 7;
BA_ "GenSigSendType" SG_ 1791 VCMNetVer_C01_Dirty 0;
BA_ "GenSigCycleTime" SG_ 1791 VCMNetVer_C01_Dirty 100;
BA_ "GenSigCycleTimeActive" SG_ 1791 VCMNetVer_C01_Dirty 100;
28 changes: 28 additions & 0 deletions test/test_CAN_bus_loogging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import os
from pathlib import Path
import tempfile
import unittest
Expand Down Expand Up @@ -82,6 +83,33 @@ def test_j1939_extract(self):

self.assertTrue(np.array_equal(values, target))

def test_almost_j1939_extract(self):
print("non-standard J1939 extract")

temp_dir = Path(TestCANBusLogging.tempdir_j1939.name)

mdf = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".mf4"][0]

mdf = MDF(mdf)

# dbc = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".dbc"][0]
# This dbc throws exception without the suggested changes in branch "relaxed_j1939"...
# else it is identical to the CSS Electronics demo file in test package
d = os.path.dirname(__file__)
dbc = os.path.join(d, "almost-J1939.dbc") # Pls replace with file from expanded zip file

signals = [input_file for input_file in temp_dir.iterdir() if input_file.suffix == ".npy"]

out = mdf.extract_bus_logging({"CAN": [(dbc, 0)]})

for signal in signals:
name = signal.stem

target = np.load(signal)
values = out.get(name).samples

self.assertTrue(np.array_equal(values, target))

def test_j1939_get_can_signal(self):
print("J1939 get CAN signal")

Expand Down

0 comments on commit 8101f14

Please sign in to comment.