BLE Transmitter not working

Fork of Dealer_23Feb by kumar singh

Committer:
NarendraSingh
Date:
Mon Mar 20 02:44:45 2017 +0000
Revision:
26:506380fccce2
Parent:
24:1063cfc311e5
Before troubleshooting BLE Transmitter

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