Using the Macchina M2 as a middle man between the vehicle and a computer in real time

This device has sparked my interest seeing that it has the possibility of being connected to so many buses: SWCAN, 2xCAN, LIN.

I am interested in buying one but first I want to make sure I can get it to do what I want. I will be connecting all its ports to my GM vehicle. I would like to have the M2 record every piece of data (can frames) from all connected ports and send them to a computer running either Windows or Linux (haven’t decided yet). I will also be sending back data from the computer to the M2 which it would then replay on the relevant bus.

My concern is whether or not the M2 is able to do this in real time and, if it is, what sort of communication would be suitable between the M2 and the computer, is it able to push this much data through its USB port? I know there are WiFi shields but I would really prefer a wired connection.

Finally, I am new to this forum and to this product. I have tried searching around but, being that there are so many topics, I wan’t really able to find much so excuse me if this information is already out there. Thanks!

I have run the M2 in my CTS which has a high speed bus and the SWCAN bus and it has done fine at capturing both.

At this point in time there is not much support beyond using SavvyCAN with the base M2 software. LIN software is available but it is not combined with the other software and able to be captured just yet.

Cancat will work with it too as a MIM but only with the 2 can ports. This will change hopefully at some point this year.

Yes, it ought to be fine doing 3 buses at full load, sending and receiving. I would recommend USB for this. The USB port on the device is USB2 at 480Mbits per second and the hardware itself can sustain at least a couple of megabytes per second.

As Rod said, really there isn’t a lot out there in terms of software support for doing this sort of thing except for SavvyCAN. But, it runs on Windows, OSX, and Linux so you can take your pick. And, both SavvyCAN (the PC side) and M2RET (the firmware on the M2) are open source so if either doesn’t do what you want you can make it do what you want.

Thank you both for the info! It’s good to know it’s capable. It will have to be connected to at least one SWCAN and 2 high speed buses. My vehicle has at least two independent SWCAN buses. I plan on using a MUX or something similar to switch between them depending on whether or not I can get the same info from the other high speed buses. Would you recommend such an approach for sequentially connecting to multiple buses with the same pins?

I don’t think I’ll be redirecting traffic from one port to another. I am more interested in monitoring the ports for various bits of data and react by sending some commands back. Seeing that the bottleneck is the USB2, at 480Mb/s, would you see any problem in sending all data through and filtering from my side in software as opposed to filtering on the M2 and just sending the filtered data?

I will definitely be using SavvyCAN for sniffing around but I will eventually be writing my own software. Does SavvyCAN offer any sort of interface / API? I could, as you suggested, take the open source code and adapt it but no point in reinventing the wheel if I don’t have to :slight_smile:.

Just ordered the M2. Can’t wait for it to arrive!

It doesn’t have an API per se but it does support Javascript scripts that you can write and run within the rest of the system. I’m going to support python at some point too. Python is really what the hacker types want to use. The goal will be to replace javascript with python and then maybe even have some of SavvyCAN itself be written in python and possible to customize locally.

Not much of a Python fan although I get why it’s so popular. I’m comfortable with C, Java, C# and even functional programming languages but after spending a whole day fruitlessly trying to call some Python code from one class into another… I guess my brain needs some rewiring that I am not really interested investing patience into.

I’m with you on that. I feel kind of dumb or strange in a way. I can program in assembly, C, C++, C#, Java, Fortran (well, it’s been YEARS… I used to be able to), javascript, ActionScript, but I haven’t been able to wrap my head around Python yet.

I think anyone starting out should learn python. Anyone who wants to seriously break into the security field should learn python. I should learn python.

I started with C / C++ and then moved on to C# and Java with a bit of Haskell and Pascal in between and now I’m looking into Javascript. I, too, don’t really learn anything passively. I can read a single page 10 times and at the end I’ll be asking myself “what did I just read?!”. It just doesn’t stick. When I actually try to replicate whatever I read or apply the info I otherwise wouldn’t gain, everything clicks into place.

There’s also machine learning. Python has an extensive set of tools that allows you to implement AI pretty fast. Or so I’ve heard.

What do you think of my other two questions regarding the mux and the filtering?

For filtering: I routinely shove all frames on the wire down USB and filter on the PC side. That’s basically all M2RET does in concert with SavvyCAN. All the frames flow over USB and we handle filtering at the PC so that filters can be changed on demand and nothing is lost. So I know it can do that for one bus at least. I think I tested with saturating two CAN buses at the same time and it was fine. I’ve captured two buses at a time on a Volt (well, really I used two adapters at the same time and captured 3 at once). So I know that works too. I think you’ll be OK sending it all down the USB link and filtering at the other side. But, if you know what sort of filtering you want it is easier on all components if you use as much filtering as you can.

For mux: The problem here is that CAN is a differential bus usually (well, SWCAN isn’t) and so you’d kind of need an analog mux to transfer through the voltage levels as-is. Luckily basically no transceiver tries to generate negative voltages so all the CAN signals should look like discrete signal levels above ground. So, basically it is just like an analog signal that just happens to only take about 3 different values. Thus, I think you’d be OK using an analog MUX to switch the CAN wires.

Ok, thanks for the help. I have another question now. I noticed you are using QSerialPort for USB serial comm. The baud rate is set to 1 Mbit. You also set the rate to 1Mbit for the Arduino as well but it might as well be 0 because it ignores the rate for SerialUSB. Is the baud rate ignored for the QSerialPort as well or should I consider changing it to a bigger rate if need be?

I thought I had it set to 10,000,000. But, the answer is, I’m not totally sure. I think QSerialPort notifies the serial driver of the baud rate. In the case of the M2 the driver is going to ignore that because both ends are unrestricted in terms of transfer speed. Well, not unrestricted technically but there is no baud rate. An easy way to test would be to set it to 1200 baud and see what happens. If that doesn’t break anything then don’t worry about it. If it does slow it down then try setting the baud rate to like 50 million.

I tried settings the QSerialPort baud rate to 1200 baud and I could still easily send 500 frames per second down the wire in both directions. This seems to confirm that the PC side ignores the baud rate set too. That’s exactly what I’d expect it to do since there is no real serial port there - just two USB 480Mbit capable devices pretending to be two sides of a serial connection. Well, I suppose USB is a serial connection anyway but you know what I mean. :wink:

It’s good to know. I used SavvyCAN with a socketcan device and it worked pretty well. I can’t wait for the device to ship.

Any idea how long, on average, it would take for it to be shipped?