From: "Daniel P. Berrange" <dan@berrange.com>
The pccam300/pccam600 drivers ignored all errors from the gp_port functions. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@14897 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -58,24 +58,23 @@
|
||||
static int
|
||||
pccam300_wait_for_status (GPPort *port)
|
||||
{
|
||||
int ret;
|
||||
int retries = 20;
|
||||
unsigned char status = 1;
|
||||
|
||||
while (status != 0x00 && retries--) {
|
||||
gp_port_set_timeout (port, 3000);
|
||||
ret = gp_port_usb_msg_read (port, 0x06, 0x00, 0x00, &status, 1);
|
||||
CHECK(gp_port_usb_msg_read (port, 0x06, 0x00, 0x00, &status, 1));
|
||||
if (status == 0 || status == 8)
|
||||
return GP_OK;
|
||||
if (status == 0xb0) {
|
||||
gp_port_set_timeout (port, 200000);
|
||||
ret = gp_port_usb_msg_read (port, 0x06, 0x00, 0x00,
|
||||
&status, 1);
|
||||
CHECK(gp_port_usb_msg_read (port, 0x06, 0x00, 0x00,
|
||||
&status, 1));
|
||||
}
|
||||
if (status == 0x40) {
|
||||
gp_port_set_timeout (port, 400000);
|
||||
ret = gp_port_usb_msg_read (port, 0x06, 0x00, 0x00,
|
||||
&status, 1);
|
||||
CHECK(gp_port_usb_msg_read (port, 0x06, 0x00, 0x00,
|
||||
&status, 1));
|
||||
}
|
||||
}
|
||||
return GP_ERROR;
|
||||
@@ -132,13 +131,12 @@ pccam300_get_mem_info (GPPort *port, GPContext *context, int *totalmem,
|
||||
int *freemem)
|
||||
{
|
||||
unsigned char response[4];
|
||||
int ret;
|
||||
|
||||
gp_port_set_timeout (port, 400000);
|
||||
ret = gp_port_usb_msg_read (port, 0x60, 0x00, 0x02, response, 0x04);
|
||||
CHECK (gp_port_usb_msg_read (port, 0x60, 0x00, 0x02, response, 0x04));
|
||||
*totalmem = response[2] * 65536 + response[1] * 256 + response[0];
|
||||
CHECK (pccam300_wait_for_status (port));
|
||||
ret = gp_port_usb_msg_read (port, 0x60, 0x00, 0x03, response, 0x04);
|
||||
CHECK (gp_port_usb_msg_read (port, 0x60, 0x00, 0x03, response, 0x04));
|
||||
*freemem = response[2] * 65536 + response[1] * 256 + response[0];
|
||||
CHECK (pccam300_wait_for_status (port));
|
||||
return GP_OK;
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define QUALITY_LO 0x56
|
||||
#define QUALITY_ME 0x58
|
||||
#define QUALITY_HI 0x45
|
||||
@@ -108,7 +107,7 @@ static int file_list_func (CameraFilesystem *fs, const char *folder,
|
||||
|
||||
Camera *camera = data;
|
||||
CameraFileInfo info;
|
||||
int ret,n,i,nr_of_blocks;
|
||||
int n,i,nr_of_blocks;
|
||||
int offset = 64;
|
||||
char *temp;
|
||||
char buffer[512];
|
||||
@@ -122,7 +121,7 @@ static int file_list_func (CameraFilesystem *fs, const char *folder,
|
||||
}
|
||||
for (n = 0; n != nr_of_blocks; n++)
|
||||
{
|
||||
ret = pccam600_read_data(camera->port, buffer);
|
||||
CHECK(pccam600_read_data(camera->port, buffer));
|
||||
for (i = offset; i <= 512-32; i=i+32)
|
||||
{
|
||||
memcpy(file_entry,&(buffer)[i],32);
|
||||
@@ -168,7 +167,7 @@ static int file_list_func (CameraFilesystem *fs, const char *folder,
|
||||
info.file.permissions = GP_FILE_PERM_READ | GP_FILE_PERM_DELETE;
|
||||
info.file.fields |= GP_FILE_INFO_SIZE | GP_FILE_INFO_PERMISSIONS
|
||||
|GP_FILE_INFO_TYPE;
|
||||
ret = gp_filesystem_set_info_noop(fs, folder, file_entry->name, info, context);
|
||||
CHECK(gp_filesystem_set_info_noop(fs, folder, file_entry->name, info, context));
|
||||
}
|
||||
}
|
||||
offset = 0;
|
||||
@@ -215,7 +214,7 @@ static int get_file_func (CameraFilesystem *fs, const char *folder,
|
||||
{
|
||||
Camera *camera = user_data;
|
||||
unsigned char *data = NULL;
|
||||
int size,ret,index;
|
||||
int size,index;
|
||||
size = 0;
|
||||
index = gp_filesystem_number(fs, folder, filename, context);
|
||||
if (index < 0)
|
||||
@@ -223,7 +222,7 @@ static int get_file_func (CameraFilesystem *fs, const char *folder,
|
||||
switch(type)
|
||||
{
|
||||
case GP_FILE_TYPE_NORMAL:
|
||||
ret=camera_get_file(camera, context, index, &data, &size);
|
||||
CHECK(camera_get_file(camera, context, index, &data, &size));
|
||||
break;
|
||||
default:
|
||||
return GP_ERROR_NOT_SUPPORTED;
|
||||
@@ -235,9 +234,8 @@ static int camera_summary(Camera *camera, CameraText *summary, GPContext *contex
|
||||
{
|
||||
int totalmem;
|
||||
int freemem;
|
||||
int ret;
|
||||
char summary_text[256];
|
||||
ret = pccam600_get_mem_info(camera->port,context,&totalmem,&freemem);
|
||||
CHECK(pccam600_get_mem_info(camera->port,context,&totalmem,&freemem));
|
||||
snprintf(summary_text,sizeof(summary_text),
|
||||
(" Total memory is %8d bytes.\n Free memory is %8d bytes."),
|
||||
totalmem,freemem );
|
||||
@@ -254,12 +252,12 @@ static int camera_about(Camera *camera, CameraText *about, GPContext *context)
|
||||
|
||||
static int delete_file_func(CameraFilesystem *fs, const char *folder,
|
||||
const char *filename, void *data, GPContext *context){
|
||||
int index,ret;
|
||||
int index;
|
||||
|
||||
Camera *camera = data;
|
||||
index = gp_filesystem_number(fs, folder, filename, context);
|
||||
gp_log(GP_LOG_DEBUG,"pccam","deleting '%s' in '%s'.. index:%d",filename, folder,index);
|
||||
ret = pccam600_delete_file(camera->port, context, index);
|
||||
CHECK(pccam600_delete_file(camera->port, context, index));
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
@@ -271,7 +269,6 @@ static CameraFilesystemFuncs fsfuncs = {
|
||||
|
||||
int camera_init(Camera *camera, GPContext *context){
|
||||
GPPortSettings settings;
|
||||
int ret = 0;
|
||||
camera->functions->exit = camera_exit;
|
||||
camera->functions->summary = camera_summary;
|
||||
camera->functions->about = camera_about;
|
||||
@@ -279,22 +276,19 @@ int camera_init(Camera *camera, GPContext *context){
|
||||
switch (camera->port->type)
|
||||
{
|
||||
case GP_PORT_USB:
|
||||
ret = gp_port_get_settings(camera->port,&settings);
|
||||
if (ret < 0) return ret;
|
||||
CHECK(gp_port_get_settings(camera->port,&settings));
|
||||
settings.usb.inep = 0x82;
|
||||
settings.usb.outep = 0x03;
|
||||
settings.usb.config = 1;
|
||||
settings.usb.interface = 1;
|
||||
settings.usb.altsetting = 0;
|
||||
ret=gp_port_set_settings(camera->port,settings);
|
||||
if (ret<0) return ret;
|
||||
CHECK(gp_port_set_settings(camera->port,settings));
|
||||
break;
|
||||
case GP_PORT_SERIAL:
|
||||
return GP_ERROR_IO_SUPPORTED_SERIAL;
|
||||
default:
|
||||
return GP_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
ret = pccam600_init(camera->port, context);
|
||||
if (ret < 0) return ret;
|
||||
CHECK(pccam600_init(camera->port, context));
|
||||
return gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
|
||||
}
|
||||
|
||||
@@ -56,23 +56,23 @@
|
||||
*waits until the status value is 0 or 8.
|
||||
*if status == 0xb0 or 0x40 we will wait some more
|
||||
*/
|
||||
static void pccam600_wait_for_status(GPPort *port){
|
||||
int ret;
|
||||
static int pccam600_wait_for_status(GPPort *port){
|
||||
unsigned char status = 1;
|
||||
while(status != 0x00){
|
||||
gp_port_set_timeout(port,3000);
|
||||
ret = gp_port_usb_msg_read(port,0x06,0x00,0x00,(char*)&status,1);
|
||||
CHECK(gp_port_usb_msg_read(port,0x06,0x00,0x00,(char*)&status,1));
|
||||
if (status == 0 || status == 8)
|
||||
return;
|
||||
return GP_OK;
|
||||
if (status == 0xb0){
|
||||
gp_port_set_timeout(port,200000);
|
||||
ret = gp_port_usb_msg_read(port,0x06,0x00,0x00,(char*)&status,1);
|
||||
CHECK(gp_port_usb_msg_read(port,0x06,0x00,0x00,(char*)&status,1));
|
||||
}
|
||||
if (status == 0x40){
|
||||
gp_port_set_timeout(port,400000);
|
||||
ret = gp_port_usb_msg_read(port,0x06,0x00,0x00,(char*)&status,1);
|
||||
CHECK(gp_port_usb_msg_read(port,0x06,0x00,0x00,(char*)&status,1));
|
||||
}
|
||||
}
|
||||
return GP_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -80,16 +80,15 @@ static void pccam600_wait_for_status(GPPort *port){
|
||||
*/
|
||||
int pccam600_delete_file(GPPort *port, GPContext *context, int index){
|
||||
unsigned char response[4];
|
||||
int ret;
|
||||
index = index + 2;
|
||||
gp_port_set_timeout(port,200000);
|
||||
ret = gp_port_usb_msg_write(port,0x09,index,0x1001,NULL,0x00);
|
||||
pccam600_wait_for_status(port);
|
||||
CHECK(gp_port_usb_msg_write(port,0x09,index,0x1001,NULL,0x00));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
gp_port_set_timeout(port, 400000);
|
||||
ret = gp_port_usb_msg_read(port,0x60,0x00,0x03,(char*)response,0x04);
|
||||
pccam600_wait_for_status(port);
|
||||
ret = gp_port_usb_msg_read(port,0x60,0x00,0x04,(char*)response,0x04);
|
||||
pccam600_wait_for_status(port);
|
||||
CHECK(gp_port_usb_msg_read(port,0x60,0x00,0x03,(char*)response,0x04));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
CHECK(gp_port_usb_msg_read(port,0x60,0x00,0x04,(char*)response,0x04));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
@@ -97,14 +96,13 @@ int pccam600_get_mem_info(GPPort *port, GPContext *context, int *totalmem,
|
||||
int *freemem)
|
||||
{
|
||||
unsigned char response[4];
|
||||
int ret;
|
||||
gp_port_set_timeout(port, 400000);
|
||||
ret = gp_port_usb_msg_read(port,0x60,0x00,0x03,(char*)response,0x04);
|
||||
CHECK(gp_port_usb_msg_read(port,0x60,0x00,0x03,(char*)response,0x04));
|
||||
*totalmem = response[2]*65536+response[1]*256+response[0];
|
||||
pccam600_wait_for_status(port);
|
||||
ret = gp_port_usb_msg_read(port,0x60,0x00,0x04,(char*)response,0x04);
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
CHECK(gp_port_usb_msg_read(port,0x60,0x00,0x04,(char*)response,0x04));
|
||||
*freemem = response[2]*65536+response[1]*256+response[0];
|
||||
pccam600_wait_for_status(port);
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
@@ -113,14 +111,14 @@ int pccam600_get_mem_info(GPPort *port, GPContext *context, int *totalmem,
|
||||
*/
|
||||
int pccam600_get_file_list(GPPort *port, GPContext *context){
|
||||
unsigned char response[4];
|
||||
int ret, nr_of_blocks;
|
||||
int nr_of_blocks;
|
||||
gp_port_set_timeout(port,500);
|
||||
ret = gp_port_usb_msg_write(port,0x08,0x00,0x1021,NULL,0x00);
|
||||
pccam600_wait_for_status(port);
|
||||
CHECK(gp_port_usb_msg_write(port,0x08,0x00,0x1021,NULL,0x00));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
gp_port_set_timeout(port, 200000);
|
||||
ret = gp_port_usb_msg_write(port,0x08,0x00,0x1021,NULL,0x00);
|
||||
pccam600_wait_for_status(port);
|
||||
ret = gp_port_usb_msg_read(port,0x08,0x00,0x1000,(char*)response,0x04);
|
||||
CHECK(gp_port_usb_msg_write(port,0x08,0x00,0x1021,NULL,0x00));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
CHECK(gp_port_usb_msg_read(port,0x08,0x00,0x1000,(char*)response,0x04));
|
||||
nr_of_blocks = response[2]*256+response[1];
|
||||
if (nr_of_blocks == 0){
|
||||
gp_log(GP_LOG_DEBUG,"pccam600 library: pccam600_get_file_list",
|
||||
@@ -134,7 +132,7 @@ int pccam600_get_file_list(GPPort *port, GPContext *context){
|
||||
|
||||
int pccam600_get_file(GPPort *port, GPContext *context, int index){
|
||||
unsigned char response[4];
|
||||
int ret,nr_of_blocks;
|
||||
int nr_of_blocks;
|
||||
index = index + 2;
|
||||
if (index < 2) {
|
||||
gp_context_error(context,
|
||||
@@ -143,13 +141,13 @@ int pccam600_get_file(GPPort *port, GPContext *context, int index){
|
||||
return GP_ERROR;
|
||||
}
|
||||
gp_port_set_timeout(port,200000);
|
||||
ret = gp_port_usb_msg_read(port,0x08,index,0x1001,(char*)response,0x04);
|
||||
CHECK(gp_port_usb_msg_read(port,0x08,index,0x1001,(char*)response,0x04));
|
||||
gp_port_set_timeout(port,3000);
|
||||
ret = gp_port_usb_msg_write(port,0x04,0x00,0x00,NULL,0x00);
|
||||
pccam600_wait_for_status(port);
|
||||
CHECK(gp_port_usb_msg_write(port,0x04,0x00,0x00,NULL,0x00));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
gp_port_set_timeout(port,200000);
|
||||
ret = gp_port_usb_msg_read(port,0x08,index,0x1002,(char*)response,0x04);
|
||||
ret = gp_port_usb_msg_read(port,0x08,index,0x1001,(char*)response,0x04);
|
||||
CHECK(gp_port_usb_msg_read(port,0x08,index,0x1002,(char*)response,0x04));
|
||||
CHECK(gp_port_usb_msg_read(port,0x08,index,0x1001,(char*)response,0x04));
|
||||
nr_of_blocks = response[2]*256+response[1];
|
||||
if (nr_of_blocks == 0){
|
||||
gp_log(GP_LOG_DEBUG,
|
||||
@@ -165,9 +163,8 @@ int pccam600_get_file(GPPort *port, GPContext *context, int index){
|
||||
*Reads bulk data from the camera in 512bytes chunks.
|
||||
*/
|
||||
int pccam600_read_data(GPPort *port, unsigned char *buffer){
|
||||
int ret;
|
||||
gp_port_set_timeout(port,500);
|
||||
ret = gp_port_read(port,(char*)buffer,512);
|
||||
CHECK(gp_port_read(port,(char*)buffer,512));
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
@@ -184,7 +181,7 @@ int pccam600_close(GPPort *port, GPContext *context){
|
||||
ret,0);
|
||||
return GP_ERROR;
|
||||
}
|
||||
pccam600_wait_for_status(port);
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
@@ -199,17 +196,16 @@ int pccam600_init(GPPort *port, GPContext *context){
|
||||
int nr_of_blocks;
|
||||
int ret,i;
|
||||
gp_port_set_timeout(port,100);
|
||||
ret = gp_port_usb_msg_write(port,0x0e,0x00,0x01,NULL,0x0);
|
||||
ret = gp_port_usb_msg_write(port,0x08,0x00,0xff,NULL,0x0);
|
||||
pccam600_wait_for_status(port);
|
||||
if (ret <0) return ret;
|
||||
CHECK(gp_port_usb_msg_write(port,0x0e,0x00,0x01,NULL,0x0));
|
||||
CHECK(gp_port_usb_msg_write(port,0x08,0x00,0xff,NULL,0x0));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
gp_port_set_timeout(port,100000);
|
||||
ret = gp_port_usb_msg_read(port,0x08,0x00,0xff,(char*)response,0x1);
|
||||
CHECK(gp_port_usb_msg_read(port,0x08,0x00,0xff,(char*)response,0x1));
|
||||
gp_port_set_timeout(port,500);
|
||||
ret = gp_port_usb_msg_write(port,0x08,0x00,0x1020,NULL,0x0);
|
||||
pccam600_wait_for_status(port);
|
||||
CHECK(gp_port_usb_msg_write(port,0x08,0x00,0x1020,NULL,0x0));
|
||||
CHECK(pccam600_wait_for_status(port));
|
||||
gp_port_set_timeout(port,200000);
|
||||
ret = gp_port_usb_msg_read(port,0x08,0x00,0x1000,(char*)response,0x4);
|
||||
CHECK(gp_port_usb_msg_read(port,0x08,0x00,0x1000,(char*)response,0x4));
|
||||
nr_of_blocks = response[2]*256+response[1];
|
||||
nr_of_blocks = 512 / nr_of_blocks;
|
||||
gp_log(GP_LOG_DEBUG,"pccam600 library: init","nr_of_blocks %d",nr_of_blocks);
|
||||
|
||||
@@ -33,6 +33,8 @@ typedef struct {
|
||||
unsigned char unk6;
|
||||
} FileEntry;
|
||||
|
||||
#define CHECK(result) {int res; res = result; if (res < 0) return (res);}
|
||||
|
||||
int pccam600_init(GPPort *port, GPContext *context);
|
||||
int pccam600_close(GPPort *port, GPContext *context);
|
||||
int pccam600_get_file_list(GPPort *port, GPContext *context);
|
||||
|
||||
Reference in New Issue
Block a user