Exemple #1
0
std::string values2str(urdf::Vector3 vec)
{
    double xyz[3];
    xyz[0] = vec.x;
    xyz[1] = vec.y;
    xyz[2] = vec.z;
    return values2str(3, xyz);
}
Exemple #2
0
std::string values2str(urdf::Color c)
{
    double rgba[4];
    rgba[0] = c.r;
    rgba[1] = c.g;
    rgba[2] = c.b;
    rgba[3] = c.a;
    return values2str(4, rgba);
}
Exemple #3
0
std::string values2str(double d)
{
    return values2str(1, &d);
}
Exemple #4
0
std::string values2str(urdf::Rotation rot)
{
    double rpy[3];
    rot.getRPY(rpy[0], rpy[1], rpy[2]);
    return values2str(3, rpy);
}
Exemple #5
0
/* do the actual output */
void print_values(unsigned int y,unsigned int x,const char *if_name,t_iface_speed_stats stats,float multiplier,t_iface_stats full_stats) {
   char buffer[50];
#if CSV || HTML
	FILE *tmp_out_file;
#endif
   t_iface_speed_stats *stats_csv = NULL;
   t_double_types stats_csv_d;
#ifdef HAVE_CURSES
	unsigned int row=0;
	unsigned int col=0;
	unsigned int width=0;
	unsigned int i=0, j=0;
	char adjust=0;
#endif
    switch (output_method) {
#ifdef HAVE_CURSES		
        case CURSES_OUT:
            mvwprintw(stdscr,y,x,"%15s:",if_name); /* output the name */
#if HAVE_WATTRON            
            if (stats.errors.in && output_unit!=ERRORS_OUT) wattron(stdscr, A_REVERSE);
#endif            
            wprintw(stdscr,"%s",values2str(0,stats,full_stats,multiplier,buffer,49));
#if HAVE_WATTRON            
            if (stats.errors.in && output_unit!=ERRORS_OUT) wattroff(stdscr, A_REVERSE);
#endif            
            wprintw(stdscr," ");
#if HAVE_WATTRON            
            if (stats.errors.out && output_unit!=ERRORS_OUT) wattron(stdscr, A_REVERSE);
#endif            
            wprintw(stdscr,"%s",values2str(1,stats,full_stats,multiplier,buffer,49));
#if HAVE_WATTRON            
            if (stats.errors.out && output_unit!=ERRORS_OUT) wattroff(stdscr, A_REVERSE);
#endif            
            wprintw(stdscr," ");
#if HAVE_WATTRON            
            if ((stats.errors.out || stats.errors.in) && output_unit!=ERRORS_OUT) wattron(stdscr, A_REVERSE);
#endif            
            wprintw(stdscr,"%s",values2str(2,stats,full_stats,multiplier,buffer,49));
#if HAVE_WATTRON            
            if ((stats.errors.out || stats.errors.in) && output_unit!=ERRORS_OUT) wattroff(stdscr, A_REVERSE);
#endif            
            break;
        case CURSES2_OUT:
	  if (cols<48 || rows<45) mvwprintw(stdscr,1,2,"window size too small.\n  it has to be at least 49x46.");
	  else {
	    if (show_only_if+5==y) { /* show only one interface at a time */
	      width=(cols-3-16-4)/3;
	      mvwprintw(stdscr,39,2," +-----> interface: %s        ",if_name); /* output the name */
	      switch (output_type) {
	      case RATE_OUT:
		i=(int)(stats.bytes.in*multiplier/1024); /* incoming */
		j=(int)(stats.bytes.out*multiplier/1024); /* outgoing */
		break;
#ifdef EXTENDED_STATS
	      case MAX_OUT:
		i=(int)(full_stats.max.bytes.in/1024);
		j=(int)(full_stats.max.bytes.out/1024);
		break;
	      case SUM_OUT:
		i=(int)(full_stats.sum.bytes.in/1024);
		j=(int)(full_stats.sum.bytes.out/1024);
		break;
	      case AVG_OUT:
		i=(int)(full_stats.avg.item_sum.bytes.in/1024);
		j=(int)(full_stats.avg.item_sum.bytes.out/1024);
		break;
#endif
	      };
	      /* adjust scale */
	      if (i>max_rt || j>max_rt) {
		adjust=1;
		if (i>j) max_rt=i; else max_rt=j;
	      } else if (i<=max_rt-24*scale && j<=max_rt-24*scale) { adjust=1; max_rt=31*scale; };
	      if (adjust) {
		adjust=!adjust;
		if (max_rt<32) max_rt=32;
		/* print scale */
		scale=max_rt/32;
		if (max_rt>=1024) for (row=0;row<=31;row++) mvwprintw(stdscr,row+3,34+cols-48,"%2.2fM|",(float)(max_rt-row*scale)/1024);
		else for (row=0;row<=31;row++) mvwprintw(stdscr,row+3,3+cols-484,"%4uk|",max_rt-row*scale);
	      };
	      /* print bar (incoming) */
	      if (i>0) { if (i<(max_rt-31*scale)) i=1; else i=(i-(max_rt-31*scale))/scale+2; };
	      for (row=34;row>=3;row--) {
		if (i>0) attron(COLOR_PAIR(1));
		for (col=0;col<width;col++) mvwaddch(stdscr,row,col+5,ACS_HLINE);
		if (i>0) { attroff(COLOR_PAIR(1)); i--; }
	      };
	      /* print bar (outgoing) */
	      if (j>0) { if (j<(max_rt-31*scale)) j=1; else j=(j-(max_rt-31*scale))/scale+2; };
	      for (row=34;row>=3;row--) {
		if (j>0) attron(COLOR_PAIR(2));
		for (col=0;col<width;col++) mvwaddch(stdscr,row,2*width+5+col,ACS_HLINE);
		if (j>0) { attroff(COLOR_PAIR(2)); j--; }
	      };
	    } else if (show_only_if+6==y) if (strcmp("total",if_name)==0) show_only_if=0;
	  };
            break;
#endif
		case PLAIN_OUT_ONCE:
        case PLAIN_OUT:
			if (output_method==PLAIN_OUT && ansi_output) printf("\033[%d;2H",y);
            printf("%15s:",if_name); /* output the name */
            printf("%s ", values2str(0,stats,full_stats,multiplier,buffer,49));
				printf("%s ",values2str(1,stats,full_stats,multiplier,buffer,49));
				printf("%s\n",values2str(2,stats,full_stats,multiplier,buffer,49));
            break;
#ifdef HTML			
		case HTML_OUT:
            tmp_out_file=out_file==NULL ? stdout : out_file;
			fprintf(tmp_out_file,"<tr><td class=\"bwm-ng-name\">%15s:</td><td class=\"bwm-ng-in\"><span class=\"bwm-ng-%s\">",if_name,
                    (stats.errors.in && output_unit!=ERRORS_OUT) ? "error" : "dummy");
            fprintf(tmp_out_file,"%s</span> </td><td class=\"bwm-ng-out\"><span class=\"bwm-ng-%s\">",
                    values2str(0,stats,full_stats,multiplier,buffer,49),
                    (stats.errors.out && output_unit!=ERRORS_OUT) ? "error" : "dummy");
            fprintf(tmp_out_file,"%s</span> </td><td class=\"bwm-ng-total\"><span class=\"bwm-ng-%s\">",
                    values2str(1,stats,full_stats,multiplier,buffer,49),
                    ((stats.errors.out || stats.errors.in) && output_unit!=ERRORS_OUT) ? "error" : "dummy" );
            fprintf(tmp_out_file,"%s</span></td><tr>\n",values2str(2,stats,full_stats,multiplier,buffer,49));
            break;
#endif
#ifdef CSV
        case CSV_OUT:
				tmp_out_file=out_file==NULL ? stdout : out_file;
            fprintf(tmp_out_file,"%i%c%s%c",(int)time(NULL),csv_char,if_name,csv_char);
				if (output_type == RATE_OUT || output_type == SUM_OUT) {
					if (output_type == RATE_OUT) {
						stats_csv = &stats;
#if !NETSTAT_BSD_BYTES && !NETSTAT_NETBSD && NETSTAT
	               if (input_method!=NETSTAT_IN)
#endif
                   /* output Bytes/s */
                   fprintf(tmp_out_file,"%.2f%c%.2f%c%.2f%c%llu%c%llu%c",(double)(stats_csv->bytes.out*multiplier),csv_char,(double)(stats_csv->bytes.in*multiplier),csv_char,(double)((stats_csv->bytes.out+stats_csv->bytes.in)*multiplier),csv_char,stats_csv->bytes.in,csv_char,stats_csv->bytes.out,csv_char);
   	            /* show packets/s and errors/s */
      	         fprintf(tmp_out_file,"%.2f%c%.2f%c%.2f%c%llu%c%llu",(double)stats_csv->packets.out*multiplier,csv_char,(double)stats_csv->packets.in*multiplier,csv_char,(double)(stats_csv->packets.out+stats_csv->packets.in)*multiplier,csv_char,stats_csv->packets.in,csv_char,stats_csv->packets.out);
         	      fprintf(tmp_out_file,"%c%.2f%c%.2f%c%llu%c%llu\n",csv_char,stats_csv->errors.out*multiplier,csv_char,stats_csv->errors.in*multiplier,csv_char,stats_csv->errors.in,csv_char,stats_csv->errors.out);
					fflush(tmp_out_file);	

					} else {
						stats_csv = &full_stats.sum;
#if !NETSTAT_BSD_BYTES && !NETSTAT_NETBSD && NETSTAT
						if (input_method!=NETSTAT_IN)
#endif                    
						 /* output Bytes */
						 fprintf(tmp_out_file,"%llu%c%llu%c%llu%c",stats_csv->bytes.out,csv_char,stats_csv->bytes.in,csv_char,(stats_csv->bytes.out+stats_csv->bytes.in),csv_char);
						/* show packets and errors */
						fprintf(tmp_out_file,"%llu%c%llu%c%llu",stats_csv->packets.out,csv_char,stats_csv->packets.in,csv_char,(stats_csv->packets.out+stats_csv->packets.in));
						fprintf(tmp_out_file,"%c%llu%c%llu\n",csv_char,stats_csv->errors.out,csv_char,stats_csv->errors.in);
					fflush(tmp_out_file);	
						}
				} else { /* MAX_OUT or AVG_OUT */
					if (output_type == MAX_OUT)
						stats_csv_d = full_stats.max;
					else {
						stats_csv_d.bytes.out = full_stats.avg.item_sum.bytes.out/full_stats.avg.items;
						stats_csv_d.bytes.in = full_stats.avg.item_sum.bytes.in/full_stats.avg.items;
						stats_csv_d.bytes.total = full_stats.avg.item_sum.bytes.total/full_stats.avg.items;
						stats_csv_d.packets.out = full_stats.avg.item_sum.packets.out/full_stats.avg.items;
						stats_csv_d.packets.in = full_stats.avg.item_sum.packets.in/full_stats.avg.items;
						stats_csv_d.packets.total = full_stats.avg.item_sum.packets.total/full_stats.avg.items;
						stats_csv_d.errors.out = full_stats.avg.item_sum.errors.out/full_stats.avg.items;
						stats_csv_d.errors.in = full_stats.avg.item_sum.errors.in/full_stats.avg.items;
						stats_csv_d.errors.total = full_stats.avg.item_sum.errors.total/full_stats.avg.items;
					}
#if !NETSTAT_BSD_BYTES && !NETSTAT_NETBSD && NETSTAT
               if (input_method!=NETSTAT_IN)
#endif
                   /* output Bytes/s */
                   fprintf(tmp_out_file,"%.2Lf%c%.2Lf%c%.2Lf%c",stats_csv_d.bytes.out,csv_char,stats_csv_d.bytes.in,csv_char,stats_csv_d.bytes.total,csv_char);
               /* show packets/s and errors/s */
               fprintf(tmp_out_file,"%.2Lf%c%.2Lf%c%.2Lf",stats_csv_d.packets.out,csv_char,stats_csv_d.packets.in,csv_char,stats_csv_d.packets.total);
               fprintf(tmp_out_file,"%c%.2Lf%c%.2Lf\n",csv_char,stats_csv_d.errors.out,csv_char,stats_csv_d.errors.in);
					fflush(tmp_out_file);	
				}
            break;
#endif			
    }
}