pires / android-obd-reader

Android OBD-II Reader application that uses pure OBD-II PID's Java API.
Apache License 2.0
807 stars 467 forks source link

Divide by zero #53

Closed Hesamedin closed 9 years ago

Hesamedin commented 9 years ago

Hi man,

I did a lot of changes to the code in order to update it with most recent libs and Android APIs. Will send you PR once I get all things done.

Meanwhile, I found a "divide by zero" exception. Although, it is being caught by IOException, I guess better way is to prevent divide operation is done. Please have a look at "FuelEconomyObdCommand.java" line 58.

`// get l/100km

kml = (100 / speedCommand.getMetricSpeed())
    * fuelConsumptionCommand.getLitersPerHour();`

Thanks

pires commented 9 years ago

Can you fix it and provide a PR for obd-java-api? Will be glad to merge. Thanks

Hesamedin commented 9 years ago

Suer. My Pleaser. Will send you tomorrow. I didn't know there is another lib like this :)

pires commented 9 years ago

@Hesamedin obd-java-apiis the actual OBD implementation. This project is just an Android app that usesobd-java-api`` for OBD operations.

I'll close this when your PR gets in.

nomwerp commented 9 years ago

on a more technical note , how should we handle this? of course any time speed is zero or very low you'll get a very high (or infinite) fuel economy. easy enough to put in a if statement for zero or low speed but what to return in that case? my car will display "--.-" at low speed. is there any more high level code that expect it always returns a number or can we safely return a string?

Paulo Pires notifications@github.com wrote:

@Hesamedin obd-java-apiis the actual OBD implementation. This project is just an Android app that usesobd-java-api`` for OBD operations.

I'll close this when your PR gets in.

— Reply to this email directly or view it on GitHub.

pires commented 9 years ago

To be honest, just now I realized the command we're talking here. Fuel related commands usually don't work. Manufacturers don't implement the standard and charge for proprietary commands access. This class and others related should disappear.