Exemplo n.º 1
0
static void cb_got_dev_info(struct libusb_transfer *transfer)
{
	struct aura_node *node = transfer->user_data;
	struct usb_dev_info *inf = aura_get_transportdata(node);
	struct usb_info_packet *pck; 
	int newbufsize; 
	char *tmp; 

	check_control(transfer);
	slog(4, SLOG_DEBUG, "usb: Got info packet from device");

	if (transfer->actual_length < sizeof(struct usb_info_packet)) { 
		slog(0, SLOG_ERROR, "usb: short-read on info packet want %d got %d  (API mismatch?)",
		     sizeof(struct usb_info_packet), transfer->actual_length);
		usb_panic_and_reset_state(node);
		return; 
	}

	pck = (struct usb_info_packet *)libusb_control_transfer_get_data(transfer);	
	aura_set_node_endian(node, usbdev_is_be(pck) ? 
			     AURA_ENDIAN_BIG : AURA_ENDIAN_LITTLE);

	newbufsize = pck->io_buf_size + LIBUSB_CONTROL_SETUP_SIZE;
	inf->num_objects = pck->num_objs;

	if (newbufsize > inf->io_buf_size) { 
		slog(4, SLOG_DEBUG, "usb: adjusting control buffer size: %d->%d bytes", 
		     inf->io_buf_size, newbufsize);
		tmp = realloc(inf->ctrlbuf, newbufsize);
		if (!tmp) { 
			slog(0, SLOG_ERROR, "Allocation error while adjusting control buffer size");
			aura_panic(node);
		}
		inf->io_buf_size = newbufsize;
		inf->ctrlbuf = (unsigned char *)tmp;
	}
	slog(4, SLOG_DEBUG, "usb: Device has %d objects, now running discovery", inf->num_objects);
	inf->etbl = aura_etable_create(node, inf->num_objects);
	if (!inf->etbl) 
	{
		slog(0, SLOG_ERROR, "usb: etable creation failed");
		aura_panic(node);
	}

	inf->current_object = 0; 
	request_object(node, inf->current_object++);
}
Exemplo n.º 2
0
static int gpio_open(struct aura_node *node, const char *opts)
{
	slog(0, SLOG_INFO, "Opening sysfs/gpio transport");
	struct aura_export_table *etbl = aura_etable_create(node, 16);
	if (!etbl)
		BUG(node, "Failed to create etable");
	aura_etable_add(etbl, "write", "33", "");
	aura_etable_add(etbl, "read", "3", "3");
	aura_etable_add(etbl, "out", "3", "");
	aura_etable_add(etbl, "in", "3", "");
	aura_etable_add(etbl, "export", "3", "3");
	aura_etable_add(etbl, "watch", "3", "");
	//Change notification
	aura_etable_add(etbl, "gpio_changed", NULL, "333");
	aura_etable_activate(etbl);
	aura_set_status(node, AURA_STATUS_ONLINE);
	slog(0, SLOG_INFO, "Opened sysfs/gpio transport");
	return 0;
}
Exemplo n.º 3
0
static int l_etable_create(lua_State *L)
{
	struct aura_node *node;
	int count = 0;
	struct aura_export_table *tbl;

	TRACE();
	aura_check_args(L, 2);
	if (!lua_islightuserdata(L, 1))
		aura_typeerror(L, 1, "ludata");
	if (!lua_isnumber(L, 2))
		aura_typeerror(L, 1, "number");

	node = lua_touserdata(L, 1);
	count = lua_tonumber(L, 2);
	tbl = aura_etable_create(node, count);
	if (!tbl)
		return luaL_error(L, "error creating etable for %d elements", count);

	lua_pushlightuserdata(L, tbl);
	return 1;
}