Exemplo n.º 1
0
int monitor_init(void) {
  int rc;

  /* Registering device */
  rc = register_chrdev(monitor_major, "badmonitor", &monitor_fops);
  if (rc < 0) {
    printk(
      "<1>badmonitor: cannot obtain major number %d\n", monitor_major);
    return rc;
  }

  /* Allocating monitor_buffer */
  monitor_buffer = kmalloc(MAX_SIZE, GFP_KERNEL); 
  if (!monitor_buffer) { 
    rc = -ENOMEM;
    goto fail; 
  } 
  memset(monitor_buffer, 0, MAX_SIZE);
  curr_size= 0;
  curr_pos= 0;
  m_init(&mutex);
  c_init(&wait_queue);

  printk("<1>Inserting badmonitor module\n"); 
  return 0;

  fail: 
    monitor_exit(); 
    return rc;
}
static int c_direct_set(const struct buxton_layer *layer,
		const char *key, const char *value, enum buxton_key_type type)
{
	int r;
	struct buxton_value val;

	if (!layer || !key || !*key || !value) {
		errno = EINVAL;
		bxt_err("Set: Layer '%s' Key '%s' Value '%s': %s",
				layer ? buxton_layer_get_name(layer) : "",
				key ? key : "", value ? value : "",
				strerror(errno));
		return -1;
	}

	r = c_set_value(type, value, &val);
	if (r == -1)
		return -1;

	r = c_init();
	if (r == -1)
		return -1;

	r = direct_set(layer, key, &val);

	c_exit();

	if (r == -1) {
		bxt_err("Set: Layer '%s' Key '%s' Value '%s': %s",
				buxton_layer_get_name(layer), key, value,
				strerror(errno));
	}

	return r;
}
static int c_direct_set_priv(const struct buxton_layer *layer,
		const char *key, const char *priv, enum buxton_priv_type type)
{
	int r;

	if (!layer || !key || !*key || !priv) {
		errno = EINVAL;
		bxt_err("Set-priv: Layer '%s' Key '%s' Priv. '%s': %s",
				layer ? buxton_layer_get_name(layer) : "",
				key ? key : "", priv ? priv : "",
				strerror(errno));
		return -1;
	}

	r = c_init();
	if (r == -1)
		return -1;

	r = direct_set_priv(layer, key, type, priv);

	c_exit();

	if (r == -1) {
		bxt_err("Set-priv: Layer '%s' Key '%s' Priv. '%s': %s",
				buxton_layer_get_name(layer), key, priv,
				strerror(errno));
	}

	return r;
}
int c_direct_unset(const struct buxton_layer *layer,
		const char *key, UNUSED const char *value,
		UNUSED const char *rpriv, UNUSED const char *wpriv)
{
	int r;

	if (!layer || !key || !*key) {
		errno = EINVAL;
		bxt_err("Unset: Layer '%s' Key '%s': %s",
				layer ? buxton_layer_get_name(layer) : "",
				key ? key : "", strerror(errno));
		return -1;
	}

	r = c_init();
	if (r == -1)
		return -1;

	r = direct_unset(layer, key);

	c_exit();

	if (r == -1) {
		bxt_err("Unset: Layer '%s' Key '%s': %s",
				buxton_layer_get_name(layer), key,
				strerror(errno));
	}

	return r;
}
Exemplo n.º 5
0
int syncread_init(void) {
  int rc;

  /* Registering device */
  rc = register_chrdev(syncread_major, "syncread", &syncread_fops);
  if (rc < 0) {
    printk(
      "<1>syncread: cannot obtain major number %d\n", syncread_major);
    return rc;
  }

  readers= 0;
  writing= FALSE;
  pend_open_write= 0;
  curr_size= 0;
  m_init(&mutex);
  c_init(&cond);

  /* Allocating syncread_buffer */
  syncread_buffer = kmalloc(MAX_SIZE, GFP_KERNEL);
  if (syncread_buffer==NULL) {
    syncread_exit();
    return -ENOMEM;
  }
  memset(syncread_buffer, 0, MAX_SIZE);

  printk("<1>Inserting syncread module\n");
  return 0;
}
Exemplo n.º 6
0
int main(){


	queue_c_t* c;
	c_node* node;
	int *z;
	int k;
	int i[20] = {100,101,102,103,104,105,106,107,108,109, 
			   110,111,112,113,114,115,116,117,118,119};
	z = (int*)xmalloc(sizeof(int));

	c = (queue_c_t*)xmalloc(sizeof(queue_c_t));
	c_init(c);

	node = c->head;

	c_push(c, &i[0]);//100 1 
	c_push(c, &i[1]);//101 5
	c_push(c, &i[2]);//102 1
	c_push(c, &i[3]);//103 1
	c_push(c, &i[4]);//104 4
	c_push(c, &i[5]);//105 1
	c_push(c, &i[6]);//106 7
	c_push(c, &i[7]);//107 1
	c_push(c, &i[8]);//108 1
	c_push(c, &i[9]);//109 2
	//c->head->next->next->next->r =0;
	
	/*z = c_pop(c);	
	printf("pop :%i \n", z[0]);
	c_push(c, &i[14], 1);//114 1
	*/
	printf("c size:%i\n", c->size);

	for(k=0; k<10 ; k++){
		z = c_pop(c);	
		printf("pop :%i \n", z[0]);
	}
	printf("TEST MAIN\n");
	c_push(c, &i[0]);//100 1 
	c_push(c, &i[1]);//101 5
	c_push(c, &i[2]);//102 1
	c_push(c, &i[3]);//103 1
	c_push(c, &i[4]);//104 4
	c_push(c, &i[5]);//105 1
	c_push(c, &i[6]);//106 7
	c_push(c, &i[7]);//107 1
	c_push(c, &i[8]);//108 1
	c_push(c, &i[9]);//109 2
	c_node_update(c, &(i[4])); //104 5
	c_node_update(c, &(i[4])); //104 6
	c_node_update(c, &(i[4])); //104 7
	printf("update item\n");
	for(k=0; k<10 ; k++){
		z = c_pop(c);	
		printf("pop :%i \n", z[0]);
	}

	return 1;
}
Exemplo n.º 7
0
Arquivo: cam.c Projeto: BotBot/ASV
int main(int argc, char* argv[]) {
  check(c_init());
  camInitialized = 1;
  camEnumDevices();
  
  if (numDevices == 0) {
    fprintf(stderr, "no cameras found\n");
    exit(1);
  }

  CHandle handle = c_open_device(camDevices[0].name);
  

  c_cleanup();
}
Exemplo n.º 8
0
int main()
{
	c_init();

	invalidated = false;
	requests.push(Request());
	auto t1 = new std::thread(invalidateRequests);
	auto t2 = new std::thread(processFirstRequest);
	t1->join();
	t2->join();
	delete t1;
	delete t2;

	c_free();
	return 0;
}
Exemplo n.º 9
0
int main(int argc, char **argv)
{
	int ret;
	pthread_t input_id, output_id;
	
	if(argc < 2)
		url="/opt/nfsroot/cache/db/10003196.mkv";/* default to testurl */
	else
		url=argv[1];/* use passed url */
	
	c_init();

	ret = input_tail(&buffer_context);
	if(ret != 0) {
		printf("input tail failed\n");
	} else {
		printf("input tail sucessed\n");
	}	

	if(pthread_create(&input_id, NULL, thrd_input, (void *)(&buffer_context)) != 0) {
		printf("Create input_thread error!\n");
		return -1;
	}
	if(pthread_create(&output_id, NULL, thrd_output, (void *)(&buffer_context)) != 0) {
		printf("Create output_thread error!\n");
		return -1;
	}
	
	// 等待线程input_id退出
	if (pthread_join(input_id,NULL) != 0) {
		printf("Join input_thread error!\n");
		return -1;
	}else
		printf("input_thread Joined!\n");
		
	// 等待线程output_id退出
	if (pthread_join(output_id,NULL) != 0) {
		printf("Join output_thread error!\n");
		return -1;
	}else
		printf("output_thread Joined!\n");
	
	//printf("tail_buffer: %s\n", tail_buffer);
	c_destroy();

	return 0;
}
Exemplo n.º 10
0
int main(int argc,char **argv)
{
  umask(022);

  fdstartdir = open_read(".");
  if (fdstartdir == -1)
    strerr_die2sys(111,FATAL,"unable to switch to current directory: ");
  coe(fdstartdir);

  sig_block(sig_term);
  sig_block(sig_alarm);
  sig_catch(sig_term,exitasap);
  sig_catch(sig_alarm,forcerotate);

  ++argv;
  f_init(argv);
  c_init(argv);
  doit(argv);
  c_quit();
  _exit(0);
}
int c_direct_list(const struct buxton_layer *layer,
		UNUSED const char *key, UNUSED const char *value,
		UNUSED const char *rpriv, UNUSED const char *wpriv)
{
	int r;
	char **keys;
	char **k;

	if (!layer) {
		errno = EINVAL;
		bxt_err("List: Layer '%s': %s",
				layer ? buxton_layer_get_name(layer) : "",
				strerror(errno));
		return -1;
	}

	r = c_init();
	if (r == -1)
		return -1;

	r = direct_list(layer, &keys, NULL);

	c_exit();

	if (r == -1) {
		bxt_err("List: Layer '%s': %s", buxton_layer_get_name(layer),
				strerror(errno));
		return -1;
	}

	k = keys;
	while (k && *k) {
		printf("%s\n", *k);
		k++;
	}

	buxton_free_keys(keys);

	return 0;
}
Exemplo n.º 12
0
int bano_init(void) {
  int b;

  /* Registering device */
  b = register_chrdev(bano_major, "bano", &bano_fops);
  if (b < 0) {
    printk("<1>Bano: cannot obtain major number %d\n", bano_major);
    return b;
  }

  damas = 0;
  varones = 0;
  curr_size_d = 0;
  curr_size_v = 0;
  damas_pos = 0;
  varones_pos = 0;
  m_init(&mutex);
  c_init(&cond);

  /* Allocating syncread_buffer */
  buffer_d = kmalloc(MAX_SIZE, GFP_KERNEL);
  if (buffer_d == NULL) {
    bano_exit();
    return -ENOMEM;
  }
  memset(buffer_d, 0, MAX_SIZE);

  buffer_v = kmalloc(MAX_SIZE, GFP_KERNEL);
  if (buffer_v == NULL) {
    bano_exit();
    return -ENOMEM;
  }
  memset(buffer_v, 0, MAX_SIZE);

  printk("<1>Inserting bano module varones y damas\n");
  return 0;
}
static int c_direct_create(const struct buxton_layer *layer,
		const char *key, const char *value, enum buxton_key_type type,
		const char *rpriv, const char *wpriv)
{
	int r;
	struct buxton_value val;

	if (!layer || !key || !*key || !value || !rpriv || !wpriv) {
		errno = EINVAL;
		bxt_err("Create: '%s' '%s' '%s' Priv '%s' '%s': %s",
				layer ? buxton_layer_get_name(layer) : "",
				key ? key : "", value ? value : "",
				rpriv ? rpriv : "", wpriv ? wpriv : "",
				strerror(errno));
		return -1;
	}

	r = c_set_value(type, value, &val);
	if (r == -1)
		return -1;

	r = c_init();
	if (r == -1)
		return -1;

	r = direct_create(layer, key, rpriv, wpriv, &val);

	c_exit();

	if (r == -1) {
		bxt_err("Create: '%s' '%s' '%s' Priv '%s' '%s': %s",
				buxton_layer_get_name(layer), key, value,
				rpriv, wpriv, strerror(errno));
	}

	return r;
}
Exemplo n.º 14
0
int
main(int argc, char **argv )
{
    char ch;
    while ( (ch = getopt(argc, argv, "hi:c:s:")) != -1 )
    switch (ch) {
        case 'h':
            break;
        case 'i':
            image_filename = optarg;
            break;
        case 's':
            symbol_name = optarg;
            break;
        case 'c':
            c_filename = optarg;
            break;
        default:
            fprintf(stderr, "bad usage [%c]\n", ch);
            return EX_USAGE;
    }
    argc -= optind;
    argv += optind;
    if (argc != 1) {
        fprintf(stderr, "type root directory\n");
        return EX_USAGE;
    }
    if (!c_filename && !image_filename) {
        fprintf(stderr, "bad usage, use -i or -c, or both.\n");
        return EX_USAGE;
    }
    if (image_init() == -1) return EX_OSERR;
    if (c_init() == -1) return EX_OSERR;
    if (scan(argv[0]) == -1) return EX_OSERR;
    if (build(argv[0]) == -1) return EX_SOFTWARE;
    return EX_OK;
}
Exemplo n.º 15
0
int main(int argc, char *argv[])
{
	char wait_forever = 0, quiet = 0, reconnect = 0, reconnect_wait = 0;
	char *config_search_dirs[3], *plugin_search_dirs[3];
	char *config_filename = DEFAULT_CONFIG_FILE;
	char home_config_dir[HOME_DIR_LEN];
	char home_plugin_dir[HOME_DIR_LEN];
	char *tmp;
	const char *dev_name = NULL;
	int c, i;
	char *str_addr;
	bdaddr_t bdaddr, current_bdaddr;
	sigset_t sigset;
	int signum, ret=0;
	struct uinput_listen_data uinput_listen_data;
	pthread_t uinput_listen_thread;

	init = 1;

	/* Parse Options */
	while (1) {
		int option_index = 0;

		static struct option long_options[] = {
			{"help", 0, 0, 'h'},
			{"version", 0, 0, 'v'},
			{"config", 1, 0, 'c'},
			{"daemon", 0, 0, 'd'},
			{"quiet", 0, 0, 'q'},
			{"reconnect", 2, 0, 'r'},
			{"wait", 0, 0, 'w'},
			{"name", 1, 0, 'n'},
			{0, 0, 0, 0}
		};

		c = getopt_long (argc, argv, "hvc:dqr::wn:", long_options, &option_index);

		if (c == -1) {
			break;
		}

		switch (c) {
		case 'h':
			print_usage();
			return 0;
			break;
		case 'v':
			printf("CWiid Version %s\n", PACKAGE_VERSION);
			return 0;
			break;
		case 'c':
			config_filename = optarg;
			break;
		case 'd':
			wait_forever = 1;
			quiet = 1;
			reconnect = 1;
			break;
		case 'q':
			quiet = 1;
			break;
		case 'r':
			reconnect = 1;
			if (optarg) {
				reconnect_wait = strtol(optarg, &tmp, 10);
				if (*tmp != '\0') {
					wminput_err("bad reconnect wait time");
					return -1;
				}
			}
			break;
		case 'w':
			wait_forever = 1;
			break;
		case 'n':
			dev_name = optarg;
			break;
		case '?':
			printf("Try `wminput --help` for more information\n");
			return 1;
			break;
		default:
			return -1;
			break;
		}
	}

	if (c_init()) {
		return -1;
	}

#ifdef HAVE_PYTHON
	if (py_init()) {
		return -1;
	}
#endif

	/* Load Config */
	/* Setup search directory arrays */
	if ((tmp = getenv("HOME")) == NULL) {
		wminput_err("Unable to find home directory");
		config_search_dirs[0] = WMINPUT_CONFIG_DIR;
		plugin_search_dirs[0] = CWIID_PLUGINS_DIR;
		config_search_dirs[1] = plugin_search_dirs[1] = NULL;
	}
	else {
		snprintf(home_config_dir, HOME_DIR_LEN, "%s/.cwiid/wminput", tmp);
		snprintf(home_plugin_dir, HOME_DIR_LEN, "%s/.cwiid/plugins", tmp);
		config_search_dirs[0] = home_config_dir;
		plugin_search_dirs[0] = home_plugin_dir;
		config_search_dirs[1] = WMINPUT_CONFIG_DIR;
		plugin_search_dirs[1] = CWIID_PLUGINS_DIR;
		config_search_dirs[2] = plugin_search_dirs[2] = NULL;
	}

	if (conf_load(&conf, config_filename, config_search_dirs,
	  plugin_search_dirs, dev_name)) {
		return -1;
	}

	/* Determine BDADDR */
	/* priority: command-line option, environment variable, BDADDR_ANY */
	if (optind < argc) {
		if (str2ba(argv[optind], &bdaddr)) {
			wminput_err("invalid bdaddr");
			bdaddr = *BDADDR_ANY;
		}
		optind++;
		if (optind < argc) {
			wminput_err("invalid command-line");
			print_usage();
			conf_unload(&conf);
			return -1;
		}
	}
	else if ((str_addr = getenv(WIIMOTE_BDADDR)) != NULL) {
		if (str2ba(str_addr, &bdaddr)) {
			wminput_err("invalid address in %s", WIIMOTE_BDADDR);
			bdaddr = *BDADDR_ANY;
		}
	}
	else {
		bdaddr = *BDADDR_ANY;
	}

	sigemptyset(&sigset);
	sigaddset(&sigset, SIGTERM);
	sigaddset(&sigset, SIGINT);
	sigaddset(&sigset, SIGUSR1);

	do {
		bacpy(&current_bdaddr, &bdaddr);

		/* Wiimote Connect */
		if (!quiet) {
			printf("Put Wiimote in discoverable mode now (press 1+2)...\n");
		}
		if (wait_forever) {
			if (!bacmp(&current_bdaddr, BDADDR_ANY)) {
				if (cwiid_find_wiimote(&current_bdaddr, -1)) {
					wminput_err("error finding wiimote");
					conf_unload(&conf);
					return -1;
				}
			}
			/* TODO: avoid continuously calling cwiid_open */
			cwiid_set_err(cwiid_err_connect);
			while (!(wiimote = cwiid_open(&current_bdaddr, CWIID_FLAG_MESG_IFC)));
			cwiid_set_err(cwiid_err_default);
		}
		else {
			if ((wiimote = cwiid_open(&current_bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) {
				wminput_err("unable to connect");
				conf_unload(&conf);
				return -1;
			}
		}
		if (cwiid_set_mesg_callback(wiimote, &cwiid_callback)) {
			wminput_err("error setting callback");
			conf_unload(&conf);
			return -1;
		}

		if (c_wiimote(wiimote)) {
			conf_unload(&conf);
			return -1;
		}
#ifdef HAVE_PYTHON
		if (py_wiimote(wiimote)) {
			conf_unload(&conf);
			return -1;
		}
#endif

		/* init plugins */
		for (i=0; (i < CONF_MAX_PLUGINS) && conf.plugins[i].name; i++) {
			switch (conf.plugins[i].type) {
			case PLUGIN_C:
				if (c_plugin_init(&conf.plugins[i], i)) {
					wminput_err("error on %s init", conf.plugins[i].name);
					conf_unload(&conf);
					cwiid_close(wiimote);
					return -1;
				}
				break;
#ifdef HAVE_PYTHON
			case PLUGIN_PYTHON:
				if (py_plugin_init(&conf.plugins[i], i)) {
					wminput_err("error %s init", conf.plugins[i].name);
					conf_unload(&conf);
					cwiid_close(wiimote);
					return -1;
				}
				break;
#endif
			}
		}

		if (wminput_set_report_mode()) {
			conf_unload(&conf);
			cwiid_close(wiimote);
			return -1;
		}

		uinput_listen_data.wiimote = wiimote;
		uinput_listen_data.conf = &conf;
		if (pthread_create(&uinput_listen_thread, NULL,
		                   (void *(*)(void *))uinput_listen,
		                   &uinput_listen_data)) {
			wminput_err("error starting uinput listen thread");
			conf_unload(&conf);
			cwiid_close(wiimote);
			return -1;
		}

		if (!quiet) {
			printf("Ready.\n");
		}

		init = 0;

		/* wait */
		sigprocmask(SIG_BLOCK, &sigset, NULL);
		sigwait(&sigset, &signum);
		sigprocmask(SIG_UNBLOCK, &sigset, NULL);

		if ((signum == SIGTERM) || (signum == SIGINT)) {
			reconnect = 0;
		}

		if (pthread_cancel(uinput_listen_thread)) {
			wminput_err("Error canceling uinput listen thread");
			ret = -1;
		}
		else if (pthread_join(uinput_listen_thread, NULL)) {
			wminput_err("Error joining uinput listen thread");
			ret = -1;
		}

		c_wiimote_deinit();
#ifdef HAVE_PYTHON
		py_wiimote_deinit();
#endif

		/* disconnect */
		if (cwiid_close(wiimote)) {
			wminput_err("Error on wiimote disconnect");
			ret = -1;
		}

		if (reconnect && reconnect_wait) {
			sleep(reconnect_wait);
		}
	} while (reconnect);

	if (conf_unload(&conf)) {
		ret = -1;
	}

	c_deinit();
#ifdef HAVE_PYTHON
	py_deinit();
#endif

	if (!quiet) {
		printf("Exiting.\n");
	}

	return ret;
}
int main (int argc, char* argv []) {
  mpi::environment env (argc, argv);
  mpi::communicator world;

  TestMatrixInitializer init;
  std::vector<AbstractMatrixInitializer*> mat_inits(10, & init);
  VacuumCouplingInitializer c_init(& init, 10, world);
  std::vector<AbstractCouplingInitializer*> c_inits(10, & c_init);

  ThreeScatterRHSCollection crc(mat_inits, c_inits, 10, world);

  double test_rhs_storage[100];
  double* test_rhs[10];

  std::fill_n(test_rhs_storage, 100, 0);

  for(int i = 0; i < 10; i++) {
    test_rhs_storage[i*10 + 0] = 1;
    // test_rhs_storage[i*9 + 8] = 1;
    test_rhs[i] = & test_rhs_storage[i*10];
  }

  world.barrier();
  crc.doLines(test_rhs);

  int dummy;
  std::ios::openmode om = (world.rank() == 0) ? std::ios::out : std::ios::app;

  for(unsigned int il=0; il < 10; il++) {
    std::ofstream dump("tdtest.txt", om);
    if (world.rank() != 0)
      world.recv(world.rank()-1, 0, dummy);
    for(int i=0; i < 10; i++) {
      dump << test_rhs[il][i] << " ";
    }
    dump.flush();
    if (world.rank()+1 < world.size()) {
      world.send(world.rank()+1, 0, dummy);
    }
    if(world.rank() == 4) {
      dump << std::endl << std::endl;
      world.send(0, 0, dummy);
    }
    if(world.rank() == 0)
      world.recv(4, 0, dummy);
    om = std::ios::app;
  }

  if(world.rank() == 4) {
    std::ofstream dump("tdtest.txt", std::ios::app);

    double herp[50];
    double d[50];
    double ld[49];
    double ud[49];

    std::fill_n(herp, 50, 0);
    std::fill_n(d, 50, 1);
    std::fill_n(ld, 49, -1.0/3.0);
    std::fill_n(ud, 49, -1.0/3.0);

    for(unsigned int i=0; i < 50; i += 10) {herp[i] = 1; // herp[i+8] = 1;
    }

    dump << "serial solve: " << std::endl;

    int ninety=50; int one=1; int info;
    dgtsv_(& ninety, & one, ud, d, ld, herp, & ninety, & info);

    for(int i = 0; i < 50; i++)
      dump << herp[i] << " ";
    dump << std::endl;
  }
}
Exemplo n.º 17
0
int main(void)
{
unsigned char  buffer[32];
unsigned a;
FILE  *fp = fopen(".CPU","r");
if (!fp)  exit(1);

c_init(BLACK);
c_cursor(C_HIDE);
do
{  
   rewind(fp);
   fread(buffer,1,32,fp);
   fflush(fp);
   c_setcolor(WHITE);
   c_goto(0,0);
   printf(" F=%02x   ", (unsigned)buffer[0]);
   c_setcolor(GREEN);
   printf("A=%02x   B=%02x   C=%0x2   D=%02x   E=%02x   H=%02x   L=%02x",
          (unsigned)buffer[1], (unsigned)buffer[2],
          (unsigned)buffer[3], (unsigned)buffer[4], (unsigned)buffer[5],
          (unsigned)buffer[6], (unsigned)buffer[7] );
   c_setcolor(WHITE);
   c_goto(0,2);
   printf("F'=%02x  ", (unsigned)buffer[8]);
   c_setcolor(GREEN);
   printf("A'=%02x  B'=%02x  C'=%0x2  D'=%02x  E'=%02x  H'=%02x  L'=%02x",
          (unsigned)buffer[9], (unsigned)buffer[10],
          (unsigned)buffer[11], (unsigned)buffer[12], (unsigned)buffer[13],
          (unsigned)buffer[14], (unsigned)buffer[15] );
   c_setcolor(BLUE);
   c_goto(0,4);
   printf("IX=%04x    IY=%04x    ",
          buffer[16]|buffer[17]<<8, buffer[18]|buffer[19]<<8 );
   c_setcolor(YELLOW);
   printf("SP=%04x    PC=%04x",
          buffer[20]|buffer[21]<<8, buffer[22]|buffer[23]<<8 );
   a= buffer[28]|buffer[29]<<8|buffer[30]<<16|buffer[31]<<24;
   c_setcolor(WHITE);
   printf("    T=%u",a);
   c_goto(0,6);
   a= (unsigned)buffer[27];
   c_setcolor(PURPLE);
   printf("I=%02x  ", (unsigned)buffer[24]);
   c_setcolor(GRAY);
   printf("R=%02x  ", (unsigned)buffer[25]);
   c_setcolor(WHITE);
   printf("DATA=%02x  ", (unsigned)buffer[26]);
   c_setcolor(CYAN);
   printf("IFF=(%u)%u%u   ", a&1, a>>1&1, a>>2&1);
   c_setcolor(RED);
   printf("%c   ", (a&8?'H':' ') );
   c_setcolor(PURPLE);
   printf("IM=%u  ", a>>4&3);
   c_setcolor(GRAY);
   printf("IO=%u  ", a>>6&1);
   c_setcolor(BRIGHT);
   printf("INT=%u", a>>7&1 );
   fflush(stdout);
   usleep(200000);
} while(!c_kbhit());
c_shutdown();
return 0;
}
Exemplo n.º 18
0
int
main (int argc, char **argv)
{
	CHandle handle = 0;
	CResult res = C_SUCCESS;

	// Parse the command line
	if(cmdline_parser(argc, argv, &args_info) != 0)
		exit(1);
	
	// Display help if no arguments were specified
	if(argc == 1) {
		cmdline_parser_print_help();
		exit(0);
	}

	res = c_init();
	if(res) goto done;
	
	// Open the device
	if (!args_info.list_given && (!args_info.import_given || args_info.device_given)) {
		handle = c_open_device(args_info.device_arg);
		if(!handle) {
			print_error("Unable to open device", -1);
			res = C_INVALID_DEVICE;
			goto done;
		}
	}

	// List devices
	if(args_info.list_given) {
		res = list_devices();
		goto done;
	}
	// Import dynamic controls from XML file
	else if(args_info.import_given) {
		res = add_control_mappings(handle, args_info.import_arg);
		goto done;
	}
	// Import dynamic controls from XML files at default location
	if(args_info.addctrl_given) {
		// list all xml files at default data/vid dir
		int nf=0;
		char vid[5];
		char pid[5];
		short pid_set = 0;
		if(fnmatch("[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]:[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]", args_info.addctrl_arg, 0))
		{
			if(fnmatch("[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]", args_info.addctrl_arg, 0))
			{
				printf("%s invalid: set at least a valid vid value, :pid is optional\n", args_info.addctrl_arg);
				goto done;
			}
			else
			{
				/*extract vid and reset pid*/
				int c = 0;
				for (c = 0; c < 4; c++)
				{
					vid[c] = args_info.addctrl_arg[c];
					pid[c] = 0;
				}
				vid[4] = '\0';
				pid[4] = '\0';
			}
		}
		else 
		{
			/*extract vid and pid*/
			int c = 0;
			for (c = 0; c < 4; c++)
			{
				vid[c] = args_info.addctrl_arg[c];
				pid[c] = args_info.addctrl_arg[c+5];
			}
			vid[4] = '\0';
			pid[4] = '\0';
			pid_set = 1; /*flag pid.xml check*/
			//printf("vid:%s pid:%s\n", vid, pid);
		}
		
		/* get xml file list from DATA_DIR/vid/ */ 
		char **xml_files = get_filename (DATA_DIR, vid);
 
		/*check for pid.xml*/
		char fname[9];
		strcpy(fname, pid);
		strcat(fname,".xml");
		if(pid_set)
		{
			pid_set = 0; /*reset*/
			nf=0;
			while (xml_files[nf] != NULL)
			{
				if ( strcasecmp(fname, xml_files[nf]) == 0)
					pid_set = 1; /*file exists so flag it*/
				nf++;
			}
		}
		
		/*parse xml files*/
		nf = 0;
		while (xml_files[nf] != NULL)
		{
			/* if pid was set and pid.xml exists parse it*/
			if(pid_set)
			{
				if ((strcasecmp(fname, xml_files[nf]) == 0))
				{
					printf ( "Parsing: %s \n", xml_files[nf]);
					res = add_control_mappings(handle, xml_files[nf]);
				}
			}
			else /* parse all xml files inside vid dir */
			{
				printf ( "Parsing: %s \n", xml_files[nf]);
				res = add_control_mappings(handle, xml_files[nf]);
			}
			free(xml_files[nf]);
			xml_files[nf]=NULL;
			nf++;
		}
		free(xml_files);
		goto done;
	}

	// List frame formats
	if(args_info.formats_given) {
		printf("Listing available frame formats for device %s:\n", args_info.device_arg);
		res = list_frame_formats(handle);
	}
	// List controls
	else if(args_info.clist_given) {
		printf("Listing available controls for device %s:\n", args_info.device_arg);
		res = list_controls(handle);
	}
	// Retrieve control value
	else if(args_info.get_given) {
		CControlValue value;
		
		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.get_arg);
		if(!controlId) {
			res = 1;
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Retrieve the control value
		res = c_get_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to retrieve control value", res);
			goto done;
		}
		printf("%d\n", value.value);
	}
	// Retrieve raw control value
	else if(args_info.get_raw_given) {
		//scan input
		uint16_t unit_id;
		unsigned char selector;
		sscanf(args_info.get_raw_arg, "%hu:%hhu", &unit_id, &selector);
		CControlValue value;
		value.type = CC_TYPE_RAW;
		// the entity is only used for the generating a control name
		//TODO: pass the guid through cmdline (optional)
		unsigned char entity[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
		res = c_read_xu_control(handle, entity, unit_id, selector, &value);
		if(res) {
			print_handle_error(handle, "Unable to retrieve control value", res);
			goto done;
		}
		
		//print the raw value
		uint8_t * val = value.raw.data;
		int i=0;
		printf("query current value of: (LE)0x");
		for(i=0; i<value.raw.size; i++)	{
			printf("%.2x", val[i]);
		}
		printf("  (BE)0x");
		for(i=value.raw.size-1; i >=0; i--) {
			printf("%.2x", val[i]);
		}
		printf("\n");
		//free the raw value alocation
		if(value.raw.data) free(value.raw.data);
	}
	else if(args_info.set_given) {
		CControlValue value;

		// Parse the control value
		if(args_info.inputs_num < 1) {
			res = 3;
			print_error("No control value specified", -1);
			goto done;
		}
		if(parse_control_value(args_info.inputs[0], &value)) {
			res = 2;
			print_error("Invalid control value specified", -1);
			goto done;
		}

		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.set_arg);
		if(!controlId) {
			res = 1;
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Set the new control value
		res = c_set_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to set new control value", res);
			goto done;
		}
	}
	// Set the raw control value
	else if(args_info.set_raw_given) {
		CControlValue value;
		
		// Parse the control value
		if(args_info.inputs_num < 1) {
			res = 3;
			print_error("No raw control value specified", -1);
			goto done;
		}
		uint16_t unit_id;
		unsigned char selector;

		sscanf(args_info.set_raw_arg, "%hu:%hhu", &unit_id, &selector);
		
		parse_raw_control_value (args_info.inputs[0], &value);
		
		// the entity is only used for the generating a control name
		//TODO: pass the guid through cmdline (optional)
		unsigned char entity[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
		res = c_write_xu_control(handle, entity, unit_id, selector, &value);
		if(res) {
			print_handle_error(handle, "Unable to set the control value", res);
			goto done;
		}
		
		//print the raw value le and be format
		uint8_t * val = value.raw.data;
		int i=0;
		printf("set value of          : (LE)0x");
		for(i=0; i<value.raw.size; i++)	{
			printf("%.2x", val[i]);
		}
		printf("  (BE)0x");
		for(i=value.raw.size-1; i >=0; i--) {
			printf("%.2x", val[i]);
		}
		printf("\n");
		//free the raw value alocation
		if(value.raw.data) free(value.raw.data);
	}
	else if(args_info.save_ctrl_given) {
		res = save_controls( handle, args_info.save_ctrl_arg);
	}
	else if(args_info.load_ctrl_given) {
		res = load_controls( handle, args_info.load_ctrl_arg);
	}

	// Clean up
done:
	if(handle) c_close_device(handle);
	c_cleanup();
	cmdline_parser_free(&args_info);

	return res;
}
Exemplo n.º 19
0
Arquivo: main.c Projeto: BotBot/ASV
int
main (int argc, char **argv)
{
	CHandle handle = 0;
	CResult res = C_SUCCESS;

	// Parse the command line
	if(cmdline_parser(argc, argv, &args_info) != 0)
		exit(1);
	
	// Display help if no arguments were specified
	if(argc == 1) {
		cmdline_parser_print_help();
		exit(0);
	}

	res = c_init();
	if(res) goto done;

	// List devices
	if(args_info.list_given) {
		res = list_devices();
		goto done;
	}
	// Import dynamic controls from XML file
	else if(args_info.import_given) {
		res = add_control_mappings(args_info.import_arg);
		goto done;
	}

	// Open the device
	handle = c_open_device(args_info.device_arg);
	if(!handle) {
		print_error("Unable to open device", -1);
		res = C_INVALID_DEVICE;
		goto done;
	}

	// List frame formats
	if(args_info.formats_given) {
		printf("Listing available frame formats for device %s:\n", args_info.device_arg);
		res = list_frame_formats(handle);
	}
	// List controls
	else if(args_info.clist_given) {
		printf("Listing available controls for device %s:\n", args_info.device_arg);
		res = list_controls(handle);
	}
	// Retrieve control value
	else if(args_info.get_given) {
		CControlValue value;
		
		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.get_arg);
		if(!controlId) {
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Retrieve the control value
		res = c_get_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to retrieve control value", res);
			goto done;
		}
		printf("%d\n", value.value);
	}
	else if(args_info.set_given) {
		CControlValue value;

		// Parse the control value
		if(args_info.inputs_num < 1) {
			print_error("No control value specified", -1);
			goto done;
		}
		if(parse_control_value(args_info.inputs[0], &value)) {
			print_error("Invalid control value specified", -1);
			goto done;
		}

		// Resolve the control Id
		CControlId controlId = get_control_id(handle, args_info.set_arg);
		if(!controlId) {
			print_handle_error(handle, "Unknown control specified", -1);
			goto done;
		}

		// Set the new control value
		res = c_set_control(handle, controlId, &value);
		if(res) {
			print_handle_error(handle, "Unable to set new control value", res);
			goto done;
		}
	}

	// Clean up
done:
	if(handle) c_close_device(handle);
	c_cleanup();
	cmdline_parser_free(&args_info);

	return res;
}