This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

unable to send data based on time difference in uart app

hi, i am trying to send data using ble_uart app. in this app i am using timer difference to send data. when i am getting 1st data in uart event handler. when i am printing the time difference between 2 consucting data available on uart handler. then it prints correct result. but when i am sending the same data over bluetooth. then when i am connecting to ble then then it get stopped and time difference is 0.

i dont know why the time difference get 0.after connecting. and before connecting if has a expected time difference. i dont know where i am doing wrong.

below is my code :

void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
		uint8_t data[5];
    static uint8_t index,push = 0;
    uint32_t       err_code;
		static uint32_t previous_time,current_time,duration_time,waiting_time;
		waiting_time=40;
		uint8_t rx_buf[17];
		int rx_buf_num=0;

    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&data_array[index]));
            index++;
						push++;
						if(index%3 == 0)
						{
							count++;
							err_code = app_timer_cnt_get(&current_time);
							APP_ERROR_CHECK(err_code);
							
							
							if(preCount!=count)
							{
							//diff
							err_code = app_timer_cnt_diff_compute(current_time,previous_time,&duration_time);
							APP_ERROR_CHECK(err_code);
							
							//SEGGER_RTT_printf(0, "Data Count:\t%d\n",count);
							SEGGER_RTT_printf(0, "current time:%d\n",current_time);
							SEGGER_RTT_printf(0, "previous time:%d\n",previous_time);
							SEGGER_RTT_printf(0, "duration time:\t%d\n",app_timer_ms(duration_time));
							}
							
							if(waiting_time<=app_timer_ms(duration_time))
							{
							
							//SEGGER_RTT_printf(0, "RawData : %x\t\t%x\t\t%x\n",data_array[0], data_array[1],data_array[2]);
							const uint8_t* midiData = parseMIDItoAppleBle(3, data_array);
							for(int i=0;i<5;i++)
							{
								data[i] = midiData[i];
							}
							SEGGER_RTT_printf(0, "%x\t%x\t%x\t%x\t%x\tcnt:%d\n",data[0], data[1],data[2],data[3], data[4],count);
							sendData(data,5);
							}
							/*else
							{
									SEGGER_RTT_printf(0, "timeout\n");
								SEGGER_RTT_printf(0, "waitingTime = %d\tdurationTime : %d\n",waiting_time,duration_time);
								int packet = waiting_time/app_timer_ms(duration_time);
								
									//SEGGER_RTT_printf(0, "append Data.\n");
									char time[2];
									char buf[20];
										
									int i=0;
									//int rx_buf_num = 6
									int localBufNum = rx_buf_num;
								 
									
									if(rx_buf_num <= 100) // arbitrary high number
									{
										 while(rx_buf[i]!='\0')
										 {
												i++;
										 }
										for (int i = 0; i < 3; i++)
										{
											rx_buf[rx_buf_num] = data_array[i];
											//SEGGER_RTT_printf(0, "data : 0x%x\n",rx_buf[rx_buf_num]);
											rx_buf_num++;
										}
											rx_buf[rx_buf_num] = 0x80;
											rx_buf_num++;
											
									}
										//SEGGER_RTT_printf(0, "index: %d\t",rx_buf_num);
										//SEGGER_RTT_printf(0, "\n");
									
							
										if(rx_buf_num==packet*4)
										{
												uint8_t temp=rx_buf[rx_buf_num-1];
												for(i=rx_buf_num;i>0;i--)
												rx_buf[i]=rx_buf[i-2];
												rx_buf[0]=rx_buf[1]=temp;
											
													rx_buf_num++;
											if(rx_buf_num<=17)
											{
												sendData(rx_buf,rx_buf_num);
											for (int i = 0; i < rx_buf_num; i++)
											{		
												SEGGER_RTT_printf(0, "%x\t",rx_buf[i]);
											}
												SEGGER_RTT_printf(0, "\n");			
											}
											rx_buf_num=0;
										}
							}*/
							
							index = 0;
							previous_time = current_time;
							preCount=count;
						}						
							
}

here after connecting i am getting duration_time as 0. due to which it skips the entire code block. dont know why.

thanks!!

Parents Reply Children
No Data
Related