Welcome to the North American Subaru Impreza Owners Club Friday August 22, 2014
Home Forums WikiNASIOC Products Store Modifications Upgrade Garage
NASIOC
Here you can view your subscribed threads, work with private messages and edit your profile and preferences Home Registration is free! Visit the NASIOC Store NASIOC Rules Search Find other members Frequently Asked Questions Calendar Archive NASIOC Upgrade Garage Logout
Go Back   NASIOC > NASIOC Technical > Engine Management & Tuning > Open Source Reflashes

Welcome to NASIOC - The world's largest online community for Subaru enthusiasts!
Welcome to the NASIOC.com Subaru forum.

You are currently viewing our forum as a guest, which gives you limited access to view most discussions and access our other features. By joining our community, free of charge, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is free, fast and simple, so please join our community today!

If you have any problems with the registration process or your account login, please contact us.
* Registered users of the site do not see these ads.
Reply
 
Thread Tools Display Modes
Old 06-11-2009, 01:14 AM   #1
D0nets
Scooby Newbie
 
Member#: 129746
Join Date: Oct 2006
Location: West TN
Vehicle:
2007 stg3 WRX
WR Blue

Default Feeler: Android bluetooth logging app

I was looking around at some obd2 to bluetooth adapters.

http://www.easy-motorcycle.com/bluet...f8a41c86ed951d

That adapter supposedly works with all protocols including CAN. I was considering starting an open source logger for Android. Basically it would allow your android based cell phone (or other device) to read live ecu data for logging and digital gauges and such via bluetooth. I dont know that I would trust it for flashing the ecu but it could be a possibility, especially if we can figure out an infrastructure like COBB's where they flash a base map to rom and then other tables to ram. We could flash the basemaps to rom with a pc but possibly do live tuning via the android device.

Post here if you have any ideas or are interested. I would also like to see how many people might be interested in hopping on board for dev help, etc...

Ryan
* Registered users of the site do not see these ads.

Last edited by D0nets; 03-09-2010 at 10:51 AM.
D0nets is offline   Reply With Quote
Old 06-11-2009, 07:35 AM   #2
Tgui
Scooby Specialist
 
Member#: 44771
Join Date: Oct 2003
Default

I hope your SN doesn't imply ".Net"

There is a not so lively discussion on realtime tuning on RR that I tried to resurrect some time ago. I think we got to the bitching about how to implement it and arguing over the XML def extensions needed to support it. Your best bet would to pick it up over there.

http://www.romraider.com/forum/topic3881.html
Tgui is offline   Reply With Quote
Old 06-11-2009, 12:02 PM   #3
D0nets
Scooby Newbie
 
Member#: 129746
Join Date: Oct 2006
Location: West TN
Vehicle:
2007 stg3 WRX
WR Blue

Default

Well the ramtune addition would come later. As of now I really just want logging of learned data (learningview), and logging of live data. I dont mind whipping out the laptop to flash , but I get annoyed with having to whip it out to log and such.

Last edited by D0nets; 06-11-2009 at 12:21 PM.
D0nets is offline   Reply With Quote
Old 06-11-2009, 01:41 PM   #4
Tgui
Scooby Specialist
 
Member#: 44771
Join Date: Oct 2003
Default

Quote:
Originally Posted by D0nets View Post
Well the ramtune addition would come later. As of now I really just want logging of learned data (learningview), and logging of live data. I dont mind whipping out the laptop to flash , but I get annoyed with having to whip it out to log and such.
I have my own logger working to some extent written in Java. Its not all that hard.


Code:
package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
It looks and smells like Java. Their VM is proprietary and the bytecode generated is NOT compatible with Suns VM. Then you have Googles subset of typical Java classes supported.


Here is a little code to get you started. Of course the gnu.io package is NOT available for Android as I've read, they have their own RfcommSocket class to negotiate BlueTooth Comm access. Serial is serial though really. If you can tie in the analogous RfcommSocket methods to this code, you should get some meaningful data back. Hope this helps.
Code:
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import gnu.io.UnsupportedCommOperationException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.TooManyListenersException;

/**
 * Eric Morgan, AKA Tgui from SimpleTune.
 * Open Source, release changes to public as you make them!
 * Reference GPLv3 for full details.
 * This header must stay complete with this code.
 */
