Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions build.gradle

This file was deleted.

54 changes: 54 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
kotlin("multiplatform") version "1.9.10"
id("com.android.library")
}

group = "com.github.reline"
version = "0.0.1-SNAPSHOT"
description = "OBD Kotlin-Multiplatform API"

kotlin {
targetHierarchy.default()

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}

// todo: configure for iOS

sourceSets {
val commonMain by getting {
dependencies {
api("com.squareup.okio:okio:3.5.0")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidUnitTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation(kotlin("test-testng"))
implementation("org.testng:testng:6.8.13")
implementation("org.easymock:easymock:3.3")
implementation("org.powermock:powermock-module-testng:1.6.0")
implementation("org.powermock:powermock-api-easymock:1.6.0")
}
}
}
}

android {
namespace = "com.github.reline.obd"
compileSdk = 33
defaultConfig {
minSdk = 24
}
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kotlin.code.style=official
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.mpp.stability.nowarn=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Wed Sep 23 18:12:03 MST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
1 change: 0 additions & 1 deletion settings.gradle

This file was deleted.

16 changes: 16 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
}

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}

rootProject.name = "obd-api"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package com.github.pires.obd.commands;

import com.github.pires.obd.commands.fuel.FuelTrimCommand;
import com.github.pires.obd.enums.FuelTrim;
import com.github.reline.obd.FuelTrim;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package com.github.pires.obd.commands;

import com.github.pires.obd.commands.control.PendingTroubleCodesCommand;
import com.github.pires.obd.exceptions.NoDataException;
import com.github.reline.obd.NoDataException;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package com.github.pires.obd.commands;

import com.github.pires.obd.commands.control.PermanentTroubleCodesCommand;
import com.github.pires.obd.exceptions.NoDataException;
import com.github.reline.obd.NoDataException;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package com.github.pires.obd.commands;

import com.github.pires.obd.commands.control.TroubleCodesCommand;
import com.github.pires.obd.exceptions.NoDataException;
import com.github.reline.obd.NoDataException;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.pires.obd.commands.protocol

import org.testng.Assert.assertEquals
import org.testng.annotations.Test
import kotlin.test.*

class TimeoutCommandTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package com.github.pires.obd.utils;

