stevendaniluk / MotecLogGenerator

For generating MoTeC .ld files from external log sources
Do What The F*ck You Want To Public License
20 stars 7 forks source link

MotecLogGenerator

Utility for generating MoTeC .ld files that can be analyzed with i2 Pro from external log sources. Generated log files are "Pro Enabled", so they can be opened in either i2 Standard or i2 Pro.

Currently the following input types are supported:

CAN bus logs must be paired with a DBC file describing the structure of the frames.

This will resample all signals from the input log to be at a fixed frequency. This is done because MoTeC expects channels to have messages at a constant frequency, while this may not always be the case for input log files. This is especially true for CAN logs from a vehicle, where some messages only get triggered by certain actions. The frequency which the data is resampled is configurable (see usage below).

Tip: To clone with the submodule included run:

git clone --recursive git@github.com:stevendaniluk/MotecLogGenerator.git

Usage

Check out the examples directory for some sample log files to test the tool with.

CAN Bus Logs

python3 motec_log_generator.py /path/to/my/data/can_data.log CAN --dbc /path/to/my/data/car.dbc

This will generate a motec .ld file /path/to/my/data/can_data.ld.

CSV Logs

python3 motec_log_generator.py /path/to/my/data/csv_data.csv CSV

This will generate a motec .ld file /path/to/my/data/csv_data.ld.

The first column of the CSV file must be time. Channels will not be assigned any units.

Accessport Logs

python3 motec_log_generator.py /path/to/my/data/accessport_data.csv ACCESSPORT

This will generate a motec .ld file /path/to/my/data/accessport_data.ld.

Additional Options

A different destination and filename for the generated .ld file can also be specified by adding the following to the command:

--output /path/to/different/location/new_filename.ld

It is also possible to provide additional arguments to populate the metadata in the motec log file for driver, venue, vehicle, etc. See the usage below for full details.

usage: motec_log_generator.py [-h] [--output OUTPUT] [--frequency FREQUENCY]
                              [--dbc DBC] [--driver DRIVER]
                              [--vehicle_id VEHICLE_ID]
                              [--vehicle_weight VEHICLE_WEIGHT]
                              [--vehicle_type VEHICLE_TYPE]
                              [--vehicle_comment VEHICLE_COMMENT]
                              [--venue_name VENUE_NAME]
                              [--event_name EVENT_NAME]
                              [--event_session EVENT_SESSION]
                              [--long_comment LONG_COMMENT]
                              [--short_comment SHORT_COMMENT]
                              log {CAN,CSV,ACCESSPORT}

Generates MoTeC .ld files from external log files generated by: CAN bus dumps,
CSV files, or COBB Accessport CSV files

positional arguments:
  log                   Path to logfile
  {CAN,CSV,ACCESSPORT}  Type of log to process

options:
  -h, --help            show this help message and exit
  --output OUTPUT       Name of output file, defaults to same as 'candump'
  --frequency FREQUENCY
                        Fixed frequency to resample all channels at
  --dbc DBC             Path to DBC file, required if log type CAN
  --driver DRIVER       Motec log metadata field
  --vehicle_id VEHICLE_ID
                        Motec log metadata field
  --vehicle_weight VEHICLE_WEIGHT
                        Motec log metadata field
  --vehicle_type VEHICLE_TYPE
                        Motec log metadata field
  --vehicle_comment VEHICLE_COMMENT
                        Motec log metadata field
  --venue_name VENUE_NAME
                        Motec log metadata field
  --event_name EVENT_NAME
                        Motec log metadata field
  --event_session EVENT_SESSION
                        Motec log metadata field
  --long_comment LONG_COMMENT
                        Motec log metadata field
  --short_comment SHORT_COMMENT
                        Motec log metadata field

The CAN bus log must be the same format as what is generated by 'candump' with
the '-l' option from the linux package can-utils. A MoTeC channel will be
created for every signal in the DBC file that has messages in the CAN log. The
signal name and units will be directly copied from the DBC file. CSV files
must have time as their first column. A MoTeC channel will be generated for
all remaining columns. All channels will not have any units assigned. COBB
Accessport CSV logs are simply generated by starting a logging session on the
accessport. A MoTeC channel will be created for every channel logged, the name
and units will be directly copied over.

Generating CAN Logs

On a linux machine connected to the CAN bus you can run:

candump can0 -l > my_candump.log

It will generate a log file formatted like below:

(1630268615.800257) can0 0D4#0000000000000000
(1630268615.801277) can0 152#E9BC00000000008C
(1630268615.802316) can0 380#150A00000000001F
(1630268615.807716) can0 140#0082C34300000981
(1630268615.808638) can0 141#6A263B27C4C32103
...

CAN Utilities

Under the can_utils directory there are some tools for:

Dependencies

pip install cantools numpy

Disclaimer

This work was produced for research purposes. It should in no way be used to circumvent MoTeC's licensing requirements for their data loggers or i2 analysis software.