Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 0:e36d80703ed0, committed 2017-02-27
- Comitter:
- bala0x07
- Date:
- Mon Feb 27 06:12:23 2017 +0000
- Child:
- 1:c23c05b36e33
- Commit message:
- Before Adding VIN & DTC
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accelerometer.cpp Mon Feb 27 06:12:23 2017 +0000 @@ -0,0 +1,325 @@ + +#include "mbed.h" +#include "obd_libraries.h" +#include "accelerometer.h" +#include "common_definitions.h" + +#define IDLE 0 +#define ACTIVE 1 + +I2C i2c(PB_9, PB_8); +Serial pc(USBTX, USBRX); + +InterruptIn double_tap(PC_1); // Pin assignment may vary +InterruptIn inactivity(PC_0); // Pin assignment may vary + +DigitalOut led(LED1); + +// INTERFACING ADXL345 ACCELEROMETER USING I2C + +/* + +NOTE : +Due to communication speed limitations, the maximum output +data rate when using 400 kHz I2C is 800 Hz and scales linearly with +a change in the I2C communication speed + +*/ + +//InterruptIn activity(PB_0); // Button B1 (Blue) + + + +const int slave_address_acc = 0xA6; +char axis_data[6] = {0,0,0,0,0,0}; +int16_t x_axis, y_axis, z_axis; +char interrupt_source[2]; +char axis_data_start_address[2]; +char intr_source_address[2] = {0x30, 0}; +char all_interrupt_clear_command[2] = {0x2E, 0x00}; +char all_interrupt_enable_command[2] = {0x2E, 0x18}; +char activity_interrupt_disable_command[2] = {0x2E, 0x28}; +char inactivity_interrupt_disable_command[2] = {0x2E, 0x30}; +char accelerometer_status_registered = 0; +unsigned int interrupt_source_duplicate; + +char previous_state = 0; +char current_state = 0; + +extern long vehicle_speed; +char current_speed, previous_speed; +char speed_threshold = 10; + +//---------------------------------------------------------------------------------------------------------- + +void char_to_int(char data_fetched) +{ + unsigned int shifter; + + interrupt_source_duplicate = 0x00; + + for(shifter = 0; shifter < 8; shifter++) + { + interrupt_source_duplicate |= (((data_fetched >> shifter) & 0x01) << shifter); // Converts char data into unsigned int + } +} + +//---------------------------------------------------------------------------------------------------------- + +void print_data_bits(char data_fetched) +{ + unsigned int shifter; + + for(shifter = 0; shifter < 8; shifter++) + { + pc.printf("%d",((data_fetched&0x80)>>7)); + data_fetched = data_fetched << 1; + } + pc.printf("\r\n\r\n"); +} + +//---------------------------------------------------------------------------------------------------------- + +/*---------------------------------------------------------------------------------------------------------- + + AS FAR NOW, ONE INTERRUPT PIN (INT1) OF ACCELEROMETER IS NOT WORKING + USE THIS TO CUSTOMIZE ACCELEROMETER WHEN THAT PIN IS WORKING + +void use_me_later() { + char count; + for(count = 0; count < 10; count++) + { + led = !led; + wait(0.10); + } +} +----------------------------------------------------------------------------------------------------------*/ + +void interrupt_sudden_jerk() +{ + char count; + + i2c.write(slave_address_acc, all_interrupt_clear_command, 2); + pc.printf("~~~ ENTERED SUDDEN JERK CONDITION ~~~\r\n\r\n"); + + for(count = 0; count < 2; count++) + { + led = 1; + wait(2); + led = 0; + wait(1); + } + + i2c.write(slave_address_acc, all_interrupt_enable_command, 2); + +} + +//********************************************************************************************************* + +// THE FOLLWOING CODE BLOCK IS THE MULITIPLEXED ISR FOR BOTH ACTIVITY & INACTIVITY INTERRUPT + +void interrupt_activity_inactivity() +{ + char count; + + // The following statement disables all interrupts since no other interrupts must disturb at this point + + i2c.write(slave_address_acc, all_interrupt_clear_command, 2); + + i2c.write(slave_address_acc, intr_source_address, 1); + i2c.read(slave_address_acc, interrupt_source, 1); + + char_to_int(interrupt_source[0]); // Coverts intr_source(char) to int & stores in intr_source_d + + pc.printf("INT Source = "); + print_data_bits((interrupt_source_duplicate)); + +//-------------------------------------------------------------------------------------------------------- + + /* VERIFY WHETHER THE INTERRUPT IS BECAUSE OF ACTIVITY */ + + //if((((int)intr_source) & 0x10) == 0x10) + if(interrupt_source_duplicate & 0x10) + { + /* THE FOLLOWING BLOCK IS USED JUST FOR VERIFICATION PURPOSE AND ARE NOT MANDATORY */ + + pc.printf("ENTERED ACTIVITY CONDITION\r\n\r\n"); + for(count = 0; count < 10; count++) + { + led = !led; + wait(0.05); + } +/* + fetch_vehicle_speed(); + previous_speed = vehicle_speed; + wait(5); + fetch_vehicle_speed(); + current_speed = vehicle_speed; + + //if((current_speed > previous_speed) && (current_speed > speed_threshold)) // Decision making regarding vehicle's current state + if(current_speed == 79) + { + i2c.write(slave_address_acc, activity_interrupt_disable_command, 2); // Disables Activity interrupt & enables Inactivity interrupt + pc.printf("\r\n>>> VEHICLE HAS STARTED FROM STOP <<<"); + } +*/ + } + +//-------------------------------------------------------------------------------------------------------- + + /* VERIFY WHETHER THE INTERRUPT IS BECAUSE OF INACTIVITY */ + + //if((((int)intr_source) & 0x08) == 0x08) // Verify whether it is inactivity interrupt + if(interrupt_source_duplicate & 0x08) + { + /* THE FOLLOWING BLOCK IS USED JUST FOR VERIFICATION PURPOSE AND ARE NOT MANDATORY */ + + pc.printf("ENTERED INACTIVITY CONDITION \r\n\r\n"); + for(count = 0; count < 10; count++) + { + led = !led; + wait(0.2); + } +/* + fetch_vehicle_speed(); + + if(vehicle_speed == 0) // Decision making regarding vehicle's current state + { + i2c.write(slave_address_acc, inactivity_interrupt_disable_command, 2); // Disables Inactivity interrupt & enables Activity interrupt + pc.printf("\r\n>>> VEHICLE HAS STOPPED FROM START <<<"); + } +*/ + } + +} + +//********************************************************************************************************* + +void initialize_accelerometer() +{ + inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge + double_tap.rise(interrupt_sudden_jerk); + pc.baud(38400); + + char cmd[2], cmd2[2], cmd3[5], cmd4[8], cmd5[3], cmd6[2], cmd7[2], cmd8[2]; + + + +/* THE FOLLOWING GROUP OF COMMAND VARIABLES STORES THE CONFIGURATION VALUES TO BE WRITTEN TO THE ADXL345 ACCELEROMETER */ + + cmd[0] = 0x2D; // Post the Register address of the slave (Have to write this into slave) + cmd[1] = 0x08; // Turn ON the Measure Bit + + cmd3[0] = 0x1D; // Threshold Tap Register address + cmd3[1] = 100; // Threshold tap Register value + cmd3[2] = 0x7F; // Offset - X axis + cmd3[3] = 0x7F; // Offset - Y axis + cmd3[4] = 0x05; // Offset - Z axis + + + cmd4[0] = 0x21; // DUR Register address + cmd4[1] = 0x15; // DUR Register value providing maximum time to be held to generate an interrupt + cmd4[2] = 0x15; // Latent + cmd4[3] = 0x45; // Window Time + cmd4[4] = 64; // THRES_ACT register value 62.5mg/LSB , therfore value 32 indicates 2g activity + cmd4[5] = 50; // THRES_INACT Register + cmd4[6] = 5; // TIME_INACT Register, making inactivity detection time = 5 secs + cmd4[7] = 0x77; // Activity, Inactivity detection enabled for all axis + + cmd5[0] = 0x2E; // INT Enable Register address + //cmd5[1] = 0x74; // INT Enable Register value enabling Single Tap, Double Tap, Activity and Free Fall detection + //cmd5[2] = 0x00; // INT Map Register value mapping Single Tap event to INT1 + //cmd5[1] = 0x20; // Enabling only the double tap interrupt + //cmd5[2] = 0x20; // Mapping the double tap interrupt to INT2 pin + //cmd5[1] = 0x10; // Enabling only the activity interrupt + //cmd5[2] = 0x10; // Mapping the sctivity interrupt to the INT2 pin + //cmd5[1] = 0x08; // Enabling only the inactivity interrupt + //cmd5[2] = 0x08; // Mapping the Inactivity interrupt to the INT2 pin + cmd5[1] = 0x38; // Enabling Activity & inactivity interrupt + cmd5[2] = 0xDF; // Activity--->INT1 & Inactivity--->INT2 + + + cmd6[0] = 0x2A; // Address of the TAP_AXES Register + cmd6[1] = 0x06; // X & Y axis participate in tap detection + + cmd7[0] = 0x28; // Address of the Threshold register for Free Fall detection + cmd7[1] = 0x07; // Recommeded value : 0x05 to 0x09 Refer datasheet + + cmd8[0] = 0x2C; // Address of the BW RATE register + cmd8[1] = 0x0D; // Increased the data rate to 800Hz, default is 0x0A indicating 100Hz + + cmd2[0] = 0x31; // Data format register address + cmd2[1] = 0x04; // Making the acceleration data as left justified + + axis_data_start_address[0] = 0x32; + + + + i2c.write(slave_address_acc, cmd, 2); + i2c.write(slave_address_acc, cmd3, 5); + i2c.write(slave_address_acc, cmd4, 8); + i2c.write(slave_address_acc, cmd5, 3); + i2c.write(slave_address_acc, cmd6, 2); + i2c.write(slave_address_acc, cmd7, 2); + i2c.write(slave_address_acc, cmd8, 2); + i2c.write(slave_address_acc, cmd2, 2); + + + //char dev_add[2] = {0x00,0}; + //i2c.write(slave_address_acc, dev_add, 1); + //i2c.read(slave_address_acc, dev_add, 1); + //print_data_bits(dev_add[0]); + + pc.printf(" ACCELEROMETER DATA LOG \r\n\r\n"); + + while (1); + + pc.printf("\r\n CAME HERE \r\n"); + + // pc.printf(" ACCELEROMETER DATA LOG \r\n\r\n"); + + // while (1) { +/*-------------------------------------------------------------------------------------------------------------------------------------- + wait(1.0); + pc.printf("STILL IN WHILE LOOP\r\n\r\n"); +--------------------------------------------------------------------------------------------------------------------------------------*/ + // wait(0.25); +//-------------------------------------------------------------------------------------------------------------------------------------- + + // USE THE FOLLOWING BLOCK TO READ THE DATA IN X-AXIS, Y-AXIS & Z-AXIS + /* + i2c.write(slave_address_acc, axis_data_start_address, 1); + i2c.read(slave_address_acc, axis_data, 6); + + x_axis = axis_data[1]; // Puts MSB data into respective axes + y_axis = axis_data[3]; + z_axis = axis_data[5]; + + if(x_axis & 0x80) // Testing the signess of the x-axis data + pc.printf("X-axis_1 = %d\r\n", (((~x_axis)+1))); // Converts 2's complement data into decimal + else + pc.printf("X-axis_0 = %d\r\n", x_axis); + + if(y_axis & 0x80) // Testing the signess of the y-axis data + pc.printf("Y-axis_1 = %d\r\n", (((~y_axis)+1))); // Converts 2's complement data into decimal + else + pc.printf("Y-axis_0 = %d\r\n", y_axis); + + if(z_axis & 0x80) // Testing the signess of the y-axis data + pc.printf("Z-axis_1 = %d\r\n\r\n", (((~z_axis)+1))); // Converts 2's complement data into decimal + else + pc.printf("Z-axis_0 = %d\r\n\r\n",z_axis); +*/ +/*-------------------------------------------------------------------------------------------------------------------------------------- + +// THIS CAN BE USED WHEN THERE IS A NEED OF VERY HIGH LEVEL ACCURACY & USE INT16_T DATA TYPE + + x_axis = (int)axis_data[1] << 8 | (int)axis_data[0]; + y_axis = (int)axis_data[3] << 8 | (int)axis_data[2]; + z_axis = (int)axis_data[5] << 8 | (int)axis_data[4]; + +--------------------------------------------------------------------------------------------------------------------------------------*/ + // } +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accelerometer.h Mon Feb 27 06:12:23 2017 +0000 @@ -0,0 +1,4 @@ + +void char_to_int(char data_fetched); +void print_data_bits(char data_fetched); +void initialize_accelerometer();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common_definitions.h Mon Feb 27 06:12:23 2017 +0000 @@ -0,0 +1,6 @@ + + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Feb 27 06:12:23 2017 +0000 @@ -0,0 +1,222 @@ + +/* **************************************************************************************************** + + OBD - ACCELEROMETER INTERFACE + +**************************************************************************************************** */ + +/* + +NOTE : +This program aims at interfacing both the OBD scan tool and ADXL345 Accelerometer +Testing the combined application of both in progress +Code is subjected to modification + +Date : 25 - Feb - 2017 (Saturday) +Author : BALA + +*/ + +#include "mbed.h" +#include "accelerometer.h" +#include "obd_libraries.h" +#include "common_definitions.h" + +//-------------------------------------------------------------------------------------------------------- + +//I2C i2cm(PB_9, PB_8); +Serial pcm(USBTX, USBRX); +Serial OBD_UARTm(PA_0, PA_1); + +//DigitalOut led(LED1); + +//InterruptIn double_tap(PC_1); // Pin assignment may vary +//InterruptIn activity_inactivity(PC_0); // Pin assignment may vary + +//-------------------------------------------------------------------------------------------------------- + +/* THE FOLLOWING DECLARATIONS ARE GLOBAL VARIABLES */ + +extern char current_speed, previous_speed; +//extern char speed_threshold = 10; + +extern float car_battery_voltage; +extern long vehicle_speed; + +extern char OBD_UART_RX_Buffer[50]; +char OBD_RxBuffer_End_Pos = 0; +char OBD_UART_RX_Size = 50; + +//extern const int slave_address_acc = 0xA6; +//extern char interrupt_source[2]; +//extern char intr_source_address[2] = {0x30, 0}; +//extern char all_interrupt_clear_command[2] = {0x2E, 0x00}; +//extern char all_interrupt_enable_command[2] = {0x2E, 0x18}; +//extern char activity_interrupt_disable_command[2] = {0x2E, 0x28}; +//extern char inactivity_interrupt_disable_command[2] = {0x2E, 0x30}; +//extern unsigned int interrupt_source_duplicate; + +extern char obd_reset_cmd[]; + +extern void OBD_onDataRx(); +extern void interrupt_sudden_jerk(); +extern void interrupt_activity_inactivity(); + + +//********************************************************************************************************* + + +/* THE FOLLOWING CODE BLOCK IS THE INTERRUPT SERVICE ROTUINE FOR OBD DATA RECEIVE */ + +//void OBD_onDataRx() +//{ +// pcm.printf("\r\n ENTERED \r\n"); +// if(OBD_UARTm.readable()) { +// +// pcm.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UARTm.getc()); +// /* +// if(OBD_RxBuffer_End_Pos >= OBD_UART_RX_Size) { +// // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. +// // For now just throw everything away. +// OBD_RxBuffer_End_Pos = 0; +// } +// */ +// } +//} + +//********************************************************************************************************* + + +/* THE FOLLOWING SET OF CODE BLOCKS ARE INTERRUPT SERVICE ROTUINES OF ACCELEROMETER */ + + +//********************************************************************************************************* + +// THE FOLLOWING CODE BLOCK IS THE ISR FOR SUDDEN JERK CONDITION + +//void interrupt_sudden_jerk() +//{ +// char count; +// +// i2cm.write(slave_address_acc, all_interrupt_clear_command, 2); +// pcm.printf("~~~ ENTERED SUDDEN JERK CONDITION ~~~\r\n\r\n"); +///* +// for(count = 0; count < 2; count++) +// { +// led = 1; +// wait(2); +// led = 0; +// wait(1); +// } +//*/ +// i2cm.write(slave_address_acc, all_interrupt_enable_command, 2); +// +//} + +//********************************************************************************************************* +// +//// THE FOLLWOING CODE BLOCK IS THE MULITIPLEXED ISR FOR BOTH ACTIVITY & INACTIVITY INTERRUPT +// +//void interrupt_activity_inactivity() +//{ +// char count; +// +// // The following statement disables all interrupts since no other interrupts must disturb at this point +// +// i2cm.write(slave_address_acc, all_interrupt_clear_command, 2); +// +// i2cm.write(slave_address_acc, intr_source_address, 1); +// i2cm.read(slave_address_acc, interrupt_source, 1); +// +// char_to_int(interrupt_source[0]); // Coverts intr_source(char) to int & stores in intr_source_d +// +// pcm.printf("INT Source = "); +// print_data_bits((interrupt_source_duplicate)); +// +////-------------------------------------------------------------------------------------------------------- +// +// /* VERIFY WHETHER THE INTERRUPT IS BECAUSE OF ACTIVITY */ +// +// //if((((int)intr_source) & 0x10) == 0x10) +// if(interrupt_source_duplicate & 0x10) +// { +// /* THE FOLLOWING BLOCK IS USED JUST FOR VERIFICATION PURPOSE AND ARE NOT MANDATORY */ +///* +// pcm.printf("ENTERED ACTIVITY CONDITION\r\n\r\n"); +// for(count = 0; count < 10; count++) +// { +// led = !led; +// wait(0.05); +// } +//*/ +// fetch_vehicle_speed(); +// previous_speed = vehicle_speed; +// wait(5); +// fetch_vehicle_speed(); +// current_speed = vehicle_speed; +// +// //if((current_speed > previous_speed) && (current_speed > speed_threshold)) // Decision making regarding vehicle's current state +// if(current_speed == 79) +// { +// i2cm.write(slave_address_acc, activity_interrupt_disable_command, 2); // Disables Activity interrupt & enables Inactivity interrupt +// pcm.printf("\r\n>>> VEHICLE HAS STARTED FROM STOP <<<"); +// } +// } +// +////-------------------------------------------------------------------------------------------------------- +// +// /* VERIFY WHETHER THE INTERRUPT IS BECAUSE OF INACTIVITY */ +// +// //if((((int)intr_source) & 0x08) == 0x08) // Verify whether it is inactivity interrupt +// if(interrupt_source_duplicate & 0x08) +// { +// /* THE FOLLOWING BLOCK IS USED JUST FOR VERIFICATION PURPOSE AND ARE NOT MANDATORY */ +///* +// pcm.printf("ENTERED INACTIVITY CONDITION \r\n\r\n"); +// for(count = 0; count < 10; count++) +// { +// led = !led; +// wait(0.2); +// } +//*/ +// fetch_vehicle_speed(); +// +// if(vehicle_speed == 0) // Decision making regarding vehicle's current state +// { +// i2cm.write(slave_address_acc, inactivity_interrupt_disable_command, 2); // Disables Inactivity interrupt & enables Activity interrupt +// pcm.printf("\r\n>>> VEHICLE HAS STOPPED FROM START <<<"); +// } +// } +//} + + +//********************************************************************************************************* + +int main(void) +{ + //OBD_UARTm.attach(&OBD_onDataRx); + //activity_inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge + //double_tap.rise(interrupt_sudden_jerk); + + pcm.baud(38400); + OBD_UARTm.baud(38400); + + + pcm.printf("\r\n\r\n\t\t>>>>>------>> OBD - ACCELEROMETER INTERFACE <<------<<<<<\r\n\r\n"); + + initialize_obd(); // OBD- scan tool initialization would be done here + + fetch_battery_voltage(); // OBD - section + + fetch_vehicle_speed(); + + //initialize_accelerometer(); // All Accerometer configurations will be done here + + //while(1); // Wait forever, let the ISR do the rest + + + return 0; + +} + +//********************************************************************************************************* \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Feb 27 06:12:23 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/obd_libraries.cpp Mon Feb 27 06:12:23 2017 +0000 @@ -0,0 +1,259 @@ +#include "mbed.h" +#include "obd_libraries.h" +#include "common_definitions.h" + +Serial pco(USBTX, USBRX); +Serial OBD_UART(PA_0, PA_1); + +char pass = 0; +char reception_complete = 0; + +char obd_reset_cmd[] = "ATZ\r"; +char battery_voltage_cmd[] = "ATRV\r"; +char protocol_auto_detect_cmd[] = "ATSP0\r"; +char read_CAN_protocol_cmd[] = "ATDPN\r"; +char allow_long_cmd[] = "ATAL\r"; +char engine_rpm_cmd[] = "010C\r"; +char vehicle_speed_cmd[] = "010D\r"; +char vin_number_cmd[] = "0902 5\r"; + +float car_battery_voltage; +long vehicle_speed; +char OBD_UART_RX_Buffer[50]; +extern char OBD_RxBuffer_End_Pos; +//char OBD_UART_RX_Size = 50; + + +//Serial pco(USBTX, USBRX); +//Serial OBD_UART(PA_0, PA_1); + +void OBD_onDataRx() +{ + //pcm.printf("\r\n ENTERED \r\n"); + if(OBD_UART.readable()) { + + pco.putc(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos++] = OBD_UART.getc()); + /* + if(OBD_RxBuffer_End_Pos >= OBD_UART_RX_Size) { + // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. + // For now just throw everything away. + OBD_RxBuffer_End_Pos = 0; + } + */ + } +} + + +//************************************************************************************************************************ + +void received_data_verification(char *rcv_data_pointer, char *ref_data_pointer, char num) +{ + char dummy_data[num], count; + for(count = 0; count < num; count++) + { + pco.putc(*rcv_data_pointer); + if(*rcv_data_pointer++ == *ref_data_pointer++) + pass = 1; + else + { + pass = 0; + return; + } + } +} + +//************************************************************************************************************************ +/* +char* copy_characters(char *copy_char_pointer, char start_position, char end_position) +{ + char total_num; + char count; + total_num = end_position - start_position; + char copied_data[total_num]; + copy_char_pointer += start_position; + + for(count = 0; count < total_num; count++) + { + copied_data[count] = *copy_char_pointer++; + } + + pco.printf("\r\n%s", copied_data); + + copy_char_pointer = copied_data; // Shifting the pointer to copied_data array + + return copy_char_pointer; +} +*/ + + +//************************************************************************************************************************ + +void process_battery_voltage(char *battery_voltage_pointer) +{ + char battery_voltage_data[4]; // One decimal point precision ( For ex : 12.5 ) + char count; + battery_voltage_pointer += 5; // ATRV<CR> counts to 5 + for(count = 0; count < 4; count++) + { + battery_voltage_data[count] = *battery_voltage_pointer++; + } + car_battery_voltage = atof(battery_voltage_data); // Converts the Battery Volatge from String to Float data type + + printf("\r\nCAR BATTERY VOLTAGE = %f",car_battery_voltage); +} + +//************************************************************************************************************************ + +void process_vehicle_speed(char *vehicle_speed_pointer) +{ + char vehicle_speed_data[2]; // Vehicle speed data is returned by a 2 byte value + char *strtol_pointer; + char count; + //"010D\r41 0D 4F\r\r>" + vehicle_speed_pointer += 11; + for(count = 0; count < 2; count++) + { + vehicle_speed_data[count] = *vehicle_speed_pointer++; + } + + vehicle_speed = strtol(vehicle_speed_data, &strtol_pointer, 16); + + printf("\r\nVEHICLE SPEED = %ld\r\n", vehicle_speed); +} + +//************************************************************************************************************************ + + +void fetch_battery_voltage() +{ + OBD_UART.printf(battery_voltage_cmd); + wait(1); + while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled + pco.printf("Reception Complete\r\n"); + received_data_verification(OBD_UART_RX_Buffer, battery_voltage_cmd, (strlen(battery_voltage_cmd)-1)); + + process_battery_voltage(OBD_UART_RX_Buffer); + + if(pass == 1) + printf("\r\nOBD READ BATTERY VOLTAGE SUCCESSFUL \r\n\r\n"); + else + printf("\r\nOBD READ BATTERY VOLTAGE FAILED \r\n\r\n"); + reception_complete = 0; // Disabling the reception complete flag + OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception +} + +//************************************************************************************************************************ + +void fetch_vehicle_speed() +{ + char virtual_rx_speed_buffer[] = "010D\r41 0D 4F\r\r>"; + /* + OBD_UART.printf(vehicle_speed_cmd); + wait(1); + while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled + pco.printf("Reception Complete\r\n"); + received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(vehicle_speed_cmd)-1)); + */ + process_vehicle_speed(virtual_rx_speed_buffer); + + if(pass == 1) + printf("\r\VEHICLE SPEED DATA RECEIVED SUCCESSFULLY \r\n\r\n"); + else + printf("\r\nVEHICLE SPEED DATA RECEPTION FAILED\r\n\r\n"); + reception_complete = 0; // Disabling the reception complete flag + OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception + +} + +//************************************************************************************************************************ +/* +void fetch_vin_number() +{ + 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>"; + */ + + /* + Chassis Number : TMBFKJ5J2CG014733 + + [TX] - 0902 5<CR> + + [RX] - 0902 5<CR> + 014 <CR> + 0: 49 02 01 54 4D 42 <CR> + 1: 46 4B 4A 35 4A 32 43 <CR> + 2: 47 30 31 34 37 33 33 <CR> + <CR> + > + */ + /* + OBD_UART.printf(vin_number_cmd); + wait(1); + while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled + pco.printf("Reception Complete\r\n"); + received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(vin_number_cmd)-1)); + */ + +//************************************************************************************************************************ +/* +void check_for_dtc() +{ +*/ + +//************************************************************************************************************************ + +void initialize_obd() +{ + char data[3]; + char *data_pointer; + + data_pointer = data; + + pco.baud(38400); + OBD_UART.baud(38400); + + OBD_UART.attach(&OBD_onDataRx); + + OBD_UART.printf("%s",obd_reset_cmd); + + wait(1); + + /* + pco.printf("Reception not completed"); + pco.printf("\r\n%d",OBD_RxBuffer_End_Pos); + pco.printf("\r\n%c",OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1]); + */ + + while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled + pco.printf("Reception Complete\r\n"); + received_data_verification(OBD_UART_RX_Buffer, obd_reset_cmd, (strlen(obd_reset_cmd)-1)); + + if(pass == 1) + printf("\r\nOBD RESET SUCCESSFUL \r\n\r\n"); + else + printf("\r\nOBD RESET FAILED \r\n\r\n"); + + reception_complete = 0; // Disabling the reception complete flag + OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception + +//-------------------------------------------------------------------------------------------------------------------------- + + OBD_UART.printf(allow_long_cmd); + wait(1); + while(!(OBD_UART_RX_Buffer[OBD_RxBuffer_End_Pos-1] == '>')); // Waits here until the reception complete flag has been enabled + pco.printf("Reception Complete\r\n"); + received_data_verification(OBD_UART_RX_Buffer, allow_long_cmd, (strlen(allow_long_cmd)-1)); + + if(pass == 1) + printf("\r\nLONG DATA RECEPTION ENABLED SUCCESSFULLY \r\n\r\n"); + else + printf("\r\nLONG DATA RECEPTION ENABLING FAILED\r\n\r\n"); + reception_complete = 0; // Disabling the reception complete flag + OBD_RxBuffer_End_Pos = 0; // Rx Buffer will be overwritten in the next data reception + +} + +//************************************************************************************************************************ + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/obd_libraries.h Mon Feb 27 06:12:23 2017 +0000 @@ -0,0 +1,15 @@ + +void received_data_verification(char*, char*, char); +//char* copy_characters(char *copy_char_pointer, char start_position, char end_position); +void process_battery_voltage(char *battery_voltage_pointer); +void process_vehicle_speed(char *vehicle_speed_pointer); +void fetch_battery_voltage(void); +void fetch_vehicle_speed(void); +void fetch_vin_number(void); +void check_for_dtc(void); +void initialize_obd(void); + + + + +