コード例 #1
0
ファイル: usb.c プロジェクト: mejedi/Gphoto2.framework
int digita_usb_open(CameraPrivateLibrary *dev, Camera *camera)
{
	GPPortSettings settings;
	unsigned char buffer[128];
	int ret;

	ret = gp_port_get_settings(camera->port, &settings);
	if (ret < 0)
		return ret;

	/* We'll take the defaults. The core should have the done what's */
	/* necessary to find the config, interface, altsetting and endpoints */

	ret = gp_port_set_settings(dev->gpdev, settings);
	if (ret < 0)
		return ret;

	dev->send = digita_usb_send;
	dev->read = digita_usb_read;

	gp_port_set_timeout(camera->port, 100);

	/* Mop up anything still pending */
	while (gp_port_read(dev->gpdev, buffer, sizeof(buffer)) > 0)
		;

	gp_port_set_timeout(camera->port, 10000);

	return GP_OK;
}
コード例 #2
0
ファイル: ultrapocket.c プロジェクト: AleksKolkov/libgphoto2
static int
ultrapocket_skip(GPPort *port, int npackets)
{
   int old_timeout = 200;
   unsigned char retbuf[0x1000];

   gp_port_get_timeout(port, &old_timeout);
   gp_port_set_timeout(port, 100);
   for (; (npackets > 0) && gp_port_read(port, (char *)retbuf, 0x1000); npackets--);
   gp_port_set_timeout(port, old_timeout);
   return GP_OK;
}
コード例 #3
0
ファイル: mdc800.c プロジェクト: CastorGemini/libgphoto2
int
camera_init (Camera *camera, GPContext *context)
{
        /* First, set up all the function pointers */
        /* camera->functions->exit                 = camera_exit; */
        camera->functions->get_config		= camera_config_get;
        camera->functions->set_config		= camera_config_set;
        camera->functions->capture              = camera_capture;
        camera->functions->summary              = camera_summary;
        camera->functions->manual               = camera_manual;
        camera->functions->about                = camera_about;

	/* Now, tell the filesystem where to get lists, files and info */
	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

	/* Configure port */
	gp_port_set_timeout(camera->port,MDC800_DEFAULT_COMMAND_RETRY_DELAY);
	if (camera->port->type == GP_PORT_SERIAL) {
	    GPPortSettings settings;
	    gp_port_get_settings(camera->port, &settings);
	    settings.serial.speed   = 57600;
	    settings.serial.bits    = 8;
	    settings.serial.parity  = 0;
	    settings.serial.stopbits= 1;
	    gp_port_set_settings(camera->port, settings);
	}
	return mdc800_openCamera(camera);
}
コード例 #4
0
ファイル: library.c プロジェクト: rajbot/gphoto
/*
 * OK, lets get serious !
 */
int 
camera_init(Camera *camera,GPContext *context)
{
 GPPortSettings settings;
 CameraAbilities abilities;
 /* try to contact the camera ...*/
 /*CR(gp_port_get_settings(camera->port,&settings));*/
 
 camera->functions->about=camera_about; 
 camera->functions->exit=camera_exit;
 gp_port_get_settings(camera->port,&settings);
 if (camera->port->type!=GP_PORT_USB)
 {
  gp_context_error(context,_("sx330z is USB only"));
  return(GP_ERROR_UNKNOWN_PORT);
 }
/* GP_DEBUG("camera_init : in = %x",camera->port->settings.usb.inep);*/
 CR(gp_port_set_settings(camera->port,settings));
 CR(gp_port_set_timeout(camera->port,TIMEOUT)); 

 CR(gp_filesystem_set_funcs(camera->fs, &fsfuncs, camera));
 
 camera->pl=malloc(sizeof(CameraPrivateLibrary));
 if (!camera->pl) 
   return(GP_ERROR_NO_MEMORY);

 CR(gp_camera_get_abilities(camera, &abilities));
 camera->pl->usb_product=abilities.usb_product; /* some models differ in Thumbnail size */
/* GP_DEBUG("sx330z Camera_init : sx init %04x",camera->pl->usb_product); */
 return(sx330z_init(camera,context));

} /* camera init */
コード例 #5
0
ファイル: puppy.c プロジェクト: nazgul77/libgphoto2
int
camera_init (Camera *camera, GPContext *context) 
{
	char *curloc;
	/* First, set up all the function pointers */
	camera->functions->get_config	= camera_config_get;
	camera->functions->set_config	= camera_config_set;
	camera->functions->summary	= camera_summary;
	camera->functions->about	= camera_about;
	camera->functions->exit		= camera_exit;

	/* Now, tell the filesystem where to get lists, files and info */
	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

	gp_port_set_timeout (camera->port, TF_PROTOCOL_TIMEOUT);
	gp_port_usb_clear_halt (camera->port, GP_PORT_USB_ENDPOINT_IN);

	camera->pl = calloc (sizeof (CameraPrivateLibrary),1);
	if (!camera->pl) return GP_ERROR_NO_MEMORY;

#if defined(HAVE_ICONV) && defined(HAVE_LANGINFO_H)
	curloc = nl_langinfo (CODESET);
	if (!curloc) curloc="UTF-8";
	cd_latin1_to_locale = iconv_open(curloc, "iso-8859-1");
	if (!cd_latin1_to_locale) return GP_ERROR_NO_MEMORY;
	cd_locale_to_latin1 = iconv_open("iso-8859-1", curloc);
	if (!cd_locale_to_latin1) return GP_ERROR_NO_MEMORY;
#endif

	do_cmd_ready (camera, context);
	return GP_OK;
}
コード例 #6
0
ファイル: stv0680.c プロジェクト: JohnChu/Snoopy
int camera_init (Camera *camera, GPContext *context) 
{
	GPPortSettings settings;

        /* First, set up all the function pointers */
        camera->functions->summary              = camera_summary;
        camera->functions->about                = camera_about;
	camera->functions->capture_preview	= camera_capture_preview;
	camera->functions->capture		= camera_capture;

	gp_port_get_settings(camera->port, &settings);
	switch(camera->port->type) {
	case GP_PORT_SERIAL:		
        	gp_port_set_timeout(camera->port, 1000);
		settings.serial.speed = 115200;
        	settings.serial.bits = 8;
        	settings.serial.parity = 0;
        	settings.serial.stopbits = 1;
		break;
	case GP_PORT_USB:
		/* Use the defaults the core parsed */
		break;
	default:
		return (GP_ERROR_UNKNOWN_PORT);
		break;
	}
	gp_port_set_settings(camera->port, settings);

	/* Set up the filesystem */
	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

        /* test camera */
        return stv0680_ping(camera->port);
}
コード例 #7
0
ファイル: usb.c プロジェクト: ryanstout/libgphoto2
/*
 * Waits for the camera 
 * type: 0:  Wait until the camera gets ready
 *       1:  Read data from irq
 * The function stores the readen 8 Bytes in data.
 * and return 0 on success else -1.
 */
