VAN bus

Talk about the 406's electrical system, what wires do what, how to add extra functionality, etc.

Moderator: Moderators

User avatar
Captain Jack
3.0 24v
Posts: 3820
Joined: Sun Aug 07, 2005 11:26 am
Location: Langford, Somerset

Re: VAN bus

Post by Captain Jack »

Oh noes... C code.... :|

Would be nice to have a USB dongle to interface decoded VAN data with a PC. Could have a LOT of fun with it... 8)
2003 - 2008: 1998 Peugeot 406 2.1 TD 110bhp LX Saloon
2008 - 2009: 2004 Honda Accord 2.2 CDTI 136bhp Executive Saloon
2009 - 2013: 2002 Peugeot 406 2.0 HDI 110bhp Executive Saloon
2013 - 2021: 2007 Peugeot 407 2.2 HDI 170bhp Executive Saloon (mapped to 213bhp :twisted:)
2021 - ????: 2016 Ford Mondeo 2.0 TDCi 180bhp Titanium
User avatar
mjb
Site Admin
Posts: 7983
Joined: Wed May 31, 2006 9:06 pm
Location: Stoke

Re: VAN bus

Post by mjb »

Captain Jack wrote:Oh noes... C code.... :|
You'll have fun trying to find a better language for writing device drivers in :roll:
Would be nice to have a USB dongle to interface decoded VAN data with a PC. Could have a LOT of fun with it... 8)
Heh don't expect a windows point-and-click app any time soon :lol:
<steve_earwig> I think this forum is more about keeping our cars going with minimal outlay than giving our cars more reason to go bang
auldy
1.8 8v
Posts: 25
Joined: Thu Jul 16, 2009 8:50 pm
Location: Hampshire
Contact:

Re: VAN bus

Post by auldy »

those FTDI chips are fairly well supported, which OS are you using? Mac/BSD I guess?

I've revised the board slightly to give larger clearances making them much easier to solder and add a ground pin to the VAN port that I missed on revision 1. [PM]

BOM for my design is below - note C5&C6 are mistakenly 100nF in the schematic on my website! They should be 47pF or so.
They're only for EMI reduction on the USB data lines so you could get away with 22pF or even nothing if you're daring.

R1 - 10k 0805
D1 - 1n4148 or similar diode 0805
C1,C2 - 22pF 0805
C3 - 10uF tantalum Case A (1-10uF really)
C4,C7,C8,C9 - 100nF 0805
C5,C6 - 47pF 0805
L1 - Ferrite bead chip inductor 0805 (can get away without)
Y1 - 10MHz Crystal HC49/4
U1 - PIC 18F2620 or 18LF2620 SOIC 28
U2 - MCP2551 DIP300 or similar CAN tranciever
U3 - FT232RL ssop28
Saloon 52 plate Pug 406 HDI GLX, silver - the same colour as everyone else...
auldy
1.8 8v
Posts: 25
Joined: Thu Jul 16, 2009 8:50 pm
Location: Hampshire
Contact:

Re: VAN bus

Post by auldy »

mjb wrote:Heh don't expect a windows point-and-click app any time soon :lol:
point & click is overrated... ---auldy gets busy coding a nice terminal front end for bus decoding--- 8)
Saloon 52 plate Pug 406 HDI GLX, silver - the same colour as everyone else...
User avatar
mjb
Site Admin
Posts: 7983
Joined: Wed May 31, 2006 9:06 pm
Location: Stoke

Re: VAN bus

Post by mjb »

auldy wrote:those FTDI chips are fairly well supported, which OS are you using? Mac/BSD I guess?
FreeBSD, aye. I try to avoid Linux wherever I can as it's just messy crap with too much random shite haphazardly piled on top and has far too many completely clueless zealots advocating its use everywhere. I can rant for weeks on the subject :oops:
BOM for my design is below - note C5&C6 are mistakenly 100nF in the schematic on my website! They should be 47pF or so.
Good job I never got round to finishing off the order eh? :lol:
<steve_earwig> I think this forum is more about keeping our cars going with minimal outlay than giving our cars more reason to go bang
auldy
1.8 8v
Posts: 25
Joined: Thu Jul 16, 2009 8:50 pm
Location: Hampshire
Contact:

Re: VAN bus

Post by auldy »

No updates tomorrow - I promise!

Schematic updated on website to correct capacitor mistake as mentioned before.

This evening I've been working on code for the PC to make it easier to monitor the VAN in real time.
It is of course a command line app :mrgreen:

http://graham.auld.me.uk/projects/vanbus/van-pc.html has been updated and now has a screen shot: Image along with a link to download the current version http://graham.auld.me.uk/projects/vanbus/vandecode.perl

Any suggestions on improvements would be good at this point.

What I have so far:
  • accepts the datastream from serial port or file,
  • displays packets at locations on screen based on their ident
  • highlights first appearance of a packet all in red
  • highlights a changed nibble in red
  • will show unknown idents too
  • can choose packet while running to be looked at closer (scroll thru IDENTS with ctrl+\)
  • selected packet highlighted in green
