BLE Transmitter not working

Fork of Dealer_23Feb by kumar singh

Committer:
NarendraSingh
Date:
Sat Feb 18 08:52:04 2017 +0000
Revision:
18:86f069689502
Parent:
17:758fb8454ab0
Child:
19:886d50ecc718
Minor added in beacon packet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NarendraSingh 11:77e595130230 1 #include "Lora.h"
NarendraSingh 11:77e595130230 2 #include "OBD.h"
NarendraSingh 11:77e595130230 3 #include "Common_Defs.h"
NarendraSingh 11:77e595130230 4 #include "Beacon.h"
NarendraSingh 11:77e595130230 5
NarendraSingh 11:77e595130230 6 //Configure Lora Packet
NarendraSingh 11:77e595130230 7 RawSerial LORA_Module_UART(PA_0, PA_1);//USART4_TX->PA_0,USART4_RX->PA_1
NarendraSingh 17:758fb8454ab0 8 RawSerial pc2(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10
NarendraSingh 17:758fb8454ab0 9 Serial pc_2(USBTX, USBRX);
NarendraSingh 11:77e595130230 10
NarendraSingh 11:77e595130230 11 uint8 Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //By Default Heart Beat PAckets should be sent
NarendraSingh 11:77e595130230 12 uint8 OBD_Protocol_Version = 0x01;
NarendraSingh 11:77e595130230 13 uint8 Vehicle_Identification_Number[17]; //Unique Vehicle_Identification_Number, Read using OBD
NarendraSingh 11:77e595130230 14 uint8 Motion_Packet_Sent_Count=0;
NarendraSingh 11:77e595130230 15 uint8 CheckIN_Packet_Sent_Count=0;
NarendraSingh 11:77e595130230 16 uint8 Lora_Packet_To_Send[100];
NarendraSingh 11:77e595130230 17 uint8 Send_Lora_Packet_Flag = FALSE;
NarendraSingh 11:77e595130230 18 int Lora_RxBuffer_Crnt_Pos,Lora_RxBuffer_End_Pos; // must be volatile or the compiler may over-optimise.
NarendraSingh 11:77e595130230 19 int receivedDataCount = 0;
NarendraSingh 11:77e595130230 20 char LORA_UART_RX_Buffer[LORA_UART_RX_Size];
NarendraSingh 11:77e595130230 21 int LORA_UART_RX_Crnt_Pos;
NarendraSingh 11:77e595130230 22 uint8 Lora_Command_Rcvd[100];
NarendraSingh 11:77e595130230 23 uint8 Lora_Cmd_Length = 0;
NarendraSingh 11:77e595130230 24 uint8 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 25
NarendraSingh 11:77e595130230 26 //Create Object for Type of Lora Packet to send
NarendraSingh 11:77e595130230 27 Heart_Beat_PacketType Heart_Beat_Lora_Packet; //Allocate Memory for HeartBeat Lora Packets
NarendraSingh 11:77e595130230 28 CheckIN_PacketType CheckIN_Lora_Packet; //Allocate Memory for CheckIN Lora Packets
NarendraSingh 18:86f069689502 29 CheckOUT_PacketType CheckOUT_Packet; //Allocate Memory for CheckOUT Lora Packets
NarendraSingh 11:77e595130230 30 Motion_PacketType Motion_Lora_Packet; //Allocate Memory for Movement Lora Packets
NarendraSingh 11:77e595130230 31 Vehicle_Status_PacketType Vehicle_Status_Lora_Packet; //Allocate Memory for Movement Lora Packets
NarendraSingh 16:7703b9d92326 32 Near_Car_Beacon Near_Car_Beacon_Packet;
NarendraSingh 16:7703b9d92326 33 Fixed_Beacon Fixed_Beacon_Packet;
NarendraSingh 11:77e595130230 34
NarendraSingh 11:77e595130230 35 //Lora AT Commands list
NarendraSingh 11:77e595130230 36 const char* Attention = {"AT\r"};
NarendraSingh 11:77e595130230 37 const char* Reset_Device = "ATZ\r";
NarendraSingh 11:77e595130230 38 const char* Reset_to_Factory_Defaults = "AT&F\r";
NarendraSingh 11:77e595130230 39 const char* Save_Configuration = "AT&W\r";
NarendraSingh 11:77e595130230 40 const char* Serial_Baud_Rate = "AT+IPR=";
NarendraSingh 11:77e595130230 41 const char* Join_Network = "AT+JOIN\r";
NarendraSingh 11:77e595130230 42 const char* Join_Retries = "AT+JR=";
NarendraSingh 11:77e595130230 43 const char* AES_Encryption = "AT+ENC=";
NarendraSingh 11:77e595130230 44 const char* Send_Lora_Packet = "AT+SEND ";
NarendraSingh 11:77e595130230 45 const char* Set_Frequency_Sub_Band = "AT+FSB=";
NarendraSingh 11:77e595130230 46 const char* Set_Network_ID = "AT+NI=";
NarendraSingh 11:77e595130230 47 const char* Set_Network_Key = "AT+NK=";
NarendraSingh 11:77e595130230 48 const char* Network_Key = "010203123";
NarendraSingh 11:77e595130230 49 const char* Network_ID = "010203040";
NarendraSingh 11:77e595130230 50 const char* Network_Join_Retries = "AT+JR=";
NarendraSingh 11:77e595130230 51 const char* Network_Join_Status = "AT+NJS=";
NarendraSingh 11:77e595130230 52 const char* Lora_Device_ID = "AT+DI\r";
NarendraSingh 11:77e595130230 53
NarendraSingh 16:7703b9d92326 54 #define CHECK_IN_PACKET 0x00
NarendraSingh 16:7703b9d92326 55 #define CHECK_OUT_PACKET 0x01
NarendraSingh 11:77e595130230 56
NarendraSingh 11:77e595130230 57 uint8 Calculate_Lora_Frame_FCS(uint8* Packet_Data,uint8 Packet_Length);
NarendraSingh 11:77e595130230 58 void Set_Up_Lora_Network_Configuration(void);
NarendraSingh 11:77e595130230 59 void Get_Lora_Response(void);
NarendraSingh 11:77e595130230 60
NarendraSingh 11:77e595130230 61 //Set Up lora network
NarendraSingh 11:77e595130230 62 void Set_Up_Lora_Network_Configuration(void)
NarendraSingh 11:77e595130230 63 {
NarendraSingh 11:77e595130230 64 LORA_Module_UART.baud(115200);
NarendraSingh 11:77e595130230 65 LORA_Module_UART.printf(Attention);//Send Attention command
NarendraSingh 11:77e595130230 66 AT_Response_Receive_Status = FAILURE;
NarendraSingh 17:758fb8454ab0 67 pc2.printf("Nwk set up started");
NarendraSingh 11:77e595130230 68 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 69 Get_Lora_Response();
NarendraSingh 17:758fb8454ab0 70 pc2.printf("AT Response received");
NarendraSingh 11:77e595130230 71 LORA_Module_UART.printf("%s%d\r",Set_Frequency_Sub_Band,FREQUENCY_SUB_BAND_CHANNEL7);//set frequency sub band to 7
NarendraSingh 11:77e595130230 72 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 73 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 74 Get_Lora_Response();
NarendraSingh 17:758fb8454ab0 75 pc2.printf("Frequency band response received");
NarendraSingh 11:77e595130230 76 LORA_Module_UART.printf("%s%d,%s\r",Set_Network_Key,STRING_PARAMETER,Network_Key); //set network key
NarendraSingh 11:77e595130230 77 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 78 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 79 Get_Lora_Response();
NarendraSingh 17:758fb8454ab0 80 pc2.printf("Network key Response received");
NarendraSingh 11:77e595130230 81 LORA_Module_UART.printf("%s%d,%s\r",Set_Network_ID,STRING_PARAMETER,Network_ID); //set network id
NarendraSingh 11:77e595130230 82 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 83 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 84 Get_Lora_Response();
NarendraSingh 17:758fb8454ab0 85 pc2.printf("Network Id response received");
NarendraSingh 11:77e595130230 86
NarendraSingh 11:77e595130230 87 //LORA_Module_UART.printf("%s",Reset_Device); //reset device
NarendraSingh 11:77e595130230 88 //wait_ms(3500);
NarendraSingh 11:77e595130230 89
NarendraSingh 11:77e595130230 90 LORA_Module_UART.printf("AT+TXDR=DR2\r");
NarendraSingh 11:77e595130230 91 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 92 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 93 Get_Lora_Response();
NarendraSingh 11:77e595130230 94 LORA_Module_UART.printf("AT+ADR=1\r"); //Enable adaptive data rate
NarendraSingh 11:77e595130230 95 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 96 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 97 Get_Lora_Response();
NarendraSingh 11:77e595130230 98 LORA_Module_UART.printf("%s",Save_Configuration); //save configuration
NarendraSingh 11:77e595130230 99 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 100 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 101 Get_Lora_Response();
NarendraSingh 17:758fb8454ab0 102 pc2.printf("Configuration saved");
NarendraSingh 13:8955f2e95021 103 LORA_Module_UART.printf("%s",Reset_Device); //reset device
NarendraSingh 13:8955f2e95021 104 wait_ms(3500);
NarendraSingh 11:77e595130230 105 LORA_Module_UART.printf(Attention); //Send Attention command
NarendraSingh 11:77e595130230 106 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 107 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 108 Get_Lora_Response();
NarendraSingh 17:758fb8454ab0 109 pc2.printf("AT Response received");
NarendraSingh 11:77e595130230 110 LORA_Module_UART.printf("%s",Join_Network); //join network with gateway
NarendraSingh 11:77e595130230 111 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 112 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 113 Get_Lora_Response();
NarendraSingh 17:758fb8454ab0 114 pc2.printf("Join Response received");
NarendraSingh 11:77e595130230 115 }
NarendraSingh 11:77e595130230 116
NarendraSingh 11:77e595130230 117 void Initialize_lora_Packets()
NarendraSingh 11:77e595130230 118 {
NarendraSingh 11:77e595130230 119 uint8 i;
NarendraSingh 11:77e595130230 120 /******* Initialize Lora packet for HeartBeat *****/
NarendraSingh 11:77e595130230 121 Heart_Beat_Lora_Packet.Header = LORA_PACKET_HEADER;
NarendraSingh 11:77e595130230 122 Heart_Beat_Lora_Packet.Protocol_Version = OBD_Protocol_Version;
NarendraSingh 11:77e595130230 123 Heart_Beat_Lora_Packet.Packet_Type = HEART_BEAT_PACKET_CMD;
NarendraSingh 13:8955f2e95021 124 Heart_Beat_Lora_Packet.OBD_Battery_Voltage = 350; //3.50V, dummy data
NarendraSingh 13:8955f2e95021 125 Heart_Beat_Lora_Packet.Car_Battery_Voltage = 1250; //12.50V, dummy data
NarendraSingh 13:8955f2e95021 126 Heart_Beat_Lora_Packet.OBD_Battery_Temperature = 95; //95'F, dummy data
NarendraSingh 13:8955f2e95021 127 Heart_Beat_Lora_Packet.Car_Ambient_Temperature = 104; //104'F, dummy data
NarendraSingh 11:77e595130230 128 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 129 Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = (0x01+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 130 Fixed_Beacon_Packet.Parking1_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 131 Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 23; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 132 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 133 Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = (10+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 134 Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 135 Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 45; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 136 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 137 Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = (20+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 138 Fixed_Beacon_Packet.Parking3_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 139 Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 12; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 140 Heart_Beat_Lora_Packet.FCS = 0x00; //FCS of all packets
NarendraSingh 11:77e595130230 141
NarendraSingh 11:77e595130230 142 /******* Initialize Lora packet for Vehicle Status *****/
NarendraSingh 11:77e595130230 143 Vehicle_Status_Lora_Packet.Header = LORA_PACKET_HEADER;
NarendraSingh 11:77e595130230 144 Vehicle_Status_Lora_Packet.Protocol_Version = OBD_Protocol_Version;
NarendraSingh 13:8955f2e95021 145 Vehicle_Status_Lora_Packet.Packet_Type = STATUS_PACKET_CMD;
NarendraSingh 11:77e595130230 146 for(i=0;i<17;i++)
NarendraSingh 13:8955f2e95021 147 Vehicle_Status_Lora_Packet.VIN[i] = (30+i);//Vehicle_Identification_Number[i];
NarendraSingh 11:77e595130230 148 for(i=0;i<3;i++)
NarendraSingh 13:8955f2e95021 149 Vehicle_Status_Lora_Packet.ODO_METER_READING[i] = 0x05; //Dummyy data, To be read using OBD
NarendraSingh 13:8955f2e95021 150 Vehicle_Status_Lora_Packet.Fuel_Level = 1050;//10.5 litre
NarendraSingh 13:8955f2e95021 151 Vehicle_Status_Lora_Packet.OBD_Battery_Voltage = 350;
NarendraSingh 13:8955f2e95021 152 Vehicle_Status_Lora_Packet.Car_Battery_Voltage = 1250;
NarendraSingh 13:8955f2e95021 153 Vehicle_Status_Lora_Packet.OBD_Battery_Temperature = 95;
NarendraSingh 13:8955f2e95021 154 Vehicle_Status_Lora_Packet.Car_Ambient_Temperature = 104;
NarendraSingh 11:77e595130230 155 for(i=0;i<6;i++)
NarendraSingh 11:77e595130230 156 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
NarendraSingh 11:77e595130230 157 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 158 Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = (30+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 159 Fixed_Beacon_Packet.Parking1_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 160 Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x07; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 13:8955f2e95021 161 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 162 Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = (40+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 163 Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 164 Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x08; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 13:8955f2e95021 165 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 166 Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = (50+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 167 Fixed_Beacon_Packet.Parking3_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 168 Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 169 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 170 Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i] = (60+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 171 Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 172 Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 173 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 174 Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i] = (70+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 175 Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 176 Near_Car_Beacon_Packet.Near_Car2_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 13:8955f2e95021 177 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 178 Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i] = (80+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 179 Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 180 Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 181 Vehicle_Status_Lora_Packet.FCS = 0x00; //FCS of all packets
NarendraSingh 11:77e595130230 182
NarendraSingh 11:77e595130230 183 /******* Initialize Lora packet for CheckIn *****/
NarendraSingh 11:77e595130230 184 CheckIN_Lora_Packet.Header = LORA_PACKET_HEADER;
NarendraSingh 11:77e595130230 185 CheckIN_Lora_Packet.Protocol_Version = OBD_Protocol_Version;
NarendraSingh 11:77e595130230 186 CheckIN_Lora_Packet.Packet_Type = CHECKIN_PACKET_CMD;
NarendraSingh 11:77e595130230 187 for(i=0;i<17;i++)
NarendraSingh 11:77e595130230 188 CheckIN_Lora_Packet.VIN[i] = Vehicle_Identification_Number[i];
NarendraSingh 11:77e595130230 189 for(i=0;i<3;i++)
NarendraSingh 11:77e595130230 190 CheckIN_Lora_Packet.ODO_METER_READING[i] = 0x00; //Dummyy data, To be read using OBD
NarendraSingh 11:77e595130230 191 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 192 Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 193 Fixed_Beacon_Packet.Parking1_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 194 Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 195 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 196 Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 197 Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 198 Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 199 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 200 Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 201 Fixed_Beacon_Packet.Parking3_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 202 Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 203 CheckIN_Lora_Packet.FCS = 0x00; //FCS of all packets
NarendraSingh 11:77e595130230 204
NarendraSingh 11:77e595130230 205 /******* Initialize Lora packet for Movement *****/
NarendraSingh 11:77e595130230 206 Motion_Lora_Packet.Header = LORA_PACKET_HEADER;
NarendraSingh 11:77e595130230 207 Motion_Lora_Packet.Protocol_Version = OBD_Protocol_Version;
NarendraSingh 11:77e595130230 208 Motion_Lora_Packet.Packet_Type = MOTION_PACKET_CMD;
NarendraSingh 11:77e595130230 209 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 210 Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 211 Fixed_Beacon_Packet.Parking1_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 212 Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00; //Signal Strength of 1st NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 213 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 214 Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 2nd NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 215 Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 216 Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 2nd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 217 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 218 Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00; //MAC ID of 3rd NearBy Beacon Device with Highest Signal Strength,dummy data
NarendraSingh 16:7703b9d92326 219 Fixed_Beacon_Packet.Parking3_Beacon_Minor = 0x0000;
NarendraSingh 16:7703b9d92326 220 Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength
NarendraSingh 11:77e595130230 221 Motion_Lora_Packet.Acceleration_Type = 0x00; //Type of acceleration, Vehicle Started/Vehicle Stopped/Sudden Vehicle Movement
NarendraSingh 11:77e595130230 222 Motion_Lora_Packet.FCS = 0x00; //FCS of all packets
NarendraSingh 14:144ed8b74713 223
NarendraSingh 11:77e595130230 224 }
NarendraSingh 16:7703b9d92326 225
NarendraSingh 11:77e595130230 226 //HeartBeat Packet should be sent every 30sec
NarendraSingh 11:77e595130230 227 void Send_HeartBeat_Packet(void)
NarendraSingh 11:77e595130230 228 {
NarendraSingh 11:77e595130230 229 //write code to read obd data,temperature,beacon data
NarendraSingh 11:77e595130230 230 uint8 Pos = 0,i;
NarendraSingh 11:77e595130230 231 Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Header; //Header of Lora Packet,0xFE
NarendraSingh 11:77e595130230 232 Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Protocol_Version;
NarendraSingh 11:77e595130230 233 Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Packet_Type; //MSB of Motion Packet Type
NarendraSingh 11:77e595130230 234 Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 235 Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 236 Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
NarendraSingh 11:77e595130230 237 Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
NarendraSingh 11:77e595130230 238 Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.OBD_Battery_Temperature; //Get Battery Temperature
NarendraSingh 11:77e595130230 239 Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Car_Ambient_Temperature; //Get Ambient Temperature
NarendraSingh 11:77e595130230 240 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 241 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 16:7703b9d92326 242 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor >> 8); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 243 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 244 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 11:77e595130230 245 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 246 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 16:7703b9d92326 247 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor >> 8); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 248 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 249 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 11:77e595130230 250 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 251 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 16:7703b9d92326 252 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 253 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 254 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 11:77e595130230 255 Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes
NarendraSingh 11:77e595130230 256 Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET;
NarendraSingh 11:77e595130230 257 Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos);
NarendraSingh 11:77e595130230 258 }
NarendraSingh 11:77e595130230 259
NarendraSingh 11:77e595130230 260 //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
NarendraSingh 11:77e595130230 261 void Send_Vehicle_Status_Packet(void)
NarendraSingh 11:77e595130230 262 {
NarendraSingh 11:77e595130230 263 //write code to read OBD data,temperature,beacon data
NarendraSingh 11:77e595130230 264 uint8 Pos = 0,i;
NarendraSingh 11:77e595130230 265 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Header; //Header of Lora Packet,0xFE
NarendraSingh 11:77e595130230 266 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Protocol_Version; //MSB of Motion Packet Type
NarendraSingh 11:77e595130230 267 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Packet_Type; //MSB of Motion Packet Type
NarendraSingh 11:77e595130230 268 for(i=0;i < 17;i++)
NarendraSingh 11:77e595130230 269 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.VIN[i]; //Get OBD_ID
NarendraSingh 11:77e595130230 270 for(i=0;i < 3;i++)
NarendraSingh 11:77e595130230 271 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.ODO_METER_READING[i]; //Get OBD_ID
NarendraSingh 11:77e595130230 272 Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Fuel_Level >> 8); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 273 Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Fuel_Level & 0xFF); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 274 Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 275 Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 276 Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
NarendraSingh 11:77e595130230 277 Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
NarendraSingh 11:77e595130230 278 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.OBD_Battery_Temperature; //Get Battery Temperature
NarendraSingh 11:77e595130230 279 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Car_Ambient_Temperature; //Get Ambient Temperature
NarendraSingh 11:77e595130230 280 for(i=0;i<6;i++)
NarendraSingh 11:77e595130230 281 Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.BLE_Adv_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 11:77e595130230 282 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 283 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 16:7703b9d92326 284 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor >> 8); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 285 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 286 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 11:77e595130230 287 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 288 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 16:7703b9d92326 289 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor >> 8); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 290 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 291 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 11:77e595130230 292 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 293 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 16:7703b9d92326 294 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 295 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 296 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 11:77e595130230 297 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 298 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 16:7703b9d92326 299 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor >> 8); //Get Near Car1 Minor
NarendraSingh 16:7703b9d92326 300 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor & 0xFF); //Get Near Car1 Minor
NarendraSingh 16:7703b9d92326 301 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 11:77e595130230 302 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 303 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 16:7703b9d92326 304 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor >> 8); //Get Near Car2 Minor
NarendraSingh 16:7703b9d92326 305 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor & 0xFF); //Get Near Car2 Minor
NarendraSingh 16:7703b9d92326 306 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 11:77e595130230 307 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 308 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 16:7703b9d92326 309 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor >> 8); //Get Near Car3 Minor
NarendraSingh 16:7703b9d92326 310 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor & 0xFF); //Get Near Car3 Minor
NarendraSingh 16:7703b9d92326 311 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 11:77e595130230 312 Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes
NarendraSingh 11:77e595130230 313 CheckIN_Packet_Sent_Count++;
NarendraSingh 11:77e595130230 314 Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos);
NarendraSingh 11:77e595130230 315 }
NarendraSingh 11:77e595130230 316
NarendraSingh 11:77e595130230 317 //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
NarendraSingh 11:77e595130230 318 void Send_CheckIN_Packet(void)
NarendraSingh 11:77e595130230 319 {
NarendraSingh 11:77e595130230 320 //write code to read OBD data,temperature,beacon data
NarendraSingh 11:77e595130230 321 uint8 Pos = 0,i;
NarendraSingh 11:77e595130230 322 Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.Header; //Header of Lora Packet,0xFE
NarendraSingh 11:77e595130230 323 Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.Protocol_Version; //MSB of Motion Packet Type
NarendraSingh 16:7703b9d92326 324 if(OBD_PlugIN_State)
NarendraSingh 16:7703b9d92326 325 Lora_Packet_To_Send[Pos++] = CHECK_IN_PACKET; //Check detected. Set packet type to Checkout type
NarendraSingh 16:7703b9d92326 326 else
NarendraSingh 16:7703b9d92326 327 Lora_Packet_To_Send[Pos++] = CHECK_OUT_PACKET; //Checkout detected. Set packet type to Checkout type
NarendraSingh 11:77e595130230 328 for(i=0;i < 17;i++)
NarendraSingh 11:77e595130230 329 Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.VIN[i]; //Get OBD_ID
NarendraSingh 11:77e595130230 330 for(i=0;i < 3;i++)
NarendraSingh 11:77e595130230 331 Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.ODO_METER_READING[i]; //Get OBD_ID
NarendraSingh 11:77e595130230 332 Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 333 Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage
NarendraSingh 11:77e595130230 334 Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
NarendraSingh 11:77e595130230 335 Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
NarendraSingh 11:77e595130230 336 Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.OBD_Battery_Temperature; //Get Battery Temperature
NarendraSingh 11:77e595130230 337 Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.Car_Ambient_Temperature; //Get Ambient Temperature
NarendraSingh 11:77e595130230 338 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 339 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 16:7703b9d92326 340 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor >> 8); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 341 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 342 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 11:77e595130230 343 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 344 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 16:7703b9d92326 345 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor >> 8); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 346 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 347 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 11:77e595130230 348 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 349 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 16:7703b9d92326 350 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 351 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 352 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 11:77e595130230 353 Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes
NarendraSingh 11:77e595130230 354 CheckIN_Packet_Sent_Count++;
NarendraSingh 11:77e595130230 355 Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos);
NarendraSingh 11:77e595130230 356 }
NarendraSingh 11:77e595130230 357
NarendraSingh 18:86f069689502 358
NarendraSingh 18:86f069689502 359 //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
NarendraSingh 18:86f069689502 360 void Send_CheckOUT_Packet(void)
NarendraSingh 18:86f069689502 361 {
NarendraSingh 18:86f069689502 362 //write code to read OBD data,temperature,beacon data
NarendraSingh 18:86f069689502 363 uint8 Pos = 0,i;
NarendraSingh 18:86f069689502 364 Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.Header; //Header of Lora Packet,0xFE
NarendraSingh 18:86f069689502 365 Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.Protocol_Version; //MSB of Motion Packet Type
NarendraSingh 18:86f069689502 366 Lora_Packet_To_Send[Pos++] = CHECK_OUT_PACKET; //Checkout detected. Set packet type to Checkout type
NarendraSingh 18:86f069689502 367 for(i=0;i < 17;i++)
NarendraSingh 18:86f069689502 368 Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.VIN[i]; //Get OBD_ID
NarendraSingh 18:86f069689502 369 for(i=0;i < 3;i++)
NarendraSingh 18:86f069689502 370 Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.ODO_METER_READING[i]; //Get OBD_ID
NarendraSingh 18:86f069689502 371 Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage
NarendraSingh 18:86f069689502 372 Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage
NarendraSingh 18:86f069689502 373 Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature
NarendraSingh 18:86f069689502 374 Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature
NarendraSingh 18:86f069689502 375 Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.OBD_Battery_Temperature; //Get Battery Temperature
NarendraSingh 18:86f069689502 376 Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.Car_Ambient_Temperature; //Get Ambient Temperature
NarendraSingh 18:86f069689502 377 for(i=0;i<6;i++)
NarendraSingh 18:86f069689502 378 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 18:86f069689502 379 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor >> 8); //Get Parking1 Minor
NarendraSingh 18:86f069689502 380 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor
NarendraSingh 18:86f069689502 381 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 18:86f069689502 382 for(i=0;i<6;i++)
NarendraSingh 18:86f069689502 383 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 18:86f069689502 384 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor >> 8); //Get Parking2 Minor
NarendraSingh 18:86f069689502 385 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor
NarendraSingh 18:86f069689502 386 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 18:86f069689502 387 for(i=0;i<6;i++)
NarendraSingh 18:86f069689502 388 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 18:86f069689502 389 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor
NarendraSingh 18:86f069689502 390 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor
NarendraSingh 18:86f069689502 391 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 18:86f069689502 392 Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes
NarendraSingh 18:86f069689502 393 CheckIN_Packet_Sent_Count++;
NarendraSingh 18:86f069689502 394 Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos);
NarendraSingh 18:86f069689502 395 }
NarendraSingh 18:86f069689502 396
NarendraSingh 11:77e595130230 397 //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.
NarendraSingh 11:77e595130230 398 // It should be sent every 30sec for 2minutes and afterthat it should stop sending
NarendraSingh 11:77e595130230 399 void Send_Motion_Packet(void)
NarendraSingh 11:77e595130230 400 {
NarendraSingh 11:77e595130230 401 //write code to read accelerometer data,temperature,beacon data
NarendraSingh 11:77e595130230 402 uint8 Pos = 0,i;
NarendraSingh 11:77e595130230 403 Lora_Packet_To_Send[Pos++] = Motion_Lora_Packet.Header; //Header of Lora Packet,0xFE
NarendraSingh 11:77e595130230 404 Lora_Packet_To_Send[Pos++] = (Motion_Lora_Packet.Packet_Type >> 8); //MSB of Motion Packet Type
NarendraSingh 11:77e595130230 405 Lora_Packet_To_Send[Pos++] = (Motion_Lora_Packet.Packet_Type & 0xFF); //LSB of Motion Packet Type
NarendraSingh 11:77e595130230 406 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 407 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 16:7703b9d92326 408 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor >> 8); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 409 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor
NarendraSingh 16:7703b9d92326 410 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 11:77e595130230 411 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 412 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 16:7703b9d92326 413 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor >> 8); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 414 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor
NarendraSingh 16:7703b9d92326 415 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 11:77e595130230 416 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 417 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 16:7703b9d92326 418 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 419 Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor
NarendraSingh 16:7703b9d92326 420 Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 14:144ed8b74713 421 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 422 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 16:7703b9d92326 423 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor >> 8); //Get Near_Car1 Minor
NarendraSingh 16:7703b9d92326 424 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor & 0xFF); //Get Near_Car1 Minor
NarendraSingh 16:7703b9d92326 425 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 14:144ed8b74713 426 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 427 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 16:7703b9d92326 428 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor >> 8); //Get Near_Car2 Minor
NarendraSingh 16:7703b9d92326 429 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor & 0xFF); //Get Near_Car2 Minor
NarendraSingh 16:7703b9d92326 430 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 14:144ed8b74713 431 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 432 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 16:7703b9d92326 433 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor >> 8); //Get Near_Car3 Minor
NarendraSingh 16:7703b9d92326 434 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor & 0xFF); //Get Near_Car3 Minor
NarendraSingh 16:7703b9d92326 435 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 11:77e595130230 436 Lora_Packet_To_Send[Pos++] = Motion_Lora_Packet.Acceleration_Type; //get Type of Acceleration
NarendraSingh 14:144ed8b74713 437 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 438 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device
NarendraSingh 16:7703b9d92326 439 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor >> 8); //Get Near Car1 Minor
NarendraSingh 16:7703b9d92326 440 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor & 0xFF); //Get Near Car1 Minor
NarendraSingh 16:7703b9d92326 441 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device
NarendraSingh 14:144ed8b74713 442 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 443 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device
NarendraSingh 16:7703b9d92326 444 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor >> 8); //Get Near Car2 Minor
NarendraSingh 16:7703b9d92326 445 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor & 0xFF); //Get Near Car2 Minor
NarendraSingh 16:7703b9d92326 446 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device
NarendraSingh 14:144ed8b74713 447 for(i=0;i<6;i++)
NarendraSingh 16:7703b9d92326 448 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device
NarendraSingh 16:7703b9d92326 449 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor >> 8); //Get Near Car3 Minor
NarendraSingh 16:7703b9d92326 450 Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor & 0xFF); //Get Near Car3 Minor
NarendraSingh 16:7703b9d92326 451 Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device
NarendraSingh 11:77e595130230 452 Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes
NarendraSingh 11:77e595130230 453 Motion_Packet_Sent_Count++;
NarendraSingh 11:77e595130230 454 Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos);
NarendraSingh 11:77e595130230 455 }
NarendraSingh 11:77e595130230 456
NarendraSingh 11:77e595130230 457
NarendraSingh 11:77e595130230 458 void Get_Lora_Response(void)
NarendraSingh 11:77e595130230 459 {
NarendraSingh 11:77e595130230 460 static uint16 Temp_Pos1;
NarendraSingh 11:77e595130230 461 static uint8 Lora_Response_Found = 0x00;
NarendraSingh 11:77e595130230 462 static uint8 Response_Start_Pos[5];
NarendraSingh 11:77e595130230 463 Lora_Response_Found = 0;
NarendraSingh 11:77e595130230 464 Temp_Pos1 = LORA_UART_RX_Crnt_Pos = 0;
NarendraSingh 11:77e595130230 465 while(Temp_Pos1 < Lora_RxBuffer_End_Pos)
NarendraSingh 11:77e595130230 466 { //check for end of AT response to calculate length
NarendraSingh 11:77e595130230 467 if((LORA_UART_RX_Buffer[Temp_Pos1] != 0x0D) || (LORA_UART_RX_Buffer[Temp_Pos1+1] != 0x0A))
NarendraSingh 11:77e595130230 468 { //check for AT end response <cr><lf> (i.e. 0x0D,0x0A)
NarendraSingh 11:77e595130230 469 Temp_Pos1++;
NarendraSingh 11:77e595130230 470 }
NarendraSingh 11:77e595130230 471 else
NarendraSingh 11:77e595130230 472 {
NarendraSingh 11:77e595130230 473 Temp_Pos1+=2;
NarendraSingh 11:77e595130230 474 Response_Start_Pos[Lora_Response_Found++] = Temp_Pos1;
NarendraSingh 17:758fb8454ab0 475 //pc2.printf("%c",Temp_Pos1);
NarendraSingh 11:77e595130230 476 if(Lora_Response_Found >= 4)
NarendraSingh 11:77e595130230 477 break;
NarendraSingh 11:77e595130230 478 }
NarendraSingh 11:77e595130230 479 }
NarendraSingh 11:77e595130230 480 if(Lora_Response_Found >= 3)
NarendraSingh 11:77e595130230 481 {
NarendraSingh 11:77e595130230 482 if((Response_Start_Pos[1] - Response_Start_Pos[0]) > 0x02) //Response received without data
NarendraSingh 11:77e595130230 483 {
NarendraSingh 11:77e595130230 484 LORA_UART_RX_Crnt_Pos = (Response_Start_Pos[0]);
NarendraSingh 11:77e595130230 485 Response_Start_Pos[1]-=2;
NarendraSingh 11:77e595130230 486 for(Temp_Pos1=0; LORA_UART_RX_Crnt_Pos < Response_Start_Pos[1]; Temp_Pos1++)
NarendraSingh 11:77e595130230 487 {
NarendraSingh 11:77e595130230 488 Lora_Command_Rcvd[Temp_Pos1] = LORA_UART_RX_Buffer[LORA_UART_RX_Crnt_Pos++];
NarendraSingh 17:758fb8454ab0 489 pc2.putc(Lora_Command_Rcvd[Temp_Pos1]);
NarendraSingh 11:77e595130230 490 }
NarendraSingh 11:77e595130230 491 Lora_RxBuffer_End_Pos = 0;
NarendraSingh 11:77e595130230 492 AT_Response_Receive_Status = SUCCESS;
NarendraSingh 11:77e595130230 493 }
NarendraSingh 11:77e595130230 494 else if((Response_Start_Pos[1] - Response_Start_Pos[0]) == 0x02) //Response received along with data
NarendraSingh 11:77e595130230 495 {
NarendraSingh 11:77e595130230 496 LORA_UART_RX_Crnt_Pos = (Response_Start_Pos[1]);
NarendraSingh 11:77e595130230 497 Response_Start_Pos[2]-=2;
NarendraSingh 11:77e595130230 498 for(Temp_Pos1=0; LORA_UART_RX_Crnt_Pos < Response_Start_Pos[2]; Temp_Pos1++)
NarendraSingh 11:77e595130230 499 {
NarendraSingh 11:77e595130230 500 Lora_Command_Rcvd[Temp_Pos1] = LORA_UART_RX_Buffer[LORA_UART_RX_Crnt_Pos++];
NarendraSingh 17:758fb8454ab0 501 pc2.putc(Lora_Command_Rcvd[Temp_Pos1]);
NarendraSingh 11:77e595130230 502 }
NarendraSingh 11:77e595130230 503 Lora_RxBuffer_End_Pos = 0;
NarendraSingh 11:77e595130230 504 AT_Response_Receive_Status = SUCCESS;
NarendraSingh 11:77e595130230 505 }
NarendraSingh 11:77e595130230 506 }
NarendraSingh 11:77e595130230 507 }
NarendraSingh 11:77e595130230 508
NarendraSingh 11:77e595130230 509 //Function to send general Lora packets using "AT+SEND" Command
NarendraSingh 11:77e595130230 510 void Send_Lora_Packet_To_Gateway(uint8* Command_To_Send,uint8 Length)
NarendraSingh 11:77e595130230 511 {
NarendraSingh 11:77e595130230 512 uint8 i=0;
NarendraSingh 11:77e595130230 513 LORA_Module_UART.printf("%s",Send_Lora_Packet);//write to serial port for sending through lora module
NarendraSingh 11:77e595130230 514 for(i=0;i<Length;i++)
NarendraSingh 13:8955f2e95021 515 {
NarendraSingh 11:77e595130230 516 LORA_Module_UART.putc(Command_To_Send[i]);//write to serial port for sending through lora module
NarendraSingh 17:758fb8454ab0 517 pc2.putc(Command_To_Send[i]);
NarendraSingh 13:8955f2e95021 518 }
NarendraSingh 11:77e595130230 519 LORA_Module_UART.printf("\r");
NarendraSingh 11:77e595130230 520 }
NarendraSingh 11:77e595130230 521
NarendraSingh 11:77e595130230 522
NarendraSingh 11:77e595130230 523 unsigned char Calculate_Lora_Frame_FCS(unsigned char* Packet_Data,unsigned char Packet_Length)
NarendraSingh 11:77e595130230 524 {
NarendraSingh 11:77e595130230 525 uint8 i,FCS = 0x00;
NarendraSingh 11:77e595130230 526 for(i=0; i < Packet_Length; i++)
NarendraSingh 11:77e595130230 527 {
NarendraSingh 11:77e595130230 528 FCS ^= (Packet_Data[i]);
NarendraSingh 11:77e595130230 529 }
NarendraSingh 11:77e595130230 530 return(FCS);
NarendraSingh 11:77e595130230 531 }