Dummy Lora Packet Sending

Fork of Dealer_18feb17 by kumar singh

Revision:
21:a5fb0ae94dc6
Parent:
20:f812f85cf97e
Child:
22:c2f034a13108
diff -r f812f85cf97e -r a5fb0ae94dc6 Lora.cpp
--- a/Lora.cpp	Tue Feb 21 13:33:29 2017 +0000
+++ b/Lora.cpp	Wed Feb 22 14:59:59 2017 +0000
@@ -85,10 +85,6 @@
         Get_Lora_Response();
     pc2.printf("Network Id response received");
     
-    LORA_Module_UART.printf("AT+TXDR\r");
-    AT_Response_Receive_Status = FAILURE;
-    while(AT_Response_Receive_Status)
-        Get_Lora_Response();
     LORA_Module_UART.printf("AT+TXDR=DR3\r");
     AT_Response_Receive_Status = FAILURE;
     while(AT_Response_Receive_Status)
@@ -105,10 +101,6 @@
     AT_Response_Receive_Status = FAILURE;
     while(AT_Response_Receive_Status)
         Get_Lora_Response();
-        LORA_Module_UART.printf("AT+TXDR\r");
-    AT_Response_Receive_Status = FAILURE;
-    while(AT_Response_Receive_Status)
-        Get_Lora_Response();
     
     pc2.printf("Configuration saved");
     LORA_Module_UART.printf("%s",Reset_Device);                    //reset device
@@ -129,7 +121,7 @@
 {
     uint8 i;
     /******* Initialize Lora packet for HeartBeat *****/
-    Heart_Beat_Lora_Packet.Header = LORA_PACKET_HEADER;
+    Misc_Packet_Data.Header = LORA_PACKET_HEADER;
     Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version;
     Heart_Beat_Lora_Packet.Packet_Type = HEART_BEAT_PACKET_CMD;
     Misc_Packet_Data.OBD_Battery_Voltage = 350;       //3.50V, dummy data
@@ -144,15 +136,16 @@
     Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 45;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
         Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = (20+i);      //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
-    Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 12;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+    Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 12;             //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength    
+    Heart_Beat_Lora_Packet.Sequence_No = 0x00;                   //Sent Packet Sequence Number
     Heart_Beat_Lora_Packet.FCS = 0x00;                                 //FCS of all packets        
     
     /******* Initialize Lora packet for Vehicle Status *****/
-    Vehicle_Status_Lora_Packet.Header = LORA_PACKET_HEADER;
+    Misc_Packet_Data.Header = LORA_PACKET_HEADER;
     Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version;
     Vehicle_Status_Lora_Packet.Packet_Type = STATUS_PACKET_CMD;
     for(i=0;i<17;i++)
-        Misc_Packet_Data.VIN[i] = (30+i);//Vehicle_Identification_Number[i];
+        Misc_Packet_Data.VIN[i] = i;//Vehicle_Identification_Number[i];
     for(i=0;i<3;i++)
         Misc_Packet_Data.ODO_METER_READING[i] = 0x05;  //Dummyy data, To be read using OBD
     Vehicle_Status_Lora_Packet.Fuel_Level = 1050;//10.5 litre
@@ -163,33 +156,36 @@
     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++)
-        Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = (30+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+        Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = i;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x07;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = (40+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+        Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = i;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x08;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = (50+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+        Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = i;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i] = (60+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+        Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i] = i;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i] = (70+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+        Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i] = i;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Near_Car_Beacon_Packet.Near_Car2_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
     for(i=0;i<6;i++)
-        Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i] = (80+i);         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
+        Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i] = i;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength = 0x09;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+    Vehicle_Status_Lora_Packet.Sequence_No = 0x00;                   //Sent Packet Sequence Number
     Vehicle_Status_Lora_Packet.FCS = 0x00;                       //FCS of all packets     
     
     /******* Initialize Lora packet for CheckIn *****/
-    CheckIN_Lora_Packet.Header = LORA_PACKET_HEADER;
+    Misc_Packet_Data.Header = LORA_PACKET_HEADER;
     Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version;
     CheckIN_Lora_Packet.Packet_Type = CHECKIN_PACKET_CMD;
     for(i=0;i<17;i++)
         Misc_Packet_Data.VIN[i] = Vehicle_Identification_Number[i];
     for(i=0;i<3;i++)
         Misc_Packet_Data.ODO_METER_READING[i] = 0x00;  //Dummyy data, To be read using OBD