static int mdc800_usb_readFromIrq (GPPort *port,int type,unsigned char* data,int timeout)
{
	int ret;
	struct timeval tv;

	gp_port_set_timeout(port,1);
	timeout+=10*MDC800_USB_IRQ_INTERVAL;
	gettimeofday(&tv,NULL);
	while (timeout>=0)
	{
		/* try a read */
		ret = gp_port_check_int(port,(char*)data,8);
		if (ret!=8)
		{
			printCError ("(mdc800_usb_readFromIRQ) reading bytes from irq fails (%d)\n",ret);
			return ret;
		}
		if (0) {
			int i=0;
			printf ("irq :");
			for (i=0; i<8; i++)
			{
				printf ("%i ", data [i]);
			}
			printf ("\n");
		}
		/* check data */
		if (type)
		{
			if (!(mdc800_usb_isReady(data)||mdc800_usb_isBusy(data))) {
			    fprintf(stderr,"got data.\n");
				/* Data received successfull */
				return GP_OK;
			}
		} else {
			if (mdc800_usb_isReady (data))
			{
			    fprintf(stderr,"got readiness.\n");
				/* Camera response ready */
				return GP_OK;
			}
		}
		/* wait the specified time */
		if (1) {

		    usleep(MDC800_USB_IRQ_INTERVAL * 1000);

		    timeout-=MDC800_USB_IRQ_INTERVAL;
		}
	}
	/* Timeout */
	printCError ("(mdc800_usb_readFromIrq) timeout\n");
	return GP_ERROR_IO;
}
コード例 #8
0
ファイル: library.c プロジェクト: CastorGemini/libgphoto2
int
camera_init (Camera *camera, GPContext *context)
{
	int ret;
	GPPortSettings settings;

	/* First, set up all the function pointers */
	camera->functions->exit = camera_exit;
	camera->functions->summary = camera_summary;
	camera->functions->about = camera_about;

	CHECK (gp_port_get_settings (camera->port, &settings));
	switch (camera->port->type) {
		case GP_PORT_USB:
			settings.usb.inep = 0x82;
			settings.usb.outep = 0x03;
			settings.usb.config = 1;
			settings.usb.interface = 0;
			settings.usb.altsetting = 0;

			CHECK (gp_port_set_settings (camera->port, settings));
			CHECK (gp_port_set_timeout (camera->port, TIMEOUT));

			break;
		default:
			gp_context_error (context,
					  _("Unsupported port type: %d. "
					    "This driver only works with USB "
					    "cameras.\n"), camera->port->type);
			return (GP_ERROR);
			break;
	}

	camera->pl = malloc (sizeof (CameraPrivateLibrary));
	if (!camera->pl)
		return (GP_ERROR_NO_MEMORY);
	memset (camera->pl, 0, sizeof (CameraPrivateLibrary));
	camera->pl->gpdev = camera->port;
	camera->pl->dirty = 1;

	ret = gsmart300_reset (camera->pl);

	if (ret < 0) {
		gp_context_error (context, _("Could not reset camera.\n"));
		free (camera->pl);
		camera->pl = NULL;

		return (ret);
	}
	/* Set up the CameraFilesystem */
	return gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
}
コード例 #9
0
ファイル: library.c プロジェクト: rajbot/gphoto
int
camera_init (Camera *camera, GPContext *context)
{
	GPPortSettings settings;
	unsigned int i;

	/* Setup all function pointers */
	camera->functions->pre_func   = pre_func;
	camera->functions->post_func  = post_func;
	camera->functions->about      = camera_about;
	camera->functions->exit       = camera_exit;
	camera->functions->get_config = camera_get_config;
	camera->functions->set_config = camera_set_config;
	camera->functions->summary    = camera_summary;

	/* We need to store some data */
	camera->pl = malloc (sizeof (CameraPrivateLibrary));
	if (!camera->pl)
		return (GP_ERROR_NO_MEMORY);
	memset (camera->pl, 0, sizeof (CameraPrivateLibrary));

	/* Set up the port, but remember the current speed. */
	CR (gp_port_set_timeout (camera->port, 1000));
	CR (gp_port_get_settings (camera->port, &settings));
	camera->pl->speed = settings.serial.speed;
	settings.serial.speed    = 9600;
	settings.serial.bits     = 8;
	settings.serial.parity   = GP_PORT_SERIAL_PARITY_EVEN;
	settings.serial.stopbits = 1;
	CR (gp_port_set_settings (camera->port, settings));

	/* Set up the filesystem. */
	CR (gp_filesystem_set_funcs   (camera->fs, &fsfuncs, camera));

	/* Initialize the connection */
	CR (pre_func (camera, context));
	/*
	 * What commands does this camera support? The question is not
	 * easy to answer, as "One issue the DS7 has is that the 
	 * supported command list command is not supported" 
	 * (Matt Martin <*****@*****.**>).
	 */
	if (fuji_get_cmds (camera, camera->pl->cmds, context) >= 0) {
		GP_DEBUG ("Your camera supports the following command(s):");
		for (i = 0; i < 0xff; i++)
			if (camera->pl->cmds[i])
				GP_DEBUG (" - 0x%02x: '%s'", i,
					  cmd_get_name (i));
	}

	return (GP_OK);
}
コード例 #10
0
ファイル: rs232.c プロジェクト: CastorGemini/libgphoto2
/*
 * receive Bytes from camera
 */
int mdc800_rs232_receive (GPPort *port,unsigned char* buffer, int b)
{
	int ret;
	gp_port_set_timeout (port,MDC800_DEFAULT_TIMEOUT );

	ret=gp_port_read(port,(char*)buffer,b);
	if (ret!=b)
	{
		printCError ("(mdc800_rs232_receive) can't read %i Bytes !\n",b);
		return GP_ERROR_IO;
	}
	return GP_OK;
}
コード例 #11
0
ファイル: rs232.c プロジェクト: CastorGemini/libgphoto2
/*
 * downloads data from camera and send
 * a checksum every 512 bytes.
 */
