Convert payload to decimal

This commit is contained in:
2026-07-13 18:17:34 +02:00
parent 835ab0fc68
commit c4156434be
+9 -4
View File
@@ -48,7 +48,7 @@ def parse_log(input_path: PathLike, out_bus1: PathLike, out_bus2: PathLike) -> N
data_bytes = []
for token in tokens:
if byte_pattern.match(token):
data_bytes.append(token.upper())
data_bytes.append(str(int(token, 16)))
else:
break
@@ -63,7 +63,7 @@ def parse_log(input_path: PathLike, out_bus1: PathLike, out_bus2: PathLike) -> N
def parse_csv(csv_path: PathLike) -> pl.LazyFrame:
"""
Ingests a parsed CSV file, unpacks hex strings into 8 hex columns,
Ingests a parsed CSV file, unpacks decimal strings into 8 integer columns,
generates sequential timestamps if missing, and returns a Polars LazyFrame.
"""
lf = pl.scan_csv(csv_path, schema_overrides={"ID": pl.String, "Data": pl.String})
@@ -82,10 +82,15 @@ def parse_csv(csv_path: PathLike) -> pl.LazyFrame:
lf = lf.with_columns(byte_exprs).drop("Data")
return lf.with_columns([
cast_exprs = [
pl.col("DLC").cast(pl.UInt8),
pl.col("Timestamp").cast(pl.Float64)
])
]
for i in range(8):
cast_exprs.append(pl.col(f"b{i}").cast(pl.UInt8, strict=False))
return lf.with_columns(cast_exprs)
if __name__ == '__main__':
import argparse