From cb459d1d05e05c80f1fcdf5b09f596ad096b602d Mon Sep 17 00:00:00 2001 From: Lutz Mueller Date: Sun, 2 Sep 2001 09:01:09 +0000 Subject: [PATCH] 2001-09-01 Chris Pinkham * configure.in: added line to generate camlibs/panasonic/coolshot/Makefile * MAINTAINERS: added line for camlibs/panasonic/coolshot driver * camlibs/panasonic/Makefile.am: added coolshot to SUBDIRS declaration * camlibs/panasonic/coolshot/Makefile.am * camlibs/panasonic/coolshot/README * camlibs/panasonic/coolshot/TODO * camlibs/panasonic/coolshot/coolshot.[c,h] * camlibs/panasonic/coolshot/library.[c,h]:added files to support Panasonic Coolshot KXL-600A & KXL-601A digital cameras. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2165 67ed7778-7388-44ab-90cf-0a291f65f57c --- ChangeLog | 13 + MAINTAINERS | 7 +- camlibs/panasonic/Makefile.am | 2 +- camlibs/panasonic/coolshot/.cvsignore | 6 + camlibs/panasonic/coolshot/Makefile.am | 11 + camlibs/panasonic/coolshot/README | 12 + camlibs/panasonic/coolshot/coolshot.c | 294 ++++++++++++ camlibs/panasonic/coolshot/library.c | 594 +++++++++++++++++++++++++ camlibs/panasonic/coolshot/library.h | 51 +++ configure.in | 1 + 10 files changed, 988 insertions(+), 3 deletions(-) create mode 100644 camlibs/panasonic/coolshot/.cvsignore create mode 100644 camlibs/panasonic/coolshot/Makefile.am create mode 100644 camlibs/panasonic/coolshot/README create mode 100644 camlibs/panasonic/coolshot/coolshot.c create mode 100644 camlibs/panasonic/coolshot/library.c create mode 100644 camlibs/panasonic/coolshot/library.h diff --git a/ChangeLog b/ChangeLog index d8dbed1c0..ef44b8678 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,19 @@ * frontends/command-line/options.c: #include +2001-09-01 Chris Pinkham + + * configure.in: added line to generate + camlibs/panasonic/coolshot/Makefile + * MAINTAINERS: added line for camlibs/panasonic/coolshot driver + * camlibs/panasonic/Makefile.am: added coolshot to SUBDIRS declaration + * camlibs/panasonic/coolshot/Makefile.am + * camlibs/panasonic/coolshot/README + * camlibs/panasonic/coolshot/TODO + * camlibs/panasonic/coolshot/coolshot.[c,h] + * camlibs/panasonic/coolshot/library.[c,h]:added files to support + Panasonic Coolshot KXL-600A & KXL-601A digital cameras. + 2001-09-01 Lutz Müller * camlibs/casio: New diff --git a/MAINTAINERS b/MAINTAINERS index 8a94c9b14..67541ed39 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8,6 +8,9 @@ libgphoto2_port: libgphoto2: Scott Fritzinger +camlibs/barbie: + Scott Fritzinger + camlibs/canon: Philippe Marzouk @@ -26,8 +29,8 @@ camlibs/kodak/dc120: camlibs/kodak/dc240: Hubert Figuiere -camlibs/barbie: - Scott Fritzinger +camlibs/panasonic/coolshot: + Chris Pinkham camlibs/sierra: Scott Fritzinger diff --git a/camlibs/panasonic/Makefile.am b/camlibs/panasonic/Makefile.am index 97b6f1a08..ae4442a10 100644 --- a/camlibs/panasonic/Makefile.am +++ b/camlibs/panasonic/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = l859 +SUBDIRS = coolshot l859 camlibdir = $(prefix)/lib/gphoto2 camlib_LTLIBRARIES =\ diff --git a/camlibs/panasonic/coolshot/.cvsignore b/camlibs/panasonic/coolshot/.cvsignore new file mode 100644 index 000000000..3bfbb7206 --- /dev/null +++ b/camlibs/panasonic/coolshot/.cvsignore @@ -0,0 +1,6 @@ +Makefile.in +Makefile +.libs +.deps +*.lo +*.la diff --git a/camlibs/panasonic/coolshot/Makefile.am b/camlibs/panasonic/coolshot/Makefile.am new file mode 100644 index 000000000..57d53186e --- /dev/null +++ b/camlibs/panasonic/coolshot/Makefile.am @@ -0,0 +1,11 @@ +camlibdir = $(prefix)/lib/gphoto2 +camlib_LTLIBRARIES = libgphoto2_panasonic_coolshot.la + +INCLUDES = -I$(top_srcdir)/include + +libgphoto2_panasonic_coolshot_la_SOURCES = coolshot.c coolshot.h library.c library.h + +libgphoto2_panasonic_coolshot_la_LDFLAGS =\ + -avoid-version -L$(shell pwd)/$(top_builddir)/libgphoto2/.libs + +libgphoto2_panasonic_coolshot_la_LIBADD = -lgphoto2 diff --git a/camlibs/panasonic/coolshot/README b/camlibs/panasonic/coolshot/README new file mode 100644 index 000000000..2139c05ab --- /dev/null +++ b/camlibs/panasonic/coolshot/README @@ -0,0 +1,12 @@ +Panasonic KXL-600A and KXL-601A a.k.a. "Coolshot" ++ +This driver is based upon protocol reverse-engineered +using ComLite32 under Windows 95. Known protocol info +along with some sample captured data is in the file +protocol.txt. + +For questions/comments, email the library author: + + Chris Pinkham + cpinkham@infi.net + diff --git a/camlibs/panasonic/coolshot/coolshot.c b/camlibs/panasonic/coolshot/coolshot.c new file mode 100644 index 000000000..80b614082 --- /dev/null +++ b/camlibs/panasonic/coolshot/coolshot.c @@ -0,0 +1,294 @@ +/****************************************************************/ +/* coolshot.c - Gphoto2 library for accessing the Panasonic */ +/* Coolshot KXL-600A & KXL-601A digital cameras. */ +/* */ +/* Copyright (C) 2001 Chris Pinkham */ +/* */ +/* Author: Chris Pinkham */ +/* */ +/* This program is free software; you can redistribute it */ +/* and/or modify it under the terms of the GNU General Public */ +/* License as published by the Free Software Foundation; either */ +/* version 2 of the License, or (at your option) any later */ +/* version. */ +/* */ +/* This program 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 General Public License for more */ +/* details. */ +/* */ +/* You should have received a copy of the GNU General Public */ +/* License along with this program; if not, write to the Free */ +/* Software Foundation, Inc., 59 Temple Place, Suite 330, */ +/* Boston, MA 02111-1307, USA. */ +/****************************************************************/ + +#include +#include +#include +#include + +#ifdef ENABLE_NLS +# include +# undef _ +# define _(String) dgettext (PACKAGE, String) +# ifdef gettext_noop +# define N_(String) gettext_noop (String) +# else +# define _(String) (String) +# define N_(String) (String) +# endif +#else +# define _(String) (String) +# define N_(String) (String) +#endif + +#include "library.h" + +#define TIMEOUT 2000 +#define DEFAULT_SPEED 9600 + +#define COOLSHOT_VERSION "0.2" +#define COOLSHOT_LAST_MOD "09/01/2001 23:03 EST" + +/* define what cameras we support */ +char *coolshot_cameras[] = { + "Panasonic Coolshot KXL-600A", + "Panasonic Coolshot KXL-601A", + "" +}; + +int camera_id (CameraText *id) +{ + strcpy(id->text, "coolshot"); + + return (GP_OK); +} + +int camera_abilities (CameraAbilitiesList *list) +{ + int x = 0; + char *ptr; + CameraAbilities *a; + + ptr = coolshot_cameras[x++]; + while( *ptr ) { + gp_abilities_new( &a ); + strcpy (a->model, ptr ); + a->port = GP_PORT_SERIAL; + a->speed[0] = 9600; + a->speed[1] = 19200; + a->speed[2] = 38400; + a->speed[3] = 57600; + a->speed[4] = 115200; + a->speed[5] = 0; + + /* fixme, need to set these operations lists to correct values */ + a->operations = GP_OPERATION_NONE; + a->file_operations = GP_FILE_OPERATION_NONE; + + /* fixme, believe supports GP_FOLDER_PUT_FILE */ + a->folder_operations = GP_FOLDER_OPERATION_NONE; + + gp_abilities_list_append (list, a); + + ptr = coolshot_cameras[x++]; + } + + return (GP_OK); +} + +static int camera_start (Camera *camera) +{ + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_start"); + + CHECK( coolshot_sb( camera, camera->port_info->speed )); + + return( GP_OK ); +} + +static int camera_stop (Camera *camera) +{ + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_stop"); + + CHECK( coolshot_sb( camera, DEFAULT_SPEED )); + return( GP_OK ); +} + +static int file_list_func (CameraFilesystem *fs, const char *folder, + CameraList *list, void *data) +{ + Camera *camera = data; + int count; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** file_list_func"); + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** folder: %s", folder); + + CHECK (camera_start (camera)); + count = coolshot_file_count (camera); + CHECK (gp_filesystem_populate (fs, "/", "pic_%04i.jpg", count)); + + return (camera_stop (camera)); +} + +static int get_info_func (CameraFilesystem *fs, const char *folder, + const char *filename, CameraFileInfo *info, void *data) +{ + Camera *camera = data; + int file_number; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** get_info_func"); + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** folder: %s", folder); + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** filename: %s", filename); + + CHECK (camera_start (camera)); + + /* Get the file number from the CameraFileSystem */ + file_number = gp_filesystem_number (camera->fs, folder, filename); + if (file_number < 0) + return (file_number); + + /* fixme, get file size also */ + info->file.fields = GP_FILE_INFO_TYPE; + strcpy (info->file.type, GP_MIME_JPEG ); + + info->preview.fields = GP_FILE_INFO_TYPE; + strcpy (info->preview.type, GP_MIME_JPEG ); + + return (camera_stop (camera)); +} + +static int camera_exit (Camera *camera) +{ + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_exit"); + + return (GP_OK); +} + +static int camera_file_get (Camera *camera, const char *folder, + const char *filename, CameraFileType type, + CameraFile *file) +{ + char data[128000]; + int size; + int number; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_file_get"); + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** folder: %s", folder); + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** filename: %s", filename); + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** type: %d", type); + + CHECK( camera_start(camera)); + + switch( type ) { + case GP_FILE_TYPE_PREVIEW: + /* fixme, preview/thumbnail downloads full image with this commented... + sscanf( filename, "thm_%d.jpg", &number ); + coolshot_request_thumbnail( camera, data, &size, number ); + break; + */ + + case GP_FILE_TYPE_NORMAL: + sscanf( filename, "pic_%d.jpg", &number ); + coolshot_request_image( camera, data, &size, number ); + break; + + default: + return( GP_ERROR_NOT_SUPPORTED ); + } + + gp_file_set_mime_type( file, GP_MIME_JPEG ); + gp_file_set_name( file, filename ); + gp_file_append(file, data, size); + + return (camera_stop (camera)); +} + +static int camera_summary (Camera *camera, CameraText *summary) +{ + int count; + char tmp[1024]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_summary"); + + CHECK( camera_start(camera)); + + /* possibly get # pics, mem free, etc. */ + count = coolshot_file_count (camera); + + sprintf( tmp, "Frames Taken : %4d\n", count ); + strcat( summary->text, tmp ); + + return (camera_stop (camera)); +} + +static int camera_manual (Camera *camera, CameraText *manual) +{ + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_manual"); + + strcpy (manual->text, _("Some notes:\n" + " No notes here yet.\n")); + return (GP_OK); +} + +static int camera_about (Camera *camera, CameraText *about) +{ + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_about"); + + strcpy (about->text, + _("coolshot library v" COOLSHOT_VERSION " " COOLSHOT_LAST_MOD "\n" + "Chris Pinkham \n" + "Support for Panasonic Coolshot digital cameras\n" + "based on reverse engineering serial protocol.\n" + "\n")); + + return (GP_OK); +} + +int camera_init (Camera *camera) +{ + int count; + gp_port_settings settings; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "*** camera_init"); + + /* First, set up all the function pointers */ + camera->functions->exit = camera_exit; + camera->functions->file_get = camera_file_get; + camera->functions->summary = camera_summary; + camera->functions->manual = camera_manual; + camera->functions->about = camera_about; + + camera->camlib_data = NULL; + + strcpy (settings.serial.port, camera->port_info->path); + settings.serial.speed = DEFAULT_SPEED; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + + CHECK( gp_port_settings_set (camera->port, settings)); + + CHECK( gp_port_timeout_set (camera->port, TIMEOUT)); + CHECK( gp_port_open( camera->port )); + + /* check to see if camera is really there */ + CHECK( coolshot_enq (camera)); + + coolshot_sm( camera ); + + /* get number of images */ + count = coolshot_file_count (camera); + if (count < 0) + return (count); + + CHECK( camera_start (camera)); + CHECK(gp_filesystem_set_list_funcs (camera->fs, + file_list_func, NULL, camera)); + CHECK(gp_filesystem_set_info_funcs (camera->fs, + get_info_func, NULL, camera)); + + return (camera_stop (camera)); +} + diff --git a/camlibs/panasonic/coolshot/library.c b/camlibs/panasonic/coolshot/library.c new file mode 100644 index 000000000..83046cea1 --- /dev/null +++ b/camlibs/panasonic/coolshot/library.c @@ -0,0 +1,594 @@ +/****************************************************************/ +/* library.c - Gphoto2 library for accessing the Panasonic */ +/* Coolshot KXL-600A & KXL-601A digital cameras. */ +/* */ +/* Copyright (C) 2001 Chris Pinkham */ +/* */ +/* Author: Chris Pinkham */ +/* */ +/* This program is free software; you can redistribute it */ +/* and/or modify it under the terms of the GNU General Public */ +/* License as published by the Free Software Foundation; either */ +/* version 2 of the License, or (at your option) any later */ +/* version. */ +/* */ +/* This program 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 General Public License for more */ +/* details. */ +/* */ +/* You should have received a copy of the GNU General Public */ +/* License along with this program; if not, write to the Free */ +/* Software Foundation, Inc., 59 Temple Place, Suite 330, */ +/* Boston, MA 02111-1307, USA. */ +/****************************************************************/ + +#include +#include +#include +#include +#include "library.h" +#include + +#define COOL_SLEEP 10000 + +int packet_size = 500; + +/* ??set mode?? */ +int coolshot_sm( Camera *camera ) { + char buf[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_sm"); + + memset( buf, 0, sizeof( buf )); + + buf[0] = COOLSHOT_PKT; + buf[2] = 'S'; + buf[3] = 'M'; + buf[4] = 0x01; + buf[15] = 0x02; + + coolshot_write_packet( camera, buf ); + + /* read ACK */ + coolshot_read_packet( camera, buf ); + + /* read data */ + coolshot_read_packet( camera, buf ); + + /* send ACK */ + coolshot_ack( camera ); + + packet_size = 128; + + return( GP_OK ); +} + +/* ?set baud? */ +int coolshot_sb( Camera *camera, int speed ) { + char buf[16]; + gp_port_settings settings; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_sb"); + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* speed: %i", speed); + + memset( buf, 0, sizeof( buf )); + + buf[0] = COOLSHOT_PKT; + buf[2] = 'S'; + buf[3] = 'B'; + buf[4] = 0x01; + buf[15] = 0x02; + + gp_port_settings_get (camera->port, &settings); + + switch (speed) { + case 9600: + buf[4] = '1'; + settings.serial.speed = 9600; + break; + case -1: + case 19200: + buf[4] = '2'; + settings.serial.speed = 19200; + break; + case 28800: + buf[4] = '3'; + settings.serial.speed = 28800; + break; + case 38400: + buf[4] = '4'; + settings.serial.speed = 38400; + break; + case 57600: + buf[4] = '5'; + settings.serial.speed = 57600; + break; + case 0: /* Default speed */ + case 115200: + buf[4] = '6'; + settings.serial.speed = 115200; + break; + default: + return (GP_ERROR_IO_SERIAL_SPEED); + } + + coolshot_enq( camera ); + + /* set speed */ + coolshot_write_packet( camera, buf ); + + /* read ack */ + coolshot_read_packet( camera, buf ); + + /* read OK */ + coolshot_read_packet( camera, buf ); + + /* ack the OK */ + coolshot_ack( camera ); + + CHECK (gp_port_settings_set (camera->port, settings)); + + GP_SYSTEM_SLEEP(10); + return (GP_OK); +} + +int coolshot_fs( Camera *camera, int number ) { + char buf[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_fs"); + + memset( buf, 0, sizeof( buf )); + + buf[0] = COOLSHOT_PKT; + buf[2] = 'F'; + buf[3] = 'S'; + buf[7] = number; + buf[15] = 0x02; + + coolshot_enq( camera ); + + coolshot_write_packet( camera, buf ); + + /* read ACK */ + coolshot_read_packet( camera, buf ); + + /* read data */ + coolshot_read_packet( camera, buf ); + + /* send ACK */ + coolshot_ack( camera ); + return( GP_OK ); +} + +int coolshot_sp( Camera *camera ) { + char buf[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_sp"); + + memset( buf, 0, sizeof( buf )); + + buf[0] = COOLSHOT_PKT; + buf[2] = 'S'; + buf[3] = 'P'; + buf[4] = 0x02; + buf[15] = 0x02; + + coolshot_enq( camera ); + + coolshot_write_packet( camera, buf ); + + /* read ACK */ + coolshot_read_packet( camera, buf ); + + packet_size = 500; + + return( GP_OK ); +} + +int coolshot_file_count (Camera *camera) { + char buf[16]; + int count = 0; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_file_count"); + + memset( buf, 0, sizeof( buf )); + + buf[0] = COOLSHOT_PKT; + buf[2] = 'R'; + buf[3] = 'N'; + buf[5] = 0x01; + buf[15] = 0x02; + + coolshot_enq( camera ); + + /* request count */ + coolshot_write_packet( camera, buf ); + + /* read ack */ + coolshot_read_packet( camera, buf ); + + /* read data packet */ + coolshot_read_packet( camera, buf ); + + count = buf[7]; + + usleep( COOL_SLEEP ); + coolshot_ack( camera ); + + return( count ); +} + +int coolshot_request_image( Camera *camera, char *buf, int *len, int number ) { + char packet[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_request_image"); + + memset( packet, 0, sizeof( packet )); + + packet[0] = COOLSHOT_PKT; + packet[2] = 'R'; + packet[3] = 'D'; + packet[7] = number; + packet[15] = 0x02; + + /* fixme */ + coolshot_fs( camera, number ); + coolshot_sp( camera ); + + coolshot_enq( camera ); + + /* request image */ + coolshot_write_packet( camera, packet ); + + /* read ack */ + coolshot_read_packet( camera, packet ); + + /* read OK */ + coolshot_read_packet( camera, packet ); + + /* read data */ + coolshot_download_image( camera, buf, len, 0 ); + + return( GP_OK ); +} + +int coolshot_request_thumbnail( Camera *camera, char *buf, int *len, int number ) { + char packet[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_request_thumbnail"); + + memset( packet, 0, sizeof( packet )); + + packet[0] = COOLSHOT_PKT; + packet[2] = 'R'; + packet[3] = 'M'; + packet[7] = number; + packet[15] = 0x02; + + /* fixme */ + coolshot_fs( camera, number ); + /* + coolshot_sp( camera ); + */ + + coolshot_enq( camera ); + + /* request image */ + coolshot_write_packet( camera, packet ); + + /* read ack */ + coolshot_read_packet( camera, packet ); + + /* read OK */ + coolshot_read_packet( camera, packet ); + + /* read data */ + coolshot_download_image( camera, buf, len, 0 ); + + return( GP_OK ); +} + +int coolshot_check_checksum( char *packet, int length ) { + int checksum = 0; + int p_csum = 0; + int x; + unsigned char *ptr; + + ptr = (unsigned char *)packet + 2; + for( x = 2; x < (length - 4 ); x++ ) { + checksum += *(ptr++); + /* checksum += (unsigned char)packet[x]; */ + } + checksum &= 0xffff; /* 16 bit checksum */ + + p_csum = (unsigned char)packet[length - 4]; + p_csum = p_csum << 8; + p_csum += (unsigned char)packet[length - 3]; + + if ( checksum == p_csum ) { + return( GP_OK ); + } else { + return( GP_ERROR ); + } +} + +int coolshot_download_image( Camera *camera, char *buf, int *len, int thumbnail ) { + char packet[1024]; + int data_len; + int bytes_read = 0; + int last_good = 0; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_download_image"); + + memset( packet, 0, sizeof( packet )); + + packet[2] = '0'; + packet[3] = '0'; + + coolshot_ack( camera ); + + coolshot_read_packet( camera, packet ); + + data_len = (unsigned char)packet[6] * 256; + data_len += (unsigned char)packet[7]; + + /* fixme, get rid of hardcoded length */ + if ( coolshot_check_checksum( packet, 8 + packet_size + 4 ) == GP_OK ) { + coolshot_ack( camera ); + last_good = 1; + } else { + /* + coolshot_nak( camera ); + */ + last_good = 0; + } + + while( strncmp( packet + 2, "DT", 2 ) == 0 ) { + /* process packet */ + if ( last_good ) { + data_len = (unsigned char)packet[6] * 256; + data_len += (unsigned char)packet[7]; + + memcpy( buf + bytes_read, packet + 8, data_len ); + + bytes_read += data_len; + } + + coolshot_read_packet( camera, packet ); + + data_len = (unsigned char)packet[6] * 256; + data_len += (unsigned char)packet[7]; + + /* fixme, get rid of hardcoded length */ + if ( coolshot_check_checksum( packet, 8 + packet_size + 4 ) == GP_OK) { + coolshot_ack( camera ); + last_good = 1; + } else { + /* + coolshot_nak( camera ); + */ + last_good = 0; + } + } + + coolshot_ack( camera ); + + *len = bytes_read; + + return( GP_OK ); +} + +int coolshot_write_packet (Camera *camera, char *packet) { + int x, ret, r, checksum=0, length; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_write_packet"); + + if ( packet[0] == COOLSHOT_PKT ) { + /* fixme */ + length = 16; + + for ( x = 2 ; x < 12; x++ ) { + checksum += (unsigned char)packet[x]; + } + + packet[length - 4] = (checksum >> 8 ) & 0xff; + packet[length - 3] = checksum & 0xff; + + } else if (( packet[0] == COOLSHOT_ENQ ) || + ( packet[0] == COOLSHOT_ACK ) || + ( packet[0] == COOLSHOT_NAK )) { + length = 1; + } else { + length = 0; + /* fixme */ + return( -1 ); + } + + for (r = 0; r < RETRIES; r++) { + ret = gp_port_write (camera->port, packet, length); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + + return (ret); + } + + return (GP_ERROR_IO_TIMEOUT); +} + + +int coolshot_read_packet (Camera *camera, char *packet) { + int r = 0, x = 0, ret, done, length=0; + int blocksize, bytes_read; + char buf[4096]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_read_packet"); + +read_packet_again: + buf[0] = 0; + packet[0] = 0; + + if (r > 0) + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* reading again..."); + + done = 0; + + blocksize = 1; + + for (r = 0; r < RETRIES; r++) { + + bytes_read = gp_port_read (camera->port, packet, blocksize); + if (bytes_read == GP_ERROR_IO_TIMEOUT) + continue; + if (bytes_read < 0) + return (bytes_read); + + if ( packet[0] == COOLSHOT_ENQ ) { + usleep( COOL_SLEEP ); + coolshot_ack( camera ); + coolshot_read_packet( camera, packet ); + return( GP_OK ); + } + + if (( packet[0] == COOLSHOT_ACK ) || + ( packet[0] == COOLSHOT_DONE )) { + return( GP_OK ); + } + + if ( packet[0] != COOLSHOT_PKT ) { + return( GP_ERROR ); + } + + bytes_read = gp_port_read (camera->port, packet + 1, 3 ); + if (bytes_read == GP_ERROR_IO_TIMEOUT) + continue; + if (bytes_read < 0) + return (bytes_read); + + /* Determine the packet type */ + if (( strncmp( packet + 2, "OK", 2 ) == 0 ) || + ( strncmp( packet + 2, "DE", 2 ) == 0 ) || + ( strncmp( packet + 2, "SB", 2 ) == 0 )) { + /* normal 16-byte packet, so read the other 12 bytes */ + ret = gp_port_read (camera->port, packet + 4, 12 ); + if (ret == GP_ERROR_IO_TIMEOUT) { + /* fixme */ + /* + coolshot_nak (camera); + */ + goto read_packet_again; + } + + if (ret < 0) + return (ret); + + return( GP_OK ); + } else if ( strncmp( packet + 2, "DT", 2 ) == 0 ) { + /* read in packet number and length */ + ret = gp_port_read (camera->port, packet + 4, 4 ); + /* fixme, error detection */ + + length = (unsigned char)packet[6] * 256; + length += (unsigned char)packet[7]; + + if (( packet_size == 128 ) || + ( length == 128 )) { + length = 128; + } else { + length = 500; + } + length += 4; + + ret = gp_port_read (camera->port, packet + 8, length ); + /* fixme, error detection */ + + x = 0; + while(( ret == GP_ERROR_IO_TIMEOUT ) && + ( x < RETRIES )) { + x++; + ret = gp_port_read (camera->port, packet + 8, length ); + } + + return( GP_OK ); + } + + if (done) break; + } + + return (GP_ERROR_IO_TIMEOUT); +} + + +int coolshot_ack (Camera *camera) +{ + int ret, r = 0; + char buf[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_ack"); + + buf[0] = COOLSHOT_ACK; + + for (r = 0; r < RETRIES; r++) { + + ret = coolshot_write_packet (camera, buf); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + if (ret == GP_OK) + return (ret); + } + return (GP_ERROR_IO_TIMEOUT); +} + +int coolshot_nak (Camera *camera) +{ + int ret, r = 0; + char buf[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_nak"); + + buf[0] = COOLSHOT_NAK; + + for (r = 0; r < RETRIES; r++) { + + ret = coolshot_write_packet (camera, buf); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + if (ret == GP_OK) + return (ret); + } + return (GP_ERROR_IO_TIMEOUT); +} + +int coolshot_enq (Camera *camera) +{ + int ret, r = 0; + char buf[16]; + + gp_debug_printf (GP_DEBUG_LOW, "coolshot", "* coolshot_enq"); + + buf[0] = COOLSHOT_ENQ; + + for (r = 0; r < RETRIES; r++) { + + ret = coolshot_write_packet (camera, buf); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + if (ret != GP_OK) + return (ret); + + ret = coolshot_read_packet (camera, buf); + if (ret == GP_ERROR_IO_TIMEOUT) + continue; + if (ret != GP_OK) + return (ret); + + if (buf[0] == COOLSHOT_ACK) + return (GP_OK); + else + return (GP_ERROR_CORRUPTED_DATA); + + } + return (GP_ERROR_IO_TIMEOUT); +} + diff --git a/camlibs/panasonic/coolshot/library.h b/camlibs/panasonic/coolshot/library.h new file mode 100644 index 000000000..38104d94c --- /dev/null +++ b/camlibs/panasonic/coolshot/library.h @@ -0,0 +1,51 @@ +/****************************************************************/ +/* library.h - Gphoto2 library for accessing the Panasonic */ +/* Coolshot KXL-600A & KXL-601A digital cameras. */ +/* */ +/* Copyright (C) 2001 Chris Pinkham */ +/* */ +/* Author: Chris Pinkham */ +/* */ +/* This program is free software; you can redistribute it */ +/* and/or modify it under the terms of the GNU General Public */ +/* License as published by the Free Software Foundation; either */ +/* version 2 of the License, or (at your option) any later */ +/* version. */ +/* */ +/* This program 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 General Public License for more */ +/* details. */ +/* */ +/* You should have received a copy of the GNU General Public */ +/* License along with this program; if not, write to the Free */ +/* Software Foundation, Inc., 59 Temple Place, Suite 330, */ +/* Boston, MA 02111-1307, USA. */ +/****************************************************************/ + +#define RETRIES 10 + +#define COOLSHOT_DONE 0x00 +#define COOLSHOT_PKT 0x01 +#define COOLSHOT_ENQ 0x05 +#define COOLSHOT_ACK 0x06 +#define COOLSHOT_NAK 0x15 + +#define CHECK(result) {int res; res = result; if (res != GP_OK) return (res);} + +int coolshot_sm (Camera *camera); +int coolshot_sb (Camera *camera, int speed); +int coolshot_fs (Camera *camera, int number); +int coolshot_sp (Camera *camera); +int coolshot_ack (Camera *camera); +int coolshot_nak (Camera *camera); +int coolshot_enq (Camera *camera); +int coolshot_write_packet (Camera *camera, char *packet); +int coolshot_read_packet (Camera *camera, char *packet); +int coolshot_file_count (Camera *camera); +int coolshot_check_checksum( char *packet, int length ); +int coolshot_request_image (Camera *camera, char *buf, int *len, int number); +int coolshot_request_thumbnail (Camera *camera, char *buf, int *len, int number); +int coolshot_download_image (Camera *camera, char *buf, int *len, int thumbnail); + diff --git a/configure.in b/configure.in index 00c2ef51f..7ab905e2e 100644 --- a/configure.in +++ b/configure.in @@ -179,6 +179,7 @@ camlibs/minolta/Makefile camlibs/minolta/dimagev/Makefile camlibs/panasonic/Makefile camlibs/panasonic/l859/Makefile +camlibs/panasonic/coolshot/Makefile camlibs/polaroid/Makefile camlibs/samsung/Makefile camlibs/sierra/Makefile