Skip to content

Commit e09fbe9

Browse files
committed
Updated to latest canedge_browser syntax. Use pathlib to ensure robustness towards execution from non-root folders
1 parent d650fa8 commit e09fbe9

File tree

5 files changed

+151
-20
lines changed

5 files changed

+151
-20
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*.mf4
22
*.csv
3-
*.dbc
43
*.exe
54
*.json
65
*.pyc
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
VERSION ""
2+
3+
4+
NS_ :
5+
NS_DESC_
6+
CM_
7+
BA_DEF_
8+
BA_
9+
VAL_
10+
CAT_DEF_
11+
CAT_
12+
FILTER
13+
BA_DEF_DEF_
14+
EV_DATA_
15+
ENVVAR_DATA_
16+
SGTYPE_
17+
SGTYPE_VAL_
18+
BA_DEF_SGTYPE_
19+
BA_SGTYPE_
20+
SIG_TYPE_REF_
21+
VAL_TABLE_
22+
SIG_GROUP_
23+
SIG_VALTYPE_
24+
SIGTYPE_VALTYPE_
25+
BO_TX_BU_
26+
BA_DEF_REL_
27+
BA_REL_
28+
BA_DEF_DEF_REL_
29+
BU_SG_REL_
30+
BU_EV_REL_
31+
BU_BO_REL_
32+
SG_MUL_VAL_
33+
34+
BS_:
35+
36+
BU_:
37+
38+
39+
BO_ 2364540158 EEC1: 8 Vector__XXX
40+
SG_ EngineSpeed : 24|16@1+ (0.125,0) [0|8031.875] "rpm" Vector__XXX
41+
42+
BO_ 2566844926 CCVS1: 8 Vector__XXX
43+
SG_ WheelBasedVehicleSpeed : 8|16@1+ (0.00390625,0) [0|250.996] "km/h" Vector__XXX
44+
45+
46+
CM_ BO_ 2364540158 "Electronic Engine Controller 1";
47+
CM_ SG_ 2364540158 EngineSpeed "Actual engine speed which is calculated over a minimum crankshaft angle of 720 degrees divided by the number of cylinders.…";
48+
CM_ BO_ 2566844926 "Cruise Control/Vehicle Speed 1";
49+
CM_ SG_ 2566844926 WheelBasedVehicleSpeed "Wheel-Based Vehicle Speed: Speed of the vehicle as calculated from wheel or tailshaft speed.";
50+
BA_DEF_ SG_ "SPN" INT 0 524287;
51+
BA_DEF_ BO_ "VFrameFormat" ENUM "StandardCAN","ExtendedCAN","reserved","J1939PG";
52+
BA_DEF_ "DatabaseVersion" STRING ;
53+
BA_DEF_ "BusType" STRING ;
54+
BA_DEF_ "ProtocolType" STRING ;
55+
BA_DEF_ "DatabaseCompiler" STRING ;
56+
BA_DEF_DEF_ "SPN" 0;
57+
BA_DEF_DEF_ "VFrameFormat" "J1939PG";
58+
BA_DEF_DEF_ "DatabaseVersion" "";
59+
BA_DEF_DEF_ "BusType" "";
60+
BA_DEF_DEF_ "ProtocolType" "";
61+
BA_DEF_DEF_ "DatabaseCompiler" "";
62+
BA_ "ProtocolType" "J1939";
63+
BA_ "BusType" "CAN";
64+
BA_ "DatabaseCompiler" "CSS ELECTRONICS (WWW.CSSELECTRONICS.COM)";
65+
BA_ "DatabaseVersion" "1.0.0";
66+
BA_ "VFrameFormat" BO_ 2364540158 3;
67+
BA_ "SPN" SG_ 2364540158 EngineSpeed 190;
68+
BA_ "SPN" SG_ 2566844926 WheelBasedVehicleSpeed 84;

examples/data-processing/process_data.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import can_decoder
44

55
import pandas as pd
6-
76
from datetime import datetime, timezone
8-
from utils import setup_fs, setup_fs_s3
7+
from pathlib import Path
98

9+
from utils import setup_fs, setup_fs_s3
1010

1111
# specify which devices to process (from local folder or S3 bucket)
1212
devices = ["LOG/958D2219"]
@@ -16,7 +16,8 @@
1616
stop = datetime(year=2099, month=1, day=1, tzinfo=timezone.utc)
1717

1818
# specify DBC path
19-
dbc_path = r"CSS-Electronics-SAE-J1939-DEMO.dbc"
19+
base_path = Path(__file__).parent
20+
dbc_path = base_path / r"CSS-Electronics-SAE-J1939-DEMO.dbc"
2021

2122
# ---------------------------------------------------
2223
# initialize DBC converter and file loader
@@ -38,22 +39,18 @@
3839
print(f"\nProcessing log file: {log_file}")
3940
with fs.open(log_file, "rb") as handle:
4041
mdf_file = mdf_iter.MdfFile(handle)
41-
device_id = mdf_file.get_metadata()[
42-
"HDComment.Device Information.serial number"
43-
]["value_raw"]
42+
device_id = mdf_file.get_metadata()["HDComment.Device Information.serial number"]["value_raw"]
4443
df_raw = mdf_file.get_data_frame()
4544