int mdc800_rs232_download (GPPort *port,unsigned char* buffer, int size)
{
	int readen=0,i,j;
	unsigned char checksum;
	unsigned char DSC_checksum;
	int numtries=0;

	gp_port_set_timeout(port, MDC800_DEFAULT_TIMEOUT );

	while (readen < size)
	{
		if (!mdc800_rs232_receive (port,&buffer[readen],512))
			return readen;
		checksum=0;
		for (i=0; i<512; i++)
			checksum=(checksum+buffer[readen+i])%256;
		if (gp_port_write (port,(char*) &checksum,1) < GP_OK)
			return readen;

		if (!mdc800_rs232_receive (port,&DSC_checksum,1))
			return readen;


		if (checksum != DSC_checksum)
		{
			numtries++;
			printCError ("(mdc800_rs232_download) checksum: software %i, DSC %i , reload block! (%i) \n",checksum,DSC_checksum,numtries);
			if (numtries > 10)
			{
				printCError ("(mdc800_rs232_download) to many retries, giving up..");
				return 0;
			}
		}
		else
		{
			readen+=512;
			numtries=0;
		}
	}


	for (i=0; i<4; i++)
	{
		printCError ("%i: ",i);
		for (j=0; j<8; j++)
			printCError (" %i", buffer[i*8+j]);
		printCError ("\n");
	}
	return readen;
}
コード例 #12
0
ファイル: lowlevel.c プロジェクト: CastorGemini/libgphoto2
int 
l_init (GPPort *p, GPContext *c)
{
	unsigned int i;
	int result = GP_OK;
	CHECK_NULL (p);

	CHECK (gp_port_set_timeout (p, DEFAULT_TIMEOUT));
	for (i = 0; i < 3; i++) {
		result = l_ping (p, c);
		if (result != GP_ERROR_TIMEOUT)
			break;
	}
	return (result);
}
コード例 #13
0
ファイル: lowlevel.c プロジェクト: pinkavaj/gphoto2
int
l_init (GPPort *p, GPFsErr *c)
{
    unsigned int i;
    int result = 0;
    CHECK_NULL (p);

    CHECK (gp_port_set_timeout (p, DEFAULT_TIMEOUT));
    for (i = 0; i < 3; i++) {
        result = l_ping (p, c);
        if (result != -1)
            break;
    }
    return (result);
}
コード例 #14
0
ファイル: dc3200.c プロジェクト: rajbot/gphoto
static
int init(Camera *camera)
{
	GPPortSettings settings;
	int ret, selected_speed;

	ret = gp_port_get_settings (camera->port, &settings);
	if (ret < 0)
		return (ret);

	/* Remember the selected speed 0 == fastest */
	selected_speed = settings.serial.speed == 0 ? 115200 : settings.serial.speed;

	settings.serial.speed    = 9600;
	settings.serial.bits     = 8;
	settings.serial.parity   = 0;
	settings.serial.stopbits = 1;

	ret = gp_port_set_settings (camera->port, settings);
	if (ret < 0)
		return (ret);

	gp_port_set_timeout (camera->port, TIMEOUT);

	if (dc3200_set_speed (camera, selected_speed) == GP_ERROR)
		return GP_ERROR;

	/* Set the new speed */
	settings.serial.speed = selected_speed;
	ret = gp_port_set_settings (camera->port, settings);
	if (ret < 0)
		return (ret);

	/* Wait for it to update */
	sleep(1);

	/* Try to talk after speed change */
	if (dc3200_keep_alive(camera) == GP_ERROR)
		return GP_ERROR;

	/* setup the camera */
	if (dc3200_setup(camera) == GP_ERROR)
		return GP_ERROR;		

	return GP_OK;
}
コード例 #15
0
ファイル: mesalib.c プロジェクト: CastorGemini/libgphoto2
/* Open the serial port and configure it */
int
mesa_port_open( GPPort *port )
{
	GPPortSettings settings;

	debuglog("mesa_port_open()");
	gp_port_set_timeout(port, 5000);

	gp_port_get_settings(port, &settings);

	settings.serial.speed   = 115200;
	settings.serial.bits    = 8;
	settings.serial.parity  = 0;
	settings.serial.stopbits= 1;

	return gp_port_set_settings(port, settings);
}
コード例 #16
0
ファイル: pdrm11.c プロジェクト: AleksKolkov/libgphoto2
int pdrm11_init(GPPort *port)
{
	unsigned char buf[20];
	int timeout = 50;
	
	gp_port_set_timeout(port,1000);

	/* exactly what windows driver does */
	gp_port_usb_msg_read (port, 0x01, PDRM11_CMD_READY, 0, (char *)buf, 4);
	gp_port_usb_msg_write(port, 0x01, PDRM11_CMD_PING3, 0, NULL, 0);
	gp_port_usb_msg_read (port, 0x01, PDRM11_CMD_READY, 0, (char *)buf, 4);
	gp_port_usb_msg_write(port, 0x01, PDRM11_CMD_INIT1, 0, NULL, 0);
	gp_port_usb_msg_read (port, 0x01, PDRM11_CMD_READY, 0, (char *)buf, 4);
	gp_port_usb_msg_write(port, 0x01, PDRM11_CMD_INIT2, 0, NULL, 0);
	gp_port_usb_msg_read (port, 0x01, PDRM11_CMD_READY, 0, (char *)buf, 4);

	gp_port_usb_msg_read (port, 0x01, PDRM11_CMD_ZERO, 0, (char *)buf, 2);
	if(buf[0] || buf[1]) {
		/* I haven't seen anything other than 00 00 yet
		 * unless the connection is bad */
		GP_DEBUG("PDRM11_CMD_ZERO: %x %x", buf[0], buf[1]);
		return(GP_ERROR);
	}
		

	/* wait til the camera is ready */
	do {
		usleep(200000);
		GP_DEBUG("waiting...");

		timeout--;
		if( gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_READY, 0, (char *)buf, 4) == -ETIMEDOUT )
			timeout = 0;
	} while( !((buf[3] == 0x25) && (buf[0] == 1)) && timeout );
	
	/* what good is this? */
	usleep(400000);

	if(!timeout)
		return(GP_ERROR_TIMEOUT);
	else
		return(GP_OK);
}
コード例 #17
0
ファイル: jamcam.c プロジェクト: CastorGemini/libgphoto2
int camera_init (Camera *camera, GPContext *context)
{
	int count;
	GPPortSettings settings;

	GP_DEBUG ("* camera_init");
	GP_DEBUG ("   * jamcam library for Gphoto2 by Chris Pinkham <*****@*****.**>");
	GP_DEBUG ("   * jamcam library v%s, %s", JAMCAM_VERSION, JAMCAM_LAST_MOD );

	/* First, set up all the function pointers */
	camera->functions->exit 	= camera_exit;
	camera->functions->summary	= camera_summary;
	camera->functions->about 	= camera_about;

	CHECK (gp_port_get_settings (camera->port, &settings));
	switch( camera->port->type ) {
	case GP_PORT_SERIAL:
		settings.serial.speed 	 = 57600;
		settings.serial.bits 	 = 8;
		settings.serial.parity 	 = 0;
		settings.serial.stopbits = 1;
		break;
	case GP_PORT_USB:
		/* Use the defaults the core parsed */
		break;
	default:
		fprintf( stderr, "Unknown port type: %d\n", camera->port->type );
		return ( GP_ERROR );
		break;
	}
	CHECK (gp_port_set_settings (camera->port, settings));
	CHECK (gp_port_set_timeout (camera->port, TIMEOUT));

	/* check to see if camera is really there */
	CHECK (jamcam_enq (camera));

	/* get number of images */
	CHECK (count = jamcam_file_count (camera));

	/* Set up the CameraFilesystem */
	return gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
}
コード例 #18
0
ファイル: enigma13.c プロジェクト: nazgul77/libgphoto2
int
camera_init (Camera *camera, GPContext *context) 
{
	GPPortSettings settings;

        camera->functions->about        = enigma13_about;

	CHECK(gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera));
	CHECK(gp_port_get_settings( camera->port, &settings));
        settings.usb.inep = 0x82;
        settings.usb.outep = 0x03;
        settings.usb.config = 1;
        settings.usb.interface = 0;
        settings.usb.altsetting = 0;
        CHECK(gp_port_set_timeout (camera->port, ENIGMA13_USB_TIMEOUT_MS));
	CHECK(gp_port_set_settings( camera->port, settings));
	return GP_OK;


}
コード例 #19
0
ファイル: rs232.c プロジェクト: CastorGemini/libgphoto2
/*
 * waits for the Commit value
 * The function expects the commandid of the corresponding command
 * to determine whether a long timeout is needed or not. (Take Photo)
 */