+    for(i=0;i<5;i++)
+        CheckIN_Lora_Packet.DTC[i] = 0x00;       //Get Beacon_ID of 1st nearby Beacon Device
     for(i=0;i<6;i++)
         Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = 0x00;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
@@ -199,10 +195,11 @@
     for(i=0;i<6;i++)
         Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+    CheckIN_Lora_Packet.Sequence_No = 0x00;                   //Sent Packet Sequence Number
     CheckIN_Lora_Packet.FCS = 0x00;                       //FCS of all packets     
        
     /******* Initialize Lora packet for CheckOUT *****/
-    CheckOUT_Packet.Header = LORA_PACKET_HEADER;
+    Misc_Packet_Data.Header = LORA_PACKET_HEADER;
     Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version;
     CheckOUT_Packet.Packet_Type = CHECKIN_PACKET_CMD;
     for(i=0;i<17;i++)
@@ -218,10 +215,11 @@
     for(i=0;i<6;i++)
         Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00;         //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
     Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00;   //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength          
+    CheckOUT_Packet.Sequence_No = 0x00;                   //Sent Packet Sequence Number
     CheckOUT_Packet.FCS = 0x00;                       //FCS of all packets     
        
     /******* Initialize Lora packet for Movement *****/
-    Motion_Lora_Packet.Header = LORA_PACKET_HEADER;
+    Misc_Packet_Data.Header = LORA_PACKET_HEADER;
     Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version;
     Motion_Lora_Packet.Packet_Type = MOTION_PACKET_CMD;
     for(i=0;i<6;i++)
@@ -234,25 +232,25 @@
         Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00;          //MAC ID of 3rd NearBy Beacon Device with Highest Signal Strength,dummy data
     Fixed_Beacon_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.Sequence_No = 0x00;                   //Sent Packet Sequence Number
     Motion_Lora_Packet.FCS = 0x00;                        //FCS of all packets  
- 
+    Lora_Packet_To_Send[0] = 0x41;//'A'
+    Lora_Packet_To_Send[1] = 0x54;//'T'
+    Lora_Packet_To_Send[2] = 0x2b;//'+'
+    Lora_Packet_To_Send[3] = 0x53;//'S'
+    Lora_Packet_To_Send[4] = 0x45;//'E'
+    Lora_Packet_To_Send[5] = 0x4e;//'N'
+    Lora_Packet_To_Send[6] = 0x44;//'D'
+    Lora_Packet_To_Send[7] = 0x20;//' ' Blank Space
+    Lora_Packet_To_Send[8] = Misc_Packet_Data.Header;                  //Header of Lora Packet,0xFE
+    Lora_Packet_To_Send[9] = Misc_Packet_Data.Protocol_Version;
 }
                
  //HeartBeat Packet should be sent every 30sec
 void Send_HeartBeat_Packet(void)
 {
     //write code to read obd data,temperature,beacon data
-    uint8 Pos = 0,i;
-    Lora_Packet_To_Send[Pos++] = 0x41;//Heart_Beat_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = 0x54;//Misc_Packet_Data.Protocol_Version;
-    Lora_Packet_To_Send[Pos++] = 0x2b;//Heart_Beat_Lora_Packet.Packet_Type;      //MSB of Motion Packet Type
-    Lora_Packet_To_Send[Pos++] = 0x53;//(Misc_Packet_Data.OBD_Battery_Voltage >> 8);     //Get OBD_Battery Voltage
-    Lora_Packet_To_Send[Pos++] = 0x45;//(Misc_Packet_Data.OBD_Battery_Voltage & 0xFF);     //Get OBD_Battery Voltage
-    Lora_Packet_To_Send[Pos++] = 0x4e;//(Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
-    Lora_Packet_To_Send[Pos++] = 0x44;//(Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
-    Lora_Packet_To_Send[Pos++] = 0x20;//Vehicle_Status_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version;
+    uint8 Pos = 10,i;
     Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Packet_Type;      //MSB of Motion Packet Type
     Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage >> 8);     //Get OBD_Battery Voltage
     Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage & 0xFF);     //Get OBD_Battery Voltage
@@ -268,35 +266,30 @@
     Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
     for(i=0;i<6;i++)
         Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i];       //Get Beacon_ID of 3rd nearby Beacon Device
-    Lora_Packet_To_Send[Pos++] = 0x04;//Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
-    Lora_Packet_To_Send[Pos++] = 0x05;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
-    Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET;
+    Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
+    Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Sequence_No;                  //Packet Sequence number
+    Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0xDE;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0x0D;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    /*Lora_Packet_To_Send[Pos++] = 0xB1;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0xB2;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0xB3;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0xB4;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    */Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET;
     Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); 
