Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Allow disabling of strict parsing of CAN frames
Browse files Browse the repository at this point in the history
The dbcfeeder now supports a new command line switch '--lax'
which can be used to disable strict parsing of CAN frames.

This is helpful with CAN dump files that contains frames that do
not contain the default 8 bytes of data.

Signed-off-by: Kai Hudalla <kai.hudalla@bosch.io>
  • Loading branch information
sophokles73 committed Feb 14, 2023
1 parent 969478d commit b747cb6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
19 changes: 15 additions & 4 deletions dbc2val/dbcfeeder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

########################################################################
# Copyright (c) 2020 Robert Bosch GmbH
# Copyright (c) 2020,2023 Robert Bosch GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -117,6 +117,7 @@ def start(
mappingfile,
candumpfile=None,
use_j1939=False,
use_strict_parsing=False,
grpc_metadata=None,
):
log.debug("Use mapping: {}".format(mappingfile))
Expand All @@ -128,11 +129,15 @@ def start(
rxqueue=self._can_queue,
dbcfile=dbcfile,
mapper=self._mapper,
use_strict_parsing=use_strict_parsing,
)
else:
log.info("Use DBC reader")
self._reader = dbcreader.DBCReader(
rxqueue=self._can_queue, dbcfile=dbcfile, mapper=self._mapper
rxqueue=self._can_queue,
dbcfile=dbcfile,
mapper=self._mapper,
use_strict_parsing=use_strict_parsing,
)

if candumpfile:
Expand Down Expand Up @@ -268,7 +273,7 @@ def _run(self):
else:
log.error("Unknown error setting {}: {}".format(target, resp))
else:
log.error("Unsupported server type: %s", server_type)
log.error("Unsupported server type: %s", self._server_type)

except kuksa_client.grpc.VSSClientError:
log.error("Failed to update datapoints", exc_info=True)
Expand Down Expand Up @@ -342,7 +347,12 @@ def main(argv):
choices=[server_type.value for server_type in ServerType],
type=ServerType,
)

parser.add_argument(
"--lax",
dest="strict",
help="Disable strict parsing of CAN frames",
action="store_false",
)
args = parser.parse_args()

config = parse_config(args.config)
Expand Down Expand Up @@ -472,6 +482,7 @@ def signal_handler(signal_received, frame):
mappingfile=mappingfile,
candumpfile=candumpfile,
use_j1939=use_j1939,
use_strict_parsing=args.strict,
grpc_metadata=grpc_metadata,
)

Expand Down
7 changes: 4 additions & 3 deletions dbc2val/dbcreader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3

########################################################################
# Copyright (c) 2020 Robert Bosch GmbH
# Copyright (c) 2020,2023 Robert Bosch GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,16 +23,17 @@
import threading
import time
import logging
from queue import Queue

log = logging.getLogger(__name__)


class DBCReader:
def __init__(self, rxqueue, dbcfile, mapper):
def __init__(self, rxqueue: Queue, dbcfile: str, mapper: str, use_strict_parsing: bool):
self.queue = rxqueue
self.mapper = mapper
log.info("Reading DBC file {}".format(dbcfile))
self.db = cantools.database.load_file(dbcfile)
self.db = cantools.database.load_file(dbcfile, strict = use_strict_parsing)
self.canidwl = self.get_whitelist()
log.info("CAN ID whitelist={}".format(self.canidwl))
self.parseErr = 0
Expand Down
7 changes: 4 additions & 3 deletions dbc2val/j1939reader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3

########################################################################
# Copyright (c) 2020 Robert Bosch GmbH
# Copyright (c) 2020,2023 Robert Bosch GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@

import cantools
import j1939
from queue import Queue

log = logging.getLogger(__name__)

Expand All @@ -40,7 +41,7 @@ class J1939Reader(j1939.ControllerApplication):
# This CA produces simulated sensor values and cyclically sends them to
# the bus with the PGN 0xFEF6 (Intake Exhaust Conditions 1)

def __init__(self, rxqueue, dbcfile, mapper):
def __init__(self, rxqueue: Queue, dbcfile: str, mapper: str, use_strict_parsing: bool):
# compose the name descriptor for the new ca
name = j1939.Name(
arbitrary_address_capable=0,
Expand All @@ -58,7 +59,7 @@ def __init__(self, rxqueue, dbcfile, mapper):
j1939.ControllerApplication.__init__(self, name, device_address_preferred)
# adaptation
self.queue = rxqueue
self.db = cantools.database.load_file(dbcfile)
self.db = cantools.database.load_file(dbcfile, strict = use_strict_parsing)
self.mapper = mapper
self.canidwl = self.get_whitelist()
self.parseErr = 0
Expand Down

0 comments on commit b747cb6

Please sign in to comment.