kumar singh
/
Dealer_23Feb
Dummy Lora Packet Sending
Fork of Dealer_18feb17 by
Lora.cpp@19:886d50ecc718, 2017-02-21 (annotated)
- Committer:
- NarendraSingh
- Date:
- Tue Feb 21 06:27:13 2017 +0000
- Revision:
- 19:886d50ecc718
- Parent:
- 18:86f069689502
- Child:
- 20:f812f85cf97e
beacon receiver21feb17
Who changed what in which revision?
User | Revision | Line number | New 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 | 11:77e595130230 | 88 | LORA_Module_UART.printf("AT+TXDR=DR2\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 | 11:77e595130230 | 96 | LORA_Module_UART.printf("AT+ADR=1\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 | 17:758fb8454ab0 | 104 | pc2.printf("Configuration saved"); |
NarendraSingh | 13:8955f2e95021 | 105 | LORA_Module_UART.printf("%s",Reset_Device); //reset device |
NarendraSingh | 13:8955f2e95021 | 106 | wait_ms(3500); |
NarendraSingh | 11:77e595130230 | 107 | LORA_Module_UART.printf(Attention); //Send Attention command |
NarendraSingh | 11:77e595130230 | 108 | AT_Response_Receive_Status = FAILURE; |
NarendraSingh | 11:77e595130230 | 109 | while(AT_Response_Receive_Status) |
NarendraSingh | 11:77e595130230 | 110 | Get_Lora_Response(); |
NarendraSingh | 17:758fb8454ab0 | 111 | pc2.printf("AT Response received"); |
NarendraSingh | 11:77e595130230 | 112 | LORA_Module_UART.printf("%s",Join_Network); //join network with gateway |
NarendraSingh | 11:77e595130230 | 113 | AT_Response_Receive_Status = FAILURE; |
NarendraSingh | 11:77e595130230 | 114 | while(AT_Response_Receive_Status) |
NarendraSingh | 11:77e595130230 | 115 | Get_Lora_Response(); |
NarendraSingh | 17:758fb8454ab0 | 116 | pc2.printf("Join Response received"); |
NarendraSingh | 11:77e595130230 | 117 | } |
NarendraSingh | 11:77e595130230 | 118 | |
NarendraSingh | 11:77e595130230 | 119 | void Initialize_lora_Packets() |
NarendraSingh | 11:77e595130230 | 120 | { |
NarendraSingh | 11:77e595130230 | 121 | uint8 i; |
NarendraSingh | 11:77e595130230 | 122 | /******* Initialize Lora packet for HeartBeat *****/ |
NarendraSingh | 11:77e595130230 | 123 | Heart_Beat_Lora_Packet.Header = LORA_PACKET_HEADER; |
NarendraSingh | 19:886d50ecc718 | 124 | Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; |
NarendraSingh | 11:77e595130230 | 125 | Heart_Beat_Lora_Packet.Packet_Type = HEART_BEAT_PACKET_CMD; |
NarendraSingh | 19:886d50ecc718 | 126 | Misc_Packet_Data.OBD_Battery_Voltage = 350; //3.50V, dummy data |
NarendraSingh | 19:886d50ecc718 | 127 | Misc_Packet_Data.Car_Battery_Voltage = 1250; //12.50V, dummy data |
NarendraSingh | 19:886d50ecc718 | 128 | Misc_Packet_Data.OBD_Battery_Temperature = 95; //95'F, dummy data |
NarendraSingh | 19:886d50ecc718 | 129 | Misc_Packet_Data.Car_Ambient_Temperature = 104; //104'F, dummy data |
NarendraSingh | 11:77e595130230 | 130 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 131 | 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 | 132 | Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 23; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 133 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 134 | 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 | 135 | Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 45; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 136 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 137 | Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = (20+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 138 | Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 12; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 139 | Heart_Beat_Lora_Packet.FCS = 0x00; //FCS of all packets |
NarendraSingh | 11:77e595130230 | 140 | |
NarendraSingh | 11:77e595130230 | 141 | /******* Initialize Lora packet for Vehicle Status *****/ |
NarendraSingh | 11:77e595130230 | 142 | Vehicle_Status_Lora_Packet.Header = LORA_PACKET_HEADER; |
NarendraSingh | 19:886d50ecc718 | 143 | Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; |
NarendraSingh | 13:8955f2e95021 | 144 | Vehicle_Status_Lora_Packet.Packet_Type = STATUS_PACKET_CMD; |
NarendraSingh | 11:77e595130230 | 145 | for(i=0;i<17;i++) |
NarendraSingh | 19:886d50ecc718 | 146 | Misc_Packet_Data.VIN[i] = (30+i);//Vehicle_Identification_Number[i]; |
NarendraSingh | 11:77e595130230 | 147 | for(i=0;i<3;i++) |
NarendraSingh | 19:886d50ecc718 | 148 | Misc_Packet_Data.ODO_METER_READING[i] = 0x05; //Dummyy data, To be read using OBD |
NarendraSingh | 13:8955f2e95021 | 149 | Vehicle_Status_Lora_Packet.Fuel_Level = 1050;//10.5 litre |
NarendraSingh | 19:886d50ecc718 | 150 | Misc_Packet_Data.OBD_Battery_Voltage = 350; |
NarendraSingh | 19:886d50ecc718 | 151 | Misc_Packet_Data.Car_Battery_Voltage = 1250; |
NarendraSingh | 19:886d50ecc718 | 152 | Misc_Packet_Data.OBD_Battery_Temperature = 95; |
NarendraSingh | 19:886d50ecc718 | 153 | Misc_Packet_Data.Car_Ambient_Temperature = 104; |
NarendraSingh | 11:77e595130230 | 154 | for(i=0;i<6;i++) |
NarendraSingh | 11:77e595130230 | 155 | 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 | 156 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 157 | Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = (30+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 158 | Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x07; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 13:8955f2e95021 | 159 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 160 | Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = (40+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 161 | Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x08; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 13:8955f2e95021 | 162 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 163 | Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = (50+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 164 | Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 165 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 166 | Near_Car_Beacon_Packet.Near_Car1_Beacon_ID[i] = (60+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 167 | Near_Car_Beacon_Packet.Near_Car1_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 168 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 169 | Near_Car_Beacon_Packet.Near_Car2_Beacon_ID[i] = (70+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 170 | Near_Car_Beacon_Packet.Near_Car2_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 13:8955f2e95021 | 171 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 172 | Near_Car_Beacon_Packet.Near_Car3_Beacon_ID[i] = (80+i); //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 173 | Near_Car_Beacon_Packet.Near_Car3_Beacon_Signal_Strength = 0x09; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 174 | Vehicle_Status_Lora_Packet.FCS = 0x00; //FCS of all packets |
NarendraSingh | 11:77e595130230 | 175 | |
NarendraSingh | 11:77e595130230 | 176 | /******* Initialize Lora packet for CheckIn *****/ |
NarendraSingh | 11:77e595130230 | 177 | CheckIN_Lora_Packet.Header = LORA_PACKET_HEADER; |
NarendraSingh | 19:886d50ecc718 | 178 | Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; |
NarendraSingh | 11:77e595130230 | 179 | CheckIN_Lora_Packet.Packet_Type = CHECKIN_PACKET_CMD; |
NarendraSingh | 11:77e595130230 | 180 | for(i=0;i<17;i++) |
NarendraSingh | 19:886d50ecc718 | 181 | Misc_Packet_Data.VIN[i] = Vehicle_Identification_Number[i]; |
NarendraSingh | 11:77e595130230 | 182 | for(i=0;i<3;i++) |
NarendraSingh | 19:886d50ecc718 | 183 | Misc_Packet_Data.ODO_METER_READING[i] = 0x00; //Dummyy data, To be read using OBD |
NarendraSingh | 11:77e595130230 | 184 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 185 | Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 186 | Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 187 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 188 | Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 189 | Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 190 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 191 | Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 192 | Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 193 | CheckIN_Lora_Packet.FCS = 0x00; //FCS of all packets |
NarendraSingh | 11:77e595130230 | 194 | |
NarendraSingh | 19:886d50ecc718 | 195 | /******* Initialize Lora packet for CheckOUT *****/ |
NarendraSingh | 19:886d50ecc718 | 196 | CheckOUT_Packet.Header = LORA_PACKET_HEADER; |
NarendraSingh | 19:886d50ecc718 | 197 | Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; |
NarendraSingh | 19:886d50ecc718 | 198 | CheckOUT_Packet.Packet_Type = CHECKIN_PACKET_CMD; |
NarendraSingh | 19:886d50ecc718 | 199 | for(i=0;i<17;i++) |
NarendraSingh | 19:886d50ecc718 | 200 | Misc_Packet_Data.VIN[i] = Vehicle_Identification_Number[i]; |
NarendraSingh | 19:886d50ecc718 | 201 | for(i=0;i<3;i++) |
NarendraSingh | 19:886d50ecc718 | 202 | Misc_Packet_Data.ODO_METER_READING[i] = 0x00; //Dummyy data, To be read using OBD |
NarendraSingh | 19:886d50ecc718 | 203 | for(i=0;i<6;i++) |
NarendraSingh | 19:886d50ecc718 | 204 | Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 19:886d50ecc718 | 205 | Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 19:886d50ecc718 | 206 | for(i=0;i<6;i++) |
NarendraSingh | 19:886d50ecc718 | 207 | Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 19:886d50ecc718 | 208 | Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 19:886d50ecc718 | 209 | for(i=0;i<6;i++) |
NarendraSingh | 19:886d50ecc718 | 210 | Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 19:886d50ecc718 | 211 | Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 19:886d50ecc718 | 212 | CheckOUT_Packet.FCS = 0x00; //FCS of all packets |
NarendraSingh | 19:886d50ecc718 | 213 | |
NarendraSingh | 11:77e595130230 | 214 | /******* Initialize Lora packet for Movement *****/ |
NarendraSingh | 11:77e595130230 | 215 | Motion_Lora_Packet.Header = LORA_PACKET_HEADER; |
NarendraSingh | 19:886d50ecc718 | 216 | Misc_Packet_Data.Protocol_Version = OBD_Protocol_Version; |
NarendraSingh | 11:77e595130230 | 217 | Motion_Lora_Packet.Packet_Type = MOTION_PACKET_CMD; |
NarendraSingh | 11:77e595130230 | 218 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 219 | Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = 0x00; //MAC ID of 1st NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 220 | Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0x00; //Signal Strength of 1st NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 221 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 222 | Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = 0x00; //MAC ID of 2nd NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 223 | Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0x00; //Signal Strength of 2nd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 224 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 225 | Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = 0x00; //MAC ID of 3rd NearBy Beacon Device with Highest Signal Strength,dummy data |
NarendraSingh | 16:7703b9d92326 | 226 | Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0x00; //Signal Strength of 3rd NearBy Beacon Device with Highest Signal Strength |
NarendraSingh | 11:77e595130230 | 227 | Motion_Lora_Packet.Acceleration_Type = 0x00; //Type of acceleration, Vehicle Started/Vehicle Stopped/Sudden Vehicle Movement |
NarendraSingh | 11:77e595130230 | 228 | Motion_Lora_Packet.FCS = 0x00; //FCS of all packets |
NarendraSingh | 14:144ed8b74713 | 229 | |
NarendraSingh | 11:77e595130230 | 230 | } |
NarendraSingh | 16:7703b9d92326 | 231 | |
NarendraSingh | 11:77e595130230 | 232 | //HeartBeat Packet should be sent every 30sec |
NarendraSingh | 11:77e595130230 | 233 | void Send_HeartBeat_Packet(void) |
NarendraSingh | 11:77e595130230 | 234 | { |
NarendraSingh | 11:77e595130230 | 235 | //write code to read obd data,temperature,beacon data |
NarendraSingh | 11:77e595130230 | 236 | uint8 Pos = 0,i; |
NarendraSingh | 11:77e595130230 | 237 | Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Header; //Header of Lora Packet,0xFE |
NarendraSingh | 19:886d50ecc718 | 238 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version; |
NarendraSingh | 11:77e595130230 | 239 | Lora_Packet_To_Send[Pos++] = Heart_Beat_Lora_Packet.Packet_Type; //MSB of Motion Packet Type |
NarendraSingh | 19:886d50ecc718 | 240 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 241 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 242 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 243 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 244 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.OBD_Battery_Temperature; //Get Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 245 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature; //Get Ambient Temperature |
NarendraSingh | 11:77e595130230 | 246 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 247 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 248 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 249 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 250 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 251 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 252 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 253 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 254 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 255 | Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes |
NarendraSingh | 11:77e595130230 | 256 | Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; |
NarendraSingh | 11:77e595130230 | 257 | Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); |
NarendraSingh | 11:77e595130230 | 258 | } |
NarendraSingh | 11:77e595130230 | 259 | |
NarendraSingh | 11:77e595130230 | 260 | //CheckIN packets sending should be started when device is plugged in to the vehicle. It should be sent every 5sec for 2minutes and afterthat it should stop sending |
NarendraSingh | 11:77e595130230 | 261 | void Send_Vehicle_Status_Packet(void) |
NarendraSingh | 11:77e595130230 | 262 | { |
NarendraSingh | 11:77e595130230 | 263 | //write code to read OBD data,temperature,beacon data |
NarendraSingh | 11:77e595130230 | 264 | uint8 Pos = 0,i; |
NarendraSingh | 11:77e595130230 | 265 | Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Header; //Header of Lora Packet,0xFE |
NarendraSingh | 19:886d50ecc718 | 266 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version; //MSB of Motion Packet Type |
NarendraSingh | 11:77e595130230 | 267 | Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.Packet_Type; //MSB of Motion Packet Type |
NarendraSingh | 11:77e595130230 | 268 | for(i=0;i < 17;i++) |
NarendraSingh | 19:886d50ecc718 | 269 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i]; //Get OBD_ID |
NarendraSingh | 11:77e595130230 | 270 | for(i=0;i < 3;i++) |
NarendraSingh | 19:886d50ecc718 | 271 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.ODO_METER_READING[i]; //Get OBD_ID |
NarendraSingh | 11:77e595130230 | 272 | Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Fuel_Level >> 8); //Get OBD_Battery Voltage |
NarendraSingh | 11:77e595130230 | 273 | Lora_Packet_To_Send[Pos++] = (Vehicle_Status_Lora_Packet.Fuel_Level & 0xFF); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 274 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 275 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 276 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 277 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 278 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.OBD_Battery_Temperature; //Get Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 279 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature; //Get Ambient Temperature |
NarendraSingh | 11:77e595130230 | 280 | for(i=0;i<6;i++) |
NarendraSingh | 11:77e595130230 | 281 | Lora_Packet_To_Send[Pos++] = Vehicle_Status_Lora_Packet.BLE_Adv_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 282 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 283 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 284 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 285 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 286 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 287 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 288 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 289 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 290 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 291 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 292 | 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 | 293 | 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 | 294 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 295 | 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 | 296 | 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 | 297 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 298 | 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 | 299 | 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 | 300 | Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes |
NarendraSingh | 11:77e595130230 | 301 | Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); |
NarendraSingh | 11:77e595130230 | 302 | } |
NarendraSingh | 11:77e595130230 | 303 | |
NarendraSingh | 11:77e595130230 | 304 | //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 | 305 | void Send_CheckIN_Packet(void) |
NarendraSingh | 11:77e595130230 | 306 | { |
NarendraSingh | 11:77e595130230 | 307 | //write code to read OBD data,temperature,beacon data |
NarendraSingh | 11:77e595130230 | 308 | uint8 Pos = 0,i; |
NarendraSingh | 11:77e595130230 | 309 | Lora_Packet_To_Send[Pos++] = CheckIN_Lora_Packet.Header; //Header of Lora Packet,0xFE |
NarendraSingh | 19:886d50ecc718 | 310 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version; //MSB of Motion Packet Type |
NarendraSingh | 16:7703b9d92326 | 311 | if(OBD_PlugIN_State) |
NarendraSingh | 16:7703b9d92326 | 312 | Lora_Packet_To_Send[Pos++] = CHECK_IN_PACKET; //Check detected. Set packet type to Checkout type |
NarendraSingh | 16:7703b9d92326 | 313 | else |
NarendraSingh | 16:7703b9d92326 | 314 | Lora_Packet_To_Send[Pos++] = CHECK_OUT_PACKET; //Checkout detected. Set packet type to Checkout type |
NarendraSingh | 11:77e595130230 | 315 | for(i=0;i < 17;i++) |
NarendraSingh | 19:886d50ecc718 | 316 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i]; //Get OBD_ID |
NarendraSingh | 11:77e595130230 | 317 | for(i=0;i < 3;i++) |
NarendraSingh | 19:886d50ecc718 | 318 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.ODO_METER_READING[i]; //Get OBD_ID |
NarendraSingh | 19:886d50ecc718 | 319 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 320 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 321 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 322 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 323 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.OBD_Battery_Temperature; //Get Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 324 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature; //Get Ambient Temperature |
NarendraSingh | 11:77e595130230 | 325 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 326 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 327 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 328 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 329 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 330 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 331 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 332 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 333 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 334 | Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes |
NarendraSingh | 11:77e595130230 | 335 | CheckIN_Packet_Sent_Count++; |
NarendraSingh | 11:77e595130230 | 336 | Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); |
NarendraSingh | 19:886d50ecc718 | 337 | pc2.printf("CheckIN Packet Sent"); |
NarendraSingh | 11:77e595130230 | 338 | } |
NarendraSingh | 11:77e595130230 | 339 | |
NarendraSingh | 18:86f069689502 | 340 | |
NarendraSingh | 18:86f069689502 | 341 | //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 | 342 | void Send_CheckOUT_Packet(void) |
NarendraSingh | 18:86f069689502 | 343 | { |
NarendraSingh | 18:86f069689502 | 344 | //write code to read OBD data,temperature,beacon data |
NarendraSingh | 18:86f069689502 | 345 | uint8 Pos = 0,i; |
NarendraSingh | 18:86f069689502 | 346 | Lora_Packet_To_Send[Pos++] = CheckOUT_Packet.Header; //Header of Lora Packet,0xFE |
NarendraSingh | 19:886d50ecc718 | 347 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version; //MSB of Motion Packet Type |
NarendraSingh | 18:86f069689502 | 348 | Lora_Packet_To_Send[Pos++] = CHECK_OUT_PACKET; //Checkout detected. Set packet type to Checkout type |
NarendraSingh | 18:86f069689502 | 349 | for(i=0;i < 17;i++) |
NarendraSingh | 19:886d50ecc718 | 350 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.VIN[i]; //Get OBD_ID |
NarendraSingh | 19:886d50ecc718 | 351 | for(i=0;i < 3;i++) |
NarendraSingh | 19:886d50ecc718 | 352 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.ODO_METER_READING[i]; //Get OBD_ID |
NarendraSingh | 19:886d50ecc718 | 353 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage >> 8); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 354 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.OBD_Battery_Voltage & 0xFF); //Get OBD_Battery Voltage |
NarendraSingh | 19:886d50ecc718 | 355 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage >> 8); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 356 | Lora_Packet_To_Send[Pos++] = (Misc_Packet_Data.Car_Battery_Voltage & 0xFF); //Get Vehicle_Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 357 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.OBD_Battery_Temperature; //Get Battery Temperature |
NarendraSingh | 19:886d50ecc718 | 358 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Car_Ambient_Temperature; //Get Ambient Temperature |
NarendraSingh | 18:86f069689502 | 359 | Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes |
NarendraSingh | 18:86f069689502 | 360 | CheckIN_Packet_Sent_Count++; |
NarendraSingh | 18:86f069689502 | 361 | Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); |
NarendraSingh | 19:886d50ecc718 | 362 | pc2.printf("CheckOUT Packet Sent"); |
NarendraSingh | 19:886d50ecc718 | 363 | |
NarendraSingh | 18:86f069689502 | 364 | } |
NarendraSingh | 18:86f069689502 | 365 | |
NarendraSingh | 11:77e595130230 | 366 | //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 | 367 | // It should be sent every 30sec for 2minutes and afterthat it should stop sending |
NarendraSingh | 11:77e595130230 | 368 | void Send_Motion_Packet(void) |
NarendraSingh | 11:77e595130230 | 369 | { |
NarendraSingh | 11:77e595130230 | 370 | //write code to read accelerometer data,temperature,beacon data |
NarendraSingh | 11:77e595130230 | 371 | uint8 Pos = 0,i; |
NarendraSingh | 11:77e595130230 | 372 | Lora_Packet_To_Send[Pos++] = Motion_Lora_Packet.Header; //Header of Lora Packet,0xFE |
NarendraSingh | 19:886d50ecc718 | 373 | Lora_Packet_To_Send[Pos++] = Misc_Packet_Data.Protocol_Version; //Protocol Version |
NarendraSingh | 11:77e595130230 | 374 | Lora_Packet_To_Send[Pos++] = (Motion_Lora_Packet.Packet_Type & 0xFF); //LSB of Motion Packet Type |
NarendraSingh | 11:77e595130230 | 375 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 376 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_ID[i]; //Get Beacon_ID of 1st nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 377 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength; //Get Signal Strength of 1st nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 378 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 379 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_ID[i]; //Get Beacon_ID of 2nd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 380 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength; //Get Signal Strength of 2nd nearby Beacon Device |
NarendraSingh | 11:77e595130230 | 381 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 382 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_ID[i]; //Get Beacon_ID of 3rd nearby Beacon Device |
NarendraSingh | 16:7703b9d92326 | 383 | Lora_Packet_To_Send[Pos++] = Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength; //Get Signal Strength of 3rd nearby Beacon Device |
NarendraSingh | 14:144ed8b74713 | 384 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 385 | 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 | 386 | 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 | 387 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 388 | 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 | 389 | 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 | 390 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 391 | 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 | 392 | 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 | 393 | Lora_Packet_To_Send[Pos++] = Motion_Lora_Packet.Acceleration_Type; //get Type of Acceleration |
NarendraSingh | 14:144ed8b74713 | 394 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 395 | 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 | 396 | 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 | 397 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 398 | 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 | 399 | 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 | 400 | for(i=0;i<6;i++) |
NarendraSingh | 16:7703b9d92326 | 401 | 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 | 402 | 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 | 403 | Lora_Packet_To_Send[Pos++] = Calculate_Lora_Frame_FCS(Lora_Packet_To_Send,Pos); //Calculate FCS of all bytes |
NarendraSingh | 11:77e595130230 | 404 | Motion_Packet_Sent_Count++; |
NarendraSingh | 11:77e595130230 | 405 | Send_Lora_Packet_To_Gateway(Lora_Packet_To_Send,Pos); |
NarendraSingh | 11:77e595130230 | 406 | } |
NarendraSingh | 11:77e595130230 | 407 | |
NarendraSingh | 11:77e595130230 | 408 | |
NarendraSingh | 11:77e595130230 | 409 | void Get_Lora_Response(void) |
NarendraSingh | 11:77e595130230 | 410 | { |
NarendraSingh | 11:77e595130230 | 411 | static uint16 Temp_Pos1; |
NarendraSingh | 11:77e595130230 | 412 | static uint8 Lora_Response_Found = 0x00; |
NarendraSingh | 11:77e595130230 | 413 | static uint8 Response_Start_Pos[5]; |
NarendraSingh | 11:77e595130230 | 414 | Lora_Response_Found = 0; |
NarendraSingh | 11:77e595130230 | 415 | Temp_Pos1 = LORA_UART_RX_Crnt_Pos = 0; |
NarendraSingh | 11:77e595130230 | 416 | while(Temp_Pos1 < Lora_RxBuffer_End_Pos) |
NarendraSingh | 11:77e595130230 | 417 | { //check for end of AT response to calculate length |
NarendraSingh | 11:77e595130230 | 418 | if((LORA_UART_RX_Buffer[Temp_Pos1] != 0x0D) || (LORA_UART_RX_Buffer[Temp_Pos1+1] != 0x0A)) |
NarendraSingh | 11:77e595130230 | 419 | { //check for AT end response <cr><lf> (i.e. 0x0D,0x0A) |
NarendraSingh | 11:77e595130230 | 420 | Temp_Pos1++; |
NarendraSingh | 11:77e595130230 | 421 | } |
NarendraSingh | 11:77e595130230 | 422 | else |
NarendraSingh | 11:77e595130230 | 423 | { |
NarendraSingh | 11:77e595130230 | 424 | Temp_Pos1+=2; |
NarendraSingh | 11:77e595130230 | 425 | Response_Start_Pos[Lora_Response_Found++] = Temp_Pos1; |
NarendraSingh | 17:758fb8454ab0 | 426 | //pc2.printf("%c",Temp_Pos1); |
NarendraSingh | 11:77e595130230 | 427 | if(Lora_Response_Found >= 4) |
NarendraSingh | 11:77e595130230 | 428 | break; |
NarendraSingh | 11:77e595130230 | 429 | } |
NarendraSingh | 11:77e595130230 | 430 | } |
NarendraSingh | 11:77e595130230 | 431 | if(Lora_Response_Found >= 3) |
NarendraSingh | 11:77e595130230 | 432 | { |
NarendraSingh | 11:77e595130230 | 433 | if((Response_Start_Pos[1] - Response_Start_Pos[0]) > 0x02) //Response received without data |
NarendraSingh | 11:77e595130230 | 434 | { |
NarendraSingh | 11:77e595130230 | 435 | LORA_UART_RX_Crnt_Pos = (Response_Start_Pos[0]); |
NarendraSingh | 11:77e595130230 | 436 | Response_Start_Pos[1]-=2; |
NarendraSingh | 11:77e595130230 | 437 | for(Temp_Pos1=0; LORA_UART_RX_Crnt_Pos < Response_Start_Pos[1]; Temp_Pos1++) |
NarendraSingh | 11:77e595130230 | 438 | { |
NarendraSingh | 11:77e595130230 | 439 | Lora_Command_Rcvd[Temp_Pos1] = LORA_UART_RX_Buffer[LORA_UART_RX_Crnt_Pos++]; |
NarendraSingh | 17:758fb8454ab0 | 440 | pc2.putc(Lora_Command_Rcvd[Temp_Pos1]); |
NarendraSingh | 11:77e595130230 | 441 | } |
NarendraSingh | 11:77e595130230 | 442 | Lora_RxBuffer_End_Pos = 0; |
NarendraSingh | 11:77e595130230 | 443 | AT_Response_Receive_Status = SUCCESS; |
NarendraSingh | 11:77e595130230 | 444 | } |
NarendraSingh | 11:77e595130230 | 445 | else if((Response_Start_Pos[1] - Response_Start_Pos[0]) == 0x02) //Response received along with data |
NarendraSingh | 11:77e595130230 | 446 | { |
NarendraSingh | 11:77e595130230 | 447 | LORA_UART_RX_Crnt_Pos = (Response_Start_Pos[1]); |
NarendraSingh | 11:77e595130230 | 448 | Response_Start_Pos[2]-=2; |
NarendraSingh | 11:77e595130230 | 449 | for(Temp_Pos1=0; LORA_UART_RX_Crnt_Pos < Response_Start_Pos[2]; Temp_Pos1++) |
NarendraSingh | 11:77e595130230 | 450 | { |
NarendraSingh | 11:77e595130230 | 451 | Lora_Command_Rcvd[Temp_Pos1] = LORA_UART_RX_Buffer[LORA_UART_RX_Crnt_Pos++]; |
NarendraSingh | 17:758fb8454ab0 | 452 | pc2.putc(Lora_Command_Rcvd[Temp_Pos1]); |
NarendraSingh | 11:77e595130230 | 453 | } |
NarendraSingh | 11:77e595130230 | 454 | Lora_RxBuffer_End_Pos = 0; |
NarendraSingh | 11:77e595130230 | 455 | AT_Response_Receive_Status = SUCCESS; |
NarendraSingh | 11:77e595130230 | 456 | } |
NarendraSingh | 11:77e595130230 | 457 | } |
NarendraSingh | 11:77e595130230 | 458 | } |
NarendraSingh | 11:77e595130230 | 459 | |
NarendraSingh | 11:77e595130230 | 460 | //Function to send general Lora packets using "AT+SEND" Command |
NarendraSingh | 11:77e595130230 | 461 | void Send_Lora_Packet_To_Gateway(uint8* Command_To_Send,uint8 Length) |
NarendraSingh | 11:77e595130230 | 462 | { |
NarendraSingh | 11:77e595130230 | 463 | uint8 i=0; |
NarendraSingh | 11:77e595130230 | 464 | LORA_Module_UART.printf("%s",Send_Lora_Packet);//write to serial port for sending through lora module |
NarendraSingh | 19:886d50ecc718 | 465 | LORA_Module_UART.printf("%s",Command_To_Send); |
NarendraSingh | 11:77e595130230 | 466 | LORA_Module_UART.printf("\r"); |
NarendraSingh | 11:77e595130230 | 467 | } |
NarendraSingh | 11:77e595130230 | 468 | |
NarendraSingh | 11:77e595130230 | 469 | |
NarendraSingh | 11:77e595130230 | 470 | unsigned char Calculate_Lora_Frame_FCS(unsigned char* Packet_Data,unsigned char Packet_Length) |
NarendraSingh | 11:77e595130230 | 471 | { |
NarendraSingh | 11:77e595130230 | 472 | uint8 i,FCS = 0x00; |
NarendraSingh | 11:77e595130230 | 473 | for(i=0; i < Packet_Length; i++) |
NarendraSingh | 11:77e595130230 | 474 | { |
NarendraSingh | 11:77e595130230 | 475 | FCS ^= (Packet_Data[i]); |
NarendraSingh | 11:77e595130230 | 476 | } |
NarendraSingh | 11:77e595130230 | 477 | return(FCS); |
NarendraSingh | 11:77e595130230 | 478 | } |