mickeyl / LTSupportAutomotive

An iOS / watchOS / macOS support library for OBD2, VIN-Decoding, and more.
MIT License
212 stars 59 forks source link

Implement CAN monitor mode / buffer dump #17

Open thdankert opened 5 years ago

thdankert commented 5 years ago

Even though the ELM327 can't monitor a high-speed CAN bus in real-time, it would be nice to have support for "streaming" all received data to the application.

According to the datasheet, either MA (monitor all) or BD (buffer dump) can be used for that purpose. Together with CF (ID filter) and CM (mask) only the relevant messages can be filtered, so the chip has a chance to capture all relevant bus traffic.

This won't play nice with the way this library currently works: by definition, the monitor command will never complete (unless the buffer becomes full). But the library will only call the response handler if the command is complete, and the whole response has been received.

My idea is to add special handling when in monitoring mode - each received line is directly forwarded to the application, with no further processing in between.

I'm going to try and implement it in my fork and will send a PR.

mickeyl commented 5 years ago

Sounds good – I'd definitely like to see this in LTAutomotiveSupport.

With respect to the inner workings, here are some spontaneous ideas:

These are just directly out of my head without thinking longer about it. Feel free to come up with an alternative proposal, if you think you have a better idea.

Good speed!

thdankert commented 5 years ago

Due to time constraints, I have not finished my rework... right now I simply start the monitoring again as soon as a response has been received from the device. Since bluetooth LE can't transmit very fast, the device quite often responds with "BUFFER FULL", but so far, I was able to sniff CAN traffic at 250kb/s (with filters set, it would be too much without them).