kumar singh / Mbed OS Dealer_23Feb

Fork of Dealer_18feb17 by kumar singh

Files at this revision

API Documentation at this revision

Comitter:
NarendraSingh
Date:
Sun Feb 12 02:57:25 2017 +0000
Parent:
12:6107b32b0729
Child:
14:144ed8b74713
Commit message:
Before implementing beacon minor;

Changed in this revision

Lora.cpp Show annotated file Show diff for this revision Revisions of this file
Lora.h 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	Mon Jan 30 18:31:30 2017 +0000
+++ b/Lora.cpp	Sun Feb 12 02:57:25 2017 +0000
@@ -95,6 +95,8 @@
     while(AT_Response_Receive_Status)
         Get_Lora_Response();
     DEBUGING_UART.printf("Configuration saved");
+    LORA_Module_UART.printf("%s",Reset_Device);                    //reset device
+    wait_ms(3500);
     LORA_Module_UART.printf(Attention);        //Send Attention command
     AT_Response_Receive_Status = FAILURE;
     while(AT_Response_Receive_Status)
@@ -114,44 +116,54 @@
     Heart_Beat_Lora_Packet.Header = LORA_PACKET_HEADER;
     Heart_Beat_Lora_Packet.Protocol_Version = OBD_Protocol_Version;
     Heart_Beat_Lora_Packet.Packet_Type = HEART_BEAT_PACKET_CMD;
-    Heart_Beat_Lora_Packet.OBD_Battery_Voltage = 0x1234;
-    Heart_Beat_Lora_Packet.Car_Battery_Voltage = 0x5241;
-    Heart_Beat_Lora_Packet.OBD_Battery_Temperature = 0x00;
-    Heart_Beat_Lora_Packet.Car_Ambient_Temperature = 0x00;
+    Heart_Beat_Lora_Packet.OBD_Battery_Voltage = 350;       //3.50V, dummy data
+    Heart_Beat_Lora_Packet.Car_Battery_Voltage = 1250;      //12.50V, dummy data
+    Heart_Beat_Lora_Packet.OBD_Battery_Temperature = 95;    //95'F, dummy data
+    Heart_Beat_Lora_Packet.Car_Ambient_Temperature = 104;   //104'F, dummy data
     for(i=0;i<6;i++)
-        Heart_Beat_Lora_Packet.Parking1_Beacon_ID[i] = 0x78;      //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
-    Heart_Beat_Lora_Packet.Parking1_Beacon_Signal_Strength = 0x00;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+        Heart_Beat_Lora_Packet.Parking1_Beacon_ID[i] = (0x01+i);      //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Heart_Beat_Lora_Packet.Parking1_Beacon_Signal_Strength = 23;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Heart_Beat_Lora_Packet.Parking2_Beacon_ID[i] = 0x12;      //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
-    Heart_Beat_Lora_Packet.Parking2_Beacon_Signal_Strength = 0x00;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+        Heart_Beat_Lora_Packet.Parking2_Beacon_ID[i] = (10+i);      //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Heart_Beat_Lora_Packet.Parking2_Beacon_Signal_Strength = 45;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Heart_Beat_Lora_Packet.Parking3_Beacon_ID[i] = 0x00;      //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
-    Heart_Beat_Lora_Packet.Parking3_Beacon_Signal_Strength = 0x00;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+        Heart_Beat_Lora_Packet.Parking3_Beacon_ID[i] = (20+i);      //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Heart_Beat_Lora_Packet.Parking3_Beacon_Signal_Strength = 12;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     Heart_Beat_Lora_Packet.FCS = 0x00;                                 //FCS of all packets        
     
     /******* Initialize Lora packet for Vehicle Status *****/
     Vehicle_Status_Lora_Packet.Header = LORA_PACKET_HEADER;
     Vehicle_Status_Lora_Packet.Protocol_Version = OBD_Protocol_Version;
-    Vehicle_Status_Lora_Packet.Packet_Type = CHECKIN_PACKET_CMD;
+    Vehicle_Status_Lora_Packet.Packet_Type = STATUS_PACKET_CMD;
     for(i=0;i<17;i++)
-        Vehicle_Status_Lora_Packet.VIN[i] = Vehicle_Identification_Number[i];
+        Vehicle_Status_Lora_Packet.VIN[i] = (30+i);//Vehicle_Identification_Number[i];
     for(i=0;i<3;i++)
