Giter Site home page Giter Site logo

mickeyl / ltsupportautomotive Goto Github PK

View Code? Open in Web Editor NEW
212.0 15.0 61.0 193 KB

An iOS / watchOS / macOS support library for OBD2, VIN-Decoding, and more.

License: MIT License

Objective-C 99.68% Ruby 0.32%
obd btle obd2 ios elm327 watchos4 macos usb-serial-adapters wifi

ltsupportautomotive's Introduction

Status

This library is stable and by now pretty much in bugfix-only mode. The reason for that is that the support for Unified Diagnostic Services (UDS) (which I originally planned to implement in this library) proved to be unworkable – see this comment for more details.

If your priority is full OBD2 coverage, you can (and should) still continue to use this library. It works great with both Objective-C and Swift (in particular the SPM branch). If your priority is UDS though, I might have something proprietary for you. If you aren't shy of licensing a closed source library, please contact me in private.

Introduction

LTSupportAutomotive is a library for writing apps that communicate with vehicles using OBD2 adapters. It also contains auxilliary classes, such as a VIN decoder, and a BTLE characteristic(s) / NSStream serial bridge.

Here is an overview of the most important classes:

LTOBD2Adapter (abstract)

Represents an OBD2 adapter sending commands over input- and output-streams using a certain vehicle protocol. Concrete subclasses (e.g., LBOBD2AdapterELM327 for ELM327-compatible chipsets, or LTOBD2AdapterCaptureFile for capture files) are available.

LTOBD2Command (abstract)

Represents an OBD2 command. Concrete subclasses, e.g. for the well-known OBD2 PIDs are available.

LTOBD2Protocol (abstract)

Represents a generic vehicle protocol. Concrete subclasses for protocols such as ISO14230-4 (CAN), ISO15765-4, ISO9141-2, or SAEJ1850 are available.

LTBTLESerialTransporter

Represents a bridge between one or two BTLE characteristics and NSStream subclasses.

How to use LTSupportAutomotive

CococaPods

Add this framework to your podfile:

pod 'LTSupportAutomotive', '~> 1.0'

Carthage

If anyone wants to make this carthage aware, feel free to supply a pull request. I'm not using this package manager myself.

Xcode subproject

You can also include LTSupportAutomotive as an Xcode subproject and link LTSupportAutomotive.framework to your executable.

Swift Package Manager

Please see the SPM branch.

Examples

LTAutomotiveSupportDemo.xcodeproj is a (pretty bare-bones) example project.

Apps using this library

Please drop us a note, if you are using this library as well.

Supported Hardware

This software should work with most ELM327-compatible hardware (including the behemoth of available clones). In general, I recommend the Bluetooth 4.0 devices, since they seem to have a much better quality compared to WiFi adapters – and these days they are only minimally more expensive. Moreover, they're much more convenient as you don't have to switch the WiFi network (potentially losing your internet connectivity).

Note that since iOS is lacking public SDK access to Bluetooth classic (in particular the Bluetooth rfcomm protocol), iOS devices will generally not work with Bluetooth 3.0 adapters – notable exceptions being those who take part in the Apple Manufactured For iPod program.

I have tested this library myself with the following adapters (Note that none of these contain a real ELM327):

Apple MFi

  • SCANTOOL OBDLINK MX+ (STN2255)

Bluetooth 4.0 (BLE)

  • Carista Bluetooth OBD2
  • FIXD OBD-II Scan Tool (2nd Gen)
  • kungfuren OBD2 Bluetooth 4.0
  • LELink Bluetooth Low Energy
  • VGate iCar Pro BLE4.0 Dual
  • WGSoft.de UniCarScan UCSI-2000
  • WGSoft.de UniCarScan UCSI-2100

WiFi

  • EXZA® SUPER Mini WiFi WLAN OBD 2
  • NAVISKAUTO WIFI WLAN ELM327
  • SCANTOOL OBDLINK MX WIFI (STN1153)

