Dummy Lora Packet Sending

Fork of Dealer_18feb17 by kumar singh

Committer:
NarendraSingh
Date:
Thu Feb 23 13:21:08 2017 +0000
Revision:
24:1063cfc311e5
Parent:
23:688ee106c385
Dummy Lora Packet Sending

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 16:7703b9d92326 13 uint8 OBD_Plug_In_Status = FALSE;
NarendraSingh 16:7703b9d92326 14
NarendraSingh 16:7703b9d92326 15 //peripheral connection
NarendraSingh 24:1063cfc311e5 16 DigitalOut led1(PB_11);
emilmont 1:491820ee784d 17 DigitalOut led2(LED2);
NarendraSingh 24:1063cfc311e5 18 DigitalIn Switch2(PB_13);
NarendraSingh 11:77e595130230 19
NarendraSingh 11:77e595130230 20 //Configure Serial port
NarendraSingh 16:7703b9d92326 21 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 23:688ee106c385 22 //RawSerial pc1(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only
NarendraSingh 23:688ee106c385 23 //RawSerial DEBUG_UART(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only
NarendraSingh 16:7703b9d92326 24 RawSerial Beacon_UART(PC_4, PC_5);//USART3_TX->PC4,USART3_RX->PC_5 : Used for sending command to beacon module
NarendraSingh 16:7703b9d92326 25 RawSerial BLE_RECEIVER_UART(PA_9, PA_10);//USART1_TX->PA_0,USART1_RX->PA_1 : Used for Lora module command sending and reception from gateway
NarendraSingh 23:688ee106c385 26 Serial pc1(USBTX, USBRX);
NarendraSingh 23:688ee106c385 27 RawSerial DEBUG_UART(USBTX, USBRX);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only
NarendraSingh 16:7703b9d92326 28
NarendraSingh 16:7703b9d92326 29 //InterruptIn OBD_PLUGIN_INTERRUPT_PIN(PC_13);
NarendraSingh 21:a5fb0ae94dc6 30 InterruptIn CheckIn_Interrupt(PB_7);//(PC_13);
NarendraSingh 24:1063cfc311e5 31 InterruptIn Motion_Start_To_Stop(PB_5);//(PC_13);
NarendraSingh 24:1063cfc311e5 32 InterruptIn Motion_Stop_To_Start(PB_14);//(PC_13);
NarendraSingh 24:1063cfc311e5 33 InterruptIn Motion_Sudden_Jerk(PC_13);//(PC_13);
NarendraSingh 24:1063cfc311e5 34
NarendraSingh 16:7703b9d92326 35
NarendraSingh 16:7703b9d92326 36 uint8 Ticker_Count = 0; //Variable to count for timer overflows
NarendraSingh 16:7703b9d92326 37
NarendraSingh 16:7703b9d92326 38 uint8 OBD_Plugin_Detected = FALSE;
NarendraSingh 16:7703b9d92326 39
NarendraSingh 16:7703b9d92326 40 //Create Object for structure of Lora Packet to be sent
NarendraSingh 11:77e595130230 41
NarendraSingh 16:7703b9d92326 42 static uint16 Calculate_Wheels_RPM(uint8* Buffer);
NarendraSingh 16:7703b9d92326 43 void flip_Packet_Sending_Flag();
NarendraSingh 16:7703b9d92326 44 void Lora_Periodic_Packet_Sending_thread(void const *args);
NarendraSingh 11:77e595130230 45
NarendraSingh 16:7703b9d92326 46 void Lora_Rcvd_Cmd_Processing_thread(void);// const *args);
NarendraSingh 16:7703b9d92326 47 void Enable_CheckIN_Packet_Sending();
NarendraSingh 16:7703b9d92326 48
NarendraSingh 23:688ee106c385 49 const char GET_RSSI[]= {0x41,0x54,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x0A};
NarendraSingh 23:688ee106c385 50 const char SET_BEACON_VENDOR_ID[]= {0x41,0x54,0xF1,0x01,0x02,0x00,0x00,0x00,0x00,0xF2,0x0D,0x0A};
NarendraSingh 23:688ee106c385 51 const char SET_BEACON_MESSAGE_TYPE[]= {0x41,0x54,0xF2,0x01,0x00,0x00,0x00,0x00,0x00,0xF3,0x0D,0x0A};
NarendraSingh 11:77e595130230 52 /*************************Accelerometer related definitions***********************************/
NarendraSingh 11:77e595130230 53 //Accelerometer related definitions
NarendraSingh 13:8955f2e95021 54
NarendraSingh 11:77e595130230 55 #define DOUBLE_TAP_INTERRUPT 0x20
NarendraSingh 11:77e595130230 56 #define ACTIVITY_INTERRUPT 0x10
NarendraSingh 11:77e595130230 57 #define INACTIVITY_INTERRUPT 0x08
NarendraSingh 11:77e595130230 58
NarendraSingh 16:7703b9d92326 59 #define TAP_THRESHOLD 75
NarendraSingh 11:77e595130230 60 #define ACTIVITY_THRESHOLD 64 // THRES_ACT register value 62.5mg/LSB , therfore value 32 indicates 2g activity
NarendraSingh 11:77e595130230 61 #define INACTIVITY_THRESHOLD 50
NarendraSingh 11:77e595130230 62
NarendraSingh 11:77e595130230 63 #define DUR_TIME 0x15 // DUR Register value providing maximum time to be held to generate an interrupt
NarendraSingh 11:77e595130230 64 #define LATENT_TIME 0x15 // The interrupt latency
NarendraSingh 11:77e595130230 65 #define WINDOW_TIME 0x45 // The time of the interrupt window in which the next tap will be detected
NarendraSingh 11:77e595130230 66 #define INACTIVITY_VALIDATION_TIME 5 // The time until which the acceleration must be held below the inactivity threshold to generate an inactvity interrupt
NarendraSingh 16:7703b9d92326 67 // Here the value 5 indicates literally 5 secs
NarendraSingh 11:77e595130230 68 #define X_AXIS_OFFSET 0x7F
NarendraSingh 11:77e595130230 69 #define Y_AXIS_OFFSET 0x7F
NarendraSingh 11:77e595130230 70 #define Z_AXIS_OFFSET 0x05
NarendraSingh 11:77e595130230 71
NarendraSingh 17:758fb8454ab0 72 Serial pc(USBTX, USBRX);
NarendraSingh 16:7703b9d92326 73 I2C i2c(PB_9, PB_8);
NarendraSingh 11:77e595130230 74
NarendraSingh 16:7703b9d92326 75 InterruptIn activity(PB_0);
NarendraSingh 11:77e595130230 76 InterruptIn inactivity(PA_4); // As for now only this is used
NarendraSingh 11:77e595130230 77 DigitalOut led(LED1);
NarendraSingh 11:77e595130230 78
NarendraSingh 11:77e595130230 79 const int slave_address_acc = 0xA6;
NarendraSingh 11:77e595130230 80 char axis_data[6] = {0,0,0,0,0,0};
NarendraSingh 11:77e595130230 81
NarendraSingh 11:77e595130230 82 char interrupt_source[2];
NarendraSingh 11:77e595130230 83 char axis_data_start_address[2] = {0x32, 0};
NarendraSingh 11:77e595130230 84 char intr_source_address[2] = {0x30, 0};
NarendraSingh 11:77e595130230 85 char all_interrupt_clear_command[2] = {0x2E, 0x00};
NarendraSingh 11:77e595130230 86 char all_interrupt_enable_command[2] = {0x2E, 0x38};
NarendraSingh 11:77e595130230 87 char activity_interrupt_disable_command[2] = {0x2E, 0x08};
NarendraSingh 11:77e595130230 88 char inactivity_interrupt_disable_command[2] = {0x2E, 0x30};
NarendraSingh 11:77e595130230 89 char accelerometer_status_registered = 0;
NarendraSingh 11:77e595130230 90 unsigned int interrupt_source_duplicate;
NarendraSingh 11:77e595130230 91
NarendraSingh 11:77e595130230 92 char threshold_offset_command[5];
NarendraSingh 11:77e595130230 93 char act_inact_time_config_command[8];
NarendraSingh 11:77e595130230 94 char interrupt_enable_command[3];
NarendraSingh 11:77e595130230 95 char tap_axis_enable_command[2];
NarendraSingh 11:77e595130230 96 char baud_rate_command[2];
NarendraSingh 11:77e595130230 97 char data_format_command[2];
NarendraSingh 11:77e595130230 98 char measure_bit_on_command[2];
NarendraSingh 11:77e595130230 99
NarendraSingh 11:77e595130230 100
NarendraSingh 11:77e595130230 101 unsigned char vehicle_speed = 25; // Kmph
NarendraSingh 11:77e595130230 102 unsigned char current_speed, previous_speed, speed_threshold = 10; // Kmph
NarendraSingh 11:77e595130230 103
NarendraSingh 11:77e595130230 104 unsigned char x_axis, y_axis, z_axis;
NarendraSingh 11:77e595130230 105
NarendraSingh 11:77e595130230 106 unsigned char Motion_Detect_Status = FALSE;
NarendraSingh 11:77e595130230 107 uint8 OBD_PlugInOut_IOC_Status = FALSE;
NarendraSingh 11:77e595130230 108 unsigned char Motion_Type_Detected = MOTION_TYPE_UNKNOWN; //By default set motion type as unknown
NarendraSingh 11:77e595130230 109 void Accelerometer_Process_thread();//void const *args) ;
NarendraSingh 11:77e595130230 110
NarendraSingh 16:7703b9d92326 111 #define BLE_RECEIVER_UART_RX_Size 100
NarendraSingh 16:7703b9d92326 112 uint8 BLE_RxBuffer_End_Pos = 0;
NarendraSingh 16:7703b9d92326 113 char BLE_Receiver_UART_RX_Buffer[BLE_RECEIVER_UART_RX_Size];
NarendraSingh 13:8955f2e95021 114
NarendraSingh 11:77e595130230 115 //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 116 void interrupt_activity_inactivity()
NarendraSingh 16:7703b9d92326 117 {
NarendraSingh 16:7703b9d92326 118 i2c.write(slave_address_acc, all_interrupt_clear_command, 2);
NarendraSingh 16:7703b9d92326 119 Motion_Detect_Status = TRUE;
NarendraSingh 11:77e595130230 120 }
NarendraSingh 13:8955f2e95021 121
NarendraSingh 13:8955f2e95021 122
NarendraSingh 16:7703b9d92326 123 /************************************************************************/
NarendraSingh 11:77e595130230 124 uint8 Command_Sent[100];
NarendraSingh 11:77e595130230 125 uint8 Command_Length_Sent;
NarendraSingh 12:6107b32b0729 126 uint8 Checkin_Detect_Status = FALSE;
NarendraSingh 11:77e595130230 127 void Extract_Received_Lora_Response(void);
NarendraSingh 23:688ee106c385 128 void Send_Command_To_BLE_Receiver(const char* Command);
NarendraSingh 16:7703b9d92326 129
NarendraSingh 16:7703b9d92326 130 char previous_state = 0;
NarendraSingh 16:7703b9d92326 131 char current_state = 0;
NarendraSingh 16:7703b9d92326 132
NarendraSingh 16:7703b9d92326 133 uint8 OBD_PlugIN_State=0;
NarendraSingh 16:7703b9d92326 134 uint8 OBD_PlugIN_State1=0;
NarendraSingh 16:7703b9d92326 135 uint8 OBD_PlugIN_State2=0;
NarendraSingh 16:7703b9d92326 136 uint8 OBD_PlugIN_Temp_State=1;
NarendraSingh 16:7703b9d92326 137
NarendraSingh 24:1063cfc311e5 138 uint8 Start_To_Stop_Status = FALSE;
NarendraSingh 24:1063cfc311e5 139 uint8 Stop_To_Start_Status = FALSE;
NarendraSingh 24:1063cfc311e5 140 uint8 Jerk_Status = FALSE;
NarendraSingh 24:1063cfc311e5 141
NarendraSingh 24:1063cfc311e5 142 void Start_To_Stop_Interrupt()
NarendraSingh 24:1063cfc311e5 143 {
NarendraSingh 24:1063cfc311e5 144 Start_To_Stop_Status = TRUE;
NarendraSingh 24:1063cfc311e5 145 Motion_Detect_Status = TRUE;
NarendraSingh 24:1063cfc311e5 146 }
NarendraSingh 24:1063cfc311e5 147
NarendraSingh 24:1063cfc311e5 148 void Stop_To_Start_Interrupt()
NarendraSingh 24:1063cfc311e5 149 {
NarendraSingh 24:1063cfc311e5 150 Stop_To_Start_Status = TRUE;
NarendraSingh 24:1063cfc311e5 151 Motion_Detect_Status = TRUE;
NarendraSingh 24:1063cfc311e5 152 }
NarendraSingh 24:1063cfc311e5 153
NarendraSingh 24:1063cfc311e5 154 void Sudden_Jerk_Interrupt()
NarendraSingh 24:1063cfc311e5 155 {
NarendraSingh 24:1063cfc311e5 156 Jerk_Status = TRUE;
NarendraSingh 24:1063cfc311e5 157 Motion_Detect_Status = TRUE;
NarendraSingh 24:1063cfc311e5 158 }
NarendraSingh 16:7703b9d92326 159 void OBD_Plug_IN_Interrupt()
NarendraSingh 16:7703b9d92326 160 {
NarendraSingh 17:758fb8454ab0 161 if(OBD_PlugIN_State1!=OBD_PlugIN_Temp_State) {
NarendraSingh 16:7703b9d92326 162 OBD_PlugIN_State1=1;
NarendraSingh 16:7703b9d92326 163 OBD_PlugIN_State=!OBD_PlugIN_State;
NarendraSingh 16:7703b9d92326 164 OBD_PlugIN_Temp_State=OBD_PlugIN_State;
NarendraSingh 16:7703b9d92326 165 OBD_PlugInOut_IOC_Status = TRUE;
NarendraSingh 16:7703b9d92326 166 }
NarendraSingh 16:7703b9d92326 167 }
NarendraSingh 17:758fb8454ab0 168
NarendraSingh 16:7703b9d92326 169 void OBD_Plug_OUT_Interrupt()
NarendraSingh 16:7703b9d92326 170 {
NarendraSingh 22:c2f034a13108 171
NarendraSingh 17:758fb8454ab0 172 if(OBD_PlugIN_State2!=OBD_PlugIN_Temp_State) {
NarendraSingh 16:7703b9d92326 173 OBD_PlugIN_State2=0;
NarendraSingh 16:7703b9d92326 174 OBD_PlugIN_State=!OBD_PlugIN_State;
NarendraSingh 16:7703b9d92326 175 OBD_PlugIN_Temp_State=OBD_PlugIN_State;
NarendraSingh 16:7703b9d92326 176 OBD_PlugInOut_IOC_Status = TRUE;
NarendraSingh 17:758fb8454ab0 177 }
NarendraSingh 16:7703b9d92326 178 }
NarendraSingh 16:7703b9d92326 179
NarendraSingh 16:7703b9d92326 180 //This function is Interrupt routine for detecting OBD Plugin and Out
NarendraSingh 11:77e595130230 181 void Handle_CheckIn_Interrupt()
NarendraSingh 16:7703b9d92326 182 {
NarendraSingh 11:77e595130230 183 OBD_PlugInOut_IOC_Status = TRUE;
NarendraSingh 24:1063cfc311e5 184 pc.printf("\nMovement_Detected\n");
NarendraSingh 11:77e595130230 185 }
NarendraSingh 11:77e595130230 186
NarendraSingh 16:7703b9d92326 187 //Declare Ticker for sending lora packet
NarendraSingh 16:7703b9d92326 188 Ticker Lora_Packet_Sending_Ticker;
NarendraSingh 16:7703b9d92326 189 void flip_Packet_Sending_Flag(void)
NarendraSingh 16:7703b9d92326 190 {
NarendraSingh 24:1063cfc311e5 191 led1=!led1;
NarendraSingh 16:7703b9d92326 192 //flip function
NarendraSingh 16:7703b9d92326 193 if(Ticker_Count < 5) {
NarendraSingh 11:77e595130230 194 Ticker_Count++;
NarendraSingh 16:7703b9d92326 195 } else {
NarendraSingh 11:77e595130230 196 Ticker_Count = 0;
NarendraSingh 11:77e595130230 197 Send_Lora_Packet_Flag = TRUE;
NarendraSingh 11:77e595130230 198 }
NarendraSingh 16:7703b9d92326 199 }
NarendraSingh 11:77e595130230 200
NarendraSingh 11:77e595130230 201 // called every time a byte is received from lora module.
NarendraSingh 11:77e595130230 202 void Lora_onDataRx()
NarendraSingh 11:77e595130230 203 {
NarendraSingh 16:7703b9d92326 204 while (LORA_UART.readable()) {
NarendraSingh 16:7703b9d92326 205 // while there is data waiting
NarendraSingh 11:77e595130230 206 LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos++] = LORA_UART.getc(); // put it in the buffer
NarendraSingh 20:f812f85cf97e 207 //pc1.putc(LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos-1]);
NarendraSingh 16:7703b9d92326 208 if(Lora_RxBuffer_End_Pos >= LORA_UART_RX_Size) {
NarendraSingh 11:77e595130230 209 // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation.
NarendraSingh 11:77e595130230 210 // For now just throw everything away.
NarendraSingh 11:77e595130230 211 Lora_RxBuffer_End_Pos = 0;
NarendraSingh 11:77e595130230 212 }
emilmont 1:491820ee784d 213 }
NarendraSingh 16:7703b9d92326 214 }
NarendraSingh 11:77e595130230 215
NarendraSingh 11:77e595130230 216 // called every time a byte is received from Beacon Module.
NarendraSingh 11:77e595130230 217 void Beacon_onDataRx()
NarendraSingh 11:77e595130230 218 {
NarendraSingh 16:7703b9d92326 219 while (Beacon_UART.readable()) {
NarendraSingh 16:7703b9d92326 220 // while there is data waiting
NarendraSingh 11:77e595130230 221 Beacon_RX_Buffer[Beacon_RxBuffer_End_Pos++] = Beacon_UART.getc(); // put it in the buffer
NarendraSingh 23:688ee106c385 222 pc1.printf("%2x",Beacon_RX_Buffer[Beacon_RxBuffer_End_Pos-1]);
NarendraSingh 16:7703b9d92326 223 if(Beacon_RxBuffer_End_Pos >= 100) {
NarendraSingh 11:77e595130230 224 // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation.
NarendraSingh 11:77e595130230 225 // For now just throw everything away.
NarendraSingh 11:77e595130230 226 Beacon_RxBuffer_End_Pos = 0;
NarendraSingh 11:77e595130230 227 }
emilmont 1:491820ee784d 228 }
emilmont 1:491820ee784d 229 }
NarendraSingh 11:77e595130230 230
NarendraSingh 16:7703b9d92326 231 void BLE_Receiver_onDataRx(void)
NarendraSingh 13:8955f2e95021 232 {
NarendraSingh 16:7703b9d92326 233 while (BLE_RECEIVER_UART.readable()) {
NarendraSingh 16:7703b9d92326 234 // while there is data waiting
NarendraSingh 24:1063cfc311e5 235 //BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos++] = BLE_RECEIVER_UART.getc(); // put it in the buffer
NarendraSingh 22:c2f034a13108 236 //pc1.putc(BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos-1]);
NarendraSingh 16:7703b9d92326 237 if(BLE_RxBuffer_End_Pos >= BLE_RECEIVER_UART_RX_Size) {
NarendraSingh 13:8955f2e95021 238 // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation.
NarendraSingh 13:8955f2e95021 239 // For now just throw everything away.
NarendraSingh 13:8955f2e95021 240 BLE_RxBuffer_End_Pos = 0;
NarendraSingh 13:8955f2e95021 241 }
NarendraSingh 12:6107b32b0729 242 }
NarendraSingh 16:7703b9d92326 243 }
NarendraSingh 16:7703b9d92326 244
NarendraSingh 16:7703b9d92326 245 int main()
NarendraSingh 11:77e595130230 246 {
NarendraSingh 17:758fb8454ab0 247 pc1.baud(115200);
NarendraSingh 16:7703b9d92326 248 BLE_RECEIVER_UART.baud(115200);
NarendraSingh 24:1063cfc311e5 249 pc1.printf("%s","Debugging started\n");
NarendraSingh 24:1063cfc311e5 250 //BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq);
NarendraSingh 11:77e595130230 251 LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq);
NarendraSingh 22:c2f034a13108 252 CheckIn_Interrupt.fall(&OBD_Plug_IN_Interrupt);
NarendraSingh 22:c2f034a13108 253 CheckIn_Interrupt.rise(&OBD_Plug_OUT_Interrupt);
NarendraSingh 24:1063cfc311e5 254 if(Switch2)
NarendraSingh 24:1063cfc311e5 255 {
NarendraSingh 24:1063cfc311e5 256 }
NarendraSingh 24:1063cfc311e5 257 Motion_Start_To_Stop.fall(&Start_To_Stop_Interrupt);
NarendraSingh 24:1063cfc311e5 258 Motion_Stop_To_Start.fall(&Stop_To_Start_Interrupt);
NarendraSingh 24:1063cfc311e5 259 Motion_Sudden_Jerk.fall(&Sudden_Jerk_Interrupt);
NarendraSingh 11:77e595130230 260 //Create a thread to read vehicle data
NarendraSingh 11:77e595130230 261 //Thread OBD_thread(OBD_Rcvd_Cmd_Processing_thread);
NarendraSingh 11:77e595130230 262
NarendraSingh 11:77e595130230 263 Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 3.0); // call flip_Packet_Sending_Flag function every 5 seconds
NarendraSingh 11:77e595130230 264
NarendraSingh 11:77e595130230 265 // OBD_PLUGIN_INTERRUPT_PIN.rise(&Enable_CheckIN_Packet_Sending); // call toggle function on the rising edge
NarendraSingh 11:77e595130230 266 //led2_thread is executing concurrently with main at this point
NarendraSingh 22:c2f034a13108 267 //inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge
NarendraSingh 19:886d50ecc718 268 Initialize_Beacon_Module();
NarendraSingh 24:1063cfc311e5 269 // Send_Command_To_BLE_Receiver(SET_BEACON_VENDOR_ID);
NarendraSingh 24:1063cfc311e5 270 // Send_Command_To_BLE_Receiver(SET_BEACON_MESSAGE_TYPE);
NarendraSingh 24:1063cfc311e5 271 pc1.printf("\n%s","Transmitter MAC ID received\n");
NarendraSingh 11:77e595130230 272 Lora_Periodic_Packet_Sending(); //Infinite loop for sending and receiving lora response, no return from here
NarendraSingh 16:7703b9d92326 273 }
NarendraSingh 13:8955f2e95021 274
NarendraSingh 23:688ee106c385 275 void Send_Command_To_BLE_Receiver(const char* Command)
NarendraSingh 23:688ee106c385 276 {
NarendraSingh 23:688ee106c385 277 uint8 i;
NarendraSingh 23:688ee106c385 278 for(i=0;i<12;i++)
NarendraSingh 23:688ee106c385 279 BLE_RECEIVER_UART.putc(Command[i]);
NarendraSingh 23:688ee106c385 280 }
NarendraSingh 16:7703b9d92326 281 //Function to be called when Interrupt is genearted for motion sensing, checkin
NarendraSingh 16:7703b9d92326 282 void Initialize_Packets_Sent_Count(void)
NarendraSingh 16:7703b9d92326 283 {
NarendraSingh 11:77e595130230 284 Motion_Packet_Sent_Count = 0x00;
NarendraSingh 11:77e595130230 285 CheckIN_Packet_Sent_Count = 0x00;
NarendraSingh 16:7703b9d92326 286 }
NarendraSingh 16:7703b9d92326 287
NarendraSingh 16:7703b9d92326 288 uint8 Status_Packet_Wait_Count = 0;
NarendraSingh 16:7703b9d92326 289 void Lora_Periodic_Packet_Sending()
NarendraSingh 11:77e595130230 290 {
NarendraSingh 24:1063cfc311e5 291 pc1.printf("\nPeriodic packet sending intiialized\n");
NarendraSingh 11:77e595130230 292 Set_Up_Lora_Network_Configuration();
NarendraSingh 16:7703b9d92326 293 Initialize_lora_Packets();
NarendraSingh 19:886d50ecc718 294 Send_Lora_Packet_Flag = TRUE;
NarendraSingh 16:7703b9d92326 295 while (true) {
NarendraSingh 16:7703b9d92326 296 if(Packet_Type_To_Send == HEARTBEAT_TYPE_PACKET) { //check if packet to be sent is Heartbeat packet
NarendraSingh 16:7703b9d92326 297 if(Send_Lora_Packet_Flag) { //Check if packet sending is enabled, Packet should be sent only when enabled after timeout period
NarendraSingh 24:1063cfc311e5 298 pc1.printf("\nStatus_Packet_Wait_Count %d\n",Status_Packet_Wait_Count);
NarendraSingh 12:6107b32b0729 299 Status_Packet_Wait_Count++;
NarendraSingh 21:a5fb0ae94dc6 300 if(Status_Packet_Wait_Count < 4) {
NarendraSingh 24:1063cfc311e5 301 // Send_Command_To_BLE_Receiver(GET_RSSI);
NarendraSingh 24:1063cfc311e5 302 //Send_RSSI_Request_Command(GET_RSSI);
NarendraSingh 24:1063cfc311e5 303 pc1.printf("\nSending heartbeat packet\n"); //call function to send periodic motion packet
NarendraSingh 12:6107b32b0729 304 Send_HeartBeat_Packet(); //call function to send heartbeat packet
NarendraSingh 24:1063cfc311e5 305 pc.printf("\nSent HeartBeat Packet\n");
NarendraSingh 24:1063cfc311e5 306 /*AT_Response_Receive_Status = FAILURE;
NarendraSingh 12:6107b32b0729 307 while(AT_Response_Receive_Status)
NarendraSingh 12:6107b32b0729 308 Get_Lora_Response();
NarendraSingh 24:1063cfc311e5 309 */Send_Lora_Packet_Flag = FALSE;
NarendraSingh 24:1063cfc311e5 310 pc1.printf("\nHeartbeat Packet Response Received\n");
NarendraSingh 22:c2f034a13108 311 } else {
NarendraSingh 20:f812f85cf97e 312 //Send_RSSI_Request_Command(GET_RSSI);
NarendraSingh 12:6107b32b0729 313 Status_Packet_Wait_Count = 0;
NarendraSingh 24:1063cfc311e5 314 pc1.printf("\nSending Vehicle status packets\n"); //call function to send periodic motion packet
NarendraSingh 13:8955f2e95021 315 Send_Vehicle_Status_Packet(); //call function to send heartbeat packet
NarendraSingh 24:1063cfc311e5 316 pc1.printf("\nSent Vehicle Status Packet\n");
NarendraSingh 19:886d50ecc718 317 //AT_Response_Receive_Status = FAILURE;
NarendraSingh 21:a5fb0ae94dc6 318 // while(AT_Response_Receive_Status)
NarendraSingh 19:886d50ecc718 319 // Get_Lora_Response();
NarendraSingh 12:6107b32b0729 320 Send_Lora_Packet_Flag = FALSE;
NarendraSingh 24:1063cfc311e5 321 Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET;
NarendraSingh 24:1063cfc311e5 322 //pc1.printf("\nStatus Packet Response Received\n");
NarendraSingh 12:6107b32b0729 323 }
NarendraSingh 11:77e595130230 324 }
NarendraSingh 16:7703b9d92326 325 } else if(Packet_Type_To_Send == MOTION_TYPE_PACKET) { //check if packet to be sent is motion packet
NarendraSingh 16:7703b9d92326 326 if(Send_Lora_Packet_Flag) { //Check if packet sending isd enabled, Packet should be sent only when enabled after timeout period
NarendraSingh 21:a5fb0ae94dc6 327 //Send_RSSI_Request_Command(GET_RSSI);
NarendraSingh 24:1063cfc311e5 328 pc1.printf("\nSending Motion Packet\n"); //call function to send periodic motion packet
NarendraSingh 11:77e595130230 329 Send_Motion_Packet();
NarendraSingh 24:1063cfc311e5 330 pc1.printf("\nSent Motion Packet\n"); //call function to send periodic motion packet
NarendraSingh 11:77e595130230 331 AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 332 while(AT_Response_Receive_Status)
NarendraSingh 11:77e595130230 333 Get_Lora_Response();
NarendraSingh 24:1063cfc311e5 334 pc1.printf("\nMotion Packet Response Received\n");
NarendraSingh 11:77e595130230 335 Send_Lora_Packet_Flag = FALSE;
NarendraSingh 16:7703b9d92326 336 if(Motion_Packet_Sent_Count >= 5) { //Stop Sending Motion Packets if after sending for 2 minute
NarendraSingh 24:1063cfc311e5 337 pc1.printf("\nPacket Type Sending Changed to HeartBeat\n");
NarendraSingh 11:77e595130230 338 Motion_Packet_Sent_Count = 0;
NarendraSingh 11:77e595130230 339 Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //Set Packet type to send as heartbeat packet
NarendraSingh 16:7703b9d92326 340 Lora_Packet_Sending_Ticker.detach(); //destroy ticker
NarendraSingh 11:77e595130230 341 Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 10.0); //create new ticker
NarendraSingh 11:77e595130230 342 }
NarendraSingh 16:7703b9d92326 343 }
NarendraSingh 16:7703b9d92326 344 } else if(Packet_Type_To_Send == CHECKIN_TYPE_PACKET) { //check if packet to be sent is Checkin packet
NarendraSingh 16:7703b9d92326 345 if(Send_Lora_Packet_Flag) { //Check if packet sending isd enabled, Packet should be sent only when enabled after timeout period
NarendraSingh 19:886d50ecc718 346 Send_Lora_Packet_Flag = FALSE;
NarendraSingh 24:1063cfc311e5 347 //pc1.printf("\nSent Beacon ID request\n");
NarendraSingh 20:f812f85cf97e 348 // Send_RSSI_Request_Command(GET_RSSI);
NarendraSingh 19:886d50ecc718 349 if(OBD_PlugIN_State)
NarendraSingh 19:886d50ecc718 350 {
NarendraSingh 24:1063cfc311e5 351 pc1.printf("\nSening Checkin Packet\n");
NarendraSingh 19:886d50ecc718 352 Send_CheckIN_Packet(); //call function to send periodic checkIn packet
NarendraSingh 24:1063cfc311e5 353 pc1.printf("\nSent Checkin Packet\n");
NarendraSingh 24:1063cfc311e5 354 //Process_Beacon_Command_Received(SET_VIRTUAL_PACKET_UUID);
NarendraSingh 24:1063cfc311e5 355 //wait(.2);
NarendraSingh 24:1063cfc311e5 356 //Process_Beacon_Command_Received(SOFT_REBOOT1);
NarendraSingh 19:886d50ecc718 357 }
NarendraSingh 19:886d50ecc718 358 else
NarendraSingh 19:886d50ecc718 359 {
NarendraSingh 24:1063cfc311e5 360 pc1.printf("\nSending Checkout Packet\n");
NarendraSingh 19:886d50ecc718 361 Send_CheckOUT_Packet();
NarendraSingh 24:1063cfc311e5 362 pc1.printf("\nSent CheckOut Packet\n");
NarendraSingh 24:1063cfc311e5 363 //Process_Beacon_Command_Received(SET_VIRTUAL_PACKET_UUID2);
NarendraSingh 24:1063cfc311e5 364 //wait(.2);
NarendraSingh 24:1063cfc311e5 365 //Process_Beacon_Command_Received(SOFT_REBOOT1);
NarendraSingh 19:886d50ecc718 366 }
NarendraSingh 22:c2f034a13108 367 /* AT_Response_Receive_Status = FAILURE;
NarendraSingh 11:77e595130230 368 while(AT_Response_Receive_Status)
NarendraSingh 22:c2f034a13108 369 Get_Lora_Response();*/
NarendraSingh 16:7703b9d92326 370 if(CheckIN_Packet_Sent_Count >= 5) { //Stop Sending Motion Packets if after sending for 2 minute
NarendraSingh 24:1063cfc311e5 371 pc1.printf("\nPacket Type Sending Changed to HeartBeat\n");
NarendraSingh 20:f812f85cf97e 372 CheckIN_Packet_Sent_Count = 0;
NarendraSingh 20:f812f85cf97e 373 Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //Set Packet type to send as heartbeat packet
NarendraSingh 20:f812f85cf97e 374 Initialize_Packets_Sent_Count();
NarendraSingh 11:77e595130230 375 }
NarendraSingh 11:77e595130230 376 }
NarendraSingh 16:7703b9d92326 377 }
NarendraSingh 16:7703b9d92326 378 if(OBD_PlugInOut_IOC_Status) { //Check if Accelerometer Interrupt is generated
NarendraSingh 13:8955f2e95021 379 //Enable_CheckIN_Packet_Sending();
NarendraSingh 11:77e595130230 380 //Get_Acceleration_Type();
NarendraSingh 21:a5fb0ae94dc6 381 // Process_Beacon_Command_Received(SET_VIRTUAL_PACKET_UUID);
NarendraSingh 21:a5fb0ae94dc6 382 // Process_Beacon_Command_Received(SOFT_REBOOT1);
NarendraSingh 11:77e595130230 383 OBD_PlugInOut_IOC_Status = FALSE;
NarendraSingh 13:8955f2e95021 384 Packet_Type_To_Send = CHECKIN_TYPE_PACKET;
NarendraSingh 13:8955f2e95021 385 Send_Lora_Packet_Flag = TRUE;
NarendraSingh 19:886d50ecc718 386 CheckIN_Packet_Sent_Count = 0;
NarendraSingh 24:1063cfc311e5 387 CheckIN_Lora_Packet.Sequence_No = 0x01; //Reset counter
NarendraSingh 24:1063cfc311e5 388 CheckOUT_Packet.Sequence_No = 0x01; //Reset counter
NarendraSingh 16:7703b9d92326 389 wait(1); //wait for 1sec to avoid detecting plugin debounce
NarendraSingh 11:77e595130230 390 }
NarendraSingh 16:7703b9d92326 391 if(Motion_Detect_Status) { //Check if Accelerometer Interrupt is generated
NarendraSingh 24:1063cfc311e5 392 Motion_Lora_Packet.Sequence_No = 0x01; //Reset counter
NarendraSingh 24:1063cfc311e5 393 Motion_Packet_Sent_Count = 0x00; //reset counetr
NarendraSingh 11:77e595130230 394 Get_Acceleration_Type();
NarendraSingh 11:77e595130230 395 Motion_Detect_Status = FALSE;
NarendraSingh 24:1063cfc311e5 396 Start_To_Stop_Status = FALSE;
NarendraSingh 24:1063cfc311e5 397 Jerk_Status = FALSE;
NarendraSingh 24:1063cfc311e5 398 Stop_To_Start_Status = FALSE;
NarendraSingh 24:1063cfc311e5 399 wait(1); //wait for 1sec to avoid detecting switch debounce
NarendraSingh 11:77e595130230 400 }
NarendraSingh 16:7703b9d92326 401 }
NarendraSingh 11:77e595130230 402 }
NarendraSingh 11:77e595130230 403
NarendraSingh 11:77e595130230 404 void Get_Acceleration_Type(void)
NarendraSingh 11:77e595130230 405 {
NarendraSingh 11:77e595130230 406 Packet_Type_To_Send = MOTION_TYPE_PACKET; //whenever acceleration is detected change the packet type to be sent to motion type
NarendraSingh 16:7703b9d92326 407 Lora_Packet_Sending_Ticker.detach(); //destroy ticker
NarendraSingh 11:77e595130230 408 Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 5.0); //create new ticker, time inetrval value to be changed
NarendraSingh 11:77e595130230 409 Send_Lora_Packet_Flag = 1; //set flag to send motion packet as soon as motion is detecetd
NarendraSingh 24:1063cfc311e5 410 if(Start_To_Stop_Status)
NarendraSingh 24:1063cfc311e5 411 Motion_Lora_Packet.Acceleration_Type = MOTION_TYPE_START_TO_STOP; //Read Type of motion deteceted
NarendraSingh 24:1063cfc311e5 412 if(Stop_To_Start_Status)
NarendraSingh 24:1063cfc311e5 413 Motion_Lora_Packet.Acceleration_Type = MOTION_TYPE_STOP_TO_START; //Read Type of motion deteceted
NarendraSingh 24:1063cfc311e5 414 if(Jerk_Status)
NarendraSingh 24:1063cfc311e5 415 Motion_Lora_Packet.Acceleration_Type = MOTION_TYPE_TAP; //Read Type of motion deteceted
NarendraSingh 11:77e595130230 416 //write code to read acceleration value for every 10sec after any of the acceleration is found
NarendraSingh 11:77e595130230 417 }
NarendraSingh 19:886d50ecc718 418
NarendraSingh 13:8955f2e95021 419 /*
NarendraSingh 11:77e595130230 420 //This function is used to enable checkin packet sending once OBD device is plugged in
NarendraSingh 16:7703b9d92326 421 void Enable_CheckIN_Packet_Sending()
NarendraSingh 11:77e595130230 422 {
NarendraSingh 12:6107b32b0729 423 // Enable_CheckIN_Packet_Sending = TRUE; //set status to true
NarendraSingh 13:8955f2e95021 424 if(Command_Received[0] == 0xFE) //check start of frame of packet received. every packet must start with 0xFE
NarendraSingh 11:77e595130230 425 {
NarendraSingh 11:77e595130230 426 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 427 {
NarendraSingh 11:77e595130230 428 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 429 {
NarendraSingh 11:77e595130230 430 Process_Beacon_Command_Received((Command_Received + 2));
NarendraSingh 11:77e595130230 431 }
NarendraSingh 11:77e595130230 432 }
NarendraSingh 13:8955f2e95021 433 }
NarendraSingh 15:a448e955b8f3 434 } */
NarendraSingh 15:a448e955b8f3 435
NarendraSingh 16:7703b9d92326 436 void Send_RSSI_Request_Command(const char* Command_To_Send)
NarendraSingh 15:a448e955b8f3 437 {
NarendraSingh 23:688ee106c385 438 //BLE_RECEIVER_UART.printf(Command_To_Send);
NarendraSingh 16:7703b9d92326 439 Get_Fixed_Beacon_RSSI();
NarendraSingh 15:a448e955b8f3 440 }
NarendraSingh 15:a448e955b8f3 441
NarendraSingh 16:7703b9d92326 442 void Get_Fixed_Beacon_RSSI(void)
NarendraSingh 15:a448e955b8f3 443 {
NarendraSingh 16:7703b9d92326 444 uint8 i;
NarendraSingh 16:7703b9d92326 445 uint8 Temp_Pos=0;
NarendraSingh 19:886d50ecc718 446 /*Fixed_Beacon_Packet.Parking1_Beacon_ID[0] = 0xA0;
NarendraSingh 16:7703b9d92326 447 Fixed_Beacon_Packet.Parking1_Beacon_ID[1] = 0xAC;
NarendraSingh 16:7703b9d92326 448 Fixed_Beacon_Packet.Parking1_Beacon_ID[2] = 0x51;
NarendraSingh 16:7703b9d92326 449 Fixed_Beacon_Packet.Parking1_Beacon_ID[3] = 0x3F;
NarendraSingh 16:7703b9d92326 450 Fixed_Beacon_Packet.Parking1_Beacon_ID[4] = 0x91;
NarendraSingh 16:7703b9d92326 451 Fixed_Beacon_Packet.Parking1_Beacon_ID[5] = 0xE0;
NarendraSingh 16:7703b9d92326 452 Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = 0xC3;
NarendraSingh 16:7703b9d92326 453 Fixed_Beacon_Packet.Parking2_Beacon_ID[0] = 0xDC;
NarendraSingh 16:7703b9d92326 454 Fixed_Beacon_Packet.Parking2_Beacon_ID[1] = 0xA3;
NarendraSingh 16:7703b9d92326 455 Fixed_Beacon_Packet.Parking2_Beacon_ID[2] = 0x6D;
NarendraSingh 16:7703b9d92326 456 Fixed_Beacon_Packet.Parking2_Beacon_ID[3] = 0x30;
NarendraSingh 16:7703b9d92326 457 Fixed_Beacon_Packet.Parking2_Beacon_ID[4] = 0x38;
NarendraSingh 16:7703b9d92326 458 Fixed_Beacon_Packet.Parking2_Beacon_ID[5] = 0xDF;
NarendraSingh 16:7703b9d92326 459 Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = 0xB4;
NarendraSingh 16:7703b9d92326 460 Fixed_Beacon_Packet.Parking3_Beacon_ID[0] = 0x6C;
NarendraSingh 16:7703b9d92326 461 Fixed_Beacon_Packet.Parking3_Beacon_ID[1] = 0x29;
NarendraSingh 16:7703b9d92326 462 Fixed_Beacon_Packet.Parking3_Beacon_ID[2] = 0xB6;
NarendraSingh 16:7703b9d92326 463 Fixed_Beacon_Packet.Parking3_Beacon_ID[3] = 0x27;
NarendraSingh 16:7703b9d92326 464 Fixed_Beacon_Packet.Parking3_Beacon_ID[4] = 0x3A;
NarendraSingh 16:7703b9d92326 465 Fixed_Beacon_Packet.Parking3_Beacon_ID[5] = 0xC9;
NarendraSingh 16:7703b9d92326 466 Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = 0xB0;
NarendraSingh 19:886d50ecc718 467 */
NarendraSingh 24:1063cfc311e5 468 pc1.printf("\nReading MACID from Receiver\n");
NarendraSingh 17:758fb8454ab0 469 while(true)
NarendraSingh 15:a448e955b8f3 470 {
NarendraSingh 21:a5fb0ae94dc6 471 wait_ms(2);
NarendraSingh 21:a5fb0ae94dc6 472 if(Temp_Pos <= BLE_RxBuffer_End_Pos)
NarendraSingh 15:a448e955b8f3 473 {
NarendraSingh 17:758fb8454ab0 474 if(BLE_Receiver_UART_RX_Buffer[Temp_Pos] == 0x0D)
NarendraSingh 16:7703b9d92326 475 {
NarendraSingh 17:758fb8454ab0 476 if(BLE_Receiver_UART_RX_Buffer[Temp_Pos+1] == 0x0A)
NarendraSingh 16:7703b9d92326 477 {
NarendraSingh 16:7703b9d92326 478 Temp_Pos = 2;
NarendraSingh 24:1063cfc311e5 479 //pc1.printf("\nFixed Beacon1 MAC ID\n");
NarendraSingh 16:7703b9d92326 480 for(i=0; i<6; i++)
NarendraSingh 21:a5fb0ae94dc6 481 {
NarendraSingh 21:a5fb0ae94dc6 482 Fixed_Beacon_Packet.Parking1_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
NarendraSingh 21:a5fb0ae94dc6 483 pc1.putc(Fixed_Beacon_Packet.Parking1_Beacon_ID[i]);
NarendraSingh 21:a5fb0ae94dc6 484 }
NarendraSingh 19:886d50ecc718 485 Temp_Pos+=2;
NarendraSingh 16:7703b9d92326 486 Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
NarendraSingh 24:1063cfc311e5 487 //pc1.printf("\nFixed Beacon2 MAC ID\n");
NarendraSingh 16:7703b9d92326 488 for(i=0; i<6; i++)
NarendraSingh 21:a5fb0ae94dc6 489 {
NarendraSingh 16:7703b9d92326 490 Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
NarendraSingh 21:a5fb0ae94dc6 491 pc1.putc(Fixed_Beacon_Packet.Parking2_Beacon_ID[i]);
NarendraSingh 21:a5fb0ae94dc6 492 }
NarendraSingh 19:886d50ecc718 493 Temp_Pos+=2;
NarendraSingh 16:7703b9d92326 494 Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
NarendraSingh 24:1063cfc311e5 495 //pc1.printf("\nFixed Beacon3 MAC ID\n");
NarendraSingh 16:7703b9d92326 496 for(i=0; i<6; i++)
NarendraSingh 21:a5fb0ae94dc6 497 {
NarendraSingh 21:a5fb0ae94dc6 498 Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
NarendraSingh 21:a5fb0ae94dc6 499 pc1.putc(Fixed_Beacon_Packet.Parking3_Beacon_ID[i]);
NarendraSingh 21:a5fb0ae94dc6 500 }
NarendraSingh 19:886d50ecc718 501 Temp_Pos+=2;
NarendraSingh 16:7703b9d92326 502 Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++];
NarendraSingh 21:a5fb0ae94dc6 503 BLE_RxBuffer_End_Pos = 0x00; //Start Next adat at 0th location
NarendraSingh 16:7703b9d92326 504 break;
NarendraSingh 16:7703b9d92326 505 }
NarendraSingh 16:7703b9d92326 506 Temp_Pos++;
NarendraSingh 15:a448e955b8f3 507 }
NarendraSingh 16:7703b9d92326 508 else
NarendraSingh 16:7703b9d92326 509 Temp_Pos++;
NarendraSingh 15:a448e955b8f3 510 }
NarendraSingh 15:a448e955b8f3 511 else
NarendraSingh 16:7703b9d92326 512 Temp_Pos = 0x00;
NarendraSingh 19:886d50ecc718 513 }
NarendraSingh 24:1063cfc311e5 514 pc1.printf("\nReading MACID finished\n");
NarendraSingh 15:a448e955b8f3 515 }