Qmax / Mbed 2 deprecated LIS_Accelerometer_WIP

Dependencies:   mbed

Committer:
subinmbed
Date:
Sat Sep 02 11:09:35 2017 +0000
Revision:
2:c4fb968de7d3
Accelerometer commented

Who changed what in which revision?

UserRevisionLine numberNew contents of line
subinmbed 2:c4fb968de7d3 1
subinmbed 2:c4fb968de7d3 2
subinmbed 2:c4fb968de7d3 3
subinmbed 2:c4fb968de7d3 4 /*
subinmbed 2:c4fb968de7d3 5 ______________________________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 6
subinmbed 2:c4fb968de7d3 7 // <<<<<<<<< OBD LIBRARIES >>>>>>>>>
subinmbed 2:c4fb968de7d3 8
subinmbed 2:c4fb968de7d3 9 CHIP : STN1110 / ELM327
subinmbed 2:c4fb968de7d3 10 -----
subinmbed 2:c4fb968de7d3 11
subinmbed 2:c4fb968de7d3 12 NOTE :
subinmbed 2:c4fb968de7d3 13 -----
subinmbed 2:c4fb968de7d3 14 THESE CODE BLOCKS ARE TESTED IN REAL TIME BY COMMUNICATING DIRECTLY WITH CAR OBD PORT
subinmbed 2:c4fb968de7d3 15 THERE ARE SOME UNTESTED PORTIONS IN THE CAR
subinmbed 2:c4fb968de7d3 16 >>> VIN NUMBER
subinmbed 2:c4fb968de7d3 17 >>> DTC
subinmbed 2:c4fb968de7d3 18 VIN NUMBER PID NOT SUPPORTED IN THE CAR TESTED
subinmbed 2:c4fb968de7d3 19 THE CAR DOESN'T HAVE ANY DTC AND THIS IS ALSO LEFT UNTESTED
subinmbed 2:c4fb968de7d3 20
subinmbed 2:c4fb968de7d3 21 >>> THIS PARTICULAR SOURCE CODE IS COMPILED AND FOUND WITH ZERO ERRORS
subinmbed 2:c4fb968de7d3 22 >>> DATE : 29-MAR-2017
subinmbed 2:c4fb968de7d3 23 >>> TIME : 1.00 PM
subinmbed 2:c4fb968de7d3 24
subinmbed 2:c4fb968de7d3 25 >>> THIS PARTICULAR SOURCE CODE HAS BEEN TESTED SUCCESSFULLY
subinmbed 2:c4fb968de7d3 26 >>> DATE : 10-APR-2017
subinmbed 2:c4fb968de7d3 27 >>> TIME : 7:00 PM
subinmbed 2:c4fb968de7d3 28
subinmbed 2:c4fb968de7d3 29 ___________________
subinmbed 2:c4fb968de7d3 30
subinmbed 2:c4fb968de7d3 31 Author : >> BALA <<
subinmbed 2:c4fb968de7d3 32 ___________________
subinmbed 2:c4fb968de7d3 33
subinmbed 2:c4fb968de7d3 34 ______________________________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 35
subinmbed 2:c4fb968de7d3 36 */
subinmbed 2:c4fb968de7d3 37
subinmbed 2:c4fb968de7d3 38 #include "mbed.h"
subinmbed 2:c4fb968de7d3 39 #include "OBD.h"
subinmbed 2:c4fb968de7d3 40 #include "ACCELEROMETER.h"
subinmbed 2:c4fb968de7d3 41 //#include "main.h"
subinmbed 2:c4fb968de7d3 42 //#include "Common_Defs.h"
subinmbed 2:c4fb968de7d3 43 //#include "Lora.h"
subinmbed 2:c4fb968de7d3 44
subinmbed 2:c4fb968de7d3 45
subinmbed 2:c4fb968de7d3 46 RawSerial OBD_UART(PA_0, PA_1);
subinmbed 2:c4fb968de7d3 47 Serial DEBUG_UART(USBTX, USBRX);
subinmbed 2:c4fb968de7d3 48
subinmbed 2:c4fb968de7d3 49 char pass = 0;
subinmbed 2:c4fb968de7d3 50 char reception_complete = 0;
subinmbed 2:c4fb968de7d3 51 AnalogIn ain(PA_7);
subinmbed 2:c4fb968de7d3 52
subinmbed 2:c4fb968de7d3 53 /*
subinmbed 2:c4fb968de7d3 54 __________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 55
subinmbed 2:c4fb968de7d3 56 THE FOLLWOING ARE THE OBD COMMAND SET FOR THE STN1110 / ELM327 OBD - UART INTERPRETER
subinmbed 2:c4fb968de7d3 57 __________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 58
subinmbed 2:c4fb968de7d3 59 */
subinmbed 2:c4fb968de7d3 60
subinmbed 2:c4fb968de7d3 61
subinmbed 2:c4fb968de7d3 62 char obd_reset_cmd[] = {"ATZ\r"};
subinmbed 2:c4fb968de7d3 63 char battery_voltage_cmd[] = "ATRV\r";
subinmbed 2:c4fb968de7d3 64 char protocol_auto_detect_cmd[] = "ATSP0\r";
subinmbed 2:c4fb968de7d3 65 char read_CAN_protocol_cmd[] = "ATDPN\r";
subinmbed 2:c4fb968de7d3 66 char allow_long_cmd[] = "ATAL\r";
subinmbed 2:c4fb968de7d3 67 char engine_rpm_cmd[] = "010C\r";
subinmbed 2:c4fb968de7d3 68 char vehicle_speed_cmd[] = "010D\r";
subinmbed 2:c4fb968de7d3 69 char vin_number_cmd[] = "0902 5\r";
subinmbed 2:c4fb968de7d3 70 char check_dtc_cmd[] = "03\r";
subinmbed 2:c4fb968de7d3 71 char check_mil_cmd[] = "0101\r";
subinmbed 2:c4fb968de7d3 72
subinmbed 2:c4fb968de7d3 73
subinmbed 2:c4fb968de7d3 74 /*
subinmbed 2:c4fb968de7d3 75 __________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 76
subinmbed 2:c4fb968de7d3 77 THE FOLLOWING ARE GLOBAL VARIABLES WHICH CAN BE ACCESSED FOR FURTHER DATA PROCESSING
subinmbed 2:c4fb968de7d3 78 __________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 79
subinmbed 2:c4fb968de7d3 80 */
subinmbed 2:c4fb968de7d3 81
subinmbed 2:c4fb968de7d3 82 float car_battery_voltage;
subinmbed 2:c4fb968de7d3 83 long rpm;
subinmbed 2:c4fb968de7d3 84 float speed1,speed2;
subinmbed 2:c4fb968de7d3 85 long vehicle_speed;
subinmbed 2:c4fb968de7d3 86 char vin_number[17];
subinmbed 2:c4fb968de7d3 87 char mil;
subinmbed 2:c4fb968de7d3 88 char no_of_stored_dtc;
subinmbed 2:c4fb968de7d3 89
subinmbed 2:c4fb968de7d3 90 //_________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 91
subinmbed 2:c4fb968de7d3 92 // THE FOLLWOING VARIABLES ARE GLOBAL BUT ARE USED ONLY FOR IN-LIBRARY PROCESSING
subinmbed 2:c4fb968de7d3 93
subinmbed 2:c4fb968de7d3 94 char OBD_UART_RX_Buffer[100];
subinmbed 2:c4fb968de7d3 95 char OBD_RxBuffer_End_Pos;
subinmbed 2:c4fb968de7d3 96 char OBD_UART_RX_Size = 50;
subinmbed 2:c4fb968de7d3 97
subinmbed 2:c4fb968de7d3 98 //_________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 99
subinmbed 2:c4fb968de7d3 100
subinmbed 2:c4fb968de7d3 101
subinmbed 2:c4fb968de7d3 102 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 103
subinmbed 2:c4fb968de7d3 104 // FUNCTION CALLED BY PARENT FUNCTION
subinmbed 2:c4fb968de7d3 105 // THE FOLLOWING CODE BLOCK IS USED TO VERIFY THE RECEIVED DATA
subinmbed 2:c4fb968de7d3 106
subinmbed 2:c4fb968de7d3 107 void received_data_verification(char *rcv_data_pointer, char *ref_data_pointer, char num)
subinmbed 2:c4fb968de7d3 108 {
subinmbed 2:c4fb968de7d3 109 char dummy_data[num], count;
subinmbed 2:c4fb968de7d3 110 for(count = 0; count < num; count++)
subinmbed 2:c4fb968de7d3 111 {
subinmbed 2:c4fb968de7d3 112 //OBD_UART.putc(*rcv_data_pointer);
subinmbed 2:c4fb968de7d3 113 if(*rcv_data_pointer++ == *ref_data_pointer++)
subinmbed 2:c4fb968de7d3 114 pass = 1;
subinmbed 2:c4fb968de7d3 115 else
subinmbed 2:c4fb968de7d3 116 {
subinmbed 2:c4fb968de7d3 117 pass = 0;
subinmbed 2:c4fb968de7d3 118 return;
subinmbed 2:c4fb968de7d3 119 }
subinmbed 2:c4fb968de7d3 120 }
subinmbed 2:c4fb968de7d3 121 }
subinmbed 2:c4fb968de7d3 122
subinmbed 2:c4fb968de7d3 123 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 124
subinmbed 2:c4fb968de7d3 125 void rpm_padding_for_comm_test()
subinmbed 2:c4fb968de7d3 126 {
subinmbed 2:c4fb968de7d3 127
subinmbed 2:c4fb968de7d3 128 char count;
subinmbed 2:c4fb968de7d3 129 char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>";
subinmbed 2:c4fb968de7d3 130 char engine_rpm[4]; // Vehicle speed data is returned by a 4 byte value
subinmbed 2:c4fb968de7d3 131 char *rpm_data_pointer;
subinmbed 2:c4fb968de7d3 132 char internal_count = 0;
subinmbed 2:c4fb968de7d3 133 char padded_rpm_17_bytes[17];
subinmbed 2:c4fb968de7d3 134 OBD_UART.printf("RPM Data\r\n");
subinmbed 2:c4fb968de7d3 135
subinmbed 2:c4fb968de7d3 136 for(count = 0; count < strlen(engine_rpm_cmd); count ++)
subinmbed 2:c4fb968de7d3 137 OBD_UART.putc(engine_rpm_cmd[count]);
subinmbed 2:c4fb968de7d3 138 wait(1);
subinmbed 2:c4fb968de7d3 139 while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 140
subinmbed 2:c4fb968de7d3 141 received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1));
subinmbed 2:c4fb968de7d3 142 for(count = 0; count < 5; count++)
subinmbed 2:c4fb968de7d3 143 OBD_UART.printf("0x%2x ",OBD_UART_RX_Buffer[count]);
subinmbed 2:c4fb968de7d3 144 process_engine_rpm(OBD_UART_RX_Buffer);
subinmbed 2:c4fb968de7d3 145 DEBUG_UART.printf("RPM Received\r\n");
subinmbed 2:c4fb968de7d3 146 rpm_data_pointer = virtual_engine_rpm;
subinmbed 2:c4fb968de7d3 147 rpm_data_pointer += 11;
subinmbed 2:c4fb968de7d3 148
subinmbed 2:c4fb968de7d3 149 for(count = 0; count < 5; count++)
subinmbed 2:c4fb968de7d3 150 {
subinmbed 2:c4fb968de7d3 151 if(*rpm_data_pointer == ' ') { // Negate the spaces added in between
subinmbed 2:c4fb968de7d3 152 rpm_data_pointer++;
subinmbed 2:c4fb968de7d3 153 continue; }
subinmbed 2:c4fb968de7d3 154 else {
subinmbed 2:c4fb968de7d3 155 engine_rpm[internal_count] = *rpm_data_pointer++;
subinmbed 2:c4fb968de7d3 156 internal_count++; }
subinmbed 2:c4fb968de7d3 157 }
subinmbed 2:c4fb968de7d3 158
subinmbed 2:c4fb968de7d3 159 //OBD_UART.printf("\r\n%s", engine_rpm);
subinmbed 2:c4fb968de7d3 160 //OBD_UART.printf("\r\nRPMMMMMM = ");
subinmbed 2:c4fb968de7d3 161 for(count = 0; count < strlen(engine_rpm); count++)
subinmbed 2:c4fb968de7d3 162 OBD_UART.putc(engine_rpm[count]);
subinmbed 2:c4fb968de7d3 163
subinmbed 2:c4fb968de7d3 164 for(count = 0; count < 4; count++){
subinmbed 2:c4fb968de7d3 165 DEBUG_UART.printf("\r\nPadded = ");
subinmbed 2:c4fb968de7d3 166 for(internal_count = 0; internal_count < strlen(padded_rpm_17_bytes); internal_count++)
subinmbed 2:c4fb968de7d3 167 OBD_UART.putc(padded_rpm_17_bytes[internal_count]);
subinmbed 2:c4fb968de7d3 168 //OBD_UART.printf("\r\nPadded RPM = %s", padded_rpm_17_bytes);
subinmbed 2:c4fb968de7d3 169 strcat(padded_rpm_17_bytes, engine_rpm);
subinmbed 2:c4fb968de7d3 170 }
subinmbed 2:c4fb968de7d3 171
subinmbed 2:c4fb968de7d3 172 strcat(padded_rpm_17_bytes, "0");
subinmbed 2:c4fb968de7d3 173 DEBUG_UART.printf("\r\n\r\n PADDED RPM = %s",padded_rpm_17_bytes);
subinmbed 2:c4fb968de7d3 174 DEBUG_UART.putc('\r');
subinmbed 2:c4fb968de7d3 175 for(count = 0; count < strlen(padded_rpm_17_bytes); count++){
subinmbed 2:c4fb968de7d3 176 DEBUG_UART.putc(padded_rpm_17_bytes[count]);
subinmbed 2:c4fb968de7d3 177 //Misc_Packet_Data.VIN[count] = padded_rpm_17_bytes[count];
subinmbed 2:c4fb968de7d3 178 }
subinmbed 2:c4fb968de7d3 179 }
subinmbed 2:c4fb968de7d3 180 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 181 // FUNCTION CALLED FROM PARENT FUNCTION
subinmbed 2:c4fb968de7d3 182 // THE FOLLOWING CODE BLOCK IS USED TO PROCESS THE DTC DATA FETCHED FROM THE OBD PORT OF THE CAR
subinmbed 2:c4fb968de7d3 183
subinmbed 2:c4fb968de7d3 184
subinmbed 2:c4fb968de7d3 185 /*
subinmbed 2:c4fb968de7d3 186 |______________________________________________________________________________________________|
subinmbed 2:c4fb968de7d3 187
subinmbed 2:c4fb968de7d3 188 FORMULA:
subinmbed 2:c4fb968de7d3 189 -------
subinmbed 2:c4fb968de7d3 190 t = total bytes of returned data
subinmbed 2:c4fb968de7d3 191 n = no of dtc
subinmbed 2:c4fb968de7d3 192
subinmbed 2:c4fb968de7d3 193 t = 2n + (n -1) , where (n-1) indicates the added spaces between two bytes
subinmbed 2:c4fb968de7d3 194 t = 3n -1
subinmbed 2:c4fb968de7d3 195
subinmbed 2:c4fb968de7d3 196 Therefore, n = (t + 1) / 3
subinmbed 2:c4fb968de7d3 197
subinmbed 2:c4fb968de7d3 198 |______________________________________________________________________________________________|
subinmbed 2:c4fb968de7d3 199
subinmbed 2:c4fb968de7d3 200 */
subinmbed 2:c4fb968de7d3 201
subinmbed 2:c4fb968de7d3 202 void process_dtc_data(char *dtc_data_pointer) // Incomplete Code block
subinmbed 2:c4fb968de7d3 203 {
subinmbed 2:c4fb968de7d3 204 // char virtual_dtc_buffer[] = "03\r43 00 85\r\r>";
subinmbed 2:c4fb968de7d3 205 char count;
subinmbed 2:c4fb968de7d3 206 char internal_count;
subinmbed 2:c4fb968de7d3 207 char dtc_data[(4*(no_of_stored_dtc))];
subinmbed 2:c4fb968de7d3 208 char dtc_codes[(6*(no_of_stored_dtc))]; // Refer below
subinmbed 2:c4fb968de7d3 209
subinmbed 2:c4fb968de7d3 210 /*
subinmbed 2:c4fb968de7d3 211 _____________________________________________
subinmbed 2:c4fb968de7d3 212
subinmbed 2:c4fb968de7d3 213 NOTE :
subinmbed 2:c4fb968de7d3 214 -----
subinmbed 2:c4fb968de7d3 215 DTC CODE ARRAY SPACE ALLOCATION
subinmbed 2:c4fb968de7d3 216
subinmbed 2:c4fb968de7d3 217 ONE DTC CONTAINS 5 CHARACTERS
subinmbed 2:c4fb968de7d3 218 '\r' IS USED AS SEPARATOR (END BYTE)
subinmbed 2:c4fb968de7d3 219 TOTALLY TO STORE ONE DTC 6 BYTES ARE USED
subinmbed 2:c4fb968de7d3 220 _____________________________________________
subinmbed 2:c4fb968de7d3 221
subinmbed 2:c4fb968de7d3 222 */
subinmbed 2:c4fb968de7d3 223
subinmbed 2:c4fb968de7d3 224 dtc_data_pointer += 6;
subinmbed 2:c4fb968de7d3 225
subinmbed 2:c4fb968de7d3 226 // THE FOLLOWING LINES OF CODE COPIES THE DTC DATA IN A VARIABLE AND ELIMINATES THE SPACE CHARACTER
subinmbed 2:c4fb968de7d3 227
subinmbed 2:c4fb968de7d3 228 for(count = 0; count < ((5*no_of_stored_dtc) + (no_of_stored_dtc - 1)); count++)
subinmbed 2:c4fb968de7d3 229 {
subinmbed 2:c4fb968de7d3 230 if((*dtc_data_pointer) == '\r')
subinmbed 2:c4fb968de7d3 231 break;
subinmbed 2:c4fb968de7d3 232
subinmbed 2:c4fb968de7d3 233 if((*dtc_data_pointer) == ' ')
subinmbed 2:c4fb968de7d3 234 {
subinmbed 2:c4fb968de7d3 235 dtc_data_pointer++;
subinmbed 2:c4fb968de7d3 236 continue;
subinmbed 2:c4fb968de7d3 237 }
subinmbed 2:c4fb968de7d3 238
subinmbed 2:c4fb968de7d3 239 else
subinmbed 2:c4fb968de7d3 240 {
subinmbed 2:c4fb968de7d3 241 if((*dtc_data_pointer - 0x30) <= 9)
subinmbed 2:c4fb968de7d3 242 dtc_data[internal_count] = (*dtc_data_pointer) - 0x30;
subinmbed 2:c4fb968de7d3 243 else
subinmbed 2:c4fb968de7d3 244 {
subinmbed 2:c4fb968de7d3 245 dtc_data[internal_count] = (*dtc_data_pointer) - 0x37;
subinmbed 2:c4fb968de7d3 246 }
subinmbed 2:c4fb968de7d3 247 internal_count++;
subinmbed 2:c4fb968de7d3 248 dtc_data_pointer++;
subinmbed 2:c4fb968de7d3 249 }
subinmbed 2:c4fb968de7d3 250 }
subinmbed 2:c4fb968de7d3 251
subinmbed 2:c4fb968de7d3 252 internal_count = 0;
subinmbed 2:c4fb968de7d3 253
subinmbed 2:c4fb968de7d3 254 char dtc_data_merged[((4*(no_of_stored_dtc)) / 2)];
subinmbed 2:c4fb968de7d3 255
subinmbed 2:c4fb968de7d3 256 for(count = 0; count < ((4*no_of_stored_dtc)); count += 2)
subinmbed 2:c4fb968de7d3 257 {
subinmbed 2:c4fb968de7d3 258 dtc_data_merged[internal_count] = ((dtc_data[count] << 4) | dtc_data[count + 1]);
subinmbed 2:c4fb968de7d3 259 internal_count++;
subinmbed 2:c4fb968de7d3 260 }
subinmbed 2:c4fb968de7d3 261
subinmbed 2:c4fb968de7d3 262 internal_count = 0;
subinmbed 2:c4fb968de7d3 263
subinmbed 2:c4fb968de7d3 264 for(count = 0; count < (2*(no_of_stored_dtc)); count += 2)
subinmbed 2:c4fb968de7d3 265 {
subinmbed 2:c4fb968de7d3 266 switch(dtc_data_merged[count] & 0b11000000)
subinmbed 2:c4fb968de7d3 267 {
subinmbed 2:c4fb968de7d3 268 case 0:
subinmbed 2:c4fb968de7d3 269 dtc_codes[internal_count] = 'P';
subinmbed 2:c4fb968de7d3 270 break;
subinmbed 2:c4fb968de7d3 271 case 1:
subinmbed 2:c4fb968de7d3 272 dtc_codes[internal_count] = 'C';
subinmbed 2:c4fb968de7d3 273 break;
subinmbed 2:c4fb968de7d3 274 case 2:
subinmbed 2:c4fb968de7d3 275 dtc_codes[internal_count] = 'B';
subinmbed 2:c4fb968de7d3 276 break;
subinmbed 2:c4fb968de7d3 277 case 3:
subinmbed 2:c4fb968de7d3 278 dtc_codes[internal_count] = 'U';
subinmbed 2:c4fb968de7d3 279 break;
subinmbed 2:c4fb968de7d3 280 }
subinmbed 2:c4fb968de7d3 281
subinmbed 2:c4fb968de7d3 282 internal_count++;
subinmbed 2:c4fb968de7d3 283
subinmbed 2:c4fb968de7d3 284 dtc_codes[internal_count] = ((dtc_data_merged[count] & 0b00110000) + 0x30);
subinmbed 2:c4fb968de7d3 285 internal_count++;
subinmbed 2:c4fb968de7d3 286 dtc_codes[internal_count] = ((dtc_data_merged[count] & 0b00001111) + 0x30);
subinmbed 2:c4fb968de7d3 287 internal_count++;
subinmbed 2:c4fb968de7d3 288 dtc_codes[internal_count] = (((dtc_data_merged[count + 1] & 0b11110000) >> 4) + 0x30);
subinmbed 2:c4fb968de7d3 289 internal_count++;
subinmbed 2:c4fb968de7d3 290 dtc_codes[internal_count] = ((dtc_data_merged[count + 1] & 0b00001111) + 0x30);
subinmbed 2:c4fb968de7d3 291 internal_count++;
subinmbed 2:c4fb968de7d3 292 dtc_codes[internal_count] = '\r';
subinmbed 2:c4fb968de7d3 293
subinmbed 2:c4fb968de7d3 294 DEBUG_UART.printf("\r\nDTC CODES :");
subinmbed 2:c4fb968de7d3 295 DEBUG_UART.printf("\r\n%s", dtc_codes);
subinmbed 2:c4fb968de7d3 296 }
subinmbed 2:c4fb968de7d3 297 }
subinmbed 2:c4fb968de7d3 298
subinmbed 2:c4fb968de7d3 299 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 300
subinmbed 2:c4fb968de7d3 301 // FUNCTION CALLED FROM PARENT FUNCTION
subinmbed 2:c4fb968de7d3 302 // THE FOLLOWING CODE BLOCK IS USED TO PROCESS MIL DATA FETCHED FROM THE OBD PORT OF THE CAR
subinmbed 2:c4fb968de7d3 303
subinmbed 2:c4fb968de7d3 304 void process_mil_data(char *mil_data_pointer)
subinmbed 2:c4fb968de7d3 305 {
subinmbed 2:c4fb968de7d3 306 DEBUG_UART.printf("\r\n\r\nENTERED PROCESS MIL DATA FUNCTION");
subinmbed 2:c4fb968de7d3 307 char mil_data[2], mil_data_converted;
subinmbed 2:c4fb968de7d3 308 char count;
subinmbed 2:c4fb968de7d3 309
subinmbed 2:c4fb968de7d3 310 // char virtual_mil_buffer = "0101\r41 01 00 04 60 00 \r\r";
subinmbed 2:c4fb968de7d3 311 mil_data_pointer += 11;
subinmbed 2:c4fb968de7d3 312
subinmbed 2:c4fb968de7d3 313 for(count = 0; count < 2; count++)
subinmbed 2:c4fb968de7d3 314 {
subinmbed 2:c4fb968de7d3 315 mil_data[count] = *mil_data_pointer++;
subinmbed 2:c4fb968de7d3 316 }
subinmbed 2:c4fb968de7d3 317
subinmbed 2:c4fb968de7d3 318 // THE FOLLOWING LINES OF CODE CONVERTS THE ASCII DATA TO THE HEX DATA
subinmbed 2:c4fb968de7d3 319
subinmbed 2:c4fb968de7d3 320 if((((mil_data[0] - 0x30) & 0x7F) <= 9) && (((mil_data[1] - 0x30) & 0x7F) <= 9))
subinmbed 2:c4fb968de7d3 321 mil_data_converted = (((mil_data[0] - 0x30)<<4) + (mil_data[1] - 0x30)); // Converting the ASCII data to the Hex data
subinmbed 2:c4fb968de7d3 322
subinmbed 2:c4fb968de7d3 323 else if((((mil_data[0] - 0x30) & 0x7F) <= 9))
subinmbed 2:c4fb968de7d3 324 mil_data_converted = (((mil_data[0] - 0x30)<<4) + (mil_data[1] - 0x37)); // Converting the ASCII data to the Hex data
subinmbed 2:c4fb968de7d3 325
subinmbed 2:c4fb968de7d3 326 else if((((mil_data[1] - 0x30) & 0x7F) <= 9))
subinmbed 2:c4fb968de7d3 327 mil_data_converted = (((mil_data[0] - 0x37)<<4) + (mil_data[1] - 0x30)); // Converting the ASCII data to the Hex data
subinmbed 2:c4fb968de7d3 328
subinmbed 2:c4fb968de7d3 329 else
subinmbed 2:c4fb968de7d3 330 mil_data_converted = (((mil_data[0] - 0x37)<<4) + (mil_data[1] - 0x37)); // Converting the ASCII data to the Hex data
subinmbed 2:c4fb968de7d3 331
subinmbed 2:c4fb968de7d3 332 // The following code lines checks for the number of Mal function indicator lamp enabled by tghe CAN ECU
subinmbed 2:c4fb968de7d3 333
subinmbed 2:c4fb968de7d3 334 if(mil_data_converted & 0x80) // Checks for the MSB bit enabled or not which inc=dicates that the MIL is On or NOT
subinmbed 2:c4fb968de7d3 335 {
subinmbed 2:c4fb968de7d3 336 mil = 1; // Setting the MIL flag
subinmbed 2:c4fb968de7d3 337 DEBUG_UART.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS ON");
subinmbed 2:c4fb968de7d3 338 no_of_stored_dtc = (mil_data_converted & 0b01111111);
subinmbed 2:c4fb968de7d3 339 DEBUG_UART.printf("\r\n NO OF STORED DYNAMIC TROUBLE CODE = %d", no_of_stored_dtc);
subinmbed 2:c4fb968de7d3 340 }
subinmbed 2:c4fb968de7d3 341 else {
subinmbed 2:c4fb968de7d3 342 mil = 0; // Clearing the MIL flag
subinmbed 2:c4fb968de7d3 343 DEBUG_UART.printf("\r\nMIL (MALFUNCTION INDICATOR LAMP) IS OFF"); }
subinmbed 2:c4fb968de7d3 344 }
subinmbed 2:c4fb968de7d3 345
subinmbed 2:c4fb968de7d3 346 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 347
subinmbed 2:c4fb968de7d3 348 // FUNCTION CALLED FROM PARENT FUNCTION
subinmbed 2:c4fb968de7d3 349 // THE FOLLWOING CODE BLOCK IS USED TO PROCESS THE VEHICLE SPEED DATA FETCHED FROM THE OBD PORT OF THE CAR
subinmbed 2:c4fb968de7d3 350
subinmbed 2:c4fb968de7d3 351 float process_vehicle_speed(char *vehicle_speed_pointer)
subinmbed 2:c4fb968de7d3 352 {
subinmbed 2:c4fb968de7d3 353 char vehicle_speed_data[2]; // Vehicle speed data is returned by a 2 byte value
subinmbed 2:c4fb968de7d3 354 char *strtol_pointer;
subinmbed 2:c4fb968de7d3 355 char count;
subinmbed 2:c4fb968de7d3 356 //"010D\r41 0D 4F\r\r>"
subinmbed 2:c4fb968de7d3 357 vehicle_speed_pointer += 11;
subinmbed 2:c4fb968de7d3 358 //for(count = 0; count < 2; count++)
subinmbed 2:c4fb968de7d3 359 {
subinmbed 2:c4fb968de7d3 360 //vehicle_speed_data[count] = *vehicle_speed_pointer++;
subinmbed 2:c4fb968de7d3 361 // vehicle_speed_data[count] = 5;
subinmbed 2:c4fb968de7d3 362 }
subinmbed 2:c4fb968de7d3 363
subinmbed 2:c4fb968de7d3 364 vehicle_speed = strtol(vehicle_speed_data, &strtol_pointer, 16);
subinmbed 2:c4fb968de7d3 365 //speed1=0;
subinmbed 2:c4fb968de7d3 366 speed1=ain.read()*100.0f;///*************************adc value for tesing need to load actual speed********************************************
subinmbed 2:c4fb968de7d3 367
subinmbed 2:c4fb968de7d3 368 DEBUG_UART.printf("\r\nVEHICLE SPEED = %ld", vehicle_speed);
subinmbed 2:c4fb968de7d3 369 return(speed1);
subinmbed 2:c4fb968de7d3 370 }
subinmbed 2:c4fb968de7d3 371
subinmbed 2:c4fb968de7d3 372 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 373
subinmbed 2:c4fb968de7d3 374 // FUNCTION CALLED BY PARENT FUCTION
subinmbed 2:c4fb968de7d3 375 // THE FOLLWOING CODE BLOCK IS USED TO PROCESS THE ENGINE RPM FETCHED FROM THE OBD PORT OF THE CAR
subinmbed 2:c4fb968de7d3 376
subinmbed 2:c4fb968de7d3 377 unsigned int process_engine_rpm(char *rpm_data_pointer)
subinmbed 2:c4fb968de7d3 378 {
subinmbed 2:c4fb968de7d3 379 //char virtual_engine_rpm[] = "010C\r41 0C 00 00 \r\r>";
subinmbed 2:c4fb968de7d3 380 char engine_rpm[4]; // Vehicle speed data is returned by a 4 byte value
subinmbed 2:c4fb968de7d3 381 char *strtol_pointer;
subinmbed 2:c4fb968de7d3 382 char count;
subinmbed 2:c4fb968de7d3 383 char internal_count = 0;
subinmbed 2:c4fb968de7d3 384
subinmbed 2:c4fb968de7d3 385 rpm_data_pointer += 11;
subinmbed 2:c4fb968de7d3 386
subinmbed 2:c4fb968de7d3 387 for(count = 0; count < 5; count++)
subinmbed 2:c4fb968de7d3 388 {
subinmbed 2:c4fb968de7d3 389 if(*rpm_data_pointer == ' ') { // Negate the spaces added in between
subinmbed 2:c4fb968de7d3 390 rpm_data_pointer++;
subinmbed 2:c4fb968de7d3 391 continue; }
subinmbed 2:c4fb968de7d3 392 else {
subinmbed 2:c4fb968de7d3 393 engine_rpm[internal_count] = *rpm_data_pointer++;
subinmbed 2:c4fb968de7d3 394 internal_count++; }
subinmbed 2:c4fb968de7d3 395 }
subinmbed 2:c4fb968de7d3 396
subinmbed 2:c4fb968de7d3 397 DEBUG_UART.printf("\r\n%s", engine_rpm);
subinmbed 2:c4fb968de7d3 398
subinmbed 2:c4fb968de7d3 399 rpm = ((strtol(engine_rpm, &strtol_pointer, 16)) / 4);
subinmbed 2:c4fb968de7d3 400
subinmbed 2:c4fb968de7d3 401 DEBUG_UART.printf("\r\nENGINE RPM = %ld", rpm);
subinmbed 2:c4fb968de7d3 402 return(rpm);
subinmbed 2:c4fb968de7d3 403 }
subinmbed 2:c4fb968de7d3 404
subinmbed 2:c4fb968de7d3 405 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 406
subinmbed 2:c4fb968de7d3 407 // FUNCTION CALLED BY PARENT FUNCTION
subinmbed 2:c4fb968de7d3 408 // THE FOLLOWING CODE BLOCK IS USED TO PROCESS THE BATTERY VOLTAGE FETCHED FROM THE OBD PORT OF THE CAR
subinmbed 2:c4fb968de7d3 409
subinmbed 2:c4fb968de7d3 410 void process_battery_voltage(char *battery_voltage_pointer)
subinmbed 2:c4fb968de7d3 411 {
subinmbed 2:c4fb968de7d3 412 char battery_voltage_data[4]; // One decimal point precision ( For ex : 12.5 )
subinmbed 2:c4fb968de7d3 413 char count;
subinmbed 2:c4fb968de7d3 414 battery_voltage_pointer += 5; // ATRV<CR> counts to 5
subinmbed 2:c4fb968de7d3 415 for(count = 0; count < 4; count++)
subinmbed 2:c4fb968de7d3 416 {
subinmbed 2:c4fb968de7d3 417 battery_voltage_data[count] = *battery_voltage_pointer++;
subinmbed 2:c4fb968de7d3 418 }
subinmbed 2:c4fb968de7d3 419 car_battery_voltage = atof(battery_voltage_data); // Converts the Battery Volatge from String to Float data type
subinmbed 2:c4fb968de7d3 420 //Misc_Packet_Data.Car_Battery_Voltage = (car_battery_voltage * 100);
subinmbed 2:c4fb968de7d3 421 DEBUG_UART.printf("\r\nCAR BATTERY VOLTAGE = %f",car_battery_voltage);
subinmbed 2:c4fb968de7d3 422 }
subinmbed 2:c4fb968de7d3 423
subinmbed 2:c4fb968de7d3 424
subinmbed 2:c4fb968de7d3 425 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 426
subinmbed 2:c4fb968de7d3 427 /*
subinmbed 2:c4fb968de7d3 428 _______________________________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 429
subinmbed 2:c4fb968de7d3 430 NOTE :
subinmbed 2:c4fb968de7d3 431 -----
subinmbed 2:c4fb968de7d3 432 THE FOLLOWING CODE O DETERMINE THE DIAGNOSTIC TROUBLE CODE (DTC) IS BASED ON THE INTERPRETATION GIVEN IN WIKIPEDIA
subinmbed 2:c4fb968de7d3 433 FOR THE ISO 15765-2 PROTOCOL
subinmbed 2:c4fb968de7d3 434 DIFFERENT INTERPRETATION METHODOLOGY IS GIVEN IN THE ELM327 DATASHEET FOR SAE PROTOCOL
subinmbed 2:c4fb968de7d3 435 SO THESE THINGS ARE SUBJECTED TO MODIFICATION AND HAVE NOT BEEN CONFIRMED WITH THE REAL TIME DATA
subinmbed 2:c4fb968de7d3 436 _______________________________________________________________________________________________________________________
subinmbed 2:c4fb968de7d3 437
subinmbed 2:c4fb968de7d3 438 */
subinmbed 2:c4fb968de7d3 439
subinmbed 2:c4fb968de7d3 440 // FUNCTION WILL BE CALLED ON REQUEST
subinmbed 2:c4fb968de7d3 441 // THE FOLLOWING CODE BLOCK WILL FETCH THE DTC DATA FROM THE OBD PORT OF THE CAR AND SENDS THE SAME FOR PROCESSING
subinmbed 2:c4fb968de7d3 442
subinmbed 2:c4fb968de7d3 443 void check_for_dtc()
subinmbed 2:c4fb968de7d3 444 {
subinmbed 2:c4fb968de7d3 445 char virtual_dtc_buffer[] = "03\r43 00 85\r\r>";
subinmbed 2:c4fb968de7d3 446
subinmbed 2:c4fb968de7d3 447 OBD_UART.printf(check_dtc_cmd);
subinmbed 2:c4fb968de7d3 448 wait(1);
subinmbed 2:c4fb968de7d3 449 while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 450 DEBUG_UART.printf("Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 451 received_data_verification(OBD_UART_RX_Buffer, check_dtc_cmd, (strlen(check_dtc_cmd)-1));
subinmbed 2:c4fb968de7d3 452
subinmbed 2:c4fb968de7d3 453 //process_dtc_data(virtual_dtc_buffer);
subinmbed 2:c4fb968de7d3 454
subinmbed 2:c4fb968de7d3 455
subinmbed 2:c4fb968de7d3 456 if(pass == 1) {
subinmbed 2:c4fb968de7d3 457 process_dtc_data(OBD_UART_RX_Buffer);
subinmbed 2:c4fb968de7d3 458 DEBUG_UART.printf("\r\VEHICLE DIAGNOSTIC TROUBLE CODE RECEIVED SUCCESSFULLY \r\n\r\n"); }
subinmbed 2:c4fb968de7d3 459 else
subinmbed 2:c4fb968de7d3 460 DEBUG_UART.printf("\r\nVEHICLE DIAGNOSTIC TROUBLE CODE DATA RECEPTION FAILED\r\n\r\n");
subinmbed 2:c4fb968de7d3 461 reception_complete = 0; // Disabling the reception complete flag
subinmbed 2:c4fb968de7d3 462 OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception
subinmbed 2:c4fb968de7d3 463
subinmbed 2:c4fb968de7d3 464 }
subinmbed 2:c4fb968de7d3 465
subinmbed 2:c4fb968de7d3 466 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 467
subinmbed 2:c4fb968de7d3 468 // FUNCTION WILL BE CALLED ON REQUEST
subinmbed 2:c4fb968de7d3 469 // THE FOLLOWING CODE BLOCK WILL FETCH THE MIL DATA FROM THE OBD PORT OF THE CAR
subinmbed 2:c4fb968de7d3 470
subinmbed 2:c4fb968de7d3 471 void check_for_MIL()
subinmbed 2:c4fb968de7d3 472 {
subinmbed 2:c4fb968de7d3 473
subinmbed 2:c4fb968de7d3 474 DEBUG_UART.printf("\r\n\r\nENTERED CHECK FOR MIL FUNCTION");
subinmbed 2:c4fb968de7d3 475 char count;
subinmbed 2:c4fb968de7d3 476 char virtual_mil_buffer[] = "0101\r41 01 82 04 60 00 \r\r";
subinmbed 2:c4fb968de7d3 477
subinmbed 2:c4fb968de7d3 478 /*
subinmbed 2:c4fb968de7d3 479 OBD_UART.printf(check_mil_cmd);
subinmbed 2:c4fb968de7d3 480
subinmbed 2:c4fb968de7d3 481 for(count = 0; count < strlen(check_mil_cmd); count++)
subinmbed 2:c4fb968de7d3 482 OBD_UART.putc(check_mil_cmd[count]);
subinmbed 2:c4fb968de7d3 483 wait(1);
subinmbed 2:c4fb968de7d3 484 while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 485 OBD_UART.printf("Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 486 received_data_verification(OBD_UART_RX_Buffer, check_mil_cmd, (strlen(check_mil_cmd)-1));
subinmbed 2:c4fb968de7d3 487 */
subinmbed 2:c4fb968de7d3 488
subinmbed 2:c4fb968de7d3 489 process_mil_data(virtual_mil_buffer);
subinmbed 2:c4fb968de7d3 490
subinmbed 2:c4fb968de7d3 491
subinmbed 2:c4fb968de7d3 492 if(pass == 1) {
subinmbed 2:c4fb968de7d3 493 process_mil_data(OBD_UART_RX_Buffer);
subinmbed 2:c4fb968de7d3 494 DEBUG_UART.printf("\r\nVEHICLE MIL DATA RECEIVED SUCCESSFULLY \r\n\r\n");}
subinmbed 2:c4fb968de7d3 495 else
subinmbed 2:c4fb968de7d3 496 DEBUG_UART.printf("\r\nVEHICLE MIL DATA RECEPTION FAILED\r\n\r\n");
subinmbed 2:c4fb968de7d3 497 reception_complete = 0; // Disabling the reception complete flag
subinmbed 2:c4fb968de7d3 498 OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception
subinmbed 2:c4fb968de7d3 499
subinmbed 2:c4fb968de7d3 500 }
subinmbed 2:c4fb968de7d3 501
subinmbed 2:c4fb968de7d3 502
subinmbed 2:c4fb968de7d3 503 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 504
subinmbed 2:c4fb968de7d3 505 char fetch_vin_number()
subinmbed 2:c4fb968de7d3 506 {
subinmbed 2:c4fb968de7d3 507 char count;
subinmbed 2:c4fb968de7d3 508 //char virtual_rx_vin_buffer[] = "3147 43\r314b \r58: 43 38 01 54 4D 42 \r1: 46 4B 4A 35 4A 32 43 \r2: 47 30 31 34 37 33 33 \r\r>";
subinmbed 2:c4fb968de7d3 509 char virtual_rx_vin_buffer[] = "0902 5\r014 \r0: 49 02 01 54 4D 42 \r1: 40 41 42 35 4A 32 43 \r2: 47 30 31 34 37 33 33 \r\r>";
subinmbed 2:c4fb968de7d3 510 //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>";
subinmbed 2:c4fb968de7d3 511 //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>";
subinmbed 2:c4fb968de7d3 512 // 1GC1KXC82BF134775->31 47 43 31 4b 58 43 38 32 42 46 31 33 34 37 37 35
subinmbed 2:c4fb968de7d3 513 // 1G1PC5SB0E7341780->31 47 31 50 43 35 53 42 30 45 37 33 34 31 37 38 30
subinmbed 2:c4fb968de7d3 514 // 1G1RD6S56GU125328->31 47 31 52 44 36 53 35 36 47 55 31 32 35 33 32 38
subinmbed 2:c4fb968de7d3 515 char vin_number_cmd1[] = "0902 5\r";
subinmbed 2:c4fb968de7d3 516 OBD_UART.printf("VIN Reception Started24432\r\n");
subinmbed 2:c4fb968de7d3 517
subinmbed 2:c4fb968de7d3 518
subinmbed 2:c4fb968de7d3 519 char vin_buffer[100];
subinmbed 2:c4fb968de7d3 520 char *vin_data_pointer;
subinmbed 2:c4fb968de7d3 521 char internal_counter = 0;
subinmbed 2:c4fb968de7d3 522 char small_buffer[2];
subinmbed 2:c4fb968de7d3 523 long ascii_converted_data;
subinmbed 2:c4fb968de7d3 524 char *vin_conv_pointer;
subinmbed 2:c4fb968de7d3 525 char vin_number[17];
subinmbed 2:c4fb968de7d3 526 wait(1);
subinmbed 2:c4fb968de7d3 527 OBD_RxBuffer_End_Pos = 0;
subinmbed 2:c4fb968de7d3 528 //for(count = 0; count < strlen(vin_number_cmd1); count++)
subinmbed 2:c4fb968de7d3 529 // OBD_UART.putc(vin_number_cmd[count]);
subinmbed 2:c4fb968de7d3 530 OBD_UART.putc(0x30);
subinmbed 2:c4fb968de7d3 531 OBD_UART.putc(0x39);
subinmbed 2:c4fb968de7d3 532 OBD_UART.putc(0x30);
subinmbed 2:c4fb968de7d3 533 OBD_UART.putc(0x32);
subinmbed 2:c4fb968de7d3 534 OBD_UART.putc(0x20);
subinmbed 2:c4fb968de7d3 535 OBD_UART.putc(0x35);
subinmbed 2:c4fb968de7d3 536 OBD_UART.putc(0x0D);
subinmbed 2:c4fb968de7d3 537
subinmbed 2:c4fb968de7d3 538 OBD_UART.printf("VIN Reception Started %d\r\n",strlen(virtual_rx_vin_buffer));
subinmbed 2:c4fb968de7d3 539
subinmbed 2:c4fb968de7d3 540 vin_data_pointer = virtual_rx_vin_buffer;
subinmbed 2:c4fb968de7d3 541 vin_data_pointer += 23;
subinmbed 2:c4fb968de7d3 542 while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')) // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 543 {
subinmbed 2:c4fb968de7d3 544 if(OBD_RxBuffer_End_Pos >=6)
subinmbed 2:c4fb968de7d3 545 break;
subinmbed 2:c4fb968de7d3 546 }
subinmbed 2:c4fb968de7d3 547 for(count = 0; count < 86; count++)
subinmbed 2:c4fb968de7d3 548 OBD_UART.putc(OBD_UART_RX_Buffer[count]);
subinmbed 2:c4fb968de7d3 549 //OBD_UART.printf("VIN Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 550 //return(1);
subinmbed 2:c4fb968de7d3 551 vin_data_pointer = OBD_UART_RX_Buffer;
subinmbed 2:c4fb968de7d3 552 vin_data_pointer += 23;
subinmbed 2:c4fb968de7d3 553
subinmbed 2:c4fb968de7d3 554 int length;
subinmbed 2:c4fb968de7d3 555 for(count = 0; count < (strlen(virtual_rx_vin_buffer) - 1); count++)
subinmbed 2:c4fb968de7d3 556 {
subinmbed 2:c4fb968de7d3 557 if((*vin_data_pointer == '\r') | (*vin_data_pointer == ' ') | (*vin_data_pointer == '>'))
subinmbed 2:c4fb968de7d3 558 {
subinmbed 2:c4fb968de7d3 559 vin_data_pointer++;
subinmbed 2:c4fb968de7d3 560 continue;
subinmbed 2:c4fb968de7d3 561 }
subinmbed 2:c4fb968de7d3 562 else if(*(vin_data_pointer + 1) == ':')
subinmbed 2:c4fb968de7d3 563 {
subinmbed 2:c4fb968de7d3 564 vin_data_pointer += 2;
subinmbed 2:c4fb968de7d3 565 continue;
subinmbed 2:c4fb968de7d3 566 }
subinmbed 2:c4fb968de7d3 567 else
subinmbed 2:c4fb968de7d3 568 {
subinmbed 2:c4fb968de7d3 569 //printf("\r\ncount2 = %d", count);
subinmbed 2:c4fb968de7d3 570 vin_buffer[internal_counter] = *vin_data_pointer;
subinmbed 2:c4fb968de7d3 571 internal_counter++;
subinmbed 2:c4fb968de7d3 572 }
subinmbed 2:c4fb968de7d3 573 vin_data_pointer++;
subinmbed 2:c4fb968de7d3 574 }
subinmbed 2:c4fb968de7d3 575
subinmbed 2:c4fb968de7d3 576 length = strlen(vin_buffer);
subinmbed 2:c4fb968de7d3 577 DEBUG_UART.printf("\r\n VIN BUFFER LENGTH = %d", length);
subinmbed 2:c4fb968de7d3 578
subinmbed 2:c4fb968de7d3 579 DEBUG_UART.printf("\r\n VIN NUMBER : %s", vin_buffer);
subinmbed 2:c4fb968de7d3 580
subinmbed 2:c4fb968de7d3 581 internal_counter = 0;
subinmbed 2:c4fb968de7d3 582
subinmbed 2:c4fb968de7d3 583 for(count = 0; count < strlen(vin_buffer); count+=2)
subinmbed 2:c4fb968de7d3 584 {
subinmbed 2:c4fb968de7d3 585 small_buffer[0] = vin_buffer[count];
subinmbed 2:c4fb968de7d3 586 small_buffer[1] = vin_buffer[count+1];
subinmbed 2:c4fb968de7d3 587 ascii_converted_data = strtol(small_buffer, &vin_conv_pointer, 16);
subinmbed 2:c4fb968de7d3 588 vin_number[internal_counter] = ascii_converted_data;
subinmbed 2:c4fb968de7d3 589 //Misc_Packet_Data.VIN[internal_counter] = ascii_converted_data;
subinmbed 2:c4fb968de7d3 590 internal_counter++;
subinmbed 2:c4fb968de7d3 591 }
subinmbed 2:c4fb968de7d3 592 DEBUG_UART.printf("\r\n\r\nVEHICLE CHASSIS NUMBER : %s", vin_number);
subinmbed 2:c4fb968de7d3 593
subinmbed 2:c4fb968de7d3 594 }
subinmbed 2:c4fb968de7d3 595
subinmbed 2:c4fb968de7d3 596 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 597
subinmbed 2:c4fb968de7d3 598
subinmbed 2:c4fb968de7d3 599 // FUNCTION WILL BE CALLED ON REQUEST
subinmbed 2:c4fb968de7d3 600 // THE FOLLOWING CODE BLOCK FETCHES THE VEHICLE SPEED DATA FROM THE OBD PORT OF THE CAR AND SENDS THE SAME FOR PROCESSING
subinmbed 2:c4fb968de7d3 601
subinmbed 2:c4fb968de7d3 602 float fetch_vehicle_speed()
subinmbed 2:c4fb968de7d3 603 {
subinmbed 2:c4fb968de7d3 604 char virtual_rx_speed_buffer[] = "010D\r41 0D 4F \r\r>";
subinmbed 2:c4fb968de7d3 605 char count;
subinmbed 2:c4fb968de7d3 606 //OBD_UART.printf(vehicle_speed_cmd);
subinmbed 2:c4fb968de7d3 607
subinmbed 2:c4fb968de7d3 608 //for(count = 0; count < strlen(vehicle_speed_cmd); count++)
subinmbed 2:c4fb968de7d3 609 // OBD_UART.putc(vehicle_speed_cmd[count]);
subinmbed 2:c4fb968de7d3 610 //wait(1);
subinmbed 2:c4fb968de7d3 611 // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 612 // DEBUG_UART.printf("Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 613 //received_data_verification(OBD_UART_RX_Buffer, vehicle_speed_cmd, (strlen(vehicle_speed_cmd)-1));
subinmbed 2:c4fb968de7d3 614
subinmbed 2:c4fb968de7d3 615 //
subinmbed 2:c4fb968de7d3 616 speed2=process_vehicle_speed(virtual_rx_speed_buffer);
subinmbed 2:c4fb968de7d3 617
subinmbed 2:c4fb968de7d3 618 if(pass == 1) {
subinmbed 2:c4fb968de7d3 619 speed2= process_vehicle_speed(OBD_UART_RX_Buffer);
subinmbed 2:c4fb968de7d3 620 DEBUG_UART.printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); }
subinmbed 2:c4fb968de7d3 621 else
subinmbed 2:c4fb968de7d3 622 DEBUG_UART.printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n");
subinmbed 2:c4fb968de7d3 623 reception_complete = 0; // Disabling the reception complete flag
subinmbed 2:c4fb968de7d3 624 OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception
subinmbed 2:c4fb968de7d3 625 return(speed2);
subinmbed 2:c4fb968de7d3 626
subinmbed 2:c4fb968de7d3 627 }
subinmbed 2:c4fb968de7d3 628
subinmbed 2:c4fb968de7d3 629 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 630
subinmbed 2:c4fb968de7d3 631 // FUNCITON WILL BE CALLED ON REQUEST
subinmbed 2:c4fb968de7d3 632 // THE FOLLOWING CODE BLOCK FETCHES THE RPM DATA FROM THE OBD PORT OF THE CAR AND WILL SEND THE SAME FOR PROCESSING
subinmbed 2:c4fb968de7d3 633
subinmbed 2:c4fb968de7d3 634 unsigned int fetch_engine_rpm()
subinmbed 2:c4fb968de7d3 635 {
subinmbed 2:c4fb968de7d3 636 char count;
subinmbed 2:c4fb968de7d3 637 unsigned int RPM;
subinmbed 2:c4fb968de7d3 638 OBD_RxBuffer_End_Pos = 0;
subinmbed 2:c4fb968de7d3 639
subinmbed 2:c4fb968de7d3 640 char virtual_engine_rpm[] = "010C\r41 0C 0E A2 \r\r>";
subinmbed 2:c4fb968de7d3 641 DEBUG_UART.printf("rpm Reception Start\r\n");
subinmbed 2:c4fb968de7d3 642 // for(count = 0; count < strlen(engine_rpm_cmd); count ++)
subinmbed 2:c4fb968de7d3 643 // OBD_UART.putc(engine_rpm_cmd[count]);
subinmbed 2:c4fb968de7d3 644 // wait(1);
subinmbed 2:c4fb968de7d3 645 // while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 646 // OBD_UART.printf("Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 647 // received_data_verification(OBD_UART_RX_Buffer, engine_rpm_cmd, (strlen(engine_rpm_cmd)-1));
subinmbed 2:c4fb968de7d3 648 //
subinmbed 2:c4fb968de7d3 649
subinmbed 2:c4fb968de7d3 650 //process_engine_rpm(virtual_engine_rpm);
subinmbed 2:c4fb968de7d3 651 if(pass == 1) {
subinmbed 2:c4fb968de7d3 652 RPM = process_engine_rpm(virtual_engine_rpm);
subinmbed 2:c4fb968de7d3 653 DEBUG_UART.printf("\r\nVEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); }
subinmbed 2:c4fb968de7d3 654 else
subinmbed 2:c4fb968de7d3 655 DEBUG_UART.printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n");
subinmbed 2:c4fb968de7d3 656 reception_complete = 0; // Disabling the reception complete flag
subinmbed 2:c4fb968de7d3 657 OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception
subinmbed 2:c4fb968de7d3 658 return(RPM);
subinmbed 2:c4fb968de7d3 659 }
subinmbed 2:c4fb968de7d3 660
subinmbed 2:c4fb968de7d3 661 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 662
subinmbed 2:c4fb968de7d3 663 // FUNCTION WILL BE CALLED ON REQUEST
subinmbed 2:c4fb968de7d3 664 // THE FOLLOWING CODE BLOCK FETCHED THE BATTERY VOLTAGE DATA FROM THE OBD PORT AND PASSES THE SAME DATA FOR PROCESSING
subinmbed 2:c4fb968de7d3 665
subinmbed 2:c4fb968de7d3 666 void fetch_battery_voltage()
subinmbed 2:c4fb968de7d3 667 {
subinmbed 2:c4fb968de7d3 668 char count;
subinmbed 2:c4fb968de7d3 669 //OBD_UART.printf(battery_voltage_cmd);
subinmbed 2:c4fb968de7d3 670 OBD_UART.printf("Battery Voltage\r\n");
subinmbed 2:c4fb968de7d3 671 for(count = 0; count < strlen(battery_voltage_cmd); count++){
subinmbed 2:c4fb968de7d3 672 OBD_UART.putc(battery_voltage_cmd[count]);
subinmbed 2:c4fb968de7d3 673 OBD_UART.printf("0x%2x ",battery_voltage_cmd[count]);
subinmbed 2:c4fb968de7d3 674 }
subinmbed 2:c4fb968de7d3 675 wait(1);
subinmbed 2:c4fb968de7d3 676
subinmbed 2:c4fb968de7d3 677 while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 678 DEBUG_UART.printf("Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 679 received_data_verification(OBD_UART_RX_Buffer, battery_voltage_cmd, (strlen(battery_voltage_cmd)-1));
subinmbed 2:c4fb968de7d3 680
subinmbed 2:c4fb968de7d3 681
subinmbed 2:c4fb968de7d3 682 if(pass == 1) {
subinmbed 2:c4fb968de7d3 683 DEBUG_UART.printf("\r\nOBD READ BATTERY VOLTAGE SUCCESSFUL");
subinmbed 2:c4fb968de7d3 684 process_battery_voltage(OBD_UART_RX_Buffer); }
subinmbed 2:c4fb968de7d3 685 else
subinmbed 2:c4fb968de7d3 686 DEBUG_UART.printf("\r\nOBD READ BATTERY VOLTAGE FAILED");
subinmbed 2:c4fb968de7d3 687 reception_complete = 0; // Disabling the reception complete flag
subinmbed 2:c4fb968de7d3 688 OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception
subinmbed 2:c4fb968de7d3 689 }
subinmbed 2:c4fb968de7d3 690
subinmbed 2:c4fb968de7d3 691
subinmbed 2:c4fb968de7d3 692 //*********************************************************************************************************************************************************************************
subinmbed 2:c4fb968de7d3 693
subinmbed 2:c4fb968de7d3 694 // FUNCTION WILL BE CALLED ON REQUEST
subinmbed 2:c4fb968de7d3 695 // TYHE FOLLOWING CODE BLOXK INITIALIZES THE OBD INTERFACE
subinmbed 2:c4fb968de7d3 696 // IT IS MANDATORY TO CALL THIS FUNCTION BEFORE USING ANY OF THE OTHER FUNCTIONS INCLUDED IN THIS PARTICULAR LIBRARY
subinmbed 2:c4fb968de7d3 697
subinmbed 2:c4fb968de7d3 698 void initialize_obd()
subinmbed 2:c4fb968de7d3 699 {
subinmbed 2:c4fb968de7d3 700 char count;
subinmbed 2:c4fb968de7d3 701 char data[3];
subinmbed 2:c4fb968de7d3 702 char *data_pointer;
subinmbed 2:c4fb968de7d3 703
subinmbed 2:c4fb968de7d3 704 data_pointer = data;
subinmbed 2:c4fb968de7d3 705
subinmbed 2:c4fb968de7d3 706 //OBD_UART.baud(9600);
subinmbed 2:c4fb968de7d3 707 // OBD_UART.attach(&OBD_onDataRx);
subinmbed 2:c4fb968de7d3 708
subinmbed 2:c4fb968de7d3 709 DEBUG_UART.printf("Reception Started\r\n");
subinmbed 2:c4fb968de7d3 710
subinmbed 2:c4fb968de7d3 711 //--------------------------------------------------------------------------------------------------------------------------
subinmbed 2:c4fb968de7d3 712 //for(Misc_Count=0; Misc_Count < 5; Misc_Count++) {
subinmbed 2:c4fb968de7d3 713 // OBD_UART.putc(battery_voltage_cmd[Misc_Count]);
subinmbed 2:c4fb968de7d3 714 // }
subinmbed 2:c4fb968de7d3 715 OBD_UART.printf(obd_reset_cmd);
subinmbed 2:c4fb968de7d3 716
subinmbed 2:c4fb968de7d3 717 wait(1);
subinmbed 2:c4fb968de7d3 718
subinmbed 2:c4fb968de7d3 719 //~sbn~ while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 720 DEBUG_UART.printf("Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 721 received_data_verification(OBD_UART_RX_Buffer, obd_reset_cmd, (strlen(obd_reset_cmd)-1));
subinmbed 2:c4fb968de7d3 722
subinmbed 2:c4fb968de7d3 723 if(pass == 1)
subinmbed 2:c4fb968de7d3 724 DEBUG_UART.printf("\r\nOBD RESET SUCCESSFUL \r\n\r\n");
subinmbed 2:c4fb968de7d3 725 else
subinmbed 2:c4fb968de7d3 726 DEBUG_UART.printf("\r\nOBD RESET FAILED \r\n\r\n");
subinmbed 2:c4fb968de7d3 727 // fetch_battery_voltage();
subinmbed 2:c4fb968de7d3 728 reception_complete = 0; // Disabling the reception complete flag
subinmbed 2:c4fb968de7d3 729 OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception
subinmbed 2:c4fb968de7d3 730
subinmbed 2:c4fb968de7d3 731 //--------------------------------------------------------------------------------------------------------------------------
subinmbed 2:c4fb968de7d3 732
subinmbed 2:c4fb968de7d3 733 //OBD_UART.printf(allow_long_cmd);
subinmbed 2:c4fb968de7d3 734 for(count = 0; count < strlen(allow_long_cmd); count++)
subinmbed 2:c4fb968de7d3 735 OBD_UART.putc(allow_long_cmd[count]);
subinmbed 2:c4fb968de7d3 736 wait(1);
subinmbed 2:c4fb968de7d3 737 //~sbn~ while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled
subinmbed 2:c4fb968de7d3 738 DEBUG_UART.printf("Reception Complete\r\n");
subinmbed 2:c4fb968de7d3 739 received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(allow_long_cmd)-1));
subinmbed 2:c4fb968de7d3 740
subinmbed 2:c4fb968de7d3 741 if(pass == 1)
subinmbed 2:c4fb968de7d3 742 DEBUG_UART.printf("\r\nLONG DATA RECEPTION ENABLED SUCCESSFULLY \r\n\r\n");
subinmbed 2:c4fb968de7d3 743 else
subinmbed 2:c4fb968de7d3 744 DEBUG_UART.printf("\r\nLONG DATA RECEPTION ENABLING FAILED\r\n\r\n");
subinmbed 2:c4fb968de7d3 745 reception_complete = 0; // Disabling the reception complete flag
subinmbed 2:c4fb968de7d3 746 OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception
subinmbed 2:c4fb968de7d3 747
subinmbed 2:c4fb968de7d3 748 }
subinmbed 2:c4fb968de7d3 749 /*********************************************************************************************************************************************************************************/