BLE Transmitter not working

Fork of Dealer_23Feb by kumar singh

Files at this revision

API Documentation at this revision

Comitter:
NarendraSingh
Date:
Mon Mar 20 02:44:45 2017 +0000
Parent:
24:1063cfc311e5
Commit message:
Before troubleshooting BLE Transmitter

Changed in this revision

Lora.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Lora.cpp	Thu Feb 23 13:21:08 2017 +0000
+++ b/Lora.cpp	Mon Mar 20 02:44:45 2017 +0000
@@ -240,6 +240,7 @@
     else
         Heart_Beat_Lora_Packet.Sequence_No = 0x01;
     pc2.printf("\nHeartbeat Packet Sequence Number %d",Heart_Beat_Lora_Packet.Sequence_No);
+    pc_2.printf("\nHeartbeat Packet Sequence Number %d",Heart_Beat_Lora_Packet.Sequence_No);
 }
 
 //CheckIN packets sending should be started when device is plugged in to the vehicle. It should be sent every 5sec for 2minutes and afterthat it should stop sending
@@ -321,6 +322,7 @@
         Vehicle_Status_Lora_Packet.Sequence_No = 0x01;
         pc2.printf("\nStatus Packet sending");
      pc2.printf("\nStatus Packet Sequence Number %d",Vehicle_Status_Lora_Packet.Sequence_No);
+     pc_2.printf("\nStatus Packet Sequence Number %d",Vehicle_Status_Lora_Packet.Sequence_No);
 }
 
 //CheckIN packets sending should be started when device is plugged in to the vehicle. It should be sent every 5sec for 2minutes and afterthat it should stop sending
--- a/main.cpp	Thu Feb 23 13:21:08 2017 +0000
+++ b/main.cpp	Mon Mar 20 02:44:45 2017 +0000
@@ -13,10 +13,14 @@
 uint8 OBD_Plug_In_Status = FALSE;
 
 //peripheral connection
-DigitalOut led1(PB_11);
-DigitalOut led2(LED2);
+//DigitalOut led1(PB_11);
+//DigitalOut led2(LED2);
 DigitalIn Switch2(PB_13);
 
+DigitalOut led1(LED1);
+DigitalOut led2(PA_11);
+DigitalOut led3(PA_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
@@ -242,11 +246,150 @@
     }
 }
 