int mdc800_rs232_waitForCommit (GPPort *port,char commandid)
{
	unsigned char ch[1];
	int ret;

	gp_port_set_timeout(port,mdc800_io_getCommandTimeout(commandid));
	ret = gp_port_read(port,ch,1);
	if (ret!=1)
	{
		printCError ("(mdc800_rs232_waitForCommit) Error receiving commit !\n");
		return GP_ERROR_IO;
	}

	if (ch[0] != ANSWER_COMMIT )
	{
		printCError ("(mdc800_rs232_waitForCommit) Byte \"%i\" was not the commit !\n",ch[0]);
		return GP_ERROR_IO;
	}
	return GP_OK;
}
コード例 #20
0
ファイル: dc120.c プロジェクト: Dvizhenka/libgphoto2
int camera_init (Camera *camera, GPContext *context) {

        GPPortSettings settings;
	int speed;

        /* First, set up all the function pointers */
	camera->functions->capture 	= camera_capture;
	camera->functions->summary 	= camera_summary;
        camera->functions->manual       = camera_manual;
        camera->functions->about        = camera_about;

	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

	/* Configure the port (remember the speed) */
	gp_port_get_settings (camera->port, &settings);
	speed = settings.serial.speed;
        settings.serial.speed    = 9600;
        settings.serial.bits     = 8;
        settings.serial.parity   = 0;
        settings.serial.stopbits = 1;
        gp_port_set_settings (camera->port, settings);
        gp_port_set_timeout (camera->port, TIMEOUT);

        /* Reset the camera to 9600 */
        gp_port_send_break (camera->port, 2);

        /* Wait for it to update */
        GP_SYSTEM_SLEEP(1500);

	if (dc120_set_speed (camera, speed) == GP_ERROR) {
                return (GP_ERROR);
        }

        /* Try to talk after speed change */
        if (dc120_get_status(camera, NULL, context) == GP_ERROR) {
                return (GP_ERROR);
        }

        return (GP_OK);
}
コード例 #21
0
ファイル: samsung.c プロジェクト: CastorGemini/libgphoto2
int
camera_init (Camera *camera, GPContext *context) 
{
	GPPortSettings settings;

        /* First, set up all the function pointers */
        camera->functions->about                = camera_about;

	/* Now, tell the filesystem where to get lists and info */
	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

	/* Some settings */
	CHECK_RESULT (gp_port_get_settings (camera->port, &settings));
	settings.serial.speed   = 115200;
	settings.serial.bits    = 8;
	settings.serial.parity  = 0;
	settings.serial.stopbits= 1;
	CHECK_RESULT (gp_port_set_settings (camera->port, settings));
	CHECK_RESULT (gp_port_set_timeout (camera->port, SDSC_TIMEOUT));
	/* Open the port and check if the camera is there */
	CHECK_RESULT (SDSC_initialize (camera->port));
	return (GP_OK);
}
コード例 #22
0
ファイル: l859.c プロジェクト: CastorGemini/libgphoto2
int camera_init (Camera *camera, GPContext *context) {

        int ret;
	GPPortSettings settings;

        /* First, set up all the function pointers */
        camera->functions->exit    = camera_exit;
        camera->functions->summary = camera_summary;
        camera->functions->manual  = camera_manual;
	camera->functions->about   = camera_about;

	/* Allocate memory for a read/write buffer */
	camera->pl = malloc (sizeof (CameraPrivateLibrary));
	if (!camera->pl)
		return (GP_ERROR_NO_MEMORY);

        gp_port_set_timeout (camera->port, 2000);
	gp_port_get_settings(camera->port, &settings);
	camera->pl->speed = settings.serial.speed;
	settings.serial.speed      = 9600; /* hand shake speed */
	settings.serial.bits       = 8;
	settings.serial.parity     = 0;
	settings.serial.stopbits   = 1;
        gp_port_set_settings(camera->port, settings);

	/* Set up the filesystem */
	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);

        ret = l859_connect (camera);
	if (ret < 0) {
		free (camera->pl);
		camera->pl = NULL;
	}

	return (ret);
}
コード例 #23
0
ファイル: pdrm11.c プロジェクト: AleksKolkov/libgphoto2
int pdrm11_get_filenames(GPPort *port, CameraList *list)
{
	int i, j;
	uint32_t numPics;
	char name[20];
	char buf[30];


	gp_port_set_timeout(port, 10000);
	CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_NUMPICS, 0, buf, 10));
	/* trying to remain endian friendly */
	numPics = le16atoh(&buf[2]) + (le16atoh(&buf[0]) * 1024);
	GP_DEBUG("found %d pictures", numPics);

	

	for(i=1;  i<numPics+1;  i++) {
		CHECK( pdrm11_select_file(port, i) );

		CHECK(gp_port_usb_msg_read(port, 0x01, 0xe600, i, buf, 14));

		/* the filename is 12 chars starting at the third byte */
		CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_FILENAME, i, buf, 26));
		for(j=0; j<12; j+=2) {
			name[j] = buf[j+2+1];
			name[j+1] = buf[j+2];
		}
		name[12] = '\0';

		GP_DEBUG("%s",name);
		gp_list_append(list, name, NULL);
	}


	return(GP_OK);
}
コード例 #24
0
ファイル: gphoto2-port.c プロジェクト: Dvizhenka/libgphoto2
int gp_port_timeout_set (GPPort *port, int timeout)
{
	return (gp_port_set_timeout (port, timeout));
}
コード例 #25
0
ファイル: gphoto2-port.c プロジェクト: Dvizhenka/libgphoto2
/**
 * \brief Configure a port
 *
 * Makes a port functional by passing in the necessary path
 * information (from the serial:/dev/ttyS0 or similar variables).
 * After calling this function, you can access the port using for
 * example gp_port_open().
 * 
 * \param port a GPPort
 * \param info the GPPortInfo to set
 *
 * \return a gphoto2 error code
 **/
