This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
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.
multiple filters, parsing and decoding, and refactoring code
This commit is comprised of three major parts 1.) Multiple filters enabled 2.) parsing function 3.) Decoding function Multiple filters including multiple filters is rather straightforward. All you need to do is reinitialize the CAN filter structure but change the filter bank you are using. To do this is rather simple and I could have done it manually for all IDs but It would have taken a lot of space. So, in order to make the code easier I went ahead and made a function that takes in two different parameters. The first parameter is filter bank number and the second is the extended ID you want to filter. I also made a variable that is called CANIDList which is an array that holds all the IDs.I made this to make to make CAN filtering a little easier on the eyes. Parsing function this function sorts the filtered extended IDs that have passed through the CAN controller. In addition, the function calls another function called canDecodeDataFrame(). This function converts the data frame from each message into either an unsigned integer or a signed integer ( this just depends on the data that is being decoded). After the data is decoded, it is then multiplied by its resolution value ( you can also divide if you like fractions better). I didn't see any trend in how the resolution was ordered so I multiplied the decoded data manually. Decoding function This is arguably the most important part of this commit. This function utilizes the equation given in the application note to decode all of the data into either an unsigned integer or a signed integer. This function was made to automate the decoding process because I noticed that there were 5 distinct ways the data was stored in a single message. With that in mind, I then created a switch statement that can order decoding based on one of the 5 unique ways data is stored. I couldn't think of any logic that could auto-detect which of the 5 decoding methods were used so I just used a parameter for the function to tell the function which decoding method is needed. I also used a printf statement to display both 0x0CFFF048 and 0x0CFFF548 on the serial monitor. This is a simple way to show that I'm able to decode data correctly and able to filter more than one ID. For 0X0CFFF048 I utilized ChatGPT to create a single simulated data Frame and sent that data frame to the CAN bus using an Arduino Uno. The data organization in 0x0CFFF048 is referred to in my code as the first unique data organization. This means that there are 4 unique data sets each having a length of 2 bytes. Bytes 1 and 2 are the RPM, bytes 3 and 4 are TPS, bytes 5 and 6 are the Fuel Open Time, and bytes 7 and 8 are the Ignition angle. The simulated value sent under the 0x0CFFF048 ID is [0x20 0x1c 0x2B 0x2 0x9B 0x00 0x9C 0xFF]. Which should read RPM = 7200, TPS = 55.5%, Fuel Open Time = 15.5ms, and Ignition angle = -10 degrees. Luckily when printing the data to the serial monitor, I managed to decode these exact values for this ID. The second ID (0x0CFFF548) is also included because previously we decoded this data frame in person last time and had the data for the battery voltage. This means I can confirm my parsing is correct since I know what the battery voltage value should be.
- Loading branch information
1 parent
177d9f6
commit 200bacf
Showing
1 changed file
with
294 additions
and
52 deletions.
There are no files selected for viewing
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