How to use the canmatrix.formats.loadp_flat function in canmatrix

To help you get started, we’ve selected a few canmatrix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ebroecker / canmatrix / examples / encodeFrame.py View on Github external
parser = optparse.OptionParser(usage=usage)
parser.add_option(
    "-f", "--frames",
    dest="frames",
    help="encode list of frames",
    default="*")

(cmdlineOptions, args) = parser.parse_args()

if len(args) < 1:
    parser.print_help()
    sys.exit(1)

# load matrix
db = canmatrix.formats.loadp_flat(args[0])

#get all frames which match the commandline
frames = db.glob_frames(cmdlineOptions.frames)

#helper to read physical value from user
def read_signal_value_from_user(signal):
    a = input("Enter Value for " + signal.name + " ")

    if signal.is_float:
        return float(a)
    else:
        return int(a)

# go through all frames
for frame in frames:
    print (frame.name)
github ebroecker / canmatrix / examples / decodeFrame.py View on Github external
matrixX can be any of *.dbc|*.dbf|*.kcd|*.arxml
frame is AAA#YYYYYYYYYYYYYYYY or
       BBBBB#YYYYYYYYYYYYYYYY or


where AAA is standard ID and BBBBB is extended ID

"""

if len(sys.argv) < 3:
    print(usage)
    sys.exit(1)

# load matrix
db = canmatrix.formats.loadp_flat(sys.argv[1])

# load frame data from argv
frame_string = sys.argv[2]
(arbitration_id_string, hexdata) = frame_string.split('#')

# set arbitration_id
if len(arbitration_id_string) <= 3:
    arbitration_id = canmatrix.ArbitrationId(int(arbitration_id_string, 16), extended = False)
else:
    # extended frame
    arbitration_id = canmatrix.ArbitrationId(int(arbitration_id_string, 16), extended = True)

# find frame to given arbitration_id
frame = db.frame_by_id(arbitration_id)
can_data = bytearray.fromhex(hexdata)
github ebroecker / canmatrix / src / canmatrix / j1939_decoder.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

from builtins import *

import attr
import pathlib2

import canmatrix.formats


@attr.s
class j1939_decoder(object):
    here = pathlib2.Path(__file__).parent

    j1939_db = canmatrix.formats.loadp_flat(str(here / "j1939.dbc"), dbcImportEncoding = "utf8")
    length = attr.ib(default=0)  # type: int
    count_succesive_frames = attr.ib(default=0)  # type: int
    transfered_pgn = attr.ib(default=0)  # type: int
    _data = attr.ib(init=False, default=bytearray())

    def decode(self, arbitration_id, can_data, matrix = None):
        if matrix is not None:
            frame = matrix.frame_by_pgn(arbitration_id.pgn)
        else:
            frame = None
        if frame is not None:
            return ("regular " + frame.name, frame.decode(can_data))
        elif self.j1939_db.frame_by_pgn(arbitration_id.pgn) is not None:
            signals = self.j1939_db.decode(arbitration_id,can_data)
            frame_name = self.j1939_db.frame_by_pgn(arbitration_id.pgn).name
            return ("J1939 known: " + frame_name, signals)
github ebroecker / canmatrix / src / canmatrix / cli / compare.py View on Github external
matrixX can be any of *.dbc|*.dbf|*.kcd|*.arxml|*.xls(x)|*.sym
    """

    import canmatrix.log
    root_logger = canmatrix.log.setup_logger()

    if silent:
        # Only print ERROR messages (ignore import warnings)
        verbosity = -1
    canmatrix.log.set_log_level(root_logger, verbosity)

    # import only after setting log level, to also disable warning messages in silent mode.
    import canmatrix.formats  # due this import we need the import alias for log module

    logger.info("Importing " + matrix1 + " ... ")
    db1 = canmatrix.formats.loadp_flat(matrix1)
    logger.info("%d Frames found" % (db1.frames.__len__()))

    logger.info("Importing " + matrix2 + " ... ")
    db2 = canmatrix.formats.loadp_flat(matrix2)
    logger.info("%d Frames found" % (db2.frames.__len__()))

    ignore = {}  # type: typing.Dict[str, typing.Union[str, bool]]

    if not check_comments:
        ignore["comment"] = "*"

    if not check_attributes:
        ignore["ATTRIBUTE"] = "*"

    if ignore_valuetables:
        ignore["VALUETABLES"] = True
github ebroecker / canmatrix / src / canmatrix / cli / compare.py View on Github external
root_logger = canmatrix.log.setup_logger()

    if silent:
        # Only print ERROR messages (ignore import warnings)
        verbosity = -1
    canmatrix.log.set_log_level(root_logger, verbosity)

    # import only after setting log level, to also disable warning messages in silent mode.
    import canmatrix.formats  # due this import we need the import alias for log module

    logger.info("Importing " + matrix1 + " ... ")
    db1 = canmatrix.formats.loadp_flat(matrix1)
    logger.info("%d Frames found" % (db1.frames.__len__()))

    logger.info("Importing " + matrix2 + " ... ")
    db2 = canmatrix.formats.loadp_flat(matrix2)
    logger.info("%d Frames found" % (db2.frames.__len__()))

    ignore = {}  # type: typing.Dict[str, typing.Union[str, bool]]

    if not check_comments:
        ignore["comment"] = "*"

    if not check_attributes:
        ignore["ATTRIBUTE"] = "*"

    if ignore_valuetables:
        ignore["VALUETABLES"] = True

    if frames:
        only_in_matrix1 = [
            frame.name