Salve system used to recieve data from line follower and interact with instrument panel.

Dependencies:   XBEE_NXP mbed

Committer:
JalilChavez
Date:
Mon Oct 20 07:08:29 2014 +0000
Revision:
0:c10ecc0e855e
Program used to receive data from line follower and display on instrument panel.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JalilChavez 0:c10ecc0e855e 1 /**
JalilChavez 0:c10ecc0e855e 2 * File: nxp_can/main.cpp
JalilChavez 0:c10ecc0e855e 3 *
JalilChavez 0:c10ecc0e855e 4 * Author1: Carla Amaya
JalilChavez 0:c10ecc0e855e 5 * Author2: Gerardo Cordero
JalilChavez 0:c10ecc0e855e 6 * Author3: José Pesado
JalilChavez 0:c10ecc0e855e 7 * Author3: Jalil Chávez
JalilChavez 0:c10ecc0e855e 8 *
JalilChavez 0:c10ecc0e855e 9 * Date: October 2014
JalilChavez 0:c10ecc0e855e 10 * Course: Instrumentation
JalilChavez 0:c10ecc0e855e 11 *
JalilChavez 0:c10ecc0e855e 12 * Summary of File:
JalilChavez 0:c10ecc0e855e 13 *
JalilChavez 0:c10ecc0e855e 14 * This file contains code which sends data through
JalilChavez 0:c10ecc0e855e 15 * a CAN bus that is received from a Xbee. This data comes
JalilChavez 0:c10ecc0e855e 16 * from a line follower.
JalilChavez 0:c10ecc0e855e 17 * Rev 0.1 18/10/2014
JalilChavez 0:c10ecc0e855e 18 * - Initial revision
JalilChavez 0:c10ecc0e855e 19 */
JalilChavez 0:c10ecc0e855e 20
JalilChavez 0:c10ecc0e855e 21 /**
JalilChavez 0:c10ecc0e855e 22 * Header files
JalilChavez 0:c10ecc0e855e 23 */
JalilChavez 0:c10ecc0e855e 24 #include "mbed.h"
JalilChavez 0:c10ecc0e855e 25 #include "xbee.h"
JalilChavez 0:c10ecc0e855e 26
JalilChavez 0:c10ecc0e855e 27 /**
JalilChavez 0:c10ecc0e855e 28 * Object initialization
JalilChavez 0:c10ecc0e855e 29 */
JalilChavez 0:c10ecc0e855e 30 Ticker tickerMSG;
JalilChavez 0:c10ecc0e855e 31 DigitalOut aliveIndicator(LED1);
JalilChavez 0:c10ecc0e855e 32 CAN can1(p30, p29);
JalilChavez 0:c10ecc0e855e 33 extern Serial PC;
JalilChavez 0:c10ecc0e855e 34
JalilChavez 0:c10ecc0e855e 35 /**
JalilChavez 0:c10ecc0e855e 36 * Global variable declaration
JalilChavez 0:c10ecc0e855e 37 */
JalilChavez 0:c10ecc0e855e 38
JalilChavez 0:c10ecc0e855e 39 /* DL B0 B1 B2 B3 B4 B5 B6 B7 */
JalilChavez 0:c10ecc0e855e 40 static char CBC_PT1[] = {0x08,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00};
JalilChavez 0:c10ecc0e855e 41 static char CBC_PT2[] = {0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
JalilChavez 0:c10ecc0e855e 42 static char ECM_A1[] = {0x08,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
JalilChavez 0:c10ecc0e855e 43 static char ESP_A8[] = {0x08,0x22,0xF1,0x22,0x00,0x00,0x00,0x00,0x64};
JalilChavez 0:c10ecc0e855e 44
JalilChavez 0:c10ecc0e855e 45 uint16_t u16Speed = 0;
JalilChavez 0:c10ecc0e855e 46 uint16_t u16RPM = 0;
JalilChavez 0:c10ecc0e855e 47 char inBuffer[BUFFER_SIZE]={0};
JalilChavez 0:c10ecc0e855e 48
JalilChavez 0:c10ecc0e855e 49 static CANMessage canmsgCBC_PT1 = CANMessage(0x334,&CBC_PT1[1],CBC_PT1[0],CANData,CANStandard );
JalilChavez 0:c10ecc0e855e 50 static CANMessage canmsgCBC_PT2 = CANMessage(0x112,&CBC_PT2[1],CBC_PT2[0],CANData,CANStandard );
JalilChavez 0:c10ecc0e855e 51 static CANMessage canmsgECM_A1 = CANMessage(0x108,&ECM_A1[1],ECM_A1[0],CANData,CANStandard );
JalilChavez 0:c10ecc0e855e 52 static CANMessage canmsgESP_A8 = CANMessage(0x11C,&ESP_A8[1],ESP_A8[0],CANData,CANStandard );
JalilChavez 0:c10ecc0e855e 53
JalilChavez 0:c10ecc0e855e 54 /**
JalilChavez 0:c10ecc0e855e 55 * Local function
JalilChavez 0:c10ecc0e855e 56 */
JalilChavez 0:c10ecc0e855e 57 void sendData()
JalilChavez 0:c10ecc0e855e 58 {
JalilChavez 0:c10ecc0e855e 59 static uint8_t ctr = 0;
JalilChavez 0:c10ecc0e855e 60 can1.frequency(500000);
JalilChavez 0:c10ecc0e855e 61
JalilChavez 0:c10ecc0e855e 62 switch(ctr)
JalilChavez 0:c10ecc0e855e 63 {
JalilChavez 0:c10ecc0e855e 64 case 0:
JalilChavez 0:c10ecc0e855e 65 can1.write( canmsgCBC_PT1 );
JalilChavez 0:c10ecc0e855e 66 ctr++;
JalilChavez 0:c10ecc0e855e 67 break;
JalilChavez 0:c10ecc0e855e 68 case 1:
JalilChavez 0:c10ecc0e855e 69 u16RPM = 3*(inBuffer[4]<<8)|(inBuffer[3]);
JalilChavez 0:c10ecc0e855e 70 ECM_A1[1]=(char)((u16RPM>>8)&0xFF);
JalilChavez 0:c10ecc0e855e 71 ECM_A1[2]=(char)((u16RPM)&0x00FF);
JalilChavez 0:c10ecc0e855e 72 canmsgECM_A1 = CANMessage(0x108,&ECM_A1[1],ECM_A1[0],CANData,CANStandard );
JalilChavez 0:c10ecc0e855e 73 can1.write( canmsgECM_A1 );
JalilChavez 0:c10ecc0e855e 74 ctr++;
JalilChavez 0:c10ecc0e855e 75 break;
JalilChavez 0:c10ecc0e855e 76 case 2:
JalilChavez 0:c10ecc0e855e 77 ESP_A8[4]=inBuffer[2];
JalilChavez 0:c10ecc0e855e 78 ESP_A8[5]=inBuffer[1];
JalilChavez 0:c10ecc0e855e 79 canmsgESP_A8 = CANMessage(0x11C,&ESP_A8[1],ESP_A8[0],CANData,CANStandard );
JalilChavez 0:c10ecc0e855e 80 can1.write( canmsgESP_A8 );
JalilChavez 0:c10ecc0e855e 81 ctr++;
JalilChavez 0:c10ecc0e855e 82 break;
JalilChavez 0:c10ecc0e855e 83 case 3:
JalilChavez 0:c10ecc0e855e 84 can1.write( canmsgCBC_PT2 );
JalilChavez 0:c10ecc0e855e 85 ctr=0;
JalilChavez 0:c10ecc0e855e 86 break;
JalilChavez 0:c10ecc0e855e 87 }
JalilChavez 0:c10ecc0e855e 88 }
JalilChavez 0:c10ecc0e855e 89
JalilChavez 0:c10ecc0e855e 90 /**
JalilChavez 0:c10ecc0e855e 91 * Main program
JalilChavez 0:c10ecc0e855e 92 */
JalilChavez 0:c10ecc0e855e 93 int main() {
JalilChavez 0:c10ecc0e855e 94 /* Start cyclic function */
JalilChavez 0:c10ecc0e855e 95 tickerMSG.attach(&sendData, 0.01);
JalilChavez 0:c10ecc0e855e 96 /* Main loop */
JalilChavez 0:c10ecc0e855e 97 XBee_vInit();
JalilChavez 0:c10ecc0e855e 98 while(1)
JalilChavez 0:c10ecc0e855e 99 {
JalilChavez 0:c10ecc0e855e 100 aliveIndicator = !aliveIndicator;
JalilChavez 0:c10ecc0e855e 101 wait(0.2);
JalilChavez 0:c10ecc0e855e 102 }
JalilChavez 0:c10ecc0e855e 103 }