kumar singh
/
Dealer_23Feb
Dummy Lora Packet Sending
Fork of Dealer_18feb17 by
Diff: Lora.cpp
- Revision:
- 19:886d50ecc718
- Parent:
- 18:86f069689502
- Child:
- 20:f812f85cf97e
--- a/Lora.cpp Sat Feb 18 08:52:04 2017 +0000 +++ b/Lora.cpp Tue Feb 21 06:27:13 2017 +0000 @@ -31,7 +31,8 @@ Vehicle_Status_PacketType Vehicle_Status_Lora_Packet; //Allocate Memory for Movement Lora Packets Near_Car_Beacon Near_Car_Beacon_Packet; Fixed_Beacon Fixed_Beacon_Packet; - + Misc_Packets Misc_Packet_Data; + //Lora AT Commands list const char* Attention = {"AT\r"}; const char* Reset_Device = "ATZ\r"; @@ -84,13 +85,14 @@ Get_Lora_Response(); pc2.printf("Network Id response received"); - //LORA_Module_UART.printf("%s",Reset_Device); //reset device - //wait_ms(3500); - LORA_Module_UART.printf("AT+TXDR=DR2\r"); AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) Get_Lora_Response(); + LORA_Module_UART.printf("AT+RXDR=10\r"); + AT_Response_Receive_Status = FAILURE; + while(AT_Response_Receive_Status) + Get_Lora_Response(); LORA_Module_UART.printf("AT+ADR=1\r"); //Enable adaptive data rate AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) @@ -119,104 +121,108 @@ uint8 i; /******* Initialize Lora packet for HeartBeat *****/ Heart_Beat_Lora_Packet.Header = LORA_PACKET_HEADER; - Heart_Beat_Lora_Packet.Protocol_Version = OBD_Protocol_Version; + Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; Heart_Beat_Lora_Packet.Packet_Type = HEART_BEAT_PACKET_CMD; - 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 + Misc_Packet_Data.OBD_Battery_Voltage = 350; //3.50V, dummy data + Misc_Packet_Data.Car_Battery_Voltage = 1250; //12.50V, dummy data + Misc_Packet_Data.OBD_Battery_Temperature = 95; //95'F, dummy data + Misc_Packet_Data.Car_Ambient_Temperature = 104; //104'F, dummy data for(i=0;i<6;i++) Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = (0x01+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data - Fixed_Beacon_Packet.Parking1_Beacon_Minor = 0x0000; Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 23; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength for(i=0;i<6;i++) Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = (10+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data - Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0000; 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_Minor = 0x0000; Fixed_Beacon_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; + Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; Vehicle_Status_Lora_Packet.Packet_Type = STATUS_PACKET_CMD; for(i=0;i<17;i++) - Vehicle_Status_Lora_Packet.VIN[i] = (30+i);//Vehicle_Identification_Number[i]; + Misc_Packet_Data.VIN[i] = (30+i);//Vehicle_Identification_Number[i]; for(i=0;i<3;i++) - Vehicle_Status_Lora_Packet.ODO_METER_READING[i] = 0x05; //Dummyy data, To be read using OBD + 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 - 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; + Misc_Packet_Data.OBD_Battery_Voltage = 350; + Misc_Packet_Data.Car_Battery_Voltage = 1250; + Misc_Packet_Data.OBD_Battery_Temperature = 95; + Misc_Packet_Data.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++) 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_Minor = 0x0000; 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_Minor = 0x0000; 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_Minor = 0x0000; 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_Minor = 0x0000; 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_Minor = 0x0000; 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_Minor = 0x0000; 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.FCS = 0x00; //FCS of all packets /******* Initialize Lora packet for CheckIn *****/ CheckIN_Lora_Packet.Header = LORA_PACKET_HEADER; - CheckIN_Lora_Packet.Protocol_Version = OBD_Protocol_Version; + Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; CheckIN_Lora_Packet.Packet_Type = CHECKIN_PACKET_CMD; for(i=0;i<17;i++) - CheckIN_Lora_Packet.VIN[i] = Vehicle_Identification_Number[i]; + Misc_Packet_Data.VIN[i] = Vehicle_Identification_Number[i]; for(i=0;i<3;i++) - CheckIN_Lora_Packet.ODO_METER_READING[i] = 0x00; //Dummyy data, To be read using OBD + Misc_Packet_Data.ODO_METER_READING[i] = 0x00; //Dummyy data, To be read using OBD 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_Minor = 0x0000; Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength for(i=0;i<6;i++) Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data - Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0000; Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength 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_Minor = 0x0000; Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength CheckIN_Lora_Packet.FCS = 0x00; //FCS of all packets + /******* Initialize Lora packet for CheckOUT *****/ + CheckOUT_Packet.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++) + 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<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 + for(i=0;i<6;i++) + Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data + Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength + 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.FCS = 0x00; //FCS of all packets + /******* Initialize Lora packet for Movement *****/ Motion_Lora_Packet.Header = LORA_PACKET_HEADER; - Motion_Lora_Packet.Protocol_Version = OBD_Protocol_Version; + Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; Motion_Lora_Packet.Packet_Type = MOTION_PACKET_CMD; 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_Minor = 0x0000; Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00; //Signal Strength of 1st NearBy Beacon Device with Highest Signal Strength for(i=0;i<6;i++) Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 2nd NearBy Beacon Device with Highest Signal Strength,dummy data - Fixed_Beacon_Packet.Parking2_Beacon_Minor = 0x0000; Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 2nd NearBy Beacon Device with Highest Signal Strength for(i=0;i<6;i++) 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_Minor = 0x0000; 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.FCS = 0x00; //FCS of all packets @@ -229,28 +235,22 @@ //write code to read obd data,temperature,beacon data uint8 Pos = 0,i; Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Header; //Header of Lora Packet,0xFE - Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Protocol_Version; + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version; Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Packet_Type; //MSB of Motion Packet Type - Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = (Heart_Beat_Lora_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.OBD_Battery_Temperature; //Get Battery Temperature - Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Car_Ambient_Temperature; //Get Ambient Temperature + 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++] = Misc_Packet_Data.OBD_Battery_Temperature; //Get Battery Temperature + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature; //Get Ambient Temperature 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_Minor >> 8); //Get Parking1 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor 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_Minor >> 8); //Get Parking2 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor 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++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor 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++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; @@ -263,54 +263,41 @@ //write code to read OBD data,temperature,beacon data uint8 Pos = 0,i; Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Header; //Header of Lora Packet,0xFE - Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Protocol_Version; //MSB of Motion Packet Type + 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 for(i=0;i < 17;i++) - Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.VIN[i]; //Get OBD_ID + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i]; //Get OBD_ID for(i=0;i < 3;i++) - Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.ODO_METER_READING[i]; //Get OBD_ID + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.ODO_METER_READING[i]; //Get OBD_ID Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Fuel_Level >> 8); //Get OBD_Battery Voltage Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Fuel_Level & 0xFF); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.OBD_Battery_Temperature; //Get Battery Temperature - Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Car_Ambient_Temperature; //Get Ambient Temperature + 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++] = Misc_Packet_Data.OBD_Battery_Temperature; //Get Battery Temperature + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature; //Get Ambient Temperature for(i=0;i<6;i++) 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_Minor >> 8); //Get Parking1 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor 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_Minor >> 8); //Get Parking2 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor 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++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device for(i=0;i<6;i++) Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor >> 8); //Get Near Car1 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor & 0xFF); //Get Near Car1 Minor Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device for(i=0;i<6;i++) Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor >> 8); //Get Near Car2 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor & 0xFF); //Get Near Car2 Minor 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++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor >> 8); //Get Near Car3 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor & 0xFF); //Get Near Car3 Minor 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++] = 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); } @@ -320,39 +307,34 @@ //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++] = CheckIN_Lora_Packet.Protocol_Version; //MSB of Motion Packet Type + 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 for(i=0;i < 17;i++) - Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.VIN[i]; //Get OBD_ID + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i]; //Get OBD_ID for(i=0;i < 3;i++) - Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.ODO_METER_READING[i]; //Get OBD_ID - Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = (CheckIN_Lora_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.OBD_Battery_Temperature; //Get Battery Temperature - Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.Car_Ambient_Temperature; //Get Ambient Temperature + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.ODO_METER_READING[i]; //Get OBD_ID + 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++] = Misc_Packet_Data.OBD_Battery_Temperature; //Get Battery Temperature + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature; //Get Ambient Temperature 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_Minor >> 8); //Get Parking1 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor 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_Minor >> 8); //Get Parking2 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor 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++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor 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++] = 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"); } @@ -362,36 +344,23 @@ //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++] = CheckOUT_Packet.Protocol_Version; //MSB of Motion Packet Type + 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 for(i=0;i < 17;i++) - Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.VIN[i]; //Get OBD_ID - for(i=0;i < 3;i++) - Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.ODO_METER_READING[i]; //Get OBD_ID - Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage - Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = (CheckOUT_Packet.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature - Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.OBD_Battery_Temperature; //Get Battery Temperature - Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.Car_Ambient_Temperature; //Get Ambient Temperature - 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_Minor >> 8); //Get Parking1 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor - 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_Minor >> 8); //Get Parking2 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor - 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++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor - 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++] = 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 + 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++] = 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++] = 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"); + } //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. @@ -401,53 +370,35 @@ //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++] = (Motion_Lora_Packet.Packet_Type >> 8); //MSB of Motion Packet Type + Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version; //Protocol Version 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 - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor >> 8); //Get Parking1 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking1_Beacon_Minor & 0xFF); //Get Parking1 Minor 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_Minor >> 8); //Get Parking2 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking2_Beacon_Minor & 0xFF); //Get Parking2 Minor 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++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor >> 8); //Get Parking3 Minor - Lora_Packet_To_Send[Pos++] = (Fixed_Beacon_Packet.Parking3_Beacon_Minor & 0xFF); //Get Parking3 Minor Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device for(i=0;i<6;i++) Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor >> 8); //Get Near_Car1 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor & 0xFF); //Get Near_Car1 Minor Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device for(i=0;i<6;i++) Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor >> 8); //Get Near_Car2 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor & 0xFF); //Get Near_Car2 Minor 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++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor >> 8); //Get Near_Car3 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor & 0xFF); //Get Near_Car3 Minor 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.Acceleration_Type; //get Type of Acceleration for(i=0;i<6;i++) Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor >> 8); //Get Near Car1 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car1_Beacon_Minor & 0xFF); //Get Near Car1 Minor Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device for(i=0;i<6;i++) Lora_Packet_To_Send[Pos++] = Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor >> 8); //Get Near Car2 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car2_Beacon_Minor & 0xFF); //Get Near Car2 Minor 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++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor >> 8); //Get Near Car3 Minor - Lora_Packet_To_Send[Pos++] = (Near_Car_Beacon_Packet.Near_Car3_Beacon_Minor & 0xFF); //Get Near Car3 Minor 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++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes Motion_Packet_Sent_Count++; @@ -511,11 +462,7 @@ { 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 - pc2.putc(Command_To_Send[i]); - } + LORA_Module_UART.printf("%s",Command_To_Send); LORA_Module_UART.printf("\r"); }