<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Madox.NET &#187; CAN Bus</title>
	<atom:link href="http://www.madox.net/blog/tag/can-bus/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.madox.net/blog</link>
	<description>Perversions of an Engineer</description>
	<lastBuildDate>Mon, 30 Jan 2012 12:21:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Reverse Engineering the Mazda CAN Bus – Part 2</title>
		<link>http://www.madox.net/blog/2009/10/24/reverse-engineering-the-mazda-can-bus-%e2%80%93-part-2/</link>
		<comments>http://www.madox.net/blog/2009/10/24/reverse-engineering-the-mazda-can-bus-%e2%80%93-part-2/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 13:03:48 +0000</pubDate>
		<dc:creator>Madox</dc:creator>
				<category><![CDATA[Perverse Applications of Science...]]></category>
		<category><![CDATA[CAN Bus]]></category>
		<category><![CDATA[Chumby]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mazda]]></category>

		<guid isPermaLink="false">http://www.madox.net/blog/?p=545</guid>
		<description><![CDATA[This is probably the most ridiculous way to reverse engineer something to date&#8230; a Chumby, an EasySync CAN Sniffer, PHP and JavaScript&#8230; but it works. Instead of designing and building my own daughter-board for the Chumby, I bought an EasySync CAN USB converter which only has one CAN interface [and its not worth buying two].  [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_546" class="wp-caption aligncenter" style="width: 460px"><a href="http://www.madox.net/blog/wp-content/uploads/2009/10/Screenshot-CAN-Bus-Sniffer-Mozilla-Firefox.png"><img class="size-medium wp-image-546" title="Screenshot-CAN Bus Sniffer - Mozilla Firefox" src="http://www.madox.net/blog/wp-content/uploads/2009/10/Screenshot-CAN-Bus-Sniffer-Mozilla-Firefox-450x421.png" alt="HTML Can Sniffer" width="450" height="421" /></a><p class="wp-caption-text">HTML Can Sniffer</p></div>
<p>This is probably the most ridiculous way to <a href="http://www.madox.net/blog/2008/11/17/reverse-engineering-the-mazda-can-bus-part-1/" target="_blank">reverse engineer</a> something to date&#8230; a <a href="http://www.chumby.com/">Chumby</a>, an <a href="http://www.madox.net/blog/2009/06/30/easysync-usb-can-bus-adapter-works-great-in-ubuntu-after-some-fiddling/" target="_blank">EasySync CAN Sniffer</a>, PHP and JavaScript&#8230; but it works.</p>
<p><span id="more-545"></span></p>
<p>Instead of designing and building my own daughter-board for the Chumby, I bought an EasySync CAN USB converter which only has one CAN interface [and its not worth buying two].  This means I will have to use the Mazda&#8217;s MS-CAN bus only [That's where the fuel/trip computer information is].  Only one problem, I didn&#8217;t pay much attention to the MS-CAN bus before and the MS-CAN bus isn&#8217;t as interesting as the HS-CAN.</p>
<p>So new mission to find out what else is on the MS-CAN bus now.  Problem is, the nature of the information on the MS-CAN is different to the HS-CAN.  For example, something like Speed on the HS-CAN was pretty easy to decipher from just logging the data then plotting again.  Trying to figure out &#8216;door open&#8217; for example on the MS-CAN is a lot hard this way.</p>
<p>I needed a tool to help me decipher the secrets of the MS-CAN, and I ended up writing (copy and pasting from old code) a ridiculous combination of PHP scripts for the chumby, a JavaScript/HTML front end.  All done and tested in 2 hours (lots of copy and pasting&#8230;) it works quite well.</p>
<h2>How it works</h2>
<ul>
<li>A background PHP script talks to the EasySync converter and reads the CAN messages that is being sent on the bus and makes this available to another data retrieval PHP script via sessions.</li>
<li>The front end HTML/Javascript combination calls upon the data retrieval PHP, which feeds it XML on the messages for example the CAN Identifer and the timestamp.</li>
<li>The XML is parsed and is rendered into a table for display, data is refreshed at periodic intervals.</li>
<li>The Javascript compares the XML values with the already rendered values before updating to detect a change in value.  If there is a change, the background of the &#8216;byte&#8217; field changes.</li>
<li>A keypress monitor allows the user to &#8216;reset&#8217; the changed background colours.</li>
<li>Code attached below if you want to peek at the mess&#8230;</li>
</ul>
<h2>How I used it</h2>
<p>Basically sat in the car with the sniffer running and trying various combinations to see which bit/byte changed.  e.g. Run sniffer, open a door, see message &#8217;433&#8242; byte &#8217;0&#8242; change colour, write down what changed, reset fields, open another door/do something else.</p>
<p>There were a few useful fields that I found/reconfirmed.  Nothing too interesting though and alot is disappointing.  For example there is information regarding headlight high beam being on, but not just normal headlights.  I suppose that&#8217;s because the high beam is displayed on the instrument panel whilst normal headlights doesn&#8217;t display/do anything.</p>
<p>Another disappointing thing is that the &#8216;ass/arse sensor&#8217; (that&#8217;s what I call the passenger seat detection gizmo) is only a boolean signal&#8230;no pressure sensing in it at all.  Would have been useful if it was an analogue signal, could have been good for the mChumby display &#8211; &#8220;Warning, the girl on the passenger seat weighs 87kg, do not go on another date&#8221;.</p>
<p>I&#8217;ll be updating the new information to the <a href="http://www.madox.net/blog/2008/11/17/reverse-engineering-the-mazda-can-bus-part-1/" target="_blank">Mazda CAN Bus</a> page in the next couple of days&#8230; check back then to see what&#8217;s new.</p>
<p><a href="http://www.madox.net/blog/wp-content/uploads/2009/10/cansniffer.zip">Download cansniffer.zip</a> (There&#8217;s still a bug with the timestamp I&#8217;m too lazy to fix&#8230; disclaimer this is hobby/crappy code <img src='http://www.madox.net/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p>
]]></content:encoded>
			<wfw:commentRss>http://www.madox.net/blog/2009/10/24/reverse-engineering-the-mazda-can-bus-%e2%80%93-part-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>mChumby &#8211; Test run</title>
		<link>http://www.madox.net/blog/2009/07/15/mchumby-test-run/</link>
		<comments>http://www.madox.net/blog/2009/07/15/mchumby-test-run/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 10:12:29 +0000</pubDate>
		<dc:creator>Madox</dc:creator>
				<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Perverse Applications of Science...]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[CAN Bus]]></category>
		<category><![CDATA[Chumby]]></category>
		<category><![CDATA[FTDI]]></category>
		<category><![CDATA[HaXe]]></category>
		<category><![CDATA[Mazda]]></category>

		<guid isPermaLink="false">http://www.madox.net/blog/?p=498</guid>
		<description><![CDATA[After getting my EasySync USB-Can Adapter it was time to resurrect the mChumby project.  The interface GUI design hasn&#8217;t changed much, namely because its been lying idle but I figured it is good enough to try putting it onto the car for a test run. I didn&#8217;t want to fiddle around with getting power to [...]]]></description>
			<content:encoded><![CDATA[<p>After getting my <a href="http://www.madox.net/blog/2009/06/30/easysync-usb-can-bus-adapter-works-great-in-ubuntu-after-some-fiddling/" target="_blank">EasySync USB-Can Adapter</a> it was time to resurrect the <a href="http://http://www.madox.net/blog/2009/03/23/mchumby-mazdamadox-chumby/" target="_blank">mChumby</a> project.  The <a href="http://www.madox.net/blog/2009/04/06/mchumby-interface-design/" target="_blank">interface GUI design</a> hasn&#8217;t changed much, namely because its been lying idle but I figured it is good enough to try putting it onto the car for a test run.</p>
<p>I didn&#8217;t want to fiddle around with getting power to the Chumby, so the test is simply using my trusty old laptop and the EasySync adapter.  Only the speedometer, the tachometer and the accelerator pedal position is attached because again I&#8217;m too lazy to fiddle with my cable layout and as such its connected to the <a href="http://www.madox.net/blog/mazda-can-bus/" target="_blank">Mazda HS-Can</a> bus only rather than the MS-Can where the <a href="http://www.madox.net/blog/2008/11/17/reverse-engineering-the-mazda-can-bus-part-1/" target="_blank">goodie trip computer information is contained.</a></p>
<p>Almost every concoction of technology is used ranging from CAN, USB, PHP, HTTP, Shared Memory, XML, Flash, to an obscure programming language called HaXe.  Here is the result :-</p>
<p><span id="more-498"></span></p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/1NRWEeg4KeE" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/1NRWEeg4KeE"></embed></object></p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/Y8t7p2WR_3k" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/Y8t7p2WR_3k"></embed></object></p>
<p>The flash movie was set to 6 frames per second and the responsiveness of the data was superb.  I think I&#8217;ve stated before that the CAN speed data differs to the one displayed on the instrumentation cluster and this again really shows at higher speeds.</p>
<p>All I need to do now is to try it on a <a href="http://www.chumby.com/" target="_blank">Chumby</a>, there should be no portability issues as I&#8217;ve tested both flash and php on the Chumby before.</p>
<p>So does anyone have any comments and suggestions on the GUI and what else I could put on it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.madox.net/blog/2009/07/15/mchumby-test-run/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EasySync USB-CAN Bus Adapter &#8211; Works great in Ubuntu after some fiddling</title>
		<link>http://www.madox.net/blog/2009/06/30/easysync-usb-can-bus-adapter-works-great-in-ubuntu-after-some-fiddling/</link>
		<comments>http://www.madox.net/blog/2009/06/30/easysync-usb-can-bus-adapter-works-great-in-ubuntu-after-some-fiddling/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 12:52:30 +0000</pubDate>
		<dc:creator>Madox</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Problems Help]]></category>
		<category><![CDATA[Software Tips & Tricks]]></category>
		<category><![CDATA[CAN Bus]]></category>
		<category><![CDATA[Chumby]]></category>
		<category><![CDATA[Free Software]]></category>
		<category><![CDATA[Free Software Tips]]></category>
		<category><![CDATA[FTDI]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.madox.net/blog/?p=476</guid>
		<description><![CDATA[The toys just keep coming in!  Another one of those wallet killing impulsive orders whilst I was sick in bed last week just arrived today, a USB-CAN bus converter module by EasySync that promises a great interface and should work in Linux!  This will give a little bump start to my Mazda CAN Bus / [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_477" class="wp-caption aligncenter" style="width: 368px"><a href="http://www.madox.net/blog/wp-content/uploads/2009/06/CIMG2414A.JPG"><img class="size-medium wp-image-477" title="CIMG2414A" src="http://www.madox.net/blog/wp-content/uploads/2009/06/CIMG2414A-358x300.jpg" alt="Neat little package" width="358" height="300" /></a><p class="wp-caption-text">Neat little package</p></div>
<p>The toys just keep coming in!  Another one of those wallet killing impulsive orders whilst I was sick in bed last week just arrived today, a USB-CAN bus converter module by <a href="http://www.easysync.co.uk/" target="_blank">EasySync</a> that promises a great interface and should work in Linux!  This will give a little bump start to my <a href="http://www.madox.net/blog/mazda-can-bus/" target="_blank">Mazda CAN Bus</a> / <a href="http://www.madox.net/blog/2009/03/23/mchumby-mazdamadox-chumby/" target="_blank">mChumby</a> projects.</p>
<p><em>Note : EasySync UK&#8217;s online form doesn&#8217;t allow international shipping but a short E-mail or two managed that.  There is a US subsidiary with US and international shipping, but the international shipping rates on the US site is plain ridiculous [$68USD to ship a $88 device to Australia].</em></p>
<p><em>Note 2 : I hear the interface is mimicking the Lawicel CAN-USB interface&#8230;only hearsay&#8230;<br />
</em></p>
<p>Plugged it in &#8211; didn&#8217;t work.  Doh!  Took a peek at the manual and website, nothing on Linux other than &#8220;Linux drivers provided&#8221;&#8230; So much for the marketing material, guess I have to try make it work myself.  (Yes I got it working, read on for the quick run-down post aimed at helping others)</p>
<p><span id="more-476"></span></p>
<div id="attachment_478" class="wp-caption aligncenter" style="width: 460px"><a href="http://www.madox.net/blog/wp-content/uploads/2009/06/CIMG2417A.JPG"><img class="size-medium wp-image-478" title="CIMG2417A" src="http://www.madox.net/blog/wp-content/uploads/2009/06/CIMG2417A-450x282.jpg" alt="Sneak peek inside the box" width="450" height="282" /></a><p class="wp-caption-text">Sneak peek inside the box</p></div>
<p>Now with the photos out of the way, a little bit of detective work is ahead of us&#8230; why doesn&#8217;t this thing work&#8230; I paid so much money for it to replace the qprotos adapter!</p>
<p>A little bit of lsusb (or cat /proc/bus/usb/devices if you&#8217;ve got usbdevfs) sleuthing later&#8230;</p>
<blockquote>
<pre>Bus 003 Device 004: ID 0403:fac6 Future Technology Devices International, Ltd
Device Descriptor:
 bLength                18
 bDescriptorType         1
 bcdUSB               2.00
 bDeviceClass            0 (Defined at Interface level)
 bDeviceSubClass         0
 bDeviceProtocol         0
 bMaxPacketSize0         8
 idVendor           0x0403 Future Technology Devices International, Ltd
 idProduct          0xfac6
 bcdDevice            6.00
 iManufacturer           1 EasySync
 iProduct                2 USB2-F-7001 CAN-Plus Adapter
 iSerial                 3 ESNFWLPL
 bNumConfigurations      1
 Configuration Descriptor:
 bLength                 9
 bDescriptorType         2
 wTotalLength           32
 bNumInterfaces          1
 bConfigurationValue     1
 iConfiguration          0
 bmAttributes         0x80
 (Bus Powered)
 MaxPower              150mA
 Interface Descriptor:
 bLength                 9
 bDescriptorType         4
 bInterfaceNumber        0
 bAlternateSetting       0
 bNumEndpoints           2
 bInterfaceClass       255 Vendor Specific Class
 bInterfaceSubClass    255 Vendor Specific Subclass
 bInterfaceProtocol    255 Vendor Specific Protocol
 iInterface              2 USB2-F-7001 CAN-Plus Adapter
 Endpoint Descriptor:
 bLength                 7
 bDescriptorType         5
 bEndpointAddress     0x81  EP 1 IN
 bmAttributes            2
 Transfer Type            Bulk
 Synch Type               None
 Usage Type               Data
 wMaxPacketSize     0x0040  1x 64 bytes
 bInterval               0
 Endpoint Descriptor:
 bLength                 7
 bDescriptorType         5
 bEndpointAddress     0x02  EP 2 OUT
 bmAttributes            2
 Transfer Type            Bulk
 Synch Type               None
 Usage Type               Data
 wMaxPacketSize     0x0040  1x 64 bytes
 bInterval               0
Device Status:     0x0000
 (Bus Powered)</pre>
</blockquote>
<p>Yup definitely a FTDI device, even with the FTDI vendor ID (Did I mention I love FTDI?).  Looks like EasySync decided they wanted their own unique product ID, unfortunately that means the vanilla ftdi_sio drive won&#8217;t pick it up without a little bit of coercing.</p>
<p>The little bit of coercing goes like&#8230;</p>
<blockquote><p><em>modprobe ftdi_sio vendor=0&#215;0403 product=0xfac6</em></p></blockquote>
<p>And bingo&#8230;</p>
<blockquote>
<pre>[ 6372.229046] usb 2-2: new full speed USB device using uhci_hcd and address 3
[ 6372.437247] usb 2-2: configuration #1 chosen from 1 choice
[ 6372.439834] ftdi_sio 2-2:1.0: FTDI USB Serial Device converter detected
[ 6372.439872] usb 2-2: Detected FT232RL
[ 6372.439934] usb 2-2: FTDI USB Serial Device converter now attached to ttyUSB0</pre>
</blockquote>
<p>Using putty to connect to ttyUSB0 at 115200, and typing &#8220;H&#8221; followed by &#8220;Enter&#8221; gives us</p>
<blockquote>
<pre>=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2009.06.30 21:23:18 =~=~=~=~=~=~=~=~=~=~=~=
H
List of Supported Commands
O - Open CAN Channel
C - Close CAN Channel
t - Transmit Standard Frame
T - Transmit Extended Frame
F - Read Status Flag
V - USB2-F-7001 Version
N - Serial Number of USB2-F-7001
Z - TimeStamp Option On/Off
S - Set CAN Bit Rate
s - Set BRGCON Registers
m - Set Acceptance Mask
M - Set Acceptance Filter
B - Enter Bootload Mode
L - Set Listen Mode
E - Clear Buffers and Echo Char
R - Reset USB2-F-7001
H, ? or h - Help on USB2-F-7001 Commands</pre>
</blockquote>
<p>Only problem is that its Mac style line endings.  Even the append CR to LF option in putty is useless because the stream seems to be CR without LF&#8230;  Doesn&#8217;t hurt too much except displaying it is a bit annoying.</p>
<p>The EasySync USB-CAN adapter&#8217;s pinout is pretty much standard DB9 for CAN Bus and all I had to do was connect my existing J1962 (aka OBD-II aka DLC-2) cable on and onto the car I went.</p>
<p>A couple of short &#8220;S6&#8243; (500kbps) &#8220;L&#8221; (Open connection for listen mode) commands later, I had CAN data being spat back at me</p>
<blockquote>
<pre>t04680601FF0000000000
t04680601FF0000000000
t04680601FF0000000000
t04680601FF0000000000
t04680601FF0000000000
t20F8FFFF27104000FF01
t2118FFFF000040000001
t4B082710271027102710
t19080000000000000000</pre>
</blockquote>
<p>All is good&#8230;except I just deleted my Chumby Development Virtual Machine a few hours ago&#8230;ooops&#8230;another day before I use this neat little adapter for <a href="http://www.madox.net/blog/2009/03/23/mchumby-mazdamadox-chumby/" target="_blank">mChumby</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.madox.net/blog/2009/06/30/easysync-usb-can-bus-adapter-works-great-in-ubuntu-after-some-fiddling/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>mChumby &#8211; Mazda/Madox Chumby</title>
		<link>http://www.madox.net/blog/2009/03/23/mchumby-mazdamadox-chumby/</link>
		<comments>http://www.madox.net/blog/2009/03/23/mchumby-mazdamadox-chumby/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 11:38:11 +0000</pubDate>
		<dc:creator>Madox</dc:creator>
				<category><![CDATA[Perverse Applications of Science...]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[CAN Bus]]></category>
		<category><![CDATA[Free Software]]></category>
		<category><![CDATA[Mazda]]></category>
		<category><![CDATA[Microcontrollers]]></category>

		<guid isPermaLink="false">http://www.madox.net/blog/?p=271</guid>
		<description><![CDATA[It&#8217;s taken me a while to officially start this project.  When I first bought my Mazda 3 I had envisaged making my own speedometer based off the Mazda CAN Bus but somehow never quite got around to it. I even ended up buying 2 Chumbies for the purpose of hacking one and developing the same [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s taken me a while to officially start this project.  When I first bought my Mazda 3 I had envisaged making my own speedometer based off the Mazda CAN Bus but somehow never quite got around to it.</p>
<p>I even ended up buying 2 <a href="http://www.chumby.com/" target="_blank">Chumbies</a> for the purpose of hacking one and developing the same speedo (The chumby is such a great alarm clock I couldn&#8217;t live without one&#8230;).</p>
<p>There has been quite a bit of interest in the comments for source code/information etc etc.  So now I&#8217;m officially starting the mChumby project!  This first post is basically a brainstorming session write-up or a mini requirements specification on myself.  Feel free to comment on any ideas/improvements you think I can make.</p>
<p>(This post seems too wordy without a photo but I&#8217;m just too lazy)</p>
<h1><span id="more-271"></span>The concept</h1>
<p>A Chumby will connect via CAN Bus to the Mazda to offer an alternative &#8216;GUI&#8217; to the car.  Information such as fuel consumption that has been removed from the Australian Mazda&#8217;s will be displayed.</p>
<p>Since a chumby doesn&#8217;t have native CAN Bus connections, a custom daughter board with dual CAN controllers and transceivers will be built to replace the native Chumby power board.</p>
<h1>The hardware</h1>
<p>In addition to the Chumby mainboard, there will be a custom daughter board to be made to handle the car interface.  The Chumby has multiple SPI interfaces brought out through the &#8216;Chumbilical&#8217;, as well as on-board voltage regulators that will take up to 15V.  So a quick brainstorm on the daughter-board components leads me to :-</p>
<p>CAN Controller : MCP2515 &#8211; Has SPI interface, great for Chumby.<br />
CAN Transceiver : TJA1041 or whatever it is I have in my box of electronics &#8211; Because I have them already<br />
USB Connectors + Associated electronics&#8230;<br />
Automotive Voltage Suppressor : Vishay had a few good ones</p>
<p>Luxuries like accelerometers are too much of a pain to hand solder <img src='http://www.madox.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h1>The software</h1>
<p>I&#8217;m going to try use completely open source software in the development.  This will be discounting the Flash Lite 3 player that ships with the Chumby.  I debated much about developing a QT app or a flash widget, what I decided was undecided and I switched back and forth.  In the end, I&#8217;m sticking with Flash (for now).</p>
<p>There are two main pieces of software required, the GUI and the CAN Bus drivers.</p>
<p>The GUI as decided before will be Flash targetting the Flash Lite 3 on the Chumby.  For this I decided to use <a href="http://www.haxe.org/" target="_blank">HaXe</a>, which will happily compile to Flash 8 bytecode.  It is not as popular in open source flash developement as say ActionScript 2 with <a href="http://tech.motion-twin.com/mtasc.html" target="_blank">mtasc</a> but I figured I&#8217;ll use the newer language.  Unfortunately there is a severe lack of HaXe examples on the net and when you find them, you&#8217;ll find that its based on Flash 9 API&#8230; GAH.  However a little bit of experimentation and googling around made me see how easy it is to actually use HaXe.  More on this later.</p>
<p>The driver&#8217;s for the MCP2515&#8242;s I haven&#8217;t really looked at yet but I hope that it&#8217;ll be a simple matter of adapting MCP2515 code from elsewhere and merging it with hopefully some SPI driver&#8217;s in the Chumby kernel source (did I mention how great the Chumby is? Source code is made available!).</p>
<p>There is a bit of other software that&#8217;ll be used to create this project.  I&#8217;m planning on learning how to use <a href="http://http://iut-tice.ujf-grenoble.fr/kicad/" target="_blank">KiCAD</a> to generate the PCB where as I&#8217;ve only previously used<a href="http://cadsoftusa.com/" target="_blank"> Eagle</a> on my hobby projects.  While I&#8217;m sure Eagle will get the job done, I really want to give a try in learning how to use the open source KiCAD.  Let me know if you have any hints.</p>
<p><a href="http://www.geany.org/" target="_blank">Geany</a> will be my lightweight editor/IDE of choice, its so simple to use and amazing.  (I like <a href="http://notepad-plus.sourceforge.net/" target="_blank">Notepad++</a> in Windows but I haven&#8217;t booted Windows at home for a while&#8230;)</p>
<h1>The HMI</h1>
<p>I like easy to use and simple user interfaces.  This is especially true when I&#8217;m driving, I definitely do not want this thing distracting me.  My initial idea was to organise it such that all the &#8216;buttons&#8217; are on the corners of the screen but on second thought even trying to touch that while driving may be a bit difficult.</p>
<p>Current idea is to use some simple swipe gestures to control the screen.  The idea is to have minimal interaction with my mChumby as possible while driving.  I intend to have 2 screens, one to display a large speedo and the main displays and a second screen to display a smaller speed with alot of additional potentially useless information (I haven&#8217;t figured out what yet).  I will also need brightness control to avoid getting a super bright screen at night.  So simply, swipe left-right will allow me to change screens and wipe up-down will allow me to adjust backlight brightness.</p>
<h2>Below is just an embarassing sample of the HaXe code I was experimenting with&#8230;</h2>
<h3></h3>
<h3>Mchumby.hx</h3>
<blockquote>
<pre>//MChumby GUI - HaXe code targetting Flash 8

class Mchumby{
  //Gesture Variables
  static var fGestureStartX:Float;
  static var fGestureStartY:Float;
  static var fGestureEndX:Float;
  static var fGestureEndY:Float;
  static var fGestureDeltaX:Float;
  static var fGestureDeltaY:Float;

  //MovieClips (Screens)
  static var mcMain : flash.MovieClip;

  static var mcD100 : flash.MovieClip;
  static var mcD101 : flash.MovieClip;
  //MovieClips (Buttons/Other Elements)

  //Text Fields
  static var tfText : flash.TextField;

  static var tfSpeedo : flash.TextField;
  static var tfAccelX : flash.TextField;
  static var tfAccelY : flash.TextField;
  static var tfAccelZ : flash.TextField;  

  //Text Format/Styles
  static var ts = new flash.TextFormat();
  static var tsCenter = new flash.TextFormat();

  public function new(){
    //Constructor - Most items are moved to main();
    fGestureStartX=0;
    fGestureStartY=0;
  }

  static function main(){
    //Setup main MovieClip
    mcMain = flash.Lib.current;

    //Set up some font styles
    ts.font = "Arial";
    ts.size = 24;
    ts.color = 0x00FFFF;

    tsCenter.font = "Arial";
    tsCenter.size = 24;
    tsCenter.color = 0xFF0000;
    tsCenter.align = 'center';

    //Set up screens the new way
    //var m100 = new M100(mcMain);
    //var m101 = new M101(mcMain);

    //Set up screens
    mcD100 = mcMain.createEmptyMovieClip("D100", mcMain.getNextHighestDepth());
    mcD101 = mcMain.createEmptyMovieClip("D101", mcMain.getNextHighestDepth());

    //Set up text fields
    tfText = mcMain.createTextField("tfText", mcMain.getNextHighestDepth(), 20, 20, 280, 100);
    tfText.setNewTextFormat(tsCenter);

    //Set up text fields (D100)
    tfSpeedo = mcD100.createTextField("speedotext", mcD100.getNextHighestDepth(), 20,50,280,100);
    tfSpeedo.setNewTextFormat(ts);
    tfAccelX = mcD100.createTextField("accelx", mcD100.getNextHighestDepth(), 20,80,280,100);
    tfAccelX.setNewTextFormat(ts);
    tfAccelY = mcD100.createTextField("accely", mcD100.getNextHighestDepth(), 20,110,280,100);
    tfAccelY.setNewTextFormat(ts);
    tfAccelZ = mcD100.createTextField("accelz", mcD100.getNextHighestDepth(), 20,140,280,100);
    tfAccelZ.setNewTextFormat(ts);

    //Set up text fields (D101)

    //Initialise text
    tfText.text = 'Hello World!';

    tfSpeedo.text = 'Accelerometer Values...';

    //Set up event handlers
    mcMain.onMouseDown = startGesture;
    mcMain.onMouseUp = endGesture;
    mcMain.onEnterFrame = update;
  }

  static function update(){
    tfAccelX.text = Std.string(ChumbyNative.getAccelerometer(5));
    tfAccelY.text = Std.string(ChumbyNative.getAccelerometer(6));
    tfAccelZ.text = Std.string(ChumbyNative.getAccelerometer(7));
  }
  static function startGesture () {
    fGestureStartX = flash.Lib.current._xmouse;
    fGestureStartY = flash.Lib.current._ymouse;
  }

  static function endGesture () {
    fGestureEndX = flash.Lib.current._xmouse;
    fGestureEndY = flash.Lib.current._ymouse;
    fGestureDeltaX = Math.round(fGestureEndX - fGestureStartX);
    fGestureDeltaY = Math.round(fGestureEndY - fGestureStartY);

		//Rather than else-if, the following if's are deliberately done to allow compound gestures
		//e.g. Up &amp; Left, Down &amp; Right etc.
    if (!Math.isNaN(fGestureDeltaY) &amp;&amp; (fGestureDeltaY &gt; 100)) {
      gestureDown();
    }

    if (!Math.isNaN(fGestureDeltaY) &amp;&amp; (fGestureDeltaY &lt; -100)) {
      gestureUp();
    } 

    if (!Math.isNaN(fGestureDeltaX) &amp;&amp; (fGestureDeltaX &lt; -200)) {
      gestureLeft();
    }

    if (!Math.isNaN(fGestureDeltaX) &amp;&amp; (fGestureDeltaX &gt; 200)) {
      gestureRight();
    }
  }
  static function gestureRight () {
    tfText.text = "To the right!";
    mcD100._alpha = 0;
    //tfText.setTextFormat(ts);
  }
  static function gestureLeft () {
    tfText.text = "To the left!";
    mcD100._alpha = 100;
  }
  static function gestureUp () {
    tfText.text = "Bright!";
    ChumbyNative.setLCDMute(0);
  }
  static function gestureDown () {
    tfText.text = "Dim!";
    ChumbyNative.setLCDMute(1);
  }
}</pre>
</blockquote>
<h3>ChumbyNative.hx</h3>
<blockquote>
<pre>class ChumbyNative{
  public static function getLCDMute():Int{
    return flash.Lib._global.ASnative(5,19);
  }
  public static function setLCDMute(x:Int):Void{
    flash.Lib._global.ASnative(5,20)(x);
  }
  public static function getAccelerometer(x:Int):Float{
    return flash.Lib._global.ASnative(5,60)(x);
  }
}</pre>
</blockquote>
<h3>Mchumby.hxml</h3>
<blockquote><p>-swf mchumby.swf<br />
-main Mchumby<br />
-swf-header 320:240:12:000033<br />
-swf-version 8</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.madox.net/blog/2009/03/23/mchumby-mazdamadox-chumby/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Reverse Engineering the Mazda CAN Bus &#8211; Part 1</title>
		<link>http://www.madox.net/blog/2008/11/17/reverse-engineering-the-mazda-can-bus-part-1/</link>
		<comments>http://www.madox.net/blog/2008/11/17/reverse-engineering-the-mazda-can-bus-part-1/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 11:37:38 +0000</pubDate>
		<dc:creator>Madox</dc:creator>
				<category><![CDATA[Perverse Applications of Science...]]></category>
		<category><![CDATA[CAN Bus]]></category>
		<category><![CDATA[Mazda]]></category>
		<category><![CDATA[Perverted Engineering]]></category>

		<guid isPermaLink="false">http://www.madox.net/blog/?p=22</guid>
		<description><![CDATA[Controller-Area Network or CAN Bus is one of many automotive communication buses for communications between various &#8216;car computers&#8217;.  Information such as speed, fuel consumption, accelerator pedal position is all transmitted between the various controllers of a car akin to &#8216;fly-by-wire&#8217; control systems of aircraft but I guess &#8216;drive-by-wire&#8217; is more appropriate in this case. There [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Controller_Area_Network">Controller-Area Network</a> or CAN Bus is one of many automotive communication buses for communications between various &#8216;car computers&#8217;.  Information such as speed, fuel consumption, accelerator pedal position is all transmitted between the various controllers of a car akin to &#8216;fly-by-wire&#8217; control systems of aircraft but I guess &#8216;drive-by-wire&#8217; is more appropriate in this case.</p>
<p>There are other rival bus technologies include LIN (Local Interconnect Network) which is supposed to be a lower cost alternative to CAN, but I&#8217;m not interested in that.  Why?  My car uses the CAN bus, not LIN, not Ethernet.  So lets go about figuring what can be gleened from the communications whizzing around my car!</p>
<div id="attachment_28" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.madox.net/blog/wp-content/uploads/2008/11/carpig2.jpg"><img class="size-medium wp-image-28" title="carpig2" src="http://www.madox.net/blog/wp-content/uploads/2008/11/carpig2-300x225.jpg" alt="Aside from CAN bus, my car has a pig too.  This photo is from 2 years ago and the pig no longer has the tail or the tag on its ass..." width="300" height="225" /></a><p class="wp-caption-text">Aside from CAN bus, my car has a pig too (Long story).  This photo is from 2 years ago and the pig no longer has the weird thing hanging from its belly or the tag on its ass...</p></div>
<p><span id="more-22"></span></p>
<h2>Background / Reason Why</h2>
<p>In June 2006 I bought a &#8216;new&#8217; car, an Australian Mazda 3 Facelift Model.  The car was a great drive, Mazda excelled in the build and features but one thing nagged at me &#8211; the speedometer.  It was stylish I had to admit but the scaling was &#8216;off&#8217; to me.  0 speed was vertically down and the scaling was&#8230; better not rant on but the thought was &#8216;maybe I can get another speedometer on&#8217;.  A history of my &#8216;better speedometer&#8217; fantasies follow <img src='http://www.madox.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div id="attachment_24" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.madox.net/blog/wp-content/uploads/2008/11/speed432.jpg"><img class="size-medium wp-image-24" title="speed432" src="http://www.madox.net/blog/wp-content/uploads/2008/11/speed432-300x266.jpg" alt="My old (and free!) Sony Ericson showing my speed on a MagLev" width="300" height="266" /></a><p class="wp-caption-text">My old (and free!) Sony Ericson showing my speed on a MagLev</p></div>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.madox.net/blog/wp-content/uploads/2008/11/hudtest.jpg"><img class="size-medium wp-image-25" title="hudtest" src="http://www.madox.net/blog/wp-content/uploads/2008/11/hudtest-300x225.jpg" alt="Testing the feasibility of using the same crappy phone as a HUD on another car of mine on a rainy night..." width="300" height="225" /></a><p class="wp-caption-text">Testing the feasibility of using the same crappy phone as a HUD on another car of mine on a rainy night...yup that&#39;s the image on my windscreen!</p></div>
<p>A little bit of research later I found out the Mazda had two CAN buses: a &#8216;HS-CAN&#8217; (High Speed) network on which most of the essential systems (ECU, ABS) were connected, and a slower &#8216;MS-CAN&#8217; (Medium Speed?) network on which accessories such as the audio system were connected.  These two networks are joined together by the instrument panel which also acts as the gateway to allow some messages to pass between the two networks.  Both buses are conveniently available via a &#8216;standard&#8217; J1962 plug just below the steering wheel (Do a search on <a href="http://en.wikipedia.org/wiki/On_Board_Diagnostics">OBD</a>) so I didn&#8217;t have to hack anything open.</p>
<p>[Note : Most of the information below is from back in 2006, I only recently picked this project back up]</p>
<p>[Note 2 : Please don't any of what I say below if you're not familiar with electronics/cars or if you value your life... I hold no responsibility for anything that happens... I need to learn how to write a better disclaimer]</p>
<h2>So what is on the network exactly?</h2>
<p>Officially?  &#8216;I dunno&#8217;.  Mazda naturally doesn&#8217;t publish this information nor can it be found on the net easily, I hope Mazda doesn&#8217;t take offense at me writing this post actually&#8230; I loved the car and I&#8217;m doing this because its such a great car <img src='http://www.madox.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  [/grovel].</p>
<p>Now if that information isn&#8217;t forthcoming from the great ol&#8217; google, I just had to try figure it out for myself!</p>
<h2>How it was done</h2>
<p>First step &#8211; Find the pin-outs of the J1962 connector, since its standard connector albeit with slightly different pin-outs per car type the answer is easily found on google.  Go search it up yourself <img src='http://www.madox.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Second step &#8211; Oscilloscope.  A lovely portable fluke connected to the two CAN bus lines told me the baud rates of each of the two buses.  500kbps and 125kbps respectively.</p>
<p>Third step &#8211; Start sniffing, or at least buy the stuff to do so.  I had wanted to build my own CAN interface board but laziness got the better of me and I bought the cheapest one online I could find from <a href="http://www.qprotos.com/">QProtos</a>.  In hindsight it wasn&#8217;t the best choice but it wasn&#8217;t that bad either.  Coupled with a J1962 cable from <a href="www.obd2cables.com">OBD2Cables.com</a> (only remember them because i&#8217;m still receiving email offers hehe) I had everything I need to start.</p>
<p>Fourth step &#8211; Really start sniffing.  A precaution I took was to set the CAN-USB adaptor to &#8216;listen&#8217; mode only, I didn&#8217;t want to risk the brakes suddenly not working.</p>
<p>A bunch of static tests to start things off nice and slow.  The methodology was simple, start the CAN bus logging then carry out actions on the car at certain times &#8211; turn the blinker, step on the accelerator etc.  All was left to be done was to review the logs to see which bits or bytes changed at those matching times.</p>
<p>Fifth step &#8211; The fun bit!  Dynamic testing!  This time with the same setup as above but with my GPS phone logging simultaneously too.  Oh what fun you can achieve here.</p>
<div id="attachment_23" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.madox.net/blog/wp-content/uploads/2008/11/speed-gps-can.jpg"><img class="size-medium wp-image-23" title="speed-gps-can" src="http://www.madox.net/blog/wp-content/uploads/2008/11/speed-gps-can-300x199.jpg" alt="Speed from GPS vs Speed from CAN bus" width="300" height="199" /></a><p class="wp-caption-text">Speed from GPS vs Speed from CAN bus</p></div>
<p>Anyone familiar with the Australian Design Rules and the laws?  The displayed vehicle speed must not be reported lower than actual, so what most manufacturers do is artificially bump that number up.  Hence you see the almost always consistently higher CAN speed compared to the GPS speed&#8230; Hey I haven&#8217;t even said how many &#8216;speed&#8217; signals are transmitted across the CAN bus&#8230;the &#8216;actual&#8217; (unmodified) one is there too.</p>
<h2>The state of affairs</h2>
<p>As of the end of 2006 (Yes two years ago) I had mapped out &#8230; (in no particular order&#8230;well actually in order of CAN bus ID&#8217;s)</p>
<p>On the HS-CAN</p>
<ul>
<li>Brake Active</li>
<li>RPM</li>
<li>Vehicle Speed</li>
<li>Accelerator Pedal position</li>
<li>Brake Active (Again)</li>
<li>True Vehicle Speed</li>
<li>Gear Position &#8211; Park</li>
<li>Gear Position -Reverse</li>
<li>Gear Position -Drive</li>
<li>1st, 2nd&#8230; etc Gears</li>
<li>Gear Shift</li>
<li>Manual/Tiptronic Selection [Yes I drive an Auto]</li>
<li>Gears again&#8230;</li>
<li>Accelerator Pedal position again&#8230;in a different scaling&#8230;Mazda is strange</li>
<li>Left Front Wheel Speed</li>
<li>Right Front Wheel Speed</li>
<li>Left Rear Wheel Speed</li>
<li>Right Rear Wheel Speed</li>
<li>Steering Wheel Angle (I&#8217;m going to have fun with this one!)</li>
<li>Odometer</li>
</ul>
<p>On the MS-CAN</p>
<ul>
<li>RPM (Retransmitted)</li>
<li>Vehicle Speed (Retransmitted)</li>
<li>Head Unit LCD Display (Oh this will be fun too)</li>
<li>TRIP COMPUTER! Average Speed, Fuel Consumption, Average Fuel Consumption, Distance Remaining</li>
</ul>
<p>Oh I so forgot to rant.  Trip Computer, very nice little pieces of information for driving a car.  Official Mazda Australia line?  Oh our Mazda 3&#8242;s don&#8217;t have this.  All overseas models have it.  All information is already on the car.  The car even has a head unit with all the trip computer LCD displays present (you can see it if you tilt your head).  Infact there&#8217;s a little trick you can do with every Mazda 3 model just prior to mine that you can hold down certain keys on the head unit before starting the car that activates it&#8230; but nooooooooooooo its disabled on mine for what reason I don&#8217;t know&#8230; erm&#8230; rant over.  Guess I have to do a better speedometer and trip meter too.</p>
<p>If anyone was expecting to see the results, you have to wait for Part 2 (or 3)&#8230;does anyone actually want to see?   Or got any questions? mmmm</p>
]]></content:encoded>
			<wfw:commentRss>http://www.madox.net/blog/2008/11/17/reverse-engineering-the-mazda-can-bus-part-1/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
	</channel>
</rss>

