OBD Source Code -Section 1- Without Car / Section 2 - With car
Dependencies: mbed
obd_libraries.cpp@2:49712259aa71, 2017-04-03 (annotated)
- Committer:
- bala0x07
- Date:
- Mon Apr 03 06:02:26 2017 +0000
- Revision:
- 2:49712259aa71
- Parent:
- 1:c23c05b36e33
This particular source code has two independent sections, comment any one of the following before proceeding
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bala0x07 | 2:49712259aa71 | 1 | |
| bala0x07 | 2:49712259aa71 | 2 | /* |
| bala0x07 | 2:49712259aa71 | 3 | |
| bala0x07 | 2:49712259aa71 | 4 | THE FILE CONTAINS TWO SEPARATE SECTIONS |
| bala0x07 | 2:49712259aa71 | 5 | |
| bala0x07 | 2:49712259aa71 | 6 | COMMENT ANY ONE OF THE FOLLWOING BEFORE PROCEEDING |
| bala0x07 | 2:49712259aa71 | 7 | |
| bala0x07 | 2:49712259aa71 | 8 | THE FOLLWOING CODE WORKS WITHOUT A CAR |
| bala0x07 | 2:49712259aa71 | 9 | NECESSARY DATA ARE STORED IN VIRTUAL BUFFER FOR PROCESSING |
| bala0x07 | 2:49712259aa71 | 10 | |
| bala0x07 | 2:49712259aa71 | 11 | */ |
| bala0x07 | 2:49712259aa71 | 12 | |
| bala0x07 | 0:e36d80703ed0 | 13 | #include "mbed.h" |
| bala0x07 | 0:e36d80703ed0 | 14 | #include "obd_libraries.h" |
| bala0x07 | 0:e36d80703ed0 | 15 | #include "common_definitions.h" |
| bala0x07 | 0:e36d80703ed0 | 16 | |
| bala0x07 | 0:e36d80703ed0 | 17 | Serial pco(USBTX, USBRX); |
| bala0x07 | 0:e36d80703ed0 | 18 | Serial OBD_UART(PA_0, PA_1); |
| bala0x07 | 0:e36d80703ed0 | 19 | |
| bala0x07 | 0:e36d80703ed0 | 20 | char pass = 0; |
| bala0x07 | 0:e36d80703ed0 | 21 | char reception_complete = 0; |
| bala0x07 | 0:e36d80703ed0 | 22 | |
| bala0x07 | 0:e36d80703ed0 | 23 | char obd_reset_cmd[] = "ATZ\r"; |
| bala0x07 | 0:e36d80703ed0 | 24 | char battery_voltage_cmd[] = "ATRV\r"; |
| bala0x07 | 0:e36d80703ed0 | 25 | char protocol_auto_detect_cmd[] = "ATSP0\r"; |
| bala0x07 | 0:e36d80703ed0 | 26 | char read_CAN_protocol_cmd[] = "ATDPN\r"; |
| bala0x07 | 0:e36d80703ed0 | 27 | char allow_long_cmd[] = "ATAL\r"; |
| bala0x07 | 0:e36d80703ed0 | 28 | char engine_rpm_cmd[] = "010C\r"; |
| bala0x07 | 0:e36d80703ed0 | 29 | char vehicle_speed_cmd[] = "010D\r"; |
| bala0x07 | 0:e36d80703ed0 | 30 | char vin_number_cmd[] = "0902 5\r"; |
| bala0x07 | 1:c23c05b36e33 | 31 | char check_dtc_cmd[] = "03\r"; |
| bala0x07 | 1:c23c05b36e33 | 32 | char check_mil_cmd[] = "0101\r"; |
| bala0x07 | 1:c23c05b36e33 | 33 | |
| bala0x07 | 1:c23c05b36e33 | 34 | char no_of_stored_dtc; |
| bala0x07 | 0:e36d80703ed0 | 35 | |
| bala0x07 | 0:e36d80703ed0 | 36 | float car_battery_voltage; |
| bala0x07 | 0:e36d80703ed0 | 37 | long vehicle_speed; |
| bala0x07 | 0:e36d80703ed0 | 38 | char OBD_UART_RX_Buffer[50]; |
| bala0x07 | 0:e36d80703ed0 | 39 | extern char OBD_RxBuffer_End_Pos; |
| bala0x07 | 0:e36d80703ed0 | 40 | //char OBD_UART_RX_Size = 50; |
| bala0x07 | 0:e36d80703ed0 | 41 | |
| bala0x07 | 0:e36d80703ed0 | 42 | |
| bala0x07 | 0:e36d80703ed0 | 43 | //Serial pco(USBTX, USBRX); |
| bala0x07 | 0:e36d80703ed0 | 44 | //Serial OBD_UART(PA_0, PA_1); |
| bala0x07 | 0:e36d80703ed0 | 45 | |
| bala0x07 | 0:e36d80703ed0 | 46 | void OBD_onDataRx() |
| bala0x07 | 0:e36d80703ed0 | 47 | { |
| bala0x07 | 0:e36d80703ed0 | 48 | //pcm.printf("\r\n ENTERED \r\n"); |
| bala0x07 | 0:e36d80703ed0 | 49 | if(OBD_UART.readable()) { |
| bala0x07 | 0:e36d80703ed0 | 50 | |
| bala0x07 | 0:e36d80703ed0 | 51 | pco.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UART.getc()); |
| bala0x07 | 0:e36d80703ed0 | 52 | /* |
| bala0x07 | 0:e36d80703ed0 | 53 | if(OBD_RxBuffer_End_Pos >= OBD_UART_RX_Size) { |
| bala0x07 | 0:e36d80703ed0 | 54 | // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. |
| bala0x07 | 0:e36d80703ed0 | 55 | // For now just throw everything away. |
| bala0x07 | 0:e36d80703ed0 | 56 | OBD_RxBuffer_End_Pos = 0; |
| bala0x07 | 0:e36d80703ed0 | 57 | } |
| bala0x07 | 0:e36d80703ed0 | 58 | */ |
| bala0x07 | 0:e36d80703ed0 | 59 | } |
| bala0x07 | 0:e36d80703ed0 | 60 | } |
| bala0x07 | 0:e36d80703ed0 | 61 | |
| bala0x07 | 0:e36d80703ed0 | 62 | |
| bala0x07 | 0:e36d80703ed0 | 63 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 64 | |
| bala0x07 | 0:e36d80703ed0 | 65 | void received_data_verification(char *rcv_data_pointer, char *ref_data_pointer, char num) |
| bala0x07 | 0:e36d80703ed0 | 66 | { |
| bala0x07 | 0:e36d80703ed0 | 67 | char dummy_data[num], count; |
| bala0x07 | 0:e36d80703ed0 | 68 | for(count = 0; count < num; count++) |
| bala0x07 | 0:e36d80703ed0 | 69 | { |
| bala0x07 | 0:e36d80703ed0 | 70 | pco.putc(*rcv_data_pointer); |
| bala0x07 | 0:e36d80703ed0 | 71 | if(*rcv_data_pointer++ == *ref_data_pointer++) |
| bala0x07 | 0:e36d80703ed0 | 72 | pass = 1; |
| bala0x07 | 0:e36d80703ed0 | 73 | else |
| bala0x07 | 0:e36d80703ed0 | 74 | { |
| bala0x07 | 0:e36d80703ed0 | 75 | pass = 0; |
| bala0x07 | 0:e36d80703ed0 | 76 | return; |
| bala0x07 | 0:e36d80703ed0 | 77 | } |
| bala0x07 | 0:e36d80703ed0 | 78 | } |
| bala0x07 | 0:e36d80703ed0 | 79 | } |
| bala0x07 | 0:e36d80703ed0 | 80 | |
| bala0x07 | 0:e36d80703ed0 | 81 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 82 | /* |
| bala0x07 | 0:e36d80703ed0 | 83 | char* copy_characters(char *copy_char_pointer, char start_position, char end_position) |
| bala0x07 | 0:e36d80703ed0 | 84 | { |
| bala0x07 | 0:e36d80703ed0 | 85 | char total_num; |
| bala0x07 | 0:e36d80703ed0 | 86 | char count; |
| bala0x07 | 0:e36d80703ed0 | 87 | total_num = end_position - start_position; |
| bala0x07 | 0:e36d80703ed0 | 88 | char copied_data[total_num]; |
| bala0x07 | 0:e36d80703ed0 | 89 | copy_char_pointer += start_position; |
| bala0x07 | 0:e36d80703ed0 | 90 | |
| bala0x07 | 0:e36d80703ed0 | 91 | for(count = 0; count < total_num; count++) |
| bala0x07 | 0:e36d80703ed0 | 92 | { |
| bala0x07 | 0:e36d80703ed0 | 93 | copied_data[count] = *copy_char_pointer++; |
| bala0x07 | 0:e36d80703ed0 | 94 | } |
| bala0x07 | 0:e36d80703ed0 | 95 | |
| bala0x07 | 0:e36d80703ed0 | 96 | pco.printf("\r\n%s", copied_data); |
| bala0x07 | 0:e36d80703ed0 | 97 | |
| bala0x07 | 0:e36d80703ed0 | 98 | copy_char_pointer = copied_data; // Shifting the pointer to copied_data array |
| bala0x07 | 0:e36d80703ed0 | 99 | |
| bala0x07 | 0:e36d80703ed0 | 100 | return copy_char_pointer; |
| bala0x07 | 0:e36d80703ed0 | 101 | } |
| bala0x07 | 0:e36d80703ed0 | 102 | */ |
| bala0x07 | 0:e36d80703ed0 | 103 | |
| bala0x07 | 0:e36d80703ed0 | 104 | |
| bala0x07 | 0:e36d80703ed0 | 105 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 106 | |
| bala0x07 | 0:e36d80703ed0 | 107 | void process_battery_voltage(char *battery_voltage_pointer) |
| bala0x07 | 0:e36d80703ed0 | 108 | { |
| bala0x07 | 0:e36d80703ed0 | 109 | char battery_voltage_data[4]; // One decimal point precision ( For ex : 12.5 ) |
| bala0x07 | 0:e36d80703ed0 | 110 | char count; |
| bala0x07 | 0:e36d80703ed0 | 111 | battery_voltage_pointer += 5; // ATRV<CR> counts to 5 |
| bala0x07 | 0:e36d80703ed0 | 112 | for(count = 0; count < 4; count++) |
| bala0x07 | 0:e36d80703ed0 | 113 | { |
| bala0x07 | 0:e36d80703ed0 | 114 | battery_voltage_data[count] = *battery_voltage_pointer++; |
| bala0x07 | 0:e36d80703ed0 | 115 | } |
| bala0x07 | 0:e36d80703ed0 | 116 | car_battery_voltage = atof(battery_voltage_data); // Converts the Battery Volatge from String to Float data type |
| bala0x07 | 0:e36d80703ed0 | 117 | |
| bala0x07 | 0:e36d80703ed0 | 118 | printf("\r\nCAR BATTERY VOLTAGE = %f",car_battery_voltage); |
| bala0x07 | 0:e36d80703ed0 | 119 | } |
| bala0x07 | 0:e36d80703ed0 | 120 | |
| bala0x07 | 0:e36d80703ed0 | 121 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 122 | |
| bala0x07 | 0:e36d80703ed0 | 123 | void process_vehicle_speed(char *vehicle_speed_pointer) |
| bala0x07 | 0:e36d80703ed0 | 124 | { |
| bala0x07 | 0:e36d80703ed0 | 125 | char vehicle_speed_data[2]; // Vehicle speed data is returned by a 2 byte value |
| bala0x07 | 0:e36d80703ed0 | 126 | char *strtol_pointer; |
| bala0x07 | 0:e36d80703ed0 | 127 | char count; |
| bala0x07 | 0:e36d80703ed0 | 128 | //"010D\r41 0D 4F\r\r>" |
| bala0x07 | 0:e36d80703ed0 | 129 | vehicle_speed_pointer += 11; |
| bala0x07 | 0:e36d80703ed0 | 130 | for(count = 0; count < 2; count++) |
| bala0x07 | 0:e36d80703ed0 | 131 | { |
| bala0x07 | 0:e36d80703ed0 | 132 | vehicle_speed_data[count] = *vehicle_speed_pointer++; |
| bala0x07 | 0:e36d80703ed0 | 133 | } |
| bala0x07 | 0:e36d80703ed0 | 134 | |
| bala0x07 | 0:e36d80703ed0 | 135 | vehicle_speed = strtol(vehicle_speed_data, &strtol_pointer, 16); |
| bala0x07 | 0:e36d80703ed0 | 136 | |
| bala0x07 | 1:c23c05b36e33 | 137 | printf("\r\nVEHICLE SPEED = %ld", vehicle_speed); |
| bala0x07 | 1:c23c05b36e33 | 138 | } |
| bala0x07 | 1:c23c05b36e33 | 139 | |
| bala0x07 | 1:c23c05b36e33 | 140 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 141 | |
| bala0x07 | 1:c23c05b36e33 | 142 | void process_mil_data(char *mil_data_pointer) |
| bala0x07 | 1:c23c05b36e33 | 143 | { |
| bala0x07 | 1:c23c05b36e33 | 144 | char mil_data[2], mil_data_converted; |
| bala0x07 | 1:c23c05b36e33 | 145 | char count; |
| bala0x07 | 1:c23c05b36e33 | 146 | |
| bala0x07 | 1:c23c05b36e33 | 147 | // char virtual_mil_buffer = "0101\r41 01 00 04 60 00 \r\r"; |
| bala0x07 | 1:c23c05b36e33 | 148 | mil_data_pointer += 11; |
| bala0x07 | 1:c23c05b36e33 | 149 | |
| bala0x07 | 1:c23c05b36e33 | 150 | for(count = 0; count < 2; count++) |
| bala0x07 | 1:c23c05b36e33 | 151 | { |
| bala0x07 | 1:c23c05b36e33 | 152 | mil_data[count] = *mil_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 153 | } |
| bala0x07 | 1:c23c05b36e33 | 154 | |
| bala0x07 | 1:c23c05b36e33 | 155 | mil_data_converted = (((mil_data[0] - 0x30)<<4) + (mil_data[1] - 0x30)); // Converting the ASCII data to the Hex data |
| bala0x07 | 1:c23c05b36e33 | 156 | |
| bala0x07 | 1:c23c05b36e33 | 157 | // The following code lines checks for the number of Mal function indicator lamp enabled by tghe CAN ECU |
| bala0x07 | 1:c23c05b36e33 | 158 | |
| bala0x07 | 1:c23c05b36e33 | 159 | if(mil_data_converted & 0x80) // Checks for the MSB bit enabled or not which inc=dicates that the MIL is On or NOT |
| bala0x07 | 1:c23c05b36e33 | 160 | { |
| bala0x07 | 1:c23c05b36e33 | 161 | pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS ON"); |
| bala0x07 | 1:c23c05b36e33 | 162 | no_of_stored_dtc = (mil_data_converted & 0b01111111); |
| bala0x07 | 1:c23c05b36e33 | 163 | pco.printf("\r\n NO OF STORED DYNAMIC TROUBLE CODE = %d", no_of_stored_dtc); |
| bala0x07 | 1:c23c05b36e33 | 164 | } |
| bala0x07 | 1:c23c05b36e33 | 165 | else |
| bala0x07 | 1:c23c05b36e33 | 166 | pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS OFF"); |
| bala0x07 | 0:e36d80703ed0 | 167 | } |
| bala0x07 | 0:e36d80703ed0 | 168 | |
| bala0x07 | 0:e36d80703ed0 | 169 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 170 | |
| bala0x07 | 1:c23c05b36e33 | 171 | void process_dtc_data(char *dtc_data_pointer) // Incomplete Code block |
| bala0x07 | 1:c23c05b36e33 | 172 | { |
| bala0x07 | 1:c23c05b36e33 | 173 | /* |
| bala0x07 | 1:c23c05b36e33 | 174 | char i; |
| bala0x07 | 1:c23c05b36e33 | 175 | for(i = 0; i<14; i++) |
| bala0x07 | 1:c23c05b36e33 | 176 | { |
| bala0x07 | 1:c23c05b36e33 | 177 | pco.printf("\r\nData = %c", *(dtc_data_pointer+i)); |
| bala0x07 | 1:c23c05b36e33 | 178 | } |
| bala0x07 | 1:c23c05b36e33 | 179 | */ |
| bala0x07 | 1:c23c05b36e33 | 180 | // char virtual_dtc_buffer[] = "03\r43 00 85\r\r>"; |
| bala0x07 | 1:c23c05b36e33 | 181 | char count1, count2, count_bytes = 0; |
| bala0x07 | 1:c23c05b36e33 | 182 | //char dtc_data_raw[5]; |
| bala0x07 | 1:c23c05b36e33 | 183 | char dtc_data[2]; // Since each DTC needs 2 bytes to make the code |
| bala0x07 | 1:c23c05b36e33 | 184 | //pco.printf("\r\n String Length = %d", strlen(dtc_data_pointer)); |
| bala0x07 | 1:c23c05b36e33 | 185 | dtc_data_pointer += 6; // Neglecting the preceding data to scroll to the actual data having some meaning |
| bala0x07 | 1:c23c05b36e33 | 186 | |
| bala0x07 | 1:c23c05b36e33 | 187 | //char dtc_codes[no_of_stored_dtc * 5]; // Since each DTC requires 5 characters to display |
| bala0x07 | 1:c23c05b36e33 | 188 | |
| bala0x07 | 1:c23c05b36e33 | 189 | char dtc_codes[5]; |
| bala0x07 | 1:c23c05b36e33 | 190 | |
| bala0x07 | 2:49712259aa71 | 191 | |
| bala0x07 | 1:c23c05b36e33 | 192 | //pco.printf("\r\n String Length = %d", strlen(dtc_data_pointer)); |
| bala0x07 | 1:c23c05b36e33 | 193 | for(count1 = 0; count1 < (strlen(dtc_data_pointer)); count1++) |
| bala0x07 | 1:c23c05b36e33 | 194 | { |
| bala0x07 | 1:c23c05b36e33 | 195 | |
| bala0x07 | 1:c23c05b36e33 | 196 | if(*(dtc_data_pointer + count1) != '\r'){ |
| bala0x07 | 2:49712259aa71 | 197 | count_bytes++;} |
| bala0x07 | 2:49712259aa71 | 198 | //pco.printf("\r\nData = %c Count Bytes = %d", *(dtc_data_pointer+count1), count_bytes); } // To be commented |
| bala0x07 | 1:c23c05b36e33 | 199 | else |
| bala0x07 | 1:c23c05b36e33 | 200 | break; |
| bala0x07 | 1:c23c05b36e33 | 201 | } |
| bala0x07 | 2:49712259aa71 | 202 | //pco.printf("\r\nDATA POINTER POINTING TO : %c", *dtc_data_pointer); |
| bala0x07 | 1:c23c05b36e33 | 203 | //pco.printf("\r\nCount Bytes = %d", count_bytes); // To be commented |
| bala0x07 | 2:49712259aa71 | 204 | |
| bala0x07 | 2:49712259aa71 | 205 | |
| bala0x07 | 2:49712259aa71 | 206 | //------------------------------------------------------------------------------------------------------------------------------------------------- |
| bala0x07 | 2:49712259aa71 | 207 | |
| bala0x07 | 1:c23c05b36e33 | 208 | /* |
| bala0x07 | 1:c23c05b36e33 | 209 | |
| bala0x07 | 1:c23c05b36e33 | 210 | FORMULA: |
| bala0x07 | 1:c23c05b36e33 | 211 | t = total bytes of returned data |
| bala0x07 | 1:c23c05b36e33 | 212 | n = no of dtc |
| bala0x07 | 1:c23c05b36e33 | 213 | |
| bala0x07 | 1:c23c05b36e33 | 214 | t = 2n + (n -1) , where (n-1) indicates the added spaces between two bytes |
| bala0x07 | 1:c23c05b36e33 | 215 | t = 3n -1 |
| bala0x07 | 1:c23c05b36e33 | 216 | |
| bala0x07 | 1:c23c05b36e33 | 217 | Therefore, n = (t + 1) / 3 |
| bala0x07 | 1:c23c05b36e33 | 218 | |
| bala0x07 | 1:c23c05b36e33 | 219 | */ |
| bala0x07 | 1:c23c05b36e33 | 220 | if(((count_bytes + 1)/3) == no_of_stored_dtc) |
| bala0x07 | 1:c23c05b36e33 | 221 | pco.printf("\r\nNO OF STORED DTC MATCHES WITH THE DTC CODE RETURNED"); |
| bala0x07 | 1:c23c05b36e33 | 222 | else |
| bala0x07 | 1:c23c05b36e33 | 223 | pco.printf("\r\nNO OF STORED DTC DOESNT MATCH WITH THE DTC DATA RETURNED"); |
| bala0x07 | 2:49712259aa71 | 224 | /* |
| bala0x07 | 1:c23c05b36e33 | 225 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 226 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 227 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 228 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 229 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); |
| bala0x07 | 2:49712259aa71 | 230 | */ |
| bala0x07 | 1:c23c05b36e33 | 231 | dtc_data_pointer -= 4; |
| bala0x07 | 1:c23c05b36e33 | 232 | |
| bala0x07 | 1:c23c05b36e33 | 233 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| bala0x07 | 1:c23c05b36e33 | 234 | // VERIFIED UPTO THIS LEVEL |
| bala0x07 | 1:c23c05b36e33 | 235 | |
| bala0x07 | 1:c23c05b36e33 | 236 | for(count1 = 0; count1 < no_of_stored_dtc; count1++) |
| bala0x07 | 1:c23c05b36e33 | 237 | { |
| bala0x07 | 1:c23c05b36e33 | 238 | for(count2 = 0; count2 < 2; count2++) |
| bala0x07 | 1:c23c05b36e33 | 239 | { |
| bala0x07 | 1:c23c05b36e33 | 240 | //dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data |
| bala0x07 | 1:c23c05b36e33 | 241 | dtc_data[count1] = *dtc_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 242 | //pco.printf("\r\nData = %c", dtc_data[count1]); |
| bala0x07 | 1:c23c05b36e33 | 243 | } |
| bala0x07 | 2:49712259aa71 | 244 | /* |
| bala0x07 | 1:c23c05b36e33 | 245 | char a[2]; |
| bala0x07 | 1:c23c05b36e33 | 246 | a[0] = 'B'; |
| bala0x07 | 1:c23c05b36e33 | 247 | a[1] = 'G'; |
| bala0x07 | 1:c23c05b36e33 | 248 | pco.printf("\r\nData = %s", a); |
| bala0x07 | 2:49712259aa71 | 249 | */ |
| bala0x07 | 1:c23c05b36e33 | 250 | //dtc_data_pointer += 2; |
| bala0x07 | 1:c23c05b36e33 | 251 | dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 252 | |
| bala0x07 | 1:c23c05b36e33 | 253 | |
| bala0x07 | 1:c23c05b36e33 | 254 | /* |
| bala0x07 | 1:c23c05b36e33 | 255 | for(count1 = 0; count1 < no_of_stored_dtc; count1++) |
| bala0x07 | 1:c23c05b36e33 | 256 | { |
| bala0x07 | 1:c23c05b36e33 | 257 | for(count2 = 0; count2 < 3; count2++) |
| bala0x07 | 1:c23c05b36e33 | 258 | { |
| bala0x07 | 1:c23c05b36e33 | 259 | if((*(dtc_data_pointer + count1)) != ' ') { |
| bala0x07 | 1:c23c05b36e33 | 260 | dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data |
| bala0x07 | 1:c23c05b36e33 | 261 | pco.printf("\r\nData = %c", *(dtc_data_pointer + count1)); } |
| bala0x07 | 1:c23c05b36e33 | 262 | else { |
| bala0x07 | 1:c23c05b36e33 | 263 | dtc_data_pointer += 3; |
| bala0x07 | 1:c23c05b36e33 | 264 | break; } |
| bala0x07 | 1:c23c05b36e33 | 265 | } |
| bala0x07 | 1:c23c05b36e33 | 266 | */ |
| bala0x07 | 1:c23c05b36e33 | 267 | |
| bala0x07 | 1:c23c05b36e33 | 268 | /* |
| bala0x07 | 1:c23c05b36e33 | 269 | for(count1 = 0; count1 < count_bytes; count1++) |
| bala0x07 | 1:c23c05b36e33 | 270 | pco.printf("\r\n DTC Bytes = %c+%d", *dtc_data_pointer, (*(dtc_data_pointer++) - 0x30)); |
| bala0x07 | 1:c23c05b36e33 | 271 | |
| bala0x07 | 1:c23c05b36e33 | 272 | // The following lines of code copy the data pointed by dtc_data_pointer to the dtc_data array |
| bala0x07 | 1:c23c05b36e33 | 273 | for(count1= 0; count1 < no_of_stored_dtc; count1++) |
| bala0x07 | 1:c23c05b36e33 | 274 | { |
| bala0x07 | 1:c23c05b36e33 | 275 | for(count2 = 0; count2 < 2; count2++) |
| bala0x07 | 1:c23c05b36e33 | 276 | { |
| bala0x07 | 1:c23c05b36e33 | 277 | dtc_data[count2] = *(dtc_data_pointer + count2); |
| bala0x07 | 1:c23c05b36e33 | 278 | } |
| bala0x07 | 1:c23c05b36e33 | 279 | pco.printf("\r\nDTC DATA >>>> %c", dtc_data[1]); |
| bala0x07 | 1:c23c05b36e33 | 280 | dtc_data_pointer += 1; // To skip the space present between two DTC data |
| bala0x07 | 1:c23c05b36e33 | 281 | */ |
| bala0x07 | 1:c23c05b36e33 | 282 | switch((dtc_data[0] & 0x11000000) >> 6) |
| bala0x07 | 1:c23c05b36e33 | 283 | { |
| bala0x07 | 1:c23c05b36e33 | 284 | case 0: |
| bala0x07 | 1:c23c05b36e33 | 285 | dtc_codes[count1*5] = 'P'; |
| bala0x07 | 1:c23c05b36e33 | 286 | break; |
| bala0x07 | 1:c23c05b36e33 | 287 | |
| bala0x07 | 1:c23c05b36e33 | 288 | case 1: |
| bala0x07 | 1:c23c05b36e33 | 289 | dtc_codes[count1*5] = 'C'; |
| bala0x07 | 1:c23c05b36e33 | 290 | break; |
| bala0x07 | 1:c23c05b36e33 | 291 | |
| bala0x07 | 1:c23c05b36e33 | 292 | case 2: |
| bala0x07 | 1:c23c05b36e33 | 293 | dtc_codes[count1*5] = 'B'; |
| bala0x07 | 1:c23c05b36e33 | 294 | break; |
| bala0x07 | 1:c23c05b36e33 | 295 | |
| bala0x07 | 1:c23c05b36e33 | 296 | case 3: |
| bala0x07 | 1:c23c05b36e33 | 297 | dtc_codes[count1*5] = 'U'; |
| bala0x07 | 1:c23c05b36e33 | 298 | break; |
| bala0x07 | 1:c23c05b36e33 | 299 | } |
| bala0x07 | 1:c23c05b36e33 | 300 | |
| bala0x07 | 1:c23c05b36e33 | 301 | // dtc_codes[(count1*5)+1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 302 | // dtc_codes[(count1*5)+2] = ((dtc_data[0] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 303 | // dtc_codes[(count1*5)+3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 304 | // dtc_codes[(count1*5)+4] = ((dtc_data[1] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 305 | dtc_codes[1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 306 | dtc_codes[2] = ((dtc_data[0] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 307 | dtc_codes[3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 308 | dtc_codes[4] = ((dtc_data[1] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 309 | |
| bala0x07 | 1:c23c05b36e33 | 310 | pco.printf("\r\n DTC CODE NO %d : %s", count1+1, dtc_codes); |
| bala0x07 | 1:c23c05b36e33 | 311 | |
| bala0x07 | 1:c23c05b36e33 | 312 | } |
| bala0x07 | 1:c23c05b36e33 | 313 | } |
| bala0x07 | 1:c23c05b36e33 | 314 | |
| bala0x07 | 1:c23c05b36e33 | 315 | |
| bala0x07 | 1:c23c05b36e33 | 316 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 317 | |
| bala0x07 | 2:49712259aa71 | 318 | void process_engine_rpm(char *rpm_data_pointer) |
| bala0x07 | 2:49712259aa71 | 319 | { |
| bala0x07 | 2:49712259aa71 | 320 | //char virtual_engine_rpm[] = "010C\r41 0C 00 00 \r\r>"; |
| bala0x07 | 2:49712259aa71 | 321 | char engine_rpm[4]; // Vehicle speed data is returned by a 4 byte value |
| bala0x07 | 2:49712259aa71 | 322 | long rpm; |
| bala0x07 | 2:49712259aa71 | 323 | char *strtol_pointer; |
| bala0x07 | 2:49712259aa71 | 324 | char count; |
| bala0x07 | 2:49712259aa71 | 325 | char internal_count = 0; |
| bala0x07 | 2:49712259aa71 | 326 | |
| bala0x07 | 2:49712259aa71 | 327 | rpm_data_pointer += 11; |
| bala0x07 | 2:49712259aa71 | 328 | |
| bala0x07 | 2:49712259aa71 | 329 | for(count = 0; count < 5; count++) |
| bala0x07 | 2:49712259aa71 | 330 | { |
| bala0x07 | 2:49712259aa71 | 331 | if(*rpm_data_pointer == ' ') { // Negate the spaces added in between |
| bala0x07 | 2:49712259aa71 | 332 | rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 333 | continue; } |
| bala0x07 | 2:49712259aa71 | 334 | else { |
| bala0x07 | 2:49712259aa71 | 335 | engine_rpm[internal_count] = *rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 336 | internal_count++; } |
| bala0x07 | 2:49712259aa71 | 337 | } |
| bala0x07 | 2:49712259aa71 | 338 | |
| bala0x07 | 2:49712259aa71 | 339 | pco.printf("\r\n%s", engine_rpm); |
| bala0x07 | 2:49712259aa71 | 340 | |
| bala0x07 | 2:49712259aa71 | 341 | rpm = ((strtol(engine_rpm, &strtol_pointer, 16)) / 4); |
| bala0x07 | 2:49712259aa71 | 342 | |
| bala0x07 | 2:49712259aa71 | 343 | pco.printf("\r\nENGINE RPM = %ld", rpm); |
| bala0x07 | 2:49712259aa71 | 344 | |
| bala0x07 | 2:49712259aa71 | 345 | } |
| bala0x07 | 2:49712259aa71 | 346 | |
| bala0x07 | 2:49712259aa71 | 347 | |
| bala0x07 | 2:49712259aa71 | 348 | //************************************************************************************************************************ |
| bala0x07 | 2:49712259aa71 | 349 | |
| bala0x07 | 0:e36d80703ed0 | 350 | void fetch_battery_voltage() |
| bala0x07 | 0:e36d80703ed0 | 351 | { |
| bala0x07 | 2:49712259aa71 | 352 | char count; |
| bala0x07 | 2:49712259aa71 | 353 | //OBD_UART.printf(battery_voltage_cmd); |
| bala0x07 | 2:49712259aa71 | 354 | //OBD_UART.putc('\r'); |
| bala0x07 | 2:49712259aa71 | 355 | for(count = 0; count < strlen(battery_voltage_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 356 | OBD_UART.putc(battery_voltage_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 357 | wait(1); |
| bala0x07 | 2:49712259aa71 | 358 | //pco.printf("\r\n\r\nEnd Position = %d\r\n", OBD_RxBuffer_End_Pos); |
| bala0x07 | 0:e36d80703ed0 | 359 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 360 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 361 | received_data_verification(OBD_UART_RX_Buffer, battery_voltage_cmd, (strlen(battery_voltage_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 362 | |
| bala0x07 | 0:e36d80703ed0 | 363 | process_battery_voltage(OBD_UART_RX_Buffer); |
| bala0x07 | 0:e36d80703ed0 | 364 | |
| bala0x07 | 0:e36d80703ed0 | 365 | if(pass == 1) |
| bala0x07 | 0:e36d80703ed0 | 366 | printf("\r\nOBD READ BATTERY VOLTAGE SUCCESSFUL \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 367 | else |
| bala0x07 | 0:e36d80703ed0 | 368 | printf("\r\nOBD READ BATTERY VOLTAGE FAILED \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 369 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 370 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 0:e36d80703ed0 | 371 | } |
| bala0x07 | 0:e36d80703ed0 | 372 | |
| bala0x07 | 0:e36d80703ed0 | 373 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 374 | |
| bala0x07 | 0:e36d80703ed0 | 375 | void fetch_vehicle_speed() |
| bala0x07 | 0:e36d80703ed0 | 376 | { |
| bala0x07 | 1:c23c05b36e33 | 377 | char virtual_rx_speed_buffer[] = "010D\r41 0D 4F \r\r>"; |
| bala0x07 | 0:e36d80703ed0 | 378 | /* |
| bala0x07 | 0:e36d80703ed0 | 379 | OBD_UART.printf(vehicle_speed_cmd); |
| bala0x07 | 0:e36d80703ed0 | 380 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 381 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 382 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 383 | received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 384 | */ |
| bala0x07 | 0:e36d80703ed0 | 385 | process_vehicle_speed(virtual_rx_speed_buffer); |
| bala0x07 | 0:e36d80703ed0 | 386 | |
| bala0x07 | 0:e36d80703ed0 | 387 | if(pass == 1) |
| bala0x07 | 1:c23c05b36e33 | 388 | printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 389 | else |
| bala0x07 | 0:e36d80703ed0 | 390 | printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 391 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 392 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 0:e36d80703ed0 | 393 | |
| bala0x07 | 0:e36d80703ed0 | 394 | } |
| bala0x07 | 0:e36d80703ed0 | 395 | |
| bala0x07 | 0:e36d80703ed0 | 396 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 397 | |
| bala0x07 | 0:e36d80703ed0 | 398 | void fetch_vin_number() |
| bala0x07 | 0:e36d80703ed0 | 399 | { |
| bala0x07 | 2:49712259aa71 | 400 | char count; |
| bala0x07 | 0:e36d80703ed0 | 401 | 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>"; |
| bala0x07 | 2:49712259aa71 | 402 | /* |
| bala0x07 | 2:49712259aa71 | 403 | for(count = 0; count < strlen(vin_number_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 404 | OBD_UART.putc(vin_number_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 405 | */ |
| bala0x07 | 2:49712259aa71 | 406 | char vin_buffer[100]; |
| bala0x07 | 1:c23c05b36e33 | 407 | char *vin_data_pointer; |
| bala0x07 | 1:c23c05b36e33 | 408 | char internal_counter = 0; |
| bala0x07 | 1:c23c05b36e33 | 409 | char small_buffer[2]; |
| bala0x07 | 1:c23c05b36e33 | 410 | long ascii_converted_data; |
| bala0x07 | 1:c23c05b36e33 | 411 | char *vin_conv_pointer; |
| bala0x07 | 1:c23c05b36e33 | 412 | char vin_number[17]; |
| bala0x07 | 1:c23c05b36e33 | 413 | |
| bala0x07 | 1:c23c05b36e33 | 414 | vin_data_pointer = virtual_rx_vin_buffer; |
| bala0x07 | 1:c23c05b36e33 | 415 | vin_data_pointer += 23; |
| bala0x07 | 1:c23c05b36e33 | 416 | |
| bala0x07 | 1:c23c05b36e33 | 417 | int length; |
| bala0x07 | 1:c23c05b36e33 | 418 | for(count = 0; count < (strlen(virtual_rx_vin_buffer) - 1); count++) |
| bala0x07 | 1:c23c05b36e33 | 419 | { |
| bala0x07 | 1:c23c05b36e33 | 420 | if((*vin_data_pointer == '\r') | (*vin_data_pointer == ' ') | (*vin_data_pointer == '>')) |
| bala0x07 | 1:c23c05b36e33 | 421 | { |
| bala0x07 | 1:c23c05b36e33 | 422 | vin_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 423 | continue; |
| bala0x07 | 1:c23c05b36e33 | 424 | } |
| bala0x07 | 1:c23c05b36e33 | 425 | else if(*(vin_data_pointer + 1) == ':') |
| bala0x07 | 1:c23c05b36e33 | 426 | { |
| bala0x07 | 1:c23c05b36e33 | 427 | vin_data_pointer += 2; |
| bala0x07 | 1:c23c05b36e33 | 428 | continue; |
| bala0x07 | 1:c23c05b36e33 | 429 | } |
| bala0x07 | 1:c23c05b36e33 | 430 | else |
| bala0x07 | 1:c23c05b36e33 | 431 | { |
| bala0x07 | 2:49712259aa71 | 432 | //printf("\r\ncount2 = %d", count); |
| bala0x07 | 1:c23c05b36e33 | 433 | vin_buffer[internal_counter] = *vin_data_pointer; |
| bala0x07 | 1:c23c05b36e33 | 434 | internal_counter++; |
| bala0x07 | 1:c23c05b36e33 | 435 | } |
| bala0x07 | 1:c23c05b36e33 | 436 | vin_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 437 | } |
| bala0x07 | 1:c23c05b36e33 | 438 | |
| bala0x07 | 1:c23c05b36e33 | 439 | length = strlen(vin_buffer); |
| bala0x07 | 2:49712259aa71 | 440 | pco.printf("\r\n VIN BUFFER LENGTH = %d", length); |
| bala0x07 | 1:c23c05b36e33 | 441 | |
| bala0x07 | 2:49712259aa71 | 442 | pco.printf("\r\n VIN NUMBER : %s", vin_buffer); |
| bala0x07 | 1:c23c05b36e33 | 443 | |
| bala0x07 | 1:c23c05b36e33 | 444 | internal_counter = 0; |
| bala0x07 | 1:c23c05b36e33 | 445 | |
| bala0x07 | 1:c23c05b36e33 | 446 | for(count = 0; count < strlen(vin_buffer); count+=2) |
| bala0x07 | 1:c23c05b36e33 | 447 | { |
| bala0x07 | 1:c23c05b36e33 | 448 | small_buffer[0] = vin_buffer[count]; |
| bala0x07 | 1:c23c05b36e33 | 449 | small_buffer[1] = vin_buffer[count+1]; |
| bala0x07 | 1:c23c05b36e33 | 450 | ascii_converted_data = strtol(small_buffer, &vin_conv_pointer, 16); |
| bala0x07 | 1:c23c05b36e33 | 451 | vin_number[internal_counter] = ascii_converted_data; |
| bala0x07 | 1:c23c05b36e33 | 452 | internal_counter++; |
| bala0x07 | 1:c23c05b36e33 | 453 | } |
| bala0x07 | 2:49712259aa71 | 454 | pco.printf("\r\n\r\nVEHICLE CHASSIS NUMBER : %s", vin_number); |
| bala0x07 | 0:e36d80703ed0 | 455 | |
| bala0x07 | 0:e36d80703ed0 | 456 | /* |
| bala0x07 | 0:e36d80703ed0 | 457 | Chassis Number : TMBFKJ5J2CG014733 |
| bala0x07 | 0:e36d80703ed0 | 458 | |
| bala0x07 | 0:e36d80703ed0 | 459 | [TX] - 0902 5<CR> |
| bala0x07 | 0:e36d80703ed0 | 460 | |
| bala0x07 | 0:e36d80703ed0 | 461 | [RX] - 0902 5<CR> |
| bala0x07 | 0:e36d80703ed0 | 462 | 014 <CR> |
| bala0x07 | 0:e36d80703ed0 | 463 | 0: 49 02 01 54 4D 42 <CR> |
| bala0x07 | 0:e36d80703ed0 | 464 | 1: 46 4B 4A 35 4A 32 43 <CR> |
| bala0x07 | 0:e36d80703ed0 | 465 | 2: 47 30 31 34 37 33 33 <CR> |
| bala0x07 | 0:e36d80703ed0 | 466 | <CR> |
| bala0x07 | 0:e36d80703ed0 | 467 | > |
| bala0x07 | 0:e36d80703ed0 | 468 | */ |
| bala0x07 | 0:e36d80703ed0 | 469 | /* |
| bala0x07 | 0:e36d80703ed0 | 470 | OBD_UART.printf(vin_number_cmd); |
| bala0x07 | 0:e36d80703ed0 | 471 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 472 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 473 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 474 | received_data_verification(OBD_UART_RX_Buffer, vin_number_cmd, (strlen(vin_number_cmd)-1)); |
| bala0x07 | 1:c23c05b36e33 | 475 | */ |
| bala0x07 | 1:c23c05b36e33 | 476 | } |
| bala0x07 | 1:c23c05b36e33 | 477 | |
| bala0x07 | 1:c23c05b36e33 | 478 | |
| bala0x07 | 1:c23c05b36e33 | 479 | |
| bala0x07 | 1:c23c05b36e33 | 480 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 481 | |
| bala0x07 | 1:c23c05b36e33 | 482 | void check_for_MIL() |
| bala0x07 | 1:c23c05b36e33 | 483 | { |
| bala0x07 | 1:c23c05b36e33 | 484 | char virtual_mil_buffer[] = "0101\r41 01 82 04 60 00 \r\r"; |
| bala0x07 | 1:c23c05b36e33 | 485 | /* |
| bala0x07 | 1:c23c05b36e33 | 486 | OBD_UART.printf(check_mil_cmd); |
| bala0x07 | 1:c23c05b36e33 | 487 | wait(1); |
| bala0x07 | 1:c23c05b36e33 | 488 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 1:c23c05b36e33 | 489 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 490 | received_data_verification(OBD_UART_RX_Buffer, check_mil_cmd, (strlen(check_mil_cmd)-1)); |
| bala0x07 | 1:c23c05b36e33 | 491 | */ |
| bala0x07 | 1:c23c05b36e33 | 492 | |
| bala0x07 | 1:c23c05b36e33 | 493 | //process_dtc_data(OBD_UART_RX_Buffer); |
| bala0x07 | 1:c23c05b36e33 | 494 | process_mil_data(virtual_mil_buffer); |
| bala0x07 | 1:c23c05b36e33 | 495 | |
| bala0x07 | 1:c23c05b36e33 | 496 | if(pass == 1) |
| bala0x07 | 2:49712259aa71 | 497 | printf("\r\nVEHICLE MIL DATA RECEIVED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 498 | else |
| bala0x07 | 1:c23c05b36e33 | 499 | printf("\r\nVEHICLE MIL DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 500 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 1:c23c05b36e33 | 501 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 1:c23c05b36e33 | 502 | } |
| bala0x07 | 1:c23c05b36e33 | 503 | |
| bala0x07 | 0:e36d80703ed0 | 504 | |
| bala0x07 | 0:e36d80703ed0 | 505 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 506 | |
| bala0x07 | 0:e36d80703ed0 | 507 | /* |
| bala0x07 | 1:c23c05b36e33 | 508 | _______________________________________________________________________________________________________________________ |
| bala0x07 | 1:c23c05b36e33 | 509 | |
| bala0x07 | 1:c23c05b36e33 | 510 | NOTE : |
| bala0x07 | 1:c23c05b36e33 | 511 | ----- |
| bala0x07 | 1:c23c05b36e33 | 512 | THE FOLLOWING CODE O DETERMINE THE DIAGNOSTIC TROUBLE CODE (DTC) IS BASED ON THE INTERPRETATION GIVEN IN WIKIPEDIA |
| bala0x07 | 1:c23c05b36e33 | 513 | FOR THE ISO 15765-2 PROTOCOL |
| bala0x07 | 1:c23c05b36e33 | 514 | DIFFERENT INTERPRETATION METHODOLOGY IS GIVEN IN THE ELM327 DATASHEET FOR SAE PROTOCOL |
| bala0x07 | 1:c23c05b36e33 | 515 | SO THESE THINGS ARE SUBJECTED TO MODIFICATION AND HAVE NOT BEEN CONFIRMED WITH THE REAL TIME DATA |
| bala0x07 | 1:c23c05b36e33 | 516 | _______________________________________________________________________________________________________________________ |
| bala0x07 | 1:c23c05b36e33 | 517 | |
| bala0x07 | 1:c23c05b36e33 | 518 | */ |
| bala0x07 | 1:c23c05b36e33 | 519 | |
| bala0x07 | 0:e36d80703ed0 | 520 | void check_for_dtc() |
| bala0x07 | 0:e36d80703ed0 | 521 | { |
| bala0x07 | 1:c23c05b36e33 | 522 | char virtual_dtc_buffer[] = "03\r43 00 85\r\r>"; |
| bala0x07 | 1:c23c05b36e33 | 523 | //char virtual_dtc_buffer[] = "0123456789a\rbc>"; |
| bala0x07 | 2:49712259aa71 | 524 | /* |
| bala0x07 | 1:c23c05b36e33 | 525 | OBD_UART.printf(check_dtc_cmd); |
| bala0x07 | 1:c23c05b36e33 | 526 | wait(1); |
| bala0x07 | 1:c23c05b36e33 | 527 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 1:c23c05b36e33 | 528 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 529 | received_data_verification(OBD_UART_RX_Buffer, check_dtc_cmd, (strlen(check_dtc_cmd)-1)); |
| bala0x07 | 1:c23c05b36e33 | 530 | */ |
| bala0x07 | 1:c23c05b36e33 | 531 | |
| bala0x07 | 1:c23c05b36e33 | 532 | //process_dtc_data(OBD_UART_RX_Buffer); |
| bala0x07 | 1:c23c05b36e33 | 533 | process_dtc_data(virtual_dtc_buffer); |
| bala0x07 | 1:c23c05b36e33 | 534 | |
| bala0x07 | 1:c23c05b36e33 | 535 | if(pass == 1) |
| bala0x07 | 1:c23c05b36e33 | 536 | printf("\r\VEHICLE DIAGNOSTIC TROUBLE CODE RECEIVED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 537 | else |
| bala0x07 | 1:c23c05b36e33 | 538 | printf("\r\nVEHICLE DIAGNOSTIC TROUBLE CODE DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 539 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 1:c23c05b36e33 | 540 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 1:c23c05b36e33 | 541 | } |
| bala0x07 | 1:c23c05b36e33 | 542 | |
| bala0x07 | 0:e36d80703ed0 | 543 | |
| bala0x07 | 0:e36d80703ed0 | 544 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 545 | |
| bala0x07 | 2:49712259aa71 | 546 | void fetch_engine_rpm() |
| bala0x07 | 2:49712259aa71 | 547 | { |
| bala0x07 | 2:49712259aa71 | 548 | char count; |
| bala0x07 | 2:49712259aa71 | 549 | char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>"; |
| bala0x07 | 2:49712259aa71 | 550 | for(count = 0; count < strlen(engine_rpm_cmd); count ++) |
| bala0x07 | 2:49712259aa71 | 551 | OBD_UART.putc(engine_rpm_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 552 | /* |
| bala0x07 | 2:49712259aa71 | 553 | OBD_UART.printf(engine_rpm_cmd); |
| bala0x07 | 2:49712259aa71 | 554 | wait(1); |
| bala0x07 | 2:49712259aa71 | 555 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 556 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 557 | received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 558 | */ |
| bala0x07 | 2:49712259aa71 | 559 | |
| bala0x07 | 2:49712259aa71 | 560 | process_engine_rpm(virtual_engine_rpm); |
| bala0x07 | 2:49712259aa71 | 561 | |
| bala0x07 | 2:49712259aa71 | 562 | } |
| bala0x07 | 2:49712259aa71 | 563 | |
| bala0x07 | 2:49712259aa71 | 564 | //************************************************************************************************************************ |
| bala0x07 | 2:49712259aa71 | 565 | |
| bala0x07 | 2:49712259aa71 | 566 | void rpm_padding_for_comm_test() |
| bala0x07 | 2:49712259aa71 | 567 | { |
| bala0x07 | 2:49712259aa71 | 568 | |
| bala0x07 | 2:49712259aa71 | 569 | char count; |
| bala0x07 | 2:49712259aa71 | 570 | char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>"; |
| bala0x07 | 2:49712259aa71 | 571 | char engine_rpm[4]; // Vehicle speed data is returned by a 4 byte value |
| bala0x07 | 2:49712259aa71 | 572 | char *rpm_data_pointer; |
| bala0x07 | 2:49712259aa71 | 573 | char internal_count = 0; |
| bala0x07 | 2:49712259aa71 | 574 | char padded_rpm_17_bytes[17]; |
| bala0x07 | 2:49712259aa71 | 575 | |
| bala0x07 | 2:49712259aa71 | 576 | /* |
| bala0x07 | 2:49712259aa71 | 577 | for(count = 0; count < strlen(engine_rpm_cmd); count ++) |
| bala0x07 | 2:49712259aa71 | 578 | OBD_UART.putc(engine_rpm_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 579 | wait(1); |
| bala0x07 | 2:49712259aa71 | 580 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 581 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 582 | received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 583 | */ |
| bala0x07 | 2:49712259aa71 | 584 | |
| bala0x07 | 2:49712259aa71 | 585 | rpm_data_pointer = virtual_engine_rpm; |
| bala0x07 | 2:49712259aa71 | 586 | rpm_data_pointer += 11; |
| bala0x07 | 2:49712259aa71 | 587 | |
| bala0x07 | 2:49712259aa71 | 588 | for(count = 0; count < 5; count++) |
| bala0x07 | 2:49712259aa71 | 589 | { |
| bala0x07 | 2:49712259aa71 | 590 | if(*rpm_data_pointer == ' ') { // Negate the spaces added in between |
| bala0x07 | 2:49712259aa71 | 591 | rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 592 | continue; } |
| bala0x07 | 2:49712259aa71 | 593 | else { |
| bala0x07 | 2:49712259aa71 | 594 | engine_rpm[internal_count] = *rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 595 | internal_count++; } |
| bala0x07 | 2:49712259aa71 | 596 | } |
| bala0x07 | 2:49712259aa71 | 597 | |
| bala0x07 | 2:49712259aa71 | 598 | //pco.printf("\r\n%s", engine_rpm); |
| bala0x07 | 2:49712259aa71 | 599 | //pco.printf("\r\nRPMMMMMM = "); |
| bala0x07 | 2:49712259aa71 | 600 | for(count = 0; count < strlen(engine_rpm); count++) |
| bala0x07 | 2:49712259aa71 | 601 | pco.putc(engine_rpm[count]); |
| bala0x07 | 2:49712259aa71 | 602 | |
| bala0x07 | 2:49712259aa71 | 603 | for(count = 0; count < 4; count++){ |
| bala0x07 | 2:49712259aa71 | 604 | pco.printf("\r\nPadded = "); |
| bala0x07 | 2:49712259aa71 | 605 | for(internal_count = 0; internal_count < strlen(padded_rpm_17_bytes); internal_count++) |
| bala0x07 | 2:49712259aa71 | 606 | pco.putc(padded_rpm_17_bytes[internal_count]); |
| bala0x07 | 2:49712259aa71 | 607 | //pco.printf("\r\nPadded RPM = %s", padded_rpm_17_bytes); |
| bala0x07 | 2:49712259aa71 | 608 | strcat(padded_rpm_17_bytes, engine_rpm); } |
| bala0x07 | 2:49712259aa71 | 609 | |
| bala0x07 | 2:49712259aa71 | 610 | strcat(padded_rpm_17_bytes, "0"); |
| bala0x07 | 2:49712259aa71 | 611 | pco.printf("\r\n\r\n PADDED RPM = %s",padded_rpm_17_bytes); |
| bala0x07 | 2:49712259aa71 | 612 | pco.putc('\r'); |
| bala0x07 | 2:49712259aa71 | 613 | for(count = 0; count < strlen(padded_rpm_17_bytes); count++) |
| bala0x07 | 2:49712259aa71 | 614 | pco.putc(padded_rpm_17_bytes[count]); |
| bala0x07 | 2:49712259aa71 | 615 | } |
| bala0x07 | 2:49712259aa71 | 616 | |
| bala0x07 | 2:49712259aa71 | 617 | |
| bala0x07 | 2:49712259aa71 | 618 | //************************************************************************************************************************ |
| bala0x07 | 2:49712259aa71 | 619 | |
| bala0x07 | 0:e36d80703ed0 | 620 | void initialize_obd() |
| bala0x07 | 0:e36d80703ed0 | 621 | { |
| bala0x07 | 2:49712259aa71 | 622 | char count; |
| bala0x07 | 0:e36d80703ed0 | 623 | char data[3]; |
| bala0x07 | 0:e36d80703ed0 | 624 | char *data_pointer; |
| bala0x07 | 0:e36d80703ed0 | 625 | |
| bala0x07 | 0:e36d80703ed0 | 626 | data_pointer = data; |
| bala0x07 | 0:e36d80703ed0 | 627 | |
| bala0x07 | 2:49712259aa71 | 628 | pco.baud(9600); |
| bala0x07 | 2:49712259aa71 | 629 | OBD_UART.baud(9600); |
| bala0x07 | 0:e36d80703ed0 | 630 | |
| bala0x07 | 0:e36d80703ed0 | 631 | OBD_UART.attach(&OBD_onDataRx); |
| bala0x07 | 0:e36d80703ed0 | 632 | |
| bala0x07 | 2:49712259aa71 | 633 | |
| bala0x07 | 0:e36d80703ed0 | 634 | OBD_UART.printf("%s",obd_reset_cmd); |
| bala0x07 | 0:e36d80703ed0 | 635 | |
| bala0x07 | 0:e36d80703ed0 | 636 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 637 | |
| bala0x07 | 2:49712259aa71 | 638 | |
| bala0x07 | 0:e36d80703ed0 | 639 | pco.printf("Reception not completed"); |
| bala0x07 | 0:e36d80703ed0 | 640 | pco.printf("\r\n%d",OBD_RxBuffer_End_Pos); |
| bala0x07 | 0:e36d80703ed0 | 641 | pco.printf("\r\n%c",OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1]); |
| bala0x07 | 2:49712259aa71 | 642 | |
| bala0x07 | 0:e36d80703ed0 | 643 | |
| bala0x07 | 0:e36d80703ed0 | 644 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 645 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 646 | received_data_verification(OBD_UART_RX_Buffer, obd_reset_cmd, (strlen(obd_reset_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 647 | |
| bala0x07 | 0:e36d80703ed0 | 648 | if(pass == 1) |
| bala0x07 | 0:e36d80703ed0 | 649 | printf("\r\nOBD RESET SUCCESSFUL \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 650 | else |
| bala0x07 | 0:e36d80703ed0 | 651 | printf("\r\nOBD RESET FAILED \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 652 | |
| bala0x07 | 0:e36d80703ed0 | 653 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 654 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 0:e36d80703ed0 | 655 | |
| bala0x07 | 0:e36d80703ed0 | 656 | //-------------------------------------------------------------------------------------------------------------------------- |
| bala0x07 | 0:e36d80703ed0 | 657 | |
| bala0x07 | 2:49712259aa71 | 658 | //OBD_UART.printf(allow_long_cmd); |
| bala0x07 | 2:49712259aa71 | 659 | for(count = 0; count < strlen(allow_long_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 660 | OBD_UART.putc(allow_long_cmd[count]); |
| bala0x07 | 0:e36d80703ed0 | 661 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 662 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 663 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 664 | received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(allow_long_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 665 | |
| bala0x07 | 0:e36d80703ed0 | 666 | if(pass == 1) |
| bala0x07 | 0:e36d80703ed0 | 667 | printf("\r\nLONG DATA RECEPTION ENABLED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 668 | else |
| bala0x07 | 0:e36d80703ed0 | 669 | printf("\r\nLONG DATA RECEPTION ENABLING FAILED\r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 670 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 671 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 672 | |
| bala0x07 | 0:e36d80703ed0 | 673 | } |
| bala0x07 | 0:e36d80703ed0 | 674 | |
| bala0x07 | 0:e36d80703ed0 | 675 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 676 | |
| bala0x07 | 0:e36d80703ed0 | 677 | |
| bala0x07 | 0:e36d80703ed0 | 678 | |
| bala0x07 | 0:e36d80703ed0 | 679 | |
| bala0x07 | 2:49712259aa71 | 680 | |
| bala0x07 | 2:49712259aa71 | 681 | |
| bala0x07 | 2:49712259aa71 | 682 | |
| bala0x07 | 2:49712259aa71 | 683 | |
| bala0x07 | 2:49712259aa71 | 684 | |
| bala0x07 | 2:49712259aa71 | 685 | |
| bala0x07 | 2:49712259aa71 | 686 | |
| bala0x07 | 2:49712259aa71 | 687 | /* |
| bala0x07 | 2:49712259aa71 | 688 | |
| bala0x07 | 2:49712259aa71 | 689 | THE FOLLWOING CODE WORKS WITHOUT A CAR |
| bala0x07 | 2:49712259aa71 | 690 | |
| bala0x07 | 2:49712259aa71 | 691 | |
| bala0x07 | 2:49712259aa71 | 692 | */ |
| bala0x07 | 2:49712259aa71 | 693 | |
| bala0x07 | 2:49712259aa71 | 694 | // |
| bala0x07 | 2:49712259aa71 | 695 | // |
| bala0x07 | 2:49712259aa71 | 696 | //#include "mbed.h" |
| bala0x07 | 2:49712259aa71 | 697 | //#include "obd_libraries.h" |
| bala0x07 | 2:49712259aa71 | 698 | //#include "common_definitions.h" |
| bala0x07 | 2:49712259aa71 | 699 | // |
| bala0x07 | 2:49712259aa71 | 700 | //Serial pco(USBTX, USBRX); |
| bala0x07 | 2:49712259aa71 | 701 | //Serial OBD_UART(PA_0, PA_1); |
| bala0x07 | 2:49712259aa71 | 702 | // |
| bala0x07 | 2:49712259aa71 | 703 | //char pass = 0; |
| bala0x07 | 2:49712259aa71 | 704 | //char reception_complete = 0; |
| bala0x07 | 2:49712259aa71 | 705 | // |
| bala0x07 | 2:49712259aa71 | 706 | ///* |
| bala0x07 | 2:49712259aa71 | 707 | //__________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 708 | // |
| bala0x07 | 2:49712259aa71 | 709 | // THE FOLLWOING ARE THE OBD COMMAND SET FOR THE STN1110 / ELM327 OBD - UART INTERPRETER |
| bala0x07 | 2:49712259aa71 | 710 | //__________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 711 | // |
| bala0x07 | 2:49712259aa71 | 712 | //*/ |
| bala0x07 | 2:49712259aa71 | 713 | // |
| bala0x07 | 2:49712259aa71 | 714 | // |
| bala0x07 | 2:49712259aa71 | 715 | //char obd_reset_cmd[] = "ATZ\r"; |
| bala0x07 | 2:49712259aa71 | 716 | //char battery_voltage_cmd[] = "ATRV\r"; |
| bala0x07 | 2:49712259aa71 | 717 | //char protocol_auto_detect_cmd[] = "ATSP0\r"; |
| bala0x07 | 2:49712259aa71 | 718 | //char read_CAN_protocol_cmd[] = "ATDPN\r"; |
| bala0x07 | 2:49712259aa71 | 719 | //char allow_long_cmd[] = "ATAL\r"; |
| bala0x07 | 2:49712259aa71 | 720 | //char engine_rpm_cmd[] = "010C\r"; |
| bala0x07 | 2:49712259aa71 | 721 | //char vehicle_speed_cmd[] = "010D\r"; |
| bala0x07 | 2:49712259aa71 | 722 | //char vin_number_cmd[] = "0902 5\r"; |
| bala0x07 | 2:49712259aa71 | 723 | //char check_dtc_cmd[] = "03\r"; |
| bala0x07 | 2:49712259aa71 | 724 | //char check_mil_cmd[] = "0101\r"; |
| bala0x07 | 2:49712259aa71 | 725 | // |
| bala0x07 | 2:49712259aa71 | 726 | // |
| bala0x07 | 2:49712259aa71 | 727 | ///* |
| bala0x07 | 2:49712259aa71 | 728 | //__________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 729 | // |
| bala0x07 | 2:49712259aa71 | 730 | // THE FOLLOWING ARE GLOBAL VARIABLES WHICH CAN BE ACCESSED FOR FURTHER DATA PROCESSING |
| bala0x07 | 2:49712259aa71 | 731 | //__________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 732 | // |
| bala0x07 | 2:49712259aa71 | 733 | //*/ |
| bala0x07 | 2:49712259aa71 | 734 | // |
| bala0x07 | 2:49712259aa71 | 735 | //float car_battery_voltage; |
| bala0x07 | 2:49712259aa71 | 736 | //long rpm; |
| bala0x07 | 2:49712259aa71 | 737 | //long vehicle_speed; |
| bala0x07 | 2:49712259aa71 | 738 | //char vin_number[17]; |
| bala0x07 | 2:49712259aa71 | 739 | //char mil; |
| bala0x07 | 2:49712259aa71 | 740 | //char no_of_stored_dtc; |
| bala0x07 | 2:49712259aa71 | 741 | // |
| bala0x07 | 2:49712259aa71 | 742 | ////_________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 743 | // |
| bala0x07 | 2:49712259aa71 | 744 | //// THE FOLLWOING VARIABLES ARE GLOBAL BUT ARE USED ONLY FOR IN-LIBRARY PROCESSING |
| bala0x07 | 2:49712259aa71 | 745 | // |
| bala0x07 | 2:49712259aa71 | 746 | //char OBD_UART_RX_Buffer[50]; |
| bala0x07 | 2:49712259aa71 | 747 | //extern char OBD_RxBuffer_End_Pos; |
| bala0x07 | 2:49712259aa71 | 748 | // |
| bala0x07 | 2:49712259aa71 | 749 | ////_________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 750 | // |
| bala0x07 | 2:49712259aa71 | 751 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 752 | // |
| bala0x07 | 2:49712259aa71 | 753 | //// SELF CALL FUNCTION |
| bala0x07 | 2:49712259aa71 | 754 | //// THE FOLLWOING CODE BLOCK DEFINES THE ISR OF THE OBD RECEIVE INTERRUPT |
| bala0x07 | 2:49712259aa71 | 755 | //// THIS PIECE OF CODE JUST FILLS THE OBD RECEIVE BUFFER WITH THE INCOMING DATA RUSHING FROM THE OBD-UART INTERPRETER |
| bala0x07 | 2:49712259aa71 | 756 | //void OBD_onDataRx() |
| bala0x07 | 2:49712259aa71 | 757 | //{ |
| bala0x07 | 2:49712259aa71 | 758 | // if(OBD_UART.readable()) { |
| bala0x07 | 2:49712259aa71 | 759 | // pco.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UART.getc()); |
| bala0x07 | 2:49712259aa71 | 760 | // } |
| bala0x07 | 2:49712259aa71 | 761 | //} |
| bala0x07 | 2:49712259aa71 | 762 | // |
| bala0x07 | 2:49712259aa71 | 763 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 764 | // |
| bala0x07 | 2:49712259aa71 | 765 | //// FUNCTION CALLED BY PARENT FUNCTION |
| bala0x07 | 2:49712259aa71 | 766 | //// THE FOLLOWING CODE BLOCK IS USED TO VERIFY THE RECEIVED DATA |
| bala0x07 | 2:49712259aa71 | 767 | // |
| bala0x07 | 2:49712259aa71 | 768 | //void received_data_verification(char *rcv_data_pointer, char *ref_data_pointer, char num) |
| bala0x07 | 2:49712259aa71 | 769 | //{ |
| bala0x07 | 2:49712259aa71 | 770 | // char dummy_data[num], count; |
| bala0x07 | 2:49712259aa71 | 771 | // for(count = 0; count < num; count++) |
| bala0x07 | 2:49712259aa71 | 772 | // { |
| bala0x07 | 2:49712259aa71 | 773 | // pco.putc(*rcv_data_pointer); |
| bala0x07 | 2:49712259aa71 | 774 | // if(*rcv_data_pointer++ == *ref_data_pointer++) |
| bala0x07 | 2:49712259aa71 | 775 | // pass = 1; |
| bala0x07 | 2:49712259aa71 | 776 | // else |
| bala0x07 | 2:49712259aa71 | 777 | // { |
| bala0x07 | 2:49712259aa71 | 778 | // pass = 0; |
| bala0x07 | 2:49712259aa71 | 779 | // return; |
| bala0x07 | 2:49712259aa71 | 780 | // } |
| bala0x07 | 2:49712259aa71 | 781 | // } |
| bala0x07 | 2:49712259aa71 | 782 | //} |
| bala0x07 | 2:49712259aa71 | 783 | // |
| bala0x07 | 2:49712259aa71 | 784 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 785 | // |
| bala0x07 | 2:49712259aa71 | 786 | //// FUNCTION WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 787 | //// 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 |
| bala0x07 | 2:49712259aa71 | 788 | //// THIS CODE BLOCK IS WRITTEN IN A INTENSION JUST TO TEST THE COMMUNICATION |
| bala0x07 | 2:49712259aa71 | 789 | //// THE CODE BLOCK IS SUBJECTED TO REMOVAL AT THE FINAL STAGE |
| bala0x07 | 2:49712259aa71 | 790 | // |
| bala0x07 | 2:49712259aa71 | 791 | //void rpm_padding_for_comm_test() |
| bala0x07 | 2:49712259aa71 | 792 | //{ |
| bala0x07 | 2:49712259aa71 | 793 | // |
| bala0x07 | 2:49712259aa71 | 794 | // char count; |
| bala0x07 | 2:49712259aa71 | 795 | // char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>"; |
| bala0x07 | 2:49712259aa71 | 796 | // char engine_rpm[4]; // Vehicle speed data is returned by a 4 byte value |
| bala0x07 | 2:49712259aa71 | 797 | // char *rpm_data_pointer; |
| bala0x07 | 2:49712259aa71 | 798 | // char internal_count = 0; |
| bala0x07 | 2:49712259aa71 | 799 | // char padded_rpm_17_bytes[17]; |
| bala0x07 | 2:49712259aa71 | 800 | // |
| bala0x07 | 2:49712259aa71 | 801 | // /* |
| bala0x07 | 2:49712259aa71 | 802 | // for(count = 0; count < strlen(engine_rpm_cmd); count ++) |
| bala0x07 | 2:49712259aa71 | 803 | // OBD_UART.putc(engine_rpm_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 804 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 805 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 806 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 807 | // received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 808 | // */ |
| bala0x07 | 2:49712259aa71 | 809 | // |
| bala0x07 | 2:49712259aa71 | 810 | // rpm_data_pointer = virtual_engine_rpm; |
| bala0x07 | 2:49712259aa71 | 811 | // rpm_data_pointer += 11; |
| bala0x07 | 2:49712259aa71 | 812 | // |
| bala0x07 | 2:49712259aa71 | 813 | // for(count = 0; count < 5; count++) |
| bala0x07 | 2:49712259aa71 | 814 | // { |
| bala0x07 | 2:49712259aa71 | 815 | // if(*rpm_data_pointer == ' ') { // Negate the spaces added in between |
| bala0x07 | 2:49712259aa71 | 816 | // rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 817 | // continue; } |
| bala0x07 | 2:49712259aa71 | 818 | // else { |
| bala0x07 | 2:49712259aa71 | 819 | // engine_rpm[internal_count] = *rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 820 | // internal_count++; } |
| bala0x07 | 2:49712259aa71 | 821 | // } |
| bala0x07 | 2:49712259aa71 | 822 | // |
| bala0x07 | 2:49712259aa71 | 823 | // //pco.printf("\r\n%s", engine_rpm); |
| bala0x07 | 2:49712259aa71 | 824 | // //pco.printf("\r\nRPMMMMMM = "); |
| bala0x07 | 2:49712259aa71 | 825 | // for(count = 0; count < strlen(engine_rpm); count++) |
| bala0x07 | 2:49712259aa71 | 826 | // pco.putc(engine_rpm[count]); |
| bala0x07 | 2:49712259aa71 | 827 | // |
| bala0x07 | 2:49712259aa71 | 828 | // for(count = 0; count < 4; count++){ |
| bala0x07 | 2:49712259aa71 | 829 | // pco.printf("\r\nPadded = "); |
| bala0x07 | 2:49712259aa71 | 830 | // for(internal_count = 0; internal_count < strlen(padded_rpm_17_bytes); internal_count++) |
| bala0x07 | 2:49712259aa71 | 831 | // pco.putc(padded_rpm_17_bytes[internal_count]); |
| bala0x07 | 2:49712259aa71 | 832 | // //pco.printf("\r\nPadded RPM = %s", padded_rpm_17_bytes); |
| bala0x07 | 2:49712259aa71 | 833 | // strcat(padded_rpm_17_bytes, engine_rpm); } |
| bala0x07 | 2:49712259aa71 | 834 | // |
| bala0x07 | 2:49712259aa71 | 835 | // strcat(padded_rpm_17_bytes, "0"); |
| bala0x07 | 2:49712259aa71 | 836 | // pco.printf("\r\n\r\n PADDED RPM = %s",padded_rpm_17_bytes); |
| bala0x07 | 2:49712259aa71 | 837 | // pco.putc('\r'); |
| bala0x07 | 2:49712259aa71 | 838 | // for(count = 0; count < strlen(padded_rpm_17_bytes); count++) |
| bala0x07 | 2:49712259aa71 | 839 | // pco.putc(padded_rpm_17_bytes[count]); |
| bala0x07 | 2:49712259aa71 | 840 | //} |
| bala0x07 | 2:49712259aa71 | 841 | // |
| bala0x07 | 2:49712259aa71 | 842 | // |
| bala0x07 | 2:49712259aa71 | 843 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 844 | // |
| bala0x07 | 2:49712259aa71 | 845 | //// FUNCTION CALLED FROM PARENT FUNCTION |
| bala0x07 | 2:49712259aa71 | 846 | //// THE FOLLOWING CODE BLOCK IS USED TO PROCESS THE DTC DATA FETCHED FROM THE OBD PORT OF THE CAR |
| bala0x07 | 2:49712259aa71 | 847 | // |
| bala0x07 | 2:49712259aa71 | 848 | //void process_dtc_data(char *dtc_data_pointer) // Incomplete Code block |
| bala0x07 | 2:49712259aa71 | 849 | //{ |
| bala0x07 | 2:49712259aa71 | 850 | // char count1, count2, count_bytes = 0; |
| bala0x07 | 2:49712259aa71 | 851 | // char dtc_data[2]; // Since each DTC needs 2 bytes to make the code |
| bala0x07 | 2:49712259aa71 | 852 | // dtc_data_pointer += 6; // Neglecting the preceding data to scroll to the actual data having some meaning |
| bala0x07 | 2:49712259aa71 | 853 | // |
| bala0x07 | 2:49712259aa71 | 854 | // char dtc_codes[5]; |
| bala0x07 | 2:49712259aa71 | 855 | // |
| bala0x07 | 2:49712259aa71 | 856 | // for(count1 = 0; count1 < (strlen(dtc_data_pointer)); count1++) |
| bala0x07 | 2:49712259aa71 | 857 | // { |
| bala0x07 | 2:49712259aa71 | 858 | // if(*(dtc_data_pointer + count1) != '\r'){ |
| bala0x07 | 2:49712259aa71 | 859 | // count_bytes++;} |
| bala0x07 | 2:49712259aa71 | 860 | // |
| bala0x07 | 2:49712259aa71 | 861 | // else |
| bala0x07 | 2:49712259aa71 | 862 | // break; |
| bala0x07 | 2:49712259aa71 | 863 | // } |
| bala0x07 | 2:49712259aa71 | 864 | // |
| bala0x07 | 2:49712259aa71 | 865 | ///* |
| bala0x07 | 2:49712259aa71 | 866 | //|______________________________________________________________________________________________| |
| bala0x07 | 2:49712259aa71 | 867 | // |
| bala0x07 | 2:49712259aa71 | 868 | //FORMULA: |
| bala0x07 | 2:49712259aa71 | 869 | //------- |
| bala0x07 | 2:49712259aa71 | 870 | //t = total bytes of returned data |
| bala0x07 | 2:49712259aa71 | 871 | //n = no of dtc |
| bala0x07 | 2:49712259aa71 | 872 | // |
| bala0x07 | 2:49712259aa71 | 873 | //t = 2n + (n -1) , where (n-1) indicates the added spaces between two bytes |
| bala0x07 | 2:49712259aa71 | 874 | //t = 3n -1 |
| bala0x07 | 2:49712259aa71 | 875 | // |
| bala0x07 | 2:49712259aa71 | 876 | //Therefore, n = (t + 1) / 3 |
| bala0x07 | 2:49712259aa71 | 877 | // |
| bala0x07 | 2:49712259aa71 | 878 | //|______________________________________________________________________________________________| |
| bala0x07 | 2:49712259aa71 | 879 | // |
| bala0x07 | 2:49712259aa71 | 880 | //*/ |
| bala0x07 | 2:49712259aa71 | 881 | // if(((count_bytes + 1)/3) == no_of_stored_dtc) |
| bala0x07 | 2:49712259aa71 | 882 | // pco.printf("\r\nNO OF STORED DTC MATCHES WITH THE DTC CODE RETURNED"); |
| bala0x07 | 2:49712259aa71 | 883 | // else |
| bala0x07 | 2:49712259aa71 | 884 | // pco.printf("\r\nNO OF STORED DTC DOESNT MATCH WITH THE DTC DATA RETURNED"); |
| bala0x07 | 2:49712259aa71 | 885 | // /* |
| bala0x07 | 2:49712259aa71 | 886 | // pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 887 | // pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 888 | // pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 889 | // pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 890 | // pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); |
| bala0x07 | 2:49712259aa71 | 891 | // */ |
| bala0x07 | 2:49712259aa71 | 892 | // dtc_data_pointer -= 4; |
| bala0x07 | 2:49712259aa71 | 893 | // |
| bala0x07 | 2:49712259aa71 | 894 | // for(count1 = 0; count1 < no_of_stored_dtc; count1++) |
| bala0x07 | 2:49712259aa71 | 895 | // { |
| bala0x07 | 2:49712259aa71 | 896 | // for(count2 = 0; count2 < 2; count2++) |
| bala0x07 | 2:49712259aa71 | 897 | // { |
| bala0x07 | 2:49712259aa71 | 898 | // //dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data |
| bala0x07 | 2:49712259aa71 | 899 | // dtc_data[count1] = *dtc_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 900 | // //pco.printf("\r\nData = %c", dtc_data[count1]); |
| bala0x07 | 2:49712259aa71 | 901 | // } |
| bala0x07 | 2:49712259aa71 | 902 | // |
| bala0x07 | 2:49712259aa71 | 903 | // dtc_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 904 | // |
| bala0x07 | 2:49712259aa71 | 905 | // switch((dtc_data[0] & 0x11000000) >> 6) |
| bala0x07 | 2:49712259aa71 | 906 | // { |
| bala0x07 | 2:49712259aa71 | 907 | // case 0: |
| bala0x07 | 2:49712259aa71 | 908 | // dtc_codes[count1*5] = 'P'; |
| bala0x07 | 2:49712259aa71 | 909 | // break; |
| bala0x07 | 2:49712259aa71 | 910 | // |
| bala0x07 | 2:49712259aa71 | 911 | // case 1: |
| bala0x07 | 2:49712259aa71 | 912 | // dtc_codes[count1*5] = 'C'; |
| bala0x07 | 2:49712259aa71 | 913 | // break; |
| bala0x07 | 2:49712259aa71 | 914 | // |
| bala0x07 | 2:49712259aa71 | 915 | // case 2: |
| bala0x07 | 2:49712259aa71 | 916 | // dtc_codes[count1*5] = 'B'; |
| bala0x07 | 2:49712259aa71 | 917 | // break; |
| bala0x07 | 2:49712259aa71 | 918 | // |
| bala0x07 | 2:49712259aa71 | 919 | // case 3: |
| bala0x07 | 2:49712259aa71 | 920 | // dtc_codes[count1*5] = 'U'; |
| bala0x07 | 2:49712259aa71 | 921 | // break; |
| bala0x07 | 2:49712259aa71 | 922 | // } |
| bala0x07 | 2:49712259aa71 | 923 | // |
| bala0x07 | 2:49712259aa71 | 924 | // dtc_codes[1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); |
| bala0x07 | 2:49712259aa71 | 925 | // dtc_codes[2] = ((dtc_data[0] & 0b00001111) + 0x30); |
| bala0x07 | 2:49712259aa71 | 926 | // dtc_codes[3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30); |
| bala0x07 | 2:49712259aa71 | 927 | // dtc_codes[4] = ((dtc_data[1] & 0b00001111) + 0x30); |
| bala0x07 | 2:49712259aa71 | 928 | // |
| bala0x07 | 2:49712259aa71 | 929 | // pco.printf("\r\n DTC CODE NO %d : %s", count1+1, dtc_codes); |
| bala0x07 | 2:49712259aa71 | 930 | // } |
| bala0x07 | 2:49712259aa71 | 931 | //} |
| bala0x07 | 2:49712259aa71 | 932 | // |
| bala0x07 | 2:49712259aa71 | 933 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 934 | // |
| bala0x07 | 2:49712259aa71 | 935 | //// FUNCTION CALLED FROM PARENT FUNCTION |
| bala0x07 | 2:49712259aa71 | 936 | //// THE FOLLOWING CODE BLOCK IS USED TO PROCESS MIL DATA FETCHED FROM THE OBD PORT OF THE CAR |
| bala0x07 | 2:49712259aa71 | 937 | // |
| bala0x07 | 2:49712259aa71 | 938 | //void process_mil_data(char *mil_data_pointer) |
| bala0x07 | 2:49712259aa71 | 939 | //{ |
| bala0x07 | 2:49712259aa71 | 940 | // char mil_data[2], mil_data_converted; |
| bala0x07 | 2:49712259aa71 | 941 | // char count; |
| bala0x07 | 2:49712259aa71 | 942 | // |
| bala0x07 | 2:49712259aa71 | 943 | // // char virtual_mil_buffer = "0101\r41 01 00 04 60 00 \r\r"; |
| bala0x07 | 2:49712259aa71 | 944 | // mil_data_pointer += 11; |
| bala0x07 | 2:49712259aa71 | 945 | // |
| bala0x07 | 2:49712259aa71 | 946 | // for(count = 0; count < 2; count++) |
| bala0x07 | 2:49712259aa71 | 947 | // { |
| bala0x07 | 2:49712259aa71 | 948 | // mil_data[count] = *mil_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 949 | // } |
| bala0x07 | 2:49712259aa71 | 950 | // |
| bala0x07 | 2:49712259aa71 | 951 | // mil_data_converted = (((mil_data[0] - 0x30)<<4) + (mil_data[1] - 0x30)); // Converting the ASCII data to the Hex data |
| bala0x07 | 2:49712259aa71 | 952 | // |
| bala0x07 | 2:49712259aa71 | 953 | // // The following code lines checks for the number of Mal function indicator lamp enabled by tghe CAN ECU |
| bala0x07 | 2:49712259aa71 | 954 | // |
| bala0x07 | 2:49712259aa71 | 955 | // if(mil_data_converted & 0x80) // Checks for the MSB bit enabled or not which inc=dicates that the MIL is On or NOT |
| bala0x07 | 2:49712259aa71 | 956 | // { |
| bala0x07 | 2:49712259aa71 | 957 | // mil = 1; // Setting the MIL flag |
| bala0x07 | 2:49712259aa71 | 958 | // pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS ON"); |
| bala0x07 | 2:49712259aa71 | 959 | // no_of_stored_dtc = (mil_data_converted & 0b01111111); |
| bala0x07 | 2:49712259aa71 | 960 | // pco.printf("\r\n NO OF STORED DYNAMIC TROUBLE CODE = %d", no_of_stored_dtc); |
| bala0x07 | 2:49712259aa71 | 961 | // } |
| bala0x07 | 2:49712259aa71 | 962 | // else { |
| bala0x07 | 2:49712259aa71 | 963 | // mil = 0; // Clearing the MIL flag |
| bala0x07 | 2:49712259aa71 | 964 | // pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS OFF"); } |
| bala0x07 | 2:49712259aa71 | 965 | //} |
| bala0x07 | 2:49712259aa71 | 966 | // |
| bala0x07 | 2:49712259aa71 | 967 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 968 | // |
| bala0x07 | 2:49712259aa71 | 969 | //// FUNCTION CALLED FROM PARENT FUNCTION |
| bala0x07 | 2:49712259aa71 | 970 | //// THE FOLLWOING CODE BLOCK IS USED TO PROCESS THE VEHICLE SPEED DATA FETCHED FROM THE OBD PORT OF THE CAR |
| bala0x07 | 2:49712259aa71 | 971 | // |
| bala0x07 | 2:49712259aa71 | 972 | //void process_vehicle_speed(char *vehicle_speed_pointer) |
| bala0x07 | 2:49712259aa71 | 973 | //{ |
| bala0x07 | 2:49712259aa71 | 974 | // char vehicle_speed_data[2]; // Vehicle speed data is returned by a 2 byte value |
| bala0x07 | 2:49712259aa71 | 975 | // char *strtol_pointer; |
| bala0x07 | 2:49712259aa71 | 976 | // char count; |
| bala0x07 | 2:49712259aa71 | 977 | // //"010D\r41 0D 4F\r\r>" |
| bala0x07 | 2:49712259aa71 | 978 | // vehicle_speed_pointer += 11; |
| bala0x07 | 2:49712259aa71 | 979 | // for(count = 0; count < 2; count++) |
| bala0x07 | 2:49712259aa71 | 980 | // { |
| bala0x07 | 2:49712259aa71 | 981 | // vehicle_speed_data[count] = *vehicle_speed_pointer++; |
| bala0x07 | 2:49712259aa71 | 982 | // } |
| bala0x07 | 2:49712259aa71 | 983 | // |
| bala0x07 | 2:49712259aa71 | 984 | // vehicle_speed = strtol(vehicle_speed_data, &strtol_pointer, 16); |
| bala0x07 | 2:49712259aa71 | 985 | // |
| bala0x07 | 2:49712259aa71 | 986 | // pco.printf("\r\nVEHICLE SPEED = %ld", vehicle_speed); |
| bala0x07 | 2:49712259aa71 | 987 | //} |
| bala0x07 | 2:49712259aa71 | 988 | // |
| bala0x07 | 2:49712259aa71 | 989 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 990 | // |
| bala0x07 | 2:49712259aa71 | 991 | //// FUNCTION CALLED BY PARENT FUCTION |
| bala0x07 | 2:49712259aa71 | 992 | //// THE FOLLWOING CODE BLOCK IS USED TO PROCESS THE ENGINE RPM FETCHED FROM THE OBD PORT OF THE CAR |
| bala0x07 | 2:49712259aa71 | 993 | // |
| bala0x07 | 2:49712259aa71 | 994 | //void process_engine_rpm(char *rpm_data_pointer) |
| bala0x07 | 2:49712259aa71 | 995 | //{ |
| bala0x07 | 2:49712259aa71 | 996 | // //char virtual_engine_rpm[] = "010C\r41 0C 00 00 \r\r>"; |
| bala0x07 | 2:49712259aa71 | 997 | // char engine_rpm[4]; // Vehicle speed data is returned by a 4 byte value |
| bala0x07 | 2:49712259aa71 | 998 | // char *strtol_pointer; |
| bala0x07 | 2:49712259aa71 | 999 | // char count; |
| bala0x07 | 2:49712259aa71 | 1000 | // char internal_count = 0; |
| bala0x07 | 2:49712259aa71 | 1001 | // |
| bala0x07 | 2:49712259aa71 | 1002 | // rpm_data_pointer += 11; |
| bala0x07 | 2:49712259aa71 | 1003 | // |
| bala0x07 | 2:49712259aa71 | 1004 | // for(count = 0; count < 5; count++) |
| bala0x07 | 2:49712259aa71 | 1005 | // { |
| bala0x07 | 2:49712259aa71 | 1006 | // if(*rpm_data_pointer == ' ') { // Negate the spaces added in between |
| bala0x07 | 2:49712259aa71 | 1007 | // rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 1008 | // continue; } |
| bala0x07 | 2:49712259aa71 | 1009 | // else { |
| bala0x07 | 2:49712259aa71 | 1010 | // engine_rpm[internal_count] = *rpm_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 1011 | // internal_count++; } |
| bala0x07 | 2:49712259aa71 | 1012 | // } |
| bala0x07 | 2:49712259aa71 | 1013 | // |
| bala0x07 | 2:49712259aa71 | 1014 | // pco.printf("\r\n%s", engine_rpm); |
| bala0x07 | 2:49712259aa71 | 1015 | // |
| bala0x07 | 2:49712259aa71 | 1016 | // rpm = ((strtol(engine_rpm, &strtol_pointer, 16)) / 4); |
| bala0x07 | 2:49712259aa71 | 1017 | // |
| bala0x07 | 2:49712259aa71 | 1018 | // pco.printf("\r\nENGINE RPM = %ld", rpm); |
| bala0x07 | 2:49712259aa71 | 1019 | // |
| bala0x07 | 2:49712259aa71 | 1020 | //} |
| bala0x07 | 2:49712259aa71 | 1021 | // |
| bala0x07 | 2:49712259aa71 | 1022 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1023 | // |
| bala0x07 | 2:49712259aa71 | 1024 | //// FUNCTION CALLED BY PARENT FUNCTION |
| bala0x07 | 2:49712259aa71 | 1025 | //// THE FOLLOWING CODE BLOCK IS USED TO PROCESS THE BATTERY VOLTAGE FETCHED FROM THE OBD PORT OF THE CAR |
| bala0x07 | 2:49712259aa71 | 1026 | // |
| bala0x07 | 2:49712259aa71 | 1027 | //void process_battery_voltage(char *battery_voltage_pointer) |
| bala0x07 | 2:49712259aa71 | 1028 | //{ |
| bala0x07 | 2:49712259aa71 | 1029 | // char battery_voltage_data[4]; // One decimal point precision ( For ex : 12.5 ) |
| bala0x07 | 2:49712259aa71 | 1030 | // char count; |
| bala0x07 | 2:49712259aa71 | 1031 | // battery_voltage_pointer += 5; // ATRV<CR> counts to 5 |
| bala0x07 | 2:49712259aa71 | 1032 | // for(count = 0; count < 4; count++) |
| bala0x07 | 2:49712259aa71 | 1033 | // { |
| bala0x07 | 2:49712259aa71 | 1034 | // battery_voltage_data[count] = *battery_voltage_pointer++; |
| bala0x07 | 2:49712259aa71 | 1035 | // } |
| bala0x07 | 2:49712259aa71 | 1036 | // car_battery_voltage = atof(battery_voltage_data); // Converts the Battery Volatge from String to Float data type |
| bala0x07 | 2:49712259aa71 | 1037 | // |
| bala0x07 | 2:49712259aa71 | 1038 | // pco.printf("\r\nCAR BATTERY VOLTAGE = %f",car_battery_voltage); |
| bala0x07 | 2:49712259aa71 | 1039 | //} |
| bala0x07 | 2:49712259aa71 | 1040 | // |
| bala0x07 | 2:49712259aa71 | 1041 | // |
| bala0x07 | 2:49712259aa71 | 1042 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1043 | // |
| bala0x07 | 2:49712259aa71 | 1044 | ///* |
| bala0x07 | 2:49712259aa71 | 1045 | //_______________________________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 1046 | // |
| bala0x07 | 2:49712259aa71 | 1047 | //NOTE : |
| bala0x07 | 2:49712259aa71 | 1048 | //----- |
| bala0x07 | 2:49712259aa71 | 1049 | //THE FOLLOWING CODE O DETERMINE THE DIAGNOSTIC TROUBLE CODE (DTC) IS BASED ON THE INTERPRETATION GIVEN IN WIKIPEDIA |
| bala0x07 | 2:49712259aa71 | 1050 | //FOR THE ISO 15765-2 PROTOCOL |
| bala0x07 | 2:49712259aa71 | 1051 | //DIFFERENT INTERPRETATION METHODOLOGY IS GIVEN IN THE ELM327 DATASHEET FOR SAE PROTOCOL |
| bala0x07 | 2:49712259aa71 | 1052 | //SO THESE THINGS ARE SUBJECTED TO MODIFICATION AND HAVE NOT BEEN CONFIRMED WITH THE REAL TIME DATA |
| bala0x07 | 2:49712259aa71 | 1053 | //_______________________________________________________________________________________________________________________ |
| bala0x07 | 2:49712259aa71 | 1054 | // |
| bala0x07 | 2:49712259aa71 | 1055 | //*/ |
| bala0x07 | 2:49712259aa71 | 1056 | // |
| bala0x07 | 2:49712259aa71 | 1057 | //// FUNCTION WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 1058 | //// THE FOLLOWING CODE BLOCK WILL FETCH THE DTC DATA FROM THE OBD PORT OF THE CAR AND SENDS THE SAME FOR PROCESSING |
| bala0x07 | 2:49712259aa71 | 1059 | // |
| bala0x07 | 2:49712259aa71 | 1060 | //void check_for_dtc() |
| bala0x07 | 2:49712259aa71 | 1061 | //{ |
| bala0x07 | 2:49712259aa71 | 1062 | // char virtual_dtc_buffer[] = "03\r43 00 85\r\r>"; |
| bala0x07 | 2:49712259aa71 | 1063 | // |
| bala0x07 | 2:49712259aa71 | 1064 | // OBD_UART.printf(check_dtc_cmd); |
| bala0x07 | 2:49712259aa71 | 1065 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1066 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1067 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1068 | // received_data_verification(OBD_UART_RX_Buffer, check_dtc_cmd, (strlen(check_dtc_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1069 | // |
| bala0x07 | 2:49712259aa71 | 1070 | // //process_dtc_data(virtual_dtc_buffer); |
| bala0x07 | 2:49712259aa71 | 1071 | // |
| bala0x07 | 2:49712259aa71 | 1072 | // if(pass == 1) { |
| bala0x07 | 2:49712259aa71 | 1073 | // process_dtc_data(OBD_UART_RX_Buffer); |
| bala0x07 | 2:49712259aa71 | 1074 | // printf("\r\VEHICLE DIAGNOSTIC TROUBLE CODE RECEIVED SUCCESSFULLY \r\n\r\n"); } |
| bala0x07 | 2:49712259aa71 | 1075 | // else |
| bala0x07 | 2:49712259aa71 | 1076 | // printf("\r\nVEHICLE DIAGNOSTIC TROUBLE CODE DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1077 | // reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 2:49712259aa71 | 1078 | // OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 1079 | // |
| bala0x07 | 2:49712259aa71 | 1080 | //} |
| bala0x07 | 2:49712259aa71 | 1081 | // |
| bala0x07 | 2:49712259aa71 | 1082 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1083 | // |
| bala0x07 | 2:49712259aa71 | 1084 | //// FUNCTION WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 1085 | //// THE FOLLOWING CODE BLOCK WILL FETCH THE MIL DATA FROM THE OBD PORT OF THE CAR |
| bala0x07 | 2:49712259aa71 | 1086 | // |
| bala0x07 | 2:49712259aa71 | 1087 | //void check_for_MIL() |
| bala0x07 | 2:49712259aa71 | 1088 | //{ |
| bala0x07 | 2:49712259aa71 | 1089 | // char count; |
| bala0x07 | 2:49712259aa71 | 1090 | // //char virtual_mil_buffer[] = "0101\r41 01 82 04 60 00 \r\r"; |
| bala0x07 | 2:49712259aa71 | 1091 | // //OBD_UART.printf(check_mil_cmd); |
| bala0x07 | 2:49712259aa71 | 1092 | // |
| bala0x07 | 2:49712259aa71 | 1093 | // for(count = 0; count < strlen(check_mil_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 1094 | // OBD_UART.putc(check_mil_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 1095 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1096 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1097 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1098 | // received_data_verification(OBD_UART_RX_Buffer, check_mil_cmd, (strlen(check_mil_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1099 | // |
| bala0x07 | 2:49712259aa71 | 1100 | // |
| bala0x07 | 2:49712259aa71 | 1101 | // //process_mil_data(virtual_mil_buffer); |
| bala0x07 | 2:49712259aa71 | 1102 | // |
| bala0x07 | 2:49712259aa71 | 1103 | // |
| bala0x07 | 2:49712259aa71 | 1104 | // if(pass == 1) { |
| bala0x07 | 2:49712259aa71 | 1105 | // process_mil_data(OBD_UART_RX_Buffer); |
| bala0x07 | 2:49712259aa71 | 1106 | // printf("\r\nVEHICLE MIL DATA RECEIVED SUCCESSFULLY \r\n\r\n"); } |
| bala0x07 | 2:49712259aa71 | 1107 | // else |
| bala0x07 | 2:49712259aa71 | 1108 | // printf("\r\nVEHICLE MIL DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1109 | // reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 2:49712259aa71 | 1110 | // OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 1111 | // |
| bala0x07 | 2:49712259aa71 | 1112 | //} |
| bala0x07 | 2:49712259aa71 | 1113 | // |
| bala0x07 | 2:49712259aa71 | 1114 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1115 | // |
| bala0x07 | 2:49712259aa71 | 1116 | //// FUNCTION WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 1117 | //// THE FOLLOWING CODE BLOCK WILL FETCH AND PROCESS THE VIN DATA FROM THE OBD PORT OF THE CAR |
| bala0x07 | 2:49712259aa71 | 1118 | // |
| bala0x07 | 2:49712259aa71 | 1119 | //void fetch_vin_number() |
| bala0x07 | 2:49712259aa71 | 1120 | //{ |
| bala0x07 | 2:49712259aa71 | 1121 | // char count; |
| bala0x07 | 2:49712259aa71 | 1122 | // //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>"; |
| bala0x07 | 2:49712259aa71 | 1123 | // |
| bala0x07 | 2:49712259aa71 | 1124 | // char vin_buffer[100]; |
| bala0x07 | 2:49712259aa71 | 1125 | // char *vin_data_pointer; |
| bala0x07 | 2:49712259aa71 | 1126 | // char internal_counter = 0; |
| bala0x07 | 2:49712259aa71 | 1127 | // char small_buffer[2]; |
| bala0x07 | 2:49712259aa71 | 1128 | // long ascii_converted_data; |
| bala0x07 | 2:49712259aa71 | 1129 | // char *vin_conv_pointer; |
| bala0x07 | 2:49712259aa71 | 1130 | // char vin_number[17]; |
| bala0x07 | 2:49712259aa71 | 1131 | // |
| bala0x07 | 2:49712259aa71 | 1132 | // for(count = 0; count < strlen(vin_number_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 1133 | // OBD_UART.putc(vin_number_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 1134 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1135 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1136 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1137 | // received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1138 | // |
| bala0x07 | 2:49712259aa71 | 1139 | // //vin_data_pointer = virtual_rx_vin_buffer; |
| bala0x07 | 2:49712259aa71 | 1140 | // vin_data_pointer = OBD_UART_RX_Buffer; |
| bala0x07 | 2:49712259aa71 | 1141 | // vin_data_pointer += 23; |
| bala0x07 | 2:49712259aa71 | 1142 | // |
| bala0x07 | 2:49712259aa71 | 1143 | // int length; |
| bala0x07 | 2:49712259aa71 | 1144 | // for(count = 0; count < (strlen(vin_data_pointer) - 1); count++) |
| bala0x07 | 2:49712259aa71 | 1145 | // { |
| bala0x07 | 2:49712259aa71 | 1146 | // if((*vin_data_pointer == '\r') | (*vin_data_pointer == ' ') | (*vin_data_pointer == '>')) |
| bala0x07 | 2:49712259aa71 | 1147 | // { |
| bala0x07 | 2:49712259aa71 | 1148 | // vin_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 1149 | // continue; |
| bala0x07 | 2:49712259aa71 | 1150 | // } |
| bala0x07 | 2:49712259aa71 | 1151 | // else if(*(vin_data_pointer + 1) == ':') |
| bala0x07 | 2:49712259aa71 | 1152 | // { |
| bala0x07 | 2:49712259aa71 | 1153 | // vin_data_pointer += 2; |
| bala0x07 | 2:49712259aa71 | 1154 | // continue; |
| bala0x07 | 2:49712259aa71 | 1155 | // } |
| bala0x07 | 2:49712259aa71 | 1156 | // else |
| bala0x07 | 2:49712259aa71 | 1157 | // { |
| bala0x07 | 2:49712259aa71 | 1158 | // //printf("\r\ncount2 = %d", count); |
| bala0x07 | 2:49712259aa71 | 1159 | // vin_buffer[internal_counter] = *vin_data_pointer; |
| bala0x07 | 2:49712259aa71 | 1160 | // internal_counter++; |
| bala0x07 | 2:49712259aa71 | 1161 | // } |
| bala0x07 | 2:49712259aa71 | 1162 | // vin_data_pointer++; |
| bala0x07 | 2:49712259aa71 | 1163 | // } |
| bala0x07 | 2:49712259aa71 | 1164 | // |
| bala0x07 | 2:49712259aa71 | 1165 | // length = strlen(vin_buffer); |
| bala0x07 | 2:49712259aa71 | 1166 | // pco.printf("\r\n VIN BUFFER LENGTH = %d", length); |
| bala0x07 | 2:49712259aa71 | 1167 | // |
| bala0x07 | 2:49712259aa71 | 1168 | // pco.printf("\r\n VIN NUMBER : %s", vin_buffer); |
| bala0x07 | 2:49712259aa71 | 1169 | // |
| bala0x07 | 2:49712259aa71 | 1170 | // internal_counter = 0; |
| bala0x07 | 2:49712259aa71 | 1171 | // |
| bala0x07 | 2:49712259aa71 | 1172 | // for(count = 0; count < strlen(vin_buffer); count+=2) |
| bala0x07 | 2:49712259aa71 | 1173 | // { |
| bala0x07 | 2:49712259aa71 | 1174 | // small_buffer[0] = vin_buffer[count]; |
| bala0x07 | 2:49712259aa71 | 1175 | // small_buffer[1] = vin_buffer[count+1]; |
| bala0x07 | 2:49712259aa71 | 1176 | // ascii_converted_data = strtol(small_buffer, &vin_conv_pointer, 16); |
| bala0x07 | 2:49712259aa71 | 1177 | // vin_number[internal_counter] = ascii_converted_data; |
| bala0x07 | 2:49712259aa71 | 1178 | // internal_counter++; |
| bala0x07 | 2:49712259aa71 | 1179 | // } |
| bala0x07 | 2:49712259aa71 | 1180 | // pco.printf("\r\n\r\nVEHICLE CHASSIS NUMBER : %s", vin_number); |
| bala0x07 | 2:49712259aa71 | 1181 | //} |
| bala0x07 | 2:49712259aa71 | 1182 | // |
| bala0x07 | 2:49712259aa71 | 1183 | // |
| bala0x07 | 2:49712259aa71 | 1184 | // |
| bala0x07 | 2:49712259aa71 | 1185 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1186 | // |
| bala0x07 | 2:49712259aa71 | 1187 | //// FUNCTION WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 1188 | //// THE FOLLOWING CODE BLOCK FETCHES THE VEHICLE SPEED DATA FROM THE OBD PORT OF THE CAR AND SENDS THE SAME FOR PROCESSING |
| bala0x07 | 2:49712259aa71 | 1189 | // |
| bala0x07 | 2:49712259aa71 | 1190 | //void fetch_vehicle_speed() |
| bala0x07 | 2:49712259aa71 | 1191 | //{ |
| bala0x07 | 2:49712259aa71 | 1192 | // char virtual_rx_speed_buffer[] = "010D\r41 0D 4F \r\r>"; |
| bala0x07 | 2:49712259aa71 | 1193 | // char count; |
| bala0x07 | 2:49712259aa71 | 1194 | // //OBD_UART.printf(vehicle_speed_cmd); |
| bala0x07 | 2:49712259aa71 | 1195 | // |
| bala0x07 | 2:49712259aa71 | 1196 | // for(count = 0; count < strlen(vehicle_speed_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 1197 | // OBD_UART.putc(vehicle_speed_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 1198 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1199 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1200 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1201 | // received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1202 | // |
| bala0x07 | 2:49712259aa71 | 1203 | // // |
| bala0x07 | 2:49712259aa71 | 1204 | // //process_vehicle_speed(virtual_rx_speed_buffer); |
| bala0x07 | 2:49712259aa71 | 1205 | // |
| bala0x07 | 2:49712259aa71 | 1206 | // if(pass == 1) { |
| bala0x07 | 2:49712259aa71 | 1207 | // process_vehicle_speed(OBD_UART_RX_Buffer); |
| bala0x07 | 2:49712259aa71 | 1208 | // printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); } |
| bala0x07 | 2:49712259aa71 | 1209 | // else |
| bala0x07 | 2:49712259aa71 | 1210 | // printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1211 | // reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 2:49712259aa71 | 1212 | // OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 1213 | // |
| bala0x07 | 2:49712259aa71 | 1214 | //} |
| bala0x07 | 2:49712259aa71 | 1215 | // |
| bala0x07 | 2:49712259aa71 | 1216 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1217 | // |
| bala0x07 | 2:49712259aa71 | 1218 | //// FUNCITON WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 1219 | //// THE FOLLOWING CODE BLOCK FETCHES THE RPM DATA FROM THE OBD PORT OF THE CAR AND WILL SEND THE SAME FOR PROCESSING |
| bala0x07 | 2:49712259aa71 | 1220 | // |
| bala0x07 | 2:49712259aa71 | 1221 | //void fetch_engine_rpm() |
| bala0x07 | 2:49712259aa71 | 1222 | //{ |
| bala0x07 | 2:49712259aa71 | 1223 | // char count; |
| bala0x07 | 2:49712259aa71 | 1224 | // //char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>"; |
| bala0x07 | 2:49712259aa71 | 1225 | // |
| bala0x07 | 2:49712259aa71 | 1226 | // for(count = 0; count < strlen(engine_rpm_cmd); count ++) |
| bala0x07 | 2:49712259aa71 | 1227 | // OBD_UART.putc(engine_rpm_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 1228 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1229 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1230 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1231 | // received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1232 | // |
| bala0x07 | 2:49712259aa71 | 1233 | // |
| bala0x07 | 2:49712259aa71 | 1234 | // //process_engine_rpm(OBD_UART_RX_Buffer); |
| bala0x07 | 2:49712259aa71 | 1235 | // //process_engine_rpm(virtual_engine_rpm); |
| bala0x07 | 2:49712259aa71 | 1236 | // |
| bala0x07 | 2:49712259aa71 | 1237 | // if(pass == 1) { |
| bala0x07 | 2:49712259aa71 | 1238 | // process_engine_rpm(OBD_UART_RX_Buffer); |
| bala0x07 | 2:49712259aa71 | 1239 | // printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); } |
| bala0x07 | 2:49712259aa71 | 1240 | // else |
| bala0x07 | 2:49712259aa71 | 1241 | // printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1242 | // reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 2:49712259aa71 | 1243 | // OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 1244 | //} |
| bala0x07 | 2:49712259aa71 | 1245 | // |
| bala0x07 | 2:49712259aa71 | 1246 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1247 | // |
| bala0x07 | 2:49712259aa71 | 1248 | //// FUNCTION WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 1249 | //// THE FOLLOWING CODE BLOCK FETCHED THE BATTERY VOLTAGE DATA FROM THE OBD PORT AND PASSES THE SAME DATA FOR PROCESSING |
| bala0x07 | 2:49712259aa71 | 1250 | // |
| bala0x07 | 2:49712259aa71 | 1251 | //void fetch_battery_voltage() |
| bala0x07 | 2:49712259aa71 | 1252 | //{ |
| bala0x07 | 2:49712259aa71 | 1253 | // char count; |
| bala0x07 | 2:49712259aa71 | 1254 | // //OBD_UART.printf(battery_voltage_cmd); |
| bala0x07 | 2:49712259aa71 | 1255 | // |
| bala0x07 | 2:49712259aa71 | 1256 | // for(count = 0; count < strlen(battery_voltage_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 1257 | // OBD_UART.putc(battery_voltage_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 1258 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1259 | // |
| bala0x07 | 2:49712259aa71 | 1260 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1261 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1262 | // received_data_verification(OBD_UART_RX_Buffer, battery_voltage_cmd, (strlen(battery_voltage_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1263 | // |
| bala0x07 | 2:49712259aa71 | 1264 | // |
| bala0x07 | 2:49712259aa71 | 1265 | // if(pass == 1) { |
| bala0x07 | 2:49712259aa71 | 1266 | // pco.printf("\r\nOBD READ BATTERY VOLTAGE SUCCESSFUL"); |
| bala0x07 | 2:49712259aa71 | 1267 | // process_battery_voltage(OBD_UART_RX_Buffer); } |
| bala0x07 | 2:49712259aa71 | 1268 | // else |
| bala0x07 | 2:49712259aa71 | 1269 | // pco.printf("\r\nOBD READ BATTERY VOLTAGE FAILED"); |
| bala0x07 | 2:49712259aa71 | 1270 | // reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 2:49712259aa71 | 1271 | // OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 1272 | //} |
| bala0x07 | 2:49712259aa71 | 1273 | // |
| bala0x07 | 2:49712259aa71 | 1274 | // |
| bala0x07 | 2:49712259aa71 | 1275 | ////********************************************************************************************************************************************************************************* |
| bala0x07 | 2:49712259aa71 | 1276 | // |
| bala0x07 | 2:49712259aa71 | 1277 | //// FUNCTION WILL BE CALLED ON REQUEST |
| bala0x07 | 2:49712259aa71 | 1278 | //// TYHE FOLLOWING CODE BLOXK INITIALIZES THE OBD INTERFACE |
| bala0x07 | 2:49712259aa71 | 1279 | //// IT IS MANDATORY TO CALL THIS FUNCTION BEFORE USING ANY OF THE OTHER FUNCTIONS INCLUDED IN THIS PARTICULAR LIBRARY |
| bala0x07 | 2:49712259aa71 | 1280 | // |
| bala0x07 | 2:49712259aa71 | 1281 | //void initialize_obd() |
| bala0x07 | 2:49712259aa71 | 1282 | //{ |
| bala0x07 | 2:49712259aa71 | 1283 | // char count; |
| bala0x07 | 2:49712259aa71 | 1284 | // char data[3]; |
| bala0x07 | 2:49712259aa71 | 1285 | // char *data_pointer; |
| bala0x07 | 2:49712259aa71 | 1286 | // |
| bala0x07 | 2:49712259aa71 | 1287 | // data_pointer = data; |
| bala0x07 | 2:49712259aa71 | 1288 | // |
| bala0x07 | 2:49712259aa71 | 1289 | // pco.baud(9600); |
| bala0x07 | 2:49712259aa71 | 1290 | // OBD_UART.baud(9600); |
| bala0x07 | 2:49712259aa71 | 1291 | // |
| bala0x07 | 2:49712259aa71 | 1292 | // OBD_UART.attach(&OBD_onDataRx); |
| bala0x07 | 2:49712259aa71 | 1293 | // |
| bala0x07 | 2:49712259aa71 | 1294 | // //-------------------------------------------------------------------------------------------------------------------------- |
| bala0x07 | 2:49712259aa71 | 1295 | // |
| bala0x07 | 2:49712259aa71 | 1296 | // OBD_UART.printf("%s",obd_reset_cmd); |
| bala0x07 | 2:49712259aa71 | 1297 | // |
| bala0x07 | 2:49712259aa71 | 1298 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1299 | // |
| bala0x07 | 2:49712259aa71 | 1300 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1301 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1302 | // received_data_verification(OBD_UART_RX_Buffer, obd_reset_cmd, (strlen(obd_reset_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1303 | // |
| bala0x07 | 2:49712259aa71 | 1304 | // if(pass == 1) |
| bala0x07 | 2:49712259aa71 | 1305 | // pco.printf("\r\nOBD RESET SUCCESSFUL \r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1306 | // else |
| bala0x07 | 2:49712259aa71 | 1307 | // pco.printf("\r\nOBD RESET FAILED \r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1308 | // |
| bala0x07 | 2:49712259aa71 | 1309 | // reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 2:49712259aa71 | 1310 | // OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 1311 | // |
| bala0x07 | 2:49712259aa71 | 1312 | ////-------------------------------------------------------------------------------------------------------------------------- |
| bala0x07 | 2:49712259aa71 | 1313 | // |
| bala0x07 | 2:49712259aa71 | 1314 | // //OBD_UART.printf(allow_long_cmd); |
| bala0x07 | 2:49712259aa71 | 1315 | // for(count = 0; count < strlen(allow_long_cmd); count++) |
| bala0x07 | 2:49712259aa71 | 1316 | // OBD_UART.putc(allow_long_cmd[count]); |
| bala0x07 | 2:49712259aa71 | 1317 | // wait(1); |
| bala0x07 | 2:49712259aa71 | 1318 | // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 2:49712259aa71 | 1319 | // pco.printf("Reception Complete\r\n"); |
| bala0x07 | 2:49712259aa71 | 1320 | // received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(allow_long_cmd)-1)); |
| bala0x07 | 2:49712259aa71 | 1321 | // |
| bala0x07 | 2:49712259aa71 | 1322 | // if(pass == 1) |
| bala0x07 | 2:49712259aa71 | 1323 | // pco.printf("\r\nLONG DATA RECEPTION ENABLED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1324 | // else |
| bala0x07 | 2:49712259aa71 | 1325 | // pco.printf("\r\nLONG DATA RECEPTION ENABLING FAILED\r\n\r\n"); |
| bala0x07 | 2:49712259aa71 | 1326 | // reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 2:49712259aa71 | 1327 | // OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 2:49712259aa71 | 1328 | // |
| bala0x07 | 2:49712259aa71 | 1329 | //} |
| bala0x07 | 2:49712259aa71 | 1330 |