4645
# extract all DBC decodable signals and print dataframe
4746
df_phys = df_decoder.decode_frame(df_raw)
4847
print(f"Extracted {len(df_phys)} DBC decoded frames")
49-
path = device_id + log_file.split(device_id)[1].replace("MF4", "csv").replace(
50-
"/", "_"
51-
)
48+
path = device_id + log_file.split(device_id)[1].replace("MF4", "csv").replace("/", "_")
5249

5350
if df_phys.empty:
5451
continue
5552

56-
df_phys.to_csv(path)
53+
df_phys.to_csv(base_path / path)
5754

5855
# create a list of the individual DBC decoded dataframes:
5956
df_concat.append(df_phys)
@@ -75,10 +72,7 @@
7572
df_join = pd.DataFrame({"TimeStamp": []})
7673
for signal, signal_data in df_concat.groupby("Signal"):
7774
df_join = pd.merge_ordered(
78-
df_join,
79-
signal_data["Physical Value"].rename(signal).resample("1S").pad().dropna(),
80-
on="TimeStamp",
81-
fill_method="none",
75+
df_join, signal_data["Physical Value"].rename(signal).resample("1S").pad().dropna(), on="TimeStamp", fill_method="none",
8276
)
8377

84-
df_join.set_index("TimeStamp").to_csv("output_joined.csv")
78+
df_join.set_index("TimeStamp").to_csv(base_path / "output_joined.csv")

examples/data-processing/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ def setup_fs_s3():
1616

1717

1818
def setup_fs():
19-
"""Helper function to setup the local file system.
19+
"""Helper function to setup the file system.
2020
"""
21-
from fsspec.implementations.local import LocalFileSystem
2221
from pathlib import Path
22+
import canedge_browser
2323

24-
# Setup path to local folder structure, as if copied from a CANedge SD.
24+
base_path = Path(__file__).parent
25+
26+
# Setup path to local folder structure, as if copied from a CANedge SD.
2527
# Assumes the folder is placed in same directory as this file
26-
fs = LocalFileSystem()
28+
fs = canedge_browser.LocalFileSystem(base_path=base_path)
2729

2830
return fs
2931

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
VERSION ""
2+
3+
4+
NS_ :
5+
NS_DESC_
6+
CM_
7+
BA_DEF_
8+
BA_
9+
VAL_
10+
CAT_DEF_
11+
CAT_
12+
FILTER
13+
BA_DEF_DEF_
14+
EV_DATA_
15+
ENVVAR_DATA_
16+
SGTYPE_
17+
SGTYPE_VAL_
18+
BA_DEF_SGTYPE_
19+
BA_SGTYPE_
20+
SIG_TYPE_REF_
21+
VAL_TABLE_
22+
SIG_GROUP_
23+
SIG_VALTYPE_
24+
SIGTYPE_VALTYPE_
25+
BO_TX_BU_
26+
BA_DEF_REL_
27+
BA_REL_
28+
BA_DEF_DEF_REL_
29+
BU_SG_REL_
30+
BU_EV_REL_
31+
BU_BO_REL_
32+
SG_MUL_VAL_
33+
34+
BS_:
35+
36+
BU_:
37+
38+
39+
BO_ 2364540158 EEC1: 8 Vector__XXX
40+
SG_ EngineSpeed : 24|16@1+ (0.125,0) [0|8031.875] "rpm" Vector__XXX
41+
42+
BO_ 2566844926 CCVS1: 8 Vector__XXX
43+
SG_ WheelBasedVehicleSpeed : 8|16@1+ (0.00390625,0) [0|250.996] "km/h" Vector__XXX
44+
45+
46+
CM_ BO_ 2364540158 "Electronic Engine Controller 1";
47+
CM_ SG_ 2364540158 EngineSpeed "Actual engine speed which is calculated over a minimum crankshaft angle of 720 degrees divided by the number of cylinders.…";
48+
CM_ BO_ 2566844926 "Cruise Control/Vehicle Speed 1";
49+
CM_ SG_ 2566844926 WheelBasedVehicleSpeed "Wheel-Based Vehicle Speed: Speed of the vehicle as calculated from wheel or tailshaft speed.";
50+
BA_DEF_ SG_ "SPN" INT 0 524287;
51+
BA_DEF_ BO_ "VFrameFormat" ENUM "StandardCAN","ExtendedCAN","reserved","J1939PG";
52+
BA_DEF_ "DatabaseVersion" STRING ;
53+
BA_DEF_ "BusType" STRING ;
54+
BA_DEF_ "ProtocolType" STRING ;
55+
BA_DEF_ "DatabaseCompiler" STRING ;
56+
BA_DEF_DEF_ "SPN" 0;
57+
BA_DEF_DEF_ "VFrameFormat" "J1939PG";
58+
BA_DEF_DEF_ "DatabaseVersion" "";
59+
BA_DEF_DEF_ "BusType" "";
60+
BA_DEF_DEF_ "ProtocolType" "";
61+
BA_DEF_DEF_ "DatabaseCompiler" "";
62+
BA_ "ProtocolType" "J1939";
63+
BA_ "BusType" "CAN";
64+
BA_ "DatabaseCompiler" "CSS ELECTRONICS (WWW.CSSELECTRONICS.COM)";
65+
BA_ "DatabaseVersion" "1.0.0";
66+
BA_ "VFrameFormat" BO_ 2364540158 3;
67+
BA_ "SPN" SG_ 2364540158 EngineSpeed 190;
68+
BA_ "SPN" SG_ 2566844926 WheelBasedVehicleSpeed 84;

0 commit comments

Comments
 (0)