Salve system used to recieve data from line follower and interact with instrument panel.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /** 00002 * File: nxp_can/main.cpp 00003 * 00004 * Author1: Carla Amaya 00005 * Author2: Gerardo Cordero 00006 * Author3: José Pesado 00007 * Author3: Jalil Chávez 00008 * 00009 * Date: October 2014 00010 * Course: Instrumentation 00011 * 00012 * Summary of File: 00013 * 00014 * This file contains code which sends data through 00015 * a CAN bus that is received from a Xbee. This data comes 00016 * from a line follower. 00017 * Rev 0.1 18/10/2014 00018 * - Initial revision 00019 */ 00020 00021 /** 00022 * Header files 00023 */ 00024 #include "mbed.h" 00025 #include "xbee.h" 00026 00027 /** 00028 * Object initialization 00029 */ 00030 Ticker tickerMSG; 00031 DigitalOut aliveIndicator(LED1); 00032 CAN can1(p30, p29); 00033 extern Serial PC; 00034 00035 /** 00036 * Global variable declaration 00037 */ 00038 00039 /* DL B0 B1 B2 B3 B4 B5 B6 B7 */ 00040 static char CBC_PT1[] = {0x08,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00}; 00041 static char CBC_PT2[] = {0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00042 static char ECM_A1[] = {0x08,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00043 static char ESP_A8[] = {0x08,0x22,0xF1,0x22,0x00,0x00,0x00,0x00,0x64}; 00044 00045 uint16_t u16Speed = 0; 00046 uint16_t u16RPM = 0; 00047 char inBuffer[BUFFER_SIZE]={0}; 00048 00049 static CANMessage canmsgCBC_PT1 = CANMessage(0x334,&CBC_PT1[1],CBC_PT1[0],CANData,CANStandard ); 00050 static CANMessage canmsgCBC_PT2 = CANMessage(0x112,&CBC_PT2[1],CBC_PT2[0],CANData,CANStandard ); 00051 static CANMessage canmsgECM_A1 = CANMessage(0x108,&ECM_A1[1],ECM_A1[0],CANData,CANStandard ); 00052 static CANMessage canmsgESP_A8 = CANMessage(0x11C,&ESP_A8[1],ESP_A8[0],CANData,CANStandard ); 00053 00054 /** 00055 * Local function 00056 */ 00057 void sendData() 00058 { 00059 static uint8_t ctr = 0; 00060 can1.frequency(500000); 00061 00062 switch(ctr) 00063 { 00064 case 0: 00065 can1.write( canmsgCBC_PT1 ); 00066 ctr++; 00067 break; 00068 case 1: 00069 u16RPM = 3*(inBuffer[4]<<8)|(inBuffer[3]); 00070 ECM_A1[1]=(char)((u16RPM>>8)&0xFF); 00071 ECM_A1[2]=(char)((u16RPM)&0x00FF); 00072 canmsgECM_A1 = CANMessage(0x108,&ECM_A1[1],ECM_A1[0],CANData,CANStandard ); 00073 can1.write( canmsgECM_A1 ); 00074 ctr++; 00075 break; 00076 case 2: 00077 ESP_A8[4]=inBuffer[2]; 00078 ESP_A8[5]=inBuffer[1]; 00079 canmsgESP_A8 = CANMessage(0x11C,&ESP_A8[1],ESP_A8[0],CANData,CANStandard ); 00080 can1.write( canmsgESP_A8 ); 00081 ctr++; 00082 break; 00083 case 3: 00084 can1.write( canmsgCBC_PT2 ); 00085 ctr=0; 00086 break; 00087 } 00088 } 00089 00090 /** 00091 * Main program 00092 */ 00093 int main() { 00094 /* Start cyclic function */ 00095 tickerMSG.attach(&sendData, 0.01); 00096 /* Main loop */ 00097 XBee_vInit(); 00098 while(1) 00099 { 00100 aliveIndicator = !aliveIndicator; 00101 wait(0.2); 00102 } 00103 }
Generated on Wed Aug 10 2022 10:19:26 by
1.7.2