UBR CAN

Dependencies:   mbed

Fork of CAN_bus_reader_pub by Satoshi Nadakiti

main.cpp

Committer:
saharshbishnoi
Date:
2013-11-17
Revision:
1:b57b77b29c7e
Parent:
0:78752077cc25

File content as of revision 1:b57b77b29c7e:

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

ecu_reader obdii(CANSPEED_1M);     //Create object and set CAN speed

//Timer CANTimer;
Timer CANTimer2;

int main() {
    while(1) 
    {  // Main CAN loop
        led2 = 1;
        wait(0.1);
        led2 = 0;
        wait(0.1);
        
        CANTimer2.reset();
        CANTimer2.start();
        pc.printf("CANTimer.start\n");
        
       while (CANTimer2.read_ms() < TIMEOUT) {
            pc.printf("CANTimer.read_ms(): %dms ", CANTimer2.read_ms());
            
            // http://mbed.org/cookbook/OBDII-Can-Bus
            
            if (can2.read(can_MsgRx)) {
                pc.printf("Message read\n\r");
                
                 //print message id
                pc.printf("can_MsgRx.id: %x\n\r", can_MsgRx.id);

                //print length of message
                pc.printf("Hex: can_MsgRx.len: %x\n\r", can_MsgRx.len);

                //print data
                //pc.printf("can_MsgRx.data[2]: %x\n\r", can_MsgRx.data[5]);

                for (int i = 0; i < (int)can_MsgRx.len; i++) {
                    pc.printf("can_MsgRx.data[%d]: %x\n\r", i, can_MsgRx.data[i]);
                }
            }
        }
    }
       
}