Dummy Lora Packet Sending

Fork of Dealer_18feb17 by kumar singh

Committer:
NarendraSingh
Date:
Fri Jan 27 18:30:02 2017 +0000
Revision:
11:77e595130230
Parent:
10:dc33cd3f4eb9
Child:
12:6107b32b0729
Before implementing queue;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:491820ee784d 1 #include "mbed.h"
NarendraSingh 11:77e595130230 2 #include "rtos.h"
NarendraSingh 11:77e595130230 3 #include "OBD.h"
NarendraSingh 11:77e595130230 4 #include "Lora.h"
NarendraSingh 11:77e595130230 5 #include "Accelerometer.h"
NarendraSingh 11:77e595130230 6 #include "Beacon.h"
NarendraSingh 11:77e595130230 7 #include "main.h"
NarendraSingh 11:77e595130230 8
NarendraSingh 11:77e595130230 9 //Datatype typecasting
NarendraSingh 11:77e595130230 10 typedef unsigned char uint8;
NarendraSingh 11:77e595130230 11 typedef unsigned int uint16;
NarendraSingh 11:77e595130230 12
NarendraSingh 11:77e595130230 13 //peripheral connection
emilmont 1:491820ee784d 14 DigitalOut led1(LED1);
emilmont 1:491820ee784d 15 DigitalOut led2(LED2);
NarendraSingh 11:77e595130230 16
NarendraSingh 11:77e595130230 17 //Configure Serial port
NarendraSingh 11:77e595130230 18 RawSerial LORA_UART(PA_0, PA_1);//USART4_TX->PA_0,USART4_RX->PA_1 : Used for Lora module command sending and reception from gateway
NarendraSingh 11:77e595130230 19 RawSerial DEBUG_UART(PA_9, PA_10);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only
NarendraSingh 11:77e595130230 20 RawSerial Beacon_UART(PC_4, PC_5);//USART3_TX->PC4,USART3_RX->PC_5 : Used for sending command to beacon module
NarendraSingh 11:77e595130230 21
NarendraSingh 11:77e595130230 22 //InterruptIn OBD_PLUGIN_INTERRUPT_PIN(PC_13);
NarendraSingh 11:77e595130230 23 InterruptIn CheckIn_Interrupt(PC_13);
NarendraSingh 11:77e595130230 24
NarendraSingh 11:77e595130230 25 uint8 Ticker_Count = 0; //Variable to count for timer overflows
NarendraSingh 11:77e595130230 26
NarendraSingh 11:77e595130230 27
NarendraSingh 11:77e595130230 28 uint8 OBD_Plugin_Detected = FALSE;
emilmont 1:491820ee784d 29
NarendraSingh 11:77e595130230 30 //Create Object for structure of Lora Packet to be sent
NarendraSingh 11:77e595130230 31
NarendraSingh 11:77e595130230 32 static uint16 Calculate_Wheels_RPM(uint8* Buffer);
NarendraSingh 11:77e595130230 33 void flip_Packet_Sending_Flag();
NarendraSingh 11:77e595130230 34 void Lora_Periodic_Packet_Sending_thread(void const *args);
NarendraSingh 11:77e595130230 35
NarendraSingh 11:77e595130230 36 void Lora_Rcvd_Cmd_Processing_thread(void);// const *args);
NarendraSingh 11:77e595130230 37 void Enable_CheckIN_Packet_Sending();
NarendraSingh 11:77e595130230 38 /*************************Accelerometer related definitions***********************************/
NarendraSingh 11:77e595130230 39 //Accelerometer related definitions
NarendraSingh 11:77e595130230 40 #define DOUBLE_TAP_INTERRUPT 0x20
NarendraSingh 11:77e595130230 41 #define ACTIVITY_INTERRUPT 0x10
NarendraSingh 11:77e595130230 42 #define INACTIVITY_INTERRUPT 0x08
NarendraSingh 11:77e595130230 43
NarendraSingh 11:77e595130230 44 #define TAP_THRESHOLD 75
NarendraSingh 11:77e595130230 45 #define ACTIVITY_THRESHOLD 64 // THRES_ACT register value 62.5mg/LSB , therfore value 32 indicates 2g activity
NarendraSingh 11:77e595130230 46 #define INACTIVITY_THRESHOLD 50
NarendraSingh 11:77e595130230 47
NarendraSingh 11:77e595130230 48 #define DUR_TIME 0x15 // DUR Register value providing maximum time to be held to generate an interrupt
NarendraSingh 11:77e595130230 49 #define LATENT_TIME 0x15 // The interrupt latency
NarendraSingh 11:77e595130230 50 #define WINDOW_TIME 0x45 // The time of the interrupt window in which the next tap will be detected
NarendraSingh 11:77e595130230 51 #define INACTIVITY_VALIDATION_TIME 5 // The time until which the acceleration must be held below the inactivity threshold to generate an inactvity interrupt
NarendraSingh 11:77e595130230 52 // Here the value 5 indicates literally 5 secs
NarendraSingh 11:77e595130230 53 #define X_AXIS_OFFSET 0x7F
NarendraSingh 11:77e595130230 54 #define Y_AXIS_OFFSET 0x7F
NarendraSingh 11:77e595130230 55 #define Z_AXIS_OFFSET 0x05
NarendraSingh 11:77e595130230 56
NarendraSingh 11:77e595130230 57
NarendraSingh 11:77e595130230 58 I2C i2c(PB_9, PB_8);
NarendraSingh 11:77e595130230 59 RawSerial DEBUG_UART1(PA_9, PA_10);//USART1_TX->PA_9,USART1_RX->PA_10
NarendraSingh 11:77e595130230 60
NarendraSingh 11:77e595130230 61 InterruptIn activity(PB_0);
NarendraSingh 11:77e595130230 62 InterruptIn inactivity(PA_4); // As for now only this is used
NarendraSingh 11:77e595130230 63 DigitalOut led(LED1);
NarendraSingh 11:77e595130230 64
NarendraSingh 11:77e595130230 65 const int slave_address_acc = 0xA6;
NarendraSingh 11:77e595130230 66 char axis_data[6] = {0,0,0,0,0,0};
NarendraSingh 11:77e595130230 67
NarendraSingh 11:77e595130230 68 char interrupt_source[2];
NarendraSingh 11:77e595130230 69 char axis_data_start_address[2] = {0x32, 0};
NarendraSingh 11:77e595130230 70 char intr_source_address[2] = {0x30, 0};
NarendraSingh 11:77e595130230 71 char all_interrupt_clear_command[2] = {0x2E, 0x00};
NarendraSingh 11:77e595130230 72 char all_interrupt_enable_command[2] = {0x2E, 0x38};
NarendraSingh 11:77e595130230 73 char activity_interrupt_disable_command[2] = {0x2E, 0x08};
NarendraSingh 11:77e595130230 74 char inactivity_interrupt_disable_command[2] = {0x2E, 0x30};
NarendraSingh 11:77e595130230 75 char accelerometer_status_registered = 0;
NarendraSingh 11:77e595130230 76 unsigned int interrupt_source_duplicate;
NarendraSingh 11:77e595130230 77
NarendraSingh 11:77e595130230 78 char threshold_offset_command[5];
NarendraSingh 11:77e595130230 79 char act_inact_time_config_command[8];
NarendraSingh 11:77e595130230 80 char interrupt_enable_command[3];
NarendraSingh 11:77e595130230 81 char tap_axis_enable_command[2];
NarendraSingh 11:77e595130230 82 char baud_rate_command[2];
NarendraSingh 11:77e595130230 83 char data_format_command[2];
NarendraSingh 11:77e595130230 84 char measure_bit_on_command[2];
NarendraSingh 11:77e595130230 85
NarendraSingh 11:77e595130230 86
NarendraSingh 11:77e595130230 87 char previous_state = 0;
NarendraSingh 11:77e595130230 88 char current_state = 0;
NarendraSingh 11:77e595130230 89
NarendraSingh 11:77e595130230 90 unsigned char vehicle_speed = 25; // Kmph
NarendraSingh 11:77e595130230 91 unsigned char current_speed, previous_speed, speed_threshold = 10; // Kmph
NarendraSingh 11:77e595130230 92
NarendraSingh 11:77e595130230 93 unsigned char x_axis, y_axis, z_axis;
NarendraSingh 11:77e595130230 94
NarendraSingh 11:77e595130230 95 unsigned char Motion_Detect_Status = FALSE;
NarendraSingh 11:77e595130230 96 uint8 OBD_PlugInOut_IOC_Status = FALSE;
NarendraSingh 11:77e595130230 97 unsigned char Motion_Type_Detected = MOTION_TYPE_UNKNOWN; //By default set motion type as unknown
NarendraSingh 11:77e595130230 98 void Accelerometer_Process_thread();//void const *args) ;
NarendraSingh 11:77e595130230 99
NarendraSingh 11:77e595130230 100 //This function is Interrupt routine for detecting motion(acceleartion), i.e. either starts from rest/vehicle stops afeter running or if sudden jurk is detected
NarendraSingh 11:77e595130230 101 void interrupt_activity_inactivity()
NarendraSingh 11:77e595130230 102 {
NarendraSingh 11:77e595130230 103 i2c.write(slave_address_acc, all_interrupt_clear_command, 2);
NarendraSingh 11:77e595130230 104 Motion_Detect_Status = TRUE;
NarendraSingh 11:77e595130230 105 }
NarendraSingh 11:77e595130230 106 /************************************************************************/
NarendraSingh 11:77e595130230 107 uint8 Command_Sent[100];
NarendraSingh 11:77e595130230 108 uint8 Command_Length_Sent;
NarendraSingh 11:77e595130230 109 void Extract_Received_Lora_Response(void);
NarendraSingh 11:77e595130230 110
NarendraSingh 11:77e595130230 111 //This function is Interrupt routine for detecting OBD Plugin and Out
NarendraSingh 11:77e595130230 112 void Handle_CheckIn_Interrupt()
NarendraSingh 11:77e595130230 113 {
NarendraSingh 11:77e595130230 114 OBD_PlugInOut_IOC_Status = TRUE;
NarendraSingh 11:77e595130230 115 DEBUG_UART.printf("Movement_Detected");
NarendraSingh 11:77e595130230 116 }
NarendraSingh 11:77e595130230 117
NarendraSingh 11:77e595130230 118 //Declare Ticker for sending lora packet
NarendraSingh 11:77e595130230 119 Ticker Lora_Packet_Sending_Ticker;
NarendraSingh 11:77e595130230 120 void flip_Packet_Sending_Flag(void)
NarendraSingh 11:77e595130230 121 { //flip function
NarendraSingh 11:77e595130230 122 if(Ticker_Count < 5)
NarendraSingh 11:77e595130230 123 {
NarendraSingh 11:77e595130230 124 Ticker_Count++;
NarendraSingh 11:77e595130230 125 }
NarendraSingh 11:77e595130230 126 else
NarendraSingh 11:77e595130230 127 {
NarendraSingh 11:77e595130230 128 Ticker_Count = 0;
NarendraSingh 11:77e595130230 129 Send_Lora_Packet_Flag = TRUE;
NarendraSingh 11:77e595130230 130 }
NarendraSingh 11:77e595130230 131 }
NarendraSingh 11:77e595130230 132
NarendraSingh 11:77e595130230 133 // called every time a byte is received from lora module.
NarendraSingh 11:77e595130230 134 void Lora_onDataRx()
NarendraSingh 11:77e595130230 135 {
NarendraSingh 11:77e595130230 136 while (LORA_UART.readable())
NarendraSingh 11:77e595130230 137 { // while there is data waiting
NarendraSingh 11:77e595130230 138 LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos++] = LORA_UART.getc(); // put it in the buffer
NarendraSingh 11:77e595130230 139 //DEBUG_UART.putc(LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos-1]);
NarendraSingh 11:77e595130230 140 if(Lora_RxBuffer_End_Pos >= LORA_UART_RX_Size)
NarendraSingh 11:77e595130230 141 {
NarendraSingh 11:77e595130230 142 // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation.
NarendraSingh 11:77e595130230 143 // For now just throw everything away.
NarendraSingh 11:77e595130230 144 Lora_RxBuffer_End_Pos = 0;
NarendraSingh 11:77e595130230 145 }
emilmont 1:491820ee784d 146 }
emilmont 1:491820ee784d 147 }
NarendraSingh 11:77e595130230 148
NarendraSingh 11:77e595130230 149
NarendraSingh 11:77e595130230 150 /*
NarendraSingh 11:77e595130230 151 // called every time a byte is received from Beacon Module.
NarendraSingh 11:77e595130230 152 void Beacon_onDataRx()
NarendraSingh 11:77e595130230 153 {
NarendraSingh 11:77e595130230 154 while (Beacon_UART.readable())
NarendraSingh 11:77e595130230 155 { // while there is data waiting
NarendraSingh 11:77e595130230 156 Beacon_RX_Buffer[Beacon_RxBuffer_End_Pos++] = Beacon_UART.getc(); // put it in the buffer
NarendraSingh 11:77e595130230 157 //DEBUG_UART.putc(LORA_UART_RX_Buffer[Beacon_RxBuffer_End_Pos-1]);
NarendraSingh 11:77e595130230 158 if(Beacon_RxBuffer_End_Pos >= 100)
NarendraSingh 11:77e595130230 159 {
NarendraSingh 11:77e595130230 160 // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation.
NarendraSingh 11:77e595130230 161 // For now just throw everything away.
NarendraSingh 11:77e595130230 162 Beacon_RxBuffer_End_Pos = 0;
NarendraSingh 11:77e595130230 163 }
emilmont 1:491820ee784d 164 }
emilmont 1:491820ee784d 165 }
NarendraSingh 11:77e595130230 166 */
NarendraSingh 11:77e595130230 167
NarendraSingh 11:77e595130230 168 int main()
NarendraSingh 11:77e595130230 169 {
NarendraSingh 11:77e595130230 170 DEBUG_UART.baud(115200);
NarendraSingh 11:77e595130230 171 DEBUG_UART.printf("%s","Debugging started");
NarendraSingh 11:77e595130230 172 LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq);
NarendraSingh 11:77e595130230 173 //Beacon_UART.attach(&Beacon_onDataRx, Serial::RxIrq);
NarendraSingh 11:77e595130230 174
NarendraSingh 11:77e595130230 175 //Create a thread to read vehicle data
NarendraSingh 11:77e595130230 176 //Thread OBD_thread(OBD_Rcvd_Cmd_Processing_thread);
NarendraSingh 11:77e595130230 177
NarendraSingh 11:77e595130230 178 Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 3.0); // call flip_Packet_Sending_Flag function every 5 seconds
NarendraSingh 11:77e595130230 179
NarendraSingh 11:77e595130230 180 // OBD_PLUGIN_INTERRUPT_PIN.rise(&Enable_CheckIN_Packet_Sending); // call toggle function on the rising edge
NarendraSingh 11:77e595130230 181 //led2_thread is executing concurrently with main at this point
NarendraSingh 11:77e595130230 182 CheckIn_Interrupt.rise(&Handle_CheckIn_Interrupt);
NarendraSingh 11:77e595130230 183 inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge
NarendraSingh 11:77e595130230 184 Initialize_Beacon_Module();
NarendraSingh 11:77e595130230 185 Lora_Periodic_Packet_Sending(); //Infinite loop for sending and receiving lora response, no return from here
NarendraSingh 11:77e595130230 186 }
NarendraSingh 11:77e595130230 187
NarendraSingh 11:77e595130230 188 //Functiont to be called when Interrupt is genearted for motion sensing, checkin
NarendraSingh 11:77e595130230 189 void Initialize_Packets_Sent_Count(void)
NarendraSingh 11:77e595130230 190 {
NarendraSingh 11:77e595130230 191 Motion_Packet_Sent_Count = 0x00;
NarendraSingh 11:77e595130230 192 CheckIN_Packet_Sent_Count = 0x00;
NarendraSingh 11:77e595130230 193 }
NarendraSingh 11:77e595130230 194
NarendraSingh 11:77e595130230 195 void Lora_Periodic_Packet_Sending()
NarendraSingh 11:77e595130230 196 {
NarendraSingh 11:77e595130230 197 DEBUG_UART.printf("Periodic packet sending intiialized");
NarendraSingh 11:77e595130230 198 Set_Up_Lora_Network_Configuration();
NarendraSingh 11:77e595130230 199 Initialize_lora_Packets();
NarendraSingh 11:77e595130230 200 while (true)
NarendraSingh 11:77e595130230 201 {
NarendraSingh 11:77e595130230 202 if(Packet_Type_To_Send == HEARTBEAT_TYPE_PACKET) //check if packet to be sent is Heartbeat packet
NarendraSingh 11:77e595130230 203 {
NarendraSingh 11:77e595130230 204 if(Send_Lora_Packet_Flag) //Check if packet sending isd enabled, Packet should be sent only when enabled after timeout period
NarendraSingh 11:77e595130230 205 {
NarendraSingh 11:77e595130230 206
NarendraSingh 11:77e595130230 207 Send_HeartBeat_Packet(); //call function to send heartbeat packet
NarendraSingh 11:77e595130230 208 DEBUG_UART.printf("Sent HeartBeat Packet");
NarendraSingh 11:77e595130230 209 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 210 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 211 Get_Lora_Response();
NarendraSingh 11:77e595130230 212 Send_Lora_Packet_Flag = FALSE;
NarendraSingh 11:77e595130230 213 DEBUG_UART.printf("Heartbeat Packet Response Received");
NarendraSingh 11:77e595130230 214 }
NarendraSingh 11:77e595130230 215 }
NarendraSingh 11:77e595130230 216 else if(Packet_Type_To_Send == MOTION_TYPE_PACKET) //check if packet to be sent is motion packet
NarendraSingh 11:77e595130230 217 {
NarendraSingh 11:77e595130230 218 if(Send_Lora_Packet_Flag) //Check if packet sending isd enabled, Packet should be sent only when enabled after timeout period
NarendraSingh 11:77e595130230 219 {
NarendraSingh 11:77e595130230 220 Send_Motion_Packet();
NarendraSingh 11:77e595130230 221 DEBUG_UART.printf("Sent Motion Packet"); //call function to send periodic motion packet
NarendraSingh 11:77e595130230 222 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 223 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 224 Get_Lora_Response();
NarendraSingh 11:77e595130230 225 DEBUG_UART.printf("Motion Packet Response Received");
NarendraSingh 11:77e595130230 226 Send_Lora_Packet_Flag = FALSE;
NarendraSingh 11:77e595130230 227 if(Motion_Packet_Sent_Count >= 5) //Stop Sending Motion Packets if after sending for 2 minute
NarendraSingh 11:77e595130230 228 {
NarendraSingh 11:77e595130230 229 DEBUG_UART.printf("Packet Type Sending Changed to HeartBeat");
NarendraSingh 11:77e595130230 230 Motion_Packet_Sent_Count = 0;
NarendraSingh 11:77e595130230 231 Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //Set Packet type to send as heartbeat packet
NarendraSingh 11:77e595130230 232 Lora_Packet_Sending_Ticker.detach(); //destroy ticker
NarendraSingh 11:77e595130230 233 Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 10.0); //create new ticker
NarendraSingh 11:77e595130230 234
NarendraSingh 11:77e595130230 235 }
NarendraSingh 11:77e595130230 236 }
NarendraSingh 11:77e595130230 237 }
NarendraSingh 11:77e595130230 238 else if(Packet_Type_To_Send == CHECKIN_TYPE_PACKET) //check if packet to be sent is Checkin packet
NarendraSingh 11:77e595130230 239 {
NarendraSingh 11:77e595130230 240 if(Send_Lora_Packet_Flag) //Check if packet sending isd enabled, Packet should be sent only when enabled after timeout period
NarendraSingh 11:77e595130230 241 {
NarendraSingh 11:77e595130230 242 Send_CheckIN_Packet(); //call function to send periodic checkIn packet
NarendraSingh 11:77e595130230 243 DEBUG_UART.printf("Sent Checkin Packet");
NarendraSingh 11:77e595130230 244 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 245 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 246 Get_Lora_Response();
NarendraSingh 11:77e595130230 247 Send_Lora_Packet_Flag = FALSE;
NarendraSingh 11:77e595130230 248 DEBUG_UART.printf("Checkin Packet Response Received");
NarendraSingh 11:77e595130230 249 if(CheckIN_Packet_Sent_Count >= 5) //Stop Sending Motion Packets if after sending for 2 minute
NarendraSingh 11:77e595130230 250 {
NarendraSingh 11:77e595130230 251 DEBUG_UART.printf("Packet Type Sending Changed to HeartBeat");
NarendraSingh 11:77e595130230 252 CheckIN_Packet_Sent_Count = 0;
NarendraSingh 11:77e595130230 253 Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //Set Packet type to send as heartbeat packet
NarendraSingh 11:77e595130230 254 Initialize_Packets_Sent_Count();
NarendraSingh 11:77e595130230 255
NarendraSingh 11:77e595130230 256 }
NarendraSingh 11:77e595130230 257 }
NarendraSingh 11:77e595130230 258 }
NarendraSingh 11:77e595130230 259 if(OBD_PlugInOut_IOC_Status) //Check if Accelerometer Interrupt is generated
NarendraSingh 11:77e595130230 260 {
NarendraSingh 11:77e595130230 261 Enable_CheckIN_Packet_Sending();
NarendraSingh 11:77e595130230 262 //Get_Acceleration_Type();
NarendraSingh 11:77e595130230 263 OBD_PlugInOut_IOC_Status = FALSE;
NarendraSingh 11:77e595130230 264 }
NarendraSingh 11:77e595130230 265 if(Motion_Detect_Status) //Check if Accelerometer Interrupt is generated
NarendraSingh 11:77e595130230 266 {
NarendraSingh 11:77e595130230 267 Get_Acceleration_Type();
NarendraSingh 11:77e595130230 268 Motion_Detect_Status = FALSE;
NarendraSingh 11:77e595130230 269 }
NarendraSingh 11:77e595130230 270 }
NarendraSingh 11:77e595130230 271 }
NarendraSingh 11:77e595130230 272
NarendraSingh 11:77e595130230 273 void Get_Acceleration_Type(void)
NarendraSingh 11:77e595130230 274 {
NarendraSingh 11:77e595130230 275 Packet_Type_To_Send = MOTION_TYPE_PACKET; //whenever acceleration is detected change the packet type to be sent to motion type
NarendraSingh 11:77e595130230 276 Lora_Packet_Sending_Ticker.detach(); //destroy ticker
NarendraSingh 11:77e595130230 277 Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 5.0); //create new ticker, time inetrval value to be changed
NarendraSingh 11:77e595130230 278 Send_Lora_Packet_Flag = 1; //set flag to send motion packet as soon as motion is detecetd
NarendraSingh 11:77e595130230 279 Motion_Lora_Packet.Acceleration_Type = Motion_Type_Detected; //Read Type of motion deteceted
NarendraSingh 11:77e595130230 280 //write code to read acceleration value for every 10sec after any of the acceleration is found
NarendraSingh 11:77e595130230 281 }
NarendraSingh 11:77e595130230 282
NarendraSingh 11:77e595130230 283 //This function is used to enable checkin packet sending once OBD device is plugged in
NarendraSingh 11:77e595130230 284 void Enable_CheckIN_Packet_Sending()
NarendraSingh 11:77e595130230 285 {
NarendraSingh 11:77e595130230 286 Packet_Type_To_Send = CHECKIN_TYPE_PACKET; //whenever acceleration is detected change the packet type to be sent to motion type
NarendraSingh 11:77e595130230 287 OBD_Plugin_Detected = TRUE;
NarendraSingh 11:77e595130230 288 Lora_Packet_Sending_Ticker.detach(); //destroy ticker
NarendraSingh 11:77e595130230 289 Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 5.0); //create new ticker
NarendraSingh 11:77e595130230 290 Send_Lora_Packet_Flag = 1; //Set Counter so that packet is sent instantly as soon as checkin interrupt is detected
NarendraSingh 11:77e595130230 291 }
NarendraSingh 11:77e595130230 292
NarendraSingh 11:77e595130230 293 static void Process_Lora_Command_Received(uint8* Command_Received,uint8 Command_Length)
NarendraSingh 11:77e595130230 294 {
NarendraSingh 11:77e595130230 295 if(Command_Received[0] == 0xFE) //check start of frame of packet received. every packet must start with 0xFE
NarendraSingh 11:77e595130230 296 {
NarendraSingh 11:77e595130230 297 if(Calculate_Lora_Frame_FCS((Command_Received + 1),(Command_Length + 1)) == (Command_Received[Command_Length + 2])) //Check for packet inegrity by checking FCS
NarendraSingh 11:77e595130230 298 {
NarendraSingh 11:77e595130230 299 if((Command_Received[0] == SET_BEACON_CMD0) && (Command_Received[1] == SET_BEACON_CMD1)) //Check if command is received for setting beacon parameters
NarendraSingh 11:77e595130230 300 {
NarendraSingh 11:77e595130230 301 Process_Beacon_Command_Received((Command_Received + 2));
NarendraSingh 11:77e595130230 302 }
NarendraSingh 11:77e595130230 303 }
NarendraSingh 11:77e595130230 304 }
NarendraSingh 11:77e595130230 305 }