BLE Transmitter not working

Fork of Dealer_23Feb by kumar singh

Revision:
19:886d50ecc718
Parent:
17:758fb8454ab0
Child:
20:f812f85cf97e
diff -r 86f069689502 -r 886d50ecc718 main.cpp
--- a/main.cpp	Sat Feb 18 08:52:04 2017 +0000
+++ b/main.cpp	Tue Feb 21 06:27:13 2017 +0000
@@ -19,6 +19,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 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
 
@@ -171,7 +172,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
-        //pc.putc(LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos-1]);
+        pc1.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.
@@ -180,7 +181,6 @@
     }
 }
 
-
 // called every time a byte is received from Beacon Module.
 void Beacon_onDataRx()
 {
@@ -228,7 +228,7 @@
     CheckIn_Interrupt.fall(&OBD_Plug_IN_Interrupt);
     CheckIn_Interrupt.rise(&OBD_Plug_OUT_Interrupt);
     inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge
-    //Initialize_Beacon_Module();
+    Initialize_Beacon_Module();
     Lora_Periodic_Packet_Sending(); //Infinite loop for sending and receiving lora response, no return from here
 }
 
@@ -245,6 +245,7 @@
     pc1.printf("Periodic packet sending intiialized");
     Set_Up_Lora_Network_Configuration();
     Initialize_lora_Packets();
+    Send_Lora_Packet_Flag = TRUE;
     while (true) {
         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
@@ -262,10 +263,10 @@
                     Send_RSSI_Request_Command(GET_RSSI);
                     Status_Packet_Wait_Count = 0;
                     Send_Vehicle_Status_Packet();                            //call function to send heartbeat packet
-                    pc1.printf("Sent Status Packet");
-                    AT_Response_Receive_Status = FAILURE;
-                    while(AT_Response_Receive_Status)
-                        Get_Lora_Response();
+                    //pc1.printf("Sent Status Packet");
+                    //AT_Response_Receive_Status = FAILURE;
+                    //while(AT_Response_Receive_Status)
+                    //    Get_Lora_Response();
                     Send_Lora_Packet_Flag = FALSE;
                     pc1.printf("Status Packet Response Received");
                 }
@@ -286,19 +287,27 @@
                     Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET;    //Set Packet type to send as heartbeat packet
                     Lora_Packet_Sending_Ticker.detach();          //destroy ticker
                     Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 10.0); //create new ticker
-
                 }
             }
         } 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");
                 Send_RSSI_Request_Command(GET_RSSI);
-                Send_CheckIN_Packet();                              //call function to send periodic checkIn packet
-                pc1.printf("Sent Checkin Packet");
+                if(OBD_PlugIN_State)
+                {
+                    Send_CheckIN_Packet();                              //call function to send periodic checkIn packet
+                    pc1.printf("Sent Checkin Packet");
+                }
+                else
+                {
+                    Send_CheckOUT_Packet();
+                    pc1.printf("Sent CheckOut Packet");
+                }
+                __enable_irq();     // Enable Interrupts
                 AT_Response_Receive_Status = FAILURE;
                 while(AT_Response_Receive_Status)
                     Get_Lora_Response();
-                Send_Lora_Packet_Flag = FALSE;
                 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");
@@ -309,11 +318,13 @@
             }
         }
         if(OBD_PlugInOut_IOC_Status) {  //Check if Accelerometer Interrupt is generated
+            __disable_irq();    // Disable Interrupts
             //Enable_CheckIN_Packet_Sending();
             //Get_Acceleration_Type();
             OBD_PlugInOut_IOC_Status = FALSE;
             Packet_Type_To_Send = CHECKIN_TYPE_PACKET;
             Send_Lora_Packet_Flag = TRUE;
+            CheckIN_Packet_Sent_Count = 0;
             wait(1); //wait for 1sec to avoid detecting plugin debounce
         }
         if(Motion_Detect_Status) {  //Check if Accelerometer Interrupt is generated
@@ -332,6 +343,7 @@
     Motion_Lora_Packet.Acceleration_Type = Motion_Type_Detected;             //Read Type of motion deteceted
     //write code to read acceleration value for every 10sec after any of the acceleration is found
 }
+
 /*
 //This function is used to enable checkin packet sending once OBD device is plugged in
 void Enable_CheckIN_Packet_Sending()
@@ -359,13 +371,12 @@
 {
     uint8 i;
     uint8 Temp_Pos=0;
-    Fixed_Beacon_Packet.Parking1_Beacon_ID[0] = 0xA0;
+    /*Fixed_Beacon_Packet.Parking1_Beacon_ID[0] = 0xA0;
     Fixed_Beacon_Packet.Parking1_Beacon_ID[1] = 0xAC;
     Fixed_Beacon_Packet.Parking1_Beacon_ID[2] = 0x51;
     Fixed_Beacon_Packet.Parking1_Beacon_ID[3] = 0x3F;
     Fixed_Beacon_Packet.Parking1_Beacon_ID[4] = 0x91;
     Fixed_Beacon_Packet.Parking1_Beacon_ID[5] = 0xE0;
-    Fixed_Beacon_Packet.Parking1_Beacon_Minor = 0x0002;
     Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0xC3;
     Fixed_Beacon_Packet.Parking2_Beacon_ID[0] = 0xDC;
     Fixed_Beacon_Packet.Parking2_Beacon_ID[1] = 0xA3;
@@ -373,7 +384,6 @@
     Fixed_Beacon_Packet.Parking2_Beacon_ID[3] = 0x30;
     Fixed_Beacon_Packet.Parking2_Beacon_ID[4] = 0x38;
     Fixed_Beacon_Packet.Parking2_Beacon_ID[5] = 0xDF;
-    Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0004;
     Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0xB4;
     Fixed_Beacon_Packet.Parking3_Beacon_ID[0] = 0x6C;
     Fixed_Beacon_Packet.Parking3_Beacon_ID[1] = 0x29;
@@ -381,9 +391,8 @@
     Fixed_Beacon_Packet.Parking3_Beacon_ID[3] = 0x27;
     Fixed_Beacon_Packet.Parking3_Beacon_ID[4] = 0x3A;
     Fixed_Beacon_Packet.Parking3_Beacon_ID[5] = 0xC9;
-    Fixed_Beacon_Packet.Parking3_Beacon_Minor = 0x0001;
     Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0xB0;
-    /*
+    */
     while(true)
     {
         if(Temp_Pos < Lora_RxBuffer_End_Pos)
@@ -395,15 +404,15 @@
                     Temp_Pos = 2;
                     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_Minor = ((BLE_Receiver_UART_RX_Buffer[Temp_Pos++]<<8)|(BLE_Receiver_UART_RX_Buffer[Temp_Pos++]));
+                    Temp_Pos+=2;
                     Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
                     for(i=0; i<6; i++)
                         Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
-                    Fixed_Beacon_Packet.Parking2_Beacon_Minor = ((BLE_Receiver_UART_RX_Buffer[Temp_Pos++]<<8)|(BLE_Receiver_UART_RX_Buffer[Temp_Pos++]));
+                    Temp_Pos+=2;
                     Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
                     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_Minor = ((BLE_Receiver_UART_RX_Buffer[Temp_Pos++]<<8)|(BLE_Receiver_UART_RX_Buffer[Temp_Pos++]));
+                    Temp_Pos+=2;
                     Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
                     break;
                 }
@@ -414,5 +423,5 @@
         }
         else
             Temp_Pos = 0x00;
-    }*/
+    }
 }