kumar singh
/
Dealer_23Feb
Dummy Lora Packet Sending
Fork of Dealer_18feb17 by
Diff: main.cpp
- Revision:
- 21:a5fb0ae94dc6
- Parent:
- 20:f812f85cf97e
- Child:
- 22:c2f034a13108
diff -r f812f85cf97e -r a5fb0ae94dc6 main.cpp --- a/main.cpp Tue Feb 21 13:33:29 2017 +0000 +++ b/main.cpp Wed Feb 22 14:59:59 2017 +0000 @@ -24,11 +24,10 @@ 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 //InterruptIn OBD_PLUGIN_INTERRUPT_PIN(PC_13); -InterruptIn CheckIn_Interrupt(PC_13); +InterruptIn CheckIn_Interrupt(PB_7);//(PC_13); uint8 Ticker_Count = 0; //Variable to count for timer overflows - uint8 OBD_Plugin_Detected = FALSE; //Create Object for structure of Lora Packet to be sent @@ -187,7 +186,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 - //pc1.putc(LORA_UART_RX_Buffer[Beacon_RxBuffer_End_Pos-1]); + //pc1.putc(Beacon_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. @@ -201,7 +200,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 - //pc1.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. @@ -251,22 +250,24 @@ if(Packet_Type_To_Send == HEARTBEAT_TYPE_PACKET) { //check if packet to be sent is Heartbeat packet if(Send_Lora_Packet_Flag) { //Check if packet sending is enabled, Packet should be sent only when enabled after timeout period Status_Packet_Wait_Count++; - if(Status_Packet_Wait_Count <= 3) { - //Send_RSSI_Request_Command(GET_RSSI); + if(Status_Packet_Wait_Count < 4) { + Send_RSSI_Request_Command(GET_RSSI); + pc1.printf("Sending heartbeat packet"); //call function to send periodic motion packet Send_HeartBeat_Packet(); //call function to send 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; - pc1.printf("Heartbeat Packet Response Received"); - } else { + //pc1.printf("Heartbeat Packet Response Received"); + } else if(Status_Packet_Wait_Count >= 6){ //Send_RSSI_Request_Command(GET_RSSI); Status_Packet_Wait_Count = 0; + pc1.printf("Sending Vehicle status packets"); //call function to send periodic motion packet Send_Vehicle_Status_Packet(); //call function to send heartbeat packet - pc1.printf("Sent Status Packet"); + pc1.printf("Sent Vehicle Status Packet"); //AT_Response_Receive_Status = FAILURE; - //while(AT_Response_Receive_Status) + // while(AT_Response_Receive_Status) // Get_Lora_Response(); Send_Lora_Packet_Flag = FALSE; //pc1.printf("Status Packet Response Received"); @@ -274,7 +275,8 @@ } } 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_RSSI_Request_Command(GET_RSSI); + pc1.printf("Sending Motion Packet"); //call function to send periodic motion packet Send_Motion_Packet(); pc1.printf("Sent Motion Packet"); //call function to send periodic motion packet AT_Response_Receive_Status = FAILURE; @@ -293,23 +295,27 @@ } 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 Send_Lora_Packet_Flag = FALSE; - pc1.printf("Sent Beacon ID request"); + //pc1.printf("Sent Beacon ID request"); // Send_RSSI_Request_Command(GET_RSSI); if(OBD_PlugIN_State) { + pc1.printf("Sening Checkin Packet"); Send_CheckIN_Packet(); //call function to send periodic checkIn packet pc1.printf("Sent Checkin Packet"); + Process_Beacon_Command_Received(SET_VIRTUAL_PACKET_UUID); + Process_Beacon_Command_Received(SOFT_REBOOT1); } else { + pc1.printf("Sending Checkout Packet"); Send_CheckOUT_Packet(); pc1.printf("Sent CheckOut Packet"); + Process_Beacon_Command_Received(SET_VIRTUAL_PACKET_UUID2); + Process_Beacon_Command_Received(SOFT_REBOOT1); } - //__enable_irq(); // Enable Interrupts AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) Get_Lora_Response(); - pc1.printf("Checkin Packet Response Received"); if(CheckIN_Packet_Sent_Count >= 5) { //Stop Sending Motion Packets if after sending for 2 minute pc1.printf("Packet Type Sending Changed to HeartBeat"); CheckIN_Packet_Sent_Count = 0; @@ -319,18 +325,20 @@ } } if(OBD_PlugInOut_IOC_Status) { //Check if Accelerometer Interrupt is generated - //__disable_irq(); // Disable Interrupts //Enable_CheckIN_Packet_Sending(); //Get_Acceleration_Type(); - Process_Beacon_Command_Received(SET_VIRTUAL_PACKET_UUID); - Process_Beacon_Command_Received(SOFT_REBOOT); + // Process_Beacon_Command_Received(SET_VIRTUAL_PACKET_UUID); + // Process_Beacon_Command_Received(SOFT_REBOOT1); OBD_PlugInOut_IOC_Status = FALSE; Packet_Type_To_Send = CHECKIN_TYPE_PACKET; Send_Lora_Packet_Flag = TRUE; CheckIN_Packet_Sent_Count = 0; + CheckIN_Lora_Packet.Sequence_No = 0x00; //Reset counter + CheckOUT_Packet.Sequence_No = 0x00; //Reset counter wait(1); //wait for 1sec to avoid detecting plugin debounce } if(Motion_Detect_Status) { //Check if Accelerometer Interrupt is generated + Motion_Lora_Packet.Sequence_No = 0x00; //Reset counter Get_Acceleration_Type(); Motion_Detect_Status = FALSE; } @@ -396,27 +404,42 @@ Fixed_Beacon_Packet.Parking3_Beacon_ID[5] = 0xC9; Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0xB0; */ + pc1.printf("Reading MACID from Receiver"); while(true) { - if(Temp_Pos < Lora_RxBuffer_End_Pos) + wait_ms(2); + if(Temp_Pos <= BLE_RxBuffer_End_Pos) { if(BLE_Receiver_UART_RX_Buffer[Temp_Pos] == 0x0D) { if(BLE_Receiver_UART_RX_Buffer[Temp_Pos+1] == 0x0A) { Temp_Pos = 2; + //pc1.printf("Fixed Beacon1 MAC ID"); for(i=0; i<6; i++) - Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + { + Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + pc1.putc(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("Fixed Beacon2 MAC ID"); 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]); + } Temp_Pos+=2; Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + //pc1.printf("Fixed Beacon3 MAC ID"); for(i=0; i<6; i++) - Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + { + Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + pc1.putc(Fixed_Beacon_Packet.Parking3_Beacon_ID[i]); + } Temp_Pos+=2; Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; + BLE_RxBuffer_End_Pos = 0x00; //Start Next adat at 0th location break; } Temp_Pos++; @@ -427,4 +450,5 @@ else Temp_Pos = 0x00; } + pc1.printf("Reading MACID finished"); }