kumar singh
/
Dealer_23Feb
Dummy Lora Packet Sending
Fork of Dealer_18feb17 by
Diff: main.cpp
- Revision:
- 13:8955f2e95021
- Parent:
- 12:6107b32b0729
- Child:
- 15:a448e955b8f3
diff -r 6107b32b0729 -r 8955f2e95021 main.cpp --- a/main.cpp Mon Jan 30 18:31:30 2017 +0000 +++ b/main.cpp Sun Feb 12 02:57:25 2017 +0000 @@ -18,6 +18,7 @@ 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 RawSerial DEBUG_UART(PA_9, PA_10);//USART1_TX->PA_9,USART1_RX->PA_10 : Used for debugging purpose only RawSerial Beacon_UART(PC_4, PC_5);//USART3_TX->PC4,USART3_RX->PC_5 : Used for sending command to beacon module + RawSerial BLE_RECEIVER_UART(PA_0, PA_1);//USART4_TX->PA_0,USART4_RX->PA_1 : Used for Lora module command sending and reception from gateway //InterruptIn OBD_PLUGIN_INTERRUPT_PIN(PC_13); InterruptIn CheckIn_Interrupt(PC_13); @@ -34,9 +35,12 @@ void Lora_Periodic_Packet_Sending_thread(void const *args); void Lora_Rcvd_Cmd_Processing_thread(void);// const *args); - void Enable_CheckIN_Packet_Sending(); + void Enable_CheckIN_Packet_Sending(); + + /*************************Accelerometer related definitions***********************************/ //Accelerometer related definitions + #define DOUBLE_TAP_INTERRUPT 0x20 #define ACTIVITY_INTERRUPT 0x10 #define INACTIVITY_INTERRUPT 0x08 @@ -97,12 +101,18 @@ unsigned char Motion_Type_Detected = MOTION_TYPE_UNKNOWN; //By default set motion type as unknown void Accelerometer_Process_thread();//void const *args) ; + #define BLE_RECEIVER_UART_RX_Size 100 + uint8 BLE_RxBuffer_End_Pos = 0; + char BLE_Receiver_UART_RX_Buffer[BLE_RECEIVER_UART_RX_Size]; + //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 void interrupt_activity_inactivity() { i2c.write(slave_address_acc, all_interrupt_clear_command, 2); Motion_Detect_Status = TRUE; } + + /************************************************************************/ uint8 Command_Sent[100]; uint8 Command_Length_Sent; @@ -145,10 +155,9 @@ Lora_RxBuffer_End_Pos = 0; } } -} +} - - /* + // called every time a byte is received from Beacon Module. void Beacon_onDataRx() { @@ -164,83 +173,28 @@ } } } -*/ -typedef struct { - uint8_t Queue_Msg_Type; /* A counter value */ -} message_type; - -MemoryPool<message_type, 16> mpool; -Queue<message_type, 16> queue; -Thread OBD_Thread; -Thread Accelerometer_Thread; - -#define OBD_MSG_TYPE 0x01 -#define ACCELEROMETER_MSG_TYPE 0x02 - -/* Send Thread */ -void OBD_Process_Thread (void) { - while (true) { - //DEBUG_UART.printf("\n OBD Message start "); - message_type message = mpool.alloc(); - message->Queue_Msg_Type = (uint8_t) OBD_MSG_TYPE; - queue.put(message); - //DEBUG_UART.printf("\n OBD Message Type Enqueued: \n");//, message->Queue_Msg_Type); - //Thread::wait(3000); - Thread::yield(); + void BLE_Receiver_onDataRx(void) +{ + while (BLE_RECEIVER_UART.readable()) + { // while there is data waiting + BLE_Receiver_UART_RX_Buffer[BLE_RxBuffer_End_Pos++] = BLE_RECEIVER_UART.getc(); // put it in the buffer + //DEBUG_UART.putc(LORA_UART_RX_Buffer[Lora_RxBuffer_End_Pos-1]); + if(BLE_RxBuffer_End_Pos >= BLE_RECEIVER_UART_RX_Size) + { + // BUFFER OVERFLOW. What goes here depends on how you want to cope with that situation. + // For now just throw everything away. + BLE_RxBuffer_End_Pos = 0; + } } -} - -/* Send Thread */ -void Accelerometer_Process_Thread (void) { - while (true) { - //DEBUG_UART.printf("\n Accelerometer Message start: "); - message_type message = mpool.alloc(); - message->Queue_Msg_Type = (uint8_t) ACCELEROMETER_MSG_TYPE; - queue.put(message); - //DEBUG_UART.printf("\n Accelerometer Message Type Enqueued: \n");//, message->Queue_Msg_Type); - //Thread::wait(5000); - Thread::yield(); - } -} - -int main (void) { - DEBUG_UART.baud(115200); - //OBD_Thread.set_priority(osPriorityLow); - OBD_Thread.start(OBD_Process_Thread); - //DEBUG_UART.printf("\n main %d", __LINE__); - //Accelerometer_Thread.set_priority(osPriorityAboveNormal); - //DEBUG_UART.printf("\n main %d", __LINE__); - Accelerometer_Thread.start(Accelerometer_Process_Thread); - //DEBUG_UART.printf("\n main %d", __LINE__); -#if 1 - while (true) { - DEBUG_UART.printf("\n main %d", __LINE__); - Thread::yield(); - /* - osEvent evt = queue.get(); - if (evt.status == osEventMessage) { - message_type *message = (message_type*)evt.value.p; - DEBUG_UART.printf("\nMessage Type Dequeued %d" , message->Queue_Msg_Type); - mpool.free(message); - }*/ - } -#endif - OBD_Thread.join(); - Accelerometer_Thread.join(); -} - - - - - -/* -int main() +} + + int main() { DEBUG_UART.baud(115200); DEBUG_UART.printf("%s","Debugging started"); LORA_UART.attach(&Lora_onDataRx, Serial::RxIrq); - //Beacon_UART.attach(&Beacon_onDataRx, Serial::RxIrq); + //BLE_RECEIVER_UART.attach(&BLE_Receiver_onDataRx, Serial::RxIrq); //Create a thread to read vehicle data //Thread OBD_thread(OBD_Rcvd_Cmd_Processing_thread); @@ -251,11 +205,11 @@ //led2_thread is executing concurrently with main at this point CheckIn_Interrupt.rise(&Handle_CheckIn_Interrupt); inactivity.rise(interrupt_activity_inactivity); // Attach the address of interrupt_activity_inactivity function to rising edge - //Initialize_Beacon_Module(); + Initialize_Beacon_Module(); Lora_Periodic_Packet_Sending(); //Infinite loop for sending and receiving lora response, no return from here -} -*/ - //Functiont to be called when Interrupt is genearted for motion sensing, checkin +} + + //Function to be called when Interrupt is genearted for motion sensing, checkin void Initialize_Packets_Sent_Count(void) { Motion_Packet_Sent_Count = 0x00; @@ -288,7 +242,7 @@ else { Status_Packet_Wait_Count = 0; - //Send_Vehicle_Status_Packet(); //call function to send heartbeat packet + Send_Vehicle_Status_Packet(); //call function to send heartbeat packet DEBUG_UART.printf("Sent Status Packet"); AT_Response_Receive_Status = FAILURE; while(AT_Response_Receive_Status) @@ -337,16 +291,17 @@ CheckIN_Packet_Sent_Count = 0; Packet_Type_To_Send = HEARTBEAT_TYPE_PACKET; //Set Packet type to send as heartbeat packet Initialize_Packets_Sent_Count(); - } } } if(OBD_PlugInOut_IOC_Status) //Check if Accelerometer Interrupt is generated { - Enable_CheckIN_Packet_Sending(); + //Enable_CheckIN_Packet_Sending(); //Get_Acceleration_Type(); OBD_PlugInOut_IOC_Status = FALSE; Checkin_Detect_Status ^= 0x01; + Packet_Type_To_Send = CHECKIN_TYPE_PACKET; + Send_Lora_Packet_Flag = TRUE; if(Checkin_Detect_Status) //OBD Plugin detected { wait(1); //wait for 1sec to avoid detecting plugin debounce @@ -377,12 +332,12 @@ Motion_Lora_Packet.Acceleration_Type = Motion_Type_Detected; //Read Type of motion deteceted //write code to read acceleration value for every 10sec after any of the acceleration is found } - +/* //This function is used to enable checkin packet sending once OBD device is plugged in void Enable_CheckIN_Packet_Sending() { // Enable_CheckIN_Packet_Sending = TRUE; //set status to true - /* if(Command_Received[0] == 0xFE) //check start of frame of packet received. every packet must start with 0xFE + if(Command_Received[0] == 0xFE) //check start of frame of packet received. every packet must start with 0xFE { if(Calculate_Lora_Frame_FCS((Command_Received + 1),(Command_Length + 1)) == (Command_Received[Command_Length + 2])) //Check for packet inegrity by checking FCS { @@ -391,5 +346,5 @@ Process_Beacon_Command_Received((Command_Received + 2)); } } - }*/ -} + } +} */ \ No newline at end of file