import com.github.pires.obd.commands.engine.ThrottlePositionCommand;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -39,7 +38,7 @@ public void testDigestAvailabilityString() throws Exception {
public void testIsAvailable() throws Exception {
Assert.assertEquals(CommandAvailabilityHelper.INSTANCE.isAvailable("02", "BE1FA813"), false);
Assert.assertEquals(CommandAvailabilityHelper.INSTANCE.isAvailable("07", "BE1FA813"), true);
Assert.assertEquals(CommandAvailabilityHelper.INSTANCE.isAvailable(new ThrottlePositionCommand().getCommandPID() /*11*/, "BE1FA813"), true);
Assert.assertEquals(CommandAvailabilityHelper.INSTANCE.isAvailable("11", "BE1FA813"), true);
Assert.assertEquals(CommandAvailabilityHelper.INSTANCE.isAvailable("1A", "BE1FA813"), false);
Assert.assertEquals(CommandAvailabilityHelper.INSTANCE.isAvailable("1D", "BE1FA813"), false);
Assert.assertEquals(CommandAvailabilityHelper.INSTANCE.isAvailable("1F", "BE1FA813"), true);
Expand Down
31 changes: 31 additions & 0 deletions src/androidUnitTest/kotlin/com/github/reline/obd/JavaTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.reline.obd;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

import okio.Buffer;

import static org.testng.Assert.assertEquals;

public class JavaTest {

private Buffer output;
private Buffer input;
private ObdSocket socket;

@BeforeMethod
public void setup() {
output = new Buffer();
input = new Buffer();
socket = new ObdSocket(output, input);
}

@Ignore
@Test
public void test() {
input.writeUtf8("41 11 95>");
// fixme
// assertEquals(58.431374f, Obd.getThrottlePosition(socket));
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
*/
package com.github.pires.obd.commands

import com.github.pires.obd.InputStream
import com.github.pires.obd.OutputStream
import com.github.pires.obd.exceptions.*
import com.github.reline.obd.NonNumericResponseException
import com.github.reline.obd.ResponseException
import okio.ByteString.Companion.encodeUtf8
import okio.IOException
import okio.Source
import okio.Sink
import okio.buffer

/**
* Base OBD command.
Expand Down Expand Up @@ -56,12 +60,12 @@ abstract class ObdCommand(protected val cmd: String) {
*
* This method CAN be overriden in fake commands.
*
* @param in a [InputStream] object.
* @param out a [OutputStream] object.
* @param in a [Source] object.
* @param out a [Sink] object.
* @throws IOException if any.
*/
@Throws(IOException::class)
open fun run(`in`: InputStream, out: OutputStream) {
open fun run(`in`: Source, out: Sink) {
sendCommand(out)
readResult(`in`)
}
Expand All @@ -73,26 +77,26 @@ abstract class ObdCommand(protected val cmd: String) {
* This method may be overriden in subclasses, such as ObMultiCommand or
* TroubleCodesCommand.
*
* @param out The output stream.
* @param out The output sink.
* @throws IOException if any.
*/
@Throws(IOException::class)
protected fun sendCommand(out: OutputStream) {
// write to OutputStream (i.e.: a BluetoothSocket) with an added
protected fun sendCommand(out: Sink) {
// write to sink (i.e.: a BluetoothSocket) with an added
// Carriage return
out.write((cmd + "\r").toByteArray())
out.buffer().write((cmd + "\r").encodeUtf8())
out.flush()
}

/**
* Resends this command.
*
* @param out a [OutputStream] object.
* @param out a [Sink] object.
* @throws IOException if any.
*/
@Throws(IOException::class)
protected fun resendCommand(out: OutputStream) {
out.write("\r".toByteArray())
protected fun resendCommand(out: Sink) {
out.buffer().write("\r".encodeUtf8())
out.flush()
}

Expand All @@ -102,11 +106,11 @@ abstract class ObdCommand(protected val cmd: String) {
*
* This method may be overriden in subclasses, such as ObdMultiCommand.
*
* @param in a [InputStream] object.
* @param in a [Source] object.
* @throws IOException if any.
*/
@Throws(IOException::class)
open fun readResult(`in`: InputStream) {
open fun readResult(`in`: Source) {
readRawData(`in`)
checkForErrors()
fillBuffer()
Expand Down Expand Up @@ -147,16 +151,16 @@ abstract class ObdCommand(protected val cmd: String) {
/**
* readRawData.
*
* @param in a [InputStream] object.
* @param in a [Source] object.
* @throws IOException if any.
*/
@Throws(IOException::class)
protected open fun readRawData(`in`: InputStream) {
protected open fun readRawData(`in`: Source) {
val res = StringBuilder()
// read until '>' arrives OR end of stream reached
// read until '>' arrives OR end reached
while (true) {
val b = `in`.read().toByte()
// -1 if the end of the stream is reached
val b = `in`.buffer().readByte()
// -1 if the end is reached
if (b < 0) {
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/
package com.github.pires.obd.commands

import com.github.pires.obd.InputStream
import com.github.pires.obd.OutputStream
import com.github.pires.obd.exceptions.IOException
import okio.IOException
import okio.Sink
import okio.Source

/**
* Container for multiple [com.github.pires.obd.commands.ObdMultiCommand] instances.
Expand Down Expand Up @@ -44,12 +44,12 @@ class ObdMultiCommand {
/**
* Iterate all commands, send them and read response.
*
* @param in a [InputStream] object.
* @param out a [OutputStream] object.
* @param in input
* @param out output
* @throws IOException if any.
*/
@Throws(IOException::class)
fun sendCommands(`in`: InputStream, out: OutputStream) {
fun sendCommands(`in`: Source, out: Sink) {
for (command in commands) command.run(`in`, out)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class PercentageObdCommand(command: String) : ObdCommand(command) {

/** {@inheritDoc} */
override val formattedResult: String get() {
return String.format("%.1f%s", percentage, resultUnit)
return "$percentage$resultUnit"
}

override val resultUnit: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package com.github.pires.obd.commands.control

import com.github.pires.obd.commands.PercentageObdCommand
import com.github.pires.obd.enums.AvailableCommandNames
import com.github.reline.obd.AvailableCommandNames

/**
* Fuel systems that use conventional oxygen sensor display the commanded open
Expand Down
Loading