int
gp_port_set_info (GPPort *port, GPPortInfo info)
{
	GPPortLibraryOperations ops_func;

	CHECK_NULL (port);

	if (port->pc->info.name) free (port->pc->info.name);
	port->pc->info.name = strdup (info->name);
	if (port->pc->info.path) free (port->pc->info.path);
	port->pc->info.path = strdup (info->path);
	port->pc->info.type = info->type;
	if (port->pc->info.library_filename) free (port->pc->info.library_filename);
	port->pc->info.library_filename = strdup (info->library_filename);

	port->type = info->type;

	/* Clean up */
	if (port->pc->ops) {
		gp_port_exit (port);
		free (port->pc->ops);
		port->pc->ops = NULL;
	}
	if (port->pc->lh) {
		lt_dlclose (port->pc->lh);
		lt_dlexit ();
	}

	lt_dlinit ();
	port->pc->lh = lt_dlopenext (info->library_filename);
	if (!port->pc->lh) {
		gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not load "
			"'%s' ('%s')."), info->library_filename,
			lt_dlerror ());
		lt_dlexit ();
		return (GP_ERROR_LIBRARY);
	}

	/* Load the operations */
	ops_func = lt_dlsym (port->pc->lh, "gp_port_library_operations");
	if (!ops_func) {
		gp_log (GP_LOG_ERROR, "gphoto2-port", _("Could not find "
			"'gp_port_library_operations' in '%s' ('%s')"),
			info->library_filename, lt_dlerror ());
		lt_dlclose (port->pc->lh);
		lt_dlexit ();
		port->pc->lh = NULL;
		return (GP_ERROR_LIBRARY);
	}
	port->pc->ops = ops_func ();
	gp_port_init (port);

	/* Initialize the settings to some default ones */
	switch (info->type) {
	case GP_PORT_SERIAL:
		port->settings.serial.speed = 0;
		port->settings.serial.bits = 8;
		port->settings.serial.parity = 0;
		port->settings.serial.stopbits = 1;
		gp_port_set_timeout (port, 500);
		break;
	case GP_PORT_USB:
		strncpy (port->settings.usb.port, info->path,
			 sizeof (port->settings.usb.port));
		port->settings.usb.inep = -1;
		port->settings.usb.outep = -1;
		port->settings.usb.config = -1;
		port->settings.usb.interface = 0;
		port->settings.usb.altsetting = -1;
		gp_port_set_timeout (port, 5000);
		break;
	case GP_PORT_USB_DISK_DIRECT:
		snprintf(port->settings.usbdiskdirect.path,
			 sizeof(port->settings.usbdiskdirect.path), "%s",
			 strchr(info->path, ':') + 1);
		break;
	case GP_PORT_USB_SCSI:
		snprintf(port->settings.usbscsi.path,
			 sizeof(port->settings.usbscsi.path), "%s",
			 strchr(info->path, ':') + 1);
		break;
	default:
		/* Nothing in here */
		break;
	}
	gp_port_set_settings (port, port->settings);

	return (GP_OK);
}
コード例 #26
0
ファイル: pdrm11.c プロジェクト: AleksKolkov/libgphoto2
int pdrm11_get_file(CameraFilesystem *fs, const char *filename, CameraFileType type, 
			CameraFile *file, GPPort *port, uint16_t picNum)
{
	uint32_t size = 0;
	uint16_t thumbsize = 0;
	uint8_t buf[30];
	uint8_t *image;
	uint8_t temp;
	int i;
	int ret;
	int file_type;

		
	gp_port_set_timeout(port,10000);
	CHECK( pdrm11_select_file(port, picNum) );

	if(type == GP_FILE_TYPE_PREVIEW) {
		CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_INFO, picNum, (char *)buf, 8));
		file_type = buf[4];

		CHECK( gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_THUMBSIZE, picNum, (char *)buf, 14) );
		thumbsize = le16atoh( &buf[8] );
		
		/* add 1 to file size only for jpeg thumbnails */
		if(file_type == 1) { 
			GP_DEBUG("thumbnail file_type: %s.", "jpeg");
			size = (uint32_t)thumbsize + 1;
		} else if(file_type == 2) {
			/* NOTE: tiff thumbnails are 160x120 pixel 8bpc rgb images, NOT jpegs... */
			GP_DEBUG("thumbnail file_type: %s.", "tiff");
			size = (uint32_t)thumbsize;
		} else {
			GP_DEBUG("Unknown thumbnail file format!");
			return(GP_ERROR_NOT_SUPPORTED);
		}

	} else if(type == GP_FILE_TYPE_NORMAL) {
		CHECK( gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_FILESIZE, picNum, (char *)buf, 26) );
		size = le32atoh( &buf[18] );
	} else {
		GP_DEBUG("Unsupported file type!");
		return(GP_ERROR_NOT_SUPPORTED);
	}

	GP_DEBUG("size: %d 0x%x", size, size);

	image = malloc(sizeof(char)*size);
	if(!image)
		return(GP_ERROR_NO_MEMORY);



	if(type == GP_FILE_TYPE_PREVIEW) {
		CHECK_AND_FREE( gp_port_usb_msg_write(port, 0x01, PDRM11_CMD_GET_THUMB, picNum, NULL, 0), image );
	} else {
		CHECK_AND_FREE( gp_port_usb_msg_write(port, 0x01, PDRM11_CMD_GET_PIC, picNum, NULL, 0), image );
	}

	ret = gp_port_read(port, (char *)image, size);
	if(ret != size) {
		GP_DEBUG("failed to read from port.  Giving it one more try...");
		ret = gp_port_read(port, (char *)image, size);
		if(ret != size) {
			GP_DEBUG("gp_port_read returned %d 0x%x.  size: %d 0x%x", ret, ret, size, size);
			free (image);
			return(GP_ERROR_IO_READ);
		}
	}

	/* swap the bytes for the thumbnail, but not the file */
	if(type == GP_FILE_TYPE_PREVIEW) {
		for(i=0; i<size;  i+=2) {
			temp = image[i];
			image[i] = image[i+1];
			image[i+1] = temp;
		}
	}
	

	gp_file_set_mime_type(file, GP_MIME_JPEG);
	gp_file_set_data_and_size(file, (char *)image, size);

	return(GP_OK);
}
コード例 #27
0
ファイル: gphoto2-port.c プロジェクト: axxel/libgphoto2
/**
 * \brief Configure a port
 *
 * Makes a port functional by passing in the necessary path
 * information (from the serial:/dev/ttyS0 or similar variables).
 * After calling this function, you can access the port using for
 * example gp_port_open().
 * 
 * \param port a GPPort
 * \param info the GPPortInfo to set
 *
 * \return a gphoto2 error code
 **/
