Exemplo n.º 1
0
Arquivo: net.c Projeto: iddumied/SDWM
int main() {
  printf("Siezof Net: %d Bytes\n", sizeof(Net));

  setup_net();

  while(1==1){
    sleep(1);
    update_net();

    int i;
    printf("lan online: %d, wlan online: %d, connected %d\n", net_lan_online(), net_wlan_online(), net.connected);
    printf("%5s| %10s %10s %10s %10s %10s %10s %10s\n", "", "online", "wireless", "linkcur", "linkmax", "easyon","b/s up", "b/s down");
    printf("%5s+-%10s-%10s-%10s-%10s-%10s-%10s-%10s\n", "-----","----------","----------","----------","----------","----------","----------","----------");
    for (i = 0; i < net.num_interfaces; i++) {
      printf("%5s| %10d %10d %10d %10d %10d %10d %10d\n", net.interfaces[i].name, net.interfaces[i].online, net.interfaces[i].wireless,
              net.interfaces[i].linkcur, net.interfaces[i].linkmax, net.interfaces[i].easy_online, net.interfaces[i].between.transmit.bytes_per_sec,
                net.interfaces[i].between.receive.bytes_per_sec);
    }

  }

  return 0;
}
Exemplo n.º 2
0
int main( int argc, char ** argv)
{
	float mse=1000;
	unsigned int num_train=R_NUM;
	unsigned int num_test=T_NUM;
	struct fann_train_data* data ;
	unsigned int i;
	const float desired_error = (const float) E_DES;
	const unsigned int epochs_between_reports = N_EPR;
	unsigned int bitf_limit=0;
	unsigned int bitf=bitf_limit+1;
	struct fann *ann;

#if MIMO_FANN
	printf("MIMO fann\n");
#else
	printf("Old fann\n");
#endif

#ifdef USE_XOR_DATA
	if (argc<2)
	{
		printf("Error: please supply a data file\n");
		return -1;
	}
	printf("Using %s\n", argv[1]);
	data=fann_read_train_from_file(argv[1]);
#else
	printf("Generating training data\n");
	data = fann_create_train(S_DIM, I_DIM, O_DIM);
	for ( i=0; i< S_DIM; i++)
	{
		f1(data, i); 
	}
#endif

	ann=setup_net(data);

#if VERBOSE
	fann_print_parameters(ann);
#endif

	for (i=0; mse>desired_error && i!=num_train && bitf>bitf_limit; i++)
	{
#if VERBOSE
		mse=train_epoch_debug(ann, data, i);
#else 
		mse=fann_train_epoch(ann, data);
#endif
		bitf=fann_get_bit_fail(ann);
		if ( !((i) % epochs_between_reports))
			printf("Epochs     %8d. Current error: %.10f. Bit fail: %u\n", i+(!i), mse, bitf);
			/*printf ("[ %7u ] MSE Error : %.10e ###################\n", i, mse);*/
	}
	printf("Epochs     %8d. Current error: %.10f. Bit fail: %u\n", i+(!i), mse, bitf);

	printf("Testing network. %f\n", fann_test_data(ann, data));
	
	gettimeofday(&tv_start,NULL);
	for (i=0; i!=num_test; i++)
 		fann_run_data(ann, data);
	gettimeofday(&tv_now,NULL);
	report("---",0);	
	

#if 1
	printf("Trying to save network\n");
#if MIMO_FANN 
	fann_save(ann, "saved_mimo.net");
	fann_destroy(ann);
	ann=fann_create_from_file("saved_mimo.net");
	fann_save(ann, "saved_mimo2.net");
	fann_destroy(ann);
#else
	fann_save(ann, "saved_old.net");
#endif
#endif

	return 0;
}
Exemplo n.º 3
0
void setup_status()
{
  #ifdef INFO
  char buffer[256];
  sprintf(buffer, "Setup Status: draw Memory %s", sbar_status_symbols[DrawMemory].active ? "yes" : "no");
  log_str(buffer, LOG_DEBUG);
  sprintf(buffer, "Setup Status: draw Battery %s", sbar_status_symbols[DrawBattery].active ? "yes" : "no");
  log_str(buffer, LOG_DEBUG);
  sprintf(buffer, "Setup Status: draw Uptime %s", sbar_status_symbols[DrawUptime].active ? "yes" : "no");
  log_str(buffer, LOG_DEBUG);
  sprintf(buffer, "Setup Status: draw Termal %s", sbar_status_symbols[DrawTermal].active ? "yes" : "no");
  log_str(buffer, LOG_DEBUG);
  #ifdef NF310_A01
  sprintf(buffer, "Setup Status: draw Backlight %s", sbar_status_symbols[DrawBacklight].active ? "yes" : "no");
  log_str(buffer, LOG_DEBUG);
  #endif
  sprintf(buffer, "Setup Status: draw Net %s", sbar_status_symbols[DrawNet].active ? "yes" : "no");
  log_str(buffer, LOG_DEBUG);
  #endif

  // setup disks
  setup_disk();  

  #ifdef INFO
  log_str("Setup Status Disk", LOG_INFO);
  #endif

  // setup uptime
  if(sbar_status_symbols[DrawUptime].active) {
    setup_uptime();
    
    #ifdef INFO
    log_str("Setup Status Uptime", LOG_INFO);
    #endif
  }
  
  // setup net
  if(sbar_status_symbols[DrawNet].active) {
    setup_net();

    #ifdef INFO
    log_str("Setup Status Net", LOG_INFO);
    #endif
  }
  
  // setup audio
  if(sbar_status_symbols[DrawAudio].active) {
    setup_audio();

    #ifdef INFO
    log_str("Setup Status Audio", LOG_INFO);
    #endif
  }
  
  #ifdef NF310_A01
  // setup backlight
  if(sbar_status_symbols[DrawBacklight].active) {
    backlight.on = True;

    #ifdef INFO
    log_str("Setup Status Backlight", LOG_INFO);
    #endif
  }
  #endif

  // setup cpu
  setup_cpu();

  #ifdef INFO
  log_str("Setup Status CPU", LOG_INFO);
  #endif
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
	struct sockaddr_can	addr = {
		.can_family	=  AF_CAN
	};

	int			s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
	struct ifreq		ifr;
	struct pollfd		fds[2];

	if (setup_net(argv[1]) < 0)
		return EXIT_FAILURE;

	strcpy(ifr.ifr_name, argv[1]);
	ioctl(s, SIOCGIFINDEX, &ifr);

	addr.can_ifindex = ifr.ifr_ifindex;
	bind(s, (void *)&addr, sizeof addr);

	fds[0].fd     = STDIN_FILENO;
	fds[0].events = POLLIN;

	fds[1].fd     = s;
	fds[1].events = POLLIN;

	for (;;) {
		int	rc;

		fds[0].revents = 0;
		fds[1].revents = 0;

		rc = poll(fds, 2, -1);
		if (rc < 0) {
			perror("poll()");
			return EXIT_FAILURE;
		}

		if ((fds[0].revents | fds[1].revents) & POLLERR)
			return EXIT_FAILURE;

		if (fds[0].revents & POLLIN) {
			char	buf[1024];
			char	*data;
			ssize_t	l = read(fds[0].fd, buf, sizeof(buf) - 1);
			int	id;
			struct can_frame	frame;

			if (l < 0) {
				perror("read(STDIN)");
				return EXIT_FAILURE;
			}

			if (l == 0)
				/* EOF */
				break;

			buf[l] = '\0';
			while (l > 0 && iscntrl(buf[l-1]))
				buf[--l] = '\0';

			id = strtol(buf, &data, 0);
			if (data[0] == '\0') {
				fprintf(stderr, "missing data in input\n");
				continue;
			}

			++data;

			if (id < 0) {
				id -= id;
				id |= CAN_RTR_FLAG;
			}

			if (id > (1 << 11) - 1) {
				id &= CAN_EFF_MASK | CAN_RTR_FLAG;
				id |= CAN_EFF_FLAG;
			}

			frame.can_dlc = MIN(strlen(data), sizeof frame.data);
			frame.can_id = id;
			memcpy(frame.data, data, frame.can_dlc);

			rc = sendto(s, &frame, sizeof frame, 0,
				    (void const *)&addr, sizeof addr);
			if (rc < 0) {
				perror("sendto(CAN)");
				return EXIT_FAILURE;
			}
		}

		if (fds[1].revents & POLLIN) {
			struct can_frame	frame;
			struct sockaddr_can	r_addr;
			socklen_t		a_len = sizeof r_addr;
			size_t			i;
			uint32_t		id;

			rc = recvfrom(s, &frame, sizeof frame, 0,
				      (void *)&r_addr, &a_len);
			if (rc < 0) {
				perror("recvfrom(CAN)");
				return EXIT_FAILURE;
			}

			if (rc == 0)
				/* EOF? */
				break;

			id = frame.can_id;
			if (!(frame.can_id & CAN_EFF_FLAG))
				id &= CAN_SFF_MASK;
			else
				id &= CAN_EFF_MASK;

			printf("[%d]: %s%s%u[%u] = [",
			       r_addr.can_ifindex,
			       frame.can_id & CAN_EFF_FLAG ? "E" : "",
			       frame.can_id & CAN_RTR_FLAG ? "R" : "",
			       id,
			       frame.can_dlc);

			for (i = 0; i < MIN(frame.can_dlc,
					    sizeof frame.data); ++i) {
				unsigned char	c = frame.data[i];

				if (i > 0)
					printf(",");

				if (isprint(c))
					printf("'%c'", c);
				else
					printf("%02x", c);
			}

			printf("]\n");
		}
	}
}