-        Vehicle_Status_Lora_Packet.ODO_METER_READING[i] = 0x00;  //Dummyy data, To be read using OBD
-    Vehicle_Status_Lora_Packet.OBD_Battery_Voltage = 0x1234;
-    Vehicle_Status_Lora_Packet.Car_Battery_Voltage = 0x5241;
-    Vehicle_Status_Lora_Packet.OBD_Battery_Temperature = 0x00;
-    Vehicle_Status_Lora_Packet.Car_Ambient_Temperature = 0x00;
+        Vehicle_Status_Lora_Packet.ODO_METER_READING[i] = 0x05;  //Dummyy data, To be read using OBD
+    Vehicle_Status_Lora_Packet.Fuel_Level = 1050;//10.5 litre
+    Vehicle_Status_Lora_Packet.OBD_Battery_Voltage = 350;
+    Vehicle_Status_Lora_Packet.Car_Battery_Voltage = 1250;
+    Vehicle_Status_Lora_Packet.OBD_Battery_Temperature = 95;
+    Vehicle_Status_Lora_Packet.Car_Ambient_Temperature = 104;
     for(i=0;i<6;i++)
         Vehicle_Status_Lora_Packet.BLE_Adv_Beacon_ID[i] = BLE_Adv_Module_Beacon_ID[i];         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     for(i=0;i<6;i++)
-        Vehicle_Status_Lora_Packet.Parking1_Beacon_ID[i] = 0x00;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
-    Vehicle_Status_Lora_Packet.Parking1_Beacon_Signal_Strength = 0x00;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+        Vehicle_Status_Lora_Packet.Parking1_Beacon_ID[i] = (30+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Vehicle_Status_Lora_Packet.Parking1_Beacon_Signal_Strength = 0x07;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+    for(i=0;i<6;i++)
+        Vehicle_Status_Lora_Packet.Parking2_Beacon_ID[i] = (40+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Vehicle_Status_Lora_Packet.Parking2_Beacon_Signal_Strength = 0x08;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+    for(i=0;i<6;i++)
+        Vehicle_Status_Lora_Packet.Parking3_Beacon_ID[i] = (50+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Vehicle_Status_Lora_Packet.Parking3_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Vehicle_Status_Lora_Packet.Parking2_Beacon_ID[i] = 0x00;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
-    Vehicle_Status_Lora_Packet.Parking2_Beacon_Signal_Strength = 0x00;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+        Vehicle_Status_Lora_Packet.Near_Car1_Beacon_ID[i] = (60+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Vehicle_Status_Lora_Packet.Near_Car1_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Vehicle_Status_Lora_Packet.Parking3_Beacon_ID[i] = 0x00;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
-    Vehicle_Status_Lora_Packet.Parking3_Beacon_Signal_Strength = 0x00;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+        Vehicle_Status_Lora_Packet.Near_Car2_Beacon_ID[i] = (70+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Vehicle_Status_Lora_Packet.Near_Car2_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+    for(i=0;i<6;i++)
+        Vehicle_Status_Lora_Packet.Near_Car3_Beacon_ID[i] = (80+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+    Vehicle_Status_Lora_Packet.Near_Car3_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     Vehicle_Status_Lora_Packet.FCS = 0x00;                       //FCS of all packets     
     
     /******* Initialize Lora packet for CheckIn *****/
@@ -188,6 +200,7 @@
     Motion_Lora_Packet.Parking3_Beacon_Signal_Strength = 0x00;    //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     Motion_Lora_Packet.Acceleration_Type = 0x00;          //Type of acceleration, Vehicle Started/Vehicle Stopped/Sudden Vehicle Movement
     Motion_Lora_Packet.FCS = 0x00;                        //FCS of all packets  
+    
 }
 
  //HeartBeat Packet should be sent every 30sec
@@ -377,7 +390,10 @@
     uint8 i=0;
     LORA_Module_UART.printf("%s",Send_Lora_Packet);//write to serial port for sending through lora module
     for(i=0;i<Length;i++)
+    {
         LORA_Module_UART.putc(Command_To_Send[i]);//write to serial port for sending through lora module
+        DEBUGING_UART.putc(Command_To_Send[i]);
+    }
     LORA_Module_UART.printf("\r");
 }
    
--- a/Lora.h	Mon Jan 30 18:31:30 2017 +0000
+++ b/Lora.h	Sun Feb 12 02:57:25 2017 +0000
@@ -169,6 +169,7 @@
 void Send_Motion_Packet(void);
 void Send_CheckIN_Packet(void);
 void Send_HeartBeat_Packet(void);
+void Send_Vehicle_Status_Packet(void);
 extern uint8 Calculate_Lora_Frame_FCS(uint8* Packet_Data,uint8 Packet_Length);
 extern void Set_Up_Lora_Network_Configuration(void);
-extern void Get_Lora_Response(void);
\ No newline at end of file
+extern void Get_Lora_Response(void);
--- a/main.cpp	Mon Jan 30 18:31:30 2017 +0000
+++ b/main.cpp	Sun Feb 12 02:57:25 2017 +0000
@@ -18,6 +18,7 @@
  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_9, PA_10);//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_0, PA_1);//USART4_TX->PA_0,USART4_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);
@@ -34,9 +35,12 @@
  void Lora_Periodic_Packet_Sending_thread(void const *args);
 
  void Lora_Rcvd_Cmd_Processing_thread(void);// const *args);
- void Enable_CheckIN_Packet_Sending();
+ void Enable_CheckIN_Packet_Sending();   
+ 
+ 
 /*************************Accelerometer related definitions***********************************/
 //Accelerometer related definitions
+
 #define DOUBLE_TAP_INTERRUPT        0x20
 #define ACTIVITY_INTERRUPT          0x10
 #define INACTIVITY_INTERRUPT        0x08
@@ -97,12 +101,18 @@
 unsigned char Motion_Type_Detected = MOTION_TYPE_UNKNOWN;    //By default set motion type as unknown
 void Accelerometer_Process_thread();//void const *args) ;
 
+ #define BLE_RECEIVER_UART_RX_Size 100
+ uint8 BLE_RxBuffer_End_Pos = 0;
+ char BLE_Receiver_UART_RX_Buffer[BLE_RECEIVER_UART_RX_Size];
+
 //This function is Interrupt routine for detecting motion(acceleartion), i.e. either starts from rest/vehicle stops afeter running or if sudden jurk is detected
 void interrupt_activity_inactivity()
 {   
     i2c.write(slave_address_acc, all_interrupt_clear_command, 2);  
     Motion_Detect_Status = TRUE;  
 }
+
+
 /************************************************************************/ 
 uint8 Command_Sent[100];
 uint8 Command_Length_Sent;
@@ -145,10 +155,9 @@
             Lora_RxBuffer_End_Pos  = 0;
         }
     }
-}
+} 
 
