Qmax / Mbed 2 deprecated OBD_Accelerometer_Interface

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers obd_libraries.cpp Source File

obd_libraries.cpp

00001 
00002 /*
00003 
00004 THE FILE CONTAINS TWO SEPARATE SECTIONS
00005 
00006 COMMENT ANY ONE OF THE FOLLWOING BEFORE PROCEEDING
00007 
00008 THE FOLLWOING CODE WORKS WITHOUT A CAR
00009 NECESSARY DATA ARE STORED IN VIRTUAL BUFFER FOR PROCESSING
00010 
00011 */
00012 
00013 #include "mbed.h"
00014 #include "obd_libraries.h"
00015 #include "common_definitions.h"
00016 
00017 Serial pco(USBTX, USBRX);
00018 Serial OBD_UART(PA_0, PA_1);
00019 
00020 char pass = 0;
00021 char reception_complete = 0;
00022 
00023 char obd_reset_cmd[]            =   "ATZ\r";
00024 char battery_voltage_cmd[]      =   "ATRV\r";
00025 char protocol_auto_detect_cmd[] =   "ATSP0\r";
00026 char read_CAN_protocol_cmd[]    =   "ATDPN\r";
00027 char allow_long_cmd[]           =   "ATAL\r";
00028 char engine_rpm_cmd[]           =   "010C\r";
00029 char vehicle_speed_cmd[]        =   "010D\r";
00030 char vin_number_cmd[]           =   "0902 5\r";
00031 char check_dtc_cmd[]            =   "03\r";
00032 char check_mil_cmd[]            =   "0101\r";
00033 
00034 char no_of_stored_dtc;
00035 
00036 float car_battery_voltage;
00037 long vehicle_speed;
00038 char OBD_UART_RX_Buffer[50];
00039 extern char OBD_RxBuffer_End_Pos;
00040 //char OBD_UART_RX_Size = 50;
00041 
00042 
00043 //Serial pco(USBTX, USBRX);
00044 //Serial OBD_UART(PA_0, PA_1);
00045 
00046 void OBD_onDataRx()
00047 {
00048     //pcm.printf("\r\n ENTERED \r\n");
00049      if(OBD_UART.readable()) {
00050        
00051         pco.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UART.getc());
00052         /*
00053         if(OBD_RxBuffer_End_Pos >= OBD_UART_RX_Size) {
00054             // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation.
00055             // For now just throw everything away.
00056             OBD_RxBuffer_End_Pos  = 0;
00057         }
00058         */
00059     }
00060 }
00061 
00062 
00063 //************************************************************************************************************************
00064 
00065 void received_data_verification(char *rcv_data_pointer, char *ref_data_pointer, char num)
00066 {
00067     char dummy_data[num], count;
00068     for(count = 0; count < num; count++)
00069     {
00070         pco.putc(*rcv_data_pointer);
00071         if(*rcv_data_pointer++ == *ref_data_pointer++)
00072             pass = 1;
00073         else   
00074         {
00075             pass = 0;
00076             return;
00077         }
00078     } 
00079 }
00080       
00081 //************************************************************************************************************************
00082 /*
00083 char* copy_characters(char *copy_char_pointer, char start_position, char end_position)
00084 {
00085     char total_num;
00086     char count;
00087     total_num = end_position - start_position;
00088     char copied_data[total_num];
00089     copy_char_pointer += start_position;
00090     
00091     for(count = 0; count < total_num; count++)
00092     {
00093         copied_data[count] = *copy_char_pointer++;
00094     }
00095     
00096     pco.printf("\r\n%s", copied_data);
00097     
00098     copy_char_pointer = copied_data;    // Shifting the pointer to copied_data array
00099     
00100     return copy_char_pointer;
00101 }
00102 */        
00103     
00104 
00105 //************************************************************************************************************************
00106 
00107 void process_battery_voltage(char *battery_voltage_pointer)
00108 {
00109     char battery_voltage_data[4];   // One decimal point precision ( For ex : 12.5 )
00110     char count;
00111     battery_voltage_pointer += 5;   // ATRV<CR> counts to 5
00112     for(count = 0; count < 4; count++)
00113     {
00114         battery_voltage_data[count] = *battery_voltage_pointer++;
00115     }
00116     car_battery_voltage = atof(battery_voltage_data);   // Converts the Battery Volatge from String to Float data type
00117     
00118     printf("\r\nCAR BATTERY VOLTAGE = %f",car_battery_voltage);
00119 }
00120 
00121 //************************************************************************************************************************
00122 
00123 void process_vehicle_speed(char *vehicle_speed_pointer)
00124 {
00125     char vehicle_speed_data[2];     // Vehicle speed data is returned by a 2 byte value
00126     char *strtol_pointer;
00127     char count;
00128     //"010D\r41 0D 4F\r\r>"
00129     vehicle_speed_pointer += 11;
00130     for(count = 0; count < 2; count++)
00131     {
00132         vehicle_speed_data[count] = *vehicle_speed_pointer++;
00133     }
00134     
00135     vehicle_speed =  strtol(vehicle_speed_data, &strtol_pointer, 16);
00136     
00137     printf("\r\nVEHICLE SPEED = %ld", vehicle_speed);
00138 }
00139 
00140 //************************************************************************************************************************
00141 
00142 void process_mil_data(char *mil_data_pointer)
00143 {
00144     char mil_data[2], mil_data_converted;
00145     char count;
00146     
00147     // char virtual_mil_buffer = "0101\r41 01 00 04 60 00 \r\r";
00148     mil_data_pointer += 11;
00149     
00150     for(count = 0; count < 2; count++)
00151     {
00152         mil_data[count] = *mil_data_pointer++;
00153     }
00154     
00155     mil_data_converted = (((mil_data[0] - 0x30)<<4) + (mil_data[1] - 0x30)); // Converting the ASCII data to the Hex data
00156     
00157     // The following code lines checks for the number of Mal function indicator lamp enabled by tghe CAN ECU
00158     
00159     if(mil_data_converted & 0x80) // Checks for the MSB bit enabled or not which inc=dicates that the MIL is On or NOT
00160     {
00161         pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS ON");
00162         no_of_stored_dtc = (mil_data_converted & 0b01111111);
00163         pco.printf("\r\n NO OF STORED DYNAMIC TROUBLE CODE = %d", no_of_stored_dtc);
00164     }
00165     else
00166         pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS OFF");
00167 }
00168 
00169 //************************************************************************************************************************
00170 
00171 void process_dtc_data(char *dtc_data_pointer)   // Incomplete Code block
00172 {
00173 /*
00174      char i;
00175      for(i = 0; i<14; i++)
00176      {
00177          pco.printf("\r\nData = %c", *(dtc_data_pointer+i));
00178      }
00179 */     
00180      // char virtual_dtc_buffer[] = "03\r43 00 85\r\r>";
00181      char count1, count2, count_bytes = 0; 
00182      //char dtc_data_raw[5];
00183      char dtc_data[2];                  // Since each DTC needs 2 bytes to make the code
00184      //pco.printf("\r\n String Length = %d", strlen(dtc_data_pointer));
00185      dtc_data_pointer += 6;             // Neglecting the preceding data to scroll to the actual data having some meaning 
00186      
00187      //char dtc_codes[no_of_stored_dtc * 5]; // Since each DTC requires 5 characters to display
00188      
00189      char dtc_codes[5];
00190      
00191 
00192      //pco.printf("\r\n String Length = %d", strlen(dtc_data_pointer));
00193      for(count1 = 0; count1 < (strlen(dtc_data_pointer)); count1++)
00194      {
00195          
00196          if(*(dtc_data_pointer + count1) != '\r'){
00197             count_bytes++;}
00198             //pco.printf("\r\nData = %c Count Bytes = %d", *(dtc_data_pointer+count1), count_bytes); }   // To be commented
00199          else
00200             break;
00201      }
00202      //pco.printf("\r\nDATA POINTER POINTING TO : %c", *dtc_data_pointer);
00203      //pco.printf("\r\nCount Bytes = %d", count_bytes);   // To be commented
00204 
00205 
00206 //-------------------------------------------------------------------------------------------------------------------------------------------------
00207 
00208 /*
00209 
00210 FORMULA:
00211 t = total bytes of returned data
00212 n = no of dtc
00213 
00214 t = 2n + (n -1) , where (n-1) indicates the added spaces between two bytes
00215 t = 3n -1
00216 
00217 Therefore, n = (t + 1) / 3
00218      
00219 */  
00220      if(((count_bytes + 1)/3) == no_of_stored_dtc)
00221         pco.printf("\r\nNO OF STORED DTC MATCHES WITH THE DTC CODE RETURNED");
00222      else
00223         pco.printf("\r\nNO OF STORED DTC DOESNT MATCH WITH THE DTC DATA RETURNED");
00224      /*
00225      pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00226      pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00227      pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00228      pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00229      pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30));
00230      */ 
00231      dtc_data_pointer -= 4;
00232      
00233 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00234 //                VERIFIED UPTO THIS LEVEL      
00235 
00236  for(count1 = 0; count1 < no_of_stored_dtc; count1++)
00237      {
00238          for(count2 = 0; count2 < 2; count2++)
00239          {
00240             //dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data
00241             dtc_data[count1] = *dtc_data_pointer++;
00242             //pco.printf("\r\nData = %c", dtc_data[count1]);
00243          }
00244          /*
00245          char a[2];
00246          a[0] = 'B';
00247          a[1] = 'G';
00248          pco.printf("\r\nData = %s", a);
00249          */
00250          //dtc_data_pointer += 2;
00251          dtc_data_pointer++;
00252 
00253 
00254 /*     
00255      for(count1 = 0; count1 < no_of_stored_dtc; count1++)
00256      {
00257          for(count2 = 0; count2 < 3; count2++)
00258          {
00259             if((*(dtc_data_pointer + count1)) != ' ') {
00260                 dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data
00261                 pco.printf("\r\nData = %c", *(dtc_data_pointer + count1)); }
00262             else {
00263                 dtc_data_pointer += 3;
00264                 break; }
00265          }
00266 */  
00267      
00268 /*
00269      for(count1 = 0; count1 < count_bytes; count1++)
00270         pco.printf("\r\n DTC Bytes = %c+%d", *dtc_data_pointer, (*(dtc_data_pointer++) - 0x30));
00271      
00272      // The following lines of code copy the data pointed by dtc_data_pointer to the dtc_data array
00273      for(count1= 0; count1 < no_of_stored_dtc; count1++)
00274      {
00275          for(count2 = 0; count2 < 2; count2++)
00276          {
00277             dtc_data[count2] = *(dtc_data_pointer + count2);
00278          }
00279          pco.printf("\r\nDTC DATA >>>> %c", dtc_data[1]);
00280          dtc_data_pointer += 1; // To skip the space present between two DTC data
00281 */         
00282          switch((dtc_data[0] & 0x11000000) >> 6)
00283          {
00284              case 0:
00285              dtc_codes[count1*5] = 'P';
00286              break;
00287              
00288              case 1:
00289              dtc_codes[count1*5] = 'C';
00290              break;
00291              
00292              case 2:
00293              dtc_codes[count1*5] = 'B';
00294              break;
00295              
00296              case 3:
00297              dtc_codes[count1*5] = 'U';
00298              break;
00299          }
00300          
00301 //         dtc_codes[(count1*5)+1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); 
00302 //         dtc_codes[(count1*5)+2] = ((dtc_data[0] & 0b00001111) + 0x30);
00303 //         dtc_codes[(count1*5)+3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30);
00304 //         dtc_codes[(count1*5)+4] = ((dtc_data[1] & 0b00001111) + 0x30);
00305          dtc_codes[1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); 
00306          dtc_codes[2] = ((dtc_data[0] & 0b00001111) + 0x30);
00307          dtc_codes[3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30);
00308          dtc_codes[4] = ((dtc_data[1] & 0b00001111) + 0x30);
00309          
00310          pco.printf("\r\n DTC CODE NO %d : %s", count1+1, dtc_codes);    
00311          
00312      }   
00313 }
00314 
00315 
00316 //************************************************************************************************************************
00317 
00318 void process_engine_rpm(char *rpm_data_pointer)
00319 {
00320     //char virtual_engine_rpm[] = "010C\r41 0C 00 00 \r\r>";
00321     char engine_rpm[4];     // Vehicle speed data is returned by a 4 byte value
00322     long rpm;
00323     char *strtol_pointer;
00324     char count;
00325     char internal_count = 0;
00326     
00327     rpm_data_pointer += 11;
00328     
00329     for(count = 0; count < 5; count++)
00330     {
00331         if(*rpm_data_pointer == ' ') {        // Negate the spaces added in between
00332             rpm_data_pointer++;
00333             continue; }
00334         else {
00335             engine_rpm[internal_count] = *rpm_data_pointer++;
00336             internal_count++; }
00337     }
00338     
00339     pco.printf("\r\n%s", engine_rpm);
00340     
00341     rpm =  ((strtol(engine_rpm, &strtol_pointer, 16)) / 4);
00342     
00343     pco.printf("\r\nENGINE RPM = %ld", rpm);
00344     
00345 }
00346 
00347 
00348 //************************************************************************************************************************
00349 
00350 void fetch_battery_voltage()
00351 {
00352     char count;
00353     //OBD_UART.printf(battery_voltage_cmd);
00354     //OBD_UART.putc('\r');
00355     for(count = 0; count < strlen(battery_voltage_cmd); count++)
00356         OBD_UART.putc(battery_voltage_cmd[count]);
00357     wait(1);                               
00358     //pco.printf("\r\n\r\nEnd Position = %d\r\n", OBD_RxBuffer_End_Pos);
00359     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00360     pco.printf("Reception Complete\r\n");
00361     received_data_verification(OBD_UART_RX_Buffer, battery_voltage_cmd, (strlen(battery_voltage_cmd)-1));
00362     
00363     process_battery_voltage(OBD_UART_RX_Buffer);
00364 
00365     if(pass == 1)
00366         printf("\r\nOBD READ BATTERY VOLTAGE SUCCESSFUL \r\n\r\n");
00367     else
00368         printf("\r\nOBD READ BATTERY VOLTAGE FAILED \r\n\r\n");
00369     reception_complete = 0;     // Disabling the reception complete flag
00370     OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
00371 }
00372     
00373 //************************************************************************************************************************   
00374 
00375 void fetch_vehicle_speed()
00376 {
00377     char virtual_rx_speed_buffer[] = "010D\r41 0D 4F \r\r>";     
00378     /*
00379     OBD_UART.printf(vehicle_speed_cmd);
00380     wait(1);
00381     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00382     pco.printf("Reception Complete\r\n");
00383     received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1));
00384     */
00385     process_vehicle_speed(virtual_rx_speed_buffer);
00386 
00387     if(pass == 1)
00388         printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n");
00389     else
00390         printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n");
00391     reception_complete = 0;     // Disabling the reception complete flag
00392     OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
00393 
00394 }  
00395 
00396 //************************************************************************************************************************
00397 
00398 void fetch_vin_number()
00399 {
00400     char count;
00401     char virtual_rx_vin_buffer[] = "0902 5\r014 \r0: 49 02 01 54 4D 42 \r1: 46 4B 4A 35 4A 32 43 \r2: 47 30 31 34 37 33 33 \r\r>"; 
00402     /*
00403     for(count = 0; count < strlen(vin_number_cmd); count++)
00404         OBD_UART.putc(vin_number_cmd[count]);
00405     */
00406     char vin_buffer[100];
00407     char *vin_data_pointer;
00408     char internal_counter = 0;
00409     char small_buffer[2];
00410     long ascii_converted_data;
00411     char *vin_conv_pointer;
00412     char vin_number[17];
00413     
00414     vin_data_pointer = virtual_rx_vin_buffer;
00415     vin_data_pointer += 23;
00416     
00417     int length;
00418     for(count = 0; count < (strlen(virtual_rx_vin_buffer) - 1); count++)
00419     {
00420         if((*vin_data_pointer == '\r') | (*vin_data_pointer == ' ') | (*vin_data_pointer == '>'))
00421         {
00422             vin_data_pointer++;
00423             continue;
00424         }
00425         else if(*(vin_data_pointer + 1) == ':')
00426         {
00427             vin_data_pointer += 2;
00428             continue;
00429         }
00430         else
00431         {
00432             //printf("\r\ncount2 = %d", count); 
00433             vin_buffer[internal_counter] = *vin_data_pointer;
00434             internal_counter++;
00435         }
00436         vin_data_pointer++;
00437     }
00438     
00439     length = strlen(vin_buffer);
00440     pco.printf("\r\n VIN BUFFER LENGTH = %d", length);
00441     
00442     pco.printf("\r\n VIN NUMBER : %s", vin_buffer);
00443     
00444     internal_counter = 0;
00445     
00446     for(count = 0; count < strlen(vin_buffer); count+=2)
00447     {
00448         small_buffer[0] = vin_buffer[count];
00449         small_buffer[1] = vin_buffer[count+1];
00450         ascii_converted_data =  strtol(small_buffer, &vin_conv_pointer, 16);
00451         vin_number[internal_counter] = ascii_converted_data;
00452         internal_counter++;
00453     }
00454     pco.printf("\r\n\r\nVEHICLE CHASSIS NUMBER : %s", vin_number);
00455     
00456     /*
00457     Chassis Number : TMBFKJ5J2CG014733
00458      
00459     [TX] - 0902 5<CR>
00460 
00461     [RX] - 0902 5<CR>
00462     014 <CR>
00463     0: 49 02 01 54 4D 42 <CR>
00464     1: 46 4B 4A 35 4A 32 43 <CR>
00465     2: 47 30 31 34 37 33 33 <CR>
00466     <CR>
00467     >
00468     */
00469     /*
00470     OBD_UART.printf(vin_number_cmd);
00471     wait(1);
00472     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00473     pco.printf("Reception Complete\r\n");
00474     received_data_verification(OBD_UART_RX_Buffer, vin_number_cmd, (strlen(vin_number_cmd)-1));
00475     */
00476 }
00477     
00478     
00479 
00480 //************************************************************************************************************************
00481 
00482 void check_for_MIL()
00483 {
00484     char virtual_mil_buffer[] = "0101\r41 01 82 04 60 00 \r\r";
00485     /*
00486     OBD_UART.printf(check_mil_cmd);
00487     wait(1);
00488     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00489     pco.printf("Reception Complete\r\n");
00490     received_data_verification(OBD_UART_RX_Buffer, check_mil_cmd, (strlen(check_mil_cmd)-1));
00491     */
00492     
00493     //process_dtc_data(OBD_UART_RX_Buffer);
00494     process_mil_data(virtual_mil_buffer);
00495     
00496     if(pass == 1)
00497         printf("\r\nVEHICLE MIL DATA RECEIVED SUCCESSFULLY \r\n\r\n");
00498     else
00499         printf("\r\nVEHICLE MIL DATA RECEPTION FAILED\r\n\r\n");
00500     reception_complete = 0;     // Disabling the reception complete flag
00501     OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
00502 }
00503  
00504 
00505 //************************************************************************************************************************
00506 
00507 /*
00508 _______________________________________________________________________________________________________________________
00509 
00510 NOTE :
00511 -----
00512 THE FOLLOWING CODE O DETERMINE THE DIAGNOSTIC TROUBLE CODE (DTC) IS BASED ON THE INTERPRETATION GIVEN IN WIKIPEDIA
00513 FOR THE  ISO 15765-2 PROTOCOL
00514 DIFFERENT INTERPRETATION METHODOLOGY IS GIVEN IN THE ELM327 DATASHEET FOR SAE PROTOCOL
00515 SO THESE THINGS ARE SUBJECTED TO MODIFICATION AND HAVE NOT BEEN CONFIRMED WITH THE REAL TIME DATA 
00516 _______________________________________________________________________________________________________________________
00517 
00518 */
00519 
00520 void check_for_dtc()
00521 {
00522     char virtual_dtc_buffer[] = "03\r43 00 85\r\r>";
00523     //char virtual_dtc_buffer[] = "0123456789a\rbc>";
00524    /*
00525     OBD_UART.printf(check_dtc_cmd);
00526     wait(1);
00527     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00528     pco.printf("Reception Complete\r\n");
00529     received_data_verification(OBD_UART_RX_Buffer, check_dtc_cmd, (strlen(check_dtc_cmd)-1));
00530     */
00531 
00532     //process_dtc_data(OBD_UART_RX_Buffer);
00533     process_dtc_data(virtual_dtc_buffer);
00534     
00535     if(pass == 1)
00536         printf("\r\VEHICLE DIAGNOSTIC TROUBLE CODE RECEIVED SUCCESSFULLY \r\n\r\n");
00537     else
00538         printf("\r\nVEHICLE DIAGNOSTIC TROUBLE CODE DATA RECEPTION FAILED\r\n\r\n");
00539     reception_complete = 0;     // Disabling the reception complete flag
00540     OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
00541 }
00542 
00543 
00544 //************************************************************************************************************************
00545 
00546 void fetch_engine_rpm()
00547 {
00548     char count;
00549     char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>";
00550     for(count = 0; count < strlen(engine_rpm_cmd); count ++)
00551         OBD_UART.putc(engine_rpm_cmd[count]);
00552     /*
00553     OBD_UART.printf(engine_rpm_cmd);
00554     wait(1);
00555     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00556     pco.printf("Reception Complete\r\n");
00557     received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1));
00558     */
00559     
00560     process_engine_rpm(virtual_engine_rpm);
00561     
00562 }
00563 
00564 //************************************************************************************************************************
00565 
00566 void rpm_padding_for_comm_test()
00567 {
00568 
00569     char count;
00570     char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>";
00571     char engine_rpm[4];     // Vehicle speed data is returned by a 4 byte value
00572     char *rpm_data_pointer;
00573     char internal_count = 0;
00574     char padded_rpm_17_bytes[17];
00575     
00576     /*
00577     for(count = 0; count < strlen(engine_rpm_cmd); count ++)
00578         OBD_UART.putc(engine_rpm_cmd[count]);
00579     wait(1);
00580     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00581     pco.printf("Reception Complete\r\n");
00582     received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1));
00583     */
00584 
00585     rpm_data_pointer = virtual_engine_rpm;
00586     rpm_data_pointer += 11;
00587     
00588     for(count = 0; count < 5; count++)
00589     {
00590         if(*rpm_data_pointer == ' ') {        // Negate the spaces added in between
00591             rpm_data_pointer++;
00592             continue; }
00593         else {
00594             engine_rpm[internal_count] = *rpm_data_pointer++;
00595             internal_count++; }
00596     }
00597     
00598     //pco.printf("\r\n%s", engine_rpm);
00599     //pco.printf("\r\nRPMMMMMM = ");
00600     for(count = 0; count < strlen(engine_rpm); count++)
00601         pco.putc(engine_rpm[count]);
00602     
00603     for(count = 0; count < 4; count++){
00604         pco.printf("\r\nPadded = ");
00605         for(internal_count = 0; internal_count < strlen(padded_rpm_17_bytes); internal_count++)
00606             pco.putc(padded_rpm_17_bytes[internal_count]);
00607         //pco.printf("\r\nPadded RPM = %s", padded_rpm_17_bytes);
00608         strcat(padded_rpm_17_bytes, engine_rpm); }
00609         
00610     strcat(padded_rpm_17_bytes, "0");
00611     pco.printf("\r\n\r\n PADDED RPM = %s",padded_rpm_17_bytes);
00612     pco.putc('\r');
00613     for(count = 0; count < strlen(padded_rpm_17_bytes); count++)
00614         pco.putc(padded_rpm_17_bytes[count]);
00615 }
00616     
00617 
00618 //************************************************************************************************************************
00619 
00620 void initialize_obd()
00621 {
00622     char count;
00623     char data[3];
00624     char *data_pointer;  
00625 
00626     data_pointer = data;
00627     
00628     pco.baud(9600);
00629     OBD_UART.baud(9600);
00630     
00631     OBD_UART.attach(&OBD_onDataRx);
00632     
00633     
00634     OBD_UART.printf("%s",obd_reset_cmd);
00635 
00636     wait(1);
00637     
00638     
00639     pco.printf("Reception not completed");
00640     pco.printf("\r\n%d",OBD_RxBuffer_End_Pos);
00641     pco.printf("\r\n%c",OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1]);
00642     
00643     
00644     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00645     pco.printf("Reception Complete\r\n");
00646     received_data_verification(OBD_UART_RX_Buffer, obd_reset_cmd, (strlen(obd_reset_cmd)-1));
00647 
00648     if(pass == 1)
00649         printf("\r\nOBD RESET SUCCESSFUL \r\n\r\n");
00650     else
00651         printf("\r\nOBD RESET FAILED \r\n\r\n");
00652         
00653     reception_complete = 0;     // Disabling the reception complete flag
00654     OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
00655     
00656 //--------------------------------------------------------------------------------------------------------------------------  
00657 
00658     //OBD_UART.printf(allow_long_cmd);
00659     for(count = 0; count < strlen(allow_long_cmd); count++)
00660         OBD_UART.putc(allow_long_cmd[count]);
00661     wait(1);
00662     while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00663     pco.printf("Reception Complete\r\n");
00664     received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(allow_long_cmd)-1));
00665 
00666     if(pass == 1)
00667         printf("\r\nLONG DATA RECEPTION ENABLED SUCCESSFULLY \r\n\r\n");
00668     else
00669         printf("\r\nLONG DATA RECEPTION ENABLING FAILED\r\n\r\n");
00670     reception_complete = 0;     // Disabling the reception complete flag
00671     OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
00672 
00673 }
00674         
00675 //************************************************************************************************************************
00676 
00677 
00678 
00679 
00680 
00681 
00682 
00683 
00684 
00685 
00686 
00687 /*
00688 
00689 THE FOLLWOING CODE WORKS WITHOUT A CAR
00690 
00691 
00692 */
00693 
00694 //
00695 //
00696 //#include "mbed.h"
00697 //#include "obd_libraries.h"
00698 //#include "common_definitions.h"
00699 //
00700 //Serial pco(USBTX, USBRX);
00701 //Serial OBD_UART(PA_0, PA_1);
00702 //
00703 //char pass                       =   0;
00704 //char reception_complete         =   0;
00705 //
00706 ///*
00707 //__________________________________________________________________________________________________
00708 //
00709 //     THE FOLLWOING ARE THE OBD COMMAND SET FOR THE STN1110 / ELM327 OBD - UART INTERPRETER
00710 //__________________________________________________________________________________________________
00711 //
00712 //*/
00713 //
00714 //
00715 //char obd_reset_cmd[]            =   "ATZ\r";
00716 //char battery_voltage_cmd[]      =   "ATRV\r";
00717 //char protocol_auto_detect_cmd[] =   "ATSP0\r";
00718 //char read_CAN_protocol_cmd[]    =   "ATDPN\r";
00719 //char allow_long_cmd[]           =   "ATAL\r";
00720 //char engine_rpm_cmd[]           =   "010C\r";
00721 //char vehicle_speed_cmd[]        =   "010D\r";
00722 //char vin_number_cmd[]           =   "0902 5\r";
00723 //char check_dtc_cmd[]            =   "03\r";
00724 //char check_mil_cmd[]            =   "0101\r";
00725 //
00726 //
00727 ///*
00728 //__________________________________________________________________________________________________
00729 //
00730 //     THE FOLLOWING ARE GLOBAL VARIABLES WHICH CAN BE ACCESSED FOR FURTHER DATA PROCESSING
00731 //__________________________________________________________________________________________________
00732 //
00733 //*/
00734 //
00735 //float   car_battery_voltage;
00736 //long    rpm;
00737 //long    vehicle_speed;
00738 //char    vin_number[17];
00739 //char    mil;
00740 //char    no_of_stored_dtc;
00741 //
00742 ////_________________________________________________________________________________________________
00743 //
00744 //// THE FOLLWOING VARIABLES ARE GLOBAL BUT ARE USED ONLY FOR IN-LIBRARY PROCESSING
00745 //
00746 //char OBD_UART_RX_Buffer[50];
00747 //extern char OBD_RxBuffer_End_Pos;
00748 //
00749 ////_________________________________________________________________________________________________
00750 //
00751 ////*********************************************************************************************************************************************************************************
00752 //
00753 //// SELF CALL FUNCTION
00754 //// THE FOLLWOING CODE BLOCK DEFINES THE ISR OF THE OBD RECEIVE INTERRUPT
00755 //// THIS PIECE OF CODE JUST FILLS THE OBD RECEIVE BUFFER WITH THE INCOMING DATA RUSHING FROM THE OBD-UART INTERPRETER
00756 //void OBD_onDataRx()
00757 //{
00758 //    if(OBD_UART.readable()) {
00759 //        pco.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UART.getc());
00760 //    }
00761 //}
00762 //
00763 ////*********************************************************************************************************************************************************************************
00764 //
00765 //// FUNCTION CALLED BY PARENT FUNCTION
00766 //// THE FOLLOWING CODE BLOCK IS USED TO VERIFY THE RECEIVED DATA
00767 //
00768 //void received_data_verification(char *rcv_data_pointer, char *ref_data_pointer, char num)
00769 //{
00770 //    char dummy_data[num], count;
00771 //    for(count = 0; count < num; count++)
00772 //    {
00773 //        pco.putc(*rcv_data_pointer);
00774 //        if(*rcv_data_pointer++ == *ref_data_pointer++)
00775 //            pass = 1;
00776 //        else   
00777 //        {
00778 //            pass = 0;
00779 //            return;
00780 //        }
00781 //    } 
00782 //}
00783 //
00784 ////*********************************************************************************************************************************************************************************
00785 //
00786 //// FUNCTION WILL BE CALLED ON REQUEST
00787 //// THE FOLLOWING CODE BLOCK WILL FETCH THE RPM DATA FROM THE OBD PORT OF THE CAR AND PROCESS IT, PADS THE SAME DATA REPEATEDLY TO MAKE IT AS A 17 BYTE DATA
00788 //// THIS CODE BLOCK IS WRITTEN IN A INTENSION JUST TO TEST THE COMMUNICATION
00789 //// THE CODE BLOCK IS SUBJECTED TO REMOVAL AT THE FINAL STAGE
00790 //
00791 //void rpm_padding_for_comm_test()
00792 //{
00793 //
00794 //    char count;
00795 //    char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>";
00796 //    char engine_rpm[4];     // Vehicle speed data is returned by a 4 byte value
00797 //    char *rpm_data_pointer;
00798 //    char internal_count = 0;
00799 //    char padded_rpm_17_bytes[17];
00800 //    
00801 //    /*
00802 //    for(count = 0; count < strlen(engine_rpm_cmd); count ++)
00803 //        OBD_UART.putc(engine_rpm_cmd[count]);
00804 //    wait(1);
00805 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
00806 //    pco.printf("Reception Complete\r\n");
00807 //    received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1));
00808 //    */
00809 //
00810 //    rpm_data_pointer = virtual_engine_rpm;
00811 //    rpm_data_pointer += 11;
00812 //    
00813 //    for(count = 0; count < 5; count++)
00814 //    {
00815 //        if(*rpm_data_pointer == ' ') {        // Negate the spaces added in between
00816 //            rpm_data_pointer++;
00817 //            continue; }
00818 //        else {
00819 //            engine_rpm[internal_count] = *rpm_data_pointer++;
00820 //            internal_count++; }
00821 //    }
00822 //    
00823 //    //pco.printf("\r\n%s", engine_rpm);
00824 //    //pco.printf("\r\nRPMMMMMM = ");
00825 //    for(count = 0; count < strlen(engine_rpm); count++)
00826 //        pco.putc(engine_rpm[count]);
00827 //    
00828 //    for(count = 0; count < 4; count++){
00829 //        pco.printf("\r\nPadded = ");
00830 //        for(internal_count = 0; internal_count < strlen(padded_rpm_17_bytes); internal_count++)
00831 //            pco.putc(padded_rpm_17_bytes[internal_count]);
00832 //        //pco.printf("\r\nPadded RPM = %s", padded_rpm_17_bytes);
00833 //        strcat(padded_rpm_17_bytes, engine_rpm); }
00834 //        
00835 //    strcat(padded_rpm_17_bytes, "0");
00836 //    pco.printf("\r\n\r\n PADDED RPM = %s",padded_rpm_17_bytes);
00837 //    pco.putc('\r');
00838 //    for(count = 0; count < strlen(padded_rpm_17_bytes); count++)
00839 //        pco.putc(padded_rpm_17_bytes[count]);
00840 //}
00841 //
00842 //
00843 ////*********************************************************************************************************************************************************************************
00844 //
00845 //// FUNCTION CALLED FROM PARENT FUNCTION
00846 //// THE FOLLOWING CODE BLOCK IS USED TO PROCESS THE DTC DATA FETCHED FROM THE OBD PORT OF THE CAR
00847 //
00848 //void process_dtc_data(char *dtc_data_pointer)   // Incomplete Code block
00849 //{
00850 //     char count1, count2, count_bytes = 0; 
00851 //     char dtc_data[2];                  // Since each DTC needs 2 bytes to make the code
00852 //     dtc_data_pointer += 6;             // Neglecting the preceding data to scroll to the actual data having some meaning 
00853 //
00854 //     char dtc_codes[5];
00855 // 
00856 //     for(count1 = 0; count1 < (strlen(dtc_data_pointer)); count1++)
00857 //     {  
00858 //         if(*(dtc_data_pointer + count1) != '\r'){
00859 //            count_bytes++;}
00860 //            
00861 //         else
00862 //            break;
00863 //     }
00864 //   
00865 ///*
00866 //|______________________________________________________________________________________________|
00867 //
00868 //FORMULA:
00869 //-------
00870 //t = total bytes of returned data
00871 //n = no of dtc
00872 //
00873 //t = 2n + (n -1) , where (n-1) indicates the added spaces between two bytes
00874 //t = 3n -1
00875 //
00876 //Therefore, n = (t + 1) / 3
00877 //
00878 //|______________________________________________________________________________________________|
00879 //
00880 //*/  
00881 //     if(((count_bytes + 1)/3) == no_of_stored_dtc)
00882 //        pco.printf("\r\nNO OF STORED DTC MATCHES WITH THE DTC CODE RETURNED");
00883 //     else
00884 //        pco.printf("\r\nNO OF STORED DTC DOESNT MATCH WITH THE DTC DATA RETURNED");
00885 //     /*
00886 //     pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00887 //     pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00888 //     pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00889 //     pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++;
00890 //     pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30));
00891 //     */ 
00892 //     dtc_data_pointer -= 4;
00893 // 
00894 // for(count1 = 0; count1 < no_of_stored_dtc; count1++)
00895 //     {
00896 //         for(count2 = 0; count2 < 2; count2++)
00897 //         {
00898 //            //dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data
00899 //            dtc_data[count1] = *dtc_data_pointer++;
00900 //            //pco.printf("\r\nData = %c", dtc_data[count1]);
00901 //         }
00902 //         
00903 //         dtc_data_pointer++;
00904 //       
00905 //         switch((dtc_data[0] & 0x11000000) >> 6)
00906 //         {
00907 //             case 0:
00908 //             dtc_codes[count1*5] = 'P';
00909 //             break;
00910 //             
00911 //             case 1:
00912 //             dtc_codes[count1*5] = 'C';
00913 //             break;
00914 //             
00915 //             case 2:
00916 //             dtc_codes[count1*5] = 'B';
00917 //             break;
00918 //             
00919 //             case 3:
00920 //             dtc_codes[count1*5] = 'U';
00921 //             break;
00922 //         }
00923 //
00924 //         dtc_codes[1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); 
00925 //         dtc_codes[2] = ((dtc_data[0] & 0b00001111) + 0x30);
00926 //         dtc_codes[3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30);
00927 //         dtc_codes[4] = ((dtc_data[1] & 0b00001111) + 0x30);
00928 //         
00929 //         pco.printf("\r\n DTC CODE NO %d : %s", count1+1, dtc_codes);    
00930 //   }   
00931 //}
00932 //
00933 ////*********************************************************************************************************************************************************************************
00934 //
00935 //// FUNCTION CALLED FROM PARENT FUNCTION
00936 //// THE FOLLOWING CODE BLOCK IS USED TO PROCESS MIL DATA FETCHED FROM THE OBD PORT OF THE CAR
00937 //
00938 //void process_mil_data(char *mil_data_pointer)
00939 //{
00940 //    char mil_data[2], mil_data_converted;
00941 //    char count;
00942 //    
00943 //    // char virtual_mil_buffer = "0101\r41 01 00 04 60 00 \r\r";
00944 //    mil_data_pointer += 11;
00945 //    
00946 //    for(count = 0; count < 2; count++)
00947 //    {
00948 //        mil_data[count] = *mil_data_pointer++;
00949 //    }
00950 //    
00951 //    mil_data_converted = (((mil_data[0] - 0x30)<<4) + (mil_data[1] - 0x30)); // Converting the ASCII data to the Hex data
00952 //    
00953 //    // The following code lines checks for the number of Mal function indicator lamp enabled by tghe CAN ECU
00954 //    
00955 //    if(mil_data_converted & 0x80) // Checks for the MSB bit enabled or not which inc=dicates that the MIL is On or NOT
00956 //    {
00957 //        mil = 1;                // Setting the MIL flag
00958 //        pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS ON");
00959 //        no_of_stored_dtc = (mil_data_converted & 0b01111111);
00960 //        pco.printf("\r\n NO OF STORED DYNAMIC TROUBLE CODE = %d", no_of_stored_dtc);
00961 //    }
00962 //    else {
00963 //        mil = 0;                // Clearing the MIL flag
00964 //        pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS OFF"); }
00965 //}
00966 //
00967 ////*********************************************************************************************************************************************************************************
00968 //
00969 //// FUNCTION CALLED FROM PARENT FUNCTION
00970 //// THE FOLLWOING CODE BLOCK IS USED TO PROCESS THE VEHICLE SPEED DATA FETCHED FROM THE OBD PORT OF THE CAR
00971 //
00972 //void process_vehicle_speed(char *vehicle_speed_pointer)
00973 //{
00974 //    char vehicle_speed_data[2];     // Vehicle speed data is returned by a 2 byte value
00975 //    char *strtol_pointer;
00976 //    char count;
00977 //    //"010D\r41 0D 4F\r\r>"
00978 //    vehicle_speed_pointer += 11;
00979 //    for(count = 0; count < 2; count++)
00980 //    {
00981 //        vehicle_speed_data[count] = *vehicle_speed_pointer++;
00982 //    }
00983 //    
00984 //    vehicle_speed =  strtol(vehicle_speed_data, &strtol_pointer, 16);
00985 //    
00986 //    pco.printf("\r\nVEHICLE SPEED = %ld", vehicle_speed);
00987 //}
00988 //
00989 ////*********************************************************************************************************************************************************************************
00990 //
00991 //// FUNCTION CALLED BY PARENT FUCTION
00992 //// THE FOLLWOING CODE BLOCK IS USED TO PROCESS THE ENGINE RPM FETCHED FROM THE OBD PORT OF THE CAR
00993 //
00994 //void process_engine_rpm(char *rpm_data_pointer)
00995 //{
00996 //    //char virtual_engine_rpm[] = "010C\r41 0C 00 00 \r\r>";
00997 //    char engine_rpm[4];     // Vehicle speed data is returned by a 4 byte value
00998 //    char *strtol_pointer;
00999 //    char count;
01000 //    char internal_count = 0;
01001 //    
01002 //    rpm_data_pointer += 11;
01003 //    
01004 //    for(count = 0; count < 5; count++)
01005 //    {
01006 //        if(*rpm_data_pointer == ' ') {        // Negate the spaces added in between
01007 //            rpm_data_pointer++;
01008 //            continue; }
01009 //        else {
01010 //            engine_rpm[internal_count] = *rpm_data_pointer++;
01011 //            internal_count++; }
01012 //    }
01013 //    
01014 //    pco.printf("\r\n%s", engine_rpm);
01015 //    
01016 //    rpm =  ((strtol(engine_rpm, &strtol_pointer, 16)) / 4);
01017 //    
01018 //    pco.printf("\r\nENGINE RPM = %ld", rpm);
01019 //    
01020 //}
01021 //
01022 ////*********************************************************************************************************************************************************************************
01023 //
01024 //// FUNCTION CALLED BY PARENT FUNCTION
01025 //// THE FOLLOWING CODE BLOCK IS USED TO PROCESS THE BATTERY VOLTAGE FETCHED FROM THE OBD PORT OF THE CAR
01026 //
01027 //void process_battery_voltage(char *battery_voltage_pointer)
01028 //{
01029 //    char battery_voltage_data[4];   // One decimal point precision ( For ex : 12.5 )
01030 //    char count;
01031 //    battery_voltage_pointer += 5;   // ATRV<CR> counts to 5
01032 //    for(count = 0; count < 4; count++)
01033 //    {
01034 //        battery_voltage_data[count] = *battery_voltage_pointer++;
01035 //    }
01036 //    car_battery_voltage = atof(battery_voltage_data);   // Converts the Battery Volatge from String to Float data type
01037 //    
01038 //    pco.printf("\r\nCAR BATTERY VOLTAGE = %f",car_battery_voltage);
01039 //}
01040 //
01041 // 
01042 ////*********************************************************************************************************************************************************************************
01043 //
01044 ///*
01045 //_______________________________________________________________________________________________________________________
01046 //
01047 //NOTE :
01048 //-----
01049 //THE FOLLOWING CODE O DETERMINE THE DIAGNOSTIC TROUBLE CODE (DTC) IS BASED ON THE INTERPRETATION GIVEN IN WIKIPEDIA
01050 //FOR THE  ISO 15765-2 PROTOCOL
01051 //DIFFERENT INTERPRETATION METHODOLOGY IS GIVEN IN THE ELM327 DATASHEET FOR SAE PROTOCOL
01052 //SO THESE THINGS ARE SUBJECTED TO MODIFICATION AND HAVE NOT BEEN CONFIRMED WITH THE REAL TIME DATA 
01053 //_______________________________________________________________________________________________________________________
01054 //
01055 //*/
01056 //
01057 //// FUNCTION WILL BE CALLED ON REQUEST
01058 //// THE FOLLOWING CODE BLOCK WILL FETCH THE DTC DATA FROM THE OBD PORT OF THE CAR AND SENDS THE SAME FOR PROCESSING
01059 //
01060 //void check_for_dtc()
01061 //{
01062 //    char virtual_dtc_buffer[] = "03\r43 00 85\r\r>";
01063 //    
01064 //    OBD_UART.printf(check_dtc_cmd);
01065 //    wait(1);
01066 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01067 //    pco.printf("Reception Complete\r\n");
01068 //    received_data_verification(OBD_UART_RX_Buffer, check_dtc_cmd, (strlen(check_dtc_cmd)-1));
01069 //    
01070 //    //process_dtc_data(virtual_dtc_buffer);
01071 //    
01072 //    if(pass == 1) {
01073 //        process_dtc_data(OBD_UART_RX_Buffer);
01074 //        printf("\r\VEHICLE DIAGNOSTIC TROUBLE CODE RECEIVED SUCCESSFULLY \r\n\r\n"); }
01075 //    else
01076 //        printf("\r\nVEHICLE DIAGNOSTIC TROUBLE CODE DATA RECEPTION FAILED\r\n\r\n");
01077 //    reception_complete = 0;     // Disabling the reception complete flag
01078 //    OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
01079 //    
01080 //}
01081 //
01082 ////*********************************************************************************************************************************************************************************
01083 //
01084 //// FUNCTION WILL BE CALLED ON REQUEST
01085 //// THE FOLLOWING CODE BLOCK WILL FETCH THE MIL DATA FROM THE OBD PORT OF THE CAR
01086 //
01087 //void check_for_MIL()
01088 //{
01089 //    char count;
01090 //    //char virtual_mil_buffer[] = "0101\r41 01 82 04 60 00 \r\r";
01091 //    //OBD_UART.printf(check_mil_cmd);
01092 //    
01093 //    for(count = 0; count < strlen(check_mil_cmd); count++)
01094 //        OBD_UART.putc(check_mil_cmd[count]);
01095 //    wait(1);
01096 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01097 //    pco.printf("Reception Complete\r\n");
01098 //    received_data_verification(OBD_UART_RX_Buffer, check_mil_cmd, (strlen(check_mil_cmd)-1));
01099 //    
01100 //    
01101 //    //process_mil_data(virtual_mil_buffer);
01102 //    
01103 //    
01104 //    if(pass == 1) {
01105 //        process_mil_data(OBD_UART_RX_Buffer);
01106 //        printf("\r\nVEHICLE MIL DATA RECEIVED SUCCESSFULLY \r\n\r\n"); }
01107 //    else
01108 //        printf("\r\nVEHICLE MIL DATA RECEPTION FAILED\r\n\r\n");
01109 //    reception_complete = 0;     // Disabling the reception complete flag
01110 //    OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
01111 //    
01112 //}
01113 //
01114 ////*********************************************************************************************************************************************************************************
01115 //
01116 //// FUNCTION WILL BE CALLED ON REQUEST
01117 //// THE FOLLOWING CODE BLOCK WILL FETCH AND PROCESS THE VIN DATA FROM THE OBD PORT OF THE CAR
01118 //
01119 //void fetch_vin_number()
01120 //{
01121 //    char count;
01122 //    //char virtual_rx_vin_buffer[] = "0902 5\r014 \r0: 49 02 01 54 4D 42 \r1: 46 4B 4A 35 4A 32 43 \r2: 47 30 31 34 37 33 33 \r\r>"; 
01123 //    
01124 //    char vin_buffer[100];
01125 //    char *vin_data_pointer;
01126 //    char internal_counter = 0;
01127 //    char small_buffer[2];
01128 //    long ascii_converted_data;
01129 //    char *vin_conv_pointer;
01130 //    char vin_number[17];
01131 //    
01132 //    for(count = 0; count < strlen(vin_number_cmd); count++)
01133 //        OBD_UART.putc(vin_number_cmd[count]);
01134 //    wait(1);
01135 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01136 //    pco.printf("Reception Complete\r\n");
01137 //    received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1));
01138 //    
01139 //    //vin_data_pointer = virtual_rx_vin_buffer;
01140 //    vin_data_pointer = OBD_UART_RX_Buffer;
01141 //    vin_data_pointer += 23;
01142 //    
01143 //    int length;
01144 //    for(count = 0; count < (strlen(vin_data_pointer) - 1); count++)
01145 //    {
01146 //        if((*vin_data_pointer == '\r') | (*vin_data_pointer == ' ') | (*vin_data_pointer == '>'))
01147 //        {
01148 //            vin_data_pointer++;
01149 //            continue;
01150 //        }
01151 //        else if(*(vin_data_pointer + 1) == ':')
01152 //        {
01153 //            vin_data_pointer += 2;
01154 //            continue;
01155 //        }
01156 //        else
01157 //        {
01158 //            //printf("\r\ncount2 = %d", count); 
01159 //            vin_buffer[internal_counter] = *vin_data_pointer;
01160 //            internal_counter++;
01161 //        }
01162 //        vin_data_pointer++;
01163 //    }
01164 //    
01165 //    length = strlen(vin_buffer);
01166 //    pco.printf("\r\n VIN BUFFER LENGTH = %d", length);
01167 //    
01168 //    pco.printf("\r\n VIN NUMBER : %s", vin_buffer);
01169 //    
01170 //    internal_counter = 0;
01171 //    
01172 //    for(count = 0; count < strlen(vin_buffer); count+=2)
01173 //    {
01174 //        small_buffer[0] = vin_buffer[count];
01175 //        small_buffer[1] = vin_buffer[count+1];
01176 //        ascii_converted_data =  strtol(small_buffer, &vin_conv_pointer, 16);
01177 //        vin_number[internal_counter] = ascii_converted_data;
01178 //        internal_counter++;
01179 //    }
01180 //    pco.printf("\r\n\r\nVEHICLE CHASSIS NUMBER : %s", vin_number);
01181 //}
01182 //    
01183 //    
01184 //  
01185 ////*********************************************************************************************************************************************************************************
01186 //
01187 //// FUNCTION WILL BE CALLED ON REQUEST
01188 //// THE FOLLOWING CODE BLOCK FETCHES THE VEHICLE SPEED DATA FROM THE OBD PORT OF THE CAR AND SENDS THE SAME FOR PROCESSING
01189 //
01190 //void fetch_vehicle_speed()
01191 //{
01192 //    char virtual_rx_speed_buffer[] = "010D\r41 0D 4F \r\r>";     
01193 //    char count;
01194 //    //OBD_UART.printf(vehicle_speed_cmd);
01195 //    
01196 //    for(count = 0; count < strlen(vehicle_speed_cmd); count++)
01197 //        OBD_UART.putc(vehicle_speed_cmd[count]);
01198 //    wait(1);
01199 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01200 //    pco.printf("Reception Complete\r\n");
01201 //    received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1));
01202 //    
01203 //    //
01204 //    //process_vehicle_speed(virtual_rx_speed_buffer);
01205 //    
01206 //    if(pass == 1) {
01207 //        process_vehicle_speed(OBD_UART_RX_Buffer);
01208 //        printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); }
01209 //    else
01210 //        printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n");
01211 //    reception_complete = 0;     // Disabling the reception complete flag
01212 //    OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
01213 //    
01214 //}  
01215 //
01216 ////*********************************************************************************************************************************************************************************
01217 //
01218 //// FUNCITON WILL BE CALLED  ON REQUEST
01219 //// THE FOLLOWING CODE BLOCK FETCHES THE RPM DATA FROM THE OBD PORT OF THE CAR AND WILL SEND THE SAME FOR PROCESSING
01220 //
01221 //void fetch_engine_rpm()
01222 //{
01223 //    char count;
01224 //    //char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>";
01225 //    
01226 //    for(count = 0; count < strlen(engine_rpm_cmd); count ++)
01227 //        OBD_UART.putc(engine_rpm_cmd[count]);
01228 //    wait(1);
01229 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01230 //    pco.printf("Reception Complete\r\n");
01231 //    received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1));
01232 //    
01233 //    
01234 //    //process_engine_rpm(OBD_UART_RX_Buffer);
01235 //    //process_engine_rpm(virtual_engine_rpm);
01236 //    
01237 //    if(pass == 1) {
01238 //        process_engine_rpm(OBD_UART_RX_Buffer);
01239 //        printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); }
01240 //    else
01241 //        printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n");
01242 //    reception_complete = 0;     // Disabling the reception complete flag
01243 //    OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
01244 //}
01245 //
01246 ////*********************************************************************************************************************************************************************************
01247 //
01248 //// FUNCTION WILL BE CALLED ON REQUEST
01249 //// THE FOLLOWING CODE BLOCK FETCHED THE BATTERY VOLTAGE DATA FROM THE OBD PORT AND PASSES THE SAME DATA FOR PROCESSING
01250 //
01251 //void fetch_battery_voltage()
01252 //{
01253 //    char count;
01254 //    //OBD_UART.printf(battery_voltage_cmd);
01255 //    
01256 //    for(count = 0; count < strlen(battery_voltage_cmd); count++)
01257 //        OBD_UART.putc(battery_voltage_cmd[count]);
01258 //    wait(1);
01259 //    
01260 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01261 //    pco.printf("Reception Complete\r\n");
01262 //    received_data_verification(OBD_UART_RX_Buffer, battery_voltage_cmd, (strlen(battery_voltage_cmd)-1));
01263 //    
01264 //
01265 //    if(pass == 1) {
01266 //        pco.printf("\r\nOBD READ BATTERY VOLTAGE SUCCESSFUL");
01267 //        process_battery_voltage(OBD_UART_RX_Buffer); }
01268 //    else
01269 //        pco.printf("\r\nOBD READ BATTERY VOLTAGE FAILED");
01270 //    reception_complete = 0;     // Disabling the reception complete flag
01271 //    OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
01272 //}
01273 //  
01274 //    
01275 ////*********************************************************************************************************************************************************************************
01276 //
01277 //// FUNCTION WILL BE CALLED ON REQUEST
01278 //// TYHE FOLLOWING CODE BLOXK INITIALIZES THE OBD INTERFACE
01279 //// IT IS MANDATORY TO CALL THIS FUNCTION BEFORE USING ANY OF THE OTHER FUNCTIONS INCLUDED IN THIS PARTICULAR LIBRARY
01280 //
01281 //void initialize_obd()
01282 //{
01283 //    char count;
01284 //    char data[3];
01285 //    char *data_pointer;  
01286 //
01287 //    data_pointer = data;
01288 //    
01289 //    pco.baud(9600);
01290 //    OBD_UART.baud(9600);
01291 //    
01292 //    OBD_UART.attach(&OBD_onDataRx);
01293 //    
01294 // //--------------------------------------------------------------------------------------------------------------------------     
01295 //    
01296 //    OBD_UART.printf("%s",obd_reset_cmd);
01297 //
01298 //    wait(1);
01299 //    
01300 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01301 //    pco.printf("Reception Complete\r\n");
01302 //    received_data_verification(OBD_UART_RX_Buffer, obd_reset_cmd, (strlen(obd_reset_cmd)-1));
01303 //
01304 //    if(pass == 1)
01305 //        pco.printf("\r\nOBD RESET SUCCESSFUL \r\n\r\n");
01306 //    else
01307 //        pco.printf("\r\nOBD RESET FAILED \r\n\r\n");
01308 //        
01309 //    reception_complete = 0;     // Disabling the reception complete flag
01310 //    OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
01311 //    
01312 ////--------------------------------------------------------------------------------------------------------------------------  
01313 //
01314 //    //OBD_UART.printf(allow_long_cmd);
01315 //    for(count = 0; count < strlen(allow_long_cmd); count++)
01316 //        OBD_UART.putc(allow_long_cmd[count]);
01317 //    wait(1);
01318 //    while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>'));        // Waits here until the reception complete flag has been enabled
01319 //    pco.printf("Reception Complete\r\n");
01320 //    received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(allow_long_cmd)-1));
01321 //
01322 //    if(pass == 1)
01323 //        pco.printf("\r\nLONG DATA RECEPTION ENABLED SUCCESSFULLY \r\n\r\n");
01324 //    else
01325 //        pco.printf("\r\nLONG DATA RECEPTION ENABLING FAILED\r\n\r\n");
01326 //    reception_complete = 0;     // Disabling the reception complete flag
01327 //    OBD_RxBuffer_End_Pos = 0;   // Rx Buffer will be overwritten in the next data reception
01328 //    
01329 //}
01330