USB

  • SCANTOOL OBDLINK SX (STN1130)
  • SCANTOOL OBDLINK EX (STN2230)

Enhancements

While this library can already be used for a lot of things, I'd like to see improvements in a bunch of areas, such as:

  • Translations (I only have DE, FR, and EN atm.),
  • Implementation of missing standardized PIDs,
  • Addition of vendor-specific DTCs,
  • Implementation of vendor-specific PIDs,
  • Implementation of direct (non-PID-based) communication with ECUs.

How to contribute

Please fork and open a pull-request. I'd also like to know about success stories or confirmation for additional compatible hardware (see above) working with this library.

Special Thanks

  • LAWA Solutions GmbH
  • Thomas Dankert
  • BOSCH Service Solutions GmbH
  • TPE Europe GmbH

License

Copyright (c) 2016-2021 Dr. Michael 'Mickey' Lauer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in the documentation of any redistributions of the template files themselves (but not in projects built using the templates).

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ltsupportautomotive's People

Contributors

mickeyl avatar thdankert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ltsupportautomotive's Issues

ELM327 parser does not detect PID return directly following ...

I got the following log report where our parser does not properly recognize the vehicle's protocol, since the adapter inserts a response PID directly after the "please-wait" dots. Here's the relevant transcript:

>0100^MSEARCHING...^M...48 6B 1A 41 00 88 18 00 10 BE

Swift support for LTSupportAutomotive 1.1

This issue keeps track about the forthcoming Swift support for LTSupportAutomotive. I'm planning to:

  • Relayout the source files to make the Swift Package Manager happy (while not breaking the .xcodeproj)
  • Check/Adjust nullability annotations
  • Check/Adjust lightweight generic annotations
  • Check/Adjust enums
  • Check whether we can make the package work on Linux
  • Register with the https://swiftpackageindex.com and the https://swiftpackageregistry.com

After that we can tag and release 1.1.
NB: I don't plan rewriting this library in Swift any time soon. However I want to make the call sites as swifty as possible.

LELink Bluetooth Low Energy - stuck on "OBD2AdapterStateInitializing" state

Hello, I have tried adjusting the UUID defined in the code to match the LELink device to no avail..

It sees the device for sure but is stuck in the "OBD2AdapterStateInitializing" state

I also adjusted the switch statement to handle the Initializing state to fall through, or also to act like it's connected... but I never get any data to the demo app

Any ideas for help? :) THANK YOU IN ADVANCE

OBDLink MX+ via BT Stuck on initializing, Received Data: Error\r

Tried by cloning repo, running Demo.xcodeproj and testing with the OBDLink MX+ Model MX201 (3.1) connected via Bluetooth. The OBDLink is connected to Freematics OBD-II emulator (KWP2000, ISO9141-2, CAN BUS & J1850).

In sendInitializationSequence, the responseHandler in transmitRawString is never called.
I see in the logs "Received Data: Error\r"

Full log: https://hastebin.com/share/ivobiqulad.xml

Sending ATD command alone causes the same error.
Sending ATZ alone gives some sort of output that is not an error:

-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: OBD-II EMULATOR V1.2
-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: \r\n
-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: -[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:169) Warning: Skipping invalid character 0x00 in response...
-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: OBD-II EMULATOR V1.2
-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: \r\n00.00.02,00.01.05,
-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: 202311,GH202311B****
-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: 15,LSGGG************
-[LTOBD2AdapterELM327 receivedData:receiveBuffer:] (LTOBD2AdapterELM327.m:154) Received data: \r\n

(*-ed out some stuff like VIN).

Full log: https://hastebin.com/share/urezewawij.xml

Is there a way to make this work? The adapter is meant to be ELM327 compatible and lists many supported ELM327 commands:

stn1100-frpm (1).pdf

Any ideas about simulating DTC functions?

Hi Mr.mickeyl

Your repo is so nice. I just wanna get some suggestion about simulating DTC functions. Could you have any ideas about it

Thank you and Best Regard.

iOS Bluetooth connection with ELM327 not working

