kumar singh
/
Dealer_20Mar
BLE Transmitter not working
Fork of Dealer_23Feb by
Diff: main.cpp
- Revision:
- 25:0ac2680d594c
- Parent:
- 24:1063cfc311e5
--- a/main.cpp Thu Feb 23 13:21:08 2017 +0000 +++ b/main.cpp Fri Mar 03 08:48:39 2017 +0000 @@ -5,6 +5,7 @@ #include "Accelerometer.h" #include "Beacon.h" #include "main.h" +#include "OBD_Libraries.h" //Datatype typecasting typedef unsigned char uint8; @@ -19,12 +20,12 @@ //Configure Serial port RawSerial LORA_UART(PA_0, PA_1);//USART4_TX->PA_0,USART4_RX->PA_1 : Used for Lora module command sending and reception from gateway -//RawSerial pc1(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only -//RawSerial DEBUG_UART(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only +RawSerial pc1(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only +RawSerial DEBUG_UART(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only RawSerial Beacon_UART(PC_4, PC_5);//USART3_TX->PC4,USART3_RX->PC_5 : Used for sending command to beacon module RawSerial BLE_RECEIVER_UART(PA_9, PA_10);//USART1_TX->PA_0,USART1_RX->PA_1 : Used for Lora module command sending and reception from gateway -Serial pc1(USBTX, USBRX); -RawSerial DEBUG_UART(USBTX, USBRX);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only +//Serial pc1(USBTX, USBRX); +//RawSerial DEBUG_UART(USBTX, USBRX);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only //InterruptIn OBD_PLUGIN_INTERRUPT_PIN(PC_13); InterruptIn CheckIn_Interrupt(PB_7);//(PC_13); @@ -98,7 +99,7 @@ char measure_bit_on_command[2]; -unsigned char vehicle_speed = 25; // Kmph +unsigned char vehicle_speed1 = 25; // Kmph unsigned char current_speed, previous_speed, speed_threshold = 10; // Kmph unsigned char x_axis, y_axis, z_axis; @@ -232,8 +233,8 @@ { while (BLE_RECEIVER_UART.readable()) { // while there is data waiting - //BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos++] = BLE_RECEIVER_UART.getc(); // put it in the buffer - //pc1.putc(BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos-1]); + BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos++] = BLE_RECEIVER_UART.getc(); // put it in the buffer + //pc1.printf("%2x",BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos-1]); if(BLE_RxBuffer_End_Pos >= BLE_RECEIVER_UART_RX_Size) { // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. // For now just throw everything away. @@ -244,19 +245,16 @@ int main() { - pc1.baud(115200); + pc1.baud(115200); BLE_RECEIVER_UART.baud(115200); pc1.printf("%s","Debugging started\n"); - //BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq); + BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq); LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq); - CheckIn_Interrupt.fall(&OBD_Plug_IN_Interrupt); - CheckIn_Interrupt.rise(&OBD_Plug_OUT_Interrupt); - if(Switch2) - { - } - Motion_Start_To_Stop.fall(&Start_To_Stop_Interrupt); - Motion_Stop_To_Start.fall(&Stop_To_Start_Interrupt); - Motion_Sudden_Jerk.fall(&Sudden_Jerk_Interrupt); + //CheckIn_Interrupt.fall(&OBD_Plug_IN_Interrupt); + //CheckIn_Interrupt.rise(&OBD_Plug_OUT_Interrupt); + //Motion_Start_To_Stop.fall(&Start_To_Stop_Interrupt); + //Motion_Stop_To_Start.fall(&Stop_To_Start_Interrupt); + //Motion_Sudden_Jerk.fall(&Sudden_Jerk_Interrupt); //Create a thread to read vehicle data //Thread OBD_thread(OBD_Rcvd_Cmd_Processing_thread); @@ -266,8 +264,9 @@ //led2_thread is executing concurrently with main at this point //inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge Initialize_Beacon_Module(); - // Send_Command_To_BLE_Receiver(SET_BEACON_VENDOR_ID); - // Send_Command_To_BLE_Receiver(SET_BEACON_MESSAGE_TYPE); + Send_Command_To_BLE_Receiver(SET_BEACON_VENDOR_ID); + Send_Command_To_BLE_Receiver(SET_BEACON_MESSAGE_TYPE); + //initialize_obd(); pc1.printf("\n%s","Transmitter MAC ID received\n"); Lora_Periodic_Packet_Sending(); //Infinite loop for sending and receiving lora response, no return from here } @@ -298,11 +297,12 @@ pc1.printf("\nStatus_Packet_Wait_Count %d\n",Status_Packet_Wait_Count); Status_Packet_Wait_Count++; if(Status_Packet_Wait_Count < 4) { - // Send_Command_To_BLE_Receiver(GET_RSSI); - //Send_RSSI_Request_Command(GET_RSSI); + Send_Command_To_BLE_Receiver(GET_RSSI); + Send_RSSI_Request_Command(GET_RSSI); pc1.printf("\nSending heartbeat packet\n"); //call function to send periodic motion packet Send_HeartBeat_Packet(); //call function to send heartbeat packet pc.printf("\nSent HeartBeat Packet\n"); + Process_Beacon_Command_Received(SET_UUID); /*AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) Get_Lora_Response(); @@ -480,26 +480,29 @@ for(i=0; i<6; i++) { Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; - pc1.putc(Fixed_Beacon_Packet.Parking1_Beacon_ID[i]); + pc1.printf("%2x",Fixed_Beacon_Packet.Parking1_Beacon_ID[i]); } Temp_Pos+=2; Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + pc1.printf("%2x",Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength); //pc1.printf("\nFixed Beacon2 MAC ID\n"); for(i=0; i<6; i++) { Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; - pc1.putc(Fixed_Beacon_Packet.Parking2_Beacon_ID[i]); + pc1.printf("%2x",Fixed_Beacon_Packet.Parking2_Beacon_ID[i]); } Temp_Pos+=2; Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + pc1.printf("%2x",Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength); //pc1.printf("\nFixed Beacon3 MAC ID\n"); for(i=0; i<6; i++) { Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; - pc1.putc(Fixed_Beacon_Packet.Parking3_Beacon_ID[i]); + pc1.printf("%2x",Fixed_Beacon_Packet.Parking3_Beacon_ID[i]); } Temp_Pos+=2; Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + pc1.printf("%2x",Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength); BLE_RxBuffer_End_Pos = 0x00; //Start Next adat at 0th location break; }