int
gp_port_set_info (GPPort *port, GPPortInfo info)
{
	int ret;

	GPPortLibraryOperations ops_func;

	C_PARAMS (port);

	free (port->pc->info.name);
	C_MEM (port->pc->info.name = strdup (info->name));
	free (port->pc->info.path);
	C_MEM (port->pc->info.path = strdup (info->path));
	port->pc->info.type = info->type;
	free (port->pc->info.library_filename);
	C_MEM (port->pc->info.library_filename = strdup (info->library_filename));

	port->type = info->type;

	/* Clean up */
	if (port->pc->ops) {
		gp_port_exit (port);
		free (port->pc->ops);
		port->pc->ops = NULL;
	}
	if (port->pc->lh) {
#if !defined(VALGRIND)
		lt_dlclose (port->pc->lh);
		lt_dlexit ();
#endif
	}

	lt_dlinit ();
	port->pc->lh = lt_dlopenext (info->library_filename);
	if (!port->pc->lh) {
		GP_LOG_E ("Could not load '%s' ('%s').", info->library_filename, lt_dlerror ());
		lt_dlexit ();
		return (GP_ERROR_LIBRARY);
	}

	/* Load the operations */
	ops_func = lt_dlsym (port->pc->lh, "gp_port_library_operations");
	if (!ops_func) {
		GP_LOG_E ("Could not find 'gp_port_library_operations' in '%s' ('%s')",
			  info->library_filename, lt_dlerror ());
		lt_dlclose (port->pc->lh);
		lt_dlexit ();
		port->pc->lh = NULL;
		return (GP_ERROR_LIBRARY);
	}
	port->pc->ops = ops_func ();
	gp_port_init (port);

	/* Initialize the settings to some default ones */
	switch (info->type) {
	case GP_PORT_SERIAL:
		port->settings.serial.speed = 0;
		port->settings.serial.bits = 8;
		port->settings.serial.parity = 0;
		port->settings.serial.stopbits = 1;
		gp_port_set_timeout (port, 500);
		break;
	case GP_PORT_USB:
		if (sizeof (port->settings.usb.port) <= strlen(info->path)) {
			GP_LOG_E ("Path is too long for static buffer '%s'.", info->path);
			return GP_ERROR_LIBRARY;
		}
		strncpy (port->settings.usb.port, info->path,
			 sizeof (port->settings.usb.port));
		port->settings.usb.inep = -1;
		port->settings.usb.outep = -1;
		port->settings.usb.config = -1;
		port->settings.usb.interface = 0;
		port->settings.usb.altsetting = -1;
		gp_port_set_timeout (port, 5000);
		break;
	case GP_PORT_USB_DISK_DIRECT:
		snprintf(port->settings.usbdiskdirect.path,
			 sizeof(port->settings.usbdiskdirect.path), "%s",
			 strchr(info->path, ':') + 1);
		break;
	case GP_PORT_USB_SCSI:
		snprintf(port->settings.usbscsi.path,
			 sizeof(port->settings.usbscsi.path), "%s",
			 strchr(info->path, ':') + 1);
		break;
	default:
		/* Nothing in here */
		break;
	}
	ret = gp_port_set_settings (port, port->settings);
	if (ret != GP_ERROR_NOT_SUPPORTED)
		CHECK_RESULT (ret);

	return GP_OK;
}
コード例 #28
0
ファイル: lowlevel.c プロジェクト: CastorGemini/libgphoto2
static int 
l_receive (GPPort *p, GPContext *context,
	   unsigned char **rb, unsigned int *rbs,
	   unsigned int timeout)
{
	unsigned char c, d, progress = 0;
	int error_flag;
	unsigned int i, j, rbs_internal, id = 0;
	unsigned char checksum;
	int result;
	KCommand command;

	CHECK_NULL (p && rb && rbs);

	for (i = 0; ; ) {
		CHECK (gp_port_set_timeout (p, timeout));
		CHECK (gp_port_read (p, &c, 1));
		CHECK (gp_port_set_timeout (p, DEFAULT_TIMEOUT));
		switch (c) {
		case ENQ:

			/* ENQ received. We can proceed. */
			break;

		case ACK:

			/* ACK received. We'll try again at most ten times. */
			if (i == 9) {

				/*
				 * The camera hangs! Although it could be
				 * that the camera accepts one of the
				 * commands
				 *  - KONICA_CANCEL,
				 *  - KONICA_GET_IO_CAPABILITY, and
				 *  - KONICA_SET_IO_CAPABILITY,
				 * we can not get the camera back to working
				 * correctly.
				 */
				return (GP_ERROR_CORRUPTED_DATA);

			}
			i++;
			break;
		default:
			/*
			 * We'll dump this data until we get ENQ (then, we'll
			 * proceed) or nothing any more (then, we'll report
			 * error).
			 */
			for (;;) {
				CHECK (gp_port_read (p, &c, 1));
				if (c == ENQ)
					break;
			}
			break;
		}
		if (c == ENQ)
			break;
	}

	/* Start progress */
	if (*rbs > 1000) {
		id = gp_context_progress_start (context, *rbs,
						_("Downloading..."));
		progress = 1;
	}

	/* Write ACK. */
	CHECK (gp_port_write (p, "\6", 1));
	for (*rbs = 0; ; ) {
		for (j = 0; ; j++) {
			CHECK (gp_port_read (p, &c, 1));
			switch (c) {
			case STX:

				/* STX received. We can proceed. */
				break;

			default:

				/* We'll dump this data and try again. */
				continue;

			}

			/*
			 * Read 2 bytes for size (low order byte, high order
			 * byte) plus ESC quotes.
			 */
			CHECK (l_esc_read (p, &c));
			checksum = c;
			CHECK (l_esc_read (p, &d));
			checksum += d;
			rbs_internal = (d << 8) | c;
			if (*rbs == 0)
				*rb = malloc (rbs_internal * sizeof (char));
			else
				*rb = realloc (*rb,
					sizeof (char) * (*rbs + rbs_internal));

			/* Read 'rbs_internal' bytes data plus ESC quotes. */
			error_flag = 0;
{
unsigned int read = 0, r = 0;
while (read < rbs_internal) {

	/*
	 * Read the specified amount of bytes. We will probably read more
	 * because some bytes will be quoted.
	 */
	GP_DEBUG ("Reading %i bytes (%i of %i already read)...", 
		  rbs_internal - read, read, rbs_internal);
	result = gp_port_read (p, &((*rb)[*rbs + read]),
			       rbs_internal - read);
	if (result < 0) {
		error_flag = 1;
		break;
	}
	r = rbs_internal - read;

	/* Unescape the data we just read */
	for (i = read; i < read + r; i++) {
		unsigned char *c = &(*rb)[*rbs + i];

		 /* The HP PhotoSmart does not escape every special code, only
		  * some and it gets confused if we do this checks. By relaxing
		  * these, it now downloads images etc.
		  */
#ifndef LESSER_ESCAPES
	        if ((*c == STX) || (*c == ETX) || (*c == ENQ ) ||
		    (*c == ACK) || (*c == XOFF) || (*c == XON) ||
		    (*c == NACK) || (*c == ETB)) {
#else /* LESSER_ESCAPES */
	        if ((*c == STX) ||  (*c == XOFF) || (*c == XON)) {
#endif /* LESSER_ESCAPES */
			GP_DEBUG ("Wrong ESC masking!");
			error_flag = 1;
			break;
		} else if (*c == ESC) {
			if (i == read + r - 1) {
				/* ESC is last char of packet */
				CHECK (gp_port_read (p, c, 1));
			} else {
				memmove (c, c + 1, read + r - i - 1);
				r--;
			}
			*c = ~*c & 0xff;
			if ((*c != STX ) && (*c != ETX ) && (*c != ENQ) &&
			    (*c != ACK ) && (*c != XOFF) && (*c != XON) &&
			    (*c != NACK) && (*c != ETB ) && (*c != ESC)) {
				GP_DEBUG ("Wrong ESC masking!");
				error_flag = 1;
				break;
			}
		}
		checksum += (*rb)[*rbs + i];
	}
	if (error_flag)
		break;
	read += r;
}}
			if (!error_flag) {
				CHECK (gp_port_read (p, &d, 1));
				switch (d) {
				case ETX:

					/*
					 * ETX received. This is the last
					 * packet.
					 */
					GP_DEBUG ("Last packet.");
					break;

				case ETB:

					/*
					 * ETB received. There are more
					 * packets to come.
					 */
					GP_DEBUG ("More packets coming.");
					break;

				default:

					/*
					 * We get more bytes than expected.
					 * Nothing serious, as we will simply
					 * dump all bytes until we receive
					 * ETX or ETB. Later, we'll read the
					 * checksum with ESC quotes and
					 * reject the packet.
					 */
					while ((d != ETX) && (d != ETB)) {
						CHECK (gp_port_read (p,
								     &d, 1));
					}
					error_flag = 1;
					break;
				}
			}
			checksum += d;

			/* Read 1 byte for checksum plus ESC quotes. */
			CHECK (l_esc_read (p, &c));
			if ((c == checksum) && (!error_flag)) {
				*rbs += rbs_internal;

				/* Write ACK. */
				CHECK (gp_port_write (p, "\6", 1));
				break;

			} else {

				/*
				 * Checksum wrong or transmission error. The
				 * camera will send us the data at the most
				 * three times.
				 */
				GP_DEBUG ("Checksum wrong: expected %i, "
					  "got %i.", c, checksum);
				if (j == 2)
					return (GP_ERROR_CORRUPTED_DATA);

				/* Write NACK. */
				c = NACK;
				CHECK (gp_port_write (p, &c, 1));
				continue;
			}
		}
		CHECK (gp_port_read (p, &c, 1));
		switch (c) {
			case EOT:

				/* EOT received. We can proceed. */
				break;

			default:

				/* Should not happen. */
				return (GP_ERROR_CORRUPTED_DATA);
		}
		/*
		 * Depending on d, we will either continue to receive data or
		 * stop.
		 * 
		 *  - ETX:  We are all done.
		 *  - ETB:  We expect more data.
		 *  - else: Should not happen.
		 */
		switch (d) {
		case ETX:

			/* We are all done. */
			if (progress)
				gp_context_progress_stop (context, id);
			return (GP_OK);

		case ETB:

			/* We expect more data. Read ENQ. */
			CHECK (gp_port_read (p, &c, 1));
			switch (c) {
			case ENQ:

				/* ENQ received. We can proceed. */
				break;

			default:

				/* Should not happen. */
				return (GP_ERROR_CORRUPTED_DATA);
			}

			if (gp_context_cancel (context) ==
						GP_CONTEXT_FEEDBACK_CANCEL) {
				GP_DEBUG ("Trying to cancel operation...");
				CHECK (k_cancel (p, context, &command));
				GP_DEBUG ("Operation 0x%x cancelled.",
					  command);
				return (GP_ERROR_CANCEL);
			}

			/* Write ACK. */
			CHECK (gp_port_write (p, "\6", 1));
			break;

		default:

			/* Should not happen. */
			return (GP_ERROR_CORRUPTED_DATA);
		}
		if (progress)
			gp_context_progress_update (context, id, *rbs);
	}
}

int 
l_send_receive (
	GPPort *p, GPContext *c,
	unsigned char *send_buffer, unsigned int send_buffer_size, 
	unsigned char **receive_buffer, unsigned int *receive_buffer_size,
	unsigned int timeout,
	unsigned char **image_buffer, unsigned int *image_buffer_size)
{
	if (!timeout)
		timeout = DEFAULT_TIMEOUT;

	/* Send data. */
	CHECK (l_send (p, c, send_buffer, send_buffer_size));

        /* Receive data. */
	if (image_buffer_size)
		*receive_buffer_size = *image_buffer_size;
	CHECK (l_receive (p, c, receive_buffer, receive_buffer_size,
			  timeout));

	/* Check if we've received the control data. */
	if ((*receive_buffer_size > 1) &&
	    (((*receive_buffer)[0] == send_buffer[0]) &&
	     ((*receive_buffer)[1] == send_buffer[1])))
	    return (GP_OK);

	/* We didn't receive control data yet. */
	*image_buffer = *receive_buffer; 
	*image_buffer_size = *receive_buffer_size;
	*receive_buffer = NULL;
	
	/* Receive control data. */
	CHECK (l_receive (p, c, receive_buffer, receive_buffer_size,
			  DEFAULT_TIMEOUT));

	/* Sanity check: Did we receive the right control data? */
	if (((*receive_buffer)[0] != send_buffer[0]) ||
	    ((*receive_buffer)[1] != send_buffer[1]))
		return (GP_ERROR_CORRUPTED_DATA);
	
	return (GP_OK);
}
コード例 #29
0
ファイル: usb.c プロジェクト: mejedi/Gphoto2.framework
static inline uint16_t
ptp_usb_event (PTPParams* params, PTPContainer* event, int wait)
{
	int			result, timeout, fasttimeout;
	unsigned long		rlen;
	PTPUSBEventContainer	usbevent;
	Camera			*camera = ((PTPData *)params->data)->camera;

	if (params->deviceinfo.VendorExtensionID == PTP_VENDOR_CANON)
		fasttimeout = PTP2_FAST_TIMEOUT*2;
	else
		fasttimeout = PTP2_FAST_TIMEOUT;

	PTP_CNT_INIT(usbevent);

	if (event==NULL)
		return PTP_ERROR_BADPARAM;

	switch(wait) {
	case PTP_EVENT_CHECK:
		result = gp_port_check_int (camera->port, (char*)&usbevent, sizeof(usbevent));
		if (result <= 0) result = gp_port_check_int (camera->port, (char*)&usbevent, sizeof(usbevent));
		break;
	case PTP_EVENT_CHECK_FAST:
		gp_port_get_timeout (camera->port, &timeout);
		gp_port_set_timeout (camera->port, fasttimeout);
		result = gp_port_check_int (camera->port, (char*)&usbevent, sizeof(usbevent));
		if (result <= 0) result = gp_port_check_int (camera->port, (char*)&usbevent, sizeof(usbevent));
		gp_port_set_timeout (camera->port, timeout);
		break;
	default:
		return PTP_ERROR_BADPARAM;
	}
	if (result < 0) {
		gp_log (GP_LOG_DEBUG, "ptp2/usb_event", "reading event an error %d occurred", result);
		if (result == GP_ERROR_TIMEOUT)
			return PTP_ERROR_TIMEOUT;
		return PTP_ERROR_IO;
	}
	if (result == 0) {
		gp_log (GP_LOG_DEBUG, "ptp2/usb_event", "reading event an 0 read occurred, assuming timeout.");
		return PTP_ERROR_TIMEOUT;
	}
	rlen = result;
	if (rlen < 8) {
		gp_log (GP_LOG_ERROR, "ptp2/usb_event",
			"reading event an short read of %ld bytes occurred", rlen);
		return PTP_ERROR_IO;
	}

	/* Only do the additional reads for "events". Canon IXUS 2 likes to
	 * send unrelated data.
	 */
	if (	(dtoh16(usbevent.type) == PTP_USB_CONTAINER_EVENT) &&
		(dtoh32(usbevent.length) > rlen)
	) {
		gp_log (GP_LOG_DEBUG, "ptp2/usb_event","Canon incremental read (done: %ld, todo: %d)", rlen, dtoh32(usbevent.length));
		gp_port_get_timeout (camera->port, &timeout);
		gp_port_set_timeout (camera->port, PTP2_FAST_TIMEOUT);
		while (dtoh32(usbevent.length) > rlen) {
			result = gp_port_check_int (camera->port, ((char*)&usbevent)+rlen, sizeof(usbevent)-rlen);
			if (result <= 0)
				break;
			rlen += result;
		}
		gp_port_set_timeout (camera->port, timeout);
	}
	/* if we read anything over interrupt endpoint it must be an event */
	/* build an appropriate PTPContainer */
	event->Nparam  = (rlen-12)/4;
	event->Code   = dtoh16(usbevent.code);
	event->SessionID=params->session_id;
	event->Transaction_ID=dtoh32(usbevent.trans_id);
	event->Param1 = dtoh32(usbevent.param1);
	event->Param2 = dtoh32(usbevent.param2);
	event->Param3 = dtoh32(usbevent.param3);
	return PTP_RC_OK;
}
コード例 #30
0
ファイル: library.c プロジェクト: rajbot/gphoto
int
camera_init (Camera *camera, GPContext *context)
{
	int ret = 0;
	int x = 0;
	char *model;

	GPPortSettings settings;
	CameraAbilities abilities;

	/* First, set up all the function pointers */
	camera->functions->exit = camera_exit;
	camera->functions->summary = camera_summary;
	camera->functions->about = camera_about;
	camera->functions->capture = camera_capture;

	CHECK (gp_port_get_settings (camera->port, &settings));
	switch (camera->port->type) {
		case GP_PORT_USB:
			settings.usb.inep = 0x82;
			settings.usb.outep = 0x03;
			settings.usb.config = 1;
			settings.usb.interface = 0;
			settings.usb.altsetting = 0;

			CHECK (gp_port_set_settings (camera->port, settings));
			CHECK (gp_port_set_timeout (camera->port, TIMEOUT));

			break;
		default:
			gp_context_error (context,
					  _("Unsupported port type: %d. "
					    "This driver only works with USB "
					    "cameras.\n"), camera->port->type);
			return (GP_ERROR);
			break;
	}

	camera->pl = malloc (sizeof (CameraPrivateLibrary));
	if (!camera->pl)
		return (GP_ERROR_NO_MEMORY);
	memset (camera->pl, 0, sizeof (CameraPrivateLibrary));
	camera->pl->gpdev = camera->port;
	camera->pl->dirty_sdram = 1;
	camera->pl->dirty_flash = 1;

	/* What bridge chip is inside the camera? The gsmart mini is spca500
	 * based, while the others have a spca50xa */
	gp_camera_get_abilities (camera, &abilities);
	model = models[x].model;
	while (model) {
		if (abilities.usb_vendor == models[x].usb_vendor
		 && abilities.usb_product == models[x].usb_product) {
			int same;
			char *m = strdup( models[x].model );
			char *p = strchr (m, ':' );

			if (p) *p = ' ';
			same = !strcmp (m, abilities.model);
			free (m);
			if (same) {
				camera->pl->bridge = models[x].bridge;
				camera->pl->storage_media_mask =
					models[x].storage_media_mask;
				break;
			}
		}
		model = models[++x].model;
	}

	CHECK (spca50x_get_firmware_revision (camera->pl));
	if (camera->pl->fw_rev > 1) {
		CHECK (spca50x_detect_storage_type (camera->pl));
	}
   
	if (cam_has_flash(camera->pl) || cam_has_card(camera->pl) ) {
		if ((camera->pl->bridge == BRIDGE_SPCA504) ||
		    (camera->pl->bridge == BRIDGE_SPCA504B_PD))
			CHECK (spca50x_flash_init (camera->pl, context));
	}

	if ((camera->pl->bridge == BRIDGE_SPCA504) ||
	    (camera->pl->bridge == BRIDGE_SPCA504B_PD)) {
/*		if (abilities.usb_vendor != 0x04fc && abilities.usb_product != 0x504a ) */
		if (!(abilities.usb_vendor == 0x04fc && abilities.usb_product == 0x504a ))
			ret = spca50x_reset (camera->pl);
	}

	if (ret < 0) {
		gp_context_error (context, _("Could not reset camera.\n"));
		free (camera->pl);
		camera->pl = NULL;

		return (ret);
	}

	/* Set up the CameraFilesystem */
	return gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
}