Skip to content

einhalv/dbctool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module dbctool

A tool to read and manipulate dbc files. The module has a Parser class with a metohd that parses the content of a dbc file held in a string and returns the content on an intermediate format in the form of a list of parsed dbc-sections. This intermediate format can be used to initialize an object of the Bus class. The objects of this class can hold the same information that a dbc-file can, but does so in a more structured form. Most, but not all, dbc sections are implemented. The class also has a method to generate a dbc representation of the object's content.

Some flexibility is added in parsing:

  • Both space and comma are allowed as separators in transmitter lists.
  • There can be any number of whitespaces before and after colon in section names, also in NS_.
  • Negative values are allowed in value descriptions.
  • Any character is accepted in strings except \ and ".

Type is probably not well handled for attributes.

Usage example

A simple diff program for dbc files can serve as an example of usage:

import dbctool
import sys

fname1 = sys.argv[1]
fname2 = sys.argv[2]

p1 = dbctool.Parser()
p2 = dbctool.Parser()

with open(fname1, "r") as fp:
    dbcstr1 = fp.read()
with open(fname2, "r") as fp:
    dbcstr2 = fp.read()

b1 = dbctool.Bus(p1.parse(dbcstr1))
b2 = dbctool.Bus(p2.parse(dbcstr2))

diffstr = b1.diff(b2)
if diffstr:
    print(diffstr)

Classes

The most important classes and their most important methods are given below.

Bus(seclist0, usermode=True, debugmode=None) : Class containing all information on CAN-bus.

This class can hold all information that is contained in a
dbc-file.

Initializes Bus object.

Args:
    seclist0(list):  List of tuples containing parsed sections.
    usermode(bool):  If True, trace of error messages are not shown.
    debugmode(bool): If True, print parsed sections as
                     they are processed

### Methods

`dbc(self)`
:   Returns dbc-format representation of Bus.

`diff(self, other)`
:   Return text describing difference in content from other Bus object.

DatabaseError(msg) : Semantic errors in database.

### Ancestors (in MRO)

* builtins.Exception
* builtins.BaseException

DatabaseWarning(msg) : Warnings about inconsistencies or ambiguities and how they are resolved.

### Ancestors (in MRO)

* builtins.Warning
* builtins.Exception
* builtins.BaseException

ParseError(line, col, msg, *args) : Syntax errors during parsing of dbc-file.

Initializes ParseError object.

Reports failure to parse string.

Args:
    line(int) Line number of error.
    col(int): Column number of error.
    msg(str): Informative description of error.
    args:     Variable arguments

### Ancestors (in MRO)

* builtins.Exception
* builtins.BaseException

Parser(usermode=True) : Class for dbc parsers.

Initalize Parser object.

Args:
    usermode(bool): If True, suppress error message traces.


### Methods

`parse(self, text)`
:   Set up parser and parse dbc text.
    
    Args:
        text(str):  String containing dbc file.
		
    Returns list for parsed dbc sections.

About

A tool to read and manipulate dbc files.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages