OBD packet analyzer

Post by: on August 23rd, 2011 | File Under Uncategorized

The following is an OBD broadcast packet analyzer script written in perl

Using the script

cat scrollback-testing123.txt | analyzedump.pl |less

Sample output

CHANGE: KEY: 10 0D 00 40 OLD=02 00 NEW=00 00 SEEN=26 CHANGES=18 PERMINUTE=42 TRIP=0
 CHANGE: KEY: 10 0D 00 40 OLD=00 00 NEW=02 00 SEEN=27 CHANGES=19 PERMINUTE=42 TRIP=0
 CHANGE: KEY: 10 0D 00 40 OLD=02 00 NEW=00 00 SEEN=28 CHANGES=20 PERMINUTE=42 TRIP=0
 TIME: Fri Mar 12 19:16:08 EST 2010 UNIX=1268439368 Messages/Second=157

The script

 

#! /usr/bin/perl

#
# This simple Perl script can be used to analyze the data captured from a HSCAN network using ATMA with ATH1 (headers present).
#
# To Use this script, use a command line such as the following:
# $ cat screenlog-obdlink-monitoring-HSCAN-bus.txt | ./analyzedump.pl | less
#
# 

# Dependencies:
# parsedate - used to parse a date string into a unix epoch timestamp thingie.
#   # perl -MCPAN -e 'install Time::ParseDate'
#
use Time::ParseDate;

# A hashmap where we'll store the Parameter + Data values for each parameter that we see.
my %vals = ();

# a hashmap to store when each PID is last seen.
my %lastseen = ();

# how many data bytes does the key include? most PIDs are probably 0 but some have more.
my %pidkeylen = ();

# will store the number of changes the given PID has changed
my %changecount = ();
# tracks rate of changes for a PID.
my %changerate  = ();

# will store the number of times the given PID has been seen regardless of whether the data is changed or not.
my %seencount = ();

# current timestamp as seen by timestamps in the file.
my $currentTime = 0;
my $currentTimeStamp = 0;
my $startTime = 0;

my $lastTime = 0;
my $messageCount = 0;

# trip number. Incremented any time we see two date stamps next to eachother (suggesting no data for at least 60 seconds).
my $currentTripNum = 0;

# populate the pid key lengths hash.
loadPIDKeylens();

# a function for resetting things. Such as when we start a new trip#.
sub resetHashes () {
	$messageCount = 0;

	%seencount = ();
	%changerate = ();
	%changecount = ();
	%vals = ();
	%lastseen = ();
}

# start main loop here:
while (<>) {
	# print "line=$_";
	# Remove junk. 

	s/.DATA ERROR//g;

	# drop crapp like carriage returns.
	s/\r//g;

	# Remove date stamps such as:
	# Sat Apr 17 15:29:01 EDT 2010
	# Fri Mar 12 18:29:02 EST 2010

	## check for timestamp. Grab it including its LF.
	if (s/([A-Z][a-z][a-z] .+E.T 2010\n)//g or s/([A-Z][a-z][a-z] .+E.T 1999\n)//g) {
		$currentTimeStamp = $1;

		# remove the LF from the timestamp string.
		$currentTimeStamp =~ s/\n//g;

		# Get the unix epoch representation of that datetime.
		$lastTime = $currentTime;
		$currentTime = parsedate ($currentTimeStamp);

		# first time seeing a timestamp? Log it.
		if ($startTime == 0) {
			$startTime = $currentTime;
		}

		# print it.
		# prevent division by zero.
		if ($currentTime - $lastTime == 0) {
			next;
		}
		my $messageRate = ($messageCount - $lastMessageCount) / ($currentTime - $lastTime);
		$messageRate = int($messageRate);
		print "TIME: $currentTimeStamp UNIX=$currentTime Messages/Second=$messageRate\n";
		$lastMessageCount = $messageCount;

		# If the last line read was also a date stamp then we encountered two date stamps next to eachother, so kick up the trip number.
		if ($lastLine =~ /DT.+2010/) {
			$currentTripNum++;

			# reset hashes for the new trip.
			resetHashes();
		}
		$lastLine=$currentTimeStamp;
		next;
	}

	my $LINE=$_;
	$lastLine=$LINE;
	$messageCount++;

	# if the line contains the necessary stuff, split it out. Otherwise skip it with a next;
	if ($LINE =~ m/^(\w\w\w)\W(.+)\W?$/) {

		# pass the new data to the newData() function - args: PID, DATA.
		newData ($1, $2);

		if (length($ADDR) != 3) {
			next;
		}

	}

	# 29-bit sniffing hack.
	if ($LINE =~ m/^(\w\w \w\w \w\w \w\w)\W(.+)\W?$/) {
		newData ($1, $2);
		if (length($ADDR) != 11) {
			next;
		}
	}

	# Place the Address/Data into the hashmap using a subroutine.
	# If the data has changed, print the old and the new top/bottom.
	# Also print 

}

sub loadPIDKeylens () {
	$pidkeylen{"199"} = 1;
	$pidkeylen{"0C1"} = 1;

	# This is wrong but for now it will do.
	# $pidkeylen{"0C5"} = 5;

	$pidkeylen{"0F1"} = 1;

	$pidkeylen{"0C9"} = 1;
}

# This sub gets called for every message - keep it optimized!
sub newData () {

	my $PID=shift;
	my $DATA=shift;
	my @DATAARRAY=split(/ /,$DATA);

	my $KEY=$PID . "-";
	if ($pidkeylen{$PID} > 0) {
		# Get pidkeylen{$PID} bytes of data, drop spaces, and append to $key.
		for ($i=0;$i0) {
			$DATA = $DATA . shift(@DATAARRAY) . " ";
		}
	}

	$KEY =~ s/(.+)-$/\1/g;
	$DATA =~ s/(.+) $/\1/g;

	$seencount{$KEY}++;

	# Is this a new PID?
	if (! exists $vals{$KEY}) {
		print "NEW: KEY: $KEY OLD=$vals{$KEY} NEW=$DATA TRIP=$currentTripNum\n";
		$vals {$KEY} = $DATA;
		$lastseen {$KEY} = $currentTime;
		$changerate{$KEY} = 1;
		return;
	}

	# When was it last seen?
	if ($lastseen{$KEY} == $currentTime) {
		$messagesThisInterval++;
		$changeRate = 0;
	} else {
		$changeRate = (60 * $changecount{$KEY}) / ($currentTime - $lastseen{$KEY});
		$changeRate = int($changeRate);
		if ($changeRate > 0) {
			$changerate{$KEY} = $changeRate;
			# Reset the change count since we hit a new timestamp
			$changecount{$KEY} = 0;
		}
		$messagesThisInterval = 0;
	}

	# Not a new PID so is the data the same or new?
	if ($vals{$KEY} =~ /$DATA/) {
		$vals {$KEY} = $DATA;
		$lastseen {$KEY} = $currentTime;
		return;
	} else {
		# yup, the data changed. increment counters, print it.
		$changecount{$KEY}++;
		print "CHANGE: KEY: $KEY OLD=$vals{$KEY} NEW=$DATA SEEN=$seencount{$KEY} CHANGES=$changecount{$KEY} PERMINUTE=$changerate{$KEY} TRIP=$currentTripNum\n";
		$vals {$KEY} = $DATA;
		$lastseen {$KEY} = $currentTime;
		return;
	}
}

# Dump all in-memory data to the screen as a final summary.
dumpAllHashData();

# Dump to the screen a full list of all data stored in hashmaps.
sub dumpAllHashData() {
	print "################# SUMMARY ####################";
	# Dump data starts at _ and ends at _ total duration _

	# for example, these columns:
	# pidKeyLen, PID/KEY, numchanges, nummessages, changerate, last data
	print "################# END OF SUMMARY ####################";
}
Comments (No responses yet)

SVIP

Post by: on August 4th, 2011 | File Under News

I’m working on SVIP right now. It stands for Simple Vehicle (Voyager) Interface Protocol. I’ll incorporate it into VoyagerConnect first, then over to other apps like VoyagerRC. The biggest benefit is that the app that the user sees will have no delay or long pauses or any unresponsiveness. Just a clean, fast interface that calls the shots in the background by way of SVIP to the VoyagerConnect service.

We’re also designing multimedia artwork and hopefully soon, a video, to get VoyagerRC onto the market. It’s not as quick to publish an app with all of the image and marketing requirements on the Android Market. It’s not a bad thing though :)

Comments (No responses yet)

Writers Block

Post by: on June 16th, 2011 | File Under News

I have a bit of Writers block lately. After committing 623 lines of code in support of the new “SVIP” protocol (described here), I have reached a bit of a creativity lull.

 

Question: What features would you like to see next, in Voyager?

 

Another question for you – should I spend some time making diagrams to describe the code? I realize it can be difficult to get started with a new project if the only documentation is in the code…

Comments (No responses yet)

Needed: Prius Testers!

Post by: on June 7th, 2011 | File Under Uncategorized

Looking for anybody with a Prius that can try out a few of our open source Apps. I’ve plugged into every car I can but I haven’t had a chance to try out a prius yet. Contact us for details! @gmail.com gtosoft

Comments (No responses yet)

“I’m surprised you published the project open source!”

Post by: on May 3rd, 2011 | File Under News, Releases

 

“I’m surprised you published the project open source!”

 

Yeah I even surprised myself by the decision ;-) The truth is, I can’t write code fast enough to keep up with technology. Not only that, but the synergy that is to be gained by having multiple contributors, all working simultaneously, is huge. As soon as I published the project, I felt like a burden had been lifted from my shoulders. Strange, huh?

 


So as far as mailing lists go, we don’t really have one. On the other hand, we do have various RSS feeds:

 

1. The project source code – commits, etc: https://github.com/gtosoft.atom
2. Our main web page – RSS feed: http://www.gtosoft.com/?feed=rss2

 

 

I will plan on being active on mp3car.comand will continue to update our web site with news as it happens. Still not sure yet which forum (or our own) we will use to coordinate the developers.

 

I’m new at publishing and coordinating an open source project, but I have experience with Linux, so I’m hoping to learn as I go.

 

Feel free to clone the repo and check it out. I will be publishing a few sample apps in the coming days, with the goal being to allow users to check out the project and immediately compile it with Eclipse.

 

Thanks for visiting – I look forward to working with you!
BH

Comments (No responses yet)

We’ve gone open-source!

Post by: on May 2nd, 2011 | File Under News

As you know, libvoyager is the culmination of all projects by GTOSoft. We have went ahead and released libvoyager to the world, via GITHub! Our hope is that others will benefit from, and contribute to what we have. Anybody can download and enhance the source code on GITHub.

In time, we will add more example applications that use libvoyager, and more documentation and diagrams as needed, to facilitate productivity among the developer community.

Comments (No responses yet)

How to build a Single-wire CAN adapter

Post by: on April 9th, 2011 | File Under News

What is it?
Newer GM vehicles use a network called “Single-wire CAN” to allow certain low-bandwidth components to communicate. For example the navigation system, radio, mirrors, locks, climate controls, remote starter, airbag, data recorder, lights, and more!

What to do with it?
Get an Android app that connects to it and use it to remotely control stuff in your car :)

How to build the adapter
Read on! Or you can buy one pre-made :)

What you will need:
- An ELM327 bluetooth adapter
- An 8055 microchip
- A few small electronics components
- A proto board on which you can mount the 8055 and its supporting circuitry (4-5 components)

Instructions
Take the proto board, solder on the 8055 chip, add the necessary circuitry (shown in the 8055 datasheet), and solder on very short leads to mate the proto board with the main board. You’ll have to de-solder the HSCAN microchip (see pictures) and then solder the leads from the proto board onto the main board. Then solder the single-wire pin from the proto board, over to pin-1 on the OBD adapter. Then stuff it all back together with some heat shrink to protect the leads from shorting out, and voila!

Pictures!

Comments (18 responses so far)

Sleuth – on the way!

Post by: on April 5th, 2011 | File Under News

Sleuth is on the way! I got a little side-tracked working on optimizing the initial connect speed. I want to get it down below 5 seconds. I tried it on my friend’s Volvo and it worked great. I do want to add more detail to the screen down the road, but for now, it does a good job of showing what is on the network.

Comments (One response so far)

CheckMate 1.0 now available on Android Market!

Post by: on March 20th, 2011 | File Under News, Releases

CheckMate 1.0

We’ve pushed the initial release to market. I was missing certain graphics and had to whip some together in a pinch, so don’t laugh at my checkerboard handy-work :) I’m working with our graphics editor to improve them. CheckMate 1.0 is available NOW for download in the Android market.

Version 1.0 features

  • Read trouble codes
  • Get descriptions for trouble codes
  • Reset trouble codes
  • RPM and Speed graphs
  • Automatic Bluetooth configuration

Upcoming Features

  • Improved Graphics
  • Improved Speed

 

Automatic trouble-code lookup?

Yes!

Screenshot

(codes shown below with no info are fake codes used for testing)

CheckMate with code descriptions

 

 

 

 

Comments (No responses yet)

CheckMate screen

Post by: on March 12th, 2011 | File Under Uncategorized

Tweaking the CheckMate main screen a little bit. Still need to attach the live data to the graph. Not far from publishing it to the market.

Checkmate app - main screen

Main screen of the new CheckMate app

Comments (No responses yet)