public class SSMQueryExampleRPM {

    // Data from ECU
    private static OutputStream outputECUStream;

    // Data to ECU
    private static InputStream inputFromECUStream;

    // Defines named comm port
    private static CommPortIdentifier commPortIdentifier;

    // Serial port being accessed
    private static SerialPort serialPort;

    // Define state of defined comm port, open or closed.
    private static boolean open = false;

    // Set to whatever is your comm port as printed out by the comm port listing method
    private static String commPortChoice = "/dev/tty.usbserial-TX45b7tf";
    
    // Pause between byte reads
    private static int BYTE_READ_PAUSE = 0;
    private static int INITIAL_PAUSE = 10;
    
    // Define comm port connection attributes
    private static int BAUD = 4800;
    private static int DATABITS = SerialPort.DATABITS_8;
    private static int STOPBITS = SerialPort.STOPBITS_1;
    private static int PARITY = SerialPort.PARITY_NONE;
    private static int FLOWCONTROL = SerialPort.FLOWCONTROL_NONE;
    private static boolean RTS = false;
    
    public static void main(String[] args){
          
    	// What ports are available?
    	printOutCommPortList();
    	
    	// Make our comm port selection based on the list printed out.
    	boolean success = bindCommPort(commPortChoice);
    	
    	// If comm port binding failed, exit.
    	if(!success){
    		System.out.println("Issues during execution, exiting.");
    		System.exit(0);
    	}
    	
    	// Open the serial port connection.
    	openConnection();
		
		// Build up command byte
		byte[] bytesToSend = new byte[13];
		bytesToSend[0] = (byte)0x80; // Every SSM command starts with this
		bytesToSend[1] = (byte)0x10; // Destination subaru ecu
		bytesToSend[2] = (byte)0xF0; // Source diagnostic tool
		bytesToSend[3] = (byte)0x08; // Size
		bytesToSend[4] = (byte)0xA8; // SSM command to send, read memory
		bytesToSend[5] = (byte)0x00; // Padding
		bytesToSend[6] = (byte)0x00; // Start First RPM tuple
		bytesToSend[7] = (byte)0x00;
		bytesToSend[8] = (byte)0x0E; // End First RPM tuple
		bytesToSend[9] = (byte)0x00; // Start Second tuple
		bytesToSend[10] = (byte)0x00;
		bytesToSend[11] = (byte)0x0F; // End Second RPM tuple
		
		// Build up checksum and print out (data <> running sum <> HEX rep)
		System.out.println("\n----------------------\nDATA BEING SENT TO ECU\n----------------------");
		long sumValue = 0;
		for(int i = 0; i < bytesToSend.length - 1; i++){
			sumValue += (int)bytesToSend[i]&0xFF;
			System.out.println("##### :"+(bytesToSend[i]&0xFF)+" <> "+sumValue + " <> " + Integer.toHexString((int)bytesToSend[i]&0xFF));
		}
		bytesToSend[12] = (byte)(sumValue&0xFF);
		System.out.println("##### :CKSUM <>"+((int)bytesToSend[12]&0xFF) + " <> " + Integer.toHexString((int)bytesToSend[12]&0xFF));
		
    	// Sleep a little to ensure the port is really ready.
		try {
			Thread.sleep(INITIAL_PAUSE);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// Finally send compiled ECU query
		
		try {
			sendECUCommand(bytesToSend);
			Thread.currentThread().sleep(60);
			
			//sendECUCommand(bytesToSend);
			//Thread.currentThread().sleep(60);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    public static void printOutCommPortList(){
    	Enumeration<CommPortIdentifier> en = CommPortIdentifier.getPortIdentifiers();
		if (!en.hasMoreElements()) {
			System.out.println("No Valid ports found, check Java installation");
			System.out.println("Exiting now.");
		}
			
		//Iterate through the ports
		while (en.hasMoreElements()) {
			CommPortIdentifier chosenCommPort = en.nextElement();
			System.out.println("Serial found on system :"+chosenCommPort.getName());
		}
    }
    
    public static boolean bindCommPort(String commPortName){
    	try {
			commPortIdentifier = CommPortIdentifier.getPortIdentifier(commPortName);
		} catch (NoSuchPortException e) {
			System.out.println("No port available by passed name :"+commPortName);
			return false;
		}
		
		return true;
    }

    public static void sendECUCommand(byte[] charValue) {

        if (serialPort == null) {
            System.err.println("No Port Selected, therefore no interraction with ECU happening.");
            return;
        }

        try {
            outputECUStream.write(charValue);

            System.out.println("Sending query to the ECU:" + charValue);
        } catch (IOException e) {
            System.err.println("Can't send char command to ECU: " + charValue);
            e.getMessage();
        }
    }

    public static void openConnection() {
        System.out.println("Opening connection now.");
        
        // Set the parameters of the connection.
   		try {
			serialPort = (SerialPort) commPortIdentifier.open("SSM_DEMO", 2000);
			serialPort.disableReceiveTimeout();
			serialPort.setRTS(RTS);
			serialPort.setFlowControlMode(FLOWCONTROL);
			serialPort.setSerialPortParams(BAUD, DATABITS, STOPBITS, PARITY);
		} catch (PortInUseException e) {
			e.printStackTrace();
		} catch (UnsupportedCommOperationException e) {
			e.printStackTrace();
		}

        // Open the input and output streams for the connection. If they won't
        // open, close the port before throwing an exception.
        try {
            outputECUStream = serialPort.getOutputStream();
            inputFromECUStream = serialPort.getInputStream();
        } catch (IOException e) {
            System.err.println("Error opening IO streams");
            serialPort.close();
        }

        // Add this object as an event listener for the serial port.
        try {
            serialPort.addEventListener(new ECUDataListener(inputFromECUStream));

        } catch (TooManyListenersException e) {
            System.err.println("Too Many listeners");
            serialPort.close();
        }

        // Set notifyOnDataAvailable to true to allow event driven input.
        serialPort.notifyOnDataAvailable(true);

        // Set notifyOnBreakInterrup to allow event driven break handling.
        serialPort.notifyOnBreakInterrupt(true);

        // Set receive timeout to allow breaking out of polling loop during
        // input handling.
        try {
            serialPort.enableReceiveTimeout(30);
        } catch (UnsupportedCommOperationException e) {
            System.err.println("Time Out");
        }

        open = true;
        System.out.println("Port opened with success.");
    }

    public static void closeConnection() {
        // If port is already closed just return.
        if (!open) {
            System.err.println("Attempting to close an already closed port.");
            return;
        }
        System.out.println("Closing connection to the currently targeted port");

        // Check to make sure sPort has reference to avoid a NPE.
        if (serialPort != null) {
            try {
                // close the i/o streams.
                outputECUStream.close();
                inputFromECUStream.close();
            } catch (IOException e) {
                System.err.println(e);
            }

            // Close the port.
            serialPort.close();
        }

        open = false;
    }
    

    /**
     * Private class to listen for responses from the ECU.
     * 
     * @author emorgan
     *
     */
    private static class ECUDataListener  implements SerialPortEventListener{
    	
    	private LinkedList<Byte> commands = new LinkedList<Byte>();
    	private InputStream in = null;
    	
    	// Pass in the input stream used to get data from the ECU
    	public ECUDataListener(InputStream in){
    		this.in = in;
    	}
    	
    	/**
    	 * Part of the SerialPortEventListener set of methods.
    	 */
    	public void serialEvent(SerialPortEvent e) {
    		System.out.println("Got Data, Event type :"+e.getEventType());
    		System.out.println("Wanted data tpye :"+SerialPortEvent.DATA_AVAILABLE);
    		
    		int newData = 1;
    		
    		switch (e.getEventType()) {
    		case SerialPortEvent.DATA_AVAILABLE:
    			while (newData != -1) {
    				// Pause between pulls, yes dirty
    				try {
						Thread.currentThread().sleep(BYTE_READ_PAUSE);
					} catch (InterruptedException e1) {
						e1.printStackTrace();
					}
    				
    				// You can read a block of bytes if needed, this implementation 
					// reads a byte one at a time from the inputstream
    				try {
    					
    					newData = in.read();
    					
    					if(newData != -1){
    						commands.add((byte)newData);
    					}
    					
    				} catch (IOException ex) {
    					System.err.println(ex);
    					return;
    				}
    				
    			}
    			
    			
    			System.out.println("\n----------------------\nDATA RECEIVED FROM ECU\n----------------------");
    			Iterator<Byte> iterator = commands.iterator();
    			System.out.println("Printing out this many bytes :"+commands.size());
    			while(iterator.hasNext()){
    				Byte next = iterator.next();
    				System.out.println("--->"+((int)next&0xFF)+" <> "+Integer.toHexString((int)next&0xFF));
    			}
    		
    			// Extract the RPM data
    			byte firstByte = commands.get(commands.size() - 3);
    			byte secondByte = commands.get(commands.size() - 2);
    			
    			System.out.println("First Byte :"+Integer.toHexString((int)firstByte&0xFF));
    			System.out.println("Second Byte :"+Integer.toHexString((int)secondByte&0xFF));
    			
    			
    			// Combine 2 result bytes into a short value
    			ByteBuffer bb = ByteBuffer.allocate(2);
    			byte[] bytes = new byte[2];
    			bytes[0] = firstByte;
    			bytes[1] = secondByte;
    			bb.put(bytes);
    			short rpmShort = bb.getShort(0);
    			System.out.println("Raw short value :"+ rpmShort);
    			System.out.println("\n\nRPM VALUE FOUND:"+rpmShort/4);
    			
    			// Clean up now
    			SSMQueryExampleRPM.closeConnection();
    		}

    	}
    }
}
Tgui is offline   Reply With Quote
Old 06-11-2009, 02:07 PM   #5
Tgui
Scooby Specialist
 
Member#: 44771
Join Date: Oct 2003
Default

Also, look here for other hardware.

http://devtoaster.com/products/rev/index.html
Tgui is offline   Reply With Quote
Old 06-11-2009, 04:39 PM   #6
573
Scooby Specialist
 
Member#: 144821
Join Date: Mar 2007
Chapter/Region: MWSOC
Location: Troy, Michigan
Vehicle:
1994 LS1 Miata
2015 white WRX

Default

This sounds like a good idea. I have the Tactrix 2.0 cable, but I'm still waiting on the log to SD card support. Once that becomes available, I probably wouldn't use this for logging, but it would still be cool to have the ability to display info on my phone.
573 is offline   Reply With Quote
Old 06-15-2009, 01:22 AM   #7
D0nets
Scooby Newbie
 
Member#: 129746
Join Date: Oct 2006
Location: West TN
Vehicle:
2007 stg3 WRX
WR Blue

Default

Well... bad news. I spoke with San Mehat at google. (He worked on the volume daemon and the wirless manager for android). He has informed me that there is not a bluetooth API yet I will keep you guys posted.

Last edited by D0nets; 09-14-2009 at 11:16 PM.
D0nets is offline   Reply With Quote
Old 06-15-2009, 01:32 AM   #8
D0nets
Scooby Newbie
 
Member#: 129746
Join Date: Oct 2006
Location: West TN
Vehicle:
2007 stg3 WRX
WR Blue

Default

http://www.obdkey.com/obd_orders.asp

The wifi one could work but I dont think it is worth the $200+.
D0nets is offline   Reply With Quote
Old 06-21-2009, 11:28 AM   #9
bfidalgo
Scooby Newbie
 
Member#: 138002
Join Date: Jan 2007
Chapter/Region: South East
Location: Long Beach
Vehicle:
2009 Legacy
Ruby Red Pearl

Default

this would be amazing! the power of android!!! i love open source. it is gonna revolutionize the world! id definitely pay for this!
bfidalgo is offline   Reply With Quote
Old 09-14-2009, 11:28 PM   #10
D0nets
Scooby Newbie
 
Member#: 129746
Join Date: Oct 2006
Location: West TN
Vehicle:
2007 stg3 WRX
WR Blue

Default

Quote:
Originally Posted by bfidalgo View Post
this would be amazing! the power of android!!! i love open source. it is gonna revolutionize the world! id definitely pay for this!

This is true... Android is picking up steam rather rapidly. I think once there are more android devices on more carriers, dev. momentum will also pickup. Anyone interested in helping with this logger project once the bluetooth API is avail?

Tgui: Thanks lots for that code. I am sure it will come in handy.
D0nets is offline   Reply With Quote
Old 09-15-2009, 02:55 AM   #11
D0nets
Scooby Newbie
 
Member#: 129746
Join Date: Oct 2006
Location: West TN
Vehicle:
2007 stg3 WRX
WR Blue

Default

Update: (unofficial) Bluetooth API v. 0.2

http://groups.google.com/group/andro...1d4fc?lnk=raot
D0nets is offline   Reply With Quote
Old 10-22-2010, 08:52 AM   #12
HTM WRX
Scooby Newbie
 
Member#: 44463
Join Date: Sep 2003
Chapter/Region: South East
Location: Spartanburg, SC
Vehicle:
2007 Impreza STi
World Rally Blue

Default

I found this thread from a google search and thought I'd bring it back for an update: There is a program in the market place called torque that will pretty much do this with a Bluetooth OBD2 tool.

Just thought I'd share. I didn't search to see if there was more info.
HTM WRX is offline   Reply With Quote
Old 10-22-2010, 09:23 AM   #13
Chevarian113
Scooby Specialist
 
Member#: 148415
Join Date: May 2007
Chapter/Region: MAIC
Location: Cardboard box
Vehicle:
1991 MR2 turbo
05 Outback XT

Default

I've been researching much of this information, and as someone posted above, Devtoaster.com is a good website to look into. It is a program called Rev. I work on iPhone, so not sure if it is available for Android or not, but worth looking into.

Also, from my research, Kiwi wifi seems to be the way to go on hardware. Apparently there is a bluetooth option as well. A quick search on google will bring up ways to purchase one.
Chevarian113 is offline   Reply With Quote
Old 12-31-2010, 02:14 PM   #14
cprincipe
Scooby Newbie
 
Member#: 201222
Join Date: Jan 2009
Chapter/Region: NESIC
Location: Nashua, NH
Vehicle:
2007 Impreza 2.5i
Grey

Default

Hope you guys don't mind me bumping this thread. Anyone had any luck with the Kiwi Bluetooth device?

http://www.plxkiwi.com/kiwibluetooth/

I'm mainly thinking of getting it for an ODBII scanner, although that's probably not the cheapest solution out there.
cprincipe is offline   Reply With Quote
Old 07-05-2013, 10:30 PM   #15
dcormier
Scooby Newbie
 
Member#: 336380
Join Date: Oct 2012
Vehicle:
2013 WRX 5-door
SWP

Default

In case anyone else find this thread in the future, Android has a Bluetooth API now. However, there's currently a hiccup in being able to connect to some serial Bluetooth devices (like the cheap OBDII Bluetooth devices). They seems to have been introduced when they changed Android's Bluetooth stack recently. I suspect it will be fixed in the next update (not sure if I should qualify that with minor or major, but I think it'll be very soon).
dcormier is offline   Reply With Quote
Old 07-06-2013, 11:19 AM   #16
mechatricity
Scooby Specialist
 
Member#: 290592
Join Date: Aug 2011
Chapter/Region: South East
Location: Charlotte, NC
Vehicle:
04 & 06 WRX Wagons
'15 WRX 6MT CWP ordered

Default

Can someone explain how this is different that what we do with Torque today? Would it allow logging/reading of custom PIDs with autodection similar to RomRaider? You can add PIDs in Torque but it's not user friendly.
mechatricity is offline   Reply With Quote
Old 07-06-2013, 12:25 PM   #17
SharpTuning
Scooby Newbie
 
Member#: 333363
Join Date: Sep 2012
Location: Cutting Edge, Delaware Valley
Default

I'm not familiar with torque, but it appears to be OBD only. A custom app would be able to use SSM to log more parameters (like RR) faster (also like RR). However, iirc there is a hardware limitation with the ELM bluetooth chips that breaks SSM packets.
SharpTuning is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FS : Pioneer AVIC D3 nav w/ Bluetooth and iPod cable DrnknZag Interior/Dressup/Audio & Security 25 08-22-2010 07:51 PM
Feeler: 06' STi BBS's with Bridgestone Potenza RE960's black_knight06 NWIC Private Classifieds 2 06-06-2010 08:20 PM
OpenECU timing problem check out logs vwjettavr67 Open Source Reflashes 7 06-05-2010 08:27 PM
QIK app for iphone and android = :banana: -=C=- Off-Topic 8 02-24-2010 09:58 AM


All times are GMT -4. The time now is 07:40 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Powered by Searchlight © 2014 Axivo Inc.
Copyright ©1999 - 2014, North American Subaru Impreza Owners Club, Inc.