pires / obd-java-api

OBD-II Java API
Apache License 2.0
594 stars 294 forks source link

Error parsing answer #16

Closed sdubakov closed 9 years ago

sdubakov commented 10 years ago

Looks like i have some problem with my Citroen C5 2013 + ELM 327

After sending to ELM "01 0D" to know speed,

I Have Answer "7E8 03 41 0D 00" where 00 - last byte - is actually Speed.

But your code reads all digits without spaces "7E803410D00" and then parses it as "7E 80 34 10 D0 ". And then your code returns 34 as Speed - 52 km/h - byte № 3.

But, according specification, it should to do it another way:

After sending any command, we can actually know where the proper data will be.

For example: After sending "01 0D" answer signature always will be 4000 | 010D=410D and then 1-2 or more bytes depending on specification of command.

Rule is: -> 0X XX <- trash_trash.. 4X XX DATA ..trash_trash

or it can be -> 0X XX <- some_trash <- trash_trash.. 4X XX DATA ..trash_trash <- some_trash

The real answer always returns the command, that we send before with LOGICAL OR 40 00h

Maybe this information will be helpful for you.

All specification on elmelectronics com page obdic.htm

pires commented 9 years ago

What you say is correct, but then again, what is "trash data", or in this case 7E 80? Where does it come from?

According to spec, 0x == request, 4x followed by specified number of bytes == response. So that's what I do, I skip the first two bytes and read the specified bytes that compose the value. There shouldn't be any trash data.

Anyway, I guess I can ignore all bytes until 4x arrives.

sdubakov commented 9 years ago

What you say is correct, but then again, what is "trash data", or in this case 7E 80?

answer is here: http://www.elmelectronics.com/DSheets/ELM327DS.pdf

page № 41

nomwerp commented 9 years ago

interesting , I also have a Citroen C5 2013 + ELM 327 but get correct speed using android-obd-reader

pires commented 9 years ago

@nomwerp one of the most difficult things with OBD is actually the ELM327 devices that are commonly of dubious quality. And even firmware versions of same device differs a lot in behavior.

But before closing this..

According to spec, 0x == request, 4x followed by specified number of bytes == response. So that's what I do, I skip the first two bytes and read the specified bytes that compose the value. There shouldn't be any trash data.

nomwerp commented 9 years ago

could also be due to difference in protocol used ? i'm using 'auto' whatever that actually is

pires commented 9 years ago

@nomwerp I always use auto as well but it shouldn't be the case.

@sdubakov can you tell us the firmware version of your ELM327 device?

Abushawish commented 8 years ago

I'm very lost on how to implement this fix? I'm having the same issue as OP.