We've tried this sample with Bluetooth ELM327 adapter and it seems it's not working. Furthermore, iOS device can't see adapter at all (Settings->Bluetooth). But android device can. If you could do that with bluetooth ELM327() and iOS device, could you, please, provide version of adapter or any details will be appreciated.

We've successfully connected with Wi-Fi ELM327 adapter with some changes in sample. So, is it possible to establish bluetooth connection between iOS and OBD2 adapter(maybe with help of CoreBluetooth)? Thanks.

Adapter<->Vehicle Communication sometimes not successful

Sometimes I receive reports where the OBD2 adapter gets recognized successfully, but for some reason the adapter<->vehicle can't negotiate on a common protocol. I wonder whether there's anything we can do about it.

We already try manual protocol selection if the automatic fails – perhaps we should improve the init sequence?

Here is a sample log:

ATD
OK

>ATZ
ATZ


ELM327 v1.5

>ATE0
ATE0
OK

>ATRV
13.9V

>ATSP0
OK

>ATE0
OK

>ATL1
OK



>ATH1
OK



>ATI
ELM327 v1.5



>ATS1
OK



>ATIGN
ON



>0100
SEARCHING...
...UNABLE TO CONNECT



>ATTP1
OK



>0100
NO DATA



>ATTP2
OK



>0100
NO DATA



>ATTP3
OK



>0100
BUS INIT: ...ERROR



>ATTP4
OK



>0100
BUS INIT: ...ERROR



>ATTP5
OK



>0100
BUS INIT: ERROR



>ATTP6
OK



>0100
NO DATA



>ATTP7
OK



>0100
NO DATA



>ATTP8
OK



>0100
NO DATA



>ATTP9
OK



>0100
NO DATA



>

Connection Issue

Hello Mickey,

I'm a student from Germany and me and a small team of colleagues is working on a simple Dashboard App for iOS. It's just a small project for university and we are all not that deep into programming. We've tried to add your library with Cocoapods and used your example project to test the connection with an OBDLink MX+ Adapter. Unfortunately, we can't get the app to connect to our Adapter or get any sign of connectivity. The build succeeds without issues and we tried several things like adding a Bluetooth Usage Key in Info.plist but nothing is working out for us.
Can you or someone help us to find the problem? Would be really appreciated.

Best Regards

LTOBD2Adapter: Race Condition in Command Queue Access

-(void)asyncEnqueueInternalCommand:(LTOBD2AdapterInternalCommand*)internalCommand
{
    **[_commandQueue addObject:internalCommand];**
    [self asyncProcessCommandQueue];
}
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 7191 beyond bounds [0 .. 7189]'

Can you help me to figure out what has happend. I record over 30 Minutes rpm and speed and 4 Other values.

How to read DTC codes ?

Hi, i'm new to this field and thanks for amazing library. My car now can connect to your demo app, but i don't know how to read DTC code from my car ?

Can someone give me some example pls

got "Invalid or short line '83' found"?

Hi Mr.Mickeyl

I got a Polo Volkswagen car. And trying to test this libs with OBD bluetooth connector. But I got message "Invalid or short line '83' found". No valid data come out. I don't know how to handle with this error message. The protocol this car using is OBD2VehicleProtocolKWP2000_5KBPS with implementation for this protocol is [LTOBD2ProtocolISO14230_4 protocol].

Here is some log about that:

