kumar singh
/
Dealer_20Mar
BLE Transmitter not working
Fork of Dealer_23Feb by
main.cpp@25:0ac2680d594c, 2017-03-03 (annotated)
- Committer:
- NarendraSingh
- Date:
- Fri Mar 03 08:48:39 2017 +0000
- Revision:
- 25:0ac2680d594c
- Parent:
- 24:1063cfc311e5
03Mar2017;
Who changed what in which revision?
User | Revision | Line number | New 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 | 25:0ac2680d594c | 8 | #include "OBD_Libraries.h" |
NarendraSingh | 11:77e595130230 | 9 | |
NarendraSingh | 11:77e595130230 | 10 | //Datatype typecasting |
NarendraSingh | 11:77e595130230 | 11 | typedef unsigned char uint8; |
NarendraSingh | 11:77e595130230 | 12 | typedef unsigned int uint16; |
NarendraSingh | 11:77e595130230 | 13 | |
NarendraSingh | 16:7703b9d92326 | 14 | uint8 OBD_Plug_In_Status = FALSE; |
NarendraSingh | 16:7703b9d92326 | 15 | |
NarendraSingh | 16:7703b9d92326 | 16 | //peripheral connection |
NarendraSingh | 24:1063cfc311e5 | 17 | DigitalOut led1(PB_11); |
emilmont | 1:491820ee784d | 18 | DigitalOut led2(LED2); |
NarendraSingh | 24:1063cfc311e5 | 19 | DigitalIn Switch2(PB_13); |
NarendraSingh | 11:77e595130230 | 20 | |
NarendraSingh | 11:77e595130230 | 21 | //Configure Serial port |
NarendraSingh | 16:7703b9d92326 | 22 | 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 | 25:0ac2680d594c | 23 | RawSerial pc1(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only |
NarendraSingh | 25:0ac2680d594c | 24 | RawSerial DEBUG_UART(PA_14, PA_15);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only |
NarendraSingh | 16:7703b9d92326 | 25 | RawSerial Beacon_UART(PC_4, PC_5);//USART3_TX->PC4,USART3_RX->PC_5 : Used for sending command to beacon module |
NarendraSingh | 16:7703b9d92326 | 26 | 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 | 25:0ac2680d594c | 27 | //Serial pc1(USBTX, USBRX); |
NarendraSingh | 25:0ac2680d594c | 28 | //RawSerial DEBUG_UART(USBTX, USBRX);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only |
NarendraSingh | 16:7703b9d92326 | 29 | |
NarendraSingh | 16:7703b9d92326 | 30 | //InterruptIn OBD_PLUGIN_INTERRUPT_PIN(PC_13); |
NarendraSingh | 21:a5fb0ae94dc6 | 31 | InterruptIn CheckIn_Interrupt(PB_7);//(PC_13); |
NarendraSingh | 24:1063cfc311e5 | 32 | InterruptIn Motion_Start_To_Stop(PB_5);//(PC_13); |
NarendraSingh | 24:1063cfc311e5 | 33 | InterruptIn Motion_Stop_To_Start(PB_14);//(PC_13); |
NarendraSingh | 24:1063cfc311e5 | 34 | InterruptIn Motion_Sudden_Jerk(PC_13);//(PC_13); |
NarendraSingh | 24:1063cfc311e5 | 35 | |
NarendraSingh | 16:7703b9d92326 | 36 | |
NarendraSingh | 16:7703b9d92326 | 37 | uint8 Ticker_Count = 0; //Variable to count for timer overflows |
NarendraSingh | 16:7703b9d92326 | 38 | |
NarendraSingh | 16:7703b9d92326 | 39 | uint8 OBD_Plugin_Detected = FALSE; |
NarendraSingh | 16:7703b9d92326 | 40 | |
NarendraSingh | 16:7703b9d92326 | 41 | //Create Object for structure of Lora Packet to be sent |
NarendraSingh | 11:77e595130230 | 42 | |
NarendraSingh | 16:7703b9d92326 | 43 | static uint16 Calculate_Wheels_RPM(uint8* Buffer); |
NarendraSingh | 16:7703b9d92326 | 44 | void flip_Packet_Sending_Flag(); |
NarendraSingh | 16:7703b9d92326 | 45 | void Lora_Periodic_Packet_Sending_thread(void const *args); |
NarendraSingh | 11:77e595130230 | 46 | |
NarendraSingh | 16:7703b9d92326 | 47 | void Lora_Rcvd_Cmd_Processing_thread(void);// const *args); |
NarendraSingh | 16:7703b9d92326 | 48 | void Enable_CheckIN_Packet_Sending(); |
NarendraSingh | 16:7703b9d92326 | 49 | |
NarendraSingh | 23:688ee106c385 | 50 | const char GET_RSSI[]= {0x41,0x54,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x0A}; |
NarendraSingh | 23:688ee106c385 | 51 | const char SET_BEACON_VENDOR_ID[]= {0x41,0x54,0xF1,0x01,0x02,0x00,0x00,0x00,0x00,0xF2,0x0D,0x0A}; |
NarendraSingh | 23:688ee106c385 | 52 | const char SET_BEACON_MESSAGE_TYPE[]= {0x41,0x54,0xF2,0x01,0x00,0x00,0x00,0x00,0x00,0xF3,0x0D,0x0A}; |
NarendraSingh | 11:77e595130230 | 53 | /*************************Accelerometer related definitions***********************************/ |
NarendraSingh | 11:77e595130230 | 54 | //Accelerometer related definitions |
NarendraSingh | 13:8955f2e95021 | 55 | |
NarendraSingh | 11:77e595130230 | 56 | #define DOUBLE_TAP_INTERRUPT 0x20 |
NarendraSingh | 11:77e595130230 | 57 | #define ACTIVITY_INTERRUPT 0x10 |
NarendraSingh | 11:77e595130230 | 58 | #define INACTIVITY_INTERRUPT 0x08 |
NarendraSingh | 11:77e595130230 | 59 | |
NarendraSingh | 16:7703b9d92326 | 60 | #define TAP_THRESHOLD 75 |
NarendraSingh | 11:77e595130230 | 61 | #define ACTIVITY_THRESHOLD 64 // THRES_ACT register value 62.5mg/LSB , therfore value 32 indicates 2g activity |
NarendraSingh | 11:77e595130230 | 62 | #define INACTIVITY_THRESHOLD 50 |
NarendraSingh | 11:77e595130230 | 63 | |
NarendraSingh | 11:77e595130230 | 64 | #define DUR_TIME 0x15 // DUR Register value providing maximum time to be held to generate an interrupt |
NarendraSingh | 11:77e595130230 | 65 | #define LATENT_TIME 0x15 // The interrupt latency |
NarendraSingh | 11:77e595130230 | 66 | #define WINDOW_TIME 0x45 // The time of the interrupt window in which the next tap will be detected |
NarendraSingh | 11:77e595130230 | 67 | #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 | 68 | // Here the value 5 indicates literally 5 secs |
NarendraSingh | 11:77e595130230 | 69 | #define X_AXIS_OFFSET 0x7F |
NarendraSingh | 11:77e595130230 | 70 | #define Y_AXIS_OFFSET 0x7F |
NarendraSingh | 11:77e595130230 | 71 | #define Z_AXIS_OFFSET 0x05 |
NarendraSingh | 11:77e595130230 | 72 | |
NarendraSingh | 17:758fb8454ab0 | 73 | Serial pc(USBTX, USBRX); |
NarendraSingh | 16:7703b9d92326 | 74 | I2C i2c(PB_9, PB_8); |
NarendraSingh | 11:77e595130230 | 75 | |
NarendraSingh | 16:7703b9d92326 | 76 | InterruptIn activity(PB_0); |
NarendraSingh | 11:77e595130230 | 77 | InterruptIn inactivity(PA_4); // As for now only this is used |
NarendraSingh | 11:77e595130230 | 78 | DigitalOut led(LED1); |
NarendraSingh | 11:77e595130230 | 79 | |
NarendraSingh | 11:77e595130230 | 80 | const int slave_address_acc = 0xA6; |
NarendraSingh | 11:77e595130230 | 81 | char axis_data[6] = {0,0,0,0,0,0}; |
NarendraSingh | 11:77e595130230 | 82 | |
NarendraSingh | 11:77e595130230 | 83 | char interrupt_source[2]; |
NarendraSingh | 11:77e595130230 | 84 | char axis_data_start_address[2] = {0x32, 0}; |
NarendraSingh | 11:77e595130230 | 85 | char intr_source_address[2] = {0x30, 0}; |
NarendraSingh | 11:77e595130230 | 86 | char all_interrupt_clear_command[2] = {0x2E, 0x00}; |
NarendraSingh | 11:77e595130230 | 87 | char all_interrupt_enable_command[2] = {0x2E, 0x38}; |
NarendraSingh | 11:77e595130230 | 88 | char activity_interrupt_disable_command[2] = {0x2E, 0x08}; |
NarendraSingh | 11:77e595130230 | 89 | char inactivity_interrupt_disable_command[2] = {0x2E, 0x30}; |
NarendraSingh | 11:77e595130230 | 90 | char accelerometer_status_registered = 0; |
NarendraSingh | 11:77e595130230 | 91 | unsigned int interrupt_source_duplicate; |
NarendraSingh | 11:77e595130230 | 92 | |
NarendraSingh | 11:77e595130230 | 93 | char threshold_offset_command[5]; |
NarendraSingh | 11:77e595130230 | 94 | char act_inact_time_config_command[8]; |
NarendraSingh | 11:77e595130230 | 95 | char interrupt_enable_command[3]; |
NarendraSingh | 11:77e595130230 | 96 | char tap_axis_enable_command[2]; |
NarendraSingh | 11:77e595130230 | 97 | char baud_rate_command[2]; |
NarendraSingh | 11:77e595130230 | 98 | char data_format_command[2]; |
NarendraSingh | 11:77e595130230 | 99 | char measure_bit_on_command[2]; |
NarendraSingh | 11:77e595130230 | 100 | |
NarendraSingh | 11:77e595130230 | 101 | |
NarendraSingh | 25:0ac2680d594c | 102 | unsigned char vehicle_speed1 = 25; // Kmph |
NarendraSingh | 11:77e595130230 | 103 | unsigned char current_speed, previous_speed, speed_threshold = 10; // Kmph |
NarendraSingh | 11:77e595130230 | 104 | |
NarendraSingh | 11:77e595130230 | 105 | unsigned char x_axis, y_axis, z_axis; |
NarendraSingh | 11:77e595130230 | 106 | |
NarendraSingh | 11:77e595130230 | 107 | unsigned char Motion_Detect_Status = FALSE; |
NarendraSingh | 11:77e595130230 | 108 | uint8 OBD_PlugInOut_IOC_Status = FALSE; |
NarendraSingh | 11:77e595130230 | 109 | unsigned char Motion_Type_Detected = MOTION_TYPE_UNKNOWN; //By default set motion type as unknown |
NarendraSingh | 11:77e595130230 | 110 | void Accelerometer_Process_thread();//void const *args) ; |
NarendraSingh | 11:77e595130230 | 111 | |
NarendraSingh | 16:7703b9d92326 | 112 | #define BLE_RECEIVER_UART_RX_Size 100 |
NarendraSingh | 16:7703b9d92326 | 113 | uint8 BLE_RxBuffer_End_Pos = 0; |
NarendraSingh | 16:7703b9d92326 | 114 | char BLE_Receiver_UART_RX_Buffer[BLE_RECEIVER_UART_RX_Size]; |
NarendraSingh | 13:8955f2e95021 | 115 | |
NarendraSingh | 11:77e595130230 | 116 | //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 | 117 | void interrupt_activity_inactivity() |
NarendraSingh | 16:7703b9d92326 | 118 | { |
NarendraSingh | 16:7703b9d92326 | 119 | i2c.write(slave_address_acc, all_interrupt_clear_command, 2); |
NarendraSingh | 16:7703b9d92326 | 120 | Motion_Detect_Status = TRUE; |
NarendraSingh | 11:77e595130230 | 121 | } |
NarendraSingh | 13:8955f2e95021 | 122 | |
NarendraSingh | 13:8955f2e95021 | 123 | |
NarendraSingh | 16:7703b9d92326 | 124 | /************************************************************************/ |
NarendraSingh | 11:77e595130230 | 125 | uint8 Command_Sent[100]; |
NarendraSingh | 11:77e595130230 | 126 | uint8 Command_Length_Sent; |
NarendraSingh | 12:6107b32b0729 | 127 | uint8 Checkin_Detect_Status = FALSE; |
NarendraSingh | 11:77e595130230 | 128 | void Extract_Received_Lora_Response(void); |
NarendraSingh | 23:688ee106c385 | 129 | void Send_Command_To_BLE_Receiver(const char* Command); |
NarendraSingh | 16:7703b9d92326 | 130 | |
NarendraSingh | 16:7703b9d92326 | 131 | char previous_state = 0; |
NarendraSingh | 16:7703b9d92326 | 132 | char current_state = 0; |
NarendraSingh | 16:7703b9d92326 | 133 | |
NarendraSingh | 16:7703b9d92326 | 134 | uint8 OBD_PlugIN_State=0; |
NarendraSingh | 16:7703b9d92326 | 135 | uint8 OBD_PlugIN_State1=0; |
NarendraSingh | 16:7703b9d92326 | 136 | uint8 OBD_PlugIN_State2=0; |
NarendraSingh | 16:7703b9d92326 | 137 | uint8 OBD_PlugIN_Temp_State=1; |
NarendraSingh | 16:7703b9d92326 | 138 | |
NarendraSingh | 24:1063cfc311e5 | 139 | uint8 Start_To_Stop_Status = FALSE; |
NarendraSingh | 24:1063cfc311e5 | 140 | uint8 Stop_To_Start_Status = FALSE; |
NarendraSingh | 24:1063cfc311e5 | 141 | uint8 Jerk_Status = FALSE; |
NarendraSingh | 24:1063cfc311e5 | 142 | |
NarendraSingh | 24:1063cfc311e5 | 143 | void Start_To_Stop_Interrupt() |
NarendraSingh | 24:1063cfc311e5 | 144 | { |
NarendraSingh | 24:1063cfc311e5 | 145 | Start_To_Stop_Status = TRUE; |
NarendraSingh | 24:1063cfc311e5 | 146 | Motion_Detect_Status = TRUE; |
NarendraSingh | 24:1063cfc311e5 | 147 | } |
NarendraSingh | 24:1063cfc311e5 | 148 | |
NarendraSingh | 24:1063cfc311e5 | 149 | void Stop_To_Start_Interrupt() |
NarendraSingh | 24:1063cfc311e5 | 150 | { |
NarendraSingh | 24:1063cfc311e5 | 151 | Stop_To_Start_Status = TRUE; |
NarendraSingh | 24:1063cfc311e5 | 152 | Motion_Detect_Status = TRUE; |
NarendraSingh | 24:1063cfc311e5 | 153 | } |
NarendraSingh | 24:1063cfc311e5 | 154 | |
NarendraSingh | 24:1063cfc311e5 | 155 | void Sudden_Jerk_Interrupt() |
NarendraSingh | 24:1063cfc311e5 | 156 | { |
NarendraSingh | 24:1063cfc311e5 | 157 | Jerk_Status = TRUE; |
NarendraSingh | 24:1063cfc311e5 | 158 | Motion_Detect_Status = TRUE; |
NarendraSingh | 24:1063cfc311e5 | 159 | } |
NarendraSingh | 16:7703b9d92326 | 160 | void OBD_Plug_IN_Interrupt() |
NarendraSingh | 16:7703b9d92326 | 161 | { |
NarendraSingh | 17:758fb8454ab0 | 162 | if(OBD_PlugIN_State1!=OBD_PlugIN_Temp_State) { |
NarendraSingh | 16:7703b9d92326 | 163 | OBD_PlugIN_State1=1; |
NarendraSingh | 16:7703b9d92326 | 164 | OBD_PlugIN_State=!OBD_PlugIN_State; |
NarendraSingh | 16:7703b9d92326 | 165 | OBD_PlugIN_Temp_State=OBD_PlugIN_State; |
NarendraSingh | 16:7703b9d92326 | 166 | OBD_PlugInOut_IOC_Status = TRUE; |
NarendraSingh | 16:7703b9d92326 | 167 | } |
NarendraSingh | 16:7703b9d92326 | 168 | } |
NarendraSingh | 17:758fb8454ab0 | 169 | |
NarendraSingh | 16:7703b9d92326 | 170 | void OBD_Plug_OUT_Interrupt() |
NarendraSingh | 16:7703b9d92326 | 171 | { |
NarendraSingh | 22:c2f034a13108 | 172 | |
NarendraSingh | 17:758fb8454ab0 | 173 | if(OBD_PlugIN_State2!=OBD_PlugIN_Temp_State) { |
NarendraSingh | 16:7703b9d92326 | 174 | OBD_PlugIN_State2=0; |
NarendraSingh | 16:7703b9d92326 | 175 | OBD_PlugIN_State=!OBD_PlugIN_State; |
NarendraSingh | 16:7703b9d92326 | 176 | OBD_PlugIN_Temp_State=OBD_PlugIN_State; |
NarendraSingh | 16:7703b9d92326 | 177 | OBD_PlugInOut_IOC_Status = TRUE; |
NarendraSingh | 17:758fb8454ab0 | 178 | } |
NarendraSingh | 16:7703b9d92326 | 179 | } |
NarendraSingh | 16:7703b9d92326 | 180 | |
NarendraSingh | 16:7703b9d92326 | 181 | //This function is Interrupt routine for detecting OBD Plugin and Out |
NarendraSingh | 11:77e595130230 | 182 | void Handle_CheckIn_Interrupt() |
NarendraSingh | 16:7703b9d92326 | 183 | { |
NarendraSingh | 11:77e595130230 | 184 | OBD_PlugInOut_IOC_Status = TRUE; |
NarendraSingh | 24:1063cfc311e5 | 185 | pc.printf("\nMovement_Detected\n"); |
NarendraSingh | 11:77e595130230 | 186 | } |
NarendraSingh | 11:77e595130230 | 187 | |
NarendraSingh | 16:7703b9d92326 | 188 | //Declare Ticker for sending lora packet |
NarendraSingh | 16:7703b9d92326 | 189 | Ticker Lora_Packet_Sending_Ticker; |
NarendraSingh | 16:7703b9d92326 | 190 | void flip_Packet_Sending_Flag(void) |
NarendraSingh | 16:7703b9d92326 | 191 | { |
NarendraSingh | 24:1063cfc311e5 | 192 | led1=!led1; |
NarendraSingh | 16:7703b9d92326 | 193 | //flip function |
NarendraSingh | 16:7703b9d92326 | 194 | if(Ticker_Count < 5) { |
NarendraSingh | 11:77e595130230 | 195 | Ticker_Count++; |
NarendraSingh | 16:7703b9d92326 | 196 | } else { |
NarendraSingh | 11:77e595130230 | 197 | Ticker_Count = 0; |
NarendraSingh | 11:77e595130230 | 198 | Send_Lora_Packet_Flag = TRUE; |
NarendraSingh | 11:77e595130230 | 199 | } |
NarendraSingh | 16:7703b9d92326 | 200 | } |
NarendraSingh | 11:77e595130230 | 201 | |
NarendraSingh | 11:77e595130230 | 202 | // called every time a byte is received from lora module. |
NarendraSingh | 11:77e595130230 | 203 | void Lora_onDataRx() |
NarendraSingh | 11:77e595130230 | 204 | { |
NarendraSingh | 16:7703b9d92326 | 205 | while (LORA_UART.readable()) { |
NarendraSingh | 16:7703b9d92326 | 206 | // while there is data waiting |
NarendraSingh | 11:77e595130230 | 207 | LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos++] = LORA_UART.getc(); // put it in the buffer |
NarendraSingh | 20:f812f85cf97e | 208 | //pc1.putc(LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos-1]); |
NarendraSingh | 16:7703b9d92326 | 209 | if(Lora_RxBuffer_End_Pos >= LORA_UART_RX_Size) { |
NarendraSingh | 11:77e595130230 | 210 | // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. |
NarendraSingh | 11:77e595130230 | 211 | // For now just throw everything away. |
NarendraSingh | 11:77e595130230 | 212 | Lora_RxBuffer_End_Pos = 0; |
NarendraSingh | 11:77e595130230 | 213 | } |
emilmont | 1:491820ee784d | 214 | } |
NarendraSingh | 16:7703b9d92326 | 215 | } |
NarendraSingh | 11:77e595130230 | 216 | |
NarendraSingh | 11:77e595130230 | 217 | // called every time a byte is received from Beacon Module. |
NarendraSingh | 11:77e595130230 | 218 | void Beacon_onDataRx() |
NarendraSingh | 11:77e595130230 | 219 | { |
NarendraSingh | 16:7703b9d92326 | 220 | while (Beacon_UART.readable()) { |
NarendraSingh | 16:7703b9d92326 | 221 | // while there is data waiting |
NarendraSingh | 11:77e595130230 | 222 | Beacon_RX_Buffer[Beacon_RxBuffer_End_Pos++] = Beacon_UART.getc(); // put it in the buffer |
NarendraSingh | 23:688ee106c385 | 223 | pc1.printf("%2x",Beacon_RX_Buffer[Beacon_RxBuffer_End_Pos-1]); |
NarendraSingh | 16:7703b9d92326 | 224 | if(Beacon_RxBuffer_End_Pos >= 100) { |
NarendraSingh | 11:77e595130230 | 225 | // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. |
NarendraSingh | 11:77e595130230 | 226 | // For now just throw everything away. |
NarendraSingh | 11:77e595130230 | 227 | Beacon_RxBuffer_End_Pos = 0; |
NarendraSingh | 11:77e595130230 | 228 | } |
emilmont | 1:491820ee784d | 229 | } |
emilmont | 1:491820ee784d | 230 | } |
NarendraSingh | 11:77e595130230 | 231 | |
NarendraSingh | 16:7703b9d92326 | 232 | void BLE_Receiver_onDataRx(void) |
NarendraSingh | 13:8955f2e95021 | 233 | { |
NarendraSingh | 16:7703b9d92326 | 234 | while (BLE_RECEIVER_UART.readable()) { |
NarendraSingh | 16:7703b9d92326 | 235 | // while there is data waiting |
NarendraSingh | 25:0ac2680d594c | 236 | BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos++] = BLE_RECEIVER_UART.getc(); // put it in the buffer |
NarendraSingh | 25:0ac2680d594c | 237 | //pc1.printf("%2x",BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos-1]); |
NarendraSingh | 16:7703b9d92326 | 238 | if(BLE_RxBuffer_End_Pos >= BLE_RECEIVER_UART_RX_Size) { |
NarendraSingh | 13:8955f2e95021 | 239 | // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. |
NarendraSingh | 13:8955f2e95021 | 240 | // For now just throw everything away. |
NarendraSingh | 13:8955f2e95021 | 241 | BLE_RxBuffer_End_Pos = 0; |
NarendraSingh | 13:8955f2e95021 | 242 | } |
NarendraSingh | 12:6107b32b0729 | 243 | } |
NarendraSingh | 16:7703b9d92326 | 244 | } |
NarendraSingh | 16:7703b9d92326 | 245 | |
NarendraSingh | 16:7703b9d92326 | 246 | int main() |
NarendraSingh | 11:77e595130230 | 247 | { |
NarendraSingh | 25:0ac2680d594c | 248 | pc1.baud(115200); |
NarendraSingh | 16:7703b9d92326 | 249 | BLE_RECEIVER_UART.baud(115200); |
NarendraSingh | 24:1063cfc311e5 | 250 | pc1.printf("%s","Debugging started\n"); |
NarendraSingh | 25:0ac2680d594c | 251 | BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq); |
NarendraSingh | 11:77e595130230 | 252 | LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq); |
NarendraSingh | 25:0ac2680d594c | 253 | //CheckIn_Interrupt.fall(&OBD_Plug_IN_Interrupt); |
NarendraSingh | 25:0ac2680d594c | 254 | //CheckIn_Interrupt.rise(&OBD_Plug_OUT_Interrupt); |
NarendraSingh | 25:0ac2680d594c | 255 | //Motion_Start_To_Stop.fall(&Start_To_Stop_Interrupt); |
NarendraSingh | 25:0ac2680d594c | 256 | //Motion_Stop_To_Start.fall(&Stop_To_Start_Interrupt); |
NarendraSingh | 25:0ac2680d594c | 257 | //Motion_Sudden_Jerk.fall(&Sudden_Jerk_Interrupt); |
NarendraSingh | 11:77e595130230 | 258 | //Create a thread to read vehicle data |
NarendraSingh | 11:77e595130230 | 259 | //Thread OBD_thread(OBD_Rcvd_Cmd_Processing_thread); |
NarendraSingh | 11:77e595130230 | 260 | |
NarendraSingh | 11:77e595130230 | 261 | Lora_Packet_Sending_Ticker.attach(&flip_Packet_Sending_Flag, 3.0); // call flip_Packet_Sending_Flag function every 5 seconds |
NarendraSingh | 11:77e595130230 | 262 | |
NarendraSingh | 11:77e595130230 | 263 | // OBD_PLUGIN_INTERRUPT_PIN.rise(&Enable_CheckIN_Packet_Sending); // call toggle function on the rising edge |
NarendraSingh | 11:77e595130230 | 264 | //led2_thread is executing concurrently with main at this point |
NarendraSingh | 22:c2f034a13108 | 265 | //inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge |
NarendraSingh | 19:886d50ecc718 | 266 | Initialize_Beacon_Module(); |
NarendraSingh | 25:0ac2680d594c | 267 | Send_Command_To_BLE_Receiver(SET_BEACON_VENDOR_ID); |
NarendraSingh | 25:0ac2680d594c | 268 | Send_Command_To_BLE_Receiver(SET_BEACON_MESSAGE_TYPE); |
NarendraSingh | 25:0ac2680d594c | 269 | //initialize_obd(); |
NarendraSingh | 24:1063cfc311e5 | 270 | pc1.printf("\n%s","Transmitter MAC ID received\n"); |
NarendraSingh | 11:77e595130230 | 271 | Lora_Periodic_Packet_Sending(); //Infinite loop for sending and receiving lora response, no return from here |
NarendraSingh | 16:7703b9d92326 | 272 | } |
NarendraSingh | 13:8955f2e95021 | 273 | |
NarendraSingh | 23:688ee106c385 | 274 | void Send_Command_To_BLE_Receiver(const char* Command) |
NarendraSingh | 23:688ee106c385 | 275 | { |
NarendraSingh | 23:688ee106c385 | 276 | uint8 i; |
NarendraSingh | 23:688ee106c385 | 277 | for(i=0;i<12;i++) |
NarendraSingh | 23:688ee106c385 | 278 | BLE_RECEIVER_UART.putc(Command[i]); |
NarendraSingh | 23:688ee106c385 | 279 | } |
NarendraSingh | 16:7703b9d92326 | 280 | //Function to be called when Interrupt is genearted for motion sensing, checkin |
NarendraSingh | 16:7703b9d92326 | 281 | void Initialize_Packets_Sent_Count(void) |
NarendraSingh | 16:7703b9d92326 | 282 | { |
NarendraSingh | 11:77e595130230 | 283 | Motion_Packet_Sent_Count = 0x00; |
NarendraSingh | 11:77e595130230 | 284 | CheckIN_Packet_Sent_Count = 0x00; |
NarendraSingh | 16:7703b9d92326 | 285 | } |
NarendraSingh | 16:7703b9d92326 | 286 | |
NarendraSingh | 16:7703b9d92326 | 287 | uint8 Status_Packet_Wait_Count = 0; |
NarendraSingh | 16:7703b9d92326 | 288 | void Lora_Periodic_Packet_Sending() |
NarendraSingh | 11:77e595130230 | 289 | { |
NarendraSingh | 24:1063cfc311e5 | 290 | pc1.printf("\nPeriodic packet sending intiialized\n"); |
NarendraSingh | 11:77e595130230 | 291 | Set_Up_Lora_Network_Configuration(); |
NarendraSingh | 16:7703b9d92326 | 292 | Initialize_lora_Packets(); |
NarendraSingh | 19:886d50ecc718 | 293 | Send_Lora_Packet_Flag = TRUE; |
NarendraSingh | 16:7703b9d92326 | 294 | while (true) { |
NarendraSingh | 16:7703b9d92326 | 295 | if(Packet_Type_To_Send == HEARTBEAT_TYPE_PACKET) { //check if packet to be sent is Heartbeat packet |
NarendraSingh | 16:7703b9d92326 | 296 | if(Send_Lora_Packet_Flag) { //Check if packet sending is enabled, Packet should be sent only when enabled after timeout period |
NarendraSingh | 24:1063cfc311e5 | 297 | pc1.printf("\nStatus_Packet_Wait_Count %d\n",Status_Packet_Wait_Count); |
NarendraSingh | 12:6107b32b0729 | 298 | Status_Packet_Wait_Count++; |
NarendraSingh | 21:a5fb0ae94dc6 | 299 | if(Status_Packet_Wait_Count < 4) { |
NarendraSingh | 25:0ac2680d594c | 300 | Send_Command_To_BLE_Receiver(GET_RSSI); |
NarendraSingh | 25:0ac2680d594c | 301 | Send_RSSI_Request_Command(GET_RSSI); |
NarendraSingh | 24:1063cfc311e5 | 302 | pc1.printf("\nSending heartbeat packet\n"); //call function to send periodic motion packet |
NarendraSingh | 12:6107b32b0729 | 303 | Send_HeartBeat_Packet(); //call function to send heartbeat packet |
NarendraSingh | 24:1063cfc311e5 | 304 | pc.printf("\nSent HeartBeat Packet\n"); |
NarendraSingh | 25:0ac2680d594c | 305 | Process_Beacon_Command_Received(SET_UUID); |
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 | 25:0ac2680d594c | 483 | pc1.printf("%2x",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 | 25:0ac2680d594c | 487 | pc1.printf("%2x",Fixed_Beacon_Packet.Parking1_Beacon_Signal_Strength); |
NarendraSingh | 24:1063cfc311e5 | 488 | //pc1.printf("\nFixed Beacon2 MAC ID\n"); |
NarendraSingh | 16:7703b9d92326 | 489 | for(i=0; i<6; i++) |
NarendraSingh | 21:a5fb0ae94dc6 | 490 | { |
NarendraSingh | 16:7703b9d92326 | 491 | Fixed_Beacon_Packet.Parking2_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; |
NarendraSingh | 25:0ac2680d594c | 492 | pc1.printf("%2x",Fixed_Beacon_Packet.Parking2_Beacon_ID[i]); |
NarendraSingh | 21:a5fb0ae94dc6 | 493 | } |
NarendraSingh | 19:886d50ecc718 | 494 | Temp_Pos+=2; |
NarendraSingh | 16:7703b9d92326 | 495 | Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; |
NarendraSingh | 25:0ac2680d594c | 496 | pc1.printf("%2x",Fixed_Beacon_Packet.Parking2_Beacon_Signal_Strength); |
NarendraSingh | 24:1063cfc311e5 | 497 | //pc1.printf("\nFixed Beacon3 MAC ID\n"); |
NarendraSingh | 16:7703b9d92326 | 498 | for(i=0; i<6; i++) |
NarendraSingh | 21:a5fb0ae94dc6 | 499 | { |
NarendraSingh | 21:a5fb0ae94dc6 | 500 | Fixed_Beacon_Packet.Parking3_Beacon_ID[i] = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; |
NarendraSingh | 25:0ac2680d594c | 501 | pc1.printf("%2x",Fixed_Beacon_Packet.Parking3_Beacon_ID[i]); |
NarendraSingh | 21:a5fb0ae94dc6 | 502 | } |
NarendraSingh | 19:886d50ecc718 | 503 | Temp_Pos+=2; |
NarendraSingh | 16:7703b9d92326 | 504 | Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength = BLE_Receiver_UART_RX_Buffer[Temp_Pos++]; |
NarendraSingh | 25:0ac2680d594c | 505 | pc1.printf("%2x",Fixed_Beacon_Packet.Parking3_Beacon_Signal_Strength); |
NarendraSingh | 21:a5fb0ae94dc6 | 506 | BLE_RxBuffer_End_Pos = 0x00; //Start Next adat at 0th location |
NarendraSingh | 16:7703b9d92326 | 507 | break; |
NarendraSingh | 16:7703b9d92326 | 508 | } |
NarendraSingh | 16:7703b9d92326 | 509 | Temp_Pos++; |
NarendraSingh | 15:a448e955b8f3 | 510 | } |
NarendraSingh | 16:7703b9d92326 | 511 | else |
NarendraSingh | 16:7703b9d92326 | 512 | Temp_Pos++; |
NarendraSingh | 15:a448e955b8f3 | 513 | } |
NarendraSingh | 15:a448e955b8f3 | 514 | else |
NarendraSingh | 16:7703b9d92326 | 515 | Temp_Pos = 0x00; |
NarendraSingh | 19:886d50ecc718 | 516 | } |
NarendraSingh | 24:1063cfc311e5 | 517 | pc1.printf("\nReading MACID finished\n"); |
NarendraSingh | 15:a448e955b8f3 | 518 | } |