Skip to content

Commit 5eaf60d

Browse files
committed
Update to NMEA 2000 TP handling
1 parent 3fac915 commit 5eaf60d

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

canedge-influxdb-writer/utils.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ def setup_fs(s3, key="", secret="", endpoint="", cert="", passwords={}):
1515
fs = s3fs.S3FileSystem(key=key, secret=secret, default_block_size=block_size)
1616
elif cert != "":
1717
fs = s3fs.S3FileSystem(
18-
key=key, secret=secret, client_kwargs={"endpoint_url": endpoint, "verify": cert}, default_block_size=block_size
18+
key=key,
19+
secret=secret,
20+
client_kwargs={"endpoint_url": endpoint, "verify": cert},
21+
default_block_size=block_size,
1922
)
2023
else:
2124
fs = s3fs.S3FileSystem(
22-
key=key, secret=secret, client_kwargs={"endpoint_url": endpoint}, default_block_size=block_size
25+
key=key,
26+
secret=secret,
27+
client_kwargs={"endpoint_url": endpoint},
28+
default_block_size=block_size,
2329
)
2430

2531
else:
@@ -34,8 +40,7 @@ def setup_fs(s3, key="", secret="", endpoint="", cert="", passwords={}):
3440

3541
# -----------------------------------------------
3642
def load_dbc_files(dbc_paths):
37-
"""Given a list of DBC file paths, create a list of conversion rule databases
38-
"""
43+
"""Given a list of DBC file paths, create a list of conversion rule databases"""
3944
import can_decoder
4045
from pathlib import Path
4146

@@ -108,7 +113,12 @@ def add_custom_sig(df_phys, signal1, signal2, function, new_signal):
108113
s1 = df_phys[df_phys["Signal"] == signal1]["Physical Value"].rename(signal1)
109114
s2 = df_phys[df_phys["Signal"] == signal2]["Physical Value"].rename(signal2)
110115

111-
df_new_sig = pd.merge_ordered(s1, s2, on="TimeStamp", fill_method="ffill",).set_index("TimeStamp")
116+
df_new_sig = pd.merge_ordered(
117+
s1,
118+
s2,
119+
on="TimeStamp",
120+
fill_method="ffill",
121+
).set_index("TimeStamp")
112122
df_new_sig = df_new_sig.apply(lambda x: function(x[0], x[1]), axis=1).dropna().rename("Physical Value").to_frame()
113123
df_new_sig["Signal"] = new_signal
114124
df_phys = df_phys.append(df_new_sig)
@@ -173,8 +183,7 @@ def rebaseline_data(self, df_phys):
173183
return df_phys
174184

175185
def filter_signals(self, df_phys):
176-
"""Given a df of physical values, return only signals matched by filter
177-
"""
186+
"""Given a df of physical values, return only signals matched by filter"""
178187
if not df_phys.empty and len(self.signals):
179188
df_phys = df_phys[df_phys["Signal"].isin(self.signals)]
180189

@@ -204,8 +213,7 @@ def get_device_id(self, mdf_file):
204213
return mdf_file.get_metadata()["HDComment.Device Information.serial number"]["value_raw"]
205214

206215
def print_log_summary(self, device_id, log_file, df_phys):
207-
"""Print summary information for each log file
208-
"""
216+
"""Print summary information for each log file"""
209217
if self.verbose:
210218
print(
211219
"\n---------------",
@@ -246,7 +254,18 @@ def __init__(self, tp_type=""):
246254
"CONSEQ_FRAME": 0x20,
247255
"ff_payload_start": 2,
248256
"bam_pgn": -1,
249-
"res_id_list_hex": ["0x7E0", "0x7E9", "0x7EA", "0x7EB", "0x7EC", "0x7ED", "0x7EE", "0x7EF", "0x7EA", "0x7BB"],
257+
"res_id_list_hex": [
258+
"0x7E0",
259+
"0x7E9",
260+
"0x7EA",
261+
"0x7EB",
262+
"0x7EC",
263+
"0x7ED",
264+
"0x7EE",
265+
"0x7EF",
266+
"0x7EA",
267+
"0x7BB",
268+
],
250269
}
251270

252271
frame_struct_j1939 = {
@@ -263,7 +282,7 @@ def __init__(self, tp_type=""):
263282

264283
frame_struct_nmea = {
265284
"SINGLE_FRAME_MASK": 0xFF,
266-
"FIRST_FRAME_MASK": 0x0F,
285+
"FIRST_FRAME_MASK": 0x1F,
267286
"CONSEQ_FRAME_MASK": 0x00,
268287
"SINGLE_FRAME": 0xFF,
269288
"FIRST_FRAME": 0x00,

0 commit comments

Comments
 (0)