OBD Source Code -Section 1- Without Car / Section 2 - With car
Dependencies: mbed
main.cpp
00001 00002 /* **************************************************************************************************** 00003 00004 OBD - ACCELEROMETER INTERFACE 00005 00006 **************************************************************************************************** */ 00007 00008 /* 00009 00010 NOTE : 00011 This program aims at interfacing both the OBD scan tool and ADXL345 Accelerometer 00012 Testing the combined application of both in progress 00013 Code is subjected to modification 00014 00015 Date : 25 - Feb - 2017 (Saturday) 00016 Author : BALA 00017 00018 */ 00019 00020 #include "mbed.h" 00021 #include "accelerometer.h" 00022 #include "obd_libraries.h" 00023 #include "common_definitions.h" 00024 00025 //-------------------------------------------------------------------------------------------------------- 00026 00027 I2C i2cm(PB_9, PB_8); 00028 Serial pcm(USBTX, USBRX); 00029 Serial OBD_UARTm(PA_0, PA_1); 00030 00031 //DigitalOut led(LED1); 00032 00033 //InterruptIn double_tap(PC_1); // Pin assignment may vary 00034 //InterruptIn activity_inactivity(PC_0); // Pin assignment may vary 00035 00036 //-------------------------------------------------------------------------------------------------------- 00037 00038 /* THE FOLLOWING DECLARATIONS ARE GLOBAL VARIABLES */ 00039 00040 extern char current_speed, previous_speed; 00041 //extern char speed_threshold = 10; 00042 00043 extern float car_battery_voltage; 00044 extern long vehicle_speed; 00045 00046 extern char OBD_UART_RX_Buffer[50]; 00047 char OBD_RxBuffer_End_Pos = 0; 00048 char OBD_UART_RX_Size = 50; 00049 00050 //extern const int slave_address_acc = 0xA6; 00051 //extern char interrupt_source[2]; 00052 //extern char intr_source_address[2] = {0x30, 0}; 00053 //extern char all_interrupt_clear_command[2] = {0x2E, 0x00}; 00054 //extern char all_interrupt_enable_command[2] = {0x2E, 0x18}; 00055 //extern char activity_interrupt_disable_command[2] = {0x2E, 0x28}; 00056 //extern char inactivity_interrupt_disable_command[2] = {0x2E, 0x30}; 00057 //extern unsigned int interrupt_source_duplicate; 00058 00059 extern char obd_reset_cmd[]; 00060 00061 extern char no_of_stored_dtc; 00062 00063 extern void OBD_onDataRx(); 00064 extern void interrupt_sudden_jerk(); 00065 extern void interrupt_activity_inactivity(); 00066 00067 00068 //********************************************************************************************************* 00069 00070 00071 /* THE FOLLOWING CODE BLOCK IS THE INTERRUPT SERVICE ROTUINE FOR OBD DATA RECEIVE */ 00072 00073 //void OBD_onDataRx() 00074 //{ 00075 // pcm.printf("\r\n ENTERED \r\n"); 00076 // if(OBD_UARTm.readable()) { 00077 // 00078 // pcm.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UARTm.getc()); 00079 // /* 00080 // if(OBD_RxBuffer_End_Pos >= OBD_UART_RX_Size) { 00081 // // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. 00082 // // For now just throw everything away. 00083 // OBD_RxBuffer_End_Pos = 0; 00084 // } 00085 // */ 00086 // } 00087 //} 00088 00089 //********************************************************************************************************* 00090 00091 00092 /* THE FOLLOWING SET OF CODE BLOCKS ARE INTERRUPT SERVICE ROTUINES OF ACCELEROMETER */ 00093 00094 00095 //********************************************************************************************************* 00096 00097 // THE FOLLOWING CODE BLOCK IS THE ISR FOR SUDDEN JERK CONDITION 00098 00099 //void interrupt_sudden_jerk() 00100 //{ 00101 // char count; 00102 // 00103 // i2cm.write(slave_address_acc, all_interrupt_clear_command, 2); 00104 // pcm.printf("~~~ ENTERED SUDDEN JERK CONDITION ~~~\r\n\r\n"); 00105 ///* 00106 // for(count = 0; count < 2; count++) 00107 // { 00108 // led = 1; 00109 // wait(2); 00110 // led = 0; 00111 // wait(1); 00112 // } 00113 //*/ 00114 // i2cm.write(slave_address_acc, all_interrupt_enable_command, 2); 00115 // 00116 //} 00117 00118 //********************************************************************************************************* 00119 // 00120 //// THE FOLLWOING CODE BLOCK IS THE MULITIPLEXED ISR FOR BOTH ACTIVITY & INACTIVITY INTERRUPT 00121 // 00122 //void interrupt_activity_inactivity() 00123 //{ 00124 // char count; 00125 // 00126 // // The following statement disables all interrupts since no other interrupts must disturb at this point 00127 // 00128 // i2cm.write(slave_address_acc, all_interrupt_clear_command, 2); 00129 // 00130 // i2cm.write(slave_address_acc, intr_source_address, 1); 00131 // i2cm.read(slave_address_acc, interrupt_source, 1); 00132 // 00133 // char_to_int(interrupt_source[0]); // Coverts intr_source(char) to int & stores in intr_source_d 00134 // 00135 // pcm.printf("INT Source = "); 00136 // print_data_bits((interrupt_source_duplicate)); 00137 // 00138 ////-------------------------------------------------------------------------------------------------------- 00139 // 00140 // /* VERIFY WHETHER THE INTERRUPT IS BECAUSE OF ACTIVITY */ 00141 // 00142 // //if((((int)intr_source) & 0x10) == 0x10) 00143 // if(interrupt_source_duplicate & 0x10) 00144 // { 00145 // /* THE FOLLOWING BLOCK IS USED JUST FOR VERIFICATION PURPOSE AND ARE NOT MANDATORY */ 00146 ///* 00147 // pcm.printf("ENTERED ACTIVITY CONDITION\r\n\r\n"); 00148 // for(count = 0; count < 10; count++) 00149 // { 00150 // led = !led; 00151 // wait(0.05); 00152 // } 00153 //*/ 00154 // fetch_vehicle_speed(); 00155 // previous_speed = vehicle_speed; 00156 // wait(5); 00157 // fetch_vehicle_speed(); 00158 // current_speed = vehicle_speed; 00159 // 00160 // //if((current_speed > previous_speed) && (current_speed > speed_threshold)) // Decision making regarding vehicle's current state 00161 // if(current_speed == 79) 00162 // { 00163 // i2cm.write(slave_address_acc, activity_interrupt_disable_command, 2); // Disables Activity interrupt & enables Inactivity interrupt 00164 // pcm.printf("\r\n>>> VEHICLE HAS STARTED FROM STOP <<<"); 00165 // } 00166 // } 00167 // 00168 ////-------------------------------------------------------------------------------------------------------- 00169 // 00170 // /* VERIFY WHETHER THE INTERRUPT IS BECAUSE OF INACTIVITY */ 00171 // 00172 // //if((((int)intr_source) & 0x08) == 0x08) // Verify whether it is inactivity interrupt 00173 // if(interrupt_source_duplicate & 0x08) 00174 // { 00175 // /* THE FOLLOWING BLOCK IS USED JUST FOR VERIFICATION PURPOSE AND ARE NOT MANDATORY */ 00176 ///* 00177 // pcm.printf("ENTERED INACTIVITY CONDITION \r\n\r\n"); 00178 // for(count = 0; count < 10; count++) 00179 // { 00180 // led = !led; 00181 // wait(0.2); 00182 // } 00183 //*/ 00184 // fetch_vehicle_speed(); 00185 // 00186 // if(vehicle_speed == 0) // Decision making regarding vehicle's current state 00187 // { 00188 // i2cm.write(slave_address_acc, inactivity_interrupt_disable_command, 2); // Disables Inactivity interrupt & enables Activity interrupt 00189 // pcm.printf("\r\n>>> VEHICLE HAS STOPPED FROM START <<<"); 00190 // } 00191 // } 00192 //} 00193 00194 00195 //********************************************************************************************************* 00196 00197 int main(void) 00198 { 00199 //OBD_UARTm.attach(&OBD_onDataRx); 00200 //activity_inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge 00201 //double_tap.rise(interrupt_sudden_jerk); 00202 00203 pcm.baud(9600); 00204 OBD_UARTm.baud(9600); 00205 00206 00207 pcm.printf("\r\n\r\n\t\t>>>>>------>> OBD - ACCELEROMETER INTERFACE <<------<<<<<\r\n\r\n"); 00208 00209 initialize_obd(); // OBD- scan tool initialization would be done here 00210 00211 fetch_battery_voltage(); // OBD - section 00212 00213 fetch_vin_number(); 00214 00215 fetch_vehicle_speed(); 00216 00217 fetch_engine_rpm(); 00218 00219 //rpm_padding_for_comm_test(); 00220 00221 00222 check_for_MIL(); 00223 00224 check_for_dtc(); 00225 00226 00227 00228 00229 00230 //if(no_of_stored_dtc > 0) 00231 //check_for_dtc(); 00232 //check_for_dtc(); 00233 00234 00235 //initialize_accelerometer(); // All Accerometer configurations will be done here 00236 00237 //while(1); // Wait forever, let the ISR do the rest 00238 00239 00240 return 0; 00241 00242 } 00243 00244 //*********************************************************************************************************
Generated on Sat Jul 23 2022 16:23:23 by
1.7.2