diff options
author | Philippe Marzouk <philm@users.sourceforge.net> | 2001-10-09 20:06:05 +0000 |
---|---|---|
committer | Philippe Marzouk <philm@users.sourceforge.net> | 2001-10-09 20:06:05 +0000 |
commit | 8e8ddf634e86226eb4e348e6cf98985836049000 (patch) | |
tree | 5d4363e48547d27e67d975ee0f7dc0d6d758411a /camlibs | |
parent | f630cceb1bd83f90727b2775e9fd367329b70619 (diff) | |
download | libgphoto2-8e8ddf634e86226eb4e348e6cf98985836049000.tar.gz |
global reindentation of the code, see the .indent.pro file for the rules used
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2470 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'camlibs')
-rw-r--r-- | camlibs/canon/.indent.pro | 21 | ||||
-rw-r--r-- | camlibs/canon/canon.c | 2246 | ||||
-rw-r--r-- | camlibs/canon/crc.c | 389 | ||||
-rw-r--r-- | camlibs/canon/psa50.c | 3596 | ||||
-rw-r--r-- | camlibs/canon/serial.c | 323 | ||||
-rw-r--r-- | camlibs/canon/util.c | 131 |
6 files changed, 3544 insertions, 3162 deletions
diff --git a/camlibs/canon/.indent.pro b/camlibs/canon/.indent.pro new file mode 100644 index 000000000..b81679cb3 --- /dev/null +++ b/camlibs/canon/.indent.pro @@ -0,0 +1,21 @@ +--gnu-style +--indent-level8 +--blank-lines-after-declarations +--blank-lines-after-procedures +--braces-on-if-line +--cuddle-else +--space-special-semicolon +--no-blank-before-sizeof +--no-space-after-parentheses +--continue-at-parentheses +--line-length95 +--comment-line-length80 +--honour-newlines +--case-indentation8 +--space-after-cast +--space-after-for +--space-after-if +--space-after-while +-T gp_port +-T Camera + diff --git a/camlibs/canon/canon.c b/camlibs/canon/canon.c index f4a4198c4..e0cabac8e 100644 --- a/camlibs/canon/canon.c +++ b/camlibs/canon/canon.c @@ -59,234 +59,271 @@ int canon_debug_driver = 9; -static struct { +static struct +{ char *name; unsigned short idVendor; unsigned short idProduct; char serial; -} models[] = { - { "Canon PowerShot A5", 0, 0, 1 }, - { "Canon PowerShot A5 Zoom", 0, 0, 1}, - { "Canon PowerShot A50", 0, 0, 1}, - { "Canon PowerShot Pro70", 0, 0, 1}, - { "Canon PowerShot S10", 0x04A9, 0x3041, 1}, - { "Canon PowerShot S20", 0x04A9, 0x3043, 1 }, - { "Canon EOS D30", 0x04A9, 0x3044, 0 }, - { "Canon PowerShot S100", 0x04A9, 0x3045, 0 }, - { "Canon IXY DIGITAL", 0x04A9, 0x3046, 0 }, - { "Canon Digital IXUS", 0x04A9, 0x3047, 0 }, - { "Canon PowerShot G1", 0x04A9, 0x3048, 1 }, - { "Canon PowerShot G2", 0x04A9, 0x3055, 0 }, - { "Canon PowerShot Pro90 IS", 0x04A9, 0x3049, 1 }, - { "Canon IXY DIGITAL 300", 0x04A9, 0x304B, 0 }, - { "Canon PowerShot S300", 0x04A9, 0x304C, 0 }, - { "Canon Digital IXUS 300", 0x04A9, 0x304D, 0 }, - { "Canon PowerShot A20", 0x04A9, 0x304E, 0 }, - { "Canon PowerShot A10", 0x04A9, 0x304F, 0 }, - { "Canon PowerShot S110", 0x04A9, 0x3051, 0 }, - { "Canon DIGITAL IXUS v", 0x04A9, 0x3052, 0 }, - { 0, 0, 0} +} +models[] = +{ + { + "Canon PowerShot A5", 0, 0, 1} + , { + "Canon PowerShot A5 Zoom", 0, 0, 1} + , { + "Canon PowerShot A50", 0, 0, 1} + , { + "Canon PowerShot Pro70", 0, 0, 1} + , { + "Canon PowerShot S10", 0x04A9, 0x3041, 1} + , { + "Canon PowerShot S20", 0x04A9, 0x3043, 1} + , { + "Canon EOS D30", 0x04A9, 0x3044, 0} + , { + "Canon PowerShot S100", 0x04A9, 0x3045, 0} + , { + "Canon IXY DIGITAL", 0x04A9, 0x3046, 0} + , { + "Canon Digital IXUS", 0x04A9, 0x3047, 0} + , { + "Canon PowerShot G1", 0x04A9, 0x3048, 1} + , { + "Canon PowerShot G2", 0x04A9, 0x3055, 0} + , { + "Canon PowerShot Pro90 IS", 0x04A9, 0x3049, 1} + , { + "Canon IXY DIGITAL 300", 0x04A9, 0x304B, 0} + , { + "Canon PowerShot S300", 0x04A9, 0x304C, 0} + , { + "Canon Digital IXUS 300", 0x04A9, 0x304D, 0} + , { + "Canon PowerShot A20", 0x04A9, 0x304E, 0} + , { + "Canon PowerShot A10", 0x04A9, 0x304F, 0} + , { + "Canon PowerShot S110", 0x04A9, 0x3051, 0} + , { + "Canon DIGITAL IXUS v", 0x04A9, 0x3052, 0} + , { + 0, 0, 0} }; -int camera_id(CameraText *id) +int +camera_id (CameraText * id) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_id()"); - - strcpy(id->text, "canon"); - + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_id()"); + + strcpy (id->text, "canon"); + return GP_OK; } -int camera_manual(Camera *camera, CameraText *manual) +int +camera_manual (Camera *camera, CameraText * manual) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_manual()"); - - strcpy(manual->text, _("For the A50, 115200 may not be faster than 57600\n" - "Folders are NOT supported\n" - "if you experience a lot of transmissions errors," - " try to have you computer as idle as possible (ie: no disk activity)")); + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_manual()"); + + strcpy (manual->text, _("For the A50, 115200 may not be faster than 57600\n" + "Folders are NOT supported\n" + "if you experience a lot of transmissions errors," + " try to have you computer as idle as possible (ie: no disk activity)")); return GP_OK; } -int camera_abilities(CameraAbilitiesList *list) +int +camera_abilities (CameraAbilitiesList * list) { - int i; - CameraAbilities *a; - - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_abilities()"); - - for (i=0; models[i].name; i++) { - gp_abilities_new(&a); - strcpy(a->model, models[i].name); - a->port = 0; - if (models[i].idProduct) { - a->port |= GP_PORT_USB; - a->usb_vendor = models[i].idVendor; - a->usb_product = models[i].idProduct; - } - if (models[i].serial) { - 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; + int i; + CameraAbilities *a; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_abilities()"); + + for (i = 0; models[i].name; i++) { + gp_abilities_new (&a); + strcpy (a->model, models[i].name); + a->port = 0; + if (models[i].idProduct) { + a->port |= GP_PORT_USB; + a->usb_vendor = models[i].idVendor; + a->usb_product = models[i].idProduct; + } + if (models[i].serial) { + 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; + } + a->operations = GP_OPERATION_CONFIG; + a->folder_operations = GP_FOLDER_OPERATION_PUT_FILE; + a->file_operations = GP_FILE_OPERATION_DELETE | GP_FILE_OPERATION_PREVIEW; + gp_abilities_list_append (list, a); } - a->operations = GP_OPERATION_CONFIG; - a->folder_operations = GP_FOLDER_OPERATION_PUT_FILE; - a->file_operations = GP_FILE_OPERATION_DELETE | - GP_FILE_OPERATION_PREVIEW; - gp_abilities_list_append(list, a); - } - - return GP_OK; + + return GP_OK; } -int camera_folder_list_folders (Camera *camera, const char *folder, - CameraList *list) +int +camera_folder_list_folders (Camera *camera, const char *folder, CameraList * list) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_folder_list()"); - + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_folder_list()"); + return GP_OK; } -void clear_readiness(Camera *camera) -{ - canon_info *cs = (struct canon_info*)camera->camlib_data; +void +clear_readiness (Camera *camera) +{ + canon_info *cs = (struct canon_info *) camera->camlib_data; - gp_debug_printf(GP_DEBUG_LOW,"canon","clear_readiness()"); - - cs->cached_ready = 0; + gp_debug_printf (GP_DEBUG_LOW, "canon", "clear_readiness()"); + + cs->cached_ready = 0; } -static int check_readiness(Camera *camera) +static int +check_readiness (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - - gp_debug_printf(GP_DEBUG_LOW,"canon","check_readiness() cached_ready == %i", cs->cached_ready); - - if (cs->cached_ready) return 1; - if (psa50_ready(camera)) { - gp_debug_printf(GP_DEBUG_LOW,"canon",_("Camera type: %d\n"),cs->model); + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "check_readiness() cached_ready == %i", + cs->cached_ready); + + if (cs->cached_ready) + return 1; + if (psa50_ready (camera)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", _("Camera type: %d\n"), cs->model); cs->cached_ready = 1; return 1; - } - gp_camera_status(camera, _("Camera unavailable")); - return 0; + } + gp_camera_status (camera, _("Camera unavailable")); + return 0; } -static void switch_camera_off(Camera *camera) +static void +switch_camera_off (Camera *camera) { - gp_debug_printf(GP_DEBUG_LOW,"canon","switch_camera_off()"); + gp_debug_printf (GP_DEBUG_LOW, "canon", "switch_camera_off()"); + - - gp_camera_status(camera, _("Switching Camera Off")); + gp_camera_status (camera, _("Switching Camera Off")); - psa50_off(camera); - clear_readiness(camera); + psa50_off (camera); + clear_readiness (camera); } -int camera_exit(Camera *camera) +int +camera_exit (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_exit()"); - - switch (camera->port->type) { - case GP_PORT_USB: - break; - case GP_PORT_SERIAL: - switch_camera_off(camera); - break; - default: - break; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_exit()"); + + switch (camera->port->type) { + case GP_PORT_USB: + break; + case GP_PORT_SERIAL: + switch_camera_off (camera); + break; + default: + break; } - - free(cs); + + free (cs); return GP_OK; } -static int canon_get_batt_status(Camera *camera, int *pwr_status, int *pwr_source) +static int +canon_get_batt_status (Camera *camera, int *pwr_status, int *pwr_source) { - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_get_batt_status()"); - - if (!check_readiness(camera)) - return -1; - - return psa50_get_battery(camera, pwr_status, pwr_source); + gp_debug_printf (GP_DEBUG_LOW, "canon", "canon_get_batt_status()"); + + if (!check_readiness (camera)) + return -1; + + return psa50_get_battery (camera, pwr_status, pwr_source); } #if 0 -char *camera_model_string(Camera *camera) +char * +camera_model_string (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_model_string()"); - - if (!check_readiness(camera)) - return _("Camera unavailable"); + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_model_string()"); + + if (!check_readiness (camera)) + return _("Camera unavailable"); switch (cs->model) { - case CANON_PS_A5: - return "Powershot A5"; - case CANON_PS_A5_ZOOM: - return "Powershot A5 Zoom"; - case CANON_PS_A50: - return "Powershot A50"; - case CANON_PS_A70: - return "Powershot Pro70"; - case CANON_PS_S10: - return "Powershot S10"; - case CANON_PS_S20: - return "Powershot S20"; - case CANON_PS_G1: - return "Powershot G1"; - case CANON_PS_G2: - return "Powershot G2"; - case CANON_PS_S100: - return "Powershot S100 / Digital IXUS / IXY DIGITAL"; - case CANON_PS_S300: - return "Powershot S300 / Digital IXUS 300 / IXY DIGITAL 300"; - case CANON_PS_A10: - return "Powershot A10"; - case CANON_PS_A20: - return "Powershot A20"; - case CANON_EOS_D30: - return "EOS D30"; - case CANON_PS_PRO90_IS: - return "Powershot Pro90 IS"; - default: - return _("Unknown model!"); + case CANON_PS_A5: + return "Powershot A5"; + case CANON_PS_A5_ZOOM: + return "Powershot A5 Zoom"; + case CANON_PS_A50: + return "Powershot A50"; + case CANON_PS_A70: + return "Powershot Pro70"; + case CANON_PS_S10: + return "Powershot S10"; + case CANON_PS_S20: + return "Powershot S20"; + case CANON_PS_G1: + return "Powershot G1"; + case CANON_PS_G2: + return "Powershot G2"; + case CANON_PS_S100: + return "Powershot S100 / Digital IXUS / IXY DIGITAL"; + case CANON_PS_S300: + return "Powershot S300 / Digital IXUS 300 / IXY DIGITAL 300"; + case CANON_PS_A10: + return "Powershot A10"; + case CANON_PS_A20: + return "Powershot A20"; + case CANON_EOS_D30: + return "EOS D30"; + case CANON_PS_PRO90_IS: + return "Powershot Pro90 IS"; + default: + return _("Unknown model!"); } } #endif -static int update_disk_cache(Camera *camera) +static int +update_disk_cache (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - char root[10]; /* D:\ or such */ + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + char root[10]; /* D:\ or such */ char *disk; - gp_debug_printf(GP_DEBUG_LOW,"canon","update_disk_cache()"); - - if (cs->cached_disk) return 1; - if (!check_readiness(camera)) return 0; - disk = psa50_get_disk(camera); + gp_debug_printf (GP_DEBUG_LOW, "canon", "update_disk_cache()"); + + if (cs->cached_disk) + return 1; + if (!check_readiness (camera)) + return 0; + disk = psa50_get_disk (camera); if (!disk) { - gp_camera_status(camera, _("No response")); + gp_camera_status (camera, _("No response")); return 0; } - strcpy(cs->cached_drive,disk); - sprintf(root,"%s\\",disk); - if (!psa50_disk_info(camera, root,&cs->cached_capacity,&cs->cached_available)) { - gp_camera_status(camera, _("No response")); + strcpy (cs->cached_drive, disk); + sprintf (root, "%s\\", disk); + if (!psa50_disk_info (camera, root, &cs->cached_capacity, &cs->cached_available)) { + gp_camera_status (camera, _("No response")); return 0; } cs->cached_disk = 1; - + return 1; } @@ -294,16 +331,17 @@ static int update_disk_cache(Camera *camera) * Test whether the name given corresponds * to a thumbnail (.THM) */ -static int is_thumbnail(const char *name) +static int +is_thumbnail (const char *name) { const char *pos; int res = 0; - pos = strchr(name, '.'); + pos = strchr (name, '.'); if (pos) - res = (!strcmp(pos,".THM")); + res = (!strcmp (pos, ".THM")); - gp_debug_printf(GP_DEBUG_LOW,"canon","is_thumbnail(%s) == %i", name, res); + gp_debug_printf (GP_DEBUG_LOW, "canon", "is_thumbnail(%s) == %i", name, res); return (res); } @@ -311,245 +349,264 @@ static int is_thumbnail(const char *name) * Test whether the name given corresponds * to a movie (.JPG) */ -static int is_image(const char *name) +static int +is_image (const char *name) { const char *pos; int res = 0; - pos = strchr(name,'.'); + pos = strchr (name, '.'); if (pos) - res = (!strcmp(pos,".JPG")); + res = (!strcmp (pos, ".JPG")); - gp_debug_printf(GP_DEBUG_LOW,"canon","is_image(%s) == %i", name, res); - return(res); + gp_debug_printf (GP_DEBUG_LOW, "canon", "is_image(%s) == %i", name, res); + return (res); } /* * Test whether the name given corresponds * to a movie (.AVI) */ -static int is_movie(const char *name) +static int +is_movie (const char *name) { const char *pos; int res = 0; - pos = strchr(name, '.'); - if(pos) - res = (!strcmp(pos,".AVI")); + pos = strchr (name, '.'); + if (pos) + res = (!strcmp (pos, ".AVI")); - gp_debug_printf(GP_DEBUG_LOW,"canon","is_movie(%s) == %i", name, res); - return(res); + gp_debug_printf (GP_DEBUG_LOW, "canon", "is_movie(%s) == %i", name, res); + return (res); } /* This function is only used by A5 */ -static int recurse(Camera *camera, const char *name) +static int +recurse (Camera *camera, const char *name) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - struct psa50_dir *dir,*walk; - char buffer[300]; /* longest path, etc. */ - int count,curr; - - gp_debug_printf(GP_DEBUG_LOW,"canon","recurse()"); - - dir = psa50_list_directory(camera, name); - if (!dir) return 1; /* assume it's empty @@@ */ - count = 0; - for (walk = dir; walk->name; walk++) - if (walk->size && (is_image(walk->name) || is_movie(walk->name) )) count++; - cs->cached_paths = realloc(cs->cached_paths,sizeof(char *)*(cs->cached_images+count+1)); - memset(cs->cached_paths+cs->cached_images+1,0,sizeof(char *)*count); - if (!cs->cached_paths) { - perror("realloc"); - return 0; - } - curr = cs->cached_images; - cs->cached_images += count; - for (walk = dir; walk->name; walk++) { - sprintf(buffer,"%s\\%s",name,walk->name); - if (!walk->size) { - if (!recurse(camera, buffer)) return 0; - } - else { - if ((!is_image(walk->name)) && (!is_movie(walk->name))) continue; - curr++; - cs->cached_paths[curr] = strdup(buffer); - if (!cs->cached_paths[curr]) { - perror("strdup"); - return 0; - } - } - } - free(dir); - return 1; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + struct psa50_dir *dir, *walk; + char buffer[300]; /* longest path, etc. */ + int count, curr; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "recurse()"); + + dir = psa50_list_directory (camera, name); + if (!dir) + return 1; /* assume it's empty @@@ */ + count = 0; + for (walk = dir; walk->name; walk++) + if (walk->size && (is_image (walk->name) || is_movie (walk->name))) + count++; + cs->cached_paths = + realloc (cs->cached_paths, sizeof (char *) * (cs->cached_images + count + 1)); + memset (cs->cached_paths + cs->cached_images + 1, 0, sizeof (char *) * count); + if (!cs->cached_paths) { + perror ("realloc"); + return 0; + } + curr = cs->cached_images; + cs->cached_images += count; + for (walk = dir; walk->name; walk++) { + sprintf (buffer, "%s\\%s", name, walk->name); + if (!walk->size) { + if (!recurse (camera, buffer)) + return 0; + } else { + if ((!is_image (walk->name)) && (!is_movie (walk->name))) + continue; + curr++; + cs->cached_paths[curr] = strdup (buffer); + if (!cs->cached_paths[curr]) { + perror ("strdup"); + return 0; + } + } + } + free (dir); + return 1; } -static int comp_dir(const void *a,const void *b) +static int +comp_dir (const void *a, const void *b) { - gp_debug_printf(GP_DEBUG_LOW,"canon","comp_dir()"); - - return strcmp(((const struct psa50_dir *) a)->name, - ((const struct psa50_dir *) b)->name); + gp_debug_printf (GP_DEBUG_LOW, "canon", "comp_dir()"); + + return strcmp (((const struct psa50_dir *) a)->name, + ((const struct psa50_dir *) b)->name); } /* This function is only used by A50 */ -static struct psa50_dir *dir_tree(Camera *camera, const char *path) +static struct psa50_dir * +dir_tree (Camera *camera, const char *path) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - struct psa50_dir *dir,*walk; - char buffer[300]; /* longest path, etc. */ - - gp_debug_printf(GP_DEBUG_LOW,"canon","dir_tree()"); - - dir = psa50_list_directory(camera, path); - if (!dir) return NULL; /* assume it's empty @@@ */ - for (walk = dir; walk->name; walk++) { - if (walk->is_file) { - if (is_image(walk->name) || is_movie(walk->name) || is_thumbnail(walk->name)) cs->cached_images++; - } - else { - sprintf(buffer,"%s\\%s",path,walk->name); - walk->user = dir_tree(camera, buffer); - } - } - qsort(dir,walk-dir,sizeof(*dir),comp_dir); - return dir; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + struct psa50_dir *dir, *walk; + char buffer[300]; /* longest path, etc. */ + + gp_debug_printf (GP_DEBUG_LOW, "canon", "dir_tree()"); + + dir = psa50_list_directory (camera, path); + if (!dir) + return NULL; /* assume it's empty @@@ */ + for (walk = dir; walk->name; walk++) { + if (walk->is_file) { + if (is_image (walk->name) || is_movie (walk->name) + || is_thumbnail (walk->name)) + cs->cached_images++; + } else { + sprintf (buffer, "%s\\%s", path, walk->name); + walk->user = dir_tree (camera, buffer); + } + } + qsort (dir, walk - dir, sizeof (*dir), comp_dir); + return dir; } -static void clear_dir_cache(Camera *camera) +static void +clear_dir_cache (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - - gp_debug_printf(GP_DEBUG_LOW,"canon","clear_dir_cache()"); - - psa50_free_dir(camera, cs->cached_tree); + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "clear_dir_cache()"); + + psa50_free_dir (camera, cs->cached_tree); } /* A5 only: sort THB_ and AUT_ into their proper arrangement. */ -static int compare_a5_paths (const void * p1, const void * p2) +static int +compare_a5_paths (const void *p1, const void *p2) { - const char * s1 = *((const char **)p1); - const char * s2 = *((const char **)p2); - const char * ptr, * base1, * base2; + const char *s1 = *((const char **) p1); + const char *s2 = *((const char **) p2); + const char *ptr, *base1, *base2; int n1 = 0, n2 = 0; - - gp_debug_printf(GP_DEBUG_LOW,"canon","compare_a5_paths()"); - - printf(_("Comparing %s to %s\n"), s1, s2); - - ptr = strrchr(s1, '_'); + + gp_debug_printf (GP_DEBUG_LOW, "canon", "compare_a5_paths()"); + + printf (_("Comparing %s to %s\n"), s1, s2); + + ptr = strrchr (s1, '_'); if (ptr) - n1 = strtol(ptr+1, 0, 10); - ptr = strrchr(s2, '_'); + n1 = strtol (ptr + 1, 0, 10); + ptr = strrchr (s2, '_'); if (ptr) - n2 = strtol(ptr+1, 0, 10); - - printf(_("Numbers are %d and %d\n"), n1, n2); - + n2 = strtol (ptr + 1, 0, 10); + + printf (_("Numbers are %d and %d\n"), n1, n2); + if (n1 < n2) - return -1; + return -1; else if (n1 > n2) - return 1; + return 1; else { - base1 = strrchr(s1, '\\'); - base2 = strrchr(s2, '\\'); - printf(_("Base 1 is %s and base 2 is %s\n"), base1, base2); - return strcmp(base1, base2); + base1 = strrchr (s1, '\\'); + base2 = strrchr (s2, '\\'); + printf (_("Base 1 is %s and base 2 is %s\n"), base1, base2); + return strcmp (base1, base2); } } -static int update_dir_cache(Camera *camera) +static int +update_dir_cache (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - int i; - - gp_debug_printf(GP_DEBUG_LOW,"canon","update_dir_cache()"); - - if (cs->cached_dir) return 1; - if (!update_disk_cache(camera)) return 0; - if (!check_readiness(camera)) return 0; - cs->cached_images = 0; - switch (cs->model) { - case CANON_PS_A5: - case CANON_PS_A5_ZOOM: - if (recurse(camera, cs->cached_drive)) { - printf(_("Before sort:\n")); - for (i = 1; i < cs->cached_images; i++) { - printf("%d: %s\n", i, cs->cached_paths[i]); - } - qsort(cs->cached_paths+1, cs->cached_images, sizeof(char *), compare_a5_paths); - printf(_("After sort:\n")); - for (i = 1; i < cs->cached_images; i++) { - printf("%d: %s\n", i, cs->cached_paths[i]); - } - cs->cached_dir = 1; - return 1; - } - clear_dir_cache(camera); - return 0; - break; - - default: /* A50 or S10 or other */ - cs->cached_tree = dir_tree(camera, cs->cached_drive); - if (!cs->cached_tree) return 0; - cs->cached_dir = 1; - return 1; - break; - } + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + int i; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "update_dir_cache()"); + + if (cs->cached_dir) + return 1; + if (!update_disk_cache (camera)) + return 0; + if (!check_readiness (camera)) + return 0; + cs->cached_images = 0; + switch (cs->model) { + case CANON_PS_A5: + case CANON_PS_A5_ZOOM: + if (recurse (camera, cs->cached_drive)) { + printf (_("Before sort:\n")); + for (i = 1; i < cs->cached_images; i++) { + printf ("%d: %s\n", i, cs->cached_paths[i]); + } + qsort (cs->cached_paths + 1, cs->cached_images, + sizeof (char *), compare_a5_paths); + printf (_("After sort:\n")); + for (i = 1; i < cs->cached_images; i++) { + printf ("%d: %s\n", i, cs->cached_paths[i]); + } + cs->cached_dir = 1; + return 1; + } + clear_dir_cache (camera); + return 0; + break; + + default: /* A50 or S10 or other */ + cs->cached_tree = dir_tree (camera, cs->cached_drive); + if (!cs->cached_tree) + return 0; + cs->cached_dir = 1; + return 1; + break; + } } -static int _canon_file_list (struct psa50_dir *tree, const char *folder, - CameraList *list) +static int +_canon_file_list (struct psa50_dir *tree, const char *folder, CameraList * list) { - if (!tree) { + if (!tree) { // debug_message(camera,"no directory listing available!\n"); - return GP_ERROR; - } - - while (tree->name) { - if(is_image(tree->name) || is_movie(tree->name)) { - gp_list_append(list,(char*)tree->name, NULL); - } else if (!tree->is_file) { - _canon_file_list(tree->user, folder, list); - } - tree++; - } - - return GP_OK; + return GP_ERROR; + } + + while (tree->name) { + if (is_image (tree->name) || is_movie (tree->name)) { + gp_list_append (list, (char *) tree->name, NULL); + } else if (!tree->is_file) { + _canon_file_list (tree->user, folder, list); + } + tree++; + } + + return GP_OK; } -static int canon_file_list (Camera *camera, const char *folder, - CameraList *list) +static int +canon_file_list (Camera *camera, const char *folder, CameraList * list) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_file_list()"); - - if(!update_dir_cache(camera)) { - gp_camera_status(camera, _("Could not obtain directory listing")); - return GP_ERROR; - } - - _canon_file_list(cs->cached_tree, folder, list); - return GP_OK; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "canon_file_list()"); + + if (!update_dir_cache (camera)) { + gp_camera_status (camera, _("Could not obtain directory listing")); + return GP_ERROR; + } + + _canon_file_list (cs->cached_tree, folder, list); + return GP_OK; } -int camera_folder_list_files (Camera *camera, const char *folder, - CameraList *list) +int +camera_folder_list_files (Camera *camera, const char *folder, CameraList * list) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_file_list()"); + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_file_list()"); - return canon_file_list(camera, folder, list); + return canon_file_list (camera, folder, list); } /**************************************************************************** @@ -562,244 +619,261 @@ int camera_folder_list_files (Camera *camera, const char *folder, #define JPEG_END 0xFFFFFFD9 #define JPEG_ESC 0xFFFFFFFF -static char *canon_get_picture (Camera *camera, char *filename, - char *path, int thumbnail, int *size) +static char * +canon_get_picture (Camera *camera, char *filename, char *path, int thumbnail, int *size) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - char *image; - char attribs; - char file[300]; - void *ptr; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + char *image; + char attribs; + char file[300]; + void *ptr; int j; - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_get_picture()"); - - if (!check_readiness(camera)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "canon_get_picture()"); + + if (!check_readiness (camera)) { return NULL; - } - switch (cs->model) { - case CANON_PS_A5: - case CANON_PS_A5_ZOOM: + } + switch (cs->model) { + case CANON_PS_A5: + case CANON_PS_A5_ZOOM: #if 0 - picture_number=picture_number*2-1; - if (thumbnail) picture_number+=1; - gp_debug_printf(GP_DEBUG_LOW,"canon",_("Picture number %d\n"),picture_number); - - image = malloc(sizeof(*image)); - if (!image) { - perror("malloc"); - return NULL; - } - memset(image,0,sizeof(*image)); - if (!picture_number || picture_number > cached_images) { - gp_camera_status(camera, _("Invalid index")); - free(image); - return NULL; - } - gp_camera_status(camera, cached_paths[picture_number]); - if (!check_readiness(camera)) { - free(image); - return NULL; - } - image = psa50_get_file(cached_paths[picture_number], size); - if (image) return image; - free(image); + picture_number = picture_number * 2 - 1; + if (thumbnail) + picture_number += 1; + gp_debug_printf (GP_DEBUG_LOW, "canon", _("Picture number %d\n"), + picture_number); + + image = malloc (sizeof (*image)); + if (!image) { + perror ("malloc"); + return NULL; + } + memset (image, 0, sizeof (*image)); + if (!picture_number || picture_number > cached_images) { + gp_camera_status (camera, _("Invalid index")); + free (image); + return NULL; + } + gp_camera_status (camera, cached_paths[picture_number]); + if (!check_readiness (camera)) { + free (image); + return NULL; + } + image = psa50_get_file (cached_paths[picture_number], size); + if (image) + return image; + free (image); #endif - return NULL; - break; - default: - /* For A50 or others */ - /* clear_readiness(); */ - if (!update_dir_cache(camera)) { - gp_camera_status(camera, _("Could not obtain directory listing")); - return 0; - } - image = malloc(sizeof(*image)); - if (!image) { - perror("malloc"); - return NULL; - } - memset(image,0,sizeof(*image)); - - sprintf(file,"%s%s",path,filename); - gp_debug_printf(GP_DEBUG_LOW,"canon", "canon_get_picture: file = %s\n\tpath=%s, filename=%s\n", - file,path,filename); - attribs = 0; - if (!check_readiness(camera)) { - free(image); return NULL; - } - if (thumbnail) { - ptr=image; - /* The thumbnail of a movie in on a file called MVI_XXXX.THM - * we replace .AVI by .THM to download the thumbnail (jpeg format) - */ - if (is_movie(filename)) { - char *thumbfile = strdup(filename); - j = strrchr(thumbfile,'.') - thumbfile; - thumbfile[j+1]='\0'; - strcat(thumbfile,"THM"); - sprintf(file,"%s%s",path,thumbfile); - free(thumbfile); - printf("movie thumbnail: %s\n",file); - image = psa50_get_file(camera, file, size); + break; + default: + /* For A50 or others */ + /* clear_readiness(); */ + if (!update_dir_cache (camera)) { + gp_camera_status (camera, + _("Could not obtain directory listing")); + return 0; + } + image = malloc (sizeof (*image)); + if (!image) { + perror ("malloc"); + return NULL; + } + memset (image, 0, sizeof (*image)); + + sprintf (file, "%s%s", path, filename); + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_get_picture: file = %s\n\tpath=%s, filename=%s\n", + file, path, filename); + attribs = 0; + if (!check_readiness (camera)) { + free (image); + return NULL; + } + if (thumbnail) { + ptr = image; + /* The thumbnail of a movie in on a file called MVI_XXXX.THM + * we replace .AVI by .THM to download the thumbnail (jpeg format) + */ + if (is_movie (filename)) { + char *thumbfile = strdup (filename); + + j = strrchr (thumbfile, '.') - thumbfile; + thumbfile[j + 1] = '\0'; + strcat (thumbfile, "THM"); + sprintf (file, "%s%s", path, thumbfile); + free (thumbfile); + printf ("movie thumbnail: %s\n", file); + image = psa50_get_file (camera, file, size); + } else { + image = psa50_get_thumbnail (camera, file, size); + } + + free (ptr); + if (image) + return image; + return NULL; } else { - image = psa50_get_thumbnail(camera, file, size); + image = psa50_get_file (camera, file, size); + if (image) { + j = strrchr (path, '\\') - path; + path[j] = '\0'; + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_get_picture: We now have to set the \"downloaded\" flag on the picture\n"); + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_get_picture: The old file attributes were: %#x\n", + attribs); + attribs = attribs & 0xdf; // 0xdf = !0x20 + psa50_set_file_attributes (camera, filename, path, + attribs); + } else { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_get_picture: psa50_get_file() failed!"); + } } - - free(ptr); if (image) return image; + //if(receive_error==FATAL_ERROR) clear_readiness(); + free (image); return NULL; - } - else { - image = psa50_get_file(camera, file,size); - if (image) { - j = strrchr(path, '\\') - path; - path[j] = '\0'; - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_get_picture: We now have to set the \"downloaded\" flag on the picture\n"); - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_get_picture: The old file attributes were: %#x\n",attribs); - attribs = attribs & 0xdf; // 0xdf = !0x20 - psa50_set_file_attributes(camera,filename,path,attribs); - } else { - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_get_picture: psa50_get_file() failed!"); - } - } - if (image) - return image; - //if(receive_error==FATAL_ERROR) clear_readiness(); - free(image); - return NULL; - break; - } - /* NOT REACHED */ - return NULL; + break; + } + /* NOT REACHED */ + return NULL; } -static int _get_file_path (struct psa50_dir *tree, const char *filename, - char *path) +static int +_get_file_path (struct psa50_dir *tree, const char *filename, char *path) { - if (tree==NULL) return GP_ERROR; - - if (canon_comm_method != CANON_USB) { - path = strchr(path,0); + if (tree == NULL) + return GP_ERROR; + + if (canon_comm_method != CANON_USB) { + path = strchr (path, 0); *path = '\\'; } - while(tree->name) { - if (!is_image(tree->name) && !is_movie(tree->name) && !is_thumbnail(tree->name)) { - switch(canon_comm_method) { - case CANON_USB: - strcpy(path,tree->name); - break; - case CANON_SERIAL_RS232: - default: - strcpy(path+1,tree->name); - break; + while (tree->name) { + if (!is_image (tree->name) && !is_movie (tree->name) + && !is_thumbnail (tree->name)) { + switch (canon_comm_method) { + case CANON_USB: + strcpy (path, tree->name); + break; + case CANON_SERIAL_RS232: + default: + strcpy (path + 1, tree->name); + break; } } - if ((is_image(tree->name) || (is_movie(tree->name) || is_thumbnail(tree->name))) && strcmp(tree->name,filename)==0) { + if ((is_image (tree->name) + || (is_movie (tree->name) || is_thumbnail (tree->name))) + && strcmp (tree->name, filename) == 0) { return GP_OK; - } - else if (!tree->is_file) { - if (_get_file_path (tree->user,filename, path) == GP_OK) - return GP_OK; + } else if (!tree->is_file) { + if (_get_file_path (tree->user, filename, path) == GP_OK) + return GP_OK; } tree++; } - - return GP_ERROR; + + return GP_ERROR; } -static int get_file_path (Camera *camera, const char *filename, - const char *path) +static int +get_file_path (Camera *camera, const char *filename, const char *path) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; - gp_debug_printf(GP_DEBUG_LOW,"canon","get_file_path()"); - - return _get_file_path (cs->cached_tree, filename, (char*) path); + gp_debug_printf (GP_DEBUG_LOW, "canon", "get_file_path()"); + + return _get_file_path (cs->cached_tree, filename, (char *) path); } -int camera_file_get (Camera *camera, const char *folder, const char *filename, - CameraFileType type, CameraFile *file) +int +camera_file_get (Camera *camera, const char *folder, const char *filename, + CameraFileType type, CameraFile * file) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; char *data; - int buflen,i,j, size; - char path[300]={0}, tempfilename[300]={0}; + int buflen, i, j, size; + char path[300] = { 0 }, tempfilename[300] = + { + 0}; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_file_get()"); - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_file_get()"); - - if(check_readiness(camera) != 1) - return GP_ERROR; + if (check_readiness (camera) != 1) + return GP_ERROR; - strcpy(path, cs->cached_drive); + strcpy (path, cs->cached_drive); /* update file cache (if necessary) first */ - if(!update_dir_cache(camera)) { - gp_camera_status(camera, _("Could not obtain directory listing")); + if (!update_dir_cache (camera)) { + gp_camera_status (camera, _("Could not obtain directory listing")); return GP_ERROR; } - - if (get_file_path(camera, filename,path) == GP_ERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Filename '%s' path '%s' not found!\n", filename, path); + + if (get_file_path (camera, filename, path) == GP_ERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "Filename '%s' path '%s' not found!\n", + filename, path); return GP_ERROR; } if (canon_comm_method != CANON_USB) { - j = strrchr(path,'\\') - path; - path[j+1] = '\0'; + j = strrchr (path, '\\') - path; + path[j + 1] = '\0'; } else { - j = strchr(path,'\0') - path; - path[j] = '\\'; - path[j+1] = '\0'; + j = strchr (path, '\0') - path; + path[j] = '\\'; + path[j + 1] = '\0'; } switch (type) { - case GP_FILE_TYPE_NORMAL: - data = canon_get_picture (camera, (char*) filename, - (char*) path, 0, &buflen); - break; - case GP_FILE_TYPE_PREVIEW: - data = canon_get_picture (camera, (char*) filename, - (char*) path, 1, &buflen); - break; - default: - return (GP_ERROR_NOT_SUPPORTED); + case GP_FILE_TYPE_NORMAL: + data = canon_get_picture (camera, (char *) filename, + (char *) path, 0, &buflen); + break; + case GP_FILE_TYPE_PREVIEW: + data = canon_get_picture (camera, (char *) filename, + (char *) path, 1, &buflen); + break; + default: + return (GP_ERROR_NOT_SUPPORTED); } if (!data) return GP_ERROR; switch (type) { - case GP_FILE_TYPE_PREVIEW: - /* we count the byte returned until the end of the jpeg data - which is FF D9 */ - /* It would be prettier to get that info from the exif tags */ - for(size=1;size<buflen;size++) - if((data[size-1]==JPEG_ESC) && (data[size]==JPEG_END)) - break; - buflen = size+1; - gp_file_set_data_and_size (file, data, buflen); - gp_file_set_mime_type (file, "image/jpeg"); /* always */ - strcpy(tempfilename, filename); - strcat(tempfilename, "\0"); - strcpy(tempfilename+strlen("IMG_XXXX"), ".JPG\0"); - gp_file_set_name (file, tempfilename); - break; - case GP_FILE_TYPE_NORMAL: - if (is_movie(filename)) - gp_file_set_mime_type (file, "video/x-msvideo"); - else - gp_file_set_mime_type (file, "image/jpeg"); - gp_file_set_data_and_size (file, data, buflen); - gp_file_set_name (file, filename); - break; - default: - return (GP_ERROR_NOT_SUPPORTED); + case GP_FILE_TYPE_PREVIEW: + /* we count the byte returned until the end of the jpeg data + which is FF D9 */ + /* It would be prettier to get that info from the exif tags */ + for (size = 1; size < buflen; size++) + if ((data[size - 1] == JPEG_ESC) && (data[size] == JPEG_END)) + break; + buflen = size + 1; + gp_file_set_data_and_size (file, data, buflen); + gp_file_set_mime_type (file, "image/jpeg"); /* always */ + strcpy (tempfilename, filename); + strcat (tempfilename, "\0"); + strcpy (tempfilename + strlen ("IMG_XXXX"), ".JPG\0"); + gp_file_set_name (file, tempfilename); + break; + case GP_FILE_TYPE_NORMAL: + if (is_movie (filename)) + gp_file_set_mime_type (file, "video/x-msvideo"); + else + gp_file_set_mime_type (file, "image/jpeg"); + gp_file_set_data_and_size (file, data, buflen); + gp_file_set_name (file, filename); + break; + default: + return (GP_ERROR_NOT_SUPPORTED); } return GP_OK; @@ -808,496 +882,535 @@ int camera_file_get (Camera *camera, const char *folder, const char *filename, /****************************************************************************/ -static void pretty_number(int number,char *buffer) +static void +pretty_number (int number, char *buffer) { - int len,tmp,digits; - char *pos; - - len = 0; - tmp = number; - do { - len++; - tmp /= 10; - } - while (tmp); - len += (len-1)/3; - pos = buffer+len; - *pos = 0; - digits = 0; - do { - *--pos = (number % 10)+'0'; - number /= 10; - if (++digits == 3) { - *--pos = '\''; - digits = 0; - } - } - while (number); + int len, tmp, digits; + char *pos; + + len = 0; + tmp = number; + do { + len++; + tmp /= 10; + } + while (tmp); + len += (len - 1) / 3; + pos = buffer + len; + *pos = 0; + digits = 0; + do { + *--pos = (number % 10) + '0'; + number /= 10; + if (++digits == 3) { + *--pos = '\''; + digits = 0; + } + } + while (number); } -int camera_summary(Camera *camera, CameraText *summary) +int +camera_summary (Camera *camera, CameraText * summary) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - char a[20],b[20]; - char *model; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + char a[20], b[20]; + char *model; int pwr_source, pwr_status; char power_stats[48], cde[16]; - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_summary()"); - - if(check_readiness(camera) != 1) - return GP_ERROR; - - /*clear_readiness();*/ - if (!update_disk_cache(camera)) return GP_ERROR; - - pretty_number(cs->cached_capacity,a); - pretty_number(cs->cached_available,b); - + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_summary()"); + + if (check_readiness (camera) != 1) + return GP_ERROR; + + /*clear_readiness(); */ + if (!update_disk_cache (camera)) + return GP_ERROR; + + pretty_number (cs->cached_capacity, a); + pretty_number (cs->cached_available, b); + model = "Canon Powershot"; - switch (cs->model) { - case CANON_PS_A5: model = "Canon Powershot A5"; break; - case CANON_PS_A5_ZOOM: model = "Canon Powershot A5 Zoom"; break; - case CANON_PS_A50: model = "Canon Powershot A50"; break; - case CANON_PS_A70: model = "Canon Powershot A70"; break; - case CANON_PS_S10: model = "Canon Powershot S10"; break; - case CANON_PS_S20: model = "Canon Powershot S20"; break; - case CANON_PS_G1: model = "Canon Powershot G1"; break; - case CANON_PS_G2: model = "Canon Powershot G2"; break; - case CANON_PS_S100: model = "Canon Powershot S100 / Digital IXUS / IXY DIGITAL"; break; - case CANON_PS_S300: model = "Canon Powershot S300 / Digital IXUS 300 / IXY DIGITAL 300"; break; - case CANON_PS_A10: model = "Canon Powershot A10"; break; - case CANON_PS_A20: model = "Canon Powershot A20"; break; - case CANON_EOS_D30: model = "Canon EOS D30"; break; - case CANON_PS_PRO90_IS: model = "Canon Pro90 IS"; break; - } - - canon_get_batt_status(camera, &pwr_status, &pwr_source); + switch (cs->model) { + case CANON_PS_A5: + model = "Canon Powershot A5"; + break; + case CANON_PS_A5_ZOOM: + model = "Canon Powershot A5 Zoom"; + break; + case CANON_PS_A50: + model = "Canon Powershot A50"; + break; + case CANON_PS_A70: + model = "Canon Powershot A70"; + break; + case CANON_PS_S10: + model = "Canon Powershot S10"; + break; + case CANON_PS_S20: + model = "Canon Powershot S20"; + break; + case CANON_PS_G1: + model = "Canon Powershot G1"; + break; + case CANON_PS_G2: + model = "Canon Powershot G2"; + break; + case CANON_PS_S100: + model = "Canon Powershot S100 / Digital IXUS / IXY DIGITAL"; + break; + case CANON_PS_S300: + model = "Canon Powershot S300 / Digital IXUS 300 / IXY DIGITAL 300"; + break; + case CANON_PS_A10: + model = "Canon Powershot A10"; + break; + case CANON_PS_A20: + model = "Canon Powershot A20"; + break; + case CANON_EOS_D30: + model = "Canon EOS D30"; + break; + case CANON_PS_PRO90_IS: + model = "Canon Pro90 IS"; + break; + } + + canon_get_batt_status (camera, &pwr_status, &pwr_source); switch (pwr_source) { - case CAMERA_ON_AC: - strcpy(power_stats, _("AC adapter ")); - break; - case CAMERA_ON_BATTERY: - strcpy(power_stats, _("on battery ")); - break; - default: - sprintf(power_stats,_("unknown (%i"),pwr_source); - break; + case CAMERA_ON_AC: + strcpy (power_stats, _("AC adapter ")); + break; + case CAMERA_ON_BATTERY: + strcpy (power_stats, _("on battery ")); + break; + default: + sprintf (power_stats, _("unknown (%i"), pwr_source); + break; } - + switch (pwr_status) { - case CAMERA_POWER_OK: - strcat(power_stats, _("(power OK)")); - break; - case CAMERA_POWER_BAD: - strcat(power_stats, _("(power low)")); - break; - default: - strcat(power_stats,cde); - sprintf(cde," - %i)",pwr_status); - break; + case CAMERA_POWER_OK: + strcat (power_stats, _("(power OK)")); + break; + case CAMERA_POWER_BAD: + strcat (power_stats, _("(power low)")); + break; + default: + strcat (power_stats, cde); + sprintf (cde, " - %i)", pwr_status); + break; } - - sprintf(summary->text,_("%s\n%s\n%s\nDrive %s\n%11s bytes total\n%11s bytes available\n"), - model, cs->owner,power_stats,cs->cached_drive,a,b); - return GP_OK; + + sprintf (summary->text, + _("%s\n%s\n%s\nDrive %s\n%11s bytes total\n%11s bytes available\n"), model, + cs->owner, power_stats, cs->cached_drive, a, b); + return GP_OK; } /****************************************************************************/ -int camera_about(Camera *camera, CameraText *about) +int +camera_about (Camera *camera, CameraText * about) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_about()"); - - strcpy(about->text, - _("Canon PowerShot series driver by\n" - "Wolfgang G. Reissnegger,\n" - "Werner Almesberger,\n" - "Edouard Lafargue,\n" - "Philippe Marzouk,\n" - "A5 additions by Ole W. Saastad\n" - "Holger Klemm\n") - ); + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_about()"); + + strcpy (about->text, + _("Canon PowerShot series driver by\n" + "Wolfgang G. Reissnegger,\n" + "Werner Almesberger,\n" + "Edouard Lafargue,\n" + "Philippe Marzouk,\n" "A5 additions by Ole W. Saastad\n" "Holger Klemm\n") + ); return GP_OK; } /****************************************************************************/ -int camera_file_delete (Camera *camera, const char *folder, - const char *filename) +int +camera_file_delete (Camera *camera, const char *folder, const char *filename) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; char path[300], thumbname[300]; int j; - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_file_delete()"); - + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_file_delete()"); + // initialize memory to avoid problems later - for (j=0; j < sizeof(path); j++) - path[j] = '\0'; - memset(thumbname, 0, sizeof(thumbname)); - - if(check_readiness(camera) != 1) - return GP_ERROR; - - if (!(cs->model == CANON_PS_A5 || - cs->model == CANON_PS_A5_ZOOM)) { /* Tested only on powershot A50 */ - - if (!update_dir_cache(camera)) { - gp_camera_status(camera, _("Could not obtain directory listing")); - return 0; - } - strcpy(path, cs->cached_drive); - - if (get_file_path(camera,filename,path) == GP_ERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Filename not found!\n"); - return GP_ERROR; - } + for (j = 0; j < sizeof (path); j++) + path[j] = '\0'; + memset (thumbname, 0, sizeof (thumbname)); + + if (check_readiness (camera) != 1) + return GP_ERROR; + + if (!(cs->model == CANON_PS_A5 || cs->model == CANON_PS_A5_ZOOM)) { /* Tested only on powershot A50 */ + + if (!update_dir_cache (camera)) { + gp_camera_status (camera, _("Could not obtain directory listing")); + return 0; + } + strcpy (path, cs->cached_drive); + + if (get_file_path (camera, filename, path) == GP_ERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "Filename not found!\n"); + return GP_ERROR; + } if (canon_comm_method != CANON_USB) { - j = strrchr(path,'\\') - path; + j = strrchr (path, '\\') - path; path[j] = '\0'; } else { - j = strchr(path,'\0') - path; + j = strchr (path, '\0') - path; path[j] = '\0'; -// path[j+1] = '\0'; +// path[j+1] = '\0'; } - fprintf(stderr,"filename: %s\n path: %s\n",filename,path); - if (psa50_delete_file(camera, filename,path)) { - gp_camera_status(camera, _("error deleting file")); - return GP_ERROR; - } - else { - /* If we have a movie, delete its thumbnail as well */ - if (is_movie(filename)) { - strcpy(thumbname, filename); - strcpy(thumbname+strlen("MVI_XXXX"), ".THM\0"); - if (psa50_delete_file(camera, thumbname, path)) { - gp_camera_status(camera, _("error deleting thumbnail")); - return GP_ERROR; + fprintf (stderr, "filename: %s\n path: %s\n", filename, path); + if (psa50_delete_file (camera, filename, path)) { + gp_camera_status (camera, _("error deleting file")); + return GP_ERROR; + } else { + /* If we have a movie, delete its thumbnail as well */ + if (is_movie (filename)) { + strcpy (thumbname, filename); + strcpy (thumbname + strlen ("MVI_XXXX"), ".THM\0"); + if (psa50_delete_file (camera, thumbname, path)) { + gp_camera_status (camera, + _("error deleting thumbnail")); + return GP_ERROR; + } } + return GP_OK; } - return GP_OK; - } - } - return GP_ERROR; + } + return GP_ERROR; } /****************************************************************************/ -static int _get_last_dir(struct psa50_dir *tree, char *path, char *temppath) +static int +_get_last_dir (struct psa50_dir *tree, char *path, char *temppath) { - if (tree==NULL) return GP_ERROR; - - if (canon_comm_method != CANON_USB) { - path = strchr(path,0); + if (tree == NULL) + return GP_ERROR; + + if (canon_comm_method != CANON_USB) { + path = strchr (path, 0); *path = '\\'; } - while(tree->name) { - if (!is_image(tree->name) && !is_movie(tree->name) && !is_thumbnail(tree->name)) { - switch(canon_comm_method) { - case CANON_USB: - strcpy(path,tree->name); - break; - case CANON_SERIAL_RS232: - default: - strcpy(path+1,tree->name); - break; + while (tree->name) { + if (!is_image (tree->name) && !is_movie (tree->name) + && !is_thumbnail (tree->name)) { + switch (canon_comm_method) { + case CANON_USB: + strcpy (path, tree->name); + break; + case CANON_SERIAL_RS232: + default: + strcpy (path + 1, tree->name); + break; } } - + if (!tree->is_file) { - if((strcmp(path+4,"CANON")==0) && (strcmp(temppath,path)<0)) - strcpy(temppath,path); - _get_last_dir(tree->user,path,temppath); + if ((strcmp (path + 4, "CANON") == 0) && (strcmp (temppath, path) < 0)) + strcpy (temppath, path); + _get_last_dir (tree->user, path, temppath); } tree++; } - - strcpy(path,temppath); - - return GP_OK; + + strcpy (path, temppath); + + return GP_OK; } /* * get from the cache the name of the highest numbered directory * */ -static int get_last_dir(Camera *camera, char *path) +static int +get_last_dir (Camera *camera, char *path) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; char temppath[300]; - gp_debug_printf(GP_DEBUG_LOW,"canon","get_last_dir()"); - - strncpy(temppath, path, sizeof(temppath)); - - return _get_last_dir(cs->cached_tree, path, temppath); + gp_debug_printf (GP_DEBUG_LOW, "canon", "get_last_dir()"); + + strncpy (temppath, path, sizeof (temppath)); + + return _get_last_dir (cs->cached_tree, path, temppath); } -static int _get_last_picture(struct psa50_dir *tree, char *directory, char *filename) +static int +_get_last_picture (struct psa50_dir *tree, char *directory, char *filename) { - if (tree==NULL) return GP_ERROR; + if (tree == NULL) + return GP_ERROR; - while(tree->name) { + while (tree->name) { - if (is_image(tree->name) || is_movie(tree->name) || is_thumbnail(tree->name)) { - if(strcmp(tree->name,filename)>0) - strcpy(filename,tree->name); + if (is_image (tree->name) || is_movie (tree->name) + || is_thumbnail (tree->name)) { + if (strcmp (tree->name, filename) > 0) + strcpy (filename, tree->name); } - + if (!tree->is_file) { - if((strcmp(tree->name,"DCIM")==0) || (strcmp(tree->name,directory)==0)) { - _get_last_picture(tree->user,directory,filename); + if ((strcmp (tree->name, "DCIM") == 0) + || (strcmp (tree->name, directory) == 0)) { + _get_last_picture (tree->user, directory, filename); } } - + tree++; } - - return GP_OK; + + return GP_OK; } /* * get from the cache the name of the highest numbered picture * */ -static int get_last_picture(Camera *camera, char *directory, char *filename) +static int +get_last_picture (Camera *camera, char *directory, char *filename) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "get_last_picture()"); - gp_debug_printf(GP_DEBUG_LOW,"canon","get_last_picture()"); - - return _get_last_picture(cs->cached_tree, directory, filename); + return _get_last_picture (cs->cached_tree, directory, filename); } -int camera_folder_put_file (Camera *camera, const char *folder, - CameraFile *file) +int +camera_folder_put_file (Camera *camera, const char *folder, CameraFile * file) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - char destpath[300], destname[300], dir[300], dcf_root_dir[10]; - int j, dirnum=0; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + char destpath[300], destname[300], dir[300], dcf_root_dir[10]; + int j, dirnum = 0; char buf[10]; - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_folder_put_file()"); - - if(check_readiness(camera) != 1) - return GP_ERROR; - - if (cs->speed>57600 && - (strcmp(camera->model,"Canon PowerShot A50") == 0 - || strcmp(camera->model, "Canon PowerShot Pro70") == 0)) { - gp_camera_message(camera, - _("Speeds greater than 57600 are not supported for uploading to this camera")); + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_folder_put_file()"); + + if (check_readiness (camera) != 1) + return GP_ERROR; + + if (cs->speed > 57600 && + (strcmp (camera->model, "Canon PowerShot A50") == 0 + || strcmp (camera->model, "Canon PowerShot Pro70") == 0)) { + gp_camera_message (camera, + _ + ("Speeds greater than 57600 are not supported for uploading to this camera")); return GP_ERROR; } - - if (!check_readiness(camera)) { + + if (!check_readiness (camera)) { return GP_ERROR; } - - for (j=0; j < sizeof(destpath); j++) { + + for (j = 0; j < sizeof (destpath); j++) { destpath[j] = '\0'; dir[j] = '\0'; - destname [j] = '\0'; + destname[j] = '\0'; } - if(!update_dir_cache(camera)) { - gp_camera_status(camera, _("Could not obtain directory listing")); - return GP_ERROR; - } + if (!update_dir_cache (camera)) { + gp_camera_status (camera, _("Could not obtain directory listing")); + return GP_ERROR; + } - sprintf(dcf_root_dir,"%s\\DCIM",cs->cached_drive); + sprintf (dcf_root_dir, "%s\\DCIM", cs->cached_drive); - if(get_last_dir(camera, dir) == GP_ERROR) - return GP_ERROR; + if (get_last_dir (camera, dir) == GP_ERROR) + return GP_ERROR; - if(strlen(dir)==0) { - sprintf(dir,"\\100CANON"); - sprintf(destname, "AUT_0001.JPG"); - } - else { - if (get_last_picture(camera,dir+1,destname)==GP_ERROR) - return GP_ERROR; - - if(strlen(destname)==0) { - sprintf(destname,"AUT_%c%c01.JPG",dir[2],dir[3]); - } - else { - sprintf(buf, "%c%c",destname[6],destname[7]); + if (strlen (dir) == 0) { + sprintf (dir, "\\100CANON"); + sprintf (destname, "AUT_0001.JPG"); + } else { + if (get_last_picture (camera, dir + 1, destname) == GP_ERROR) + return GP_ERROR; + + if (strlen (destname) == 0) { + sprintf (destname, "AUT_%c%c01.JPG", dir[2], dir[3]); + } else { + sprintf (buf, "%c%c", destname[6], destname[7]); j = 1; - j = atoi(buf); - if (j==99) { - j=1; - sprintf(buf,"%c%c%c",dir[1],dir[2],dir[3]); - dirnum = atoi(buf); + j = atoi (buf); + if (j == 99) { + j = 1; + sprintf (buf, "%c%c%c", dir[1], dir[2], dir[3]); + dirnum = atoi (buf); if (dirnum == 999) { - gp_camera_message(camera,_("Could not upload, no free folder name available!\n" - "999CANON folder name exists and has an AUT_9999.JPG picture in it.")); + gp_camera_message (camera, + _ + ("Could not upload, no free folder name available!\n" + "999CANON folder name exists and has an AUT_9999.JPG picture in it.")); return GP_ERROR; - } - else { + } else { dirnum++; - sprintf(dir,"\\%03iCANON", dirnum); + sprintf (dir, "\\%03iCANON", dirnum); } - } - else - j++; - - sprintf(destname,"AUT_%c%c%02i.JPG",dir[2],dir[3],j); + } else + j++; + + sprintf (destname, "AUT_%c%c%02i.JPG", dir[2], dir[3], j); } - - sprintf(destpath,"%s%s",dcf_root_dir,dir); - - gp_debug_printf(GP_DEBUG_LOW,"canon","destpath: %s destname: %s\n",destpath,destname); + + sprintf (destpath, "%s%s", dcf_root_dir, dir); + + gp_debug_printf (GP_DEBUG_LOW, "canon", "destpath: %s destname: %s\n", + destpath, destname); } - - if(!psa50_directory_operations(camera, dcf_root_dir, DIR_CREATE)) { - gp_camera_message(camera,"could not create \\DCIM directory"); + + if (!psa50_directory_operations (camera, dcf_root_dir, DIR_CREATE)) { + gp_camera_message (camera, "could not create \\DCIM directory"); return GP_ERROR; } - - if(!psa50_directory_operations(camera,destpath, DIR_CREATE)) { - gp_camera_message(camera,"could not create destination directory"); + + if (!psa50_directory_operations (camera, destpath, DIR_CREATE)) { + gp_camera_message (camera, "could not create destination directory"); return GP_ERROR; } - - j = strlen(destpath); + + j = strlen (destpath); destpath[j] = '\\'; - destpath[j+1] = '\0'; - - clear_readiness(camera); - - return psa50_put_file(camera,file, destname, destpath); + destpath[j + 1] = '\0'; + + clear_readiness (camera); + + return psa50_put_file (camera, file, destname, destpath); } /****************************************************************************/ - -int camera_get_config (Camera *camera, CameraWidget **window) + +int +camera_get_config (Camera *camera, CameraWidget ** window) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; CameraWidget *t, *section; - char power_stats[48], firm[64]; + char power_stats[48], firm[64]; int pwr_status, pwr_source; struct tm *camtm; time_t camtime; - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_get_config()"); - - gp_widget_new (GP_WIDGET_WINDOW, "Canon PowerShot Configuration", - window); + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_get_config()"); + + gp_widget_new (GP_WIDGET_WINDOW, "Canon PowerShot Configuration", window); gp_widget_new (GP_WIDGET_SECTION, _("Configure"), §ion); - gp_widget_append (*window,section); - - gp_widget_new (GP_WIDGET_TEXT,_("Camera Model"), &t); + gp_widget_append (*window, section); + + gp_widget_new (GP_WIDGET_TEXT, _("Camera Model"), &t); gp_widget_set_value (t, cs->ident); - gp_widget_append (section,t); + gp_widget_append (section, t); - gp_widget_new (GP_WIDGET_TEXT,_("Owner name"), &t); + gp_widget_new (GP_WIDGET_TEXT, _("Owner name"), &t); gp_widget_set_value (t, cs->owner); - gp_widget_append (section,t); + gp_widget_append (section, t); gp_widget_new (GP_WIDGET_TEXT, "date", &t); if (cs->cached_ready == 1) { - camtime = psa50_get_time(camera); - if (camtime != GP_ERROR) { - camtm = gmtime(&camtime); - gp_widget_set_value (t, asctime(camtm)); - } else - gp_widget_set_value (t, _("Error")); + camtime = psa50_get_time (camera); + if (camtime != GP_ERROR) { + camtm = gmtime (&camtime); + gp_widget_set_value (t, asctime (camtm)); + } else + gp_widget_set_value (t, _("Error")); } else - gp_widget_set_value (t, _("Unavailable")); - gp_widget_append (section,t); - + gp_widget_set_value (t, _("Unavailable")); + gp_widget_append (section, t); + gp_widget_new (GP_WIDGET_TOGGLE, _("Set camera date to PC date"), &t); - gp_widget_append (section,t); - - gp_widget_new (GP_WIDGET_TEXT,_("Firmware revision"), &t); - sprintf (firm,"%i.%i.%i.%i",cs->firmwrev[3], - cs->firmwrev[2],cs->firmwrev[1], - cs->firmwrev[0]); + gp_widget_append (section, t); + + gp_widget_new (GP_WIDGET_TEXT, _("Firmware revision"), &t); + sprintf (firm, "%i.%i.%i.%i", cs->firmwrev[3], + cs->firmwrev[2], cs->firmwrev[1], cs->firmwrev[0]); gp_widget_set_value (t, firm); - gp_widget_append (section,t); - + gp_widget_append (section, t); + if (cs->cached_ready == 1) { - canon_get_batt_status(camera, &pwr_status,&pwr_source); + canon_get_batt_status (camera, &pwr_status, &pwr_source); switch (pwr_source) { - case CAMERA_ON_AC: - strcpy(power_stats, _("AC adapter ")); - break; - case CAMERA_ON_BATTERY: - strcpy(power_stats, _("on battery ")); - break; - default: - sprintf(power_stats,_("unknown (%i"),pwr_source); - break; + case CAMERA_ON_AC: + strcpy (power_stats, _("AC adapter ")); + break; + case CAMERA_ON_BATTERY: + strcpy (power_stats, _("on battery ")); + break; + default: + sprintf (power_stats, _("unknown (%i"), pwr_source); + break; } switch (pwr_status) { - char cde[16]; - case CAMERA_POWER_OK: - strcat(power_stats, _("(power OK)")); - break; - case CAMERA_POWER_BAD: - strcat(power_stats, _("(power low)")); - break; - default: - strcat(power_stats,cde); - sprintf(cde," - %i)",pwr_status); - break; + char cde[16]; + + case CAMERA_POWER_OK: + strcat (power_stats, _("(power OK)")); + break; + case CAMERA_POWER_BAD: + strcat (power_stats, _("(power low)")); + break; + default: + strcat (power_stats, cde); + sprintf (cde, " - %i)", pwr_status); + break; } - } - else - strcpy (power_stats,_("Power: camera unavailable")); - - gp_widget_new (GP_WIDGET_TEXT,_("Power"), &t); + } else + strcpy (power_stats, _("Power: camera unavailable")); + + gp_widget_new (GP_WIDGET_TEXT, _("Power"), &t); gp_widget_set_value (t, power_stats); - gp_widget_append (section,t); - + gp_widget_append (section, t); + gp_widget_new (GP_WIDGET_SECTION, _("Debug"), §ion); gp_widget_append (*window, section); - + gp_widget_new (GP_WIDGET_MENU, _("Debug level"), &t); - gp_widget_add_choice (t, "none") ; + gp_widget_add_choice (t, "none"); gp_widget_add_choice (t, "functions"); gp_widget_add_choice (t, "complete"); switch (cs->debug) { - case 0: - default: - gp_widget_set_value (t, "none"); - break; - case 1: - gp_widget_set_value (t, "functions"); - break; - case 9: - gp_widget_set_value (t, "complete"); - break; + case 0: + default: + gp_widget_set_value (t, "none"); + break; + case 1: + gp_widget_set_value (t, "functions"); + break; + case 9: + gp_widget_set_value (t, "complete"); + break; } - gp_widget_append (section,t); + gp_widget_append (section, t); gp_widget_new (GP_WIDGET_TOGGLE, _("Dump data by packets to stderr"), &t); gp_widget_set_value (t, &(cs->dump_packets)); - gp_widget_append (section,t); + gp_widget_append (section, t); return GP_OK; } #if 0 -int camera_config(Camera *camera) +int +camera_config (Camera *camera) { CameraWidget *window; camera_get_config (camera, &window); - - /* Prompt the user with the config window */ + + /* Prompt the user with the config window */ if (gp_frontend_prompt (camera, window) == GP_PROMPT_CANCEL) { - gp_widget_unref(window); + gp_widget_unref (window); return GP_OK; } @@ -1307,147 +1420,153 @@ int camera_config(Camera *camera) } #endif -int camera_set_config (Camera *camera, CameraWidget *window) +int +camera_set_config (Camera *camera, CameraWidget * window) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - CameraWidget *w; - char *wvalue; - char buf[8]; - - gp_debug_printf (GP_DEBUG_LOW,"canon","camera_set_config()"); - - gp_widget_get_child_by_label (window,_("Debug level"), &w); - if (gp_widget_changed (w)) { - gp_widget_get_value (w, &wvalue); - if(strcmp(wvalue,"none") == 0) - cs->debug = 0; - else if (strcmp(wvalue,"functions") == 0) - cs->debug = 1; - else if (strcmp(wvalue,"complete") == 0) - cs->debug = 9; - - sprintf(buf,"%i",cs->debug); - gp_setting_set("canon", "debug", buf); - } - - gp_widget_get_child_by_label (window,_("Dump data by packets to stderr"), - &w); - if (gp_widget_changed (w)) { - gp_widget_get_value (w, &(cs->dump_packets)); - sprintf(buf,"%i",cs->dump_packets); - gp_setting_set("canon", "dump_packets", buf); - } - - gp_widget_get_child_by_label (window,_("Owner name"), &w); - if (gp_widget_changed (w)) { - gp_widget_get_value (w, &wvalue); - if(!check_readiness(camera)) { - gp_camera_status(camera,_("Camera unavailable")); - } else { - if(psa50_set_owner_name(camera, wvalue) == GP_OK) - gp_camera_status(camera, _("Owner name changed")); - else - gp_camera_status (camera, - _("could not change owner name")); - } - } - - gp_widget_get_child_by_label (window,_("Set camera date to PC date"), &w); - if (gp_widget_changed (w)) { - gp_widget_get_value (w, &wvalue); - if(!check_readiness(camera)) { - gp_camera_status(camera,_("Camera unavailable")); - } else { - if(psa50_set_time(camera)) { - gp_camera_status(camera,_("time set")); - } else { - gp_camera_status(camera,_("could not set time")); - } - } - } - - gp_debug_printf (GP_DEBUG_LOW, "canon", _("done configuring camera.\n")); - - return GP_OK; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + CameraWidget *w; + char *wvalue; + char buf[8]; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_set_config()"); + + gp_widget_get_child_by_label (window, _("Debug level"), &w); + if (gp_widget_changed (w)) { + gp_widget_get_value (w, &wvalue); + if (strcmp (wvalue, "none") == 0) + cs->debug = 0; + else if (strcmp (wvalue, "functions") == 0) + cs->debug = 1; + else if (strcmp (wvalue, "complete") == 0) + cs->debug = 9; + + sprintf (buf, "%i", cs->debug); + gp_setting_set ("canon", "debug", buf); + } + + gp_widget_get_child_by_label (window, _("Dump data by packets to stderr"), &w); + if (gp_widget_changed (w)) { + gp_widget_get_value (w, &(cs->dump_packets)); + sprintf (buf, "%i", cs->dump_packets); + gp_setting_set ("canon", "dump_packets", buf); + } + + gp_widget_get_child_by_label (window, _("Owner name"), &w); + if (gp_widget_changed (w)) { + gp_widget_get_value (w, &wvalue); + if (!check_readiness (camera)) { + gp_camera_status (camera, _("Camera unavailable")); + } else { + if (psa50_set_owner_name (camera, wvalue) == GP_OK) + gp_camera_status (camera, _("Owner name changed")); + else + gp_camera_status (camera, _("could not change owner name")); + } + } + + gp_widget_get_child_by_label (window, _("Set camera date to PC date"), &w); + if (gp_widget_changed (w)) { + gp_widget_get_value (w, &wvalue); + if (!check_readiness (camera)) { + gp_camera_status (camera, _("Camera unavailable")); + } else { + if (psa50_set_time (camera)) { + gp_camera_status (camera, _("time set")); + } else { + gp_camera_status (camera, _("could not set time")); + } + } + } + + gp_debug_printf (GP_DEBUG_LOW, "canon", _("done configuring camera.\n")); + + return GP_OK; } -int camera_file_get_info (Camera *camera, const char *folder, - const char *filename, CameraFileInfo *info) +int +camera_file_get_info (Camera *camera, const char *folder, + const char *filename, CameraFileInfo * info) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_file_get_info()"); - - info->preview.fields = GP_FILE_INFO_TYPE; + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_file_get_info()"); + + info->preview.fields = GP_FILE_INFO_TYPE; - /* thumbnails are always jpeg on Canon Cameras */ - strcpy (info->preview.type, "image/jpeg"); + /* thumbnails are always jpeg on Canon Cameras */ + strcpy (info->preview.type, "image/jpeg"); - /* FIXME GP_FILE_INFO_PERMISSIONS to add */ - info->file.fields = GP_FILE_INFO_NAME | GP_FILE_INFO_TYPE; + /* FIXME GP_FILE_INFO_PERMISSIONS to add */ + info->file.fields = GP_FILE_INFO_NAME | GP_FILE_INFO_TYPE; - if(is_movie(filename)) - strcpy (info->file.type, "video/x-msvideo"); - else if (is_image(filename)) - strcpy (info->file.type, "image/jpeg"); - else - /* May no be correct behaviour ... */ - strcpy (info->file.type, "unknown"); + if (is_movie (filename)) + strcpy (info->file.type, "video/x-msvideo"); + else if (is_image (filename)) + strcpy (info->file.type, "image/jpeg"); + else + /* May no be correct behaviour ... */ + strcpy (info->file.type, "unknown"); - strcpy (info->file.name, filename); + strcpy (info->file.name, filename); - return GP_OK; + return GP_OK; } -int camera_file_set_info (Camera *camera, const char *folder, - const char *filename, CameraFileInfo *info) +int +camera_file_set_info (Camera *camera, const char *folder, + const char *filename, CameraFileInfo * info) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_file_set_info()"); - - return GP_ERROR_NOT_SUPPORTED; + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_file_set_info()"); + + return GP_ERROR_NOT_SUPPORTED; } /****************************************************************************/ - -int camera_capture (Camera *camera, int capture_type, CameraFilePath *path) + +int +camera_capture (Camera *camera, int capture_type, CameraFilePath * path) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_capture()"); - - return GP_ERROR_NOT_SUPPORTED; + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_capture()"); + + return GP_ERROR_NOT_SUPPORTED; } -int camera_capture_preview(Camera *camera, CameraFile *file) +int +camera_capture_preview (Camera *camera, CameraFile * file) { - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_capture_preview()"); - - return GP_ERROR_NOT_SUPPORTED; + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_capture_preview()"); + + return GP_ERROR_NOT_SUPPORTED; } -int camera_file_get_config (Camera *camera, const char *folder, - const char *filename, CameraWidget **window) +int +camera_file_get_config (Camera *camera, const char *folder, + const char *filename, CameraWidget ** window) { - return GP_ERROR_NOT_SUPPORTED; + return GP_ERROR_NOT_SUPPORTED; } -int camera_file_set_config (Camera *camera, const char *folder, - const char *filename, CameraWidget *window) +int +camera_file_set_config (Camera *camera, const char *folder, + const char *filename, CameraWidget * window) { - return GP_ERROR_NOT_SUPPORTED; + return GP_ERROR_NOT_SUPPORTED; } -int camera_folder_get_config(Camera *camera, const char *folder, - CameraWidget **window) +int +camera_folder_get_config (Camera *camera, const char *folder, CameraWidget ** window) { - return GP_ERROR_NOT_SUPPORTED; + return GP_ERROR_NOT_SUPPORTED; } -int camera_folder_set_config (Camera *camera, const char *folder, - CameraWidget *window) +int +camera_folder_set_config (Camera *camera, const char *folder, CameraWidget * window) { - return GP_ERROR_NOT_SUPPORTED; + return GP_ERROR_NOT_SUPPORTED; } -const char *camera_result_as_string (Camera *camera, int result) +const char * +camera_result_as_string (Camera *camera, int result) { - return NULL; + return NULL; } /** @@ -1455,104 +1574,107 @@ const char *camera_result_as_string (Camera *camera, int result) * camera settings. Right now it is only the speed that is * saved. */ -int camera_init(Camera *camera) +int +camera_init (Camera *camera) { - struct canon_info *cs; - char buf[8]; - - gp_debug_printf(GP_DEBUG_LOW,"canon","camera_init()"); - - /* First, set up all the function pointers */ - camera->functions->exit = camera_exit; - camera->functions->folder_list_folders = camera_folder_list_folders; - camera->functions->folder_list_files = camera_folder_list_files; + struct canon_info *cs; + char buf[8]; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "camera_init()"); + + /* First, set up all the function pointers */ + camera->functions->exit = camera_exit; + camera->functions->folder_list_folders = camera_folder_list_folders; + camera->functions->folder_list_files = camera_folder_list_files; #warning File upload and deletion now only works using the filesystem. #warning Please update this library! // camera->functions->folder_put_file = camera_folder_put_file; - camera->functions->file_get = camera_file_get; + camera->functions->file_get = camera_file_get; // camera->functions->file_delete = camera_file_delete; - camera->functions->file_get_info = camera_file_get_info; - camera->functions->file_set_info = camera_file_set_info; - camera->functions->get_config = camera_get_config; - camera->functions->set_config = camera_set_config; - camera->functions->file_get_config = camera_file_get_config; - camera->functions->file_set_config = camera_file_set_config; - camera->functions->folder_get_config = camera_folder_get_config; - camera->functions->folder_set_config = camera_folder_set_config; - camera->functions->capture = camera_capture; - camera->functions->summary = camera_summary; - camera->functions->manual = camera_manual; - camera->functions->about = camera_about; - camera->functions->result_as_string = camera_result_as_string; - - cs = (struct canon_info*)malloc(sizeof(struct canon_info)); - camera->camlib_data = cs; - - cs->first_init = 1; - cs->uploading = 0; - cs->slow_send = 0; - cs->cached_ready = 0; - cs->cached_disk = 0; - cs->cached_dir = 0; - cs->dump_packets = 0; - cs->cached_tree = NULL; - - fprintf(stderr,"canon_initialize()\n"); - - cs->speed = camera->port_info->speed; - /* Default speed */ - if (cs->speed == 0) - cs->speed = 9600; - - if (gp_setting_get("canon","debug",buf) != GP_OK) - cs->debug = 1; - - if (strncmp(buf, "0", 1) == 0) - cs->debug = 0; - if (strncmp(buf, "1", 1) == 0) - cs->debug = 1; - if (strncmp(buf, "1", 1) == 0) - cs->debug = 1; - if (strncmp(buf, "2", 1) == 0) - cs->debug = 2; - if (strncmp(buf, "3", 1) == 0) - cs->debug = 3; - if (strncmp(buf, "4", 1) == 0) - cs->debug = 4; - if (strncmp(buf, "5", 1) == 0) - cs->debug = 5; - if (strncmp(buf, "6", 1) == 0) - cs->debug = 6; - if (strncmp(buf, "7", 1) == 0) - cs->debug = 7; - if (strncmp(buf, "8", 1) == 0) - cs->debug = 8; - if (strncmp(buf, "9", 1) == 0) - cs->debug = 9; - fprintf(stderr,"Debug level: %i\n",cs->debug); - - if(gp_setting_get("canon","dump_packets",buf) == GP_OK) { - if(strncmp(buf, "1", 1) == 0) - cs->dump_packets = 1; - if(strncmp(buf, "0", 1) == 0) - cs->dump_packets = 0; - } - - switch (camera->port->type) { - case GP_PORT_USB: - gp_debug_printf(GP_DEBUG_LOW,"canon","GPhoto tells us that we should use a USB link.\n"); - canon_comm_method = CANON_USB; - break; - case GP_PORT_SERIAL: - default: - gp_debug_printf(GP_DEBUG_LOW,"canon","GPhoto tells us that we should use a RS232 link.\n"); - canon_comm_method = CANON_SERIAL_RS232; - break; - } - if (canon_comm_method == CANON_SERIAL_RS232) - gp_debug_printf(GP_DEBUG_LOW,"canon","Camera transmission speed : %i\n", cs->speed); - - - return canon_serial_init(camera,camera->port_info->path); -} + camera->functions->file_get_info = camera_file_get_info; + camera->functions->file_set_info = camera_file_set_info; + camera->functions->get_config = camera_get_config; + camera->functions->set_config = camera_set_config; + camera->functions->file_get_config = camera_file_get_config; + camera->functions->file_set_config = camera_file_set_config; + camera->functions->folder_get_config = camera_folder_get_config; + camera->functions->folder_set_config = camera_folder_set_config; + camera->functions->capture = camera_capture; + camera->functions->summary = camera_summary; + camera->functions->manual = camera_manual; + camera->functions->about = camera_about; + camera->functions->result_as_string = camera_result_as_string; + + cs = (struct canon_info *) malloc (sizeof (struct canon_info)); + camera->camlib_data = cs; + + cs->first_init = 1; + cs->uploading = 0; + cs->slow_send = 0; + cs->cached_ready = 0; + cs->cached_disk = 0; + cs->cached_dir = 0; + cs->dump_packets = 0; + cs->cached_tree = NULL; + + fprintf (stderr, "canon_initialize()\n"); + + cs->speed = camera->port_info->speed; + /* Default speed */ + if (cs->speed == 0) + cs->speed = 9600; + + if (gp_setting_get ("canon", "debug", buf) != GP_OK) + cs->debug = 1; + + if (strncmp (buf, "0", 1) == 0) + cs->debug = 0; + if (strncmp (buf, "1", 1) == 0) + cs->debug = 1; + if (strncmp (buf, "1", 1) == 0) + cs->debug = 1; + if (strncmp (buf, "2", 1) == 0) + cs->debug = 2; + if (strncmp (buf, "3", 1) == 0) + cs->debug = 3; + if (strncmp (buf, "4", 1) == 0) + cs->debug = 4; + if (strncmp (buf, "5", 1) == 0) + cs->debug = 5; + if (strncmp (buf, "6", 1) == 0) + cs->debug = 6; + if (strncmp (buf, "7", 1) == 0) + cs->debug = 7; + if (strncmp (buf, "8", 1) == 0) + cs->debug = 8; + if (strncmp (buf, "9", 1) == 0) + cs->debug = 9; + fprintf (stderr, "Debug level: %i\n", cs->debug); + + if (gp_setting_get ("canon", "dump_packets", buf) == GP_OK) { + if (strncmp (buf, "1", 1) == 0) + cs->dump_packets = 1; + if (strncmp (buf, "0", 1) == 0) + cs->dump_packets = 0; + } + switch (camera->port->type) { + case GP_PORT_USB: + gp_debug_printf (GP_DEBUG_LOW, "canon", + "GPhoto tells us that we should use a USB link.\n"); + canon_comm_method = CANON_USB; + break; + case GP_PORT_SERIAL: + default: + gp_debug_printf (GP_DEBUG_LOW, "canon", + "GPhoto tells us that we should use a RS232 link.\n"); + canon_comm_method = CANON_SERIAL_RS232; + break; + } + if (canon_comm_method == CANON_SERIAL_RS232) + gp_debug_printf (GP_DEBUG_LOW, "canon", "Camera transmission speed : %i\n", + cs->speed); + + + return canon_serial_init (camera, camera->port_info->path); +} diff --git a/camlibs/canon/crc.c b/camlibs/canon/crc.c index 54c3f6b31..3b3fb11b5 100644 --- a/camlibs/canon/crc.c +++ b/camlibs/canon/crc.c @@ -11,38 +11,38 @@ * CRC 0102010 */ static unsigned short crc_table[256] = { - 0x0, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, - 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, - 0x1081, 0x108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, - 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, - 0x2102, 0x308b, 0x210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, - 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, - 0x3183, 0x200a, 0x1291, 0x318, 0x77a7, 0x662e, 0x54b5, 0x453c, - 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, - 0x4204, 0x538d, 0x6116, 0x709f, 0x420, 0x15a9, 0x2732, 0x36bb, - 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, - 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x528, 0x37b3, 0x263a, - 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, - 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x630, 0x17b9, - 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, - 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x738, - 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, - 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, - 0x840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, - 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, - 0x18c1, 0x948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, - 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, - 0x2942, 0x38cb, 0xa50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, - 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, - 0x39c3, 0x284a, 0x1ad1, 0xb58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, - 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, - 0x4a44, 0x5bcd, 0x6956, 0x78df, 0xc60, 0x1de9, 0x2f72, 0x3efb, - 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, - 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0xd68, 0x3ff3, 0x2e7a, - 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, - 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0xe70, 0x1ff9, - 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, - 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0xf78, + 0x0, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, + 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, + 0x1081, 0x108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, + 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, + 0x2102, 0x308b, 0x210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, + 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, + 0x3183, 0x200a, 0x1291, 0x318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, + 0x4204, 0x538d, 0x6116, 0x709f, 0x420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, + 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x528, 0x37b3, 0x263a, + 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, + 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x630, 0x17b9, + 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x738, + 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, + 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, + 0x840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, + 0x18c1, 0x948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, + 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0xa50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, + 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, + 0x39c3, 0x284a, 0x1ad1, 0xb58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, + 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, + 0x4a44, 0x5bcd, 0x6956, 0x78df, 0xc60, 0x1de9, 0x2f72, 0x3efb, + 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0xd68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, + 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0xe70, 0x1ff9, + 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, + 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0xf78, }; @@ -51,186 +51,193 @@ static unsigned short crc_table[256] = { */ static int crc_init[1024] = { - -1, -1, -1, -1, -1, 0x83a4, 0x5b70, 0x724e, - 0x0ee6, 0x5969, 0x7b6c, 0x647f, 0x8e90, 0x07ad, 0x5af0, 0xfa5f, - 0x77aa, 0xc2b3, 0x5003, 0x59f5, 0xe76c, 0xad67, 0xe2af, 0x4632, - 0xd983, 0xb9a8, 0x8cfb, 0x7c8f, 0xbf08, 0x1c9d, 0xb35b, 0x2f51, - 0xec49, 0xd0dc, 0xae31, 0xac9c, 0x11be, 0xf886, 0xbe88, 0x948c, - 0xca17, 0xb48b, 0xc726, 0xed56, 0xc7cd, 0x0656, 0xa9e1, 0x44eb, - 0x10a1, 0xef97, 0x16ef, 0x91f1, 0x9f42, 0x5cac, 0x9639, 0x6f35, - 0x9c2b, 0x2d9f, 0x326b, 0x3f84, 0xb859, 0x75ea, 0x9291, 0xe771, - 0xb067, 0x0b62, 0xf53c, 0x6c55, 0xe418, 0xc154, 0xaf30, 0xa58d, - 0x4827, 0xbc6d, 0x61ae, 0x77c5, 0xadb3, 0x36af, 0xdbc0, 0xea8a, - 0x23ba, 0x6785, 0x6ca3, 0x1218, 0x46b5, 0x5e83, 0xa91b, 0xbeeb, - 0xf78c, 0xcc77, 0xe4ed, 0x3454, 0x30e2, 0xa6a6, 0x7b14, 0x1c7f, - 0x515b, 0x09e4, 0x631e, 0xd7e7, 0xad46, 0xc3af, 0x4412, 0xe9a1, - 0x1089, 0xc797, 0x5c56, 0x6c39, 0x8818, 0xbfcb, 0xdf9d, 0x97ce, - 0x9024, 0x4253, 0x98c7, 0xe1db, 0x2a01, 0x941c, 0x5a17, 0x1d5f, - 0x794a, 0x525d, 0x17d7, 0xa1e0, 0x0563, 0x84d2, 0x1507, 0x61c2, - 0x1bc5, 0xd32c, 0x4602, 0xe983, 0x3289, 0xdd84, 0x9eec, 0xfabd, - 0x95aa, 0xe406, 0xdf54, 0x5ece, 0xe41b, 0xc254, 0xb703, 0x5715, - 0x7782, 0xeab3, 0x1aba, 0xa43d, 0xf036, 0x4e00, 0xab0b, 0xbec9, - 0xd58c, 0xd664, 0x2657, 0xa2d0, 0x2d50, 0xfd6b, 0x7bdd, 0xd57f, - 0x2564, 0x89e3, 0x4cda, 0x6129, 0xf0c5, 0xbd00, 0x04bf, 0x50c3, - 0x99f5, 0xdbca, 0xe08a, 0x7310, 0x58f7, 0xed7d, 0xeccd, 0x54dc, - 0xa6b1, 0x6c14, 0xa518, 0xdd27, 0x3dec, 0xc07b, 0x8821, 0x86cb, - 0x1c25, 0x0b5b, 0xcc3c, 0xafed, 0x788d, 0x9d4c, 0x428e, 0x45c7, - 0x34b0, 0xd4e2, 0xb075, 0x1962, 0x640e, 0xff90, 0x90ff, 0x9953, - 0x7dca, 0xf219, 0x7122, 0x7ad5, 0xd56e, 0x3464, 0x00e2, 0x2d87, - 0x2a6b, 0xfe1c, 0x14ee, 0x80d3, 0x3443, 0x27e2, 0x1fc1, 0xf768, - 0x2877, 0xf23e, 0x5622, 0x4893, 0x086d, 0xe20f, 0xe632, 0xfb76, - 0x56bb, 0xd193, 0xe920, 0x9189, 0xe742, 0x8367, 0x9870, 0x56db, - 0xb193, 0xf773, 0x3377, 0x2b95, 0x080d, 0x820f, 0xf861, 0x5988, - 0x9a6c, 0x5af9, 0xf35f, 0x3f33, 0x0f59, 0xee78, 0xf1fe, 0x8e11, - 0x86ad, 0x7a25, 0x256e, 0x83e3, 0x1c70, 0x5e5b, 0x711b, 0x43d5, - 0x16d6, 0xa8f1, 0x5cfa, 0xc039, 0xca21, 0x828b, 0x7c61, 0x5108, - 0x5ae4, 0xee5f, 0xd6fe, 0xbc57, 0x5bae, 0xac4e, 0xc3be, 0x5512, - 0x60a0, 0x71d4, 0x8cd5, 0x528f, 0xc5d7, 0x0c74, 0xdb4b, 0x618a, - 0x53c5, 0x87c6, 0x1934, 0x320e, 0x5a84, 0x8e5f, 0xc8ad, 0x1ea9, - 0x9779, 0x2724, 0xd9c1, 0xfba8, 0x88bb, 0x1ccb, 0xe55b, 0x8a45, - 0xf2e9, 0x8122, 0xcd52, 0xc9fc, 0x47b8, 0x5b92, 0x904e, 0x2853, - 0xd63e, 0x7c57, 0x6708, 0xe1a3, 0x5201, 0x4bd7, 0x545e, 0x24b1, - 0x54f2, 0x88b1, 0x16cb, 0xb5f1, 0xb537, 0x7337, 0x7ff7, 0xdf3b, - 0x31ce, 0x82b7, 0x4061, 0xbae5, 0xd9c8, 0xf2a8, 0xc022, 0xd121, - 0x5b20, 0x224e, 0x9b94, 0xaae8, 0x55d8, 0xaaa0, 0x1dd8, 0xfe4a, - 0x42ee, 0x25c7, 0x2ae3, 0x761c, 0x7ca2, 0x9208, 0x7e71, 0x512a, - 0x78e4, 0xf44c, 0x1444, 0x2ad3, 0x461c, 0xf783, 0xc377, 0x9c12, - 0x149f, 0xf1d3, 0xa311, 0xe441, 0x9854, 0x72db, 0x9be6, 0xd8e8, - 0xdab9, 0x9b9b, 0xa5e8, 0x2d27, 0x8a6b, 0xdce9, 0xfbfd, 0xddbb, - 0xa1ec, 0x0963, 0xe41e, 0xc754, 0x9f56, 0x48ac, 0x376d, 0x11d1, - 0x9786, 0xd824, 0x16b9, 0xc7f1, 0x3a56, 0x420c, 0xc7c7, 0x0c56, - 0xf94b, 0x7b99, 0x917f, 0x1142, 0x0486, 0x69c3, 0x5a4d, 0x475f, - 0xbc92, 0x9eae, 0xb8bd, 0x91ea, 0x8442, 0x8507, 0xc816, 0xa5a9, - 0x6c27, 0x9618, 0x4e35, 0x9e0b, 0x1dbd, 0x9b4a, 0x74e8, 0x9880, - 0xa6db, 0x0614, 0xebe1, 0x40ab, 0x70e5, 0xb5c4, 0x8037, 0xd043, - 0x3131, 0x7db7, 0x8f19, 0x86bc, 0x6b25, 0xac6f, 0xe2be, 0x5732, - 0x5082, 0xd8f5, 0xc7b9, 0x7256, 0x16e6, 0x98f1, 0xd7db, 0x9146, - 0x2842, 0xc73e, 0xf556, 0x0655, 0xaae1, 0x5cd8, 0xe239, 0xd032, - 0x4031, 0xeae5, 0x4cba, 0x0129, 0xee96, 0x1ffe, 0xc868, 0xdba9, - 0x838a, 0x7570, 0x0891, 0x1e0f, 0x3179, 0x35b7, 0xdbf3, 0xd98a, - 0xb0a8, 0xc462, 0xb165, 0x0173, 0xb496, 0xda26, 0x049b, 0x74c3, - 0xb380, 0xf451, 0x0944, 0xc31e, 0xf512, 0x4255, 0x9ec7, 0xd1bd, - 0xc720, 0xeb56, 0xf7ab, 0xeb77, 0xd6ab, 0xe957, 0xe689, 0x4076, - 0xade5, 0x60af, 0x7ed4, 0xf42a, 0x7244, 0x04e6, 0x09c3, 0x441e, - 0xe5a1, 0x7045, 0x15c4, 0xa2c2, 0x3f50, 0x6c59, 0xe818, 0xa198, - 0x7d63, 0x5b19, 0x1b4e, 0x582c, 0x367d, 0x09c0, 0x471e, 0xfd92, - 0x82dd, 0x2a61, 0xf41c, 0x4444, 0xbfa1, 0xb59d, 0xd937, 0x0da8, - 0x0f5a, 0xed78, 0xe9cd, 0x7c89, 0xb908, 0x2cfb, 0x5e7a, 0x501b, - 0x41f5, 0x26f4, 0x01d0, 0x1796, 0xe0e0, 0x1910, 0x160e, 0x70f1, - 0xa1c4, 0x2163, 0xaea7, 0x3a9c, 0x880c, 0xabcb, 0x7ec9, 0xe92a, - 0x9b89, 0xb7e8, 0xbc15, 0x19ae, 0xa80e, 0xa3fa, 0x0f41, 0xf678, - 0x3066, 0x22a6, 0x7394, 0xdcf7, 0xe5fd, 0x2c45, 0xe07a, 0x8310, - 0xef70, 0xf1ef, 0x9f11, 0x0fac, 0x1b78, 0x6e2c, 0x8d3a, 0xb59e, - 0xda37, 0x159b, 0xfdc2, 0xd2dd, 0xbf13, 0x079d, 0x6af0, 0x717e, - 0x26d5, 0x20d0, 0x15b6, 0xd0c2, 0xb031, 0x5d62, 0x5028, 0x72f5, - 0xb5e6, 0xa237, 0xca50, 0xf38b, 0xeb33, 0x92ab, 0xdd71, 0x6bec, - 0x656f, 0x9681, 0xd735, 0x7f46, 0x6e3b, 0x9a3a, 0x0cf9, 0x564b, - 0x2193, 0x5ea7, 0x8d1b, 0x949e, 0xd817, 0x25b9, 0x54e3, 0x99b1, - 0x9fca, 0xd4ac, 0xfe75, 0x7dee, 0xd619, 0x5b57, 0x554e, 0x3ca0, - 0x846a, 0xad07, 0x82af, 0x5861, 0x7b7d, 0x757f, 0x0791, 0x66f0, - 0x11b2, 0xf486, 0xde44, 0x46df, 0x3483, 0xe7e2, 0x2367, 0xba85, - 0xb9c8, 0xecfb, 0x62dc, 0x1df6, 0xd04a, 0x3831, 0x352e, 0x42f3, - 0x38c7, 0xc32e, 0xc512, 0xc974, 0xcfb8, 0x33de, 0x8295, 0x6261, - 0xa0f6, 0x1b72, 0x642c, 0xdd90, 0x8aec, 0x5be9, 0xeb4e, 0xefab, - 0x2aef, 0x7a1c, 0x1c6e, 0x405b, 0x80e5, 0x0243, 0x9ca5, 0xa39f, - 0x6a41, 0xc07e, 0x8d21, 0xae9e, 0x039c, 0x4bb4, 0x375e, 0x22d1, - 0x0494, 0x7bc3, 0xcb7f, 0xd49a, 0xc875, 0xc6a9, 0x6a47, 0xc67e, - 0xbd47, 0x43bf, 0x7cd6, 0xe608, 0xc176, 0x8d30, 0xbf9e, 0x8a9d, - 0x2ae9, 0x7c1c, 0x2c08, 0xad7a, 0xffaf, 0xafff, 0x6a8d, 0x0c7e, - 0xd14b, 0x3120, 0x6cb7, 0x0618, 0xe7e1, 0x2067, 0xa2b6, 0x4b50, - 0xd35e, 0x3402, 0x66e2, 0x03b2, 0x65b4, 0x4d81, 0x3238, 0x6c84, - 0x3518, 0x74f3, 0x8380, 0x7f70, 0x583b, 0x217d, 0xb0a7, 0xcb62, - 0xc99a, 0x21b8, 0x75a7, 0xdf91, 0x9bce, 0xf0e8, 0x9000, 0x6653, - 0xb2b2, 0xce40, 0xc3cf, 0x2412, 0xf7f2, 0xb277, 0x0b40, 0xd73c, - 0x7646, 0x26a2, 0x57d0, 0xb282, 0xfe40, 0x48ee, 0x756d, 0x1591, - 0xf7c2, 0x8277, 0x8061, 0x8643, 0x9425, 0x6317, 0xdee7, 0xe5df, - 0x0e45, 0xfa69, 0x41aa, 0x79f4, 0xec5d, 0xc4dc, 0x0f65, 0xd278, - 0x1a13, 0x0d3d, 0x9a5a, 0x6cf9, 0x4818, 0x836d, 0x9270, 0x0671, - 0x8ee1, 0x76ad, 0xcda2, 0x39fc, 0xf03f, 0x4700, 0xe392, 0x7323, - 0x6bf7, 0x7e6f, 0x4f2a, 0x891a, 0xb5da, 0x9e37, 0x21bd, 0x70a7, - 0xf7c4, 0x8477, 0xb007, 0x6b62, 0xeb6f, 0xceab, 0x28cf, 0x4a3e, - 0xb54f, 0x0b37, 0xa03c, 0xd172, 0x0820, 0xaf0f, 0x9a8d, 0xbbf9, - 0xcdd9, 0x42fc, 0x37c7, 0xbbd1, 0xe5d9, 0x0845, 0xca0f, 0xac8b, - 0x06be, 0x41e1, 0x32f4, 0xa084, 0x6972, 0xeb4d, 0xecab, 0x32dc, - 0x8884, 0x23cb, 0x1685, 0xfbf1, 0xd1bb, 0xc120, 0xdb30, 0x1a8a, - 0x943d, 0x7b17, 0x1f7f, 0x4968, 0xfb7c, 0x5cbb, 0x8139, 0xd652, - 0x1057, 0x1997, 0x910e, 0x6042, 0x93d4, 0xaa60, 0xddd8, 0xc2ec, - 0x0f03, 0xb478, 0x3426, 0x42e2, 0x29c7, 0x4a2f, 0xa44f, 0x8236, - 0xc161, 0x9a30, 0x06f9, 0x06e1, 0x1ee1, 0xdf79, 0x73ce, 0x86f7, - 0x2025, 0xe0b6, 0x4f10, 0xb31a, 0x6e51, 0xf03a, 0x4200, 0xcbc7, - 0x6c9a, 0x2b18, 0x850d, 0xc216, 0xf503, 0x5355, 0x17c6, 0xb0e0, - 0x8c62, 0xe58f, 0x5e45, 0x6f1b, 0xb22b, 0x5740, 0x2282, 0x5794, - 0xf682, 0xca66, 0xc58b, 0x5074, 0x2ef5, 0x4058, 0x83e5, 0x1a70, - 0x6e3d, 0x9c3a, 0x3c9f, 0xbb6a, 0x5ed9, 0xf31b, 0x7b33, 0x3b7f, - 0x631d, 0xd4e7, 0xb575, 0x3137, 0x7bb7, 0xbf7f, 0x6b9d, 0x146f, - 0x01d3, 0x1496, 0xf8d3, 0xeb88, 0x29ab, 0x262f, 0xdad0, 0xf29b, - 0xf322, 0x4233, 0xf8c7, 0xff88, 0x88ff, 0x58cb, 0xd17d, 0x0720, - 0xd7f0, 0xba46, 0x7ac8, 0xc86e, 0xdda9, 0xb3ec, 0x9851, 0x77db, - 0xb3b3, 0xc751, 0x9a56, 0x60f9, 0x28d4, 0x513e, 0x6ce4, 0x5518, - 0x6aa0, 0x217e, 0xb3a7, 0xd351, 0x3b02, 0x1e1d, 0x2379, 0xa485, - 0x4836, 0xad6d, 0xe8af, 0x1698, 0xe6f1, 0x3876, 0x722e, 0x6ee6, - 0x473a, 0xd992, 0xa8a8, 0x05fa, 0x1dd2, 0xf44a, 0x1244, 0x1ab5, - 0xab3d, 0x88c9, 0x6ecb, 0x6a3a, 0xbb7e, 0x4ad9, 0x524f, 0x05d7, - 0x30d2, 0x96a6, 0xf035, 0x4d00, 0xb338, 0x4c51, 0xea29, 0x80ba, - 0x5d43, 0x7128, 0x70d5, 0x85c4, 0x0b16, 0x813c, 0xd352, 0x3802, - 0x062e, 0xd1e1, 0x9b20, 0x1ee8, 0xd679, 0x3b57, 0x4b1d, 0x9e5e, - 0x48bd, 0x266d, 0x98d0, 0xf6db, 0x9366, 0x1860, 0x6e1f, 0xbe3a, - 0x268c, 0x79d0, 0xc85d, 0xeea9, 0x20fe, 0x3bb6, 0xaa1d, 0xa0d8, - 0x3572, 0x1ef3, 0xcd79, 0xe2fc, 0x1532, 0x54c2, 0xb8b1, 0x9dea, - 0xe48e, 0x5754, 0x3682, 0xf6c0, 0x8866, 0xc1cb, 0x3030, 0x74a6, - 0xd680, 0xc257, 0xb403, 0x4f26, 0x851a, -1, -1, -1 + -1, -1, -1, -1, -1, 0x83a4, 0x5b70, 0x724e, + 0x0ee6, 0x5969, 0x7b6c, 0x647f, 0x8e90, 0x07ad, 0x5af0, 0xfa5f, + 0x77aa, 0xc2b3, 0x5003, 0x59f5, 0xe76c, 0xad67, 0xe2af, 0x4632, + 0xd983, 0xb9a8, 0x8cfb, 0x7c8f, 0xbf08, 0x1c9d, 0xb35b, 0x2f51, + 0xec49, 0xd0dc, 0xae31, 0xac9c, 0x11be, 0xf886, 0xbe88, 0x948c, + 0xca17, 0xb48b, 0xc726, 0xed56, 0xc7cd, 0x0656, 0xa9e1, 0x44eb, + 0x10a1, 0xef97, 0x16ef, 0x91f1, 0x9f42, 0x5cac, 0x9639, 0x6f35, + 0x9c2b, 0x2d9f, 0x326b, 0x3f84, 0xb859, 0x75ea, 0x9291, 0xe771, + 0xb067, 0x0b62, 0xf53c, 0x6c55, 0xe418, 0xc154, 0xaf30, 0xa58d, + 0x4827, 0xbc6d, 0x61ae, 0x77c5, 0xadb3, 0x36af, 0xdbc0, 0xea8a, + 0x23ba, 0x6785, 0x6ca3, 0x1218, 0x46b5, 0x5e83, 0xa91b, 0xbeeb, + 0xf78c, 0xcc77, 0xe4ed, 0x3454, 0x30e2, 0xa6a6, 0x7b14, 0x1c7f, + 0x515b, 0x09e4, 0x631e, 0xd7e7, 0xad46, 0xc3af, 0x4412, 0xe9a1, + 0x1089, 0xc797, 0x5c56, 0x6c39, 0x8818, 0xbfcb, 0xdf9d, 0x97ce, + 0x9024, 0x4253, 0x98c7, 0xe1db, 0x2a01, 0x941c, 0x5a17, 0x1d5f, + 0x794a, 0x525d, 0x17d7, 0xa1e0, 0x0563, 0x84d2, 0x1507, 0x61c2, + 0x1bc5, 0xd32c, 0x4602, 0xe983, 0x3289, 0xdd84, 0x9eec, 0xfabd, + 0x95aa, 0xe406, 0xdf54, 0x5ece, 0xe41b, 0xc254, 0xb703, 0x5715, + 0x7782, 0xeab3, 0x1aba, 0xa43d, 0xf036, 0x4e00, 0xab0b, 0xbec9, + 0xd58c, 0xd664, 0x2657, 0xa2d0, 0x2d50, 0xfd6b, 0x7bdd, 0xd57f, + 0x2564, 0x89e3, 0x4cda, 0x6129, 0xf0c5, 0xbd00, 0x04bf, 0x50c3, + 0x99f5, 0xdbca, 0xe08a, 0x7310, 0x58f7, 0xed7d, 0xeccd, 0x54dc, + 0xa6b1, 0x6c14, 0xa518, 0xdd27, 0x3dec, 0xc07b, 0x8821, 0x86cb, + 0x1c25, 0x0b5b, 0xcc3c, 0xafed, 0x788d, 0x9d4c, 0x428e, 0x45c7, + 0x34b0, 0xd4e2, 0xb075, 0x1962, 0x640e, 0xff90, 0x90ff, 0x9953, + 0x7dca, 0xf219, 0x7122, 0x7ad5, 0xd56e, 0x3464, 0x00e2, 0x2d87, + 0x2a6b, 0xfe1c, 0x14ee, 0x80d3, 0x3443, 0x27e2, 0x1fc1, 0xf768, + 0x2877, 0xf23e, 0x5622, 0x4893, 0x086d, 0xe20f, 0xe632, 0xfb76, + 0x56bb, 0xd193, 0xe920, 0x9189, 0xe742, 0x8367, 0x9870, 0x56db, + 0xb193, 0xf773, 0x3377, 0x2b95, 0x080d, 0x820f, 0xf861, 0x5988, + 0x9a6c, 0x5af9, 0xf35f, 0x3f33, 0x0f59, 0xee78, 0xf1fe, 0x8e11, + 0x86ad, 0x7a25, 0x256e, 0x83e3, 0x1c70, 0x5e5b, 0x711b, 0x43d5, + 0x16d6, 0xa8f1, 0x5cfa, 0xc039, 0xca21, 0x828b, 0x7c61, 0x5108, + 0x5ae4, 0xee5f, 0xd6fe, 0xbc57, 0x5bae, 0xac4e, 0xc3be, 0x5512, + 0x60a0, 0x71d4, 0x8cd5, 0x528f, 0xc5d7, 0x0c74, 0xdb4b, 0x618a, + 0x53c5, 0x87c6, 0x1934, 0x320e, 0x5a84, 0x8e5f, 0xc8ad, 0x1ea9, + 0x9779, 0x2724, 0xd9c1, 0xfba8, 0x88bb, 0x1ccb, 0xe55b, 0x8a45, + 0xf2e9, 0x8122, 0xcd52, 0xc9fc, 0x47b8, 0x5b92, 0x904e, 0x2853, + 0xd63e, 0x7c57, 0x6708, 0xe1a3, 0x5201, 0x4bd7, 0x545e, 0x24b1, + 0x54f2, 0x88b1, 0x16cb, 0xb5f1, 0xb537, 0x7337, 0x7ff7, 0xdf3b, + 0x31ce, 0x82b7, 0x4061, 0xbae5, 0xd9c8, 0xf2a8, 0xc022, 0xd121, + 0x5b20, 0x224e, 0x9b94, 0xaae8, 0x55d8, 0xaaa0, 0x1dd8, 0xfe4a, + 0x42ee, 0x25c7, 0x2ae3, 0x761c, 0x7ca2, 0x9208, 0x7e71, 0x512a, + 0x78e4, 0xf44c, 0x1444, 0x2ad3, 0x461c, 0xf783, 0xc377, 0x9c12, + 0x149f, 0xf1d3, 0xa311, 0xe441, 0x9854, 0x72db, 0x9be6, 0xd8e8, + 0xdab9, 0x9b9b, 0xa5e8, 0x2d27, 0x8a6b, 0xdce9, 0xfbfd, 0xddbb, + 0xa1ec, 0x0963, 0xe41e, 0xc754, 0x9f56, 0x48ac, 0x376d, 0x11d1, + 0x9786, 0xd824, 0x16b9, 0xc7f1, 0x3a56, 0x420c, 0xc7c7, 0x0c56, + 0xf94b, 0x7b99, 0x917f, 0x1142, 0x0486, 0x69c3, 0x5a4d, 0x475f, + 0xbc92, 0x9eae, 0xb8bd, 0x91ea, 0x8442, 0x8507, 0xc816, 0xa5a9, + 0x6c27, 0x9618, 0x4e35, 0x9e0b, 0x1dbd, 0x9b4a, 0x74e8, 0x9880, + 0xa6db, 0x0614, 0xebe1, 0x40ab, 0x70e5, 0xb5c4, 0x8037, 0xd043, + 0x3131, 0x7db7, 0x8f19, 0x86bc, 0x6b25, 0xac6f, 0xe2be, 0x5732, + 0x5082, 0xd8f5, 0xc7b9, 0x7256, 0x16e6, 0x98f1, 0xd7db, 0x9146, + 0x2842, 0xc73e, 0xf556, 0x0655, 0xaae1, 0x5cd8, 0xe239, 0xd032, + 0x4031, 0xeae5, 0x4cba, 0x0129, 0xee96, 0x1ffe, 0xc868, 0xdba9, + 0x838a, 0x7570, 0x0891, 0x1e0f, 0x3179, 0x35b7, 0xdbf3, 0xd98a, + 0xb0a8, 0xc462, 0xb165, 0x0173, 0xb496, 0xda26, 0x049b, 0x74c3, + 0xb380, 0xf451, 0x0944, 0xc31e, 0xf512, 0x4255, 0x9ec7, 0xd1bd, + 0xc720, 0xeb56, 0xf7ab, 0xeb77, 0xd6ab, 0xe957, 0xe689, 0x4076, + 0xade5, 0x60af, 0x7ed4, 0xf42a, 0x7244, 0x04e6, 0x09c3, 0x441e, + 0xe5a1, 0x7045, 0x15c4, 0xa2c2, 0x3f50, 0x6c59, 0xe818, 0xa198, + 0x7d63, 0x5b19, 0x1b4e, 0x582c, 0x367d, 0x09c0, 0x471e, 0xfd92, + 0x82dd, 0x2a61, 0xf41c, 0x4444, 0xbfa1, 0xb59d, 0xd937, 0x0da8, + 0x0f5a, 0xed78, 0xe9cd, 0x7c89, 0xb908, 0x2cfb, 0x5e7a, 0x501b, + 0x41f5, 0x26f4, 0x01d0, 0x1796, 0xe0e0, 0x1910, 0x160e, 0x70f1, + 0xa1c4, 0x2163, 0xaea7, 0x3a9c, 0x880c, 0xabcb, 0x7ec9, 0xe92a, + 0x9b89, 0xb7e8, 0xbc15, 0x19ae, 0xa80e, 0xa3fa, 0x0f41, 0xf678, + 0x3066, 0x22a6, 0x7394, 0xdcf7, 0xe5fd, 0x2c45, 0xe07a, 0x8310, + 0xef70, 0xf1ef, 0x9f11, 0x0fac, 0x1b78, 0x6e2c, 0x8d3a, 0xb59e, + 0xda37, 0x159b, 0xfdc2, 0xd2dd, 0xbf13, 0x079d, 0x6af0, 0x717e, + 0x26d5, 0x20d0, 0x15b6, 0xd0c2, 0xb031, 0x5d62, 0x5028, 0x72f5, + 0xb5e6, 0xa237, 0xca50, 0xf38b, 0xeb33, 0x92ab, 0xdd71, 0x6bec, + 0x656f, 0x9681, 0xd735, 0x7f46, 0x6e3b, 0x9a3a, 0x0cf9, 0x564b, + 0x2193, 0x5ea7, 0x8d1b, 0x949e, 0xd817, 0x25b9, 0x54e3, 0x99b1, + 0x9fca, 0xd4ac, 0xfe75, 0x7dee, 0xd619, 0x5b57, 0x554e, 0x3ca0, + 0x846a, 0xad07, 0x82af, 0x5861, 0x7b7d, 0x757f, 0x0791, 0x66f0, + 0x11b2, 0xf486, 0xde44, 0x46df, 0x3483, 0xe7e2, 0x2367, 0xba85, + 0xb9c8, 0xecfb, 0x62dc, 0x1df6, 0xd04a, 0x3831, 0x352e, 0x42f3, + 0x38c7, 0xc32e, 0xc512, 0xc974, 0xcfb8, 0x33de, 0x8295, 0x6261, + 0xa0f6, 0x1b72, 0x642c, 0xdd90, 0x8aec, 0x5be9, 0xeb4e, 0xefab, + 0x2aef, 0x7a1c, 0x1c6e, 0x405b, 0x80e5, 0x0243, 0x9ca5, 0xa39f, + 0x6a41, 0xc07e, 0x8d21, 0xae9e, 0x039c, 0x4bb4, 0x375e, 0x22d1, + 0x0494, 0x7bc3, 0xcb7f, 0xd49a, 0xc875, 0xc6a9, 0x6a47, 0xc67e, + 0xbd47, 0x43bf, 0x7cd6, 0xe608, 0xc176, 0x8d30, 0xbf9e, 0x8a9d, + 0x2ae9, 0x7c1c, 0x2c08, 0xad7a, 0xffaf, 0xafff, 0x6a8d, 0x0c7e, + 0xd14b, 0x3120, 0x6cb7, 0x0618, 0xe7e1, 0x2067, 0xa2b6, 0x4b50, + 0xd35e, 0x3402, 0x66e2, 0x03b2, 0x65b4, 0x4d81, 0x3238, 0x6c84, + 0x3518, 0x74f3, 0x8380, 0x7f70, 0x583b, 0x217d, 0xb0a7, 0xcb62, + 0xc99a, 0x21b8, 0x75a7, 0xdf91, 0x9bce, 0xf0e8, 0x9000, 0x6653, + 0xb2b2, 0xce40, 0xc3cf, 0x2412, 0xf7f2, 0xb277, 0x0b40, 0xd73c, + 0x7646, 0x26a2, 0x57d0, 0xb282, 0xfe40, 0x48ee, 0x756d, 0x1591, + 0xf7c2, 0x8277, 0x8061, 0x8643, 0x9425, 0x6317, 0xdee7, 0xe5df, + 0x0e45, 0xfa69, 0x41aa, 0x79f4, 0xec5d, 0xc4dc, 0x0f65, 0xd278, + 0x1a13, 0x0d3d, 0x9a5a, 0x6cf9, 0x4818, 0x836d, 0x9270, 0x0671, + 0x8ee1, 0x76ad, 0xcda2, 0x39fc, 0xf03f, 0x4700, 0xe392, 0x7323, + 0x6bf7, 0x7e6f, 0x4f2a, 0x891a, 0xb5da, 0x9e37, 0x21bd, 0x70a7, + 0xf7c4, 0x8477, 0xb007, 0x6b62, 0xeb6f, 0xceab, 0x28cf, 0x4a3e, + 0xb54f, 0x0b37, 0xa03c, 0xd172, 0x0820, 0xaf0f, 0x9a8d, 0xbbf9, + 0xcdd9, 0x42fc, 0x37c7, 0xbbd1, 0xe5d9, 0x0845, 0xca0f, 0xac8b, + 0x06be, 0x41e1, 0x32f4, 0xa084, 0x6972, 0xeb4d, 0xecab, 0x32dc, + 0x8884, 0x23cb, 0x1685, 0xfbf1, 0xd1bb, 0xc120, 0xdb30, 0x1a8a, + 0x943d, 0x7b17, 0x1f7f, 0x4968, 0xfb7c, 0x5cbb, 0x8139, 0xd652, + 0x1057, 0x1997, 0x910e, 0x6042, 0x93d4, 0xaa60, 0xddd8, 0xc2ec, + 0x0f03, 0xb478, 0x3426, 0x42e2, 0x29c7, 0x4a2f, 0xa44f, 0x8236, + 0xc161, 0x9a30, 0x06f9, 0x06e1, 0x1ee1, 0xdf79, 0x73ce, 0x86f7, + 0x2025, 0xe0b6, 0x4f10, 0xb31a, 0x6e51, 0xf03a, 0x4200, 0xcbc7, + 0x6c9a, 0x2b18, 0x850d, 0xc216, 0xf503, 0x5355, 0x17c6, 0xb0e0, + 0x8c62, 0xe58f, 0x5e45, 0x6f1b, 0xb22b, 0x5740, 0x2282, 0x5794, + 0xf682, 0xca66, 0xc58b, 0x5074, 0x2ef5, 0x4058, 0x83e5, 0x1a70, + 0x6e3d, 0x9c3a, 0x3c9f, 0xbb6a, 0x5ed9, 0xf31b, 0x7b33, 0x3b7f, + 0x631d, 0xd4e7, 0xb575, 0x3137, 0x7bb7, 0xbf7f, 0x6b9d, 0x146f, + 0x01d3, 0x1496, 0xf8d3, 0xeb88, 0x29ab, 0x262f, 0xdad0, 0xf29b, + 0xf322, 0x4233, 0xf8c7, 0xff88, 0x88ff, 0x58cb, 0xd17d, 0x0720, + 0xd7f0, 0xba46, 0x7ac8, 0xc86e, 0xdda9, 0xb3ec, 0x9851, 0x77db, + 0xb3b3, 0xc751, 0x9a56, 0x60f9, 0x28d4, 0x513e, 0x6ce4, 0x5518, + 0x6aa0, 0x217e, 0xb3a7, 0xd351, 0x3b02, 0x1e1d, 0x2379, 0xa485, + 0x4836, 0xad6d, 0xe8af, 0x1698, 0xe6f1, 0x3876, 0x722e, 0x6ee6, + 0x473a, 0xd992, 0xa8a8, 0x05fa, 0x1dd2, 0xf44a, 0x1244, 0x1ab5, + 0xab3d, 0x88c9, 0x6ecb, 0x6a3a, 0xbb7e, 0x4ad9, 0x524f, 0x05d7, + 0x30d2, 0x96a6, 0xf035, 0x4d00, 0xb338, 0x4c51, 0xea29, 0x80ba, + 0x5d43, 0x7128, 0x70d5, 0x85c4, 0x0b16, 0x813c, 0xd352, 0x3802, + 0x062e, 0xd1e1, 0x9b20, 0x1ee8, 0xd679, 0x3b57, 0x4b1d, 0x9e5e, + 0x48bd, 0x266d, 0x98d0, 0xf6db, 0x9366, 0x1860, 0x6e1f, 0xbe3a, + 0x268c, 0x79d0, 0xc85d, 0xeea9, 0x20fe, 0x3bb6, 0xaa1d, 0xa0d8, + 0x3572, 0x1ef3, 0xcd79, 0xe2fc, 0x1532, 0x54c2, 0xb8b1, 0x9dea, + 0xe48e, 0x5754, 0x3682, 0xf6c0, 0x8866, 0xc1cb, 0x3030, 0x74a6, + 0xd680, 0xc257, 0xb403, 0x4f26, 0x851a, -1, -1, -1 }; -static unsigned short chksum(unsigned short init,unsigned n, - const unsigned char *s) +static unsigned short +chksum (unsigned short init, unsigned n, const unsigned char *s) { - unsigned short crc; + unsigned short crc; - for (crc = init; n > 0; n--) - crc = crc_table[(crc ^ *s++) & 0xff] ^ (crc >> 8); - return crc; + for (crc = init; n > 0; n--) + crc = crc_table[(crc ^ *s++) & 0xff] ^ (crc >> 8); + return crc; } -static int find_init(int len) +static int +find_init (int len) { - return len < 1024 ? crc_init[len] : -1; + return len < 1024 ? crc_init[len] : -1; } -unsigned short canon_psa50_gen_crc(const unsigned char *pkt,int len) +unsigned short +canon_psa50_gen_crc (const unsigned char *pkt, int len) { - int init; + int init; - init = find_init(len); - if (init != -1) return chksum(init,len,pkt); - fprintf(stderr,"FATAL ERROR: initial CRC value for length %d " - "unknown\n",len); - exit(1); + init = find_init (len); + if (init != -1) + return chksum (init, len, pkt); + fprintf (stderr, "FATAL ERROR: initial CRC value for length %d " "unknown\n", len); + exit (1); } -static int guess(const unsigned char *m,int len,int crc) +static int +guess (const unsigned char *m, int len, int crc) { - int i; + int i; - for (i = 0; i < 0x10000; i++) - if (chksum(i,len,m) == crc) return i; - fprintf(stderr,"unable to guess initial CRC value\n"); - exit(1); + for (i = 0; i < 0x10000; i++) + if (chksum (i, len, m) == crc) + return i; + fprintf (stderr, "unable to guess initial CRC value\n"); + exit (1); } -int canon_psa50_chk_crc(const unsigned char *pkt,int len,unsigned short crc) +int +canon_psa50_chk_crc (const unsigned char *pkt, int len, unsigned short crc) { - unsigned short this; - int init; - - init = find_init(len); - if (init != -1) return chksum(init,len,pkt) == crc; - this = guess(pkt,len,crc); - fprintf(stderr,"warning: CRC not checked (add len %d, value 0x%04x) #########################\n", - len,this); - return 1; + unsigned short this; + int init; + + init = find_init (len); + if (init != -1) + return chksum (init, len, pkt) == crc; + this = guess (pkt, len, crc); + fprintf (stderr, + "warning: CRC not checked (add len %d, value 0x%04x) #########################\n", + len, this); + return 1; } diff --git a/camlibs/canon/psa50.c b/camlibs/canon/psa50.c index 74cb73c98..d035321a7 100644 --- a/camlibs/canon/psa50.c +++ b/camlibs/canon/psa50.c @@ -26,7 +26,7 @@ #include <termios.h> #include <ctype.h> #ifdef OS2 - #include <db.h> +#include <db.h> #endif #include <netinet/in.h> #include <gphoto2.h> @@ -58,6 +58,7 @@ gp_port *gdev; gp_port_settings settings; + /************ new stuff ********/ #define MAX_TRIES 10 @@ -77,56 +78,66 @@ static unsigned char psa50_eot[8]; #define CANON_ESC 0x7e #define CANON_XOR 0x20 -int psa50_send_frame(Camera *camera, const unsigned char *pkt,int len) +int +psa50_send_frame (Camera *camera, const unsigned char *pkt, int len) { - static unsigned char buffer[2100]; - /* worst case: two maximum-sized packets (~1020 bytes, full of data - that needs to be escaped */ - unsigned char *p; - - p = buffer; - *p++ = CANON_FBEG; - while (len--) { - if (p-buffer >= sizeof(buffer)-1) { - gp_debug_printf(GP_DEBUG_LOW,"canon","FATAL ERROR: send buffer overflow\n"); - return -1; - } - if (*pkt != CANON_FBEG && *pkt != CANON_FEND && *pkt != CANON_ESC) - *p++ = *pkt++; - else { - *p++ = CANON_ESC; - *p++ = *pkt++ ^ CANON_XOR; - } - } - *p++ = CANON_FEND; - - return !canon_serial_send(camera, buffer,p-buffer,USLEEP2); + static unsigned char buffer[2100]; + + /* worst case: two maximum-sized packets (~1020 bytes, full of data + that needs to be escaped */ + unsigned char *p; + + p = buffer; + *p++ = CANON_FBEG; + while (len--) { + if (p - buffer >= sizeof (buffer) - 1) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "FATAL ERROR: send buffer overflow\n"); + return -1; + } + if (*pkt != CANON_FBEG && *pkt != CANON_FEND && *pkt != CANON_ESC) + *p++ = *pkt++; + else { + *p++ = CANON_ESC; + *p++ = *pkt++ ^ CANON_XOR; + } + } + *p++ = CANON_FEND; + + return !canon_serial_send (camera, buffer, p - buffer, USLEEP2); } -unsigned char *psa50_recv_frame(Camera *camera, int *len) +unsigned char * +psa50_recv_frame (Camera *camera, int *len) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - static unsigned char buffer[5000]; - /* more than enough :-) (allow for a few run-together packets) */ - unsigned char *p = buffer; - int c; - - while ((c = canon_serial_get_byte(camera->port)) != CANON_FBEG) - if (c == -1) return NULL; - while ((c = canon_serial_get_byte(camera->port)) != CANON_FEND) { - if (c < 0) return NULL; - if (c == CANON_ESC) c = canon_serial_get_byte(camera->port) ^ CANON_XOR; - if (p-buffer >= sizeof(buffer)) { - gp_debug_printf(GP_DEBUG_LOW,"canon","FATAL ERROR: receive buffer overflow\n"); - return NULL; - } - *p++ = c; - } - if(cs->dump_packets == 1) - dump_hex(camera,"RECV",buffer,p-buffer); - if (len) *len = p-buffer; - return buffer; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + static unsigned char buffer[5000]; + + /* more than enough :-) (allow for a few run-together packets) */ + unsigned char *p = buffer; + int c; + + while ((c = canon_serial_get_byte (camera->port)) != CANON_FBEG) + if (c == -1) + return NULL; + while ((c = canon_serial_get_byte (camera->port)) != CANON_FEND) { + if (c < 0) + return NULL; + if (c == CANON_ESC) + c = canon_serial_get_byte (camera->port) ^ CANON_XOR; + if (p - buffer >= sizeof (buffer)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "FATAL ERROR: receive buffer overflow\n"); + return NULL; + } + *p++ = c; + } + if (cs->dump_packets == 1) + dump_hex (camera, "RECV", buffer, p - buffer); + if (len) + *len = p - buffer; + return buffer; } @@ -155,72 +166,79 @@ static unsigned char seq_tx = 1; static unsigned char seq_rx = 1; -static int psa50_send_packet(Camera *camera, unsigned char type, - unsigned char seq, unsigned char *pkt,int len) +static int +psa50_send_packet (Camera *camera, unsigned char type, + unsigned char seq, unsigned char *pkt, int len) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *hdr = pkt-PKT_HDR_LEN; - unsigned short crc; - - hdr[PKT_TYPE] = type; - hdr[PKT_SEQ] = seq; - hdr[PKT_LEN_LSB] = len & 0xff; - hdr[PKT_LEN_MSB] = len >> 8; - - if (type == PKT_NACK) { - hdr[PKT_TYPE] = PKT_ACK; - hdr[PKT_TYPE+1] = '\xff';/* PKTACK_NACK; */ - } - - if (type == PKT_UPLOAD_EOT) { - hdr[PKT_TYPE] = PKT_EOT; - hdr[PKT_TYPE+1] = 0x3; - len = 2; - } - - if (type == PKT_EOT || type == PKT_ACK || type == PKT_NACK) len = 2; /* @@@ hack */ - crc = canon_psa50_gen_crc(hdr,len+PKT_HDR_LEN); - pkt[len] = crc & 0xff; - pkt[len+1] = crc >> 8; - - return psa50_send_frame(camera, hdr,len+PKT_HDR_LEN+2); + unsigned char *hdr = pkt - PKT_HDR_LEN; + unsigned short crc; + + hdr[PKT_TYPE] = type; + hdr[PKT_SEQ] = seq; + hdr[PKT_LEN_LSB] = len & 0xff; + hdr[PKT_LEN_MSB] = len >> 8; + + if (type == PKT_NACK) { + hdr[PKT_TYPE] = PKT_ACK; + hdr[PKT_TYPE + 1] = '\xff'; /* PKTACK_NACK; */ + } + + if (type == PKT_UPLOAD_EOT) { + hdr[PKT_TYPE] = PKT_EOT; + hdr[PKT_TYPE + 1] = 0x3; + len = 2; + } + + if (type == PKT_EOT || type == PKT_ACK || type == PKT_NACK) + len = 2; /* @@@ hack */ + crc = canon_psa50_gen_crc (hdr, len + PKT_HDR_LEN); + pkt[len] = crc & 0xff; + pkt[len + 1] = crc >> 8; + + return psa50_send_frame (camera, hdr, len + PKT_HDR_LEN + 2); } -static unsigned char *psa50_recv_packet(Camera *camera, unsigned char *type, - unsigned char *seq, int *len) +static unsigned char * +psa50_recv_packet (Camera *camera, unsigned char *type, unsigned char *seq, int *len) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *pkt; - unsigned short crc; - int raw_length,length=0; - - pkt = psa50_recv_frame(camera, &raw_length); - if (!pkt) return NULL; - if (raw_length < PKT_HDR_LEN) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: packet truncated\n"); - return NULL; - } - if (pkt[PKT_TYPE] == PKT_MSG) { - length = pkt[PKT_LEN_LSB] | (pkt[PKT_LEN_MSB] << 8); - if (length+PKT_HDR_LEN > raw_length-2) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: invalid length\n"); - /*fprintf(stderr,"Sending NACK\n"); - psa50_send_packet(PKT_NACK,seq_rx++,psa50_eot+PKT_HDR_LEN,0); */ - receive_error = ERROR_RECEIVED; - return NULL; - } - } - crc = pkt[raw_length-2] | (pkt[raw_length-1] << 8); - if (!canon_psa50_chk_crc(pkt,raw_length-2,crc)) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: CRC error\n"); - return NULL; - } - if (type) *type = pkt[PKT_TYPE]; - if (seq) *seq = pkt[PKT_SEQ]; - if (len) *len = length; - if (*type == PKT_ACK || *type == PKT_EOT) return pkt; - return pkt+PKT_HDR_LEN; + unsigned char *pkt; + unsigned short crc; + int raw_length, length = 0; + + pkt = psa50_recv_frame (camera, &raw_length); + if (!pkt) + return NULL; + if (raw_length < PKT_HDR_LEN) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: packet truncated\n"); + return NULL; + } + if (pkt[PKT_TYPE] == PKT_MSG) { + length = pkt[PKT_LEN_LSB] | (pkt[PKT_LEN_MSB] << 8); + if (length + PKT_HDR_LEN > raw_length - 2) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: invalid length\n"); + /*fprintf(stderr,"Sending NACK\n"); + psa50_send_packet(PKT_NACK,seq_rx++,psa50_eot+PKT_HDR_LEN,0); */ + receive_error = ERROR_RECEIVED; + return NULL; + } + } + crc = pkt[raw_length - 2] | (pkt[raw_length - 1] << 8); + if (!canon_psa50_chk_crc (pkt, raw_length - 2, crc)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: CRC error\n"); + return NULL; + } + if (type) + *type = pkt[PKT_TYPE]; + if (seq) + *seq = pkt[PKT_SEQ]; + if (len) + *len = length; + if (*type == PKT_ACK || *type == PKT_EOT) + return pkt; + return pkt + PKT_HDR_LEN; } @@ -257,57 +275,68 @@ static unsigned char *psa50_recv_packet(Camera *camera, unsigned char *type, * 0 : communication error (no reply received for example) * -1 : NACK received. */ -static int psa50_wait_for_ack(Camera *camera) +static int +psa50_wait_for_ack (Camera *camera) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *pkt; - unsigned char type,seq,old_seq; - int len; - - while (1) { - pkt = psa50_recv_packet(camera, &type,&seq,&len); - if (!pkt) return 0; - if (seq == seq_tx && type == PKT_ACK) { - if (pkt[2] == PKTACK_NACK) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: NACK received\n"); - return -1; - } - seq_tx++; - return 1; - } - old_seq='\0'; - if (type == PKT_EOT) { - old_seq=pkt[0]; - if (receive_error == NOERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Old EOT received, sending corresponding ACK\n"); - if (!psa50_send_packet(camera,PKT_ACK,old_seq,psa50_eot+PKT_HDR_LEN,0)) return 0; - pkt = psa50_recv_packet(camera,&type,&seq,&len); - if (!pkt) return 0; - if (seq == old_seq && type == PKT_ACK) { - if (pkt[2] == PKTACK_NACK) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Old EOT acknowledged\n"); - return -1; - } - return 1; - } - } - } - /* error already aknowledged, we skip the following ones */ - if (receive_error == ERROR_RECEIVED) { - if (!psa50_send_packet(camera,PKT_NACK,old_seq,psa50_eot+PKT_HDR_LEN,0)) return 0; - return 1; - } - - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: ACK format or sequence error, retrying\n"); - gp_debug_printf(GP_DEBUG_LOW,"canon","Sending NACK\n"); - psa50_send_packet(camera,PKT_NACK,seq_rx++,psa50_eot+PKT_HDR_LEN,0); - receive_error = ERROR_RECEIVED; + unsigned char *pkt; + unsigned char type, seq, old_seq; + int len; + + while (1) { + pkt = psa50_recv_packet (camera, &type, &seq, &len); + if (!pkt) + return 0; + if (seq == seq_tx && type == PKT_ACK) { + if (pkt[2] == PKTACK_NACK) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: NACK received\n"); + return -1; + } + seq_tx++; + return 1; + } + old_seq = '\0'; + if (type == PKT_EOT) { + old_seq = pkt[0]; + if (receive_error == NOERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Old EOT received, sending corresponding ACK\n"); + if (!psa50_send_packet + (camera, PKT_ACK, old_seq, psa50_eot + PKT_HDR_LEN, 0)) + return 0; + pkt = psa50_recv_packet (camera, &type, &seq, &len); + if (!pkt) + return 0; + if (seq == old_seq && type == PKT_ACK) { + if (pkt[2] == PKTACK_NACK) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Old EOT acknowledged\n"); + return -1; + } + return 1; + } + } + } + /* error already aknowledged, we skip the following ones */ + if (receive_error == ERROR_RECEIVED) { + if (!psa50_send_packet + (camera, PKT_NACK, old_seq, psa50_eot + PKT_HDR_LEN, 0)) + return 0; + return 1; + } + + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: ACK format or sequence error, retrying\n"); + gp_debug_printf (GP_DEBUG_LOW, "canon", "Sending NACK\n"); + psa50_send_packet (camera, PKT_NACK, seq_rx++, psa50_eot + PKT_HDR_LEN, 0); + receive_error = ERROR_RECEIVED; /* * just keep on trying. protocol seems to retransmit EOTs, so we may get * some old EOTs when we're actually expecting ACKs. */ - } + } } /** @@ -321,94 +350,107 @@ static int psa50_wait_for_ack(Camera *camera) * dir : direction. * ap : message payload (list of arguments, see 'man va_start' */ -static int psa50_send_msg(Camera *camera,unsigned char mtype, - unsigned char dir,va_list *ap) +static int +psa50_send_msg (Camera *camera, unsigned char mtype, unsigned char dir, va_list * ap) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char buffer[MAX_PKT_PAYLOAD+2]; /* allow space for CRC */ - unsigned char upload_buffer[MAX_PKT_PAYLOAD+2]; - unsigned char *pkt, *pkt2, *pos; - int total, good_ack, try; - - memset(buffer,0,PKT_HDR_LEN+MSG_HDR_LEN); - - pkt = buffer+PKT_HDR_LEN; - pkt[MSG_02] = 2; - pkt[MSG_MTYPE] = mtype; - pkt[MSG_DIR] = dir; - - pos = pkt+MSG_HDR_LEN; - total = 0; - - while (1) { - const char *str; - int len; - - str = va_arg(*ap,unsigned char *); - if (!str) break; - len = va_arg(*ap,int); - if (pos+len-pkt > MAX_MSG_SIZE && cs->uploading != 1) { - gp_debug_printf(GP_DEBUG_LOW,"canon","FATAL ERROR: message too big (%i)\n",pos+len-pkt); - return -1; - } - memcpy(pos,str,len); - pos += len; - } - - total = pos-pkt; - - pkt[MSG_LEN_LSB] = total & 0xff; - pkt[MSG_LEN_MSB] = total >> 8; - - if (cs->uploading==1) { - memset(upload_buffer,0,PKT_HDR_LEN+MSG_HDR_LEN); - pkt2 = upload_buffer; - memcpy(pkt2,pkt+UPLOAD_DATA_BLOCK,total-UPLOAD_DATA_BLOCK); - for(try=0;try<MAX_TRIES;try++) { - psa50_send_packet(camera, PKT_MSG,0,pkt,UPLOAD_DATA_BLOCK); - psa50_send_packet(camera, PKT_MSG,0x1,pkt2, - total-UPLOAD_DATA_BLOCK); - if (!psa50_send_packet(camera, PKT_UPLOAD_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,1)) - return 0; - if (!psa50_send_packet(camera, PKT_UPLOAD_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,1)) - return 0; - - good_ack = psa50_wait_for_ack(camera); - if (good_ack == 1) - return good_ack; - } - return -1; - } - else { - pkt[MSG_LEN_LSB] = total & 0xff; - pkt[MSG_LEN_MSB] = total >> 8; - for (try=1; try < MAX_TRIES; try++) { - if (!psa50_send_packet(camera,PKT_MSG,0,pkt,total)) return 0; - if (!psa50_send_packet(camera,PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,1)) return 0; - good_ack = psa50_wait_for_ack(camera); - if (good_ack == -1) { - gp_debug_printf(GP_DEBUG_LOW,"canon","NACK received, retrying command\n"); - } - else if (good_ack==1) { - return good_ack; - } - else { - gp_debug_printf(GP_DEBUG_LOW,"canon","No ACK received, retrying command\n"); - if (try==2) { - //is the camera still there? - if (!psa50_send_packet(camera,PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0)) return 0; - good_ack = psa50_wait_for_ack(camera); - if (good_ack==0) { - receive_error = FATAL_ERROR; - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: FATAL ERROR\n"); - clear_readiness(camera); - return -1; - } - } - } - } - return -1; - } + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + unsigned char buffer[MAX_PKT_PAYLOAD + 2]; /* allow space for CRC */ + unsigned char upload_buffer[MAX_PKT_PAYLOAD + 2]; + unsigned char *pkt, *pkt2, *pos; + int total, good_ack, try; + + memset (buffer, 0, PKT_HDR_LEN + MSG_HDR_LEN); + + pkt = buffer + PKT_HDR_LEN; + pkt[MSG_02] = 2; + pkt[MSG_MTYPE] = mtype; + pkt[MSG_DIR] = dir; + + pos = pkt + MSG_HDR_LEN; + total = 0; + + while (1) { + const char *str; + int len; + + str = va_arg (*ap, unsigned char *); + + if (!str) + break; + len = va_arg (*ap, int); + + if (pos + len - pkt > MAX_MSG_SIZE && cs->uploading != 1) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "FATAL ERROR: message too big (%i)\n", + pos + len - pkt); + return -1; + } + memcpy (pos, str, len); + pos += len; + } + + total = pos - pkt; + + pkt[MSG_LEN_LSB] = total & 0xff; + pkt[MSG_LEN_MSB] = total >> 8; + + if (cs->uploading == 1) { + memset (upload_buffer, 0, PKT_HDR_LEN + MSG_HDR_LEN); + pkt2 = upload_buffer; + memcpy (pkt2, pkt + UPLOAD_DATA_BLOCK, total - UPLOAD_DATA_BLOCK); + for (try = 0; try < MAX_TRIES; try++) { + psa50_send_packet (camera, PKT_MSG, 0, pkt, UPLOAD_DATA_BLOCK); + psa50_send_packet (camera, PKT_MSG, 0x1, pkt2, + total - UPLOAD_DATA_BLOCK); + if (!psa50_send_packet + (camera, PKT_UPLOAD_EOT, seq_tx, psa50_eot + PKT_HDR_LEN, 1)) + return 0; + if (!psa50_send_packet + (camera, PKT_UPLOAD_EOT, seq_tx, psa50_eot + PKT_HDR_LEN, 1)) + return 0; + + good_ack = psa50_wait_for_ack (camera); + if (good_ack == 1) + return good_ack; + } + return -1; + } else { + pkt[MSG_LEN_LSB] = total & 0xff; + pkt[MSG_LEN_MSB] = total >> 8; + for (try = 1; try < MAX_TRIES; try++) { + if (!psa50_send_packet (camera, PKT_MSG, 0, pkt, total)) + return 0; + if (!psa50_send_packet + (camera, PKT_EOT, seq_tx, psa50_eot + PKT_HDR_LEN, 1)) + return 0; + good_ack = psa50_wait_for_ack (camera); + if (good_ack == -1) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "NACK received, retrying command\n"); + } else if (good_ack == 1) { + return good_ack; + } else { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "No ACK received, retrying command\n"); + if (try == 2) { + //is the camera still there? + if (!psa50_send_packet + (camera, PKT_EOT, seq_tx, psa50_eot + PKT_HDR_LEN, + 0)) + return 0; + good_ack = psa50_wait_for_ack (camera); + if (good_ack == 0) { + receive_error = FATAL_ERROR; + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: FATAL ERROR\n"); + clear_readiness (camera); + return -1; + } + } + } + } + return -1; + } } /** @@ -425,146 +467,163 @@ static int psa50_send_msg(Camera *camera,unsigned char mtype, * Returns: * char* : pointer to the message payload. */ -static unsigned char *psa50_recv_msg(Camera *camera, unsigned char mtype, - unsigned char dir,int *total) +static unsigned char * +psa50_recv_msg (Camera *camera, unsigned char mtype, unsigned char dir, int *total) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - static unsigned char *msg = NULL; - static int msg_size = 512; /* initial allocation/2 */ - unsigned char *frag; - unsigned char type,seq; - int len,length = 0,msg_pos = 0; - - while (1) { - frag = psa50_recv_packet(camera,&type,NULL,&len); - if (!frag) return NULL; - if (type == PKT_MSG) break; - //uploading is special + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + static unsigned char *msg = NULL; + static int msg_size = 512; /* initial allocation/2 */ + unsigned char *frag; + unsigned char type, seq; + int len, length = 0, msg_pos = 0; + + while (1) { + frag = psa50_recv_packet (camera, &type, NULL, &len); + if (!frag) + return NULL; + if (type == PKT_MSG) + break; + //uploading is special // if (type == PKT_ACK && mtype == 0x3 && dir == 0x21) break; - if (type == PKT_EOT) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Old EOT received sending corresponding ACK\n"); - psa50_send_packet(camera,PKT_ACK,frag[0],psa50_eot+PKT_HDR_LEN,0); - } - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: protocol error, retrying\n"); - } - /* we keep the fragment only if there was no error */ - if (receive_error == NOERROR) { - length = frag[MSG_LEN_LSB] | (frag[MSG_LEN_MSB] << 8); - /* while uploading we expect 2 ACKs and a message 0x3 0x21 - * not always in the same order */ + if (type == PKT_EOT) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Old EOT received sending corresponding ACK\n"); + psa50_send_packet (camera, PKT_ACK, frag[0], psa50_eot + PKT_HDR_LEN, + 0); + } + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: protocol error, retrying\n"); + } + /* we keep the fragment only if there was no error */ + if (receive_error == NOERROR) { + length = frag[MSG_LEN_LSB] | (frag[MSG_LEN_MSB] << 8); + /* while uploading we expect 2 ACKs and a message 0x3 0x21 + * not always in the same order */ // if (type == PKT_ACK && mtype == 0x3 && dir == 0x21) { // gp_debug_printf(GP_DEBUG_LOW,"canon","ignoring ACK received while waiting for MSG\n"); // return frag; // } - if (len < MSG_HDR_LEN || frag[MSG_02] != 2) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: message format error\n"); - return NULL; - } - - if (frag[MSG_MTYPE] != mtype || frag[MSG_DIR] != dir) { - if(frag[MSG_MTYPE] =='\x01' && frag[MSG_DIR] == '\x00' && - memcmp(frag+12,"\x30\x00\x00\x30",4)) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: Battery exhausted, camera off"); - gp_camera_status(camera, _("Battery exhausted, camera off.")); - receive_error=ERROR_LOWBATT; - } - else { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: unexpected message.\n"); - gp_camera_status(camera, _("ERROR: unexpected message")); - } - return NULL; - } - frag += MSG_HDR_LEN; - len -= MSG_HDR_LEN; - } - while (1) { - if (receive_error == NOERROR) { - if (msg_pos+len > length) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: message overrun\n"); - gp_camera_status(camera, _("ERROR: message overrun")); - return NULL; - } - if (msg_pos+len > msg_size || !msg) { - msg_size *= 2; - msg = realloc(msg,msg_size); - if (!msg) { - perror("realloc"); - exit(1); - } - } - memcpy(msg+msg_pos,frag,len); - msg_pos += len; - } - frag = psa50_recv_packet(camera,&type,&seq,&len); - if (!frag) return NULL; - if (type == PKT_EOT) { - /* in case of error we don't want to stop as the camera will send - the 1st packet of the sequence again */ - if (receive_error == ERROR_RECEIVED) { - seq_rx = seq; - psa50_send_packet(camera,PKT_NACK,seq_rx,psa50_eot+PKT_HDR_LEN,0); - receive_error = ERROR_ADDRESSED; - } else { - if (seq == seq_rx) break; - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: out of sequence\n"); - gp_camera_status(camera, _("ERROR: out of sequence.")); - return NULL; - } - } - if (type != PKT_MSG && receive_error == NOERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: unexpected packet type\n"); - gp_camera_status(camera, _("ERROR: unexpected packet type.")); - return NULL; - } - if (type == PKT_EOT && receive_error == ERROR_RECEIVED) { - receive_error = ERROR_ADDRESSED; - } - if (type == PKT_MSG && receive_error == ERROR_ADDRESSED) { - msg_pos =0; - length = frag[MSG_LEN_LSB] | (frag[MSG_LEN_MSB] << 8); - if (len < MSG_HDR_LEN || frag[MSG_02] != 2) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: message format error\n"); - gp_camera_status(camera, _("ERROR: message format error.")); - return NULL; - } - - if (frag[MSG_MTYPE] != mtype || frag[MSG_DIR] != dir) { - if(frag[MSG_MTYPE] =='\x01' && frag[MSG_DIR] == '\x00' && - memcmp(frag+12,"\x30\x00\x00\x30",4)) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: Battery exhausted, camera off"); - gp_camera_status(camera, _("Battery exhausted, camera off.")); - receive_error=ERROR_LOWBATT; - } - else { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: unexpected message2\n"); - gp_camera_status(camera, _("ERROR: unexpected message2.")); - } - return NULL; - } - frag += MSG_HDR_LEN; - len -= MSG_HDR_LEN; - receive_error = NOERROR; - } - } - if (receive_error == ERROR_ADDRESSED) { - receive_error = NOERROR; - } - if (receive_error == NOERROR) { - /*we want to be sure the camera U N D E R S T A N D S our packets*/ - if (cs->uploading == 1 && cs->model == CANON_PS_A50) - cs->slow_send = 1; - if (!psa50_send_packet(camera,PKT_ACK,seq_rx++,psa50_eot+PKT_HDR_LEN,0)) { - if (cs->uploading == 1 && cs->model == CANON_PS_A50) - cs->slow_send = 0; - return NULL; - } - if (cs->uploading == 1 && cs->model == CANON_PS_A50) - cs->slow_send = 0; - if (total) *total = msg_pos; - return msg; - } - - return NULL; + if (len < MSG_HDR_LEN || frag[MSG_02] != 2) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: message format error\n"); + return NULL; + } + + if (frag[MSG_MTYPE] != mtype || frag[MSG_DIR] != dir) { + if (frag[MSG_MTYPE] == '\x01' && frag[MSG_DIR] == '\x00' && + memcmp (frag + 12, "\x30\x00\x00\x30", 4)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: Battery exhausted, camera off"); + gp_camera_status (camera, _("Battery exhausted, camera off.")); + receive_error = ERROR_LOWBATT; + } else { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: unexpected message.\n"); + gp_camera_status (camera, _("ERROR: unexpected message")); + } + return NULL; + } + frag += MSG_HDR_LEN; + len -= MSG_HDR_LEN; + } + while (1) { + if (receive_error == NOERROR) { + if (msg_pos + len > length) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: message overrun\n"); + gp_camera_status (camera, _("ERROR: message overrun")); + return NULL; + } + if (msg_pos + len > msg_size || !msg) { + msg_size *= 2; + msg = realloc (msg, msg_size); + if (!msg) { + perror ("realloc"); + exit (1); + } + } + memcpy (msg + msg_pos, frag, len); + msg_pos += len; + } + frag = psa50_recv_packet (camera, &type, &seq, &len); + if (!frag) + return NULL; + if (type == PKT_EOT) { + /* in case of error we don't want to stop as the camera will send + the 1st packet of the sequence again */ + if (receive_error == ERROR_RECEIVED) { + seq_rx = seq; + psa50_send_packet (camera, PKT_NACK, seq_rx, + psa50_eot + PKT_HDR_LEN, 0); + receive_error = ERROR_ADDRESSED; + } else { + if (seq == seq_rx) + break; + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: out of sequence\n"); + gp_camera_status (camera, _("ERROR: out of sequence.")); + return NULL; + } + } + if (type != PKT_MSG && receive_error == NOERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: unexpected packet type\n"); + gp_camera_status (camera, _("ERROR: unexpected packet type.")); + return NULL; + } + if (type == PKT_EOT && receive_error == ERROR_RECEIVED) { + receive_error = ERROR_ADDRESSED; + } + if (type == PKT_MSG && receive_error == ERROR_ADDRESSED) { + msg_pos = 0; + length = frag[MSG_LEN_LSB] | (frag[MSG_LEN_MSB] << 8); + if (len < MSG_HDR_LEN || frag[MSG_02] != 2) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: message format error\n"); + gp_camera_status (camera, _("ERROR: message format error.")); + return NULL; + } + + if (frag[MSG_MTYPE] != mtype || frag[MSG_DIR] != dir) { + if (frag[MSG_MTYPE] == '\x01' && frag[MSG_DIR] == '\x00' && + memcmp (frag + 12, "\x30\x00\x00\x30", 4)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: Battery exhausted, camera off"); + gp_camera_status (camera, + _("Battery exhausted, camera off.")); + receive_error = ERROR_LOWBATT; + } else { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: unexpected message2\n"); + gp_camera_status (camera, + _("ERROR: unexpected message2.")); + } + return NULL; + } + frag += MSG_HDR_LEN; + len -= MSG_HDR_LEN; + receive_error = NOERROR; + } + } + if (receive_error == ERROR_ADDRESSED) { + receive_error = NOERROR; + } + if (receive_error == NOERROR) { + /*we want to be sure the camera U N D E R S T A N D S our packets */ + if (cs->uploading == 1 && cs->model == CANON_PS_A50) + cs->slow_send = 1; + if (!psa50_send_packet (camera, PKT_ACK, seq_rx++, psa50_eot + PKT_HDR_LEN, 0)) { + if (cs->uploading == 1 && cs->model == CANON_PS_A50) + cs->slow_send = 0; + return NULL; + } + if (cs->uploading == 1 && cs->model == CANON_PS_A50) + cs->slow_send = 0; + if (total) + *total = msg_pos; + return msg; + } + + return NULL; } /** @@ -587,185 +646,199 @@ static unsigned char *psa50_recv_msg(Camera *camera, unsigned char mtype, * psa50_serial_dialogue(0x05,0x12,&len,name,strlen(name)+1,NULL); * */ -static unsigned char *psa50_serial_dialogue(Camera *camera, - unsigned char mtype, - unsigned char dir,int *len,...) +static unsigned char * +psa50_serial_dialogue (Camera *camera, unsigned char mtype, unsigned char dir, int *len, ...) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - va_list ap; - int okay,try; - unsigned char *good_ack; - - for ( try = 1; try < MAX_TRIES; try++) { - va_start(ap,len); - okay = psa50_send_msg(camera,mtype,dir,&ap); - va_end(ap); - if (!okay) return NULL; - /* while uploading we receive 2 ACKs and 1 confirmation message - * The first ACK has already been received if we are here */ - if (cs->uploading == 1) { - seq_tx--; - good_ack = psa50_recv_msg(camera,mtype,dir ^ DIR_REVERSE,len); - if (!good_ack) return NULL; - if (good_ack[0] == seq_tx && good_ack[1] == 0x5) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ACK received waiting for the confirmation message\n"); - good_ack = psa50_recv_msg(camera,mtype,dir ^ DIR_REVERSE,len); - } else { - okay = psa50_wait_for_ack(camera); - if (okay == 1) - return good_ack; - } - } - else - good_ack = psa50_recv_msg(camera,mtype,dir ^ DIR_REVERSE,len); - - if (good_ack) return good_ack; - if (receive_error == NOERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Resending message\n"); - seq_tx--; - } - if (receive_error == FATAL_ERROR) break; - } - return NULL; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + va_list ap; + int okay, try; + unsigned char *good_ack; + + for (try = 1; try < MAX_TRIES; try++) { + va_start (ap, len); + okay = psa50_send_msg (camera, mtype, dir, &ap); + va_end (ap); + if (!okay) + return NULL; + /* while uploading we receive 2 ACKs and 1 confirmation message + * The first ACK has already been received if we are here */ + if (cs->uploading == 1) { + seq_tx--; + good_ack = psa50_recv_msg (camera, mtype, dir ^ DIR_REVERSE, len); + if (!good_ack) + return NULL; + if (good_ack[0] == seq_tx && good_ack[1] == 0x5) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ACK received waiting for the confirmation message\n"); + good_ack = + psa50_recv_msg (camera, mtype, dir ^ DIR_REVERSE, len); + } else { + okay = psa50_wait_for_ack (camera); + if (okay == 1) + return good_ack; + } + } else + good_ack = psa50_recv_msg (camera, mtype, dir ^ DIR_REVERSE, len); + + if (good_ack) + return good_ack; + if (receive_error == NOERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "Resending message\n"); + seq_tx--; + } + if (receive_error == FATAL_ERROR) + break; + } + return NULL; } /** * Utility function used by psa50_usb_dialogue */ -void intatpos(unsigned char *block, int pos, int integer ) +void +intatpos (unsigned char *block, int pos, int integer) { - *(unsigned *)(block+pos)=integer; + *(unsigned *) (block + pos) = integer; } /** * USB version of the dialogue function. */ -static unsigned char *psa50_usb_dialogue(Camera *camera, char cmd1, char cmd2, int cmd3, int *retlen, const char *payload, int pay_length) +static unsigned char * +psa50_usb_dialogue (Camera *camera, char cmd1, char cmd2, int cmd3, int *retlen, + const char *payload, int pay_length) { - int msgsize; - char packet[0x3000]; - static char buffer[BULK_READ_SIZE]; - // int i; - int lonlen, status; - - char *funct = "UNKNOWN FUNCTION"; - - switch(cmd1) - { - case 0x01: - if (cmd2 == 0x11 && cmd3 == 0x202) - funct = "Get picture/thumbnail"; - if (cmd2 == 0x12 && cmd3 == 0x201) - funct = "Identify camera"; - break; - case 0x03: - if (cmd2 == 0x12 && cmd3 == 0x201) - funct = "Get time"; - break; - case 0x04: - if (cmd2 == 0x12 && cmd3 == 0x201) - funct = "Set time"; - break; - case 0x05: - if (cmd2 == 0x11 && cmd3 == 0x201) - funct = "Make directory"; - if (cmd2 == 0x12 && cmd3 == 0x201) - funct = "Change owner"; - break; - case 0x06: - if (cmd2 == 0x11 && cmd3 == 0x201) - funct = "Remove directory"; - break; - case 0x09: - if (cmd2 == 0x11 && cmd3 == 0x201) - funct = "Disk info request"; - break; - case 0x0a: - if (cmd2 == 0x11 && cmd3 == 0x202) - funct = "Flash device ident"; - if (cmd2 == 0x12 && cmd3 == 0x201) - funct = "Power supply status"; - break; - case 0x0b: - if (cmd2 == 0x11 && cmd3 == 0x202) - funct = "Get directory"; - break; - case 0x0d: - if (cmd2 == 0x11 && cmd3 == 0x201) - funct = "Delete file"; - break; - case 0x0e: - if (cmd2 == 0x11 && cmd3 == 0x201) - funct = "Set file attribute"; - break; - } - - gp_debug_printf(GP_DEBUG_LOW,"canon", "\n\npsa50_usb_dialogue() cmd 0x%x 0x%x 0x%x (%s), payload = %i bytes\n", - cmd1, cmd2, cmd3, funct, pay_length); - - if ((pay_length + 0x50) > sizeof(packet)) { - gp_debug_printf(GP_DEBUG_LOW,"canon", "psa50_usb_dialogue: payload too big, won't fit into buffer (%i > %i)", - (pay_length + 0x50), sizeof(packet)); - return NULL; - } - - memset(packet, 0x00, sizeof(packet)); /* zero block */ - memset(buffer, 0x00, sizeof(buffer)); - - intatpos(packet, 0x0, 0x10 + pay_length); - packet[0x40]= 0x2; - packet[0x44]= cmd1; - packet[0x47]= cmd2; - intatpos(packet, 0x04, cmd3); /* cmd3 */ - intatpos(packet, 0x4c, 0x12345678); - intatpos(packet, 0x48, 0x10 + pay_length); - - msgsize = 0x50 + pay_length; /* TOTAL msg size */ - - if (pay_length > 0) - memcpy(packet+0x50, payload, pay_length); - - status = gp_port_usb_msg_write(camera->port,msgsize > 1 ? 0x04 : 0x0c,0x10,0,packet,msgsize); - if (status != msgsize) { - gp_debug_printf(GP_DEBUG_LOW,"canon", "psa50_usb_dialogue: write failed! (returned %i)\n", - status); - return NULL; - } - - if (cmd3==0x202) { - status = gp_port_read(camera->port, buffer, 0x40); - if (status != 0x40) { - gp_debug_printf(GP_DEBUG_LOW,"canon", "psa50_usb_dialogue: read #1 failed! " - "(returned %i, expected %i)\n", status, 0x40); - return NULL; - } - - lonlen = *(unsigned *)(buffer+0x6); - *retlen=lonlen; - - /* read max BULK_READ_SIZE bytes */ - if (lonlen > BULK_READ_SIZE) - lonlen = BULK_READ_SIZE; - - status = gp_port_read(camera->port,buffer,lonlen); - if (status != lonlen) { - gp_debug_printf(GP_DEBUG_LOW,"canon", "psa50_usb_dialogue: read #2 failed! " - "(returned %i, expected %i)\n", status, lonlen); - return NULL; - } - - return buffer; - } else { - //fprintf(stderr,"Internal retlen: %x\n",*retlen); - status = gp_port_read(camera->port, buffer, *retlen+0x50); - if (status != *retlen+0x50) { - gp_debug_printf(GP_DEBUG_LOW,"canon", "psa50_usb_dialogue: read #3 failed! " - "(returned %i, expected %i)\n", status, *retlen+0x50); - return NULL; - } - return buffer+0x50; - } + int msgsize; + char packet[0x3000]; + static char buffer[BULK_READ_SIZE]; + + // int i; + int lonlen, status; + + char *funct = "UNKNOWN FUNCTION"; + + switch (cmd1) { + case 0x01: + if (cmd2 == 0x11 && cmd3 == 0x202) + funct = "Get picture/thumbnail"; + if (cmd2 == 0x12 && cmd3 == 0x201) + funct = "Identify camera"; + break; + case 0x03: + if (cmd2 == 0x12 && cmd3 == 0x201) + funct = "Get time"; + break; + case 0x04: + if (cmd2 == 0x12 && cmd3 == 0x201) + funct = "Set time"; + break; + case 0x05: + if (cmd2 == 0x11 && cmd3 == 0x201) + funct = "Make directory"; + if (cmd2 == 0x12 && cmd3 == 0x201) + funct = "Change owner"; + break; + case 0x06: + if (cmd2 == 0x11 && cmd3 == 0x201) + funct = "Remove directory"; + break; + case 0x09: + if (cmd2 == 0x11 && cmd3 == 0x201) + funct = "Disk info request"; + break; + case 0x0a: + if (cmd2 == 0x11 && cmd3 == 0x202) + funct = "Flash device ident"; + if (cmd2 == 0x12 && cmd3 == 0x201) + funct = "Power supply status"; + break; + case 0x0b: + if (cmd2 == 0x11 && cmd3 == 0x202) + funct = "Get directory"; + break; + case 0x0d: + if (cmd2 == 0x11 && cmd3 == 0x201) + funct = "Delete file"; + break; + case 0x0e: + if (cmd2 == 0x11 && cmd3 == 0x201) + funct = "Set file attribute"; + break; + } + + gp_debug_printf (GP_DEBUG_LOW, "canon", + "\n\npsa50_usb_dialogue() cmd 0x%x 0x%x 0x%x (%s), payload = %i bytes\n", + cmd1, cmd2, cmd3, funct, pay_length); + + if ((pay_length + 0x50) > sizeof (packet)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "psa50_usb_dialogue: payload too big, won't fit into buffer (%i > %i)", + (pay_length + 0x50), sizeof (packet)); + return NULL; + } + + memset (packet, 0x00, sizeof (packet)); /* zero block */ + memset (buffer, 0x00, sizeof (buffer)); + + intatpos (packet, 0x0, 0x10 + pay_length); + packet[0x40] = 0x2; + packet[0x44] = cmd1; + packet[0x47] = cmd2; + intatpos (packet, 0x04, cmd3); /* cmd3 */ + intatpos (packet, 0x4c, 0x12345678); + intatpos (packet, 0x48, 0x10 + pay_length); + + msgsize = 0x50 + pay_length; /* TOTAL msg size */ + + if (pay_length > 0) + memcpy (packet + 0x50, payload, pay_length); + + status = gp_port_usb_msg_write (camera->port, msgsize > 1 ? 0x04 : 0x0c, 0x10, 0, + packet, msgsize); + if (status != msgsize) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "psa50_usb_dialogue: write failed! (returned %i)\n", status); + return NULL; + } + + if (cmd3 == 0x202) { + status = gp_port_read (camera->port, buffer, 0x40); + if (status != 0x40) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "psa50_usb_dialogue: read #1 failed! " + "(returned %i, expected %i)\n", status, 0x40); + return NULL; + } + + lonlen = *(unsigned *) (buffer + 0x6); + *retlen = lonlen; + + /* read max BULK_READ_SIZE bytes */ + if (lonlen > BULK_READ_SIZE) + lonlen = BULK_READ_SIZE; + + status = gp_port_read (camera->port, buffer, lonlen); + if (status != lonlen) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "psa50_usb_dialogue: read #2 failed! " + "(returned %i, expected %i)\n", status, lonlen); + return NULL; + } + + return buffer; + } else { + //fprintf(stderr,"Internal retlen: %x\n",*retlen); + status = gp_port_read (camera->port, buffer, *retlen + 0x50); + if (status != *retlen + 0x50) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "psa50_usb_dialogue: read #3 failed! " + "(returned %i, expected %i)\n", status, + *retlen + 0x50); + return NULL; + } + return buffer + 0x50; + } } @@ -785,39 +858,43 @@ static unsigned char *psa50_usb_dialogue(Camera *camera, char cmd1, char cmd2, i #define SPEED_57600 "\x00\x03\x40\x02\x01\x10\x00\x00\x00\x00\x5e\x57" #define SPEED_115200 "\x00\x03\x80\x02\x01\x10\x00\x00\x00\x00\x4d\xf9" -char psa50_id[200]; /* some models may have a lot to report */ +char psa50_id[200]; /* some models may have a lot to report */ + //struct canon_info camera_data; -static unsigned int get_int(const unsigned char *p) +static unsigned int +get_int (const unsigned char *p) { - return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); + return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); } /** * Switches the camera off */ -int psa50_end(Camera *camera) +int +psa50_end (Camera *camera) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - canon_serial_send(camera,"\xC0\x00\x02\x55\x2C\xC1",6,USLEEP2); - canon_serial_send(camera,"\xC0\x00\x04\x01\x00\x00\x00\x24\xC6\xC1",8,USLEEP2); - return 0; + canon_serial_send (camera, "\xC0\x00\x02\x55\x2C\xC1", 6, USLEEP2); + canon_serial_send (camera, "\xC0\x00\x04\x01\x00\x00\x00\x24\xC6\xC1", 8, USLEEP2); + return 0; } /** * Switches the camera off, and resets the serial driver to 9600 bauds, * in order to be ready to switch the camera back on again if wanted. */ -int psa50_off(Camera *camera) +int +psa50_off (Camera *camera) { - canon_serial_send(camera,"\xC0\x00\x02\x55\x2C\xC1",6,USLEEP2); - canon_serial_send(camera,"\xC0\x00\x04\x01\x00\x00\x00\x24\xC6\xC1",8,USLEEP2); - canon_serial_change_speed(camera->port,9600); - return 0; + canon_serial_send (camera, "\xC0\x00\x02\x55\x2C\xC1", 6, USLEEP2); + canon_serial_send (camera, "\xC0\x00\x04\x01\x00\x00\x00\x24\xC6\xC1", 8, USLEEP2); + canon_serial_change_speed (camera->port, 9600); + return 0; } /** @@ -825,50 +902,57 @@ int psa50_off(Camera *camera) * of action : DIR_CREATE, DIR_REMOVE * */ -int psa50_directory_operations(Camera *camera, char *path, int action) +int +psa50_directory_operations (Camera *camera, char *path, int action) { - unsigned char *msg; - int len; - char type; + unsigned char *msg; + int len; + char type; + // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - switch (action) { - case DIR_CREATE: - type = 0x5; - break; - case DIR_REMOVE: - type = 0x6; - break; - default: - gp_debug_printf(GP_DEBUG_LOW,"canon","Bad operation specified : %i\n", action); - return GP_ERROR; - break; - } - - switch (canon_comm_method) { - case CANON_USB: - msg = psa50_usb_dialogue(camera, type,0x11,0x201,&len,path,strlen(path)+1); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera, type,0x11,&len,path,strlen(path)+1,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return 0; - } - - if(msg[0] != 0x00) { - if (action == DIR_CREATE) - gp_debug_printf(GP_DEBUG_LOW,"canon","Could not create directory %s\n",path); - else - gp_debug_printf(GP_DEBUG_LOW,"canon","Could not remove directory %s\n",path); - return 0; - } - - return 1; + switch (action) { + case DIR_CREATE: + type = 0x5; + break; + case DIR_REMOVE: + type = 0x6; + break; + default: + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Bad operation specified : %i\n", action); + return GP_ERROR; + break; + } + + switch (canon_comm_method) { + case CANON_USB: + msg = psa50_usb_dialogue (camera, type, 0x11, 0x201, &len, path, + strlen (path) + 1); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, type, 0x11, &len, path, + strlen (path) + 1, NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return 0; + } + + if (msg[0] != 0x00) { + if (action == DIR_CREATE) + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Could not create directory %s\n", path); + else + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Could not remove directory %s\n", path); + return 0; + } + + return 1; } /** @@ -878,107 +962,115 @@ int psa50_directory_operations(Camera *camera, char *path, int action) * This function also gets the firmware revision in the camera struct. * */ -int psa50_get_owner_name(Camera *camera) +int +psa50_get_owner_name (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - int len; - - switch (canon_comm_method) { - case CANON_USB: - len=0x4c; - msg = psa50_usb_dialogue(camera, 0x01,0x12,0x201,&len,0,0); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera, 0x01,0x12,&len,NULL); - break; - - } - - if (!msg) { - gp_debug_printf(GP_DEBUG_LOW,"canon","psa50_get_owner_name: msg error"); - psa50_error_type(camera); - return GP_ERROR; - } - gp_debug_printf(GP_DEBUG_LOW,"canon","psa50_get_owner_name: msg received"); - - /* Store these values in our "camera" structure: */ - memcpy(cs->firmwrev,(char *) msg+8,4); - strncpy(cs->ident,(char *) msg+12,30); - strncpy(cs->owner,(char *) msg+44,30); - - return GP_OK; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + len = 0x4c; + msg = psa50_usb_dialogue (camera, 0x01, 0x12, 0x201, &len, 0, 0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0x01, 0x12, &len, NULL); + break; + + } + + if (!msg) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "psa50_get_owner_name: msg error"); + psa50_error_type (camera); + return GP_ERROR; + } + gp_debug_printf (GP_DEBUG_LOW, "canon", "psa50_get_owner_name: msg received"); + + /* Store these values in our "camera" structure: */ + memcpy (cs->firmwrev, (char *) msg + 8, 4); + strncpy (cs->ident, (char *) msg + 12, 30); + strncpy (cs->owner, (char *) msg + 44, 30); + + return GP_OK; } /** * Get battery status. */ -int psa50_get_battery(Camera *camera, int *pwr_status, int *pwr_source) +int +psa50_get_battery (Camera *camera, int *pwr_status, int *pwr_source) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - int len; - - switch (canon_comm_method) { - case CANON_USB: - len=0x8; - msg = psa50_usb_dialogue(camera, 0x0A,0x12,0x201,&len,0,0); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera,0x0a,0x12,&len,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return -1; - } - - if (pwr_status) *pwr_status = msg[4]; - if (pwr_source) *pwr_source = msg[7]; - gp_debug_printf(GP_DEBUG_LOW,"canon","Status: %i / Source: %i\n",*pwr_status,*pwr_source); - return 0; + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + len = 0x8; + msg = psa50_usb_dialogue (camera, 0x0A, 0x12, 0x201, &len, 0, 0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0x0a, 0x12, &len, NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return -1; + } + + if (pwr_status) + *pwr_status = msg[4]; + if (pwr_source) + *pwr_source = msg[7]; + gp_debug_printf (GP_DEBUG_LOW, "canon", "Status: %i / Source: %i\n", *pwr_status, + *pwr_source); + return 0; } /** * Sets a file's attributes. See the 'Protocol' file for details. */ -int psa50_set_file_attributes(Camera *camera, const char *file, const char *dir, char attrs) +int +psa50_set_file_attributes (Camera *camera, const char *file, const char *dir, char attrs) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char buf[300]; - unsigned char *msg; - unsigned char attr[4]; - int len,name_len; - - attr[0] = attr[1] = attr[2] = 0; - attr[3] = attrs; - - switch (canon_comm_method) { - case CANON_USB: - memcpy(buf,attr,4); - memcpy(buf+4,dir,strlen(dir)+1); - memcpy(buf+4+strlen(dir)+1,file,strlen(file)+1); - name_len=strlen(dir)+strlen(file)+2+4; - len=0x4; - msg = psa50_usb_dialogue(camera, 0x0e,0x11,0x201,&len,buf,name_len); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera, 0xe,0x11,&len,attr,4,dir,strlen(dir)+1, - file,strlen(file)+1,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return -1; - } - - return 0; + unsigned char buf[300]; + unsigned char *msg; + unsigned char attr[4]; + int len, name_len; + + attr[0] = attr[1] = attr[2] = 0; + attr[3] = attrs; + + switch (canon_comm_method) { + case CANON_USB: + memcpy (buf, attr, 4); + memcpy (buf + 4, dir, strlen (dir) + 1); + memcpy (buf + 4 + strlen (dir) + 1, file, strlen (file) + 1); + name_len = strlen (dir) + strlen (file) + 2 + 4; + len = 0x4; + msg = psa50_usb_dialogue (camera, 0x0e, 0x11, 0x201, &len, buf, + name_len); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0xe, 0x11, &len, attr, 4, dir, + strlen (dir) + 1, file, strlen (file) + 1, + NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return -1; + } + + return 0; } /** @@ -987,35 +1079,40 @@ int psa50_set_file_attributes(Camera *camera, const char *file, const char *dir, * afterwards in order to check that everything went fine. * */ -int psa50_set_owner_name(Camera *camera, const char *name) +int +psa50_set_owner_name (Camera *camera, const char *name) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - int len; - - if (strlen(name) > 30) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Name too long (%i chars), could not store it !", strlen(name)); - gp_camera_status(camera, _("Name too long, could not store it!")); - return 0; - } - gp_debug_printf(GP_DEBUG_LOW,"canon","New owner: %s\n",name); - - switch (canon_comm_method) { - case CANON_USB: - len=0x4; - msg = psa50_usb_dialogue(camera, 0x05,0x12,0x201,&len,name,strlen(name)+1); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera, 0x05,0x12,&len,name,strlen(name)+1,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return GP_ERROR; - } - return psa50_get_owner_name(camera); + unsigned char *msg; + int len; + + if (strlen (name) > 30) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Name too long (%i chars), could not store it !", + strlen (name)); + gp_camera_status (camera, _("Name too long, could not store it!")); + return 0; + } + gp_debug_printf (GP_DEBUG_LOW, "canon", "New owner: %s\n", name); + + switch (canon_comm_method) { + case CANON_USB: + len = 0x4; + msg = psa50_usb_dialogue (camera, 0x05, 0x12, 0x201, &len, name, + strlen (name) + 1); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0x05, 0x12, &len, name, + strlen (name) + 1, NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return GP_ERROR; + } + return psa50_get_owner_name (camera); } @@ -1030,992 +1127,1103 @@ int psa50_set_owner_name(Camera *camera, const char *name) * time _a second time_, and the result will be wrong. Only use functions * that don't translate the date into localtime, like "gmtime". */ -time_t psa50_get_time(Camera *camera) +time_t +psa50_get_time (Camera *camera) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - int len; - time_t date; - - - switch (canon_comm_method) { - case CANON_USB: - len=0x10; - msg = psa50_usb_dialogue(camera, 0x03,0x12,0x201,&len,0,0); - break; - case CANON_SERIAL_RS232: - default: - msg=psa50_serial_dialogue(camera, 0x03,0x12,&len,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return GP_ERROR; - } - - /* Beware, this is very dirty, and might fail one day, if time_t - is not a 4-byte value anymore. */ - memcpy(&date,msg+4,4); - - return byteswap32(date); + unsigned char *msg; + int len; + time_t date; + + + switch (canon_comm_method) { + case CANON_USB: + len = 0x10; + msg = psa50_usb_dialogue (camera, 0x03, 0x12, 0x201, &len, 0, 0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0x03, 0x12, &len, NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return GP_ERROR; + } + + /* Beware, this is very dirty, and might fail one day, if time_t + is not a 4-byte value anymore. */ + memcpy (&date, msg + 4, 4); + + return byteswap32 (date); } -int psa50_set_time(Camera *camera) +int +psa50_set_time (Camera *camera) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - int len,i; - time_t date; - char pcdate[4]; - - date = time(NULL); - for (i=0;i<4;i++) - pcdate[i] = (date >> (8*i)) & 0xff; - - switch (canon_comm_method) { - case CANON_USB: - len=0x10; - msg = psa50_usb_dialogue(camera, 0x04,0x12,0x201,&len,0,0); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera, 0x04, 0x12, &len, pcdate, - sizeof(pcdate), - "\x00\x00\x00\x00\x00\x00\x00\x00",8,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return 0; - } - - return 1; + unsigned char *msg; + int len, i; + time_t date; + char pcdate[4]; + + date = time (NULL); + for (i = 0; i < 4; i++) + pcdate[i] = (date >> (8 * i)) & 0xff; + + switch (canon_comm_method) { + case CANON_USB: + len = 0x10; + msg = psa50_usb_dialogue (camera, 0x04, 0x12, 0x201, &len, 0, 0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0x04, 0x12, &len, pcdate, + sizeof (pcdate), + "\x00\x00\x00\x00\x00\x00\x00\x00", 8, + NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return 0; + } + + return 1; } /** * Switches the camera on, detects the model and sets its speed. */ -int psa50_ready(Camera *camera) +int +psa50_ready (Camera *camera) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char type,seq; - char *pkt; - int try,len,speed,good_ack,res; - // int cts; - - gp_debug_printf(GP_DEBUG_LOW,"canon","psa50_ready()"); - - switch (canon_comm_method) { - case CANON_USB: - res = psa50_get_owner_name(camera); - if (res != GP_OK) { - printf("Camera not ready ('get owner name' request failed (%d))\n", res); - return 0; - } - res = psa50_get_time(camera); - if (res == GP_ERROR) { - printf("Camera not ready ('get time' request failed (%d))\n", res); - return 0; - } - if (!strcmp("Canon PowerShot S20",cs->ident)) { - gp_camera_status(camera, "Detected a Powershot S20"); - cs->model = CANON_PS_S20; - A5 = 0; - return 1; - } - else if (!strcmp("Canon PowerShot S10",cs->ident)) { - gp_camera_status(camera, "Detected a Powershot S10"); - cs->model = CANON_PS_S10; - A5 = 0; - return 1; - } - else if (!strcmp("Canon PowerShot G1",cs->ident)) { - gp_camera_status(camera, "Detected a Powershot G1"); - cs->model = CANON_PS_G1; - A5 = 0; - return 1; - } - else if (!strcmp("Canon PowerShot G2",cs->ident)) { - gp_camera_status(camera, "Detected a Powershot G2"); - cs->model = CANON_PS_G2; - A5 = 0; - return 1; - } - else if ((!strcmp("Canon DIGITAL IXUS",cs->ident)) - || (!strcmp("Canon IXY DIGITAL",cs->ident)) - || (!strcmp("Canon PowerShot S110",cs->ident)) - || (!strcmp("Canon PowerShot S100",cs->ident)) - || (!strcmp("Canon DIGITAL IXUS v",cs->ident))) { - gp_camera_status(camera, "Detected a Digital IXUS series / IXY DIGITAL / Powershot S100 series"); - cs->model = CANON_PS_S100; - A5=0; - return 1; - } - else if ((!strcmp("Canon DIGITAL IXUS 300",cs->ident)) - || (!strcmp("Canon IXY DIGITAL 300",cs->ident)) - || (!strcmp("Canon PowerShot S300",cs->ident))) { - gp_camera_status(camera, "Detected a Digital IXUS 300 / IXY DIGITAL 300 / Powershot S300"); - cs->model = CANON_PS_S300; - A5=0; - return 1; - } - else if (!strcmp("Canon PowerShot A10",cs->ident)) { - gp_camera_status(camera, "Detected a Powershot A10"); - cs->model = CANON_PS_A10; - A5 = 0; - return 1; - } - else if (!strcmp("Canon PowerShot A20",cs->ident)) { - gp_camera_status(camera, "Detected a Powershot A20"); - cs->model = CANON_PS_A20; - A5 = 0; - return 1; - } - else if (!strcmp("Canon EOS D30",cs->ident)) { - gp_camera_status(camera, "Detected a EOS D30"); - cs->model = CANON_EOS_D30; - A5 = 0; - return 1; - } - else if (!strcmp("Canon PowerShot Pro90 IS",cs->ident)) { - gp_camera_status(camera, "Detected a PowerShot Pro90 IS"); - cs->model = CANON_PS_PRO90_IS; - A5 = 0; - return 1; - } else { - printf ("Unknown camera! (%s)\n", cs->ident); - return 0; - } - break; - case CANON_SERIAL_RS232: - default: - - serial_set_timeout(camera->port,900); // 1 second is the delay for awakening the camera - serial_flush_input(camera->port); - serial_flush_output(camera->port); - - receive_error=NOERROR; - - /* First of all, we must check if the camera is already on */ - /* cts=canon_serial_get_cts(); - gp_debug_printf(GP_DEBUG_LOW,"canon","cts : %i\n",cts); - if (cts==32) { CTS == 32 when the camera is connected. */ - if (cs->first_init==0 && cs->cached_ready==1) { - /* First case, the serial speed of the camera is the same as - * ours, so let's try to send a ping packet : */ - if (!psa50_send_packet(camera, PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0)) - return 0; - good_ack=psa50_wait_for_ack(camera); - gp_debug_printf(GP_DEBUG_LOW,"canon","good_ack = %i\n",good_ack); - if (good_ack==0) { - /* no answer from the camera, let's try - * at the speed saved in the settings... */ - speed=cs->speed; - if (speed!=9600) { - if(!canon_serial_change_speed(camera->port, speed)) { - gp_camera_status(camera, _("Error changing speed.")); - gp_debug_printf(GP_DEBUG_LOW,"canon","speed changed.\n"); - } - } - if (!psa50_send_packet(camera, PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0)) - return 0; - good_ack=psa50_wait_for_ack(camera); - if (good_ack==0) { - gp_camera_status(camera, _("Resetting protocol...")); - psa50_off(camera); - sleep(3); /* The camera takes a while to switch off */ - return psa50_ready(camera); - } - if (good_ack==-1) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Received a NACK !\n"); - return 0; - } - gp_camera_status(camera, _("Camera OK.\n")); + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + unsigned char type, seq; + char *pkt; + int try, len, speed, good_ack, res; + + // int cts; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "psa50_ready()"); + + switch (canon_comm_method) { + case CANON_USB: + res = psa50_get_owner_name (camera); + if (res != GP_OK) { + printf ("Camera not ready ('get owner name' request failed (%d))\n", res); + return 0; + } + res = psa50_get_time (camera); + if (res == GP_ERROR) { + printf ("Camera not ready ('get time' request failed (%d))\n", + res); + return 0; + } + if (!strcmp ("Canon PowerShot S20", cs->ident)) { + gp_camera_status (camera, "Detected a Powershot S20"); + cs->model = CANON_PS_S20; + A5 = 0; + return 1; + } else if (!strcmp ("Canon PowerShot S10", cs->ident)) { + gp_camera_status (camera, "Detected a Powershot S10"); + cs->model = CANON_PS_S10; + A5 = 0; + return 1; + } else if (!strcmp ("Canon PowerShot G1", cs->ident)) { + gp_camera_status (camera, "Detected a Powershot G1"); + cs->model = CANON_PS_G1; + A5 = 0; + return 1; + } else if (!strcmp ("Canon PowerShot G2", cs->ident)) { + gp_camera_status (camera, "Detected a Powershot G2"); + cs->model = CANON_PS_G2; + A5 = 0; + return 1; + } else if ((!strcmp ("Canon DIGITAL IXUS", cs->ident)) + || (!strcmp ("Canon IXY DIGITAL", cs->ident)) + || (!strcmp ("Canon PowerShot S110", cs->ident)) + || (!strcmp ("Canon PowerShot S100", cs->ident)) + || (!strcmp ("Canon DIGITAL IXUS v", cs->ident))) { + gp_camera_status (camera, + "Detected a Digital IXUS series / IXY DIGITAL / Powershot S100 series"); + cs->model = CANON_PS_S100; + A5 = 0; + return 1; + } else if ((!strcmp ("Canon DIGITAL IXUS 300", cs->ident)) + || (!strcmp ("Canon IXY DIGITAL 300", cs->ident)) + || (!strcmp ("Canon PowerShot S300", cs->ident))) { + gp_camera_status (camera, + "Detected a Digital IXUS 300 / IXY DIGITAL 300 / Powershot S300"); + cs->model = CANON_PS_S300; + A5 = 0; + return 1; + } else if (!strcmp ("Canon PowerShot A10", cs->ident)) { + gp_camera_status (camera, "Detected a Powershot A10"); + cs->model = CANON_PS_A10; + A5 = 0; + return 1; + } else if (!strcmp ("Canon PowerShot A20", cs->ident)) { + gp_camera_status (camera, "Detected a Powershot A20"); + cs->model = CANON_PS_A20; + A5 = 0; + return 1; + } else if (!strcmp ("Canon EOS D30", cs->ident)) { + gp_camera_status (camera, "Detected a EOS D30"); + cs->model = CANON_EOS_D30; + A5 = 0; + return 1; + } else if (!strcmp ("Canon PowerShot Pro90 IS", cs->ident)) { + gp_camera_status (camera, "Detected a PowerShot Pro90 IS"); + cs->model = CANON_PS_PRO90_IS; + A5 = 0; + return 1; + } else { + printf ("Unknown camera! (%s)\n", cs->ident); + return 0; + } + break; + case CANON_SERIAL_RS232: + default: + + serial_set_timeout (camera->port, 900); // 1 second is the delay for awakening the camera + serial_flush_input (camera->port); + serial_flush_output (camera->port); + + receive_error = NOERROR; + + /* First of all, we must check if the camera is already on */ + /* cts=canon_serial_get_cts(); + gp_debug_printf(GP_DEBUG_LOW,"canon","cts : %i\n",cts); + if (cts==32) { CTS == 32 when the camera is connected. */ + if (cs->first_init == 0 && cs->cached_ready == 1) { + /* First case, the serial speed of the camera is the same as + * ours, so let's try to send a ping packet : */ + if (!psa50_send_packet + (camera, PKT_EOT, seq_tx, psa50_eot + PKT_HDR_LEN, 0)) + return 0; + good_ack = psa50_wait_for_ack (camera); + gp_debug_printf (GP_DEBUG_LOW, "canon", "good_ack = %i\n", + good_ack); + if (good_ack == 0) { + /* no answer from the camera, let's try + * at the speed saved in the settings... */ + speed = cs->speed; + if (speed != 9600) { + if (!canon_serial_change_speed + (camera->port, speed)) { + gp_camera_status (camera, + _ + ("Error changing speed.")); + gp_debug_printf (GP_DEBUG_LOW, "canon", + "speed changed.\n"); + } + } + if (!psa50_send_packet + (camera, PKT_EOT, seq_tx, psa50_eot + PKT_HDR_LEN, + 0)) + return 0; + good_ack = psa50_wait_for_ack (camera); + if (good_ack == 0) { + gp_camera_status (camera, + _("Resetting protocol...")); + psa50_off (camera); + sleep (3); /* The camera takes a while to switch off */ + return psa50_ready (camera); + } + if (good_ack == -1) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Received a NACK !\n"); + return 0; + } + gp_camera_status (camera, _("Camera OK.\n")); + return 1; + } + if (good_ack == -1) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Received a NACK !\n"); + return 0; + } + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Camera replied to ping, proceed.\n"); + return 1; + } + + /* Camera was off... */ + + gp_camera_status (camera, _("Looking for camera ...")); + gp_camera_progress (camera, 0); + if (receive_error == FATAL_ERROR) { + /* we try to recover from an error + we go back to 9600bps */ + if (!canon_serial_change_speed (camera->port, 9600)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: Error changing speed"); + return 0; + } + receive_error = NOERROR; + } + for (try = 1; try < MAX_TRIES; try++) { + gp_camera_progress (camera, (try / (float) MAX_TRIES) * 100); + if (canon_serial_send + (camera, "\x55\x55\x55\x55\x55\x55\x55\x55", 8, + USLEEP1) < 0) { + gp_camera_status (camera, _("Communication error 1")); + return 0; + } + pkt = psa50_recv_frame (camera, &len); + if (pkt) + break; + } + if (try == MAX_TRIES) { + gp_camera_status (camera, _("No response from camera")); + return 0; + } + if (!pkt) { + gp_camera_status (camera, _("No response from camera")); + return 0; + } + if (len < 40 && strncmp (pkt + 26, "Canon", 5)) { + gp_camera_status (camera, _("Unrecognized response")); + return 0; + } + strcpy (psa50_id, pkt + 26); /* @@@ check size */ + + gp_debug_printf (GP_DEBUG_LOW, "canon", "psa50_id : '%s'\n", psa50_id); + + cs->first_init = 0; + + if (!strcmp ("DE300 Canon Inc.", psa50_id)) { + gp_camera_status (camera, "Powershot A5"); + cs->model = CANON_PS_A5; + if (cs->speed > 57600) + cs->slow_send = 1; + A5 = 1; + } else if (!strcmp ("Canon PowerShot A5 Zoom", psa50_id)) { + gp_camera_status (camera, "Powershot A5 Zoom"); + cs->model = CANON_PS_A5_ZOOM; + if (cs->speed > 57600) + cs->slow_send = 1; + A5 = 1; + } else if (!strcmp ("Canon PowerShot A50", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot A50"); + cs->model = CANON_PS_A50; + if (cs->speed > 57600) + cs->slow_send = 1; + A5 = 0; + } else if (!strcmp ("Canon PowerShot S20", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot S20"); + cs->model = CANON_PS_S20; + A5 = 0; + } else if (!strcmp ("Canon PowerShot G1", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot G1"); + cs->model = CANON_PS_G1; + A5 = 0; + } else if (!strcmp ("Canon PowerShot G2", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot G2"); + cs->model = CANON_PS_G2; + A5 = 0; + } else if (!strcmp ("Canon PowerShot A10", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot A10"); + cs->model = CANON_PS_A10; + A5 = 0; + } else if (!strcmp ("Canon PowerShot A20", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot A20"); + cs->model = CANON_PS_A20; + A5 = 0; + } else if (!strcmp ("Canon EOS D30", psa50_id)) { + gp_camera_status (camera, "Detected a EOS D30"); + cs->model = CANON_EOS_D30; + A5 = 0; + } else if (!strcmp ("Canon PowerShot Pro90 IS", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot Pro90 IS"); + cs->model = CANON_PS_PRO90_IS; + A5 = 0; + } else if (!strcmp ("Canon PowerShot Pro70", psa50_id)) { + gp_camera_status (camera, "Detected a Powershot Pro70"); + cs->model = CANON_PS_A70; + A5 = 0; + } else if ((!strcmp ("Canon DIGITAL IXUS", psa50_id)) + || (!strcmp ("Canon IXY DIGITAL", psa50_id)) + || (!strcmp ("Canon PowerShot S100", psa50_id)) + || (!strcmp ("Canon DIGITAL IXUS v", psa50_id))) { + gp_camera_status (camera, + "Detected a Digital IXUS series / IXY DIGITAL / Powershot S100 series"); + cs->model = CANON_PS_S100; + A5 = 0; + } else if ((!strcmp ("Canon DIGITAL IXUS 300", psa50_id)) + || (!strcmp ("Canon IXY DIGITAL 300", psa50_id)) + || (!strcmp ("Canon PowerShot S300", psa50_id))) { + gp_camera_status (camera, + "Detected a Digital IXUS 300 / IXY DIGITAL 300 / Powershot S300"); + cs->model = CANON_PS_S300; + A5 = 0; + } else { + gp_camera_status (camera, "Detected a Powershot S10"); + cs->model = CANON_PS_S10; + A5 = 0; + } + + // 5 seconds delay should be enough for big flash cards. By + // experience, one or two seconds is too little, as a large flash + // card needs more access time. + serial_set_timeout (camera->port, 5000); + (void) psa50_recv_packet (camera, &type, &seq, NULL); + if (type != PKT_EOT || seq) { + gp_camera_status (camera, _("Bad EOT")); + return 0; + } + seq_tx = 0; + seq_rx = 1; + if (!psa50_send_frame (camera, "\x00\x05\x00\x00\x00\x00\xdb\xd1", 8)) { + gp_camera_status (camera, _("Communication error 2")); + return 0; + } + res = 0; + switch (cs->speed) { + case 9600: + res = psa50_send_frame (camera, SPEED_9600, 12); + break; + case 19200: + res = psa50_send_frame (camera, SPEED_19200, 12); + break; + case 38400: + res = psa50_send_frame (camera, SPEED_38400, 12); + break; + case 57600: + res = psa50_send_frame (camera, SPEED_57600, 12); + break; + case 115200: + res = psa50_send_frame (camera, SPEED_115200, 12); + break; + } + + if (!res + || !psa50_send_frame (camera, "\x00\x04\x01\x00\x00\x00\x24\xc6", + 8)) { + gp_camera_status (camera, _("Communication error 3")); + return 0; + } + speed = cs->speed; + gp_camera_status (camera, _("Changing speed... wait...")); + if (!psa50_wait_for_ack (camera)) + return 0; + if (speed != 9600) { + if (!canon_serial_change_speed (camera->port, speed)) { + gp_camera_status (camera, _("Error changing speed")); + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: Error changing speed"); + } else { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "speed changed\n"); + } + + } + for (try = 1; try < MAX_TRIES; try++) { + psa50_send_packet (camera, PKT_EOT, seq_tx, + psa50_eot + PKT_HDR_LEN, 0); + if (!psa50_wait_for_ack (camera)) { + gp_camera_status (camera, + _ + ("Error waiting ACK during initialization retrying")); + } else + break; + } + } + if (try == MAX_TRIES) { + gp_camera_status (camera, _("Error waiting ACK during initialization")); + return 0; + } + gp_camera_status (camera, _("Connected to camera")); + /* Now is a good time to ask the camera for its owner + * name (and Model String as well) */ + psa50_get_owner_name (camera); + psa50_get_time (camera); return 1; - } - if (good_ack==-1) { - gp_debug_printf(GP_DEBUG_LOW,"canon","Received a NACK !\n"); - return 0; - } - gp_debug_printf(GP_DEBUG_LOW,"canon","Camera replied to ping, proceed.\n"); - return 1; - } - - /* Camera was off... */ - - gp_camera_status(camera, _("Looking for camera ...")); - gp_camera_progress(camera, 0); - if(receive_error==FATAL_ERROR) { - /* we try to recover from an error - we go back to 9600bps */ - if(!canon_serial_change_speed(camera->port, 9600 )) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: Error changing speed"); - return 0; - } - receive_error=NOERROR; - } - for (try = 1; try < MAX_TRIES; try++) { - gp_camera_progress(camera, (try/(float) MAX_TRIES)*100); - if (canon_serial_send(camera,"\x55\x55\x55\x55\x55\x55\x55\x55",8,USLEEP1) < 0) { - gp_camera_status(camera, _("Communication error 1")); - return 0; - } - pkt = psa50_recv_frame(camera, &len); - if (pkt) break; - } - if (try == MAX_TRIES) { - gp_camera_status(camera, _("No response from camera")); - return 0; - } - if (!pkt) { - gp_camera_status(camera, _("No response from camera")); - return 0; - } - if (len < 40 && strncmp(pkt+26,"Canon",5)) { - gp_camera_status(camera, _("Unrecognized response")); - return 0; - } - strcpy(psa50_id,pkt+26); /* @@@ check size */ - - gp_debug_printf(GP_DEBUG_LOW,"canon","psa50_id : '%s'\n",psa50_id); - - cs->first_init=0; - - if (!strcmp("DE300 Canon Inc.",psa50_id)) { - gp_camera_status(camera, "Powershot A5"); - cs->model = CANON_PS_A5; - if (cs->speed>57600) cs->slow_send = 1; - A5 = 1; - } else if (!strcmp("Canon PowerShot A5 Zoom",psa50_id)) { - gp_camera_status(camera, "Powershot A5 Zoom"); - cs->model = CANON_PS_A5_ZOOM; - if (cs->speed>57600) cs->slow_send = 1; - A5 = 1; - } else if (!strcmp("Canon PowerShot A50",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot A50"); - cs->model = CANON_PS_A50; - if (cs->speed>57600) cs->slow_send = 1; - A5 = 0; - } else if (!strcmp("Canon PowerShot S20",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot S20"); - cs->model = CANON_PS_S20; - A5 = 0; - } else if (!strcmp("Canon PowerShot G1",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot G1"); - cs->model = CANON_PS_G1; - A5 = 0; - } else if (!strcmp("Canon PowerShot G2",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot G2"); - cs->model = CANON_PS_G2; - A5 = 0; - } else if (!strcmp("Canon PowerShot A10",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot A10"); - cs->model = CANON_PS_A10; - A5 = 0; - } else if (!strcmp("Canon PowerShot A20",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot A20"); - cs->model = CANON_PS_A20; - A5 = 0; - } else if (!strcmp("Canon EOS D30",psa50_id)) { - gp_camera_status(camera, "Detected a EOS D30"); - cs->model = CANON_EOS_D30; - A5 = 0; - } else if (!strcmp("Canon PowerShot Pro90 IS",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot Pro90 IS"); - cs->model = CANON_PS_PRO90_IS; - A5 = 0; - } else if (!strcmp("Canon PowerShot Pro70",psa50_id)) { - gp_camera_status(camera, "Detected a Powershot Pro70"); - cs->model = CANON_PS_A70; - A5=0; - } else if ((!strcmp("Canon DIGITAL IXUS",psa50_id)) - || (!strcmp("Canon IXY DIGITAL",psa50_id)) - || (!strcmp("Canon PowerShot S100",psa50_id)) - || (!strcmp("Canon DIGITAL IXUS v",psa50_id))) - { - gp_camera_status(camera, "Detected a Digital IXUS series / IXY DIGITAL / Powershot S100 series"); - cs->model = CANON_PS_S100; - A5=0; - } else if ((!strcmp("Canon DIGITAL IXUS 300",psa50_id)) - || (!strcmp("Canon IXY DIGITAL 300",psa50_id)) - || (!strcmp("Canon PowerShot S300",psa50_id))) - { - gp_camera_status(camera, "Detected a Digital IXUS 300 / IXY DIGITAL 300 / Powershot S300"); - cs->model = CANON_PS_S300; - A5=0; - } else { - gp_camera_status(camera, "Detected a Powershot S10"); - cs->model = CANON_PS_S10; - A5 = 0; - } - - // 5 seconds delay should be enough for big flash cards. By - // experience, one or two seconds is too little, as a large flash - // card needs more access time. - serial_set_timeout(camera->port,5000); - (void) psa50_recv_packet(camera, &type,&seq,NULL); - if (type != PKT_EOT || seq) { - gp_camera_status(camera, _("Bad EOT")); - return 0; - } - seq_tx = 0; - seq_rx = 1; - if (!psa50_send_frame(camera,"\x00\x05\x00\x00\x00\x00\xdb\xd1",8)) { - gp_camera_status(camera, _("Communication error 2")); - return 0; - } - res=0; - switch (cs->speed) { - case 9600: res=psa50_send_frame(camera,SPEED_9600,12); break; - case 19200: res=psa50_send_frame(camera,SPEED_19200,12); break; - case 38400: res=psa50_send_frame(camera,SPEED_38400,12); break; - case 57600: res=psa50_send_frame(camera,SPEED_57600,12); break; - case 115200: res=psa50_send_frame(camera,SPEED_115200,12); break; - } - - if( !res || !psa50_send_frame(camera,"\x00\x04\x01\x00\x00\x00\x24\xc6",8)) { - gp_camera_status(camera, _("Communication error 3")); - return 0; - } - speed=cs->speed; - gp_camera_status(camera, _("Changing speed... wait...")); - if (!psa50_wait_for_ack(camera)) return 0; - if (speed!=9600) { - if(!canon_serial_change_speed(camera->port,speed)) { - gp_camera_status(camera, _("Error changing speed")); - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: Error changing speed"); - } - else { - gp_debug_printf(GP_DEBUG_LOW,"canon","speed changed\n"); - } - - } - for (try=1; try < MAX_TRIES; try++) { - psa50_send_packet(camera, PKT_EOT,seq_tx,psa50_eot+PKT_HDR_LEN,0); - if (!psa50_wait_for_ack(camera)) { - gp_camera_status(camera, _("Error waiting ACK during initialization retrying")); - } else - break; - } - } - if (try==MAX_TRIES) { - gp_camera_status(camera, _("Error waiting ACK during initialization")); - return 0; - } - gp_camera_status(camera, _("Connected to camera")); - /* Now is a good time to ask the camera for its owner - * name (and Model String as well) */ - psa50_get_owner_name(camera); - psa50_get_time(camera); - return 1; } /** * Ask the camera for the name of the flash storage * device. Usually "D:" or somehting like that. */ -char *psa50_get_disk(Camera *camera) +char * +psa50_get_disk (Camera *camera) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - int len; - - switch (canon_comm_method) { - case CANON_USB: - msg = psa50_usb_dialogue(camera,0x0A,0x11,0x202,&len,0,0); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera,0x0a,0x11,&len,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return NULL; - } - if (canon_comm_method == CANON_SERIAL_RS232) { - msg = strdup((char *) msg+4); /* @@@ should check length */ - if (!msg) perror("strdup"); - } - return msg; + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + msg = psa50_usb_dialogue (camera, 0x0A, 0x11, 0x202, &len, 0, 0); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0x0a, 0x11, &len, NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return NULL; + } + if (canon_comm_method == CANON_SERIAL_RS232) { + msg = strdup ((char *) msg + 4); /* @@@ should check length */ + if (!msg) + perror ("strdup"); + } + return msg; } /** * Gets available room and max capacity of a given disk. */ -int psa50_disk_info(Camera *camera, const char *name,int *capacity,int *available) +int +psa50_disk_info (Camera *camera, const char *name, int *capacity, int *available) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - int len; - - switch (canon_comm_method) { - case CANON_USB: - len=0xc; - msg = psa50_usb_dialogue(camera,0x09,0x11,0x201,&len,name,strlen(name)+1); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera,0x09,0x11,&len,name,strlen(name)+1,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return 0; - } - if (len < 12) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: truncated message\n"); - return 0; - } - if (capacity) *capacity = get_int(msg+4); - if (available) *available = get_int(msg+8); - return 1; + unsigned char *msg; + int len; + + switch (canon_comm_method) { + case CANON_USB: + len = 0xc; + msg = psa50_usb_dialogue (camera, 0x09, 0x11, 0x201, &len, name, + strlen (name) + 1); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0x09, 0x11, &len, name, + strlen (name) + 1, NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return 0; + } + if (len < 12) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: truncated message\n"); + return 0; + } + if (capacity) + *capacity = get_int (msg + 4); + if (available) + *available = get_int (msg + 8); + return 1; } -void psa50_free_dir(Camera *camera, struct psa50_dir *list) +void +psa50_free_dir (Camera *camera, struct psa50_dir *list) { - struct psa50_dir *walk; + struct psa50_dir *walk; - for (walk = list; walk->name; walk++) free((char *) walk->name); - free(list); + for (walk = list; walk->name; walk++) + free ((char *) walk->name); + free (list); } /** * Get the directory tree of a given flash device. */ -struct psa50_dir *psa50_list_directory(Camera *camera, const char *name) +struct psa50_dir * +psa50_list_directory (Camera *camera, const char *name) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - struct psa50_dir *dir = NULL; - int entries = 0; - unsigned char *msg,*p; - int len,namlen; - char attributes; - char newstr[100]={0}; - - /* Ask the camera for a full directory listing */ - switch (canon_comm_method) { - case CANON_USB: - // fprintf(stderr,"Path: %s\n",name); - newstr[0] = 1; - newstr[1] = 0; - strcat(newstr,name); - namlen=strlen(newstr)+3; - newstr[0] = 0; - - msg = psa50_usb_dialogue(camera, 0x0b,0x11,0x202,&len,newstr,namlen); - // fprintf(stderr,"Dir length: %x\n",len); - // - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera,0xb,0x11,&len,"",1,name,strlen(name)+1, - "\x00",2,NULL); - break; - } - - if (!msg) { - psa50_error_type(camera); - return NULL; - } - if (len < 16) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: truncated message\n"); - return NULL; - } - - switch (canon_comm_method) { - case CANON_USB: - p=msg-1; - if (p >= msg+len) goto error; - break; - case CANON_SERIAL_RS232: - default: - if (!msg[5]) return NULL; - p = msg+15; - if (p >= msg+len) goto error; - for (; *p; p++) - if (p >= msg+len) goto error; - break; - } - - /* This is the main loop, for every entry in the structure */ - while (p[0xb] != 0x00) { - unsigned char *start; - int is_file; - - //fprintf(stderr,"p %p msg+len %p len %d\n",p,msg+len,len); - if (p == msg+len-1) { - if (msg[4]) break; - if (canon_comm_method == CANON_SERIAL_RS232) - msg = psa50_recv_msg(camera, 0xb,0x21,&len); - else - gp_debug_printf(GP_DEBUG_LOW,"canon","USB Driver: this message (psa50.c line 1126) should never be printed"); - if (!msg) goto error; - if (len < 5) goto error; - p = msg+4; - } - if (p+2 >= msg+len) goto error; - attributes = p[1]; - is_file = !((p[1] & 0x10) == 0x10); - if (p[1] == 0x10 || is_file) p += 11; - else break; - if (p >= msg+len) goto error; - for (start = p; *p; p++) - if (p >= msg+len) goto error; - dir = realloc(dir,sizeof(*dir)*(entries+2)); - if (!dir) { - perror("realloc"); - exit(1); - } - dir[entries].name = strdup(start); - if (!dir[entries].name) { - perror("strdup"); - exit(1); - } - - memcpy((unsigned char *) &dir[entries].size,start-8,4); - dir[entries].size = byteswap32(dir[entries].size); /* re-order little/big endian */ - memcpy((unsigned char *) &dir[entries].date,start-4,4); - dir[entries].date = byteswap32(dir[entries].date); /* re-order little/big endian */ - dir[entries].is_file = is_file; - dir[entries].attrs = attributes; - // Every directory contains a "null" file entry, so we skip it - if (strlen(dir[entries].name) > 0) { - // Debug output: - if (is_file) gp_debug_printf(GP_DEBUG_LOW,"canon","-"); else gp_debug_printf(GP_DEBUG_LOW,"canon","d"); - if ((dir[entries].attrs & 0x1) == 0x1) gp_debug_printf(GP_DEBUG_LOW,"canon","r- "); else gp_debug_printf(GP_DEBUG_LOW,"canon","rw "); - if ((dir[entries].attrs & 0x20) == 0x20) gp_debug_printf(GP_DEBUG_LOW,"canon"," new "); else gp_debug_printf(GP_DEBUG_LOW,"canon","saved "); - gp_debug_printf(GP_DEBUG_LOW,"canon","%#2x - %8i %.24s %s\n",dir[entries].attrs, dir[entries].size, - asctime(gmtime(&dir[entries].date)), dir[entries].name); - entries++; - } - } - if (dir) dir[entries].name = NULL; - return dir; -error: - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: truncated message\n"); - if (dir) psa50_free_dir(camera, dir); - return NULL; + struct psa50_dir *dir = NULL; + int entries = 0; + unsigned char *msg, *p; + int len, namlen; + char attributes; + char newstr[100] = { 0 }; + + /* Ask the camera for a full directory listing */ + switch (canon_comm_method) { + case CANON_USB: + // fprintf(stderr,"Path: %s\n",name); + newstr[0] = 1; + newstr[1] = 0; + strcat (newstr, name); + namlen = strlen (newstr) + 3; + newstr[0] = 0; + + msg = psa50_usb_dialogue (camera, 0x0b, 0x11, 0x202, &len, newstr, + namlen); + // fprintf(stderr,"Dir length: %x\n",len); + // + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0xb, 0x11, &len, "", 1, name, + strlen (name) + 1, "\x00", 2, NULL); + break; + } + + if (!msg) { + psa50_error_type (camera); + return NULL; + } + if (len < 16) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: truncated message\n"); + return NULL; + } + + switch (canon_comm_method) { + case CANON_USB: + p = msg - 1; + if (p >= msg + len) + goto error; + break; + case CANON_SERIAL_RS232: + default: + if (!msg[5]) + return NULL; + p = msg + 15; + if (p >= msg + len) + goto error; + for (; *p; p++) + if (p >= msg + len) + goto error; + break; + } + + /* This is the main loop, for every entry in the structure */ + while (p[0xb] != 0x00) { + unsigned char *start; + int is_file; + + //fprintf(stderr,"p %p msg+len %p len %d\n",p,msg+len,len); + if (p == msg + len - 1) { + if (msg[4]) + break; + if (canon_comm_method == CANON_SERIAL_RS232) + msg = psa50_recv_msg (camera, 0xb, 0x21, &len); + else + gp_debug_printf (GP_DEBUG_LOW, "canon", + "USB Driver: this message (psa50.c line 1126) should never be printed"); + if (!msg) + goto error; + if (len < 5) + goto error; + p = msg + 4; + } + if (p + 2 >= msg + len) + goto error; + attributes = p[1]; + is_file = !((p[1] & 0x10) == 0x10); + if (p[1] == 0x10 || is_file) + p += 11; + else + break; + if (p >= msg + len) + goto error; + for (start = p; *p; p++) + if (p >= msg + len) + goto error; + dir = realloc (dir, sizeof (*dir) * (entries + 2)); + if (!dir) { + perror ("realloc"); + exit (1); + } + dir[entries].name = strdup (start); + if (!dir[entries].name) { + perror ("strdup"); + exit (1); + } + + memcpy ((unsigned char *) &dir[entries].size, start - 8, 4); + dir[entries].size = byteswap32 (dir[entries].size); /* re-order little/big endian */ + memcpy ((unsigned char *) &dir[entries].date, start - 4, 4); + dir[entries].date = byteswap32 (dir[entries].date); /* re-order little/big endian */ + dir[entries].is_file = is_file; + dir[entries].attrs = attributes; + // Every directory contains a "null" file entry, so we skip it + if (strlen (dir[entries].name) > 0) { + // Debug output: + if (is_file) + gp_debug_printf (GP_DEBUG_LOW, "canon", "-"); + else + gp_debug_printf (GP_DEBUG_LOW, "canon", "d"); + if ((dir[entries].attrs & 0x1) == 0x1) + gp_debug_printf (GP_DEBUG_LOW, "canon", "r- "); + else + gp_debug_printf (GP_DEBUG_LOW, "canon", "rw "); + if ((dir[entries].attrs & 0x20) == 0x20) + gp_debug_printf (GP_DEBUG_LOW, "canon", " new "); + else + gp_debug_printf (GP_DEBUG_LOW, "canon", "saved "); + gp_debug_printf (GP_DEBUG_LOW, "canon", "%#2x - %8i %.24s %s\n", + dir[entries].attrs, dir[entries].size, + asctime (gmtime (&dir[entries].date)), + dir[entries].name); + entries++; + } + } + if (dir) + dir[entries].name = NULL; + return dir; + error: + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: truncated message\n"); + if (dir) + psa50_free_dir (camera, dir); + return NULL; } -unsigned char *psa50_get_file_serial(Camera *camera, const char *name,int *length) +unsigned char * +psa50_get_file_serial (Camera *camera, const char *name, int *length) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *file = NULL; - unsigned char *msg; - unsigned char name_len; - unsigned int total = 0,expect = 0,size; - int len,maxfilesize; - - gp_camera_progress(camera, 0); - if(receive_error==FATAL_ERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: can't continue a fatal error condition detected\n"); - return NULL; - } - name_len = strlen(name)+1; - msg = psa50_serial_dialogue(camera, 0x1,0x11,&len,"\x00\x00\x00\x00",5, - &name_len,1,"\x00",2,name,strlen(name)+1,NULL); - if (!msg) { - psa50_error_type(camera); - return NULL; - } - while (msg) { - if (len < 20 || get_int(msg)) { - break; - } - if (!file) { - total = get_int(msg+4); - if(cs->model == CANON_PS_S20 || cs->model==CANON_PS_G1 - || cs->model==CANON_PS_G2 - || cs->model == CANON_PS_S10) { - maxfilesize=10000000; - } - else { - maxfilesize=2000000; - } - - if (total > maxfilesize) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: %d is too big\n",total); - break; - } - file = malloc(total); - if (!file) { - perror("malloc"); - break; - } - if (length) *length = total; - } - size = get_int(msg+12); - if (get_int(msg+8) != expect || expect+size > total || size > len-20) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: doesn't fit\n"); - break; - } - memcpy(file+expect,msg+20,size); - expect += size; - gp_camera_progress(camera, total ? (expect/(float) total)*100 : 100); - if ((expect == total) != get_int(msg+16)) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: end mark != end of data\n"); - break; - } - if (expect == total) return file; - msg = psa50_recv_msg(camera, 0x1,0x21,&len); - } - free(file); - return NULL; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + unsigned char *file = NULL; + unsigned char *msg; + unsigned char name_len; + unsigned int total = 0, expect = 0, size; + int len, maxfilesize; + + gp_camera_progress (camera, 0); + if (receive_error == FATAL_ERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: can't continue a fatal error condition detected\n"); + return NULL; + } + name_len = strlen (name) + 1; + msg = psa50_serial_dialogue (camera, 0x1, 0x11, &len, "\x00\x00\x00\x00", 5, + &name_len, 1, "\x00", 2, name, strlen (name) + 1, NULL); + if (!msg) { + psa50_error_type (camera); + return NULL; + } + while (msg) { + if (len < 20 || get_int (msg)) { + break; + } + if (!file) { + total = get_int (msg + 4); + if (cs->model == CANON_PS_S20 || cs->model == CANON_PS_G1 + || cs->model == CANON_PS_G2 || cs->model == CANON_PS_S10) { + maxfilesize = 10000000; + } else { + maxfilesize = 2000000; + } + + if (total > maxfilesize) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: %d is too big\n", total); + break; + } + file = malloc (total); + if (!file) { + perror ("malloc"); + break; + } + if (length) + *length = total; + } + size = get_int (msg + 12); + if (get_int (msg + 8) != expect || expect + size > total || size > len - 20) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: doesn't fit\n"); + break; + } + memcpy (file + expect, msg + 20, size); + expect += size; + gp_camera_progress (camera, total ? (expect / (float) total) * 100 : 100); + if ((expect == total) != get_int (msg + 16)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: end mark != end of data\n"); + break; + } + if (expect == total) + return file; + msg = psa50_recv_msg (camera, 0x1, 0x21, &len); + } + free (file); + return NULL; } -unsigned char *psa50_get_file_usb(Camera *camera, const char *name,int *length) +unsigned char * +psa50_get_file_usb (Camera *camera, const char *name, int *length) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *file = NULL; - unsigned char msg[BULK_READ_SIZE]; - unsigned char *msgg; - char newstr[100]; - // unsigned char *namn; - unsigned int total = 0, expect = 0, size = BULK_READ_SIZE; - int name_len, len, maxfilesize, status = 0; - - gp_debug_printf(GP_DEBUG_LOW,"canon","psa50_get_file_usb() called for file '%s'", name); - memset(msg, 0, sizeof(msg)); - - gp_camera_progress(camera, 0); - if(receive_error==FATAL_ERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: can't continue a fatal error condition detected\n"); - return NULL; - } - // *newstr="12345678"; - newstr[0]=0x31; - newstr[1]=0x32; - newstr[2]=0x31; - newstr[3]=0x31; - newstr[4]=0x31; - newstr[5]=0x31; - newstr[6]=0x31; - newstr[7]=0x31; - newstr[8]=0x0; - strcat(newstr,name); - gp_debug_printf(GP_DEBUG_LOW,"canon","%s\n",newstr); - name_len=strlen(newstr)+1; - intatpos(newstr,0x0,0x0); // get picture - intatpos(newstr,0x4, BULK_READ_SIZE); - msgg = psa50_usb_dialogue(camera, 0x01, 0x11, 0x202, &len, newstr, name_len); - if (! msgg) { - gp_debug_printf(GP_DEBUG_LOW,"canon","psa50_get_file_usb: psa50_usb_dialogue() " - "returned error (%i).", msgg); - return NULL; - } - if (len < size) - memcpy(msg, msgg, len); - else - memcpy(msg, msgg, size); - - *length=len; - - total=len; - if(cs->model == CANON_PS_S10 || cs->model == CANON_PS_S20 - || cs->model == CANON_PS_G2 || cs->model == CANON_PS_G1 || cs->model == CANON_PS_S300 - || cs->model == CANON_PS_S100 || cs->model == CANON_PS_A10 - || cs->model == CANON_PS_A20 || cs->model == CANON_EOS_D30 - || cs->model == CANON_PS_PRO90_IS) { - maxfilesize=10000000; - } else { - maxfilesize=2000000; - } - - if (total > maxfilesize) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: %d is too big " - "(max reasonable file size for this camera model is %d)\n", - total, maxfilesize); - return NULL; - } - - file = malloc(total); - if (!file) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: Alloc problems!\n"); - perror("malloc"); - return NULL;; - } - while (1) { - memcpy(file+expect,msg,size); - - expect += size; - - gp_camera_progress(camera, total ? (expect/(float) total)*100 : 100); - if (expect == total) return file; - - if ((total-expect) < size) - size=total-expect; - - gp_debug_printf(GP_DEBUG_LOW,"canon","calling gp_port_read(), total = %i, expect = %i, size = %i (0x%x)", - total, expect, size, size); - /* FIXME: (pm) a direct call to gp_port_read here ??????? */ - status = gp_port_read(camera->port,msg,size); - if (status < 1) { - gp_debug_printf(GP_DEBUG_LOW,"canon","gp_port_read() returned error (%i) or no data\n", status); - break; - } - } - - free(file); - - return NULL; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + unsigned char *file = NULL; + unsigned char msg[BULK_READ_SIZE]; + unsigned char *msgg; + char newstr[100]; + + // unsigned char *namn; + unsigned int total = 0, expect = 0, size = BULK_READ_SIZE; + int name_len, len, maxfilesize, status = 0; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "psa50_get_file_usb() called for file '%s'", + name); + memset (msg, 0, sizeof (msg)); + + gp_camera_progress (camera, 0); + if (receive_error == FATAL_ERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: can't continue a fatal error condition detected\n"); + return NULL; + } + // *newstr="12345678"; + newstr[0] = 0x31; + newstr[1] = 0x32; + newstr[2] = 0x31; + newstr[3] = 0x31; + newstr[4] = 0x31; + newstr[5] = 0x31; + newstr[6] = 0x31; + newstr[7] = 0x31; + newstr[8] = 0x0; + strcat (newstr, name); + gp_debug_printf (GP_DEBUG_LOW, "canon", "%s\n", newstr); + name_len = strlen (newstr) + 1; + intatpos (newstr, 0x0, 0x0); // get picture + intatpos (newstr, 0x4, BULK_READ_SIZE); + msgg = psa50_usb_dialogue (camera, 0x01, 0x11, 0x202, &len, newstr, name_len); + if (!msgg) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "psa50_get_file_usb: psa50_usb_dialogue() " + "returned error (%i).", msgg); + return NULL; + } + if (len < size) + memcpy (msg, msgg, len); + else + memcpy (msg, msgg, size); + + *length = len; + + total = len; + if (cs->model == CANON_PS_S10 || cs->model == CANON_PS_S20 + || cs->model == CANON_PS_G2 || cs->model == CANON_PS_G1 + || cs->model == CANON_PS_S300 || cs->model == CANON_PS_S100 + || cs->model == CANON_PS_A10 || cs->model == CANON_PS_A20 + || cs->model == CANON_EOS_D30 || cs->model == CANON_PS_PRO90_IS) { + maxfilesize = 10000000; + } else { + maxfilesize = 2000000; + } + + if (total > maxfilesize) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: %d is too big " + "(max reasonable file size for this camera model is %d)\n", + total, maxfilesize); + return NULL; + } + + file = malloc (total); + if (!file) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: Alloc problems!\n"); + perror ("malloc"); + return NULL;; + } + while (1) { + memcpy (file + expect, msg, size); + + expect += size; + + gp_camera_progress (camera, total ? (expect / (float) total) * 100 : 100); + if (expect == total) + return file; + + if ((total - expect) < size) + size = total - expect; + + gp_debug_printf (GP_DEBUG_LOW, "canon", + "calling gp_port_read(), total = %i, expect = %i, size = %i (0x%x)", + total, expect, size, size); + /* FIXME: (pm) a direct call to gp_port_read here ??????? */ + status = gp_port_read (camera->port, msg, size); + if (status < 1) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "gp_port_read() returned error (%i) or no data\n", + status); + break; + } + } + + free (file); + + return NULL; } -unsigned char *psa50_get_file(Camera *camera, const char *name,int *length) +unsigned char * +psa50_get_file (Camera *camera, const char *name, int *length) { - switch (canon_comm_method) { - case CANON_USB: - return psa50_get_file_usb(camera, name,length); - break; - case CANON_SERIAL_RS232: - default: - return psa50_get_file_serial(camera, name,length); - break; - } + switch (canon_comm_method) { + case CANON_USB: + return psa50_get_file_usb (camera, name, length); + break; + case CANON_SERIAL_RS232: + default: + return psa50_get_file_serial (camera, name, length); + break; + } } /** * Returns the thumbnail of a picture. */ -unsigned char *psa50_get_thumbnail(Camera *camera, const char *name,int *length) +unsigned char * +psa50_get_thumbnail (Camera *camera, const char *name, int *length) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *file = NULL; - unsigned char *msg; - char newstr[100]; - exifparser exifdat; - unsigned char name_len; - unsigned int total = 0,expect = 0,size; - int len; - int i,j,in; - unsigned char *thumb; - - gp_camera_progress(camera, 0); - if(receive_error==FATAL_ERROR) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: can't continue a fatal error condition detected\n"); - return NULL; - } - - switch (canon_comm_method) { - case CANON_USB: - newstr[0]=0x31; - newstr[1]=0x31; - newstr[2]=0x31; - newstr[3]=0x31; - newstr[4]=0x31; - newstr[5]=0x31; - newstr[6]=0x31; - newstr[7]=0x31; - newstr[8]=0x0; - - strcat(newstr,name); - name_len = strlen(newstr)+1; - gp_debug_printf(GP_DEBUG_LOW,"canon","%s\n",newstr); - intatpos(newstr,0x0,0x1); // get picturethumbnail - intatpos(newstr,0x4,BULK_READ_SIZE); - msg = psa50_usb_dialogue(camera, 0x01, 0x11, 0x202, &len, newstr, name_len); - if (! msg) { - psa50_error_type(camera); - return NULL; - } - gp_debug_printf(GP_DEBUG_LOW,"canon","File length: %x\n",len); - file = malloc(len); - if (!file) { - perror("malloc"); - return NULL; - } - memcpy(file,msg,len); - total=len; - *length=len; - break; - case CANON_SERIAL_RS232: - default: - name_len = strlen(name)+1; - msg = psa50_serial_dialogue(camera,0x1,0x11,&len, - "\x01\x00\x00\x00\x00",5, - &name_len,1,"\x00",2, - name,strlen(name)+1,NULL); - if (!msg) { - psa50_error_type(camera); - return NULL; - } - while (msg) { - if (len < 20 || get_int(msg)) { - return NULL; - } - if (!file) { - total = get_int(msg+4); - if (total > 2000000) { /* 2 MB thumbnails ? unlikely ... */ - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: %d is too big\n",total); - return NULL; - } - file = malloc(total); - if (!file) { - perror("malloc"); - return NULL; - } - if (length) *length = total; - } - size = get_int(msg+12); - if (get_int(msg+8) != expect || expect+size > total || size > len-20) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: doesn't fit\n"); - return NULL; - } - memcpy(file+expect,msg+20,size); - expect += size; - gp_camera_progress(camera, total ? (expect/(float) total)*100 : 100); - if ((expect == total) != get_int(msg+16)) { - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: end mark != end of data\n"); - return NULL; - } - if (expect == total) { - /* We finished receiving the file. Parse the header and - return just the thumbnail */ - break; - } - msg = psa50_recv_msg(camera,0x1,0x21,&len); - } - break; - } - - switch(cs->model) { - case CANON_PS_A70: /* pictures are JFIF files */ - /* we skip the first FF D8 */ - i=3; - j=0; - in=0; - - /* we want to drop the header to get the thumbnail */ - - thumb = malloc(total); - if (!thumb) { - perror("malloc"); - break; - } - - while(i<total) { - if (file[i]==JPEG_ESC) { - if (file[i+1]==JPEG_BEG && - ((file[i+3]== JPEG_SOS) || ( file[i+3]== JPEG_A50_SOS))) { - in=1; - } - else if (file[i+1]==JPEG_END) { - in=0; - thumb[j++]=file[i]; - thumb[j]=file[i+1]; - return thumb; - } - } - - if (in==1) - thumb[j++]=file[i]; - i++; - - } - return NULL; - break; - - default: /* Camera supports EXIF */ - exifdat.header=file; - exifdat.data=file+12; - - gp_debug_printf(GP_DEBUG_LOW,"canon","Got thumbnail, extracting it with the EXIF lib.\n"); - if (exif_parse_data(&exifdat)>0){ - gp_debug_printf(GP_DEBUG_LOW,"canon","Parsed exif data.\n"); - file = exif_get_thumbnail(&exifdat); // Extract Thumbnail - if (file==NULL) { - int f; - char fn[255]; - - if (rindex(name, '\\') != NULL) - snprintf(fn, sizeof(fn) - 1, "canon-death-dump.dat-%s", rindex(name, '\\') + 1); - else - snprintf(fn, sizeof(fn) - 1, "canon-death-dump.dat-%s", name); - fn[sizeof(fn) - 1] = 0; - - gp_debug_printf(GP_DEBUG_LOW,"canon","psa50_get_thumbnail: " - "Thumbnail conversion error, saving " - "%i bytes to '%s'", total, fn); - /* create with O_EXCL and 0600 for security */ - if ((f = open(fn, O_CREAT|O_EXCL|O_RDWR, 0600)) == -1) { - char errstr[255]; - - snprintf(errstr, sizeof(errstr), "psa50_get_thumbnail: error creating '%s'", - fn); - errstr[sizeof(errstr) - 1] = 0; - - perror(errstr); - break; - } - if (write(f, file, total) == -1) { - char errstr[255]; - snprintf(errstr, sizeof(errstr), "psa50_get_thumbnail: error writing to file '%s'", - fn); - errstr[sizeof(errstr) - 1] = 0; - - perror(errstr); - } - - close(f); - break; - } - return file; - } - break; - } - - free(file); - return NULL; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + unsigned char *file = NULL; + unsigned char *msg; + char newstr[100]; + exifparser exifdat; + unsigned char name_len; + unsigned int total = 0, expect = 0, size; + int len; + int i, j, in; + unsigned char *thumb; + + gp_camera_progress (camera, 0); + if (receive_error == FATAL_ERROR) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: can't continue a fatal error condition detected\n"); + return NULL; + } + + switch (canon_comm_method) { + case CANON_USB: + newstr[0] = 0x31; + newstr[1] = 0x31; + newstr[2] = 0x31; + newstr[3] = 0x31; + newstr[4] = 0x31; + newstr[5] = 0x31; + newstr[6] = 0x31; + newstr[7] = 0x31; + newstr[8] = 0x0; + + strcat (newstr, name); + name_len = strlen (newstr) + 1; + gp_debug_printf (GP_DEBUG_LOW, "canon", "%s\n", newstr); + intatpos (newstr, 0x0, 0x1); // get picturethumbnail + intatpos (newstr, 0x4, BULK_READ_SIZE); + msg = psa50_usb_dialogue (camera, 0x01, 0x11, 0x202, &len, newstr, + name_len); + if (!msg) { + psa50_error_type (camera); + return NULL; + } + gp_debug_printf (GP_DEBUG_LOW, "canon", "File length: %x\n", len); + file = malloc (len); + if (!file) { + perror ("malloc"); + return NULL; + } + memcpy (file, msg, len); + total = len; + *length = len; + break; + case CANON_SERIAL_RS232: + default: + name_len = strlen (name) + 1; + msg = psa50_serial_dialogue (camera, 0x1, 0x11, &len, + "\x01\x00\x00\x00\x00", 5, + &name_len, 1, "\x00", 2, + name, strlen (name) + 1, NULL); + if (!msg) { + psa50_error_type (camera); + return NULL; + } + while (msg) { + if (len < 20 || get_int (msg)) { + return NULL; + } + if (!file) { + total = get_int (msg + 4); + if (total > 2000000) { /* 2 MB thumbnails ? unlikely ... */ + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: %d is too big\n", + total); + return NULL; + } + file = malloc (total); + if (!file) { + perror ("malloc"); + return NULL; + } + if (length) + *length = total; + } + size = get_int (msg + 12); + if (get_int (msg + 8) != expect || expect + size > total + || size > len - 20) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: doesn't fit\n"); + return NULL; + } + memcpy (file + expect, msg + 20, size); + expect += size; + gp_camera_progress (camera, + total ? (expect / (float) total) * + 100 : 100); + if ((expect == total) != get_int (msg + 16)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: end mark != end of data\n"); + return NULL; + } + if (expect == total) { + /* We finished receiving the file. Parse the header and + return just the thumbnail */ + break; + } + msg = psa50_recv_msg (camera, 0x1, 0x21, &len); + } + break; + } + + switch (cs->model) { + case CANON_PS_A70: /* pictures are JFIF files */ + /* we skip the first FF D8 */ + i = 3; + j = 0; + in = 0; + + /* we want to drop the header to get the thumbnail */ + + thumb = malloc (total); + if (!thumb) { + perror ("malloc"); + break; + } + + while (i < total) { + if (file[i] == JPEG_ESC) { + if (file[i + 1] == JPEG_BEG && + ((file[i + 3] == JPEG_SOS) + || (file[i + 3] == JPEG_A50_SOS))) { + in = 1; + } else if (file[i + 1] == JPEG_END) { + in = 0; + thumb[j++] = file[i]; + thumb[j] = file[i + 1]; + return thumb; + } + } + + if (in == 1) + thumb[j++] = file[i]; + i++; + + } + return NULL; + break; + + default: /* Camera supports EXIF */ + exifdat.header = file; + exifdat.data = file + 12; + + gp_debug_printf (GP_DEBUG_LOW, "canon", + "Got thumbnail, extracting it with the EXIF lib.\n"); + if (exif_parse_data (&exifdat) > 0) { + gp_debug_printf (GP_DEBUG_LOW, "canon", "Parsed exif data.\n"); + file = exif_get_thumbnail (&exifdat); // Extract Thumbnail + if (file == NULL) { + int f; + char fn[255]; + + if (rindex (name, '\\') != NULL) + snprintf (fn, sizeof (fn) - 1, + "canon-death-dump.dat-%s", + rindex (name, '\\') + 1); + else + snprintf (fn, sizeof (fn) - 1, + "canon-death-dump.dat-%s", name); + fn[sizeof (fn) - 1] = 0; + + gp_debug_printf (GP_DEBUG_LOW, "canon", + "psa50_get_thumbnail: " + "Thumbnail conversion error, saving " + "%i bytes to '%s'", total, fn); + /* create with O_EXCL and 0600 for security */ + if ((f = + open (fn, O_CREAT | O_EXCL | O_RDWR, + 0600)) == -1) { + char errstr[255]; + + snprintf (errstr, sizeof (errstr), + "psa50_get_thumbnail: error creating '%s'", + fn); + errstr[sizeof (errstr) - 1] = 0; + + perror (errstr); + break; + } + if (write (f, file, total) == -1) { + char errstr[255]; + + snprintf (errstr, sizeof (errstr), + "psa50_get_thumbnail: error writing to file '%s'", + fn); + errstr[sizeof (errstr) - 1] = 0; + + perror (errstr); + } + + close (f); + break; + } + return file; + } + break; + } + + free (file); + return NULL; } -int psa50_delete_file(Camera *camera, const char *name, const char *dir) +int +psa50_delete_file (Camera *camera, const char *name, const char *dir) { // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char buf[300]; - unsigned char *msg; - int len,name_len; - - switch (canon_comm_method) { - case CANON_USB: - memcpy(buf,dir,strlen(dir)+1); - memcpy(buf+strlen(dir)+1,name,strlen(name)+1); - name_len=strlen(dir)+strlen(name)+2; - len=0x4; - msg = psa50_usb_dialogue(camera,0x0d,0x11,0x201,&len,buf,name_len); - break; - case CANON_SERIAL_RS232: - default: - msg = psa50_serial_dialogue(camera,0xd,0x11,&len,dir,strlen(dir)+1, - name,strlen(name)+1,NULL); - break; - } - if (!msg) { - psa50_error_type(camera); - return -1; - } - if (msg[0] == 0x29) { - gp_camera_message(camera,_("File protected")); - return -1; - } - - return 0; + unsigned char buf[300]; + unsigned char *msg; + int len, name_len; + + switch (canon_comm_method) { + case CANON_USB: + memcpy (buf, dir, strlen (dir) + 1); + memcpy (buf + strlen (dir) + 1, name, strlen (name) + 1); + name_len = strlen (dir) + strlen (name) + 2; + len = 0x4; + msg = psa50_usb_dialogue (camera, 0x0d, 0x11, 0x201, &len, buf, + name_len); + break; + case CANON_SERIAL_RS232: + default: + msg = psa50_serial_dialogue (camera, 0xd, 0x11, &len, dir, + strlen (dir) + 1, name, strlen (name) + 1, + NULL); + break; + } + if (!msg) { + psa50_error_type (camera); + return -1; + } + if (msg[0] == 0x29) { + gp_camera_message (camera, _("File protected")); + return -1; + } + + return 0; } /* * Upload to USB Camera * */ -int psa50_put_file_usb(Camera *camera, CameraFile *file, char *destname, char *destpath) +int +psa50_put_file_usb (Camera *camera, CameraFile * file, char *destname, char *destpath) { - gp_camera_message(camera,_("Not implemented!")); - return GP_ERROR; + gp_camera_message (camera, _("Not implemented!")); + return GP_ERROR; } /* @@ -2025,102 +2233,106 @@ int psa50_put_file_usb(Camera *camera, CameraFile *file, char *destname, char *d #define HDR_FIXED_LEN 30 #define DATA_BLOCK 1536 -int psa50_put_file_serial(Camera *camera, CameraFile *file, char *destname, char *destpath) +int +psa50_put_file_serial (Camera *camera, CameraFile * file, char *destname, char *destpath) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - unsigned char *msg; - char filename[64]; - char buf[4096]; - int offset=0; - char offset2[4]; - int block_len; - char block_len2[4]; - int sent=0; - int i,j=0,len, hdr_len; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + unsigned char *msg; + char filename[64]; + char buf[4096]; + int offset = 0; + char offset2[4]; + int block_len; + char block_len2[4]; + int sent = 0; + int i, j = 0, len, hdr_len; long int size; const char *data, *name; - cs->uploading = 1; + cs->uploading = 1; gp_file_get_name (file, &name); - for(i=0;name[i];i++) - filename[i]=toupper(name[i]); - filename[i]='\0'; + for (i = 0; name[i]; i++) + filename[i] = toupper (name[i]); + filename[i] = '\0'; - hdr_len = HDR_FIXED_LEN + strlen(name) + strlen(destpath); + hdr_len = HDR_FIXED_LEN + strlen (name) + strlen (destpath); - gp_camera_progress(camera, 0); + gp_camera_progress (camera, 0); gp_file_get_data_and_size (file, &data, &size); - while(sent<size) { - - if(size < DATA_BLOCK) - block_len = size; - else if ((size - sent < DATA_BLOCK)) - block_len = size - sent; - else - block_len = DATA_BLOCK; - - offset = sent; - - for(i=0;i<4;i++) { - offset2[i] = (offset >> (8*i)) & 0xff; - block_len2[i] = (block_len >> (8*i)) & 0xff; - } - - for(i=0; i<DATA_BLOCK; i++) { - buf[i] = data[j]; - j++; - } - - msg = psa50_serial_dialogue(camera,0x3,0x11,&len,"\x02\x00\x00\x00",4, - offset2,4,block_len2,4, - destpath,strlen(destpath),destname,strlen(destname)+1, - buf,block_len, - NULL); - if (!msg) { - cs->uploading = 0; - return GP_ERROR; - } - sent += block_len; - gp_camera_progress(camera, size ? (sent/(float) size)*100 : 100); - } - cs->uploading = 0; - return GP_OK; + while (sent < size) { + + if (size < DATA_BLOCK) + block_len = size; + else if ((size - sent < DATA_BLOCK)) + block_len = size - sent; + else + block_len = DATA_BLOCK; + + offset = sent; + + for (i = 0; i < 4; i++) { + offset2[i] = (offset >> (8 * i)) & 0xff; + block_len2[i] = (block_len >> (8 * i)) & 0xff; + } + + for (i = 0; i < DATA_BLOCK; i++) { + buf[i] = data[j]; + j++; + } + + msg = psa50_serial_dialogue (camera, 0x3, 0x11, &len, "\x02\x00\x00\x00", 4, + offset2, 4, block_len2, 4, + destpath, strlen (destpath), destname, + strlen (destname) + 1, buf, block_len, NULL); + if (!msg) { + cs->uploading = 0; + return GP_ERROR; + } + sent += block_len; + gp_camera_progress (camera, size ? (sent / (float) size) * 100 : 100); + } + cs->uploading = 0; + return GP_OK; } /* * Upload a file to the camera * */ -int psa50_put_file(Camera *camera, CameraFile *file, char *destname, char *destpath) +int +psa50_put_file (Camera *camera, CameraFile * file, char *destname, char *destpath) { - switch (canon_comm_method) { - case CANON_USB: - return psa50_put_file_usb(camera, file,destname,destpath); - break; - case CANON_SERIAL_RS232: - default: - return psa50_put_file_serial(camera, file,destname,destpath); - break; - } + switch (canon_comm_method) { + case CANON_USB: + return psa50_put_file_usb (camera, file, destname, destpath); + break; + case CANON_SERIAL_RS232: + default: + return psa50_put_file_serial (camera, file, destname, destpath); + break; + } } /* * print a message corresponding * to the error encountered */ -void psa50_error_type(Camera *camera) +void +psa50_error_type (Camera *camera) { - switch(receive_error) { - case ERROR_LOWBATT: - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: no battery left, Bailing out!\n"); - break; - case FATAL_ERROR: - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: camera connection lost!\n"); - break; - default: - gp_debug_printf(GP_DEBUG_LOW,"canon","ERROR: malformed message\n"); - break; - } + switch (receive_error) { + case ERROR_LOWBATT: + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: no battery left, Bailing out!\n"); + break; + case FATAL_ERROR: + gp_debug_printf (GP_DEBUG_LOW, "canon", + "ERROR: camera connection lost!\n"); + break; + default: + gp_debug_printf (GP_DEBUG_LOW, "canon", "ERROR: malformed message\n"); + break; + } } diff --git a/camlibs/canon/serial.c b/camlibs/canon/serial.c index 2e54b680c..7ab073b64 100644 --- a/camlibs/canon/serial.c +++ b/camlibs/canon/serial.c @@ -39,11 +39,13 @@ gp_port_settings settings; -void serial_flush_input(gp_port *gdev) +void +serial_flush_input (gp_port *gdev) { } -void serial_flush_output(gp_port *gdev) +void +serial_flush_output (gp_port *gdev) { } @@ -60,16 +62,17 @@ void serial_flush_output(gp_port *gdev) * ****************************************************************************/ -int canon_serial_change_speed(gp_port *gdev, int speed) +int +canon_serial_change_speed (gp_port *gdev, int speed) { - /* set speed */ - gp_port_settings_get(gdev, &settings); - settings.serial.speed = speed; - gp_port_settings_set(gdev, settings); - - usleep(70000); - - return 1; + /* set speed */ + gp_port_settings_get (gdev, &settings); + settings.serial.speed = speed; + gp_port_settings_set (gdev, settings); + + usleep (70000); + + return 1; } @@ -85,11 +88,13 @@ int canon_serial_change_speed(gp_port *gdev, int speed) * Returns 0 on CTS low. * ****************************************************************************/ -int canon_serial_get_cts(gp_port *gdev) +int +canon_serial_get_cts (gp_port *gdev) { - int level; - gp_port_pin_get(gdev,PIN_CTS, &level); - return (level); + int level; + + gp_port_pin_get (gdev, PIN_CTS, &level); + return (level); } /***************************************************************************** @@ -102,7 +107,8 @@ int canon_serial_get_cts(gp_port *gdev) * Returns GP_ERROR on any error. * ****************************************************************************/ -int canon_usb_camera_init(Camera *camera) +int +canon_usb_camera_init (Camera *camera) { char msg[0x58]; char buffer[0x44]; @@ -110,20 +116,19 @@ int canon_usb_camera_init(Camera *camera) char *camstat_str = "NOT RECOGNIZED"; char camstat; - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_usb_camera_init()"); - - memset(msg, 0, sizeof(msg)); - memset(buffer, 0, sizeof(buffer)); + gp_debug_printf (GP_DEBUG_LOW, "canon", "canon_usb_camera_init()"); + + memset (msg, 0, sizeof (msg)); + memset (buffer, 0, sizeof (buffer)); - i = gp_port_usb_msg_read(camera->port, 0x0c, 0x55, 0, msg, 1); + i = gp_port_usb_msg_read (camera->port, 0x0c, 0x55, 0, msg, 1); if (i != 1) { - fprintf(stderr,"canon_usb_camera_init(): step #1 read failed! (returned %i) " - "Camera not operational.\n", i); + fprintf (stderr, "canon_usb_camera_init(): step #1 read failed! (returned %i) " + "Camera not operational.\n", i); return GP_ERROR; } camstat = msg[0]; - switch(camstat) - { + switch (camstat) { case 'A': camstat_str = "Camera was already active"; break; @@ -133,44 +138,48 @@ int canon_usb_camera_init(Camera *camera) case 'I': case 'E': camstat_str = "Unknown (some kind of error)"; - break; + break; } if (camstat != 'A' && camstat != 'C') { - fprintf(stderr, "canon_usb_camera_init(): initial camera response: %c/'%s' " - "not 'A' or 'C'. Camera not operational.\n", - camstat, camstat_str); + fprintf (stderr, "canon_usb_camera_init(): initial camera response: %c/'%s' " + "not 'A' or 'C'. Camera not operational.\n", camstat, camstat_str); return GP_ERROR; } - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_usb_camera_init(): initial camera response: %c/'%s'", - camstat, camstat_str); + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_usb_camera_init(): initial camera response: %c/'%s'", camstat, + camstat_str); - i = gp_port_usb_msg_read(camera->port, 0x04, 0x1, 0, msg, 0x58); + i = gp_port_usb_msg_read (camera->port, 0x04, 0x1, 0, msg, 0x58); if (i != 0x58) { - fprintf(stderr, "canon_usb_camera_init(): step #2 read failed! (returned %i, expected %i) " - "Camera not operational.\n", i, 0x58); + fprintf (stderr, + "canon_usb_camera_init(): step #2 read failed! (returned %i, expected %i) " + "Camera not operational.\n", i, 0x58); return GP_ERROR; } - i = gp_port_usb_msg_write(camera->port, 0x04, 0x11, 0, msg+0x48, 0x10); + i = gp_port_usb_msg_write (camera->port, 0x04, 0x11, 0, msg + 0x48, 0x10); if (i != 0x10) { - fprintf(stderr, "canon_usb_camera_serial(): step #3 write failed! (returned %i, expected %i) " - "Camera not operational.\n", i, 0x10); + fprintf (stderr, + "canon_usb_camera_serial(): step #3 write failed! (returned %i, expected %i) " + "Camera not operational.\n", i, 0x10); return GP_ERROR; } - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_usb_camera_init(): PC sign on LCD should be lit now"); - - i = gp_port_read(camera->port, buffer, 0x44); - - if ( (i >= 4) - && (buffer[i-4] == 0x54) && (buffer[i-3] == 0x78) - && (buffer[i-2] == 0x00) && (buffer[i-1] == 0x00)) { - gp_debug_printf(GP_DEBUG_LOW,"canon", - "canon_usb_camera_init(): expected %i and got %i bytes with " - "\"54 78 00 00\" at the end, so we just ignore the whole bunch", 0x44, i); + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_usb_camera_init(): PC sign on LCD should be lit now"); + + i = gp_port_read (camera->port, buffer, 0x44); + + if ((i >= 4) + && (buffer[i - 4] == 0x54) && (buffer[i - 3] == 0x78) + && (buffer[i - 2] == 0x00) && (buffer[i - 1] == 0x00)) { + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_usb_camera_init(): expected %i and got %i bytes with " + "\"54 78 00 00\" at the end, so we just ignore the whole bunch", + 0x44, i); } else { - fprintf(stderr, - "canon_usb_camera_init(): step #4 read failed! (returned %i, expected %i) " - "Camera might still work though. Continuing.\n", i, 0x44); + fprintf (stderr, + "canon_usb_camera_init(): step #4 read failed! (returned %i, expected %i) " + "Camera might still work though. Continuing.\n", i, 0x44); } return GP_OK; } @@ -188,62 +197,69 @@ int canon_usb_camera_init(Camera *camera) * ****************************************************************************/ -int canon_serial_init(Camera *camera, const char *devname) +int +canon_serial_init (Camera *camera, const char *devname) { - int res; - gp_port_settings settings; - - gp_debug_printf(GP_DEBUG_LOW,"canon","Initializing the camera.\n"); - - switch (canon_comm_method) { - case CANON_USB: - - res = gp_port_settings_get(camera->port, &settings); - if (res != GP_OK) { - fprintf(stderr,"canon_init_serial(): Cannot get USB port settings (returned %i)", res); - return GP_ERROR; - } - - settings.usb.inep = 0x81; - settings.usb.outep = 0x02; - settings.usb.config = 1; - settings.usb.altsetting = 0; - - res = gp_port_settings_set(camera->port, settings); - if (res != GP_OK) { - fprintf(stderr,"canon_init_serial(): Cannot apply USB port settings (returned %i) " - "Camera not operational.\n", res); - return GP_ERROR; - } - - res = canon_usb_camera_init(camera); - if (res != GP_OK) { - fprintf(stderr,"canon_init_serial(): Cannot initialize camera, canon_usb_camera_init() " - "returned %i\n", res); - return GP_ERROR; - } - break; - case CANON_SERIAL_RS232: - default: - - if (!devname) { - fprintf(stderr, "INVALID device string (NULL)\n"); - return GP_ERROR; - } - - gp_debug_printf(GP_DEBUG_LOW,"canon","canon_init_serial(): Using serial port on %s\n", devname); - - strcpy(settings.serial.port, devname); - settings.serial.speed = 9600; - settings.serial.bits = 8; - settings.serial.parity = 0; - settings.serial.stopbits = 1; - - gp_port_settings_set(camera->port, settings); /* Sets the serial device name */ - - break; - } - return GP_OK; + int res; + gp_port_settings settings; + + gp_debug_printf (GP_DEBUG_LOW, "canon", "Initializing the camera.\n"); + + switch (canon_comm_method) { + case CANON_USB: + + res = gp_port_settings_get (camera->port, &settings); + if (res != GP_OK) { + fprintf (stderr, + "canon_init_serial(): Cannot get USB port settings (returned %i)", + res); + return GP_ERROR; + } + + settings.usb.inep = 0x81; + settings.usb.outep = 0x02; + settings.usb.config = 1; + settings.usb.altsetting = 0; + + res = gp_port_settings_set (camera->port, settings); + if (res != GP_OK) { + fprintf (stderr, + "canon_init_serial(): Cannot apply USB port settings (returned %i) " + "Camera not operational.\n", res); + return GP_ERROR; + } + + res = canon_usb_camera_init (camera); + if (res != GP_OK) { + fprintf (stderr, + "canon_init_serial(): Cannot initialize camera, canon_usb_camera_init() " + "returned %i\n", res); + return GP_ERROR; + } + break; + case CANON_SERIAL_RS232: + default: + + if (!devname) { + fprintf (stderr, "INVALID device string (NULL)\n"); + return GP_ERROR; + } + + gp_debug_printf (GP_DEBUG_LOW, "canon", + "canon_init_serial(): Using serial port on %s\n", + devname); + + strcpy (settings.serial.port, devname); + settings.serial.speed = 9600; + settings.serial.bits = 8; + settings.serial.parity = 0; + settings.serial.stopbits = 1; + + gp_port_settings_set (camera->port, settings); /* Sets the serial device name */ + + break; + } + return GP_OK; } /***************************************************************************** @@ -260,38 +276,40 @@ int canon_serial_init(Camera *camera, const char *devname) * ****************************************************************************/ -int canon_serial_send(Camera *camera, const unsigned char *buf, int len, int sleep) +int +canon_serial_send (Camera *camera, const unsigned char *buf, int len, int sleep) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; - int i; - - if (cs->dump_packets == 1) - dump_hex(camera,"canon_serial_send()", buf, len); - - /* the A50 does not like to get too much data in a row at 115200 - * The S10 and S20 do not have this problem */ - if (sleep>0 && cs->slow_send == 1) { - for(i=0;i<len;i++) { - gp_port_write(camera->port,(char*)buf,1); - buf++; - usleep(sleep); - } - } else { - gp_port_write(camera->port,(char*)buf,len); - } - - return 0; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; + int i; + + if (cs->dump_packets == 1) + dump_hex (camera, "canon_serial_send()", buf, len); + + /* the A50 does not like to get too much data in a row at 115200 + * The S10 and S20 do not have this problem */ + if (sleep > 0 && cs->slow_send == 1) { + for (i = 0; i < len; i++) { + gp_port_write (camera->port, (char *) buf, 1); + buf++; + usleep (sleep); + } + } else { + gp_port_write (camera->port, (char *) buf, len); + } + + return 0; } /** * Sets the timeout, in miliseconds. */ -void serial_set_timeout(gp_port *gdev, int to) +void +serial_set_timeout (gp_port *gdev, int to) { - // struct canon_info *cs = (struct canon_info*)camera->camlib_data; - - gp_port_timeout_set(gdev,to); + // struct canon_info *cs = (struct canon_info*)camera->camlib_data; + + gp_port_timeout_set (gdev, to); } /***************************************************************************** @@ -305,30 +323,31 @@ void serial_set_timeout(gp_port *gdev, int to) * Returns the byte on success, -1 on error. * ****************************************************************************/ -int canon_serial_get_byte(gp_port *gdev) +int +canon_serial_get_byte (gp_port *gdev) { - static unsigned char cache[512]; - static unsigned char *cachep = cache; - static unsigned char *cachee = cache; - int recv; - - /* if still data in cache, get it */ - if (cachep < cachee) { - return (int) *cachep++; - } - - recv = gp_port_read(gdev, cache, 1); - if (recv == GP_ERROR || recv == GP_ERROR_IO_TIMEOUT) - return -1; - - cachep = cache; - cachee = cache + recv; - - if (recv) { - return (int) *cachep++; - } - - return -1; + static unsigned char cache[512]; + static unsigned char *cachep = cache; + static unsigned char *cachee = cache; + int recv; + + /* if still data in cache, get it */ + if (cachep < cachee) { + return (int) *cachep++; + } + + recv = gp_port_read (gdev, cache, 1); + if (recv == GP_ERROR || recv == GP_ERROR_IO_TIMEOUT) + return -1; + + cachep = cache; + cachee = cache + recv; + + if (recv) { + return (int) *cachep++; + } + + return -1; } /**************************************************************************** diff --git a/camlibs/canon/util.c b/camlibs/canon/util.c index 9234a11dc..d912a2298 100644 --- a/camlibs/canon/util.c +++ b/camlibs/canon/util.c @@ -37,86 +37,87 @@ #define NIBBLE(_i) (((_i) < 10) ? '0' + (_i) : 'A' + (_i) - 10) -void dump_hex(Camera *camera, const char *msg, const unsigned char *buf, int len) +void +dump_hex (Camera *camera, const char *msg, const unsigned char *buf, int len) { -// struct canon_info *cs = (struct canon_info*)camera->camlib_data; - int i; - int nlocal; - const unsigned char *pc; - char *out; - const unsigned char *start; - char c; - char line[100]; - - // if (cs->debug > 8) { // Only printout with max. debug level (9) - start = buf; - +// struct canon_info *cs = (struct canon_info*)camera->camlib_data; + int i; + int nlocal; + const unsigned char *pc; + char *out; + const unsigned char *start; + char c; + char line[100]; + + // if (cs->debug > 8) { // Only printout with max. debug level (9) + start = buf; + #if 0 - if (len > 160) { - fprintf(stderr,"dump n:%d --> 160\n", len); - len = 160; - } + if (len > 160) { + fprintf (stderr, "dump n:%d --> 160\n", len); + len = 160; + } #endif - - fprintf(stderr,"%s: (%d bytes)\n", msg, len); - while (len > 0) { - sprintf(line, "%08x: ", buf - start); - out = line + 10; - - for (i = 0, pc = buf, nlocal = len; i < 16; i++, pc++) { - if (nlocal > 0) { - c = *pc; - - *out++ = NIBBLE((c >> 4) & 0xF); - *out++ = NIBBLE(c & 0xF); - - nlocal--; - } else { - *out++ = ' '; - *out++ = ' '; - } - + + fprintf (stderr, "%s: (%d bytes)\n", msg, len); + while (len > 0) { + sprintf (line, "%08x: ", buf - start); + out = line + 10; + + for (i = 0, pc = buf, nlocal = len; i < 16; i++, pc++) { + if (nlocal > 0) { + c = *pc; + + *out++ = NIBBLE ((c >> 4) & 0xF); + *out++ = NIBBLE (c & 0xF); + + nlocal--; + } else { + *out++ = ' '; *out++ = ' '; } - - *out++ = '-'; + *out++ = ' '; - - for (i = 0, pc = buf, nlocal = len; - (i < 16) && (nlocal > 0); - i++, pc++, nlocal--) { - c = *pc; - - if ((c < ' ') || (c >= 126)) { - c = '.'; - } - - *out++ = c; + } + + *out++ = '-'; + *out++ = ' '; + + for (i = 0, pc = buf, nlocal = len; + (i < 16) && (nlocal > 0); i++, pc++, nlocal--) { + c = *pc; + + if ((c < ' ') || (c >= 126)) { + c = '.'; } - - *out++ = 0; - - fprintf(stderr,"%s\n", line); - - buf += 16; - len -= 16; - } /* end while */ - /* } end 'if debug' */ + + *out++ = c; + } + + *out++ = 0; + + fprintf (stderr, "%s\n", line); + + buf += 16; + len -= 16; + } /* end while */ + /* } end 'if debug' */ } /* end dump */ -void debug_message(Camera *camera, const char * msg, ...) +void +debug_message (Camera *camera, const char *msg, ...) { - struct canon_info *cs = (struct canon_info*)camera->camlib_data; + struct canon_info *cs = (struct canon_info *) camera->camlib_data; va_list ap; - + if (cs->debug) { - va_start(ap, msg); - vfprintf(stderr,msg, ap); - va_end(ap); + va_start (ap, msg); + vfprintf (stderr, msg, ap); + va_end (ap); } } - + /**************************************************************************** * * End of file: util.c |