/* pdrm11.c -- interfaces directly with the camera * * Copyright 2003 David Hogue * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ #include "config.h" #include "pdrm11.h" #include #include #include #include "gphoto2-endian.h" #define GP_MODULE "pdrm11" #define ETIMEDOUT 110 /* do not sleep during fuzzing */ #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION # define usleep(x) #endif static int pdrm11_select_file(GPPort *port, uint16_t file); 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); } 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