void process_packet (u_char *arg, const struct pcap_pkthdr* pkthdr, const u_char* packet) { packet_probe *pkt; data_test *data = (data_test *)arg; settings *conf_settings = data->conf_settings; received_probe *recv_probe = &(data->probe[0]); resume *result = data->result; timeval32 tm32_now; int jitter = 0; pcap_t* handle = (pcap_t*)data->handle; if (pkthdr->len >= (sizeof(packet_probe) + OVERHEAD_SIZE)) { #ifdef CONECT_4G pkt = (packet_probe *)&packet[OVERHEAD_SIZE+2]; #else pkt = (packet_probe *)&packet[OVERHEAD_SIZE]; #endif tm32_now.tv_sec = pkthdr->ts.tv_sec; tm32_now.tv_usec = pkthdr->ts.tv_usec; if (pkt->packet_id != PACKET_END_TEST) { if (recv_probe->received_total == 0) { recv_probe->received_total = pkthdr->len; recv_probe->received_packets = 1; recv_probe->start = tm32_now; recv_probe->end = recv_probe->report_time = tm32_now; recv_probe->report_time.tv_usec += ((conf_settings->test.cont.report_interval) % 1000) * 1000; recv_probe->report_time.tv_sec += (conf_settings->test.cont.report_interval) / 1000; if (recv_probe->report_time.tv_usec >= 1000000) { recv_probe->report_time.tv_usec -= 1000000; recv_probe->report_time.tv_sec += 1; } } else { /* calcular jitter medio, min e max */ jitter = difftimeval2us (&(recv_probe->end), &tm32_now); if (jitter > result->jitter_max) result->jitter_max = jitter; if (jitter < result->jitter_min) result->jitter_min = jitter; result->jitter_med += jitter; recv_probe->received_total += pkthdr->len; recv_probe->received_packets++; recv_probe->end = tm32_now; } } if ((pkt->packet_id == PACKET_END_TEST) || (compare_time (&(recv_probe->report_time), &(tm32_now)))) { recv_probe->stop_recv = 1; if (handle != NULL) { pcap_breakloop (handle); } } } return; }
void print_time_list(Ttime *time_list, int time_list_size){ Ttime winner = find_winner_time(time_list, time_list_size); for (int i = 0; i < time_list_size; i++) { printf("%d: ", i+1); print_time(time_list[i]); print_time(compare_time(&time_list[i], &winner)); printf("\n"); } }
/* * start or stop chronometer */ inline void StartStopChronometer(void) { add_beep_alarm(1); add_led_alarm(1); //beep(1,100); //led_alarm(1,50); // led_alarm(3,50) (à diminuer pour ne pas ralentir traitement interruption) if (running_chronometer) { //copy_time(&src_time, &dest_time); copy_time(&last_time, &before_last_time); copy_time(¤t_time, &last_time); //running_chronometer = false; // false = 0 if (compare_time(&last_time, &best_time) == 1) // meilleur temps { // better time them the best time copy_time(&last_time, &best_time); //led_alarm(3,50); add_led_alarm(3); add_beep_alarm(3); } if (compare_time(&last_time, &before_last_time) == 1) // meilleur que le dernier tour { // better time them the last time //led_alarm(1,50); add_led_alarm(1); add_beep_alarm(1); } init_time(¤t_time); } else { // this is before first lap (start from pit) running_chronometer = true; // true = -1 // this is after first lap } }
static int compare_by_age (GtkTreeModel * m, GtkTreeIter * a, GtkTreeIter * b, gpointer u) { int ret = 0; tr_torrent *ta, *tb; gtk_tree_model_get (m, a, MC_TORRENT, &ta, -1); gtk_tree_model_get (m, b, MC_TORRENT, &tb, -1); if (!ret) ret = compare_time (tr_torrentStatCached (ta)->addedDate, tr_torrentStatCached (tb)->addedDate); if (!ret) ret = compare_by_name (m, a, b, u); return ret; }
static void load_hw_timer(uint8_t timer_id) { if (NO_TIMER != timer_id) { uint32_t now = gettime(); uint32_t point_in_time = timer_array[timer_id].abs_exp_timer; if (compare_time(now, point_in_time)) { if (!timer_array[timer_id].loaded) { uint32_t timediff = point_in_time - now; if (timediff <= UINT16_MAX) { common_tc_delay(timediff); timer_array[timer_id].loaded = true; } else { timer_array[timer_id].loaded = false; } } } else { timer_trigger = true; } } else { common_tc_compare_stop(); } }
void *timeout_thread (void *param) { data_test *data = (data_test *)param; received_probe *recv_probe = &(data->probe[0]); int recv_packets = -1; struct timeval tm_now; timeval32 tm32_now, tm_timeout; pcap_t* handle = (pcap_t*)data->handle; while (!(recv_probe->stop_recv)) { if (recv_probe->end.tv_sec != 0) { gettimeofday(&tm_now, NULL); tm32_now.tv_sec = tm_now.tv_sec; tm32_now.tv_usec = tm_now.tv_usec; if (recv_probe->received_packets == recv_packets) { tm_timeout = recv_probe->end; tm_timeout.tv_usec += (RECVCAPTURE_TIMEOUT * 1000); while (tm_timeout.tv_usec >= 1000000) { tm_timeout.tv_usec -= 1000000; tm_timeout.tv_sec += 1; } if ((compare_time (&tm_timeout, &tm32_now))) { recv_probe->stop_recv = 1; if (handle != NULL) { pcap_breakloop (handle); } break; } } else { recv_packets = recv_probe->received_packets; } } usleep(100000); } return NULL; }
void find_closest_prc_rec(char *prc_file, ymd_date *seekDate, hms_time *seekTime, stateVector *vec, float *offset_time) { int currRec; STATE *header; PRC_REC *rec1 = NULL; PRC_REC *rec2 = NULL; ymd_date date, date1, date2; hms_time time, time1, time2; float diff1, diff2; int startRec; /* Marks start of earth-fixed state vectors */ header = fetch_prc_header(prc_file); currRec = 0; /* Skip to the Earth-Fixed Data Records */ asfPrintStatus(" Skipping to earth-fixed state vector records...\n"); do { if (rec1!=(PRC_REC *) NULL) free(rec1); rec1 = fetch_prc_rec(prc_file,currRec); currRec++; } while (strncmp(rec1->reckey,"STTERR",6)!=0); startRec = currRec -= 1; /* Skip to the first state vector after seek time counting by 100 */ asfPrintStatus(" Seeking to the first state vector after seek time...\n"); do { free(rec1); rec1 = fetch_prc_rec(prc_file,currRec); prc_date_time(rec1, header->tdtutc, &date, &time); currRec+=100; } while (compare_time(&date,&time,seekDate,seekTime)==-1); currRec -=200; if (currRec < startRec) currRec = startRec; /* Skip to the first state vector after seek time counting by 1 */ do { free(rec1); rec1 = fetch_prc_rec(prc_file,currRec); prc_date_time(rec1, header->tdtutc, &date, &time); currRec++; } while (compare_time(&date,&time,seekDate,seekTime)==-1); if (currRec < startRec) currRec = startRec+2; rec2 = rec1; rec1 = fetch_prc_rec(prc_file,currRec-2); prc_date_time(rec1, header->tdtutc, &date1, &time1); prc_date_time(rec2, header->tdtutc, &date2, &time2); diff1 = date_difference(&date1, &time1, seekDate, seekTime); diff2 = date_difference(&date2, &time2, seekDate, seekTime); if (diff1 < diff2) { *offset_time = -1.0*diff1; asfPrintStatus(" Closest state vector to requested time (offset = %f):\n", *offset_time); display_prc_rec_mod(rec1,header->tdtutc); vec->pos.x = rec1->xsat / 1000.0; vec->pos.y = rec1->ysat / 1000.0; vec->pos.z = rec1->zsat / 1000.0; vec->vel.x = rec1->xdsat / 1000000.0; vec->vel.y = rec1->ydsat / 1000000.0; vec->vel.z = rec1->zdsat / 1000000.0; } else { *offset_time = diff2; asfPrintStatus(" Closest state vector to requested time (offset = %f):\n", *offset_time); display_prc_rec_mod(rec2,header->tdtutc); vec->pos.x = rec2->xsat / 1000.0; vec->pos.y = rec2->ysat / 1000.0; vec->pos.z = rec2->zsat / 1000.0; vec->vel.x = rec2->xdsat / 1000000.0; vec->vel.y = rec2->ydsat / 1000000.0; vec->vel.z = rec2->zdsat / 1000000.0; } }
bool test_rtc(case_t *rtc_case) { int fd = -1; int ret = -1; struct rtc_time rtc; struct tm sys_clock; time_t tmp_time; struct timeval tv; char rtc_hardware[50] = "/sys/class/rtc/rtc0/ext_osc"; ret = cat_file(rtc_hardware); if(1 != ret) return false; fd = open("/dev/rtc0", O_RDWR); if(!fd) { printf("open rtc device error\n"); return false; } sscanf(rtc_case->nod_path, "%d-%d-%d %d:%d:%d", &rtc.tm_year, &rtc.tm_mon, &rtc.tm_mday,&rtc.tm_hour, &rtc.tm_min, &rtc.tm_sec); rtc.tm_year -= 1900; rtc.tm_mon -= 1; printf("\nCurrentRTC data/time is %d-%d-%d, %02d:%02d:%02d.\n", rtc.tm_mday, rtc.tm_mon + 1,rtc.tm_year + 1900, rtc.tm_hour, rtc.tm_min, rtc.tm_sec); ret = ioctl(fd, RTC_SET_TIME, &rtc); if(-1 == ret) { printf("set rtc device error\n"); printf("errno = %d\n", errno); return false; } direct_thread_sleep(5000000); // modified wait more time for rtc to set time ret = ioctl(fd, RTC_RD_TIME, &rtc); if(-1 == ret) { printf("read rtc device error\n"); return false; } printf("\nCurrentRTC data/time is %d-%d-%d, %02d:%02d:%02d.\n", rtc.tm_mday, rtc.tm_mon + 1,rtc.tm_year + 1900, rtc.tm_hour, rtc.tm_min, rtc.tm_sec); sys_clock.tm_sec = rtc.tm_sec; sys_clock.tm_min = rtc.tm_min; sys_clock.tm_hour = rtc.tm_hour; sys_clock.tm_mday = rtc.tm_mday; sys_clock.tm_mon = rtc.tm_mon; sys_clock.tm_year = rtc.tm_year; tmp_time = mktime(&sys_clock); tv.tv_sec = tmp_time; tv.tv_usec = 0; if(settimeofday(&tv, NULL) < 0) { printf("Set system datatime error!\n"); printf("errno = %d\n", errno); return false; } direct_thread_sleep(4000000); ret = ioctl(fd, RTC_RD_TIME, &rtc); if(-1 == ret) { printf("read rtc device error\n"); return false; } if(gettimeofday(&tv, NULL) < 0) { printf("get system datatime error!\n"); printf("errno = %d\n", errno); return false; } if(!compare_time(rtc, tv)) { printf("rtc != linux time\n"); return false; } else { sprintf(rtc_case->pass_string, "%s(%d-%d-%d, %02d:%02d:%02d)",rtc_case->pass_string, rtc.tm_mday, rtc.tm_mon + 1,rtc.tm_year + 1900, rtc.tm_hour, rtc.tm_min, rtc.tm_sec); } return true; }
static void start_absolute_timer(uint8_t timer_id, uint32_t point_in_time, FUNC_PTR handler_cb, void *parameter) { uint8_t flags = cpu_irq_save(); /* Check is done to see if any timer has expired */ internal_timer_handler(); timer_array[timer_id].abs_exp_timer = point_in_time; timer_array[timer_id].timer_cb = (FUNC_PTR)handler_cb; timer_array[timer_id].param_cb = parameter; timer_array[timer_id].loaded = false; running_timers++; if (NO_TIMER == running_timer_queue_head) { running_timer_queue_head = timer_id; load_hw_timer(running_timer_queue_head); } else { uint8_t index; bool timer_inserted = false; uint8_t curr_index = running_timer_queue_head; uint8_t prev_index = running_timer_queue_head; for (index = 0; index < running_timers; index++) { if (NO_TIMER != curr_index) { if (compare_time(timer_array[curr_index]. abs_exp_timer, point_in_time)) { /* * Requested absolute time value is * greater than the time * value pointed by the curr_index in * the timer array */ prev_index = curr_index; curr_index = timer_array[curr_index]. next_timer_in_queue; } else { timer_array[timer_id]. next_timer_in_queue = curr_index; timer_array[curr_index].loaded = false; if (running_timer_queue_head == curr_index) { /* Insertion at the head of the * timer queue. */ running_timer_queue_head = timer_id; load_hw_timer( running_timer_queue_head); } else { timer_array[prev_index]. next_timer_in_queue = timer_id; } timer_inserted = true; break; } } } if (!timer_inserted) { /* Insertion at the tail of the timer queue. */ timer_array[prev_index].next_timer_in_queue = timer_id; timer_array[timer_id].next_timer_in_queue = NO_TIMER; } } cpu_irq_restore(flags); }
/** * @brief Programs the Timer compare register of timer channel * * This function programs the Timer compare register of timer channel with * the timeout value of the timer present at the head of the running queue. */ static void prog_comp_reg(void) { uint16_t timeout_high; uint16_t timeout_low; uint32_t timeout; uint32_t tc_status; ENTER_CRITICAL_REGION(); if (NO_TIMER != running_timer_queue_head) { timeout = timer_array[running_timer_queue_head].abs_exp_timer; timeout_high = (uint16_t)(timeout >> SYS_TIME_SHIFT_MASK); if (timeout_high == TIME_STAMP_HIGH_REGISTER) { timeout_low = (uint16_t)(timeout & HW_TIME_MASK); /* * The status register is read to clear any pending compare match * interrupts. */ tc_status = PAL_TIMER_STATUS_REG; /* The compare register is programmed */ PAL_TIMER_COMP_REG = timeout_low; /* * The output compare match of timer channel interrupt is * enabled. */ PAL_TIMER_IER = PAL_TIMER_IER_FLAG; /* * As the timer status register read above, it is necessary to check * whether the overflow bit is set. If the counter has overflowed * when the execution has just entered the function, no interrupt * will be generated, as all the callees of this function call this * function when in critical region. Reading the status register * will clear the overflow bit and hence it has to be acknowledged * here. */ #ifdef TIMESTAMP_UPPER_16BIT_SW if (TC_SR_COVFS == tc_status) { sys_time++; } #else tc_status = tc_status; #endif reg_rc_loaded = true; } else { /* * The output compare match of timer channel 0 interrupt is * disabled. */ PAL_TIMER_IDR = PAL_TIMER_IDR_FLAG; reg_rc_loaded = false; } uint32_t current_time = gettime(); /* Safety check: Trigger timer, if next_trigger is in the past. */ if (compare_time(timer_array[running_timer_queue_head].abs_exp_timer, current_time + 1)) { timer_trigger = true; } }
meta_parameters* vp2meta(vexcel_plain *vp) { vp_doppler_centroid_parameters doppler_params; meta_parameters *meta; char *mon[13]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec"}; ymd_date ymd, ref_date; hms_time time, ref_time; julian_date jd; int i, nStVec; // Initialize the meta structure meta = raw_init(); // Fill general block strcpy(meta->general->basename, vp->gli_product.image_desc.title); strcpy(meta->general->sensor, vp->sensor.instrument_name); strcpy(meta->general->sensor_name, vp->sensor.sensor_name); // FIXME: need to handle multibeam data strcpy(meta->general->mode, vp->sensor.beam[0].beam_name); strcpy(meta->general->processor, vp->gli_product.processor_name); if (vp->gli_product.image_desc.bytes_per_pixel == 1) meta->general->data_type = ASF_BYTE; else if (vp->gli_product.image_desc.bytes_per_pixel == 2) meta->general->data_type = INTEGER16; else if (vp->gli_product.image_desc.bytes_per_pixel == 4) meta->general->data_type = REAL32; meta->general->image_data_type = AMPLITUDE_IMAGE; meta->general->radiometry = r_AMP; date_dssr2date(vp->gli_product.orbit_nr_date, &ymd, &time); sprintf(meta->general->acquisition_date, "%2d-%s-%4d", ymd.day, mon[ymd.month], ymd.year); meta->general->orbit = vp->gli_product.orbit_nr; if (strncmp(vp->flight_path_direction, "ASCENDING", 9) == 0) meta->general->orbit_direction = 'A'; else meta->general->orbit_direction = 'D'; meta->general->frame = MAGIC_UNSET_INT; meta->general->band_count = vp->sensor.nr_beams; strcpy(meta->general->bands, "AMP"); meta->general->line_count = vp->gli_product.image_desc.nr_lines;; meta->general->sample_count = vp->gli_product.image_desc.nr_pixels; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->x_pixel_size = vp->gli_product.image_desc.line_spacing; meta->general->y_pixel_size = vp->gli_product.image_desc.pixel_spacing; meta->general->center_latitude = vp->gli_product.image_desc.coord.center_line_center_pixel.lat; meta->general->center_longitude = vp->gli_product.image_desc.coord.center_line_center_pixel.lon;; meta->general->re_major = vp->gli_product.image_desc.coord.earth_model.major; meta->general->re_minor = vp->gli_product.image_desc.coord.earth_model.minor; meta->general->bit_error_rate = MAGIC_UNSET_DOUBLE; meta->general->missing_lines = 0; meta->general->no_data = MAGIC_UNSET_DOUBLE; // Fill SAR block meta->sar = meta_sar_init(); // working with assumptions here meta->sar->image_type = 'G'; if (vp->sensor.clock_angle >= 0.0) meta->sar->look_direction = 'R'; else meta->sar->look_direction = 'L'; meta->sar->azimuth_look_count = vp->gli_product.azimuth_looks; meta->sar->range_look_count = vp->gli_product.range_looks; meta->sar->deskewed = vp->gli_product.skew_flag; meta->sar->original_line_count = meta->general->line_count; meta->sar->original_sample_count = meta->general->sample_count; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; meta->sar->range_time_per_pixel = fabs((2.0 * vp->gli_product.image_desc.pixel_spacing) / SPD_LIGHT); meta->sar->azimuth_time_per_pixel = vp->gli_product.time_per_line; meta->sar->slant_range_first_pixel = vp->gli_product.near_range; meta->sar->slant_shift = 0.0; if (meta->general->orbit_direction == 'D') meta->sar->time_shift = 0.0; else if (meta->general->orbit_direction == 'A') meta->sar->time_shift = fabs(meta->sar->original_line_count * meta->sar->azimuth_time_per_pixel); else meta->sar->time_shift = MAGIC_UNSET_DOUBLE; meta->sar->wavelength = SPD_LIGHT / vp->sensor.beam[0].carrier_freq; meta->sar->prf = vp->sensor.beam[0].prf; meta->sar->earth_radius_pp = MAGIC_UNSET_DOUBLE; strcpy(meta->sar->satellite_binary_time, MAGIC_UNSET_STRING); strcpy(meta->sar->satellite_clock_time, MAGIC_UNSET_STRING); doppler_params = vp->sensor.beam[0].doppler_centroid_parameters; // FIXME: Check units for higher coefficients meta->sar->range_doppler_coefficients[0] = doppler_params.doppler_centroid_coefficients.a[0]; meta->sar->range_doppler_coefficients[1] = doppler_params.doppler_centroid_coefficients.a[1]; meta->sar->range_doppler_coefficients[2] = doppler_params.doppler_centroid_coefficients.a[2]; for (i=0; i<3; i++) meta->sar->azimuth_doppler_coefficients[i] = 0.0; meta->sar->azimuth_processing_bandwidth = vp->gli_product.processor_bandwidth; meta->sar->chirp_rate = vp->sensor.beam[0].chirp_rate; meta->sar->pulse_duration = vp->sensor.beam[0].pulse_length; meta->sar->range_sampling_rate = vp->sensor.beam[0].sampling_freq; strcpy(meta->sar->polarization, vp->sensor.beam[0].polarization_block.polarization[0].polarization); meta->sar->multilook = 1; meta->sar->pitch = vp->sensor.ephemeris.attitude.pitch; meta->sar->roll = vp->sensor.ephemeris.attitude.roll; meta->sar->yaw = vp->sensor.ephemeris.attitude.yaw; // Fill state vector structure nStVec = vp->sensor.ephemeris.sv_block.nr_sv; meta->state_vectors = meta_state_vectors_init(nStVec); date_dssr2date(vp->sensor.ephemeris.sv_block.state_vector[0].date, &ref_date, &ref_time); meta->state_vectors->year = ref_date.year; date_ymd2jd(&ref_date, &jd); meta->state_vectors->julDay = jd.jd; meta->state_vectors->second = date_hms2sec(&ref_time); meta->state_vectors->vector_count = nStVec; for (i=0; i<nStVec; i++) { date_dssr2date(vp->sensor.ephemeris.sv_block.state_vector[i].date, &ymd, &time); meta->state_vectors->vecs[i].time = date_difference(&ref_date, &ref_time, &ymd, &time); meta->state_vectors->vecs[i].vec.pos.x = vp->sensor.ephemeris.sv_block.state_vector[i].x; meta->state_vectors->vecs[i].vec.pos.y = vp->sensor.ephemeris.sv_block.state_vector[i].y; meta->state_vectors->vecs[i].vec.pos.z = vp->sensor.ephemeris.sv_block.state_vector[i].z; meta->state_vectors->vecs[i].vec.vel.x = vp->sensor.ephemeris.sv_block.state_vector[i].xv; meta->state_vectors->vecs[i].vec.vel.y = vp->sensor.ephemeris.sv_block.state_vector[i].yv; meta->state_vectors->vecs[i].vec.vel.z = vp->sensor.ephemeris.sv_block.state_vector[i].zv; } date_dssr2date(vp->gli_product.first_line, &ymd, &time); double shift = date_difference(&ref_date, &ref_time, &ymd, &time); int sign; if (compare_time(&ymd, &time, &ref_date, &ref_time) > 0) sign = -1; else sign = 1; for (i=0; i<nStVec; i++) meta->state_vectors->vecs[i].time += sign * shift; meta->state_vectors->second = date_hms2sec(&time); double interval = meta->general->line_count * meta->sar->azimuth_time_per_pixel / 2; propagate_state(meta, 3, interval); meta->sar->earth_radius = meta_get_earth_radius(meta, meta->general->line_count/2, meta->general->sample_count/2); meta->sar->satellite_height = meta_get_sat_height(meta, meta->general->line_count/2, meta->general->sample_count/2); // Fill location block meta->location = meta_location_init(); meta->location->lat_start_near_range = vp->gli_product.image_desc.coord.first_line_first_pixel.lat; meta->location->lon_start_near_range = vp->gli_product.image_desc.coord.first_line_first_pixel.lon; meta->location->lat_start_far_range = vp->gli_product.image_desc.coord.first_line_last_pixel.lat; meta->location->lon_start_far_range = vp->gli_product.image_desc.coord.first_line_last_pixel.lon; meta->location->lat_end_near_range = vp->gli_product.image_desc.coord.last_line_first_pixel.lat; meta->location->lon_end_near_range = vp->gli_product.image_desc.coord.last_line_first_pixel.lon; meta->location->lat_end_far_range = vp->gli_product.image_desc.coord.last_line_last_pixel.lat; meta->location->lon_end_far_range = vp->gli_product.image_desc.coord.last_line_last_pixel.lon; return meta; }
void *recv2_continuo_burst (void *param) { data_test *data = (data_test *)param; received_probe *recv_probe = &(data->probe[0]); settings *conf_settings = data->conf_settings; resume *result = data->result; int sockfd = -1, resize_buffer = DEFAULT_SOC_BUFFER, yes = 1, received = 0; struct sockaddr receiver_addr; struct sockaddr_in *receiver_addr_in = (struct sockaddr_in *)&receiver_addr; char buffer[BUFFER_SIZE]; packet_probe *pkt = (packet_probe *)buffer; struct timeval tm_now; timeval32 tm32_now; int jitter = 0; resize_buffer = conf_settings->recvsock_buffer * 1024; if (resize_socket_buffer (resize_buffer)) { DEBUG_MSG(DEBUG_LEVEL_LOW, "Could not resize socket buffers!!\n"); return NULL; } sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); bzero(&receiver_addr, sizeof(receiver_addr)); receiver_addr_in->sin_family = AF_INET; receiver_addr_in->sin_addr.s_addr = 0; receiver_addr_in->sin_port = htons(conf_settings->udp_port); if (setsockopt (sockfd, SOL_SOCKET, SO_RCVBUF, (const void *)&resize_buffer, sizeof(resize_buffer)) != 0) { DEBUG_MSG (DEBUG_LEVEL_LOW, "Could not resize receive socket buffers!!\n"); return NULL; } if (setsockopt (sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { DEBUG_LEVEL_MSG (DEBUG_LEVEL_LOW, "Could not set socket\n"); return NULL; } if (bind(sockfd, (const struct sockaddr *)&receiver_addr, sizeof(receiver_addr))==-1) { DEBUG_LEVEL_MSG (DEBUG_LEVEL_LOW, "Could not bind!!\n"); return NULL; } memset (recv_probe, 0, sizeof(received_probe)); while (!recv_probe->stop_recv) { memset (buffer, 0, BUFFER_SIZE); received = recvfrom(sockfd, pkt, BUFFER_SIZE, 0, NULL, NULL); ioctl(sockfd, SIOCGSTAMP, &tm_now); tm32_now.tv_sec = tm_now.tv_sec; tm32_now.tv_usec = tm_now.tv_usec; if ((received > sizeof(packet_probe)) && (pkt->packet_id != PACKET_END_TEST)) { if (recv_probe->received_total == 0) { recv_probe->received_total = received + OVERHEAD_SIZE; recv_probe->received_packets = 1; recv_probe->start = tm32_now; recv_probe->end = recv_probe->report_time = tm32_now; recv_probe->report_time.tv_usec += ((conf_settings->test.cont.report_interval) % 1000) * 1000; recv_probe->report_time.tv_sec += (conf_settings->test.cont.report_interval) / 1000; if (recv_probe->report_time.tv_usec >= 1000000) { recv_probe->report_time.tv_usec -= 1000000; recv_probe->report_time.tv_sec += 1; } } else { /* calcular jitter medio, min e max */ jitter = difftimeval2us (&(recv_probe->end), &tm32_now); if (jitter > result->jitter_max) result->jitter_max = jitter; if (jitter < result->jitter_min) result->jitter_min = jitter; result->jitter_med += jitter; recv_probe->received_total += received + OVERHEAD_SIZE; recv_probe->received_packets++; recv_probe->end = tm32_now; } } if ((compare_time(&(recv_probe->report_time), &(tm32_now))) || (pkt->packet_id == PACKET_END_TEST)) { recv_probe->stop_recv = 1; break; } } close (sockfd); result->loss_med = conf_settings->test.cont.pkt_num - recv_probe->received_packets; return NULL; }