Skip to content

Commit 6215750

Browse files
author
Martin
committed
Updated utils.py and process_data.py to incorporate support for .MFC, .MFE, .MFM files (data compression and/or data encryption)
1 parent 1b822cc commit 6215750

17 files changed

+26
-13
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ output/
99
*j1939-engine.dbc
1010
*FE34E37D*
1111
LOG2/
12-
*LIN.dbc
12+
*LIN.dbc
13+
*NMEA-2000-CSS-Electronics-v*
14+
*find_data_event.py
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

examples/data-processing/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ fs = setup_fs(s3=True, key="access_key", secret="secret_key", endpoint="endpoint
2828

2929
If you're using AWS S3, your endpoint would e.g. be `https://s3.us-east-2.amazonaws.com` (if your region is `us-east-2`). A MinIO S3 endpoint would e.g. be `http://192.168.0.1:9000`.
3030

31+
---
32+
### Regarding encrypted log files
33+
If you need to handle encrypted log files, you can provide a passwords dictionary object with similar structure as the `passwords.json` file used in the CANedge MF4 converters. The object can be provided e.g. as below (or via environmental variables):
34+
35+
```
36+
pw = {"default": "password"} # hardcoded
37+
pw = json.load(open("passwords.json")) # from local JSON file
38+
```
39+
3140
---
3241

3342
### Regarding Transport Protocol example

examples/data-processing/process_data.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
from datetime import datetime, timezone
66
from utils import setup_fs, load_dbc_files, restructure_data, add_custom_sig, ProcessData
77

8-
# specify devices to process (from local/S3), DBC files and start time
8+
# specify devices to process (from local/S3), DBC files, start time and optionally passwords
99
devices = ["LOG/958D2219"]
10+
1011
dbc_paths = ["dbc_files/CSS-Electronics-SAE-J1939-DEMO.dbc"]
1112
start = datetime(year=2020, month=1, day=13, hour=0, tzinfo=timezone.utc)
13+
pw = {"default": "password"}
1214

1315
# setup filesystem (local/S3), load DBC files and list log files for processing
14-
fs = setup_fs(s3=False, key="", secret="", endpoint="")
16+
fs = setup_fs(s3=False, key="", secret="", endpoint="", passwords=pw)
1517
db_list = load_dbc_files(dbc_paths)
16-
log_files = canedge_browser.get_log_files(fs, devices, start_date=start)
18+
log_files = canedge_browser.get_log_files(fs, devices, start_date=start, passwords=pw)
1719
print(f"Found a total of {len(log_files)} log files")
1820

1921
# --------------------------------------------
@@ -22,7 +24,7 @@
2224
df_phys_all = pd.DataFrame()
2325

2426
for log_file in log_files:
25-
df_raw, device_id = proc.get_raw_data(log_file)
27+
df_raw, device_id = proc.get_raw_data(log_file, passwords=pw)
2628
df_phys = proc.extract_phys(df_raw)
2729
proc.print_log_summary(device_id, log_file, df_phys)
2830

examples/data-processing/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ attrs==21.2.0
66
bitstruct==8.11.1
77
botocore==1.20.49
88
can-decoder>=0.1.3
9-
canedge-browser>=0.0.7
9+
canedge-browser>=0.0.8
1010
canmatrix==0.9.1
1111
chardet==4.0.0
1212
click==8.0.1
@@ -17,7 +17,7 @@ idna==3.2
1717
importlib-metadata==4.5.0
1818
J1939-PGN==0.4
1919
jmespath==0.10.0
20-
mdf-iter>=0.0.4
20+
mdf-iter>=0.0.6
2121
multidict==5.1.0
2222
numpy==1.20.3
2323
pandas==1.2.4

examples/data-processing/utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def setup_fs(s3, key="", secret="", endpoint="", cert=""):
1+
def setup_fs(s3, key="", secret="", endpoint="", cert="", passwords={}):
22
"""Given a boolean specifying whether to use local disk or S3, setup filesystem
33
Syntax examples: AWS (http://s3.us-east-2.amazonaws.com), MinIO (http://192.168.0.1:9000)
44
The cert input is relevant if you're using MinIO with TLS enabled, for specifying the path to the certficiate.
@@ -27,7 +27,7 @@ def setup_fs(s3, key="", secret="", endpoint="", cert=""):
2727
import canedge_browser
2828

2929
base_path = Path(__file__).parent
30-
fs = canedge_browser.LocalFileSystem(base_path=base_path)
30+
fs = canedge_browser.LocalFileSystem(base_path=base_path, passwords=passwords)
3131

3232
return fs
3333

@@ -48,7 +48,7 @@ def load_dbc_files(dbc_paths):
4848

4949

5050
# -----------------------------------------------
51-
def list_log_files(fs, devices, start_times, verbose=True):
51+
def list_log_files(fs, devices, start_times, verbose=True, passwords={}):
5252
"""Given a list of device paths, list log files from specified filesystem.
5353
Data is loaded based on the list of start datetimes
5454
"""
@@ -59,7 +59,7 @@ def list_log_files(fs, devices, start_times, verbose=True):
5959
if len(start_times):
6060
for idx, device in enumerate(devices):
6161
start = start_times[idx]
62-
log_files_device = canedge_browser.get_log_files(fs, [device], start_date=start)
62+
log_files_device = canedge_browser.get_log_files(fs, [device], start_date=start, passwords=passwords)
6363
log_files.extend(log_files_device)
6464

6565
if verbose:
@@ -180,14 +180,14 @@ def filter_signals(self, df_phys):
180180

181181
return df_phys
182182

183-
def get_raw_data(self, log_file, lin=False):
183+
def get_raw_data(self, log_file, lin=False, passwords={}):
184184
"""Extract a df of raw data and device ID from log file.
185185
Optionally include LIN bus data by setting lin=True
186186
"""
187187
import mdf_iter
188188

189189
with self.fs.open(log_file, "rb") as handle:
190-
mdf_file = mdf_iter.MdfFile(handle)
190+
mdf_file = mdf_iter.MdfFile(handle, passwords=passwords)
191191
device_id = self.get_device_id(mdf_file)
192192

193193
if lin:

0 commit comments

Comments
 (0)