Hello, so I have a central and two peripheral cards that each send their counters to the central.
What I want to do is compare each of the two counters.
But there's a problem every other time the n-1 data is corrupted.
on this image the good coportement
on this image the bad coportement
static void cid_c_evt_handler(ble_cid_c_t * p_cid_c, ble_cid_c_evt_t * p_cid_c_evt)
{
ret_code_t err_code;
static float moyenne[NRF_SDH_BLE_CENTRAL_LINK_COUNT] = {0};
static float timer[NRF_SDH_BLE_CENTRAL_LINK_COUNT] = {0};
static int compteur[NRF_SDH_BLE_CENTRAL_LINK_COUNT] ={0};
static uint64_t time_actu[NRF_SDH_BLE_CENTRAL_LINK_COUNT]={0};
static uint64_t time_diff[NRF_SDH_BLE_CENTRAL_LINK_COUNT]={0};
static uint32_t num_data[NRF_SDH_BLE_CENTRAL_LINK_COUNT];
static float time_con[NRF_SDH_BLE_CENTRAL_LINK_COUNT]= {0};
uint16_t dif2 ;
uint16_t datatab[]={data_1_16[p_cid_c_evt->conn_handle-1].data_receive}; // table to save data
int i = 0;
//etat gpiote
nrf_drv_gpiote_init();
nrf_gpio_cfg_input(7,NRF_GPIO_PIN_PULLDOWN);
uint16_t state = nrf_gpio_pin_read(7);
state = 1;
switch (p_cid_c_evt->evt_type)
{
case BLE_CID_C_EVT_DISCOVERY_COMPLETE:
{
NRF_LOG_INFO("Cidelec service discovered.");
err_code = ble_cid_c_handles_assign(p_cid_c,
p_cid_c_evt->conn_handle,
&p_cid_c_evt->params.peer_db);
APP_ERROR_CHECK(err_code);
// Initiate bonding.
err_code = pm_conn_secure(p_cid_c_evt->conn_handle, false);
if (err_code != NRF_ERROR_INVALID_STATE)
{
APP_ERROR_CHECK(err_code);
}
//param_conn.m_conn_handle=p_cid_c->conn_handle;
m_cid_c[p_cid_c->conn_handle].conn_handle=p_cid_c->conn_handle;
} break;
case BLE_CID_C_EVT_NOTIFICATION_SIMPLE_DATA_RECEIVE:
{
bsp_board_led_invert(BSP_BOARD_LED_2);
// for(uint8_t i=0;i<p_cid_c_evt->params.cid_data.data_length;i++){
// if(p_cid_c_evt->params.cid_data.data[i]!=i){
// NRF_LOG_INFO("erreur:mauvaise donnée recu");
// i=250;
// }
// }
if(param_conn[p_cid_c_evt->conn_handle].test_debit.etat_test){
param_conn[p_cid_c_evt->conn_handle].test_debit.data_receive+=p_cid_c_evt->params.cid_data.data_length;
}else if(data_1_16[p_cid_c_evt->conn_handle].etat_test){
num_data[p_cid_c_evt->conn_handle]=p_cid_c_evt->params.cid_data.data[0];
num_data[p_cid_c_evt->conn_handle]|=p_cid_c_evt->params.cid_data.data[1]<<8;
num_data[p_cid_c_evt->conn_handle]|=p_cid_c_evt->params.cid_data.data[2]<<16;
num_data[p_cid_c_evt->conn_handle]|=p_cid_c_evt->params.cid_data.data[3]<<24;
data_1_16[p_cid_c_evt->conn_handle].data_receive+=p_cid_c_evt->params.cid_data.data_length;
state =1;
//NRF_LOG_INFO("EtatData = %d",state);
}else{
NRF_LOG_INFO("data_receive:%d octets from conn %d",p_cid_c_evt->params.cid_data.data_length,p_cid_c_evt->conn_handle);
// NRF_LOG_INFO("EtatData = %d",state);
}
} break;
case BLE_CID_C_EVT_NOTIFICATION_START_TEST_DEBIT:
bsp_board_led_on(BSP_BOARD_LED_3);
start_throughput_test(¶m_conn[p_cid_c_evt->conn_handle]);
NRF_LOG_INFO("receive start from conn %d, etat_test=%d",p_cid_c_evt->conn_handle,param_conn[p_cid_c_evt->conn_handle].test_debit.etat_test);
// uint32_t errCode;
/*nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_HIGH;
config.init_set = true;
err_code = nrf_drv_gpiote_out_config(10, &config);
if(errCode != NRF_SUCCESS)
{
NRF_LOG_INFO("====================Probleme+++++++++++++++%d",errCode);
}*/
nrfx_gpiote_out_task_force(15,1);
break;
case BLE_CID_C_EVT_NOTIFICATION_STOP_TEST_DEBIT:
bsp_board_led_off(BSP_BOARD_LED_3);
NRF_LOG_INFO("receive stop from conn %d",p_cid_c_evt->conn_handle);
stop_throughput_test(¶m_conn[p_cid_c_evt->conn_handle]);
nrfx_gpiote_out_task_force(15,1);
break;
case BLE_CID_C_EVT_NOTIFICATION_1_16_START:
NRF_LOG_INFO("1_16_start conn_%d",p_cid_c_evt->conn_handle);
data_1_16[p_cid_c_evt->conn_handle].data_receive=0;
data_1_16[p_cid_c_evt->conn_handle].etat_test=1;
nrfx_gpiote_out_task_force(15,1);
//NRF_LOG_INFO("================NEWSTART:%ld",NRF_RADIO->STATE);
//NRF_LOG_INFO("================POWERSTART:%d",NRF_RADIO->POWER);
//NRF_LOG_INFO("================EVENTS_END0:%d",NRF_RADIO-> EVENTS_END);
//fait la différence entre le temps actuelle et le temps du dernier paquet de start
time_diff[p_cid_c_evt->conn_handle]=(app_timer_cnt_get()*1000/32768)-time_actu[p_cid_c_evt->conn_handle];
time_actu[p_cid_c_evt->conn_handle] = app_timer_cnt_get()*1000/32768;
compteur[p_cid_c_evt->conn_handle]++;
time_con[p_cid_c_evt->conn_handle]= app_timer_cnt_get()*1000/32768;
if(compteur[p_cid_c_evt->conn_handle]==1){
return ;
}
moyenne[p_cid_c_evt->conn_handle] = (time_diff[p_cid_c_evt->conn_handle]+ moyenne[p_cid_c_evt->conn_handle]);
if (compteur[p_cid_c_evt->conn_handle]==10000){
moyenne[p_cid_c_evt->conn_handle]= (time_diff[p_cid_c_evt->conn_handle]+ moyenne[p_cid_c_evt->conn_handle])/(compteur[p_cid_c_evt->conn_handle]-1);
NRF_LOG_INFO("========La moyenne :%f" NRF_LOG_FLOAT_MARKER "\r\n"" connexion :%d===========",NRF_LOG_FLOAT(moyenne[p_cid_c_evt->conn_handle]), p_cid_c_evt->conn_handle);
}
uint32_t app_timer_cnt_get ( void ) ;
timer[p_cid_c_evt->conn_handle] = app_timer_cnt_get()*1000/32768;
break;
case BLE_CID_C_EVT_NOTIFICATION_1_16_STOP:
i++;
data_1_16[p_cid_c_evt->conn_handle].etat_test=0;
time_con[p_cid_c_evt->conn_handle]=(app_timer_cnt_get()*1000/32768.f)-time_con[p_cid_c_evt->conn_handle];
//NRF_LOG_INFO("num_data=%d for conn %d",num_data[p_cid_c_evt->conn_handle],p_cid_c_evt->conn_handle);
NRF_LOG_INFO("-----------------------------------------------------------" );
NRF_LOG_INFO("data_receive=%d from conn%d time_data=%d",data_1_16[p_cid_c_evt->conn_handle].data_receive, p_cid_c_evt->conn_handle, time_diff[p_cid_c_evt->conn_handle]);
//NRF_LOG_INFO("Connexion %d", p_cid_c_evt->conn_handle);
datatab[i] = data_1_16[p_cid_c_evt->conn_handle].data_receive; // put data on the table
datatab[i-1]= data_1_16[p_cid_c_evt->conn_handle-1].data_receive;
if(datatab[i-1]>datatab[i]){
dif2 = datatab[i-1]-datatab[i]; //compare of two values
NRF_LOG_INFO("i-1>i");
}
else{
dif2 = datatab[i]-datatab[i-1]; //compare of two values
NRF_LOG_INFO("i-1<i");
}
NRF_LOG_INFO("Difference timer recu - timer recu-1= %d" ,dif2);
NRF_LOG_INFO("datatab i-1 = %d" ,datatab[i-1]);
NRF_LOG_INFO("-----------------------------------------------------------" );
//NRF_LOG_INFO("Difference timer recu - timer central= %d" ,dif);
//NRF_LOG_INFO("================NEWSTOP%ld",NRF_RADIO->STATE);
//NRF_LOG_INFO("================POWERSTOP:%d",NRF_RADIO->POWER);
// NRF_LOG_INFO("================EVENTS_END:%d",NRF_RADIO-> EVENTS_END);
uint16_t state = nrf_gpio_pin_read(3);
state =1;
// NRF_LOG_INFO("EtatStop = %d",state);
nrfx_gpiote_out_task_force(15,1);
//NRF_LOG_INFO("time_connexion=%f"NRF_LOG_FLOAT_MARKER "\r\n",NRF_LOG_FLOAT(time_con[p_cid_c_evt->conn_handle]));
//ble_conn_params_stop();
//err_code=ble_cid_info_send(&m_cid_c[p_cid_c_evt->conn_handle],data_1_16[p_cid_c_evt->conn_handle].data_receive);ss
//NRF_LOG_INFO("err_code=%d",err_code);
break;
default:
break;
}
}
In green the code concerned.