Reading a value inside of a CAN packet

I am hoping that someone can help me out with this code as I hit a bit of a wall.

The plan for the code is capture the CAN packet that says the car is in reverse and then watch for the car to no longer go in reverse and the speed of the car goes over say 5 mph. The end goal is to turn on a front facing parking camera that will be located in my rear view mirror every time the car is put into reverse and leave it on until the car goes forward at some speed. This basically mimics how the front facing camera worked in a loaner Cadillac CT6.

I have found that on the SW CAN bus there is a packet that is sent out that changes the 2nd octet from 0x20 while in reverse to 0XF0 when not in reverse. The Id (in case anyone is wondering) is 0x1004A040. My best guess is that is what the gauge cluster is using to light up the R in the dash when the car is in reverse.

I started by taking the example code for sending a SMS when the emergency flashers are turned on. However, I ran into an issue in that it appears to be looking at a CAN packet that only contains the button press data. What is checks is “incoming.data.low == 192 //192 = C0 in dec”. I read through the due_can readme but unfortunately I didn’t really find anything to help me with this.

So, my question, as in the subject of this topic, how exactly do I find the value of a single octet inside of a CAN packet with a length (from SavvyCAN) of 7.

Thanks,
Douglas

On what Cadillac? What year?

2012 CTS-V

I also played with this more yesterday and actually found what I think is the reverse switch packet, which I’ll probably end up using. It sends one packet when the car goes into reverse and another packet when it comes out of reverse. Uses the same signal id, just different values in the first octet (as far as I’ve seen so far at least)

However, my question still stands, how do you decipher the value of a single octet in my scenario?

Thanks,
Douglas

So what you want to do is make a sketch that reads the CAN bus and triggers when a single wire CAN frame with ID 0x1004A040. But, here’s the thing, if you are reading single wire CAN you aren’t using the due_can library. You need mcp2515 and Single-Wire-CAN-mcp2515 to interface with single wire CAN. At the moment this has a different API from due_can. But, I’m fixing that virtually as we speak. Very soon mcp2515 and due_can will descend from the same base class and you’ll be able to use a common API to communicate with either one. This will make things a lot less confusing for everyone.

But, either way, if you have a frame that came in and you want to figure out where it has the proper ID its
if (frame.id == 0x1004A040)

If you want to know if the second byte is 0x20 its
if (frame.data.byte[1] == 0x20)

Colin - Thank you, thank you, thank you! That was exactly what I was looking for. Is this documented somewhere that I missed? I feel like I keep asking questions that I should be able to find the answer to.

For the SW CAN - I realized in my playing with it that no SW data was coming through on Can 1, but I was getting my normal CAN data on Can 0. I wasn’t sure if the SavvyCAN single wire workaround would work for what I was doing or not, but I wasn’t that concerned about it at this moment since I didn’t know how to look for the data. That is awesome to hear about mcp2515 and due_can.