[LTOBD2AdapterInternalCommand didCompleteResponse:protocol:protocolType:] (LTOBD2Adapter.m:58) <LTOBD2PID_VEHICLE_SPEED_0D:0x282bf60a0 = '010D'> complete [487 ms] => '83 - F1 - 1A - 41 - 0D - 00 - DC'
-[LTOBD2ProtocolISO14230_4 decode:originatingCommand:] (LTOBD2ProtocolISO14230_4.m:55) Invalid or short line '83' found
-[LTOBD2ProtocolISO14230_4 decode:originatingCommand:] (LTOBD2ProtocolISO14230_4.m:55) Invalid or short line 'F1' found
-[LTOBD2ProtocolISO14230_4 decode:originatingCommand:] (LTOBD2ProtocolISO14230_4.m:55) Invalid or short line '1A' found
-[LTOBD2ProtocolISO14230_4 decode:originatingCommand:] (LTOBD2ProtocolISO14230_4.m:55) Invalid or short line '41' found
-[LTOBD2ProtocolISO14230_4 decode:originatingCommand:] (LTOBD2ProtocolISO14230_4.m:55) Invalid or short line '0D' found
-[LTOBD2ProtocolISO14230_4 decode:originatingCommand:] (LTOBD2ProtocolISO14230_4.m:55) Invalid or short line '00' found
-[LTOBD2ProtocolISO14230_4 decode:originatingCommand:] (LTOBD2ProtocolISO14230_4.m:55) Invalid or short line 'DC' found

Command Response

purpose: Vehicle Speed
formattedResponse: No data
rawResponse: ["83", "F1", "1A", "41", "0D", "00", "DC"]
rawCommand: false
commandString: 010D
protocol: OBD2VehicleProtocol(rawValue: 4)
cookedResponse: [:]
failureResponse: [:]
answer: true
validAnswer: false
CAN: false

Reading DTCs

I am having some issues regarding reading DTCs through mode 03, 07, and 0A.

When compared to a wired OBD reader, we only read from one of all available locations.
Pictured below is a wired reader with DTCs on the ABS and ECM modules, along with the OBDII/EOBD. We are only reading codes from the OBDII/EOBD, and not on the ABS nor ECM, nor TCM if applicable.

image

I am using a compatible adapter, and using some apps on the App Store I have been able to read from the ABS module using my adapter.

I am wondering if anything like this has been done with this library

Bug in LTOBD2PID_DISTANCE_SINCE_DTC_CLEARED_31

The -(NSString*)formattedResponse method in @implementation LTOBD2PID_DISTANCE_SINCE_DTC_CLEARED_31 uses -(NSString*)formatSingleByteDoubleValueWithString:(NSString*)formatString offset:(double)offset factor:(double)factor

It should use instead: -(NSString*)formatTwoByteDoubleValueWithString:(NSString*)formatString offset:(double)offset factor:(double)factor with factor: 1

Source: https://en.wikipedia.org/wiki/OBD-II_PIDs
The formula for Distance traveled since codes cleared: 256A + B

UDS Support (cancelled)

This issue is for keeping track of the necessary work to allow UDS communication as per ISO14229

  • Allow configuring the ELM327 adapter initialization
  • Implement ELM327 Arbitration and Control Flow commands
  • Implement ISO-TP in direction ADAPTER → ECU
  • Add service IDs for UDS

I want to know how it work

I have to start a app that communicate with vehicles using ELM327 adapters. I know nothing about it. I don't know how to start.

Do you have any turtorial about OBD programing?

Your library is very good, but I don't know what it means.

Like pidForMode1, pid or pidForFreezeFrameDTC.

If I want to program OBD by myself, I need to learn more about it.

Adapter State Flow

Just made a raw diagram about Adapter State Flow, hope it helps.
Please let me know if anything wrong.

adapter state flow

Adapter State Initializing

i am getting error "Unhandeld adapter state OBD2AdapterStateInitializing" after i am replace your services "[@[ @"FFF0", @"FFE0", @"BEEF" , @"E7810A71-73AE-499D-8C15-FAA9AEF0C3F2"]" with my own service "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxx" and also added check for verify own characteristics not getting any response

-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError )error
{
for ( CBCharacteristic
characteristic in service.characteristics )
{
if ([characteristic.UUID.UUIDString isEqualToString:@"xxxxxxxxxxxx-xxxxxxx-xxxxxx-xxxxxxxxxxxx"]) {
if ( characteristic.properties & CBCharacteristicPropertyRead )
{
LOG( @"Did see read characteristic" );
_reader = characteristic;

            [peripheral readValueForCharacteristic:characteristic];
            //[peripheral setNotifyValue:YES forCharacteristic:characteristic];
        }
        
        if ( characteristic.properties & CBCharacteristicPropertyWrite )
        {
            LOG( @"Did see write characteristic" );
            _writer = characteristic;
        }
    }
}

if ( _reader && _writer )
{
    [self connectionAttemptSucceeded];
}
else
{
    [self connectionAttemptFailed];
}

}