+    if(Heart_Beat_Lora_Packet.Sequence_No < 0xFF)
+        Heart_Beat_Lora_Packet.Sequence_No++;
+    else
+        Heart_Beat_Lora_Packet.Sequence_No = 0x00;
+    pc2.printf("Heartbeat 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
 void Send_Vehicle_Status_Packet(void)
 {
     //write code to read OBD data,temperature,beacon data
-    uint8 Pos = 0,i;
-    Lora_Packet_To_Send[Pos++] = 0x41;//Heart_Beat_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = 0x54;//Misc_Packet_Data.Protocol_Version;
-    Lora_Packet_To_Send[Pos++] = 0x2b;//Heart_Beat_Lora_Packet.Packet_Type;      //MSB of Motion Packet Type
-    Lora_Packet_To_Send[Pos++] = 0x53;//(Misc_Packet_Data.OBD_Battery_Voltage >> 8);     //Get OBD_Battery Voltage
-    Lora_Packet_To_Send[Pos++] = 0x45;//(Misc_Packet_Data.OBD_Battery_Voltage & 0xFF);     //Get OBD_Battery Voltage
-    Lora_Packet_To_Send[Pos++] = 0x4e;//(Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
-    Lora_Packet_To_Send[Pos++] = 0x44;//(Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
-    Lora_Packet_To_Send[Pos++] = 0x20;//Vehicle_Status_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version;
-    Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Packet_Type;      //MSB of Motion Packet Type
-    Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage >> 8);     //Get OBD_Battery Voltage
-    Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage & 0xFF);     //Get OBD_Battery Voltage
-    Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
-    Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
-    Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version;      //MSB of Motion Packet Type
-    Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Packet_Type;      //MSB of Motion Packet Type
+    uint8 Pos = 10,i;
+    Lora_Packet_To_Send[Pos++] = STATUS_PACKET_CMD;      //MSB of Motion Packet Type
     for(i=0;i < 17;i++)
         Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i];           //Get OBD_ID
     for(i=0;i < 3;i++)
@@ -313,7 +306,7 @@
         Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.BLE_Adv_Beacon_ID[i];       //Get Beacon_ID of 1st nearby Beacon Device
     for(i=0;i<6;i++)
         Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i];       //Get Beacon_ID of 1st nearby Beacon Device
-    /*Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
+    Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
     for(i=0;i<6;i++)
         Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i];       //Get Beacon_ID of 2nd nearby Beacon Device
     Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
@@ -328,26 +321,39 @@
     Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
     for(i=0;i<6;i++)
         Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i];       //Get Beacon_ID of 3rd nearby Beacon Device
-    */Lora_Packet_To_Send[Pos++] = 0x06;//Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
-    Lora_Packet_To_Send[Pos++] = 0x04;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
-    Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); 
+    Lora_Packet_To_Send[Pos++] = 0x23;//Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
+    Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Sequence_No;                  //Packet Sequence number
+    Lora_Packet_To_Send[Pos++] = 0xEE;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0x0D;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    /*Lora_Packet_To_Send[Pos++] = 0xA1;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0xA2;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0xA3;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    Lora_Packet_To_Send[Pos++] = 0xA4;//Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
+    */Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); 
+    if(Vehicle_Status_Lora_Packet.Sequence_No < 0xFF)
+        Vehicle_Status_Lora_Packet.Sequence_No++;
+    else
+        Vehicle_Status_Lora_Packet.Sequence_No = 0x00;
+    /*for(i=0; i < Pos; i++)
+     {
+        pc2.putc(Lora_Packet_To_Send[i]);
+        //pc2.putc(Command_To_Send[i]);
+     }*/
+     pc2.printf("Status 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
 void Send_CheckIN_Packet(void)
 {
     //write code to read OBD data,temperature,beacon data
-    uint8 Pos = 0,i;
-    Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version;      //MSB of Motion Packet Type
-    if(OBD_PlugIN_State)
-        Lora_Packet_To_Send[Pos++] = CHECK_IN_PACKET;      //Check detected. Set packet type to Checkout type
-    else
-        Lora_Packet_To_Send[Pos++] = CHECK_OUT_PACKET;      //Checkout detected. Set packet type to Checkout type
+    uint8 Pos = 10,i;
+    Lora_Packet_To_Send[Pos++] = CHECKIN_PACKET_CMD;      //Check detected. Set packet type to Checkout type
     for(i=0;i < 17;i++)
         Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i];           //Get OBD_ID
     for(i=0;i < 3;i++)
         Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.ODO_METER_READING[i];           //Get OBD_ID
+    for(i=0;i<5;i++)
+        Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.DTC[i];       //Get Beacon_ID of 1st nearby Beacon Device
     Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage >> 8);     //Get OBD_Battery Voltage
     Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage & 0xFF);     //Get OBD_Battery Voltage
     Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