-
- /*
+ 
 // called every time a byte is received from Beacon Module.
 void Beacon_onDataRx()
 {
@@ -164,83 +173,28 @@
         }
     }
 }
-*/
 
-typedef struct {
-    uint8_t Queue_Msg_Type;   /* A counter value               */
-} message_type;
-
-MemoryPool<message_type, 16> mpool;
-Queue<message_type, 16> queue;   
-Thread OBD_Thread;
-Thread Accelerometer_Thread;
-
-#define OBD_MSG_TYPE                    0x01
-#define ACCELEROMETER_MSG_TYPE          0x02
-
-/* Send Thread */
-void OBD_Process_Thread (void) {
-    while (true) {
-        //DEBUG_UART.printf("\n OBD Message start ");
-        message_type message = mpool.alloc();
-        message->Queue_Msg_Type = (uint8_t) OBD_MSG_TYPE; 
-        queue.put(message);
-        //DEBUG_UART.printf("\n OBD Message Type Enqueued: \n");//, message->Queue_Msg_Type);
-        //Thread::wait(3000);
-        Thread::yield();
+ void BLE_Receiver_onDataRx(void)
+{
+    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(LORA_UART_RX_Buffer[Lora_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.
+            BLE_RxBuffer_End_Pos  = 0;
+        }
     }
-}
-
-/* Send Thread */
-void Accelerometer_Process_Thread (void) {
-    while (true) {
-        //DEBUG_UART.printf("\n Accelerometer Message start: ");
-        message_type message = mpool.alloc();
-        message->Queue_Msg_Type = (uint8_t) ACCELEROMETER_MSG_TYPE; 
-        queue.put(message);
-        //DEBUG_UART.printf("\n Accelerometer Message Type Enqueued: \n");//, message->Queue_Msg_Type);
-        //Thread::wait(5000);
-        Thread::yield();
-    }
-}
-
-int main (void) {
-    DEBUG_UART.baud(115200);    
-    //OBD_Thread.set_priority(osPriorityLow);
-    OBD_Thread.start(OBD_Process_Thread);
-    //DEBUG_UART.printf("\n main %d", __LINE__);
-    //Accelerometer_Thread.set_priority(osPriorityAboveNormal);
-    //DEBUG_UART.printf("\n main %d", __LINE__);
-    Accelerometer_Thread.start(Accelerometer_Process_Thread);
-    //DEBUG_UART.printf("\n main %d", __LINE__);
-#if 1    
-    while (true) {
-        DEBUG_UART.printf("\n main %d", __LINE__);
-         Thread::yield();
-        /*
-        osEvent evt = queue.get();
-        if (evt.status == osEventMessage) {
-            message_type *message = (message_type*)evt.value.p;
-            DEBUG_UART.printf("\nMessage Type Dequeued %d"   , message->Queue_Msg_Type);
-            mpool.free(message);
-        }*/
-    }
-#endif
-    OBD_Thread.join();  
-    Accelerometer_Thread.join(); 
-}
-
-
-
-
-
-/*
-int main()
+} 
+ 
+ int main()
 {
     DEBUG_UART.baud(115200);
     DEBUG_UART.printf("%s","Debugging started");
     LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq);
-    //Beacon_UART.attach(&Beacon_onDataRx, Serial::RxIrq);
+    //BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq);
     
     //Create a thread to read vehicle data
     //Thread OBD_thread(OBD_Rcvd_Cmd_Processing_thread);
@@ -251,11 +205,11 @@
     //led2_thread is executing concurrently with main at this point
     CheckIn_Interrupt.rise(&Handle_CheckIn_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
-}
-*/
- //Functiont to be called when Interrupt is genearted for motion sensing, checkin
+} 
+
+ //Function to be called when Interrupt is genearted for motion sensing, checkin
  void Initialize_Packets_Sent_Count(void)
  {
     Motion_Packet_Sent_Count = 0x00;
@@ -288,7 +242,7 @@
                 else
                 {
                     Status_Packet_Wait_Count = 0;
-                    //Send_Vehicle_Status_Packet();                            //call function to send heartbeat packet
+                    Send_Vehicle_Status_Packet();                            //call function to send heartbeat packet
                     DEBUG_UART.printf("Sent Status Packet");
                     AT_Response_Receive_Status = FAILURE;
                     while(AT_Response_Receive_Status)
@@ -337,16 +291,17 @@
                     CheckIN_Packet_Sent_Count = 0;
                     Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET;    //Set Packet type to send as heartbeat packet
                     Initialize_Packets_Sent_Count();
-                    
                 }
             }
         } 
         if(OBD_PlugInOut_IOC_Status)    //Check if Accelerometer Interrupt is generated
         {
-            Enable_CheckIN_Packet_Sending();
+            //Enable_CheckIN_Packet_Sending();
             //Get_Acceleration_Type();
             OBD_PlugInOut_IOC_Status = FALSE;
             Checkin_Detect_Status ^= 0x01;
+            Packet_Type_To_Send = CHECKIN_TYPE_PACKET;
+            Send_Lora_Packet_Flag = TRUE;
             if(Checkin_Detect_Status)   //OBD Plugin detected
             {
                 wait(1); //wait for 1sec to avoid detecting plugin debounce
@@ -377,12 +332,12 @@
     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() 
 {
    // Enable_CheckIN_Packet_Sending = TRUE;  //set status to true
-   /* if(Command_Received[0] == 0xFE) //check start of frame of packet received. every packet must start with 0xFE
+    if(Command_Received[0] == 0xFE) //check start of frame of packet received. every packet must start with 0xFE
     {
         if(Calculate_Lora_Frame_FCS((Command_Received + 1),(Command_Length + 1)) == (Command_Received[Command_Length + 2]))  //Check for packet inegrity by checking FCS
         {
@@ -391,5 +346,5 @@
                 Process_Beacon_Command_Received((Command_Received + 2));
             }
         }
-    }*/
-}
+    }
+} */
\ No newline at end of file