I consider my code to be a delightful mix of elegant design and nasty nasty hacks so take it as you will please.

My intention is to now use this to discover more of the unknown info by watching for any data that changes in response to an input in the car - wiper stalk, clutch pedal, lock unclock etc
I still need to add subroutines to decode what I already know about and perhaps mask out or at least colour that information grey so it's no longer distracting.

Now: sleep :?
Saloon 52 plate Pug 406 HDI GLX, silver - the same colour as everyone else...
User avatar
mjb
Site Admin
Posts: 7983
Joined: Wed May 31, 2006 9:06 pm
Location: Stoke

Re: VAN bus

Post by mjb »

ANSI HELL!!! :lol:

Couple of little code pointers (since I can't get frames yet):

1. Why the & when calling functions? You only need to use & when chucking around references, as in your signal handlers

2. I hate big lists of elsifs and hard-coded stuff. The whole load of elsif($ident eq 'xxx'){}... what about

Code: Select all

my %ident_lookup = ( '4D4' => { pos=>2,  name=>'Audio Settings'},
                     '4DC' => { pos=>3,  name=>'Air Con'},
                     '4EC' => { pos=>4,  name=>'CDC Info'},
                     ...
                     '9C4' => { pos=>23, name=>'Radio Remote', handler=>\&decode9C4},
                     ...
                     'unk' => { pos=>27, name=>'Unknown Ident'}
                    );
...
$this_ident = $ident_lookup{$ident} || $ident_lookup{'unk'};
difprint($this_ident{pos}, $linecol, $this_ident{name},$ident,$atr,$data,$ack);
...
sub focusdecode {
  ...
   if($ident_lookup{$ident}{'handler'}) {
      &{$ident_lookup{$ident}{'handler'}}($dataToPassIn)
   }
   ...

3. Instead of the select, it's cleaner to just use Time::HiRes qw(sleep) and call sleep 0.0001, or use its usleep...

4. use strict; Always! 8)

I think I'm really starting to dislike perl nowadays.
<steve_earwig> I think this forum is more about keeping our cars going with minimal outlay than giving our cars more reason to go bang
auldy
1.8 8v
Posts: 25
Joined: Thu Jul 16, 2009 8:50 pm
Location: Hampshire
Contact:

Re: VAN bus

Post by auldy »

ha ha, firstly I have a package ready to post for you, haven't checked my PP account yet.

1. I've settled on the convention of using &'s for all my function calls because IMHO it helps with readability.

2. The hash lookup is a great idea, as you might imagine the code has been hacked together bit by bit so yes I extended a short list of elsif's to a long one in quite short order!

3. meh - apples & pairs. :|

4. yeah, strict comes and goes in my code depending on how much of a hack-it-together-hurry I'm in, I'll get to that. It does of course spoil one of the 'features' of perl - allowing you to throw together some pretty nasty but functional code.

I'm busy all this weekend but I suspect I'll have some updated code around the start of next week and hopefully some more decodes for the website.
Saloon 52 plate Pug 406 HDI GLX, silver - the same colour as everyone else...
User avatar
mjb
Site Admin
Posts: 7983
Joined: Wed May 31, 2006 9:06 pm
Location: Stoke

Re: VAN bus

Post by mjb »

auldy wrote:ha ha, firstly I have a package ready to post for you, haven't checked my PP account yet.
I'll try to remember to send it tomorrow.... :oops: My memory's terrible :cry:
4. yeah, strict comes and goes in my code depending on how much of a hack-it-together-hurry I'm in, I'll get to that. It does of course spoil one of the 'features' of perl - allowing you to throw together some pretty nasty but functional code.
*cough* :oops:

Code: Select all

perl -e 'use Time::HiRes qw{usleep};@states=("usr","nic","sys","idl","io","irq","softirq");while(1){
open S,"/proc/stat";@c=<S>;close S;(undef,$usr,$nic,$sys,$idl,$io,$irq,$softirq)=split/\s+/,$c[0];$t=0;
foreach(@states){${"d".$_}=$$_-${"o".$_};$t+=${"d".$_}}foreach(@states){
printf("%-50s|","*"x(int((${"d".$_}/$t)*50)));${"o".$_}=$$_}print"\n";usleep 5000}'
Shows the individual cpu states of a Linux box in 1/200s resolution in a bar chart format. Requires a 357 character wide terminal although you can drop the 50's down to make it less wide.

It'd never, ever run with strict with the dynamic variable names :lol:

(In case you're wondering I was trying to locate the source of stuttering video on a MythTV box. Turned out to be bad IDE tuning parameters causing the ringbuffer write to hog the CPU for around 1/50th of a second every so often. And I wrote it while very, VERY drunk :shock: :shock: :shock:)

Nowadays I have to maintain absolutely shedloads of hacked-together perl written by different people as part of my day job, so readability's become massively important to me as I keep having to refactor/rewrite stuff to make it maintainable :(
<steve_earwig> I think this forum is more about keeping our cars going with minimal outlay than giving our cars more reason to go bang
Post Reply