@@ -363,10 +369,18 @@
     for(i=0;i<6;i++)
         Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i];       //Get Beacon_ID of 3rd nearby Beacon Device
     Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
+    Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.Sequence_No;                  //Packet Sequence number
     Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
     CheckIN_Packet_Sent_Count++;
     Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); 
-    pc2.printf("CheckIN Packet Sent");
+    for(i=0; i < Pos; i++)
+     {
+        pc2.putc(Lora_Packet_To_Send[i]);
+        //pc2.putc(Command_To_Send[i]);
+     }
+     pc2.printf("CheckIN Packet Sent");
+    CheckIN_Lora_Packet.Sequence_No++;
+    pc2.printf("Status Packet Sequence Number %d",CheckIN_Lora_Packet.Sequence_No);
 }
 
 
@@ -374,10 +388,8 @@
 void Send_CheckOUT_Packet(void)
 {
     //write code to read OBD data,temperature,beacon data
-    uint8 Pos = 0,i;
-    Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version;      //MSB of Motion Packet Type
-    Lora_Packet_To_Send[Pos++] = CHECK_OUT_PACKET;      //Checkout detected. Set packet type to Checkout type
+    uint8 Pos = 10,i;
+    Lora_Packet_To_Send[Pos++] = CHECKOUT_PACKET_CMD;      //Checkout detected. Set packet type to Checkout type
     for(i=0;i < 17;i++)
         Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i];           //Get OBD_ID
     for(i=0;i < 3;i++) 
@@ -388,11 +400,17 @@
     Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
     Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.OBD_Battery_Temperature;     //Get Battery Temperature
     Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature;     //Get Ambient Temperature
+    Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.Sequence_No;                  //Packet Sequence number
     Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
     CheckIN_Packet_Sent_Count++;
     Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); 
-    pc2.printf("CheckOUT Packet Sent");
-    
+    for(i=0; i < Pos; i++)
+     {
+        pc2.putc(Lora_Packet_To_Send[i]);
+        //pc2.putc(Command_To_Send[i]);
+     }pc2.printf("CheckOUT Packet Sent");
+    CheckOUT_Packet.Sequence_No++;
+    pc2.printf("Status Packet Sequence Number %d",CheckOUT_Packet.Sequence_No);
 }
 
 //Motion packets sending should be started when vehicle acceleration changes like when it starts moving,stops moving and gets sudden jurk in case of theft.
@@ -400,9 +418,7 @@
 void Send_Motion_Packet(void)
 {
     //write code to read accelerometer data,temperature,beacon data
-    uint8 Pos = 0,i;
-    Lora_Packet_To_Send[Pos++] = Motion_Lora_Packet.Header;                  //Header of Lora Packet,0xFE
-    Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version;          //Protocol Version
+    uint8 Pos = 10,i;
     Lora_Packet_To_Send[Pos++] = (Motion_Lora_Packet.Packet_Type & 0xFF);         //LSB of Motion Packet Type
     for(i=0;i<6;i++)
         Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i];       //Get Beacon_ID of 1st nearby Beacon Device
@@ -432,15 +448,21 @@
     for(i=0;i<6;i++)
         Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i];       //Get Beacon_ID of 3rd nearby Beacon Device
     Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
+    Lora_Packet_To_Send[Pos++] = Motion_Lora_Packet.Sequence_No;                  //Packet Sequence number
     Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos);   //Calculate FCS of all bytes
     Motion_Packet_Sent_Count++;
     Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); 
