I'm a web developer, freelancer, author, speaker, entrepreneur, technical reviewer and blogger based in the North East, living in a village just outside of Chester-le-Street.
My blog
Processing CAN Messages in PHP
The automotive industry makes extensive use of a standard called CAN bus, a Controller Area Network which allows the various components of a vehicle to talk to each other without the need for a host. Typically, messages sent on the CAN bus are short 16 character hexadecimal words, with an identifier associated with them. To get from these 16 character words to meaningful information you need two things: a CAN specification provided by the relevant component manufacturer, and a way to process the information and decode it as per the specification.
Recently, I've been doing some work which has involved verifying the information that has been extracted from the CAN bus is correct, and that we are interpreting the CAN specification correctly. This has proved difficult, as while I can see where the specification hasn't been correctly translated into the application which processes it, it isn't easy to see (when it has been translated correctly) where the incorrect values are coming from. To make things easier, and to try and further my knowledge of the CAN bus, I have written a PHP based CAN processing tool. This allows me to perform the translations and calculations myself and see why certain pieces of information have been translated incorrectly.
As a seperate project I'm working with a group of engineers to develop a small autonomous robot, which will use a CAN bus to keep itself aware of its location and what its various components are doing. With this PHP tool, I will be able to quickly process what it is doing and display this in a web browser without the need for some middleware application.
The CAN processing tool is relatively simple. You provide an XML based specification detailing which type of CAN bus messages can be translated into which useful pieces of information, detailing which bytes and bits of the hexadecimal word contain the information, as well as which scaling, multiplication and data type conversion (e.g. convert two a short by applying a two's compliment) factors need to be applied to get the correct output.
Get the code
The code is available on GitHub: https://github.com/mkpeacock/PHP-CAN-Processor
How to use it
There are two ways to use the application, you can either provide an XML specification to the application, pass a message and let it do the work, or you can manually tell the application which messages need to be translated in which ways.
Providing a specification
The easiest way to use this system is to provide an XML based "specification" of the different CAN message types you wish to decode, and the pieces of information from within.
<?xml version="1.0" encoding="UTF-8"?>
<canspec>
<canID id="ABC" type="multiplex" multiplexByte="0" namePrefix="" nameSuffix="_Piston%1$d">
<engineeringUnit type="multi-byte">
<name>Piston_position</name>
<unit>mm</unit>
<mostSignificantByte>2</mostSignificantByte>
<leastSignificantByte>3</leastSignificantByte>
<dataType>null</dataType>
<multiplier>0.01</multiplier>
<offset>0</offset>
</engineeringUnit>
</canID>
</canspec>
You can then use a factory to build the keys, the decoders and turn that into a collection of decoders.
$factory = new CentralApps\CAN\Decoder_Factory();
$spec = $factory->makeDecoderFromXMLFile('sample_can_specification.xml');
Passing a message to the collection of decoders will find the decoder for that can message type, and perform the decoding logic from within.
$message = new CentralApps\CAN\Message( 'ABC', '0000000000000000' );
$units = $spec->decode( $message );
foreach( $units as $unit )
{
echo $unit;
}
Manual
$message = new CentralApps\CAN\Message( 'ABC', '0000000000000000' );
$multiByteKey = new CentralApps\CAN\Decoder_Keys_MultiByte();
$multiByteKey->setCanID( 'ABC' );
$multiByteKey->setName( 'Piston_position' );
$multiByteKey->setUnit( "mm" );
$multiByteKey->setMultiplier( 0.01 );
$multiByteKey->setOffset( 0 );
$multiByteKey->setMostSignificantByte( 2 );
$multiByteKey->setLeastSignificantByte( 3 );
$multiByteKey->setDataLength( 16 );
$multiByteKey->setDataType( 'short' );
$decoder = new CentralApps\CAN\Decoder_Multiplex();
$decoder->setMultiplexByte(0);
$decoder->setNameSuffix('_Pison%1$d');
$decoder->add( $multiByteKey );
$units = $decoder->decode( $message );
foreach( $units as $unit )
{
echo $unit;
}
Other notes
This tool makes use of the PSR-0 autoloading "standard", so if you use an autoloader compatible with this you should just be able to drop the code in. If you find you need to support another data type conversion, simply create a new class in the /src/CentralApps/CAN/Decoder/DataTypes folder which implements the Decoder_DataTypes_Interface. If you need to decode information differently, create a new class in /src/CentralApps/CAN/Decoder/Keys which extends the Decoder_Core class. You will need to update the Decider_Factory to correctly build decoder keys of that type.
Posted by Michael on 29th Jan 2012 at 01:01
Leave a comment, there are 0 comments on this entry.
AMQP Conference & 1.0 Launch - New York
Today, myself and Sam Lambert were at the 4th Annual AMQP Conference and Launch of the version 1.0 of the protocol. We were there representing Smith Electric Vehicles, who use StormMQ a cloud based message queue (more on that in a forthcoming post about my work at Smith). AMQP is the "Advanced Message Queueing Protocol" a protocol which is currently in the process of establishing itself as a formal standard through the OASIS group.
Posted by Michael on 13th Oct 2011 at 09:09
Leave a comment, there are 0 comments on this entry.
Speaking at PHPNW11 Unconference
This is just a quick note to say I'll be speaking at PHPNW 2011 in their Unconference track, delivering two 15 minute talks:
- PHP and Continuous Data Processing
- PHP and Twilio
PHP and Continuous Data Processing
At Smith Electric Vehicles, the worlds largest manufacturer of commercial electric vehicles, we run the largest telemetry system outside of Formula 1. This telemetry system involves our vehicles transmitting thousands of pieces of information back to us every second. We need to be able to process this information, keep on top of it, generate reports and calculations and display real-time, historical and analytical data through our web interface for customers, engineers and service technicians. This talk discusses some of the challenges we face and some of the solutions we have both in terms of the system itself and also making PHP play nicely with large volumes of continuously processing information.
PHP and Twilio
Twilio is a set of Infrastructure APIs which allow developers to integrate voice and SMS services into their applications. This includes receiving inbound calls, making outbound calls, transferring calls, processing responses and so on. This talk walks quickly through Twilio and shows how to quickly build a telephone interface for customers to manage their accounts on PHP based systems.
Posted by Michael on 6th Oct 2011 at 06:06
Leave a comment, there are 0 comments on this entry.
Multi-step form navigation jQuery plugin
I was recently creating a system with a multi-step form. The form itself wasn't particularly complicated, it just had a number of steps which the user needed to complete. It didn't make sense for each stage of the form to be a seperate form which is posted to a server, and then fully processed at the end. Instead, it seemed more appropriate to hide each section of the form, except for the current section being completed, using jQuery.
Posted by Michael on 7th Aug 2011 at 01:01
Leave a comment, there are 2 comments on this entry.
Equality South West - recent website release
One of my final few projects working with the team at Peacock Carter has come to a close, following a launch in mid-April, and I wanted to write up a post about the project and my involvement: the website redesign and redevelopment for Equality South West.
Posted by Michael on 6th Jun 2011 at 08:08
Leave a comment, there are 0 comments on this entry.
Moving on to pastures new
After nearly five years at the helm of Peacock Carter I recently decided that it was time for me to move on. I formally handed in my notice to step down from the position of Managing Director and Senior / Lead developer - and at the end of April 2011 I left the business, after handing over my technical duties to Ian and my management duties to Richard.
In the short term, I still have some involvement in the business, as a Non-Executive Director/Technical Consultant and as co-owner, however I've moved on to new opportunities. Due to my integral role in the business, I'm still helping Ian to wind down and complete one or two longer-term projects.
Posted by Michael on 29th May 2011 at 14:02
Leave a comment, there are 0 comments on this entry.
Jenkins CI: An Introduction for PHP Developers
Many of the projects I work on, are tied to some simple home-brew deployment and integrity checks (which I recently discussed at PHP North-East: Automated Deployment talk). These are some nice, simple scripts which quick take code out of version control, move things around, apply database schema changes, and deploy.
For the projects I tend to work on, this approach works well, however these techniques can be further enhanced, by being combined with a Continuous Integration service, such as Jenkins CI. This allows continuous quality control checks to be made against a code base, and allows for deployment scripts to be executed provided a build was successful, and depending on the output of these quality control checks, the build can be marked as failed, stable or unstable.
Through this blog post, I'll go through the steps involved in installing Jenkins, and configuring it with:
- Ant build scripts
- SimpleTest
- PHPDocumentor
- PHP Code Sniffer
I'm writing this blog entry primarily for two reasons: first in the hope that others find it useful; and secondly so I can remember what to do next time I set it up, or run into one of the problems I've mentioned below!
Posted by Michael on 26th Mar 2011 at 08:08
Leave a comment, there are 3 comments on this entry.
PHP North-East: Automated Deployment Talk
This evening, I presented a 25 minute talk on "Automated Deployment Mechanisms with PHP and Linux", which gave an overview of various tips and techniques I currently use to work with deploying websites and web applications on a relatively small scale (i.e. projects which don't warrant large CI servers, or where experience with those is limited). The presentation itself is available on slideshare.
Posted by Michael on 15th Mar 2011 at 11:11
Leave a comment, there are 0 comments on this entry.
PHP North-East March talk
On the 15th of March 2011, I will be delivering the following talk to the PHP North-East user group. If you would like to attend, please book a place through the EventBrite website. You can find out more about PHP North-East through its Google Group.
Posted by Michael on 28th Feb 2011 at 05:05
Leave a comment, there are 3 comments on this entry.
Dynamic routing with PHP
For one reason or another, most of my home-brew code has always used a really basic routing method - if the requested URL (well, technically a $_GET variable set by mod_rewrite) starts with the reference to a controller followed by a forward slash, e.g. blog/some-blog-post-reference, control is passed to that controller. If it doesn't, then the page controller kicks in and looks up the entire URL as a possible page, either rendering it, displaying an authentication message, or displaying a 404 page.
While simple, this approach has worked well. More recently, I've been thinking about making this more dynamic; it is all well and good seperating add-on features such as blog to a seperate URL scheme, but what about if the site in question is a blog, instead of just having a blog?
Posted by Michael on 19th Feb 2011 at 11:11
Leave a comment, there are 6 comments on this entry.
Pages...
Page 1 of 6


