Dummy Lora Packet Sending

Fork of Dealer_18feb17 by kumar singh

Committer:
NarendraSingh
Date:
Thu Feb 23 08:15:58 2017 +0000
Revision:
23:688ee106c385
Parent:
22:c2f034a13108
Child:
24:1063cfc311e5
basic lora packet sending working.

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