kumar singh
/
Dealer_23Feb
Dummy Lora Packet Sending
Fork of Dealer_18feb17 by
Diff: main.cpp
- Revision:
- 17:758fb8454ab0
- Parent:
- 16:7703b9d92326
- Child:
- 19:886d50ecc718
--- a/main.cpp Fri Feb 17 08:30:35 2017 +0000 +++ b/main.cpp Sat Feb 18 08:36:54 2017 +0000 @@ -18,7 +18,7 @@ //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 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 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 @@ -60,6 +60,7 @@ #define Y_AXIS_OFFSET 0x7F #define Z_AXIS_OFFSET 0x05 +Serial pc(USBTX, USBRX); I2C i2c(PB_9, PB_8); InterruptIn activity(PB_0); @@ -126,31 +127,29 @@ void OBD_Plug_IN_Interrupt() { - if(OBD_PlugIN_State1!=OBD_PlugIN_Temp_State) - { + if(OBD_PlugIN_State1!=OBD_PlugIN_Temp_State) { OBD_PlugIN_State1=1; OBD_PlugIN_State=!OBD_PlugIN_State; OBD_PlugIN_Temp_State=OBD_PlugIN_State; OBD_PlugInOut_IOC_Status = TRUE; } } - + void OBD_Plug_OUT_Interrupt() { - if(OBD_PlugIN_State2!=OBD_PlugIN_Temp_State) - { + if(OBD_PlugIN_State2!=OBD_PlugIN_Temp_State) { OBD_PlugIN_State2=0; OBD_PlugIN_State=!OBD_PlugIN_State; OBD_PlugIN_Temp_State=OBD_PlugIN_State; OBD_PlugInOut_IOC_Status = TRUE; - } + } } //This function is Interrupt routine for detecting OBD Plugin and Out void Handle_CheckIn_Interrupt() { OBD_PlugInOut_IOC_Status = TRUE; - DEBUG_UART.printf("Movement_Detected"); + pc.printf("Movement_Detected"); } //Declare Ticker for sending lora packet @@ -172,7 +171,7 @@ while (LORA_UART.readable()) { // while there is data waiting LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos++] = LORA_UART.getc(); // put it in the buffer - //DEBUG_UART.putc(LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos-1]); + //pc.putc(LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos-1]); if(Lora_RxBuffer_End_Pos >= LORA_UART_RX_Size) { // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. // For now just throw everything away. @@ -188,7 +187,7 @@ while (Beacon_UART.readable()) { // while there is data waiting Beacon_RX_Buffer[Beacon_RxBuffer_End_Pos++] = Beacon_UART.getc(); // put it in the buffer - //DEBUG_UART.putc(LORA_UART_RX_Buffer[Beacon_RxBuffer_End_Pos-1]); + //pc1.putc(LORA_UART_RX_Buffer[Beacon_RxBuffer_End_Pos-1]); if(Beacon_RxBuffer_End_Pos >= 100) { // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. // For now just throw everything away. @@ -202,7 +201,7 @@ 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 - //DEBUG_UART.putc(BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos-1]); + //pc1.putc(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. @@ -213,12 +212,12 @@ int main() { - DEBUG_UART.baud(115200); + pc1.baud(115200); BLE_RECEIVER_UART.baud(115200); - DEBUG_UART.printf("%s","Debugging started"); + pc1.printf("%s","Debugging started"); BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq); LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq); - + //Create a thread to read vehicle data //Thread OBD_thread(OBD_Rcvd_Cmd_Processing_thread); @@ -243,7 +242,7 @@ uint8 Status_Packet_Wait_Count = 0; void Lora_Periodic_Packet_Sending() { - DEBUG_UART.printf("Periodic packet sending intiialized"); + pc1.printf("Periodic packet sending intiialized"); Set_Up_Lora_Network_Configuration(); Initialize_lora_Packets(); while (true) { @@ -253,36 +252,36 @@ if(Status_Packet_Wait_Count < 5) { Send_RSSI_Request_Command(GET_RSSI); Send_HeartBeat_Packet(); //call function to send heartbeat packet - DEBUG_UART.printf("Sent HeartBeat Packet"); + pc.printf("Sent HeartBeat Packet"); AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) Get_Lora_Response(); Send_Lora_Packet_Flag = FALSE; - DEBUG_UART.printf("Heartbeat Packet Response Received"); + pc1.printf("Heartbeat Packet Response Received"); } else { Send_RSSI_Request_Command(GET_RSSI); Status_Packet_Wait_Count = 0; Send_Vehicle_Status_Packet(); //call function to send heartbeat packet - DEBUG_UART.printf("Sent Status Packet"); + pc1.printf("Sent Status Packet"); AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) Get_Lora_Response(); Send_Lora_Packet_Flag = FALSE; - DEBUG_UART.printf("Status Packet Response Received"); + pc1.printf("Status Packet Response Received"); } } } else if(Packet_Type_To_Send == MOTION_TYPE_PACKET) { //check if packet to be sent is motion packet if(Send_Lora_Packet_Flag) { //Check if packet sending isd enabled, Packet should be sent only when enabled after timeout period Send_RSSI_Request_Command(GET_RSSI); Send_Motion_Packet(); - DEBUG_UART.printf("Sent Motion Packet"); //call function to send periodic motion packet + pc1.printf("Sent Motion Packet"); //call function to send periodic motion packet AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) Get_Lora_Response(); - DEBUG_UART.printf("Motion Packet Response Received"); + pc1.printf("Motion Packet Response Received"); Send_Lora_Packet_Flag = FALSE; if(Motion_Packet_Sent_Count >= 5) { //Stop Sending Motion Packets if after sending for 2 minute - DEBUG_UART.printf("Packet Type Sending Changed to HeartBeat"); + pc1.printf("Packet Type Sending Changed to HeartBeat"); Motion_Packet_Sent_Count = 0; Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //Set Packet type to send as heartbeat packet Lora_Packet_Sending_Ticker.detach(); //destroy ticker @@ -292,17 +291,17 @@ } } else if(Packet_Type_To_Send == CHECKIN_TYPE_PACKET) { //check if packet to be sent is Checkin packet if(Send_Lora_Packet_Flag) { //Check if packet sending isd enabled, Packet should be sent only when enabled after timeout period - DEBUG_UART.printf("Sent Beacon ID request"); + pc1.printf("Sent Beacon ID request"); Send_RSSI_Request_Command(GET_RSSI); Send_CheckIN_Packet(); //call function to send periodic checkIn packet - DEBUG_UART.printf("Sent Checkin Packet"); + pc1.printf("Sent Checkin Packet"); AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) Get_Lora_Response(); Send_Lora_Packet_Flag = FALSE; - DEBUG_UART.printf("Checkin Packet Response Received"); + pc1.printf("Checkin Packet Response Received"); if(CheckIN_Packet_Sent_Count >= 5) { //Stop Sending Motion Packets if after sending for 2 minute - DEBUG_UART.printf("Packet Type Sending Changed to HeartBeat"); + pc1.printf("Packet Type Sending Changed to HeartBeat"); CheckIN_Packet_Sent_Count = 0; Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //Set Packet type to send as heartbeat packet Initialize_Packets_Sent_Count(); @@ -385,13 +384,13 @@ Fixed_Beacon_Packet.Parking3_Beacon_Minor = 0x0001; Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0xB0; /* - while(true) + while(true) { - if(Temp_Pos < Lora_RxBuffer_End_Pos) + if(Temp_Pos < Lora_RxBuffer_End_Pos) { - if(BLE_Receiver_UART_RX_Buffer[Temp_Pos] == 0x0D) + if(BLE_Receiver_UART_RX_Buffer[Temp_Pos] == 0x0D) { - if(BLE_Receiver_UART_RX_Buffer[Temp_Pos+1] == 0x0A) + if(BLE_Receiver_UART_RX_Buffer[Temp_Pos+1] == 0x0A) { Temp_Pos = 2; for(i=0; i<6; i++)