Disconnecting and Reconnecting to OBD2 adapter / Crash

I've been using this library to establish BLE communication between iOS device and a vehicle for a while now - it helps a lot. Now I am getting a crash from the library, trying to disconnect the LTBTLESerialTransporter object. The crash is in:

-(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
    LOG( @"Did disconnect %@: %@", peripheral, error );
    if ( peripheral == _adapter )
    {
        [_inputStream close];
        [_outputStream close];
    }
}

If there is established communication and the disconnect method is just called on the LTBTLESerialTransporter object (which is after that set to nil) there is no issue. But if the OBD2 adapter is disconnected from the vehicle and therefore the OBD2AdapterStateGone notification is received - on calling disconnect + setting the LTBTLESerialTransporter object to nil or just setting it to nil - the crash happens.
The error is EXC_BAD_ACCESS KERN_INVALID_ADDRESS and happens on -[LTBTLEWriteCharacteristicStream close] .
Is there more correct way to disconnect at this point - to avoid the crash and be able to reconnect after that? How is it intended to work?

Wrong conversion of DTC codes to ASCII

When DTCs are received (eg. as a result of a mode 03 request), they are converted from the native ELM327 format to SAE format, as defined in the ELM data sheet.

However, this conversion does not correctly convert received DTCs with hex characters.
The error lies in function -(NSString*)dtcCodeForA:(uint)A B:(uint)B, which tries to convert all received values back to ASCII numbers.

Example:
DTC = P2B4A is received via ELM327 as 2B4A, but the function returns the following:

[pid dtcCodeForA:0x2B B:0x4A] = "P2;4:"

; and : are A and B (ASCII hex lower nibble), respectively.

I'll provide a push request shortly - the received characters should be passed through as-is.

Transmitting DTCs using Swift

Hi,

I'm student from Czech Republic working right now on my thesis where I'm trying to use this library. Whole application is written in Swift with SwiftUI. Everything works fine but when I'm attempting to get DTCs whole communication fails. Here is the part of application that is causing the problems:

let dtcPids = [LTOBD2PID_STORED_DTC_03(),LTOBD2PID_PENDING_DTC_07(),LTOBD2PID_PERMANENT_DTC_0A()]
self._obd2Adapter?.transmitMultipleCommands(dtcPids, completionHandler: { _ in
self.dtcS = dtcPids[0].troubleCodes
self.dtcP = dtcPids[1].troubleCodes
self.dtcPer = dtcPids[2].troubleCodes
})

I was also watching Demo application but didn't find solution.

LTOBD2PID_FUEL_TANK_LEVEL_2F Command - Response "No data"

I have been using this library to get the speed of a car via Bluetooth (LTOBD2PID_VEHICLE_SPEED_0D) and it works great. Now I need to get the tank fuel - LTOBD2PID_FUEL_TANK_LEVEL_2F - but I get response: "No data". I tried with 2 different OBD2 dongles on 2 different cars and the result is the same. I am trying to get it the same way I get the speed. Should there be some difference? What can be wrong?
Edit: I checked also with the iOS demo project and the result there is also "No data" for Fuel tank level. Why could this happen? I noticed that also for some other PIDs the result is "No data".

Documentation refers to Swift-UDS which cannot be found on GitHub

Is there any plan to make Swift-UDS available? I would LOVE to try it out if so, I'm working on a hobby project using iPad Swift Playgrounds so I can only easily include Swift-based libraries and this would be huge. Just finished getting some BLE lithium batteries hooked up to my app, which was a lot of fun in itself ;)

Thank you!

Enhance demo program