+    for(i=0; i < Pos; i++)
+     {
+        pc2.putc(Lora_Packet_To_Send[i]);
+        //pc2.putc(Command_To_Send[i]);
+     }Motion_Lora_Packet.Sequence_No++;
 }   
 
 
 void Get_Lora_Response(void)
 {
-    static uint16 Temp_Pos1;
+    static uint16 Temp_Pos1,Temp_pos2;
     static uint8 Lora_Response_Found = 0x00; 
     static uint8 Response_Start_Pos[5];
     Lora_Response_Found = 0;
@@ -455,7 +477,9 @@
         {
             Temp_Pos1+=2;
             Response_Start_Pos[Lora_Response_Found++] = Temp_Pos1;
-            //pc2.printf("%c",Temp_Pos1);
+            /*pc2.printf("\nEcho data\n");
+            for(Temp_pos2 = LORA_UART_RX_Crnt_Pos;Temp_pos2<Temp_Pos1;Temp_pos2++)
+                pc2.printf("0x%2x ",(LORA_UART_RX_Buffer[Temp_pos2]));*/
             if(Lora_Response_Found >= 4)
                 break;
         }
@@ -466,11 +490,14 @@
         {
             LORA_UART_RX_Crnt_Pos = (Response_Start_Pos[0]);
             Response_Start_Pos[1]-=2;
+            //pc2.printf("\n Response packet\n");
             for(Temp_Pos1=0; LORA_UART_RX_Crnt_Pos < Response_Start_Pos[1]; Temp_Pos1++)
             {
                 Lora_Command_Rcvd[Temp_Pos1] = LORA_UART_RX_Buffer[LORA_UART_RX_Crnt_Pos++];
-                pc2.putc(Lora_Command_Rcvd[Temp_Pos1]);
+                //pc2.printf("0x%2x ",(Lora_Command_Rcvd[Temp_Pos1]));
+                //pc2.putc(Lora_Command_Rcvd[Temp_Pos1]);
             }
+            //pc2.printf("\nTotal Reecived Bytes %d\n",LORA_UART_RX_Crnt_Pos);
             Lora_RxBuffer_End_Pos = 0;
             AT_Response_Receive_Status = SUCCESS;
         }
@@ -478,11 +505,18 @@
         {
             LORA_UART_RX_Crnt_Pos = (Response_Start_Pos[1]);
             Response_Start_Pos[2]-=2;
+            //pc2.printf("\n Response packet\n");
             for(Temp_Pos1=0; LORA_UART_RX_Crnt_Pos < Response_Start_Pos[2]; Temp_Pos1++)
             {
                 Lora_Command_Rcvd[Temp_Pos1] = LORA_UART_RX_Buffer[LORA_UART_RX_Crnt_Pos++];
-                pc2.putc(Lora_Command_Rcvd[Temp_Pos1]);
+                
+                //pc2.putc(Lora_Command_Rcvd[Temp_Pos1]);
             }
+            /*for(Temp_Pos1=0; Temp_Pos1 < Length; Temp_Pos1++)
+             {
+            pc2.printf("0x%2x ",(Lora_Command_Rcvd[Temp_Pos1]));
+            }*/
+            //pc2.printf("\nTotal Reecived Bytes %d\n",LORA_UART_RX_Crnt_Pos);
             Lora_RxBuffer_End_Pos = 0;
             AT_Response_Receive_Status = SUCCESS;
         }
@@ -492,6 +526,28 @@
 //Function to send general Lora packets using "AT+SEND" Command
 void Send_Lora_Packet_To_Gateway(uint8* Command_To_Send,uint8 Length)
 {
+     uint8 i=0;
+     for(i=0; i < Length; i++)
+     {
+        LORA_Module_UART.putc(Command_To_Send[i]);
+        //pc2.putc(Command_To_Send[i]);
+     }
+     //LORA_Module_UART.printf("\r");
+     
+     pc2.printf("\n Sending packet\n");
+     for(i=0; i < Length; i++)
+     {
+        pc2.printf("0x%2x ",(Command_To_Send[i]));
+     }
+     
+     // LORA_Module_UART.printf("%s",Command_To_Send);
+     pc2.printf("\nTotal Bytes %d\n",Length);
+}
+
+/*
+//Function to send general Lora packets using "AT+SEND" Command
+void Send_Lora_Packet_To_Gateway(uint8* Command_To_Send,uint8 Length)
+{
     uint8 i=0;
     //pc2.printf("Sending data");
    // LORA_Module_UART.printf("%s",Send_Lora_Packet);//write to serial port for sending through lora module
@@ -499,7 +555,7 @@
      {
         LORA_Module_UART.putc(Send_Lora_Packet[i]);
         
-     }*/
+     }
      for(i=0; i < Length; i++)
      {
         LORA_Module_UART.putc(Command_To_Send[i]);
@@ -514,8 +570,7 @@
    // LORA_Module_UART.printf("%s",Command_To_Send);
     LORA_Module_UART.printf("\r");
     pc2.printf("Total Bytes %d",Length);
-}
-   
+}*/
 
  unsigned char Calculate_Lora_Frame_FCS(unsigned char* Packet_Data,unsigned char Packet_Length)
  {