-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kiran Jojare
committed
Jul 19, 2024
1 parent
d85a2a0
commit 2e39625
Showing
4 changed files
with
263 additions
and
43 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,96 @@ | ||
|
||
# CAN Log Parser | ||
|
||
# CAN-Log-Parser | ||
|
||
![Build Status](https://github.com/kiranj26/CAN-Log-Parser/actions/workflows/ci.yml/badge.svg) | ||
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/4a476526a37145f2922f58a6f903ff27)](https://app.codacy.com/gh/kiranj26/CAN-Log-Parser/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) | ||
![Flake8 Linting](https://img.shields.io/badge/flake8-linting-brightgreen) | ||
![Python Version](https://img.shields.io/badge/python-3.12-blue) | ||
![License](https://img.shields.io/github/license/kiranj26/CAN-Log-Parser) | ||
|
||
This project is a CAN log parser that parses DBC files and CAN log files, and plots signal values over time. | ||
This repository contains a Python-based tool to parse DBC formatted CAN log files and plot the signals. It leverages `cantools` for parsing DBC files and `matplotlib` for plotting signals, providing an easy way to visualize CAN signal data. | ||
|
||
## Features | ||
- Parse DBC files | ||
- Parse CAN log files | ||
- Plot signal values | ||
|
||
## Usage | ||
### Parsing DBC Files | ||
```bash | ||
python src/parse_dbc.py path_to_dbc_file | ||
|
||
|
||
This project is a tool to parse DBC formatted CAN log files and plot the signals. | ||
|
||
## Features | ||
- Parse DBC files to extract signal definitions | ||
- Read and parse CAN log files | ||
- Decode signals from CAN messages | ||
- Plot the decoded signals | ||
|
||
## Requirements | ||
- Python 3.8+ | ||
|
||
All required packages are listed in the `requirements.txt` file. | ||
|
||
- Python 3.6 or higher | ||
- cantools | ||
- matplotlib | ||
|
||
## Installation | ||
Clone the repository and install the required packages: | ||
|
||
```bash | ||
git clone https://github.com/your-username/CAN-Log-Parser.git | ||
cd CAN-Log-Parser | ||
pip install -r requirements.txt | ||
``` | ||
1. Clone the repository: | ||
|
||
```bash | ||
git clone https://github.com/kiranj26/CAN-Log-Parser.git | ||
cd CAN-Log-Parser | ||
``` | ||
|
||
2. Install the required dependencies: | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## Usage | ||
Place your DBC file and log file in the `data/` directory. | ||
|
||
Run the main script: | ||
1. Place your DBC file and log file in the `data/` directory. | ||
|
||
```bash | ||
python src/main.py | ||
``` | ||
2. Run the main script with the appropriate arguments: | ||
|
||
```bash | ||
python src/main.py test SAF_SpeedTest | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
python src/main.py test SAF_SpeedTest 43.2 45.6 | ||
``` | ||
|
||
## Repository Structure | ||
- `src/`: Contains the main scripts | ||
- `main.py`: Main script to run the tool | ||
- `can_parser.py`: Contains functions to parse CAN messages | ||
- `plot_signals.py`: Contains functions to plot signals | ||
- `data/`: Directory to place your DBC and log files | ||
|
||
- `src/`: Contains the main script and related files. | ||
- `main.py`: Main script to run the tool. | ||
- `data/`: Directory to place your DBC and log files. | ||
- `requirements.txt`: List of dependencies. | ||
|
||
## Script Description | ||
|
||
### parse_dbc(file_path) | ||
|
||
Parses the DBC file located at `file_path`. | ||
|
||
### parse_log(db, log_file_path) | ||
|
||
Parses the log file located at `log_file_path` using the parsed DBC data. | ||
|
||
### process_message(db, message_lines, parsed_data) | ||
|
||
Processes a single CAN message and extracts the signals. | ||
|
||
### print_parsed_data(parsed_data) | ||
|
||
Prints the parsed CAN data. | ||
|
||
### plot_signals(parsed_data, signal_name, start_time, end_time) | ||
|
||
Plots the specified CAN signal within the given time range. | ||
|
||
## Example | ||
An example DBC file and log file are provided in the `data/` directory. | ||
|
||
## Dependencies | ||
- `cantools`: A library for parsing DBC files and decoding CAN messages. It simplifies working with CAN databases and allows you to decode and encode CAN messages. | ||
- `matplotlib`: A plotting library for Python and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications. | ||
To run the script, navigate to the directory containing `main.py` and execute the following commands: | ||
|
||
```bash | ||
python src/main.py test SAF_SpeedTest | ||
OR | ||
python src/main.py test SAF_SpeedTest 43.2 45.6 | ||
``` | ||
|
||
These commands will parse the test.dbc and test_log.txt files located in the data/ directory, process the CAN messages, and generate a plot for the SAF_SpeedTest signal. | ||
|
||
## Output Screenshots | ||
|
||
# Contact | ||
|
||
You can download this README file by copying the content above and saving it as `README.md` in your repository folder. Make sure to replace the placeholder paths for the screenshots with the actual paths once you have the images ready. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
VERSION "" | ||
|
||
|
||
NS_ : | ||
NS_DESC_ | ||
CM_ | ||
BA_DEF_ | ||
BA_ | ||
VAL_ | ||
CAT_DEF_ | ||
CAT_ | ||
FILTER | ||
BA_DEF_DEF_ | ||
EV_DATA_ | ||
ENVVAR_DATA_ | ||
SGTYPE_ | ||
SGTYPE_VAL_ | ||
BA_DEF_SGTYPE_ | ||
BA_SGTYPE_ | ||
SIG_TYPE_REF_ | ||
VAL_TABLE_ | ||
SIG_GROUP_ | ||
SIG_VALTYPE_ | ||
SIGTYPE_VALTYPE_ | ||
BO_TX_BU_ | ||
BA_DEF_REL_ | ||
BA_REL_ | ||
BA_DEF_DEF_REL_ | ||
BU_SG_REL_ | ||
BU_EV_REL_ | ||
BU_BO_REL_ | ||
SG_MUL_VAL_ | ||
|
||
BS_: | ||
|
||
BU_: Node1 Node2 Node3 | ||
|
||
|
||
BO_ 100 AccelerationCommandTest: 8 Node1 | ||
SG_ ACC_AccelerationTest : 0|1@1+ (1,0) [0|1] "Bool" Node1,Node2 | ||
SG_ ACC_CurrentTest : 1|1@1+ (1,0) [0|1] "Bool" Node2,Node1 | ||
SG_ ACC_SurgeTest : 16|16@1+ (1,0) [0|32767] "RPM" Node1,Node2 | ||
SG_ ACC_AccelTest : 32|16@1+ (1,0) [0|32767] "RPM/sec" Node1,Node2 | ||
SG_ ACC_MaxCurrentTest : 48|8@1+ (5,0) [0|1275] "Amp" Node1,Node2 | ||
|
||
BO_ 101 FeedbackTest: 8 Node2 | ||
SG_ FB_SafetyModeTest : 0|1@1+ (1,0) [0|1] "Enum" Node1,Node2 | ||
SG_ FB_TorqueTest : 1|15@1+ (0.2,-3212.8) [-3212.8|3212.8] "Nm" Node2,Node1 | ||
SG_ FB_VoltageTest : 16|16@1+ (0.1,-3212.8) [-3212.8|3212.8] "Volts" Node2,Node1 | ||
SG_ FB_CurrentTest : 32|16@1+ (0.1,-3212.8) [-3212.8|3212.8] "Amps" Node2,Node1 | ||
SG_ FB_SpeedTest : 48|16@1+ (0.5,-16064) [-16064|16064] "rpm" Node2,Node1 | ||
|
||
BO_ 102 SafetyFeedbackTest: 8 Node3 | ||
SG_ SAF_SafetyModeTest : 0|1@1+ (1,0) [0|1] "Enum" Node1,Node3 | ||
SG_ SAF_TorqueTest : 1|12@1+ (1,-2048) [-2048|2047] "Nm" Node1,Node3 | ||
SG_ SAF_VoltageTest : 13|12@1+ (1,0) [0|4095] "Volts" Node1,Node3 | ||
SG_ SAF_CurrentTest : 25|12@1+ (1,-2048) [-2048|2047] "Amps" Node1,Node3 | ||
SG_ SAF_SpeedTest : 37|15@1+ (1,-16384) [-16384|16383] "rpm" Node1,Node3 | ||
|
||
BO_ 103 CommandTest: 8 Node1 | ||
SG_ CMD_ControlModeTest : 0|4@1+ (1,0) [0|6] "Enum" Node2,Node1,Node3 | ||
SG_ CMD_CommandCounterTest : 4|4@1+ (1,0) [0|15] "Integer" Node2,Node1,Node3 | ||
SG_ CMD_ActiveDischargeTest : 8|1@1+ (1,0) [0|1] "Bool" Node3,Node2 | ||
SG_ CMD_UseRawSpeedTest : 10|1@1+ (1,0) [0|1] "Bool" Node1,Node2,Node3 | ||
SG_ CMD_DirOfRotationTest : 11|1@1+ (1,0) [0|1] "Enum" Node1,Node2,Node3 | ||
|
||
BO_ 104 StatusTest: 8 Node2 | ||
SG_ STS_NotEnabledTest : 0|1@1+ (1,0) [0|1] "Bool" Node2,Node1 | ||
SG_ STS_OverCurrentTest : 1|1@1+ (1,0) [0|1] "Bool" Node2,Node1 | ||
SG_ STS_OverBusTest : 2|1@1+ (1,0) [0|1] "Bool" Node2,Node1 | ||
SG_ STS_OverPhaseTest : 3|1@1+ (1,0) [0|1] "Bool" Node2,Node1 | ||
SG_ STS_UnderVoltageTest : 4|1@1+ (1,0) [0|1] "Bool" Node2,Node1 | ||
|
||
CM_ "Test CAN database definition."; | ||
CM_ BU_ Node1 "Test Node 1"; | ||
CM_ BU_ Node2 "Test Node 2"; | ||
CM_ BU_ Node3 "Test Node 3"; | ||
CM_ BO_ 100 "Test command message for acceleration limits."; | ||
CM_ SG_ 100 ACC_AccelerationTest "Test signal for updating acceleration limits."; | ||
CM_ SG_ 100 ACC_CurrentTest "Test signal for updating current limits."; | ||
CM_ SG_ 100 ACC_SurgeTest "Test signal for controlling surges in acceleration."; | ||
CM_ SG_ 100 ACC_AccelTest "Test signal for maximum rate of acceleration."; | ||
CM_ SG_ 100 ACC_MaxCurrentTest "Test signal for maximum current in drive mode."; | ||
|
||
BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType","NotUsed"; | ||
BA_DEF_ SG_ "GenSigCycleTime" INT 0 0; | ||
BA_DEF_ BO_ "GenMsgSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoMsgSendType","NotUsed"; | ||
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 0; | ||
BA_DEF_ "BusType" STRING ; | ||
BA_DEF_DEF_ "GenSigSendType" "Cyclic"; | ||
BA_DEF_DEF_ "GenSigCycleTime" 0; | ||
BA_DEF_DEF_ "GenMsgSendType" "Cyclic"; | ||
BA_DEF_DEF_ "GenMsgCycleTime" 0; | ||
BA_DEF_DEF_ "BusType" ""; | ||
BA_ "BusType" "CAN"; | ||
BA_ "GenMsgCycleTime" BO_ 101 100; | ||
BA_ "GenSigCycleTime" SG_ 101 FB_SafetyModeTest 100; | ||
BA_ "GenSigCycleTime" SG_ 101 FB_TorqueTest 100; | ||
BA_ "GenSigCycleTime" SG_ 101 FB_VoltageTest 100; | ||
BA_ "GenSigCycleTime" SG_ 101 FB_CurrentTest 100; | ||
BA_ "GenSigCycleTime" SG_ 101 FB_SpeedTest 100; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
WinNo Identifier Flg Dlc Name Time Dir | ||
CAN 1 000064 X 8 VehicleNode AccelerationCommand_ECU.AccelerationCommandTest 44709.992868 R | ||
-> ACC_AccelerationTest 0.0000 Bool | ||
-> ACC_CurrentTest 1.0000 Bool | ||
-> ACC_SurgeTest 12345.0000 RPM | ||
-> ACC_AccelTest 67890.0000 RPM/sec | ||
-> ACC_MaxCurrentTest 100.0000 Amp | ||
CAN 1 000065 X 8 VehicleNode Feedback_ECU.FeedbackTest 44710.002938 R | ||
-> FB_SafetyModeTest 1.0000 Enum | ||
-> FB_TorqueTest 2345.6000 Nm | ||
-> FB_VoltageTest 3456.7000 Volts | ||
-> FB_CurrentTest 4567.8000 Amps | ||
-> FB_SpeedTest 5678.9000 rpm | ||
CAN 1 000066 X 8 VehicleNode SafetyFeedback_ECU.SafetyFeedbackTest 44710.012918 R | ||
-> SAF_SafetyModeTest 0.0000 Enum | ||
-> SAF_TorqueTest 567.0000 Nm | ||
-> SAF_VoltageTest 6789.0000 Volts | ||
-> SAF_CurrentTest 7890.1000 Amps | ||
-> SAF_SpeedTest 8901.2000 rpm | ||
CAN 1 000067 X 8 VehicleNode Command_ECU.CommandTest 44710.022908 R | ||
-> CMD_ControlModeTest 2.0000 Enum | ||
-> CMD_CommandCounterTest 3.0000 Integer | ||
-> CMD_ActiveDischargeTest 0.0000 Bool | ||
-> CMD_UseRawSpeedTest 1.0000 Bool | ||
-> CMD_DirOfRotationTest 0.0000 Enum | ||
CAN 1 000068 X 8 VehicleNode Status_ECU.StatusTest 44710.032888 R | ||
-> STS_NotEnabledTest 1.0000 Bool | ||
-> STS_OverCurrentTest 0.0000 Bool | ||
-> STS_OverBusTest 1.0000 Bool | ||
-> STS_OverPhaseTest 0.0000 Bool | ||
-> STS_UnderVoltageTest 1.0000 Bool | ||
CAN 1 000064 X 8 VehicleNode AccelerationCommand_ECU.AccelerationCommandTest 44710.042868 R | ||
-> ACC_AccelerationTest 1.0000 Bool | ||
-> ACC_CurrentTest 0.0000 Bool | ||
-> ACC_SurgeTest 54321.0000 RPM | ||
-> ACC_AccelTest 98765.0000 RPM/sec | ||
-> ACC_MaxCurrentTest 150.0000 Amp | ||
CAN 1 000065 X 8 VehicleNode Feedback_ECU.FeedbackTest 44710.052938 R | ||
-> FB_SafetyModeTest 0.0000 Enum | ||
-> FB_TorqueTest 1234.5000 Nm | ||
-> FB_VoltageTest 4567.8000 Volts | ||
-> FB_CurrentTest 5678.9000 Amps | ||
-> FB_SpeedTest 6789.0000 rpm | ||
CAN 1 000066 X 8 VehicleNode SafetyFeedback_ECU.SafetyFeedbackTest 44710.062918 R | ||
-> SAF_SafetyModeTest 1.0000 Enum | ||
-> SAF_TorqueTest 890.0000 Nm | ||
-> SAF_VoltageTest 5678.0000 Volts | ||
-> SAF_CurrentTest 6789.1000 Amps | ||
-> SAF_SpeedTest 7890.2000 rpm | ||
CAN 1 000067 X 8 VehicleNode Command_ECU.CommandTest 44710.072908 R | ||
-> CMD_ControlModeTest 3.0000 Enum | ||
-> CMD_CommandCounterTest 4.0000 Integer | ||
-> CMD_ActiveDischargeTest 1.0000 Bool | ||
-> CMD_UseRawSpeedTest 0.0000 Bool | ||
-> CMD_DirOfRotationTest 1.0000 Enum | ||
CAN 1 000068 X 8 VehicleNode Status_ECU.StatusTest 44710.082888 R | ||
-> STS_NotEnabledTest 0.0000 Bool | ||
-> STS_OverCurrentTest 1.0000 Bool | ||
-> STS_OverBusTest 0.0000 Bool | ||
-> STS_OverPhaseTest 1.0000 Bool | ||
-> STS_UnderVoltageTest 0.0000 Bool | ||
CAN 1 000064 X 8 VehicleNode AccelerationCommand_ECU.AccelerationCommandTest 44710.092868 R | ||
-> ACC_AccelerationTest 2.0000 Bool | ||
-> ACC_CurrentTest 2.0000 Bool | ||
-> ACC_SurgeTest 54322.0000 RPM | ||
-> ACC_AccelTest 98766.0000 RPM/sec | ||
-> ACC_MaxCurrentTest 151.0000 Amp | ||
CAN 1 000065 X 8 VehicleNode Feedback_ECU.FeedbackTest 44710.102938 R | ||
-> FB_SafetyModeTest 1.0000 Enum | ||
-> FB_TorqueTest 2346.5000 Nm | ||
-> FB_VoltageTest 4568.8000 Volts | ||
-> FB_CurrentTest 5679.9000 Amps | ||
-> FB_SpeedTest 6780.0000 rpm | ||
CAN 1 000066 X 8 VehicleNode SafetyFeedback_ECU.SafetyFeedbackTest 44710.112918 R | ||
-> SAF_SafetyModeTest 0.0000 Enum | ||
-> SAF_TorqueTest 569.0000 Nm | ||
-> SAF_VoltageTest 6782.0000 Volts | ||
-> SAF_CurrentTest 7892.1000 Amps | ||
-> SAF_SpeedTest 8912.2000 rpm | ||
CAN 1 000067 X 8 VehicleNode Command_ECU.CommandTest 44710.122908 R | ||
-> CMD_ControlModeTest 2.0000 Enum | ||
-> CMD_CommandCounterTest 5.0000 Integer | ||
-> CMD_ActiveDischargeTest 0.0000 Bool | ||
-> CMD_UseRawSpeedTest 1.0000 Bool | ||
-> CMD_DirOfRotationTest 0.0000 Enum | ||
CAN 1 000068 X 8 VehicleNode Status_ECU.StatusTest 44710.132888 R | ||
-> STS_NotEnabledTest 1.0000 Bool | ||
-> STS_OverCurrentTest 0.0000 Bool | ||
-> STS_OverBusTest 1.0000 Bool | ||
-> STS_OverPhaseTest 0.0000 Bool | ||
-> STS_UnderVoltageTest 1.0000 Bool |