The demo is a bit sparse. I should add at least a minimum of code to

  • Choose between a WiFi adapter and a Bluetooth adapter, and
  • Select a Bluetooth adapter

Expected behavior of BT in background

Hi @mickeyl, first off, thanks for helping to troubleshoot the other issue I had recently.

I was curious what the expected behavior is of BT when going into the background. I have this app using LTSupportAutomotive, that runs a web server in the background using the silent audio trick exposing OBD readings that are polled every 0.3s (we're just running it via Testflight, it doesn't need to pass app review).

Project: https://github.com/dennislysenko/OBD2Loxone

image

We have all these background modes selected. However when going to background, the web server keeps running for hours (indicating that the app is still awake, as intended), but the BT connection seems to go down.

Do you know what the expected behavior is of BLE under these conditions, when the app is running in the background (not getting killed)? I did a quick search for any UIApplicationDidEnterBackground etc. in the LTSupportAutomotive repo, and didn't find any reason to think the library would switch off BT connections when backgrounding.

How to Connect to ODB with USB? (help wanted)

Hello
I wanted to transform the ios code to mOS. So that there is also a simple example for mOS
I saw now that the application connects via Bluetooth. Is it also possible to connect via USB and how would it be done?

Bug in LTOBD2ProtocolISO15765_4

I think there is a bug in LTOBD2ProtocolISO15765_4 where it incorrectly applies the "Clunky workaround for mode 06 behavior".

I noticed that my app was showing weird decoded values for LTOBD2PID_SHORT_TERM_FUEL_TRIM_1_06 vs LTOBD2PID_SHORT_TERM_FUEL_TRIM_2_08. PID

I noticed that pid 0x08 works fine, but pid 0x06 was sometimes giving strange results. 06 is the magic pid number to trigger the bug.

I tracked it down to the section where the protocol applies "clunky workaround". This causes it to (in some cases) decode incorrect values.

i.e. given a command: 0106, response: 7E80341067C -> that should be a single 0x7C response value which should be dec 124.

However, this workaround code, causes the library to apply the "decrementing the numberOfBytesInCommand" which engages the 'originalCommandCorrective' modifier, which causes it to return two numbers [ 06, 124 ] in the payload.

This means when you are expecting a single byte for this command and take the first byte in the payload, ala 'decodeSingleByteDoubleValueWithOffset' then you'll decode the 06 and get the wrong value.

The workaround seems to be reading the sid and pid incorrectly. In response '7E80341067C' it thinks the sid=6 and the pid =7c, but actually the sid is 01 and the pid is 06. Perhaps there are too many +1's being applied to the headerLength in this function.

Not able to read all DTC if vehicle having multiple ECU

Hello @mickeyl , I am only able to get the Generic/ Manufacturer specific DTC code from the main ECU module, not getting any DTC code for ABS,TCM etc modules using this library.
is it Hardware(OBD dongle) issue that is not able to catchup all codes or something i am missing in this Library to get all DCT from multiple modules? even i am using all three modes.
LTOBD2PID_PERMANENT_DTC_0A
LTOBD2PID_PENDING_DTC_07
LTOBD2PID_STORED_DTC_03

Reference Module:
Engine Control Module (ECM) - This controls the actuators of the engine, affecting things like ignition timing, air to fuel ratios, and idle speeds.
Vehicle Control Module (VCM) - Another module name that controls the engine and vehicle performance.
Transmission Control Module (TCM) - This handles the transmission, including items like transmission fluid temperature, throttle position, and wheel speed.
Powertrain Control Module (PCM) - Typically, a combination of an ECM and a TCM. This controls your powertrain.
Electronic Brake Control Module (EBCM) - This controls and reads data from the anti-lock braking system (ABS).
Body Control Module (BCM) - The module that controls vehicle body features, such as power windows, power seats, etc.

Trouble codes parsing array index why start with 1

NSRange codeRange = NSMakeRange(1, bytes.count-1);
NSArray<NSNumber*>* codeBytes = [bytes subarrayWithRange:codeRange];

The returned result is different from other OBD apps.(Such as Auto Doctor、ELM327...)

If I change the index to 0,the result will be consistent.

How to connect with Wifi ELM327?

The demo I tried is only can connect with bluetooth mode.

When I connect to a Wifi ELM327 and get the ip address, open the app. Found that it is always in search status.

Allow optimized communication

Right now the parser requires to communicate in S1 mode, which is – albeit more readable – not as space efficient as possible. In particular when communicating with BTLE adapters, due to their inherently small bandwidths, every saved byte is a win.

It's not trivial to do this though since the current design relies on the space format to detect whether we have multi frames. Ideally we would feed the protocol a "normalized" form (no matter whether with or without spaces, we just have to decide on one) and take care about spaces or not on the parser level.

An added bonus would be to make the parser adaptive, i.e., to make it work with whatever input we feed, so that we would not have to configure to spaces-mode or non-spaces mode beforehand.

Implement CAN monitor mode / buffer dump

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.

Is it possible to get PID commands return data faster?

Hey there,

Is there any way I can get the PID command return data faster?

Im using the code exactly same as Demo project. It is very slow for each PID command finish. it maybe takes more than 200+ms to read one data. I guess we can do something for transmitMultipleCommands function to improve the speed of loading.

-(void)updateSensorData
{
    LTOBD2PID_ENGINE_RPM_0C* rpm = [LTOBD2PID_ENGINE_RPM_0C pidForMode1];
    LTOBD2PID_VEHICLE_SPEED_0D* speed = [LTOBD2PID_VEHICLE_SPEED_0D pidForMode1];
    LTOBD2PID_COOLANT_TEMP_05* temp = [LTOBD2PID_COOLANT_TEMP_05 pidForMode1];
    
    [_obd2Adapter transmitMultipleCommands:@[ rpm, speed, temp ] completionHandler:^(NSArray<LTOBD2Command *> * _Nonnull commands) {
    
        dispatch_async( dispatch_get_main_queue(), ^{

            self->_rpmLabel.text = rpm.formattedResponse;
            self->_speedLabel.text = speed.formattedResponse;
            self->_tempLabel.text = temp.formattedResponse;

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self updateSensorData];
            });

        } );
        
    }];
}

NSlog:

-[LTOBD2AdapterInternalCommand didCompleteResponse:protocol:protocolType:] (LTOBD2Adapter.m:58) <LTOBD2PID_COOLANT_TEMP_05:0x28382ca20 = '0105'> complete [226 ms] => '83F1114105804B'

Crash when adapter state changed

@mickeyl The libraray is working fine getting all the required data but sometime when adater state changed ,I am getting crash with odd logs .Whenever you have have time can you please check.Here the log which i am getting during crash -
Unhandeld adapter state OBD2AdapterStateReady

thread #53, queue = 'LTBTLESerialTransporter', stop reason = EXC_BAD_ACCESS (code=1, address=0x2ce66b20)
frame #0: 0x0000000198499880 libobjc.A.dylibobjc_retain + 16 libobjc.A.dylibobjc_retain:
-> 0x198499880 <+16>: ldrb w10, [x9, #0x20]
0x198499884 <+20>: tbz w10, #0x2, 0x1984998b4 ; <+68>
0x198499888 <+24>: tbz w8, #0x0, 0x1984998dc ; <+108>
0x19849988c <+28>: mov x9, #0x200000000000
Target 0: (Runner) stopped.

PIDs: Add support for compute-friendly API (NSUnit and NSNumber)

Right now, the main command class LTOBD2Command provides the formattedResponse call that returns an NSString for displaying the result of a command.

To allow more sophisticated processing of the returned value (like, putting values into a database, comparing different runs, drawing graphs, etc.), it would be beneficial to add API that returns the actual units and values of a command, e.g.:

+(NSUnit)unit;
-(NSNumber)value;

Subsequently, the implementation of formattedResponse would then be rewritten to utilize these functions leveraging a (customizable?) NSUnitFormatter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.