CAN-Bus ECU simulator. Only part of the SAE J1979 are implemented. Uses CAN-Bus demo board as hardware platform. http://skpang.co.uk/catalog/canbus-ecu-simulator-with-lpc1768-module-p-1400.html Useful for testing diagnostic tools.

Dependencies:   TextLCD mbed

Fork of ecu_reader by Sukkin Pang

main.cpp

Committer:
pangsk
Date:
2010-07-08
Revision:
0:908be729d27c
Child:
1:3552a3289608

File content as of revision 0:908be729d27c:

/*

mbed Can-Bus demo

This program is to demonstrate the CAN-bus capability of the mbed module.

www.skpang.co.uk/catalog

v1.0 July 2010

********************************************************************************

WARNING: Use at your own risk, sadly this software comes with no guarantees.
This software is provided 'free' and in good faith, but the author does not
accept liability for any damage arising from its use.

********************************************************************************


*/

#include "mbed.h"
#include "ecu_reader.h"
#include "globals.h"
#include "TextLCD.h"
#include "GPS.h"

GPS gps(p28, p27);
TextLCD lcd(p18, p19, p20, p17, p16, p15, p14); // rs, rw, e, d0, d1, d2, d3

DigitalIn click(p21);   // Joystick inputs
DigitalIn right(p22);
DigitalIn down(p23);
DigitalIn left(p24);
DigitalIn up(p25);

ecu_reader obdii(CANSPEED_500);     //Create object and set CAN speed
void gps_demo(void);
void sd_demo(void);

int main() {
    
    char buffer[20];
 
    lcd.locate(0,0);
    lcd.printf("CAN-Bus demo");
    
    lcd.locate(0,1);
    lcd.printf("www.skpang.co.uk");
       
    pc.printf("\n\rCAN-bus demo...");
    
    wait(3);
    lcd.cls();
    lcd.printf("Use joystick");

    lcd.locate(0,1);
    lcd.printf("U-CAN:D-GPS:L-SD");

    while(1)    // Wait until option is selected by the joystick
    {
   
        if(down == 0) gps_demo();
        if(left == 0) sd_demo();
               
        if(up == 0) break;
        
    }
    lcd.cls();

    while(1) {  // Main CAN loop
        led2 = 1;
        wait(0.1);
        led2 = 0;
        wait(0.1);
        
        if(obdii.request(ENGINE_RPM,buffer) == 1)   // Get engine rpm and display on LCD
        {
            lcd.locate(0,0);
            lcd.printf(buffer);
        }   
         
        if(obdii.request(ENGINE_COOLANT_TEMP,buffer) == 1)
        {
            lcd.locate(9,0);
            lcd.printf(buffer);
        }
        
        if(obdii.request(VEHICLE_SPEED,buffer) == 1)
        {
            lcd.locate(0,1);
            lcd.printf(buffer);
        }
     
        if(obdii.request(THROTTLE,buffer) ==1 )
        {
            lcd.locate(9,1);
            lcd.printf(buffer);          
        }   
       
    }
}

void gps_demo(void)
{
    pc.printf("\rGPS demo");
    lcd.cls();
    lcd.printf("GPS demo");
    lcd.locate(0,1);
    lcd.printf("Waiting for lock");
 
    wait(3);    
    lcd.cls();
    
    
    while(1)
    {
      if(gps.sample()) {
         lcd.cls();
        lcd.printf("Long:%f", gps.longitude);
           lcd.locate(0,1);
        lcd.printf("Lat:%f", gps.latitude);
            pc.printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
        } else {
            pc.printf("Oh Dear! No lock :(\n");
            lcd.cls();
            lcd.printf("Waiting for lock");
     
 
    
        }
    
    
    }
 
}

void sd_demo(void)
{
    pc.printf("\rSD demo");
    
    lcd.cls();
    lcd.printf("Use joystick");
    wait(3);      
    while(1)
    {
    
    
    
    }
 
}