OBD Source Code -Section 1- Without Car / Section 2 - With car
Dependencies: mbed
obd_libraries.cpp@1:c23c05b36e33, 2017-03-19 (annotated)
- Committer:
- bala0x07
- Date:
- Sun Mar 19 22:57:49 2017 +0000
- Revision:
- 1:c23c05b36e33
- Parent:
- 0:e36d80703ed0
- Child:
- 2:49712259aa71
20-Mar-2017; Added VIN number
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bala0x07 | 0:e36d80703ed0 | 1 | #include "mbed.h" |
| bala0x07 | 0:e36d80703ed0 | 2 | #include "obd_libraries.h" |
| bala0x07 | 0:e36d80703ed0 | 3 | #include "common_definitions.h" |
| bala0x07 | 0:e36d80703ed0 | 4 | |
| bala0x07 | 0:e36d80703ed0 | 5 | Serial pco(USBTX, USBRX); |
| bala0x07 | 0:e36d80703ed0 | 6 | Serial OBD_UART(PA_0, PA_1); |
| bala0x07 | 0:e36d80703ed0 | 7 | |
| bala0x07 | 0:e36d80703ed0 | 8 | char pass = 0; |
| bala0x07 | 0:e36d80703ed0 | 9 | char reception_complete = 0; |
| bala0x07 | 0:e36d80703ed0 | 10 | |
| bala0x07 | 0:e36d80703ed0 | 11 | char obd_reset_cmd[] = "ATZ\r"; |
| bala0x07 | 0:e36d80703ed0 | 12 | char battery_voltage_cmd[] = "ATRV\r"; |
| bala0x07 | 0:e36d80703ed0 | 13 | char protocol_auto_detect_cmd[] = "ATSP0\r"; |
| bala0x07 | 0:e36d80703ed0 | 14 | char read_CAN_protocol_cmd[] = "ATDPN\r"; |
| bala0x07 | 0:e36d80703ed0 | 15 | char allow_long_cmd[] = "ATAL\r"; |
| bala0x07 | 0:e36d80703ed0 | 16 | char engine_rpm_cmd[] = "010C\r"; |
| bala0x07 | 0:e36d80703ed0 | 17 | char vehicle_speed_cmd[] = "010D\r"; |
| bala0x07 | 0:e36d80703ed0 | 18 | char vin_number_cmd[] = "0902 5\r"; |
| bala0x07 | 1:c23c05b36e33 | 19 | char check_dtc_cmd[] = "03\r"; |
| bala0x07 | 1:c23c05b36e33 | 20 | char check_mil_cmd[] = "0101\r"; |
| bala0x07 | 1:c23c05b36e33 | 21 | |
| bala0x07 | 1:c23c05b36e33 | 22 | char no_of_stored_dtc; |
| bala0x07 | 0:e36d80703ed0 | 23 | |
| bala0x07 | 0:e36d80703ed0 | 24 | float car_battery_voltage; |
| bala0x07 | 0:e36d80703ed0 | 25 | long vehicle_speed; |
| bala0x07 | 0:e36d80703ed0 | 26 | char OBD_UART_RX_Buffer[50]; |
| bala0x07 | 0:e36d80703ed0 | 27 | extern char OBD_RxBuffer_End_Pos; |
| bala0x07 | 0:e36d80703ed0 | 28 | //char OBD_UART_RX_Size = 50; |
| bala0x07 | 0:e36d80703ed0 | 29 | |
| bala0x07 | 0:e36d80703ed0 | 30 | |
| bala0x07 | 0:e36d80703ed0 | 31 | //Serial pco(USBTX, USBRX); |
| bala0x07 | 0:e36d80703ed0 | 32 | //Serial OBD_UART(PA_0, PA_1); |
| bala0x07 | 0:e36d80703ed0 | 33 | |
| bala0x07 | 0:e36d80703ed0 | 34 | void OBD_onDataRx() |
| bala0x07 | 0:e36d80703ed0 | 35 | { |
| bala0x07 | 0:e36d80703ed0 | 36 | //pcm.printf("\r\n ENTERED \r\n"); |
| bala0x07 | 0:e36d80703ed0 | 37 | if(OBD_UART.readable()) { |
| bala0x07 | 0:e36d80703ed0 | 38 | |
| bala0x07 | 0:e36d80703ed0 | 39 | pco.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UART.getc()); |
| bala0x07 | 0:e36d80703ed0 | 40 | /* |
| bala0x07 | 0:e36d80703ed0 | 41 | if(OBD_RxBuffer_End_Pos >= OBD_UART_RX_Size) { |
| bala0x07 | 0:e36d80703ed0 | 42 | // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. |
| bala0x07 | 0:e36d80703ed0 | 43 | // For now just throw everything away. |
| bala0x07 | 0:e36d80703ed0 | 44 | OBD_RxBuffer_End_Pos = 0; |
| bala0x07 | 0:e36d80703ed0 | 45 | } |
| bala0x07 | 0:e36d80703ed0 | 46 | */ |
| bala0x07 | 0:e36d80703ed0 | 47 | } |
| bala0x07 | 0:e36d80703ed0 | 48 | } |
| bala0x07 | 0:e36d80703ed0 | 49 | |
| bala0x07 | 0:e36d80703ed0 | 50 | |
| bala0x07 | 0:e36d80703ed0 | 51 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 52 | |
| bala0x07 | 0:e36d80703ed0 | 53 | void received_data_verification(char *rcv_data_pointer, char *ref_data_pointer, char num) |
| bala0x07 | 0:e36d80703ed0 | 54 | { |
| bala0x07 | 0:e36d80703ed0 | 55 | char dummy_data[num], count; |
| bala0x07 | 0:e36d80703ed0 | 56 | for(count = 0; count < num; count++) |
| bala0x07 | 0:e36d80703ed0 | 57 | { |
| bala0x07 | 0:e36d80703ed0 | 58 | pco.putc(*rcv_data_pointer); |
| bala0x07 | 0:e36d80703ed0 | 59 | if(*rcv_data_pointer++ == *ref_data_pointer++) |
| bala0x07 | 0:e36d80703ed0 | 60 | pass = 1; |
| bala0x07 | 0:e36d80703ed0 | 61 | else |
| bala0x07 | 0:e36d80703ed0 | 62 | { |
| bala0x07 | 0:e36d80703ed0 | 63 | pass = 0; |
| bala0x07 | 0:e36d80703ed0 | 64 | return; |
| bala0x07 | 0:e36d80703ed0 | 65 | } |
| bala0x07 | 0:e36d80703ed0 | 66 | } |
| bala0x07 | 0:e36d80703ed0 | 67 | } |
| bala0x07 | 0:e36d80703ed0 | 68 | |
| bala0x07 | 0:e36d80703ed0 | 69 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 70 | /* |
| bala0x07 | 0:e36d80703ed0 | 71 | char* copy_characters(char *copy_char_pointer, char start_position, char end_position) |
| bala0x07 | 0:e36d80703ed0 | 72 | { |
| bala0x07 | 0:e36d80703ed0 | 73 | char total_num; |
| bala0x07 | 0:e36d80703ed0 | 74 | char count; |
| bala0x07 | 0:e36d80703ed0 | 75 | total_num = end_position - start_position; |
| bala0x07 | 0:e36d80703ed0 | 76 | char copied_data[total_num]; |
| bala0x07 | 0:e36d80703ed0 | 77 | copy_char_pointer += start_position; |
| bala0x07 | 0:e36d80703ed0 | 78 | |
| bala0x07 | 0:e36d80703ed0 | 79 | for(count = 0; count < total_num; count++) |
| bala0x07 | 0:e36d80703ed0 | 80 | { |
| bala0x07 | 0:e36d80703ed0 | 81 | copied_data[count] = *copy_char_pointer++; |
| bala0x07 | 0:e36d80703ed0 | 82 | } |
| bala0x07 | 0:e36d80703ed0 | 83 | |
| bala0x07 | 0:e36d80703ed0 | 84 | pco.printf("\r\n%s", copied_data); |
| bala0x07 | 0:e36d80703ed0 | 85 | |
| bala0x07 | 0:e36d80703ed0 | 86 | copy_char_pointer = copied_data; // Shifting the pointer to copied_data array |
| bala0x07 | 0:e36d80703ed0 | 87 | |
| bala0x07 | 0:e36d80703ed0 | 88 | return copy_char_pointer; |
| bala0x07 | 0:e36d80703ed0 | 89 | } |
| bala0x07 | 0:e36d80703ed0 | 90 | */ |
| bala0x07 | 0:e36d80703ed0 | 91 | |
| bala0x07 | 0:e36d80703ed0 | 92 | |
| bala0x07 | 0:e36d80703ed0 | 93 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 94 | |
| bala0x07 | 0:e36d80703ed0 | 95 | void process_battery_voltage(char *battery_voltage_pointer) |
| bala0x07 | 0:e36d80703ed0 | 96 | { |
| bala0x07 | 0:e36d80703ed0 | 97 | char battery_voltage_data[4]; // One decimal point precision ( For ex : 12.5 ) |
| bala0x07 | 0:e36d80703ed0 | 98 | char count; |
| bala0x07 | 0:e36d80703ed0 | 99 | battery_voltage_pointer += 5; // ATRV<CR> counts to 5 |
| bala0x07 | 0:e36d80703ed0 | 100 | for(count = 0; count < 4; count++) |
| bala0x07 | 0:e36d80703ed0 | 101 | { |
| bala0x07 | 0:e36d80703ed0 | 102 | battery_voltage_data[count] = *battery_voltage_pointer++; |
| bala0x07 | 0:e36d80703ed0 | 103 | } |
| bala0x07 | 0:e36d80703ed0 | 104 | car_battery_voltage = atof(battery_voltage_data); // Converts the Battery Volatge from String to Float data type |
| bala0x07 | 0:e36d80703ed0 | 105 | |
| bala0x07 | 0:e36d80703ed0 | 106 | printf("\r\nCAR BATTERY VOLTAGE = %f",car_battery_voltage); |
| bala0x07 | 0:e36d80703ed0 | 107 | } |
| bala0x07 | 0:e36d80703ed0 | 108 | |
| bala0x07 | 0:e36d80703ed0 | 109 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 110 | |
| bala0x07 | 0:e36d80703ed0 | 111 | void process_vehicle_speed(char *vehicle_speed_pointer) |
| bala0x07 | 0:e36d80703ed0 | 112 | { |
| bala0x07 | 0:e36d80703ed0 | 113 | char vehicle_speed_data[2]; // Vehicle speed data is returned by a 2 byte value |
| bala0x07 | 0:e36d80703ed0 | 114 | char *strtol_pointer; |
| bala0x07 | 0:e36d80703ed0 | 115 | char count; |
| bala0x07 | 0:e36d80703ed0 | 116 | //"010D\r41 0D 4F\r\r>" |
| bala0x07 | 0:e36d80703ed0 | 117 | vehicle_speed_pointer += 11; |
| bala0x07 | 0:e36d80703ed0 | 118 | for(count = 0; count < 2; count++) |
| bala0x07 | 0:e36d80703ed0 | 119 | { |
| bala0x07 | 0:e36d80703ed0 | 120 | vehicle_speed_data[count] = *vehicle_speed_pointer++; |
| bala0x07 | 0:e36d80703ed0 | 121 | } |
| bala0x07 | 0:e36d80703ed0 | 122 | |
| bala0x07 | 0:e36d80703ed0 | 123 | vehicle_speed = strtol(vehicle_speed_data, &strtol_pointer, 16); |
| bala0x07 | 0:e36d80703ed0 | 124 | |
| bala0x07 | 1:c23c05b36e33 | 125 | printf("\r\nVEHICLE SPEED = %ld", vehicle_speed); |
| bala0x07 | 1:c23c05b36e33 | 126 | } |
| bala0x07 | 1:c23c05b36e33 | 127 | |
| bala0x07 | 1:c23c05b36e33 | 128 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 129 | |
| bala0x07 | 1:c23c05b36e33 | 130 | void process_mil_data(char *mil_data_pointer) |
| bala0x07 | 1:c23c05b36e33 | 131 | { |
| bala0x07 | 1:c23c05b36e33 | 132 | char mil_data[2], mil_data_converted; |
| bala0x07 | 1:c23c05b36e33 | 133 | char count; |
| bala0x07 | 1:c23c05b36e33 | 134 | |
| bala0x07 | 1:c23c05b36e33 | 135 | // char virtual_mil_buffer = "0101\r41 01 00 04 60 00 \r\r"; |
| bala0x07 | 1:c23c05b36e33 | 136 | mil_data_pointer += 11; |
| bala0x07 | 1:c23c05b36e33 | 137 | |
| bala0x07 | 1:c23c05b36e33 | 138 | for(count = 0; count < 2; count++) |
| bala0x07 | 1:c23c05b36e33 | 139 | { |
| bala0x07 | 1:c23c05b36e33 | 140 | mil_data[count] = *mil_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 141 | } |
| bala0x07 | 1:c23c05b36e33 | 142 | |
| bala0x07 | 1:c23c05b36e33 | 143 | mil_data_converted = (((mil_data[0] - 0x30)<<4) + (mil_data[1] - 0x30)); // Converting the ASCII data to the Hex data |
| bala0x07 | 1:c23c05b36e33 | 144 | |
| bala0x07 | 1:c23c05b36e33 | 145 | // The following code lines checks for the number of Mal function indicator lamp enabled by tghe CAN ECU |
| bala0x07 | 1:c23c05b36e33 | 146 | |
| bala0x07 | 1:c23c05b36e33 | 147 | 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 | 148 | { |
| bala0x07 | 1:c23c05b36e33 | 149 | pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS ON"); |
| bala0x07 | 1:c23c05b36e33 | 150 | no_of_stored_dtc = (mil_data_converted & 0b01111111); |
| bala0x07 | 1:c23c05b36e33 | 151 | pco.printf("\r\n NO OF STORED DYNAMIC TROUBLE CODE = %d", no_of_stored_dtc); |
| bala0x07 | 1:c23c05b36e33 | 152 | } |
| bala0x07 | 1:c23c05b36e33 | 153 | else |
| bala0x07 | 1:c23c05b36e33 | 154 | pco.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS OFF"); |
| bala0x07 | 0:e36d80703ed0 | 155 | } |
| bala0x07 | 0:e36d80703ed0 | 156 | |
| bala0x07 | 0:e36d80703ed0 | 157 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 158 | |
| bala0x07 | 1:c23c05b36e33 | 159 | void process_dtc_data(char *dtc_data_pointer) // Incomplete Code block |
| bala0x07 | 1:c23c05b36e33 | 160 | { |
| bala0x07 | 1:c23c05b36e33 | 161 | /* |
| bala0x07 | 1:c23c05b36e33 | 162 | char i; |
| bala0x07 | 1:c23c05b36e33 | 163 | for(i = 0; i<14; i++) |
| bala0x07 | 1:c23c05b36e33 | 164 | { |
| bala0x07 | 1:c23c05b36e33 | 165 | pco.printf("\r\nData = %c", *(dtc_data_pointer+i)); |
| bala0x07 | 1:c23c05b36e33 | 166 | } |
| bala0x07 | 1:c23c05b36e33 | 167 | */ |
| bala0x07 | 1:c23c05b36e33 | 168 | // char virtual_dtc_buffer[] = "03\r43 00 85\r\r>"; |
| bala0x07 | 1:c23c05b36e33 | 169 | char count1, count2, count_bytes = 0; |
| bala0x07 | 1:c23c05b36e33 | 170 | //char dtc_data_raw[5]; |
| bala0x07 | 1:c23c05b36e33 | 171 | char dtc_data[2]; // Since each DTC needs 2 bytes to make the code |
| bala0x07 | 1:c23c05b36e33 | 172 | //pco.printf("\r\n String Length = %d", strlen(dtc_data_pointer)); |
| bala0x07 | 1:c23c05b36e33 | 173 | dtc_data_pointer += 6; // Neglecting the preceding data to scroll to the actual data having some meaning |
| bala0x07 | 1:c23c05b36e33 | 174 | |
| bala0x07 | 1:c23c05b36e33 | 175 | //char dtc_codes[no_of_stored_dtc * 5]; // Since each DTC requires 5 characters to display |
| bala0x07 | 1:c23c05b36e33 | 176 | |
| bala0x07 | 1:c23c05b36e33 | 177 | char dtc_codes[5]; |
| bala0x07 | 1:c23c05b36e33 | 178 | |
| bala0x07 | 1:c23c05b36e33 | 179 | //pco.printf("\r\n String Length = %d", strlen(dtc_data_pointer)); |
| bala0x07 | 1:c23c05b36e33 | 180 | for(count1 = 0; count1 < (strlen(dtc_data_pointer)); count1++) |
| bala0x07 | 1:c23c05b36e33 | 181 | { |
| bala0x07 | 1:c23c05b36e33 | 182 | |
| bala0x07 | 1:c23c05b36e33 | 183 | if(*(dtc_data_pointer + count1) != '\r'){ |
| bala0x07 | 1:c23c05b36e33 | 184 | count_bytes++; |
| bala0x07 | 1:c23c05b36e33 | 185 | pco.printf("\r\nData = %c Count Bytes = %d", *(dtc_data_pointer+count1), count_bytes); } // To be commented |
| bala0x07 | 1:c23c05b36e33 | 186 | else |
| bala0x07 | 1:c23c05b36e33 | 187 | break; |
| bala0x07 | 1:c23c05b36e33 | 188 | } |
| bala0x07 | 1:c23c05b36e33 | 189 | pco.printf("\r\nDATA POINTER POINTING TO : %c", *dtc_data_pointer); |
| bala0x07 | 1:c23c05b36e33 | 190 | //pco.printf("\r\nCount Bytes = %d", count_bytes); // To be commented |
| bala0x07 | 1:c23c05b36e33 | 191 | /* |
| bala0x07 | 1:c23c05b36e33 | 192 | |
| bala0x07 | 1:c23c05b36e33 | 193 | FORMULA: |
| bala0x07 | 1:c23c05b36e33 | 194 | t = total bytes of returned data |
| bala0x07 | 1:c23c05b36e33 | 195 | n = no of dtc |
| bala0x07 | 1:c23c05b36e33 | 196 | |
| bala0x07 | 1:c23c05b36e33 | 197 | t = 2n + (n -1) , where (n-1) indicates the added spaces between two bytes |
| bala0x07 | 1:c23c05b36e33 | 198 | t = 3n -1 |
| bala0x07 | 1:c23c05b36e33 | 199 | |
| bala0x07 | 1:c23c05b36e33 | 200 | Therefore, n = (t + 1) / 3 |
| bala0x07 | 1:c23c05b36e33 | 201 | |
| bala0x07 | 1:c23c05b36e33 | 202 | */ |
| bala0x07 | 1:c23c05b36e33 | 203 | if(((count_bytes + 1)/3) == no_of_stored_dtc) |
| bala0x07 | 1:c23c05b36e33 | 204 | pco.printf("\r\nNO OF STORED DTC MATCHES WITH THE DTC CODE RETURNED"); |
| bala0x07 | 1:c23c05b36e33 | 205 | else |
| bala0x07 | 1:c23c05b36e33 | 206 | pco.printf("\r\nNO OF STORED DTC DOESNT MATCH WITH THE DTC DATA RETURNED"); |
| bala0x07 | 1:c23c05b36e33 | 207 | |
| bala0x07 | 1:c23c05b36e33 | 208 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 209 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 210 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 211 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 212 | pco.printf("\r\n %d", ((*dtc_data_pointer) - 0x30)); |
| bala0x07 | 1:c23c05b36e33 | 213 | |
| bala0x07 | 1:c23c05b36e33 | 214 | dtc_data_pointer -= 4; |
| bala0x07 | 1:c23c05b36e33 | 215 | |
| bala0x07 | 1:c23c05b36e33 | 216 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| bala0x07 | 1:c23c05b36e33 | 217 | // VERIFIED UPTO THIS LEVEL |
| bala0x07 | 1:c23c05b36e33 | 218 | |
| bala0x07 | 1:c23c05b36e33 | 219 | for(count1 = 0; count1 < no_of_stored_dtc; count1++) |
| bala0x07 | 1:c23c05b36e33 | 220 | { |
| bala0x07 | 1:c23c05b36e33 | 221 | for(count2 = 0; count2 < 2; count2++) |
| bala0x07 | 1:c23c05b36e33 | 222 | { |
| bala0x07 | 1:c23c05b36e33 | 223 | //dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data |
| bala0x07 | 1:c23c05b36e33 | 224 | dtc_data[count1] = *dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 225 | pco.printf("\r\nData = %c", dtc_data[count1]); |
| bala0x07 | 1:c23c05b36e33 | 226 | } |
| bala0x07 | 1:c23c05b36e33 | 227 | char a[2]; |
| bala0x07 | 1:c23c05b36e33 | 228 | a[0] = 'B'; |
| bala0x07 | 1:c23c05b36e33 | 229 | a[1] = 'G'; |
| bala0x07 | 1:c23c05b36e33 | 230 | pco.printf("\r\nData = %s", a); |
| bala0x07 | 1:c23c05b36e33 | 231 | //dtc_data_pointer += 2; |
| bala0x07 | 1:c23c05b36e33 | 232 | dtc_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 233 | |
| bala0x07 | 1:c23c05b36e33 | 234 | |
| 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 < 3; count2++) |
| bala0x07 | 1:c23c05b36e33 | 239 | { |
| bala0x07 | 1:c23c05b36e33 | 240 | if((*(dtc_data_pointer + count1)) != ' ') { |
| bala0x07 | 1:c23c05b36e33 | 241 | dtc_data[count1] = (*(dtc_data_pointer + count1)) - 0x30; // Converts to integer and stores in dtc_data |
| bala0x07 | 1:c23c05b36e33 | 242 | pco.printf("\r\nData = %c", *(dtc_data_pointer + count1)); } |
| bala0x07 | 1:c23c05b36e33 | 243 | else { |
| bala0x07 | 1:c23c05b36e33 | 244 | dtc_data_pointer += 3; |
| bala0x07 | 1:c23c05b36e33 | 245 | break; } |
| bala0x07 | 1:c23c05b36e33 | 246 | } |
| bala0x07 | 1:c23c05b36e33 | 247 | */ |
| bala0x07 | 1:c23c05b36e33 | 248 | |
| bala0x07 | 1:c23c05b36e33 | 249 | /* |
| bala0x07 | 1:c23c05b36e33 | 250 | for(count1 = 0; count1 < count_bytes; count1++) |
| bala0x07 | 1:c23c05b36e33 | 251 | pco.printf("\r\n DTC Bytes = %c+%d", *dtc_data_pointer, (*(dtc_data_pointer++) - 0x30)); |
| bala0x07 | 1:c23c05b36e33 | 252 | |
| bala0x07 | 1:c23c05b36e33 | 253 | // The following lines of code copy the data pointed by dtc_data_pointer to the dtc_data array |
| bala0x07 | 1:c23c05b36e33 | 254 | for(count1= 0; count1 < no_of_stored_dtc; count1++) |
| bala0x07 | 1:c23c05b36e33 | 255 | { |
| bala0x07 | 1:c23c05b36e33 | 256 | for(count2 = 0; count2 < 2; count2++) |
| bala0x07 | 1:c23c05b36e33 | 257 | { |
| bala0x07 | 1:c23c05b36e33 | 258 | dtc_data[count2] = *(dtc_data_pointer + count2); |
| bala0x07 | 1:c23c05b36e33 | 259 | } |
| bala0x07 | 1:c23c05b36e33 | 260 | pco.printf("\r\nDTC DATA >>>> %c", dtc_data[1]); |
| bala0x07 | 1:c23c05b36e33 | 261 | dtc_data_pointer += 1; // To skip the space present between two DTC data |
| bala0x07 | 1:c23c05b36e33 | 262 | */ |
| bala0x07 | 1:c23c05b36e33 | 263 | switch((dtc_data[0] & 0x11000000) >> 6) |
| bala0x07 | 1:c23c05b36e33 | 264 | { |
| bala0x07 | 1:c23c05b36e33 | 265 | case 0: |
| bala0x07 | 1:c23c05b36e33 | 266 | dtc_codes[count1*5] = 'P'; |
| bala0x07 | 1:c23c05b36e33 | 267 | break; |
| bala0x07 | 1:c23c05b36e33 | 268 | |
| bala0x07 | 1:c23c05b36e33 | 269 | case 1: |
| bala0x07 | 1:c23c05b36e33 | 270 | dtc_codes[count1*5] = 'C'; |
| bala0x07 | 1:c23c05b36e33 | 271 | break; |
| bala0x07 | 1:c23c05b36e33 | 272 | |
| bala0x07 | 1:c23c05b36e33 | 273 | case 2: |
| bala0x07 | 1:c23c05b36e33 | 274 | dtc_codes[count1*5] = 'B'; |
| bala0x07 | 1:c23c05b36e33 | 275 | break; |
| bala0x07 | 1:c23c05b36e33 | 276 | |
| bala0x07 | 1:c23c05b36e33 | 277 | case 3: |
| bala0x07 | 1:c23c05b36e33 | 278 | dtc_codes[count1*5] = 'U'; |
| bala0x07 | 1:c23c05b36e33 | 279 | break; |
| bala0x07 | 1:c23c05b36e33 | 280 | } |
| bala0x07 | 1:c23c05b36e33 | 281 | |
| bala0x07 | 1:c23c05b36e33 | 282 | // dtc_codes[(count1*5)+1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 283 | // dtc_codes[(count1*5)+2] = ((dtc_data[0] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 284 | // dtc_codes[(count1*5)+3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 285 | // dtc_codes[(count1*5)+4] = ((dtc_data[1] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 286 | dtc_codes[1] = (((dtc_data[0] & 0b00110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 287 | dtc_codes[2] = ((dtc_data[0] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 288 | dtc_codes[3] = (((dtc_data[1] & 0b11110000) >> 4) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 289 | dtc_codes[4] = ((dtc_data[1] & 0b00001111) + 0x30); |
| bala0x07 | 1:c23c05b36e33 | 290 | |
| bala0x07 | 1:c23c05b36e33 | 291 | pco.printf("\r\n DTC CODE NO %d : %s", count1+1, dtc_codes); |
| bala0x07 | 1:c23c05b36e33 | 292 | |
| bala0x07 | 1:c23c05b36e33 | 293 | } |
| bala0x07 | 1:c23c05b36e33 | 294 | } |
| bala0x07 | 1:c23c05b36e33 | 295 | |
| bala0x07 | 1:c23c05b36e33 | 296 | |
| bala0x07 | 1:c23c05b36e33 | 297 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 298 | |
| bala0x07 | 0:e36d80703ed0 | 299 | void fetch_battery_voltage() |
| bala0x07 | 0:e36d80703ed0 | 300 | { |
| bala0x07 | 0:e36d80703ed0 | 301 | OBD_UART.printf(battery_voltage_cmd); |
| bala0x07 | 0:e36d80703ed0 | 302 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 303 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 304 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 305 | received_data_verification(OBD_UART_RX_Buffer, battery_voltage_cmd, (strlen(battery_voltage_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 306 | |
| bala0x07 | 0:e36d80703ed0 | 307 | process_battery_voltage(OBD_UART_RX_Buffer); |
| bala0x07 | 0:e36d80703ed0 | 308 | |
| bala0x07 | 0:e36d80703ed0 | 309 | if(pass == 1) |
| bala0x07 | 0:e36d80703ed0 | 310 | printf("\r\nOBD READ BATTERY VOLTAGE SUCCESSFUL \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 311 | else |
| bala0x07 | 0:e36d80703ed0 | 312 | printf("\r\nOBD READ BATTERY VOLTAGE FAILED \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 313 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 314 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 0:e36d80703ed0 | 315 | } |
| bala0x07 | 0:e36d80703ed0 | 316 | |
| bala0x07 | 0:e36d80703ed0 | 317 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 318 | |
| bala0x07 | 0:e36d80703ed0 | 319 | void fetch_vehicle_speed() |
| bala0x07 | 0:e36d80703ed0 | 320 | { |
| bala0x07 | 1:c23c05b36e33 | 321 | char virtual_rx_speed_buffer[] = "010D\r41 0D 4F \r\r>"; |
| bala0x07 | 0:e36d80703ed0 | 322 | /* |
| bala0x07 | 0:e36d80703ed0 | 323 | OBD_UART.printf(vehicle_speed_cmd); |
| bala0x07 | 0:e36d80703ed0 | 324 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 325 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 326 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 327 | received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 328 | */ |
| bala0x07 | 0:e36d80703ed0 | 329 | process_vehicle_speed(virtual_rx_speed_buffer); |
| bala0x07 | 0:e36d80703ed0 | 330 | |
| bala0x07 | 0:e36d80703ed0 | 331 | if(pass == 1) |
| bala0x07 | 1:c23c05b36e33 | 332 | printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 333 | else |
| bala0x07 | 0:e36d80703ed0 | 334 | printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 335 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 336 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 0:e36d80703ed0 | 337 | |
| bala0x07 | 0:e36d80703ed0 | 338 | } |
| bala0x07 | 0:e36d80703ed0 | 339 | |
| bala0x07 | 0:e36d80703ed0 | 340 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 341 | |
| bala0x07 | 0:e36d80703ed0 | 342 | void fetch_vin_number() |
| bala0x07 | 0:e36d80703ed0 | 343 | { |
| bala0x07 | 0:e36d80703ed0 | 344 | 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 | 1:c23c05b36e33 | 345 | char vin_buffer[100], count; |
| bala0x07 | 1:c23c05b36e33 | 346 | char *vin_data_pointer; |
| bala0x07 | 1:c23c05b36e33 | 347 | char internal_counter = 0; |
| bala0x07 | 1:c23c05b36e33 | 348 | char small_buffer[2]; |
| bala0x07 | 1:c23c05b36e33 | 349 | long ascii_converted_data; |
| bala0x07 | 1:c23c05b36e33 | 350 | char *vin_conv_pointer; |
| bala0x07 | 1:c23c05b36e33 | 351 | char vin_number[17]; |
| bala0x07 | 1:c23c05b36e33 | 352 | |
| bala0x07 | 1:c23c05b36e33 | 353 | vin_data_pointer = virtual_rx_vin_buffer; |
| bala0x07 | 1:c23c05b36e33 | 354 | vin_data_pointer += 23; |
| bala0x07 | 1:c23c05b36e33 | 355 | |
| bala0x07 | 1:c23c05b36e33 | 356 | int length; |
| bala0x07 | 1:c23c05b36e33 | 357 | for(count = 0; count < (strlen(virtual_rx_vin_buffer) - 1); count++) |
| bala0x07 | 1:c23c05b36e33 | 358 | { |
| bala0x07 | 1:c23c05b36e33 | 359 | if((*vin_data_pointer == '\r') | (*vin_data_pointer == ' ') | (*vin_data_pointer == '>')) |
| bala0x07 | 1:c23c05b36e33 | 360 | { |
| bala0x07 | 1:c23c05b36e33 | 361 | printf("\r\ncount1 = %c", *vin_data_pointer); |
| bala0x07 | 1:c23c05b36e33 | 362 | vin_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 363 | continue; |
| bala0x07 | 1:c23c05b36e33 | 364 | } |
| bala0x07 | 1:c23c05b36e33 | 365 | else if(*(vin_data_pointer + 1) == ':') |
| bala0x07 | 1:c23c05b36e33 | 366 | { |
| bala0x07 | 1:c23c05b36e33 | 367 | vin_data_pointer += 2; |
| bala0x07 | 1:c23c05b36e33 | 368 | continue; |
| bala0x07 | 1:c23c05b36e33 | 369 | } |
| bala0x07 | 1:c23c05b36e33 | 370 | else |
| bala0x07 | 1:c23c05b36e33 | 371 | { |
| bala0x07 | 1:c23c05b36e33 | 372 | printf("\r\ncount2 = %d", count); |
| bala0x07 | 1:c23c05b36e33 | 373 | vin_buffer[internal_counter] = *vin_data_pointer; |
| bala0x07 | 1:c23c05b36e33 | 374 | internal_counter++; |
| bala0x07 | 1:c23c05b36e33 | 375 | } |
| bala0x07 | 1:c23c05b36e33 | 376 | vin_data_pointer++; |
| bala0x07 | 1:c23c05b36e33 | 377 | } |
| bala0x07 | 1:c23c05b36e33 | 378 | |
| bala0x07 | 1:c23c05b36e33 | 379 | length = strlen(vin_buffer); |
| bala0x07 | 1:c23c05b36e33 | 380 | printf("\r\n VIN BUFFER LENGTH = %d", length); |
| bala0x07 | 1:c23c05b36e33 | 381 | |
| bala0x07 | 1:c23c05b36e33 | 382 | printf("\r\n VIN NUMBER : %s", vin_buffer); |
| bala0x07 | 1:c23c05b36e33 | 383 | |
| bala0x07 | 1:c23c05b36e33 | 384 | internal_counter = 0; |
| bala0x07 | 1:c23c05b36e33 | 385 | |
| bala0x07 | 1:c23c05b36e33 | 386 | for(count = 0; count < strlen(vin_buffer); count+=2) |
| bala0x07 | 1:c23c05b36e33 | 387 | { |
| bala0x07 | 1:c23c05b36e33 | 388 | small_buffer[0] = vin_buffer[count]; |
| bala0x07 | 1:c23c05b36e33 | 389 | small_buffer[1] = vin_buffer[count+1]; |
| bala0x07 | 1:c23c05b36e33 | 390 | ascii_converted_data = strtol(small_buffer, &vin_conv_pointer, 16); |
| bala0x07 | 1:c23c05b36e33 | 391 | vin_number[internal_counter] = ascii_converted_data; |
| bala0x07 | 1:c23c05b36e33 | 392 | internal_counter++; |
| bala0x07 | 1:c23c05b36e33 | 393 | } |
| bala0x07 | 1:c23c05b36e33 | 394 | printf("\r\n\r\nVEHICLE CHASSIS NUMBER : %s", vin_number); |
| bala0x07 | 0:e36d80703ed0 | 395 | |
| bala0x07 | 0:e36d80703ed0 | 396 | /* |
| bala0x07 | 0:e36d80703ed0 | 397 | Chassis Number : TMBFKJ5J2CG014733 |
| bala0x07 | 0:e36d80703ed0 | 398 | |
| bala0x07 | 0:e36d80703ed0 | 399 | [TX] - 0902 5<CR> |
| bala0x07 | 0:e36d80703ed0 | 400 | |
| bala0x07 | 0:e36d80703ed0 | 401 | [RX] - 0902 5<CR> |
| bala0x07 | 0:e36d80703ed0 | 402 | 014 <CR> |
| bala0x07 | 0:e36d80703ed0 | 403 | 0: 49 02 01 54 4D 42 <CR> |
| bala0x07 | 0:e36d80703ed0 | 404 | 1: 46 4B 4A 35 4A 32 43 <CR> |
| bala0x07 | 0:e36d80703ed0 | 405 | 2: 47 30 31 34 37 33 33 <CR> |
| bala0x07 | 0:e36d80703ed0 | 406 | <CR> |
| bala0x07 | 0:e36d80703ed0 | 407 | > |
| bala0x07 | 0:e36d80703ed0 | 408 | */ |
| bala0x07 | 0:e36d80703ed0 | 409 | /* |
| bala0x07 | 0:e36d80703ed0 | 410 | OBD_UART.printf(vin_number_cmd); |
| bala0x07 | 0:e36d80703ed0 | 411 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 412 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 413 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 414 | received_data_verification(OBD_UART_RX_Buffer, vin_number_cmd, (strlen(vin_number_cmd)-1)); |
| bala0x07 | 1:c23c05b36e33 | 415 | */ |
| bala0x07 | 1:c23c05b36e33 | 416 | } |
| bala0x07 | 1:c23c05b36e33 | 417 | |
| bala0x07 | 1:c23c05b36e33 | 418 | |
| bala0x07 | 1:c23c05b36e33 | 419 | |
| bala0x07 | 1:c23c05b36e33 | 420 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 421 | |
| bala0x07 | 1:c23c05b36e33 | 422 | void check_for_MIL() |
| bala0x07 | 1:c23c05b36e33 | 423 | { |
| bala0x07 | 1:c23c05b36e33 | 424 | char virtual_mil_buffer[] = "0101\r41 01 82 04 60 00 \r\r"; |
| bala0x07 | 1:c23c05b36e33 | 425 | /* |
| bala0x07 | 1:c23c05b36e33 | 426 | OBD_UART.printf(check_mil_cmd); |
| bala0x07 | 1:c23c05b36e33 | 427 | wait(1); |
| bala0x07 | 1:c23c05b36e33 | 428 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 1:c23c05b36e33 | 429 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 430 | received_data_verification(OBD_UART_RX_Buffer, check_mil_cmd, (strlen(check_mil_cmd)-1)); |
| bala0x07 | 1:c23c05b36e33 | 431 | */ |
| bala0x07 | 1:c23c05b36e33 | 432 | |
| bala0x07 | 1:c23c05b36e33 | 433 | //process_dtc_data(OBD_UART_RX_Buffer); |
| bala0x07 | 1:c23c05b36e33 | 434 | process_mil_data(virtual_mil_buffer); |
| bala0x07 | 1:c23c05b36e33 | 435 | |
| bala0x07 | 1:c23c05b36e33 | 436 | if(pass == 1) |
| bala0x07 | 1:c23c05b36e33 | 437 | printf("\r\VEHICLE MIL DATA RECEIVED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 438 | else |
| bala0x07 | 1:c23c05b36e33 | 439 | printf("\r\nVEHICLE MIL DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 440 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 1:c23c05b36e33 | 441 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 1:c23c05b36e33 | 442 | } |
| bala0x07 | 1:c23c05b36e33 | 443 | |
| bala0x07 | 0:e36d80703ed0 | 444 | |
| bala0x07 | 0:e36d80703ed0 | 445 | //************************************************************************************************************************ |
| bala0x07 | 1:c23c05b36e33 | 446 | |
| bala0x07 | 0:e36d80703ed0 | 447 | /* |
| bala0x07 | 1:c23c05b36e33 | 448 | _______________________________________________________________________________________________________________________ |
| bala0x07 | 1:c23c05b36e33 | 449 | |
| bala0x07 | 1:c23c05b36e33 | 450 | NOTE : |
| bala0x07 | 1:c23c05b36e33 | 451 | ----- |
| bala0x07 | 1:c23c05b36e33 | 452 | THE FOLLOWING CODE O DETERMINE THE DIAGNOSTIC TROUBLE CODE (DTC) IS BASED ON THE INTERPRETATION GIVEN IN WIKIPEDIA |
| bala0x07 | 1:c23c05b36e33 | 453 | FOR THE ISO 15765-2 PROTOCOL |
| bala0x07 | 1:c23c05b36e33 | 454 | DIFFERENT INTERPRETATION METHODOLOGY IS GIVEN IN THE ELM327 DATASHEET FOR SAE PROTOCOL |
| bala0x07 | 1:c23c05b36e33 | 455 | SO THESE THINGS ARE SUBJECTED TO MODIFICATION AND HAVE NOT BEEN CONFIRMED WITH THE REAL TIME DATA |
| bala0x07 | 1:c23c05b36e33 | 456 | _______________________________________________________________________________________________________________________ |
| bala0x07 | 1:c23c05b36e33 | 457 | |
| bala0x07 | 1:c23c05b36e33 | 458 | */ |
| bala0x07 | 1:c23c05b36e33 | 459 | |
| bala0x07 | 0:e36d80703ed0 | 460 | void check_for_dtc() |
| bala0x07 | 0:e36d80703ed0 | 461 | { |
| bala0x07 | 1:c23c05b36e33 | 462 | char virtual_dtc_buffer[] = "03\r43 00 85\r\r>"; |
| bala0x07 | 1:c23c05b36e33 | 463 | //char virtual_dtc_buffer[] = "0123456789a\rbc>"; |
| bala0x07 | 1:c23c05b36e33 | 464 | /* |
| bala0x07 | 1:c23c05b36e33 | 465 | OBD_UART.printf(check_dtc_cmd); |
| bala0x07 | 1:c23c05b36e33 | 466 | wait(1); |
| bala0x07 | 1:c23c05b36e33 | 467 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 1:c23c05b36e33 | 468 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 469 | received_data_verification(OBD_UART_RX_Buffer, check_dtc_cmd, (strlen(check_dtc_cmd)-1)); |
| bala0x07 | 1:c23c05b36e33 | 470 | */ |
| bala0x07 | 1:c23c05b36e33 | 471 | |
| bala0x07 | 1:c23c05b36e33 | 472 | //process_dtc_data(OBD_UART_RX_Buffer); |
| bala0x07 | 1:c23c05b36e33 | 473 | process_dtc_data(virtual_dtc_buffer); |
| bala0x07 | 1:c23c05b36e33 | 474 | |
| bala0x07 | 1:c23c05b36e33 | 475 | if(pass == 1) |
| bala0x07 | 1:c23c05b36e33 | 476 | printf("\r\VEHICLE DIAGNOSTIC TROUBLE CODE RECEIVED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 477 | else |
| bala0x07 | 1:c23c05b36e33 | 478 | printf("\r\nVEHICLE DIAGNOSTIC TROUBLE CODE DATA RECEPTION FAILED\r\n\r\n"); |
| bala0x07 | 1:c23c05b36e33 | 479 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 1:c23c05b36e33 | 480 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 1:c23c05b36e33 | 481 | } |
| bala0x07 | 1:c23c05b36e33 | 482 | |
| bala0x07 | 0:e36d80703ed0 | 483 | |
| bala0x07 | 0:e36d80703ed0 | 484 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 485 | |
| bala0x07 | 0:e36d80703ed0 | 486 | void initialize_obd() |
| bala0x07 | 0:e36d80703ed0 | 487 | { |
| bala0x07 | 0:e36d80703ed0 | 488 | char data[3]; |
| bala0x07 | 0:e36d80703ed0 | 489 | char *data_pointer; |
| bala0x07 | 0:e36d80703ed0 | 490 | |
| bala0x07 | 0:e36d80703ed0 | 491 | data_pointer = data; |
| bala0x07 | 0:e36d80703ed0 | 492 | |
| bala0x07 | 0:e36d80703ed0 | 493 | pco.baud(38400); |
| bala0x07 | 0:e36d80703ed0 | 494 | OBD_UART.baud(38400); |
| bala0x07 | 0:e36d80703ed0 | 495 | |
| bala0x07 | 0:e36d80703ed0 | 496 | OBD_UART.attach(&OBD_onDataRx); |
| bala0x07 | 0:e36d80703ed0 | 497 | |
| bala0x07 | 0:e36d80703ed0 | 498 | OBD_UART.printf("%s",obd_reset_cmd); |
| bala0x07 | 0:e36d80703ed0 | 499 | |
| bala0x07 | 0:e36d80703ed0 | 500 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 501 | |
| bala0x07 | 0:e36d80703ed0 | 502 | /* |
| bala0x07 | 0:e36d80703ed0 | 503 | pco.printf("Reception not completed"); |
| bala0x07 | 0:e36d80703ed0 | 504 | pco.printf("\r\n%d",OBD_RxBuffer_End_Pos); |
| bala0x07 | 0:e36d80703ed0 | 505 | pco.printf("\r\n%c",OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1]); |
| bala0x07 | 0:e36d80703ed0 | 506 | */ |
| bala0x07 | 0:e36d80703ed0 | 507 | |
| bala0x07 | 0:e36d80703ed0 | 508 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 509 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 510 | received_data_verification(OBD_UART_RX_Buffer, obd_reset_cmd, (strlen(obd_reset_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 511 | |
| bala0x07 | 0:e36d80703ed0 | 512 | if(pass == 1) |
| bala0x07 | 0:e36d80703ed0 | 513 | printf("\r\nOBD RESET SUCCESSFUL \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 514 | else |
| bala0x07 | 0:e36d80703ed0 | 515 | printf("\r\nOBD RESET FAILED \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 516 | |
| bala0x07 | 0:e36d80703ed0 | 517 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 518 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 0:e36d80703ed0 | 519 | |
| bala0x07 | 0:e36d80703ed0 | 520 | //-------------------------------------------------------------------------------------------------------------------------- |
| bala0x07 | 0:e36d80703ed0 | 521 | |
| bala0x07 | 0:e36d80703ed0 | 522 | OBD_UART.printf(allow_long_cmd); |
| bala0x07 | 0:e36d80703ed0 | 523 | wait(1); |
| bala0x07 | 0:e36d80703ed0 | 524 | while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled |
| bala0x07 | 0:e36d80703ed0 | 525 | pco.printf("Reception Complete\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 526 | received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(allow_long_cmd)-1)); |
| bala0x07 | 0:e36d80703ed0 | 527 | |
| bala0x07 | 0:e36d80703ed0 | 528 | if(pass == 1) |
| bala0x07 | 0:e36d80703ed0 | 529 | printf("\r\nLONG DATA RECEPTION ENABLED SUCCESSFULLY \r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 530 | else |
| bala0x07 | 0:e36d80703ed0 | 531 | printf("\r\nLONG DATA RECEPTION ENABLING FAILED\r\n\r\n"); |
| bala0x07 | 0:e36d80703ed0 | 532 | reception_complete = 0; // Disabling the reception complete flag |
| bala0x07 | 0:e36d80703ed0 | 533 | OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception |
| bala0x07 | 0:e36d80703ed0 | 534 | |
| bala0x07 | 0:e36d80703ed0 | 535 | } |
| bala0x07 | 0:e36d80703ed0 | 536 | |
| bala0x07 | 0:e36d80703ed0 | 537 | //************************************************************************************************************************ |
| bala0x07 | 0:e36d80703ed0 | 538 | |
| bala0x07 | 0:e36d80703ed0 | 539 | |
| bala0x07 | 0:e36d80703ed0 | 540 | |
| bala0x07 | 0:e36d80703ed0 | 541 |