+#define LORA_SEND_THREAD "lora_send_thread"
+#define HEART_BEAT_PACKET_SENDING   0x01
+#define STATUS_PACKET_SENDING       0x02
+
+InterruptIn checkinIntr(PC_13);
+InterruptIn motionIntr(PB_14);
+InterruptIn testIntr(PB_5);
+
+
+
+/* reserve the debbuger uart to shell interface */
+Serial pc_serial(USBTX,USBRX);
+
+/* declares threads for this demo: */
+const size_t a_stk_size = 512;
+uint8_t a_stk[a_stk_size];
+Thread loraSendThread(osPriorityNormal, a_stk_size, &a_stk[0]);
+
+const size_t c_stk_size = 512;
+uint8_t c_stk[c_stk_size];
+
+const size_t e_stk_size = 512;
+uint8_t e_stk[e_stk_size];
+Thread checkinEventThread(osPriorityNormal, e_stk_size, &e_stk[0]);
+Thread motionEventThread(osPriorityNormal, c_stk_size, &c_stk[0]);
+
+// create an event queue
+EventQueue chechinEventQueue;
+EventQueue motionEventQueue;
+
+Queue<int, 16> loraQueue;
+int message2;
+int message3;
+ 
+uint32_t count = 0;
+
+void checkinFunction() {
+  // this now runs in the context of checkinEventThread, instead of in the ISR
+  count++;
+  printf("Toggling LED 2!\r\n");
+  for(int i = 0 ; i < 0xFFFFFF; i++);
+  led2 = !led2;
+  message2 = HEART_BEAT_PACKET_SENDING;
+  loraQueue.put(&message2);
+  printf("Toggled LED 2 count = %d \r\n", count);
+}
+
+void motionFunction() {
+  // this now runs in the context of motionEventThread, instead of in the ISR
+  count++;
+  printf("Toggling LED 3!\r\n");
+  for(int i = 0 ; i < 0xFFFFFF; i++);
+  led3 = !led3;
+  message3 = STATUS_PACKET_SENDING;
+  loraQueue.put(&message3);
+  printf("Toggled LED 3 count = %d \r\n", count);
+}
+
+/**
+ * @brief thread a function 
+ */
+static void loraSendThreadFunc(void const *buf)
+{
+    uint32_t execs = 0;
+    int *message1;
+    osEvent evt;
+    pc_serial.printf("## started %s execution! ##\n\r", (char *)buf);
+ 
+    for(;;) {
+        execs++;
+        /* adds dummy processing */
+        for(int i = 0 ; i < 0xFFFFFF; i++);
+        evt = loraQueue.get();
+        if (evt.status == osEventMessage) {
+           message1 = (int*)evt.value.p;
+        }
+        if( *message1 == HEART_BEAT_PACKET_SENDING)
+           Send_HeartBeat_Packet();                            //call function to send heartbeat packet
+        else if( *message1 == STATUS_PACKET_SENDING)
+           Send_Vehicle_Status_Packet();                            //call function to send heartbeat packet
+        
+  
+        pc_serial.printf("## %s executed %d times! p = %d ##\n\r", (char *)buf, execs, *message1);
+        led1 = !led1;
+        Thread::yield();
+    }
+}
+
+/**
+ * @brief main application loop
+ *
+int main(void) 
+{      
+    pc_serial.baud(115200);
+    loraSendThread.start(callback(loraSendThreadFunc, (void *)LORA_SEND_THREAD));
+    //b_thread.start(callback(thread2, (void *)THREAD_B));
+    /*c_thread.start(callback(thread3, (void *)THREAD_C));*
+    
+    checkinEventThread.start(callback(&chechinEventQueue, &EventQueue::dispatch_forever));
+    motionEventThread.start(callback(&motionEventQueue, &EventQueue::dispatch_forever));
+ 
+    // wrap calls in queue.event to automatically defer to the queue's thread
+    checkinIntr.fall(chechinEventQueue.event(&checkinFunction));
+    motionIntr.fall(motionEventQueue.event(&motionFunction));
+  
+  
+    return 0;
+}
+*/
+int main(void) 
+{      
+    pc_serial.baud(115200);
+    loraSendThread.start(callback(loraSendThreadFunc, (void *)LORA_SEND_THREAD));
+    //b_thread.start(callback(thread2, (void *)THREAD_B));
+    /*c_thread.start(callback(thread3, (void *)THREAD_C));*/
+    
+    checkinEventThread.start(callback(&chechinEventQueue, &EventQueue::dispatch_forever));
+    motionEventThread.start(callback(&motionEventQueue, &EventQueue::dispatch_forever));
+ 
+    // wrap calls in queue.event to automatically defer to the queue's thread
+    checkinIntr.fall(chechinEventQueue.event(&checkinFunction));
+    motionIntr.fall(motionEventQueue.event(&motionFunction));
+    return 0;
+}
+/*
+
 int main()
 {
     pc1.baud(115200);
     BLE_RECEIVER_UART.baud(115200);
-    pc1.printf("%s","Debugging started\n");
+    //pc1.printf("%s","Debugging started\n");
+    pc_serial.printf("%s","Debugging started\n");
+     loraSendThread.start(callback(loraSendThreadFunc, (void *)LORA_SEND_THREAD));
+    //b_thread.start(callback(thread2, (void *)THREAD_B));
+    /*c_thread.start(callback(thread3, (void *)THREAD_C));*
+    
+    checkinEventThread.start(callback(&chechinEventQueue, &EventQueue::dispatch_forever));
+    motionEventThread.start(callback(&motionEventQueue, &EventQueue::dispatch_forever));
+ 
+    // wrap calls in queue.event to automatically defer to the queue's thread
+    checkinIntr.fall(chechinEventQueue.event(&checkinFunction));
+    motionIntr.fall(motionEventQueue.event(&motionFunction));
+  /*
+    
     //BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq);
     LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq);
    CheckIn_Interrupt.fall(&OBD_Plug_IN_Interrupt);
@@ -270,8 +413,9 @@
    // Send_Command_To_BLE_Receiver(SET_BEACON_MESSAGE_TYPE);
     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
+    *
 }
-
+*/
 void Send_Command_To_BLE_Receiver(const char* Command)
 {
     uint8 i;