2001-11-08 Lutz M�ller <urc8@rz.uni-karlsruhe.de>

* camlibs/sierra: Improve error reporting. Use register 47 for
          pic-info retrieval. Support GP_FILE_TYPE_AUDIO.


git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2971 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Lutz Mueller
2001-11-08 15:48:40 +00:00
parent ad87fc5707
commit 0f47ae4092
9 changed files with 199 additions and 121 deletions

View File

@@ -1,3 +1,8 @@
2001-11-08 Lutz Müller <urc8@rz.uni-karlsruhe.de>
* camlibs/sierra: Improve error reporting. Use register 47 for
pic-info retrieval. Support GP_FILE_TYPE_AUDIO.
2001-11-08 Chris Pinkham <cpinkham@infi.net>
* camlibs/jamcam/README

View File

@@ -10,6 +10,8 @@
#define QUICKSLEEP 5
#define GP_MODULE "sierra"
/**
* sierra_valid_type:
* @b : first byte of the packet to be checked
@@ -67,12 +69,8 @@ int sierra_change_folder (Camera *camera, const char *folder)
int st = 0,i = 1;
char target[128];
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** sierra_change_folder");
if (!folder || !camera)
return GP_ERROR_BAD_PARAMETERS;
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder);
GP_DEBUG ("*** sierra_change_folder");
GP_DEBUG ("*** folder: %s", folder);
/*
* Do not issue the command if the camera doesn't support folders
@@ -113,7 +111,7 @@ int sierra_change_folder (Camera *camera, const char *folder)
int sierra_list_files (Camera *camera, const char *folder, CameraList *list)
{
int count, i, bsize;
int count, i, bsize = 0;
char buf[1024];
CHECK (sierra_change_folder (camera, folder));
@@ -698,8 +696,12 @@ int sierra_set_int_register (Camera *camera, int reg, int value)
return GP_OK;
/* DC1 = invalid register or value */
if (buf[0] == DC1)
if (buf[0] == DC1) {
gp_camera_set_error (camera, _("Could not set "
"int register %i. Please contact "
"<gphoto-devel@gphoto.org>."), reg);
return GP_ERROR_BAD_PARAMETERS;
}
}
sierra_set_speed (camera, -1);
@@ -735,8 +737,12 @@ int sierra_get_int_register (Camera *camera, int reg, int *value)
CHECK (ret);
/* DC1 = invalid register or value */
if (buf[0] == DC1)
if (buf[0] == DC1) {
gp_camera_set_error (camera, _("Could not get "
"register %i. Please contact "
"<gphoto-devel@gphoto.org>."), reg);
return GP_ERROR_BAD_PARAMETERS;
}
if (buf[0] == TYPE_DATA_END) {
ret = sierra_write_ack(camera);
@@ -819,9 +825,13 @@ int sierra_set_string_register (Camera *camera, int reg, const char *s, long int
CHECK (ret);
c = (unsigned char)buf[0];
if (c == DC1)
if (c == DC1) {
gp_camera_set_error (camera, _("Could not "
"set string register %i. Please "
"contact <gphoto-devel@gphoto.org>."),
reg);
return GP_ERROR_BAD_PARAMETERS;
if (c == ACK) {
} else if (c == ACK) {
done = 1;
if (do_percent)
gp_camera_progress (camera, (float)x / (float)length);
@@ -841,10 +851,11 @@ int sierra_set_string_register (Camera *camera, int reg, const char *s, long int
}
int sierra_get_string_register (Camera *camera, int reg, int file_number,
CameraFile *file, char *s, int *length) {
CameraFile *file, unsigned char *b,
unsigned int *b_len) {
char packet[4096];
int done, x, packlength, do_percent, l;
unsigned char packet[4096];
unsigned int packlength, total = *b_len;
gp_debug_printf (GP_DEBUG_HIGH, "sierra",
"* sierra_get_string_register");
@@ -852,34 +863,10 @@ int sierra_get_string_register (Camera *camera, int reg, int file_number,
gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* file number: %i",
file_number);
do_percent = 1;
/* Set the current picture number */
if (file_number >= 0)
CHECK (sierra_set_int_register (camera, 4, file_number));
switch (reg) {
case 14:
/* Get the size of the current image */
CHECK (sierra_get_int_register (camera, 12, &l));
break;
case 15:
/* Get the size of the current thumbnail */
CHECK (sierra_get_int_register (camera, 13, &l));
break;
case 44:
/* Get the size of the current audio will do */
//FIXME
break;
default:
do_percent = 0;
}
/* Build and send the request */
CHECK (sierra_build_packet (camera, TYPE_COMMAND, 0, 2, packet));
packet[4] = 0x04;
@@ -887,35 +874,33 @@ int sierra_get_string_register (Camera *camera, int reg, int file_number,
CHECK (sierra_write_packet (camera, packet));
/* Read all the data packets */
x = 0; done = 0;
while (!done) {
*b_len = 0;
do {
/* Read one packet */
CHECK (sierra_read_packet (camera, packet));
if (packet[0] == DC1)
if (packet[0] == DC1) {
gp_camera_set_error (camera, _("Could not get "
"string register %i. Please contact "
"<gphoto-devel@gphoto.org>."), reg);
return GP_ERROR_BAD_PARAMETERS;
}
CHECK (sierra_write_ack (camera));
packlength = ((unsigned char)packet[2]) +
((unsigned char)packet[3] * 256);
packlength = packet[2] | (packet[3] << 8);
GP_DEBUG ("Packet length: %d", packlength);
if (s)
memcpy (&s[x], &packet[4], packlength);
if (b)
memcpy (&b[*b_len], &packet[4], packlength);
*b_len += packlength;
if (file) {
CHECK (gp_file_append (file, &packet[4], packlength));
if (do_percent)
gp_camera_progress (camera,
(float)((float)(x+packlength)/(float)(l)));
gp_camera_progress (camera,
(float) (*b_len) / (float) (total));
}
x += packlength;
if (packet[0] == TYPE_DATA_END)
done = 1;
}
if (length)
*length = x;
} while (packet[0] != TYPE_DATA_END);
return (GP_OK);
}
@@ -1043,17 +1028,15 @@ int sierra_end_session (Camera *camera)
int sierra_capture_preview (Camera *camera, CameraFile *file)
{
gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_capture_preview");
unsigned int size;
if (file == NULL)
return (GP_ERROR_BAD_PARAMETERS);
/* Send to the camera the capture request and wait
for the completion */
CHECK (sierra_write_action_command_and_wait(camera, 5));
/* Retrieve the preview and set the MIME type */
CHECK (sierra_get_string_register (camera, 14, 0, file, NULL, NULL));
CHECK (sierra_get_int_register (camera, 12, &size));
CHECK (sierra_get_string_register (camera, 14, 0, file, NULL, &size));
CHECK (gp_file_set_mime_type (file, "image/jpeg"));
return (GP_OK);
@@ -1062,15 +1045,13 @@ int sierra_capture_preview (Camera *camera, CameraFile *file)
int sierra_capture (Camera *camera, CameraCaptureType type,
CameraFilePath *filepath)
{
int picnum, length;
int picnum, length = 0;
char buf[128];
const char *folder;
gp_debug_printf (GP_DEBUG_HIGH, "sierra", "* sierra_capture");
/* Various preliminary checks */
if (!camera || !filepath)
return (GP_ERROR_BAD_PARAMETERS);
/* We can only capture images */
if (type != GP_CAPTURE_IMAGE)
return (GP_ERROR_NOT_SUPPORTED);
@@ -1131,3 +1112,38 @@ int sierra_upload_file (Camera *camera, CameraFile *file)
return GP_OK;
}
static unsigned int
get_int (const unsigned char b[])
{
return (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24));
}
int sierra_get_pic_info (Camera *camera, unsigned int n,
SierraPicInfo *pic_info)
{
unsigned char buf[1024];
unsigned int buf_len = 0;
CHECK (sierra_get_string_register (camera, 47, n, NULL, buf, &buf_len));
if (buf_len != 32)
return (GP_ERROR_CORRUPTED_DATA);
pic_info->size_file = get_int (buf);
pic_info->size_preview = get_int (buf + 4);
pic_info->size_audio = get_int (buf + 8);
pic_info->resolution = get_int (buf + 12);
pic_info->locked = get_int (buf + 16);
pic_info->date = get_int (buf + 20);
pic_info->animation_type = get_int (buf + 28);
/* Make debugging easier */
GP_DEBUG ("File size: %d", pic_info->size_file);
GP_DEBUG ("Preview size: %i", pic_info->size_preview);
GP_DEBUG ("Audio size: %i", pic_info->size_audio);
GP_DEBUG ("Resolution: %i", pic_info->resolution);
GP_DEBUG ("Locked: %i", pic_info->locked);
GP_DEBUG ("Date: %i", pic_info->date);
GP_DEBUG ("Animation type: %i", pic_info->animation_type);
return (GP_OK);
}

View File

@@ -49,6 +49,24 @@ int sierra_write_packet (Camera *camera, char *packet);
int sierra_read_packet (Camera *camera, char *packet);
int sierra_build_packet (Camera *camera, char type, char subtype, int data_length, char *packet);
typedef enum {
SIERRA_LOCKED_NO = 0x00,
SIERRA_LOCKED_YES = 0x01
} SierraLocked;
typedef struct _SierraPicInfo SierraPicInfo;
struct _SierraPicInfo {
unsigned int size_file;
unsigned int size_preview;
unsigned int size_audio;
unsigned int resolution;
SierraLocked locked;
unsigned int date;
unsigned int animation_type;
};
int sierra_get_pic_info (Camera *camera, unsigned int n,
SierraPicInfo *pic_info);
/* Communications functions */
int sierra_set_speed (Camera *camera, int speed);
int sierra_end_session (Camera *camera);
@@ -61,7 +79,8 @@ int sierra_set_int_register (Camera *camera, int reg, int value);
int sierra_get_int_register (Camera *camera, int reg, int *value);
int sierra_set_string_register (Camera *camera, int reg, const char *s, long int length);
int sierra_get_string_register (Camera *camera, int reg, int file_number,
CameraFile *file, char *s, int *length);
CameraFile *file,
unsigned char *b, unsigned int *b_len);
int sierra_delete (Camera *camera, int picture_number);
int sierra_delete_all (Camera *camera);
int sierra_capture (Camera *camera, CameraCaptureType type,

View File

@@ -34,7 +34,7 @@
#define TIMEOUT 2000
#define CHECK_STOP(camera,result) {int res; res = result; if (res < 0) {camera_stop (camera); return (res);}}
#define CHECK_STOP(camera,result) {int res; res = result; if (res < 0) {camera_stop (camera); gp_log (GP_LOG_DEBUG, "sierra", "Operation failed!"); return (res);}}
#define CHECK_STOP_FREE(camera,result) {int res; res = result; if (res < 0) {camera_stop (camera); free (camera->pl); camera->pl = NULL; return (res);}}
@@ -159,7 +159,8 @@ int camera_abilities (CameraAbilitiesList *list)
GP_OPERATION_CAPTURE_PREVIEW |
GP_OPERATION_CONFIG;
a.file_operations = GP_FILE_OPERATION_DELETE |
GP_FILE_OPERATION_PREVIEW;
GP_FILE_OPERATION_PREVIEW |
GP_FILE_OPERATION_AUDIO;
a.folder_operations = GP_FOLDER_OPERATION_DELETE_ALL |
GP_FOLDER_OPERATION_PUT_FILE;
a.usb_vendor = sierra_cameras[x].usb_vendor;
@@ -197,33 +198,51 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
CameraFileInfo *info, void *data)
{
Camera *camera = data;
int n, l;
int n;
SierraPicInfo pic_info;
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** Getting info:");
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder);
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** file: %s", filename);
/* Get the file number from the CameraFilesystem */
/*
* Get the file number from the CameraFilesystem. We need numbers
* starting with 1.
*/
CHECK (n = gp_filesystem_number (camera->fs, folder, filename));
n++;
/* Set the working folder and the current picture number */
CHECK (camera_start (camera));
CHECK_STOP (camera, sierra_change_folder (camera, folder));
CHECK_STOP (camera, sierra_set_int_register (camera, 4, n + 1));
info->file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE |
GP_FILE_INFO_NAME;
info->preview.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE;
info->file.fields = GP_FILE_INFO_NONE;
info->preview.fields = GP_FILE_INFO_NONE;
info->audio.fields = GP_FILE_INFO_NONE;
/* Name of image */
strncpy (info->file.name, filename, sizeof (info->file.name) - 1);
info->file.name[sizeof (info->file.name) - 1] = '\0';
info->file.fields |= GP_FILE_INFO_NAME;
/* Get the size of the current image */
CHECK_STOP (camera, sierra_get_int_register (camera, 12, &l));
info->file.size = l;
/* Get information about this image */
CHECK (camera_start (camera));
CHECK_STOP (camera, sierra_change_folder (camera, folder));
CHECK_STOP (camera, sierra_get_pic_info (camera, n, &pic_info));
/* Type of image? */
/* Size of file */
info->file.fields |= GP_FILE_INFO_SIZE;
info->file.size = pic_info.size_file;
/* Size of preview */
info->preview.fields |= GP_FILE_INFO_SIZE;
info->preview.size = pic_info.size_preview;
/* Audio data? */
if (pic_info.size_audio) {
/* Size */
info->audio.size = pic_info.size_audio;
info->audio.fields |= GP_FILE_INFO_SIZE;
/* Type */
strcpy (info->audio.type, GP_MIME_WAV);
info->audio.fields |= GP_FILE_INFO_TYPE;
}
/* Type of image and preview? */
if (strstr (filename, ".MOV") != NULL) {
strcpy (info->file.type, GP_MIME_QUICKTIME);
strcpy (info->preview.type, GP_MIME_JPEG);
@@ -234,10 +253,14 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
strcpy (info->file.type, GP_MIME_JPEG);
strcpy (info->preview.type, GP_MIME_JPEG);
}
info->file.fields |= GP_FILE_INFO_TYPE;
info->preview.fields |= GP_FILE_INFO_TYPE;
/* Get the size of the current thumbnail */
CHECK_STOP (camera, sierra_get_int_register (camera, 13, &l));
info->preview.size = l;
/* Image protected? */
info->file.fields |= GP_FILE_INFO_PERMISSIONS;
info->file.permissions = GP_FILE_PERM_READ;
if (pic_info.locked == SIERRA_LOCKED_NO)
info->file.permissions |= GP_FILE_PERM_DELETE;
return (camera_stop (camera));
}
@@ -309,38 +332,45 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
CameraFileType type, CameraFile *file, void *user_data)
{
Camera *camera = user_data;
int regl, regd, n;
int regd, n;
char *jpeg_data = NULL;
int jpeg_size;
const char *data, *mime_type;
long int size;
SierraPicInfo info;
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** sierra_file_get_generic");
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder);
gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** filename: %s", filename);
/* Get the file number from the CameraFileSystem and set the name */
/*
* Get the file number from the CameraFileSystem.
* We need file numbers starting with 1.
*/
CHECK (n = gp_filesystem_number (camera->fs, folder, filename));
CHECK (gp_file_set_name (file, filename));
n++;
/* In which register do we have to look for data? */
switch (type) {
case GP_FILE_TYPE_PREVIEW:
regl = 13;
regd = 15;
break;
case GP_FILE_TYPE_NORMAL:
regl = 12;
regd = 14;
break;
case GP_FILE_TYPE_AUDIO:
regd = 44;
break;
default:
return (GP_ERROR_NOT_SUPPORTED);
}
/* Set the working folder and get the picture data */
/* Set the working folder */
CHECK (camera_start (camera));
CHECK_STOP (camera, sierra_change_folder (camera, folder));
CHECK_STOP (camera, sierra_get_string_register (camera, regd, n + 1,
file, NULL, NULL));
/* We need the file size in order to display progress information */
CHECK_STOP (camera, sierra_get_pic_info (camera, n, &info));
/* Get the file */
CHECK_STOP (camera, sierra_get_string_register (camera, regd, n,
file, NULL, &(info.size_file)));
CHECK (camera_stop (camera));
/* Now get the data and do some post-processing */
@@ -348,12 +378,8 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
switch (type) {
case GP_FILE_TYPE_PREVIEW:
/*
* Thumbnails are always JPEG files (as far as we know...).
* Correct the filename to reflect that.
*/
/* * Thumbnails are always JPEG files (as far as we know...) */
CHECK (gp_file_set_mime_type (file, GP_MIME_JPEG));
CHECK (gp_file_adjust_name_for_mime_type (file));
/*
* Some camera (e.g. Epson 3000z) send the EXIF application
@@ -383,7 +409,10 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
if (!strcmp (mime_type, GP_MIME_RAW))
CHECK (gp_file_set_mime_type (file, GP_MIME_QUICKTIME));
break;
case GP_FILE_TYPE_AUDIO:
CHECK (gp_file_set_mime_type (file, GP_MIME_WAV));
break;
default:
return (GP_ERROR_NOT_SUPPORTED);
}
@@ -485,8 +514,8 @@ put_file_func (CameraFilesystem * fs, const char *folder, CameraFile * file, voi
/* Check the size */
CHECK (gp_file_get_data_and_size (file, &data_file, &data_size));
if ( data_size == 0 ) {
gp_camera_set_error(camera,
_("The file to be uploaded has a null length"));
gp_camera_set_error (camera,
_("The file to be uploaded has a null length"));
return GP_ERROR_BAD_PARAMETERS;
}
@@ -1318,9 +1347,6 @@ int camera_init (Camera *camera)
GPPortSettings settings;
CameraAbilities a;
if (!camera)
return (GP_ERROR_BAD_PARAMETERS);
/* First, set up all the function pointers */
camera->functions->exit = camera_exit;
camera->functions->capture_preview = camera_capture_preview;
@@ -1405,7 +1431,7 @@ int camera_init (Camera *camera)
gp_log (GP_LOG_DEBUG, "sierra", "Could not get register 1: %s",
gp_camera_get_error (camera));
/* FIXME??? What's that for? */
/* FIXME??? What's that for? "Resetting folder system"? */
gp_camera_set_error (camera, NULL);
ret = sierra_set_int_register (camera, 83, -1);
if (ret != GP_OK)

View File

@@ -663,7 +663,9 @@ save_camera_file_to_file (CameraFile *file, CameraFileType type)
}
} else {
gp_file_get_name (file, &name);
strcat(ofile, name);
strcat (ofile, name);
gp_log (GP_LOG_DEBUG, "gphoto2", "Using filename '%s'...",
ofile);
}
switch (type) {

View File

@@ -60,7 +60,7 @@
#define CRS(c,res) {int r = (res); if (r < 0) {gp_camera_status ((c), ""); return (r);}}
#define CHECK_RESULT_OPEN_CLOSE(c,result) {int r; CHECK_OPEN (c); r = (result); if (r < 0) {CHECK_CLOSE (c); gp_camera_status ((c), ""); gp_camera_progress ((c), 0.0); return (r);}; CHECK_CLOSE (c);}
#define CHECK_RESULT_OPEN_CLOSE(c,result) {int r; CHECK_OPEN (c); r = (result); if (r < 0) {CHECK_CLOSE (c); gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Operation failed!"); gp_camera_status ((c), ""); gp_camera_progress ((c), 0.0); return (r);}; CHECK_CLOSE (c);}
#define CHECK_INIT(c) {if (!(c)->pc->lh) {CHECK_RESULT(gp_camera_init(c));}}
struct _CameraPrivateCore {
@@ -470,8 +470,8 @@ gp_camera_progress (Camera *camera, float percentage)
CHECK_NULL (camera);
if ((percentage < 0.) || (percentage > 1.)) {
gp_log (GP_LOG_ERROR, "gphoto2-camera",
"Wrong percentage: %f", percentage);
gp_camera_set_error (camera, _("Wrong percentage: %f"),
percentage);
return (GP_ERROR_BAD_PARAMETERS);
}
@@ -1169,9 +1169,7 @@ gp_camera_file_get (Camera *camera, const char *folder, const char *file,
gp_camera_status (camera, "");
gp_camera_progress (camera, 0.0);
/* We don't trust the camera libraries */
CHECK_RESULT (gp_file_set_type (camera_file, type));
CHECK_RESULT (gp_file_set_name (camera_file, file));
gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Got file '%s'.", file);
return (GP_OK);
}

View File

@@ -24,6 +24,8 @@
#include <stdio.h>
#include <string.h>
#include <gphoto2-port-log.h>
#include "gphoto2-result.h"
static int glob_session_file = 0;
@@ -427,6 +429,8 @@ gp_file_adjust_name_for_mime_type (CameraFile *file)
CHECK_NULL (file);
gp_log (GP_LOG_DEBUG, "gphoto2-file", "Adjusting file name for "
"mime type '%s'...", file->mime_type);
for (x = 0; table[x]; x += 2)
if (!strcmp (file->mime_type, table[x])) {
@@ -437,6 +441,8 @@ gp_file_adjust_name_for_mime_type (CameraFile *file)
strcat (file->name, table[x + 1]);
break;
}
gp_log (GP_LOG_DEBUG, "gphoto2-file", "Name adjusted to '%s'.",
file->name);
return (GP_OK);
}

View File

@@ -21,6 +21,7 @@
#ifndef __GPHOTO2_FILE_H__
#define __GPHOTO2_FILE_H__
#define GP_MIME_WAV "audio/wav"
#define GP_MIME_RAW "image/x-raw"
#define GP_MIME_PNG "image/png"
#define GP_MIME_PGM "image/x-portable-graymap"

View File

@@ -261,6 +261,7 @@ append_file (CameraFilesystem *fs, int x, CameraFile *file)
fs->folder[x].file[fs->folder[x].count - 1].info_dirty = 1;
fs->folder[x].file[fs->folder[x].count - 1].raw = NULL;
fs->folder[x].file[fs->folder[x].count - 1].preview = NULL;
fs->folder[x].file[fs->folder[x].count - 1].audio = NULL;
fs->folder[x].file[fs->folder[x].count - 1].normal = file;
gp_file_ref (file);
@@ -473,6 +474,7 @@ gp_filesystem_append (CameraFilesystem *fs, const char *folder,
fs->folder[x].file[fs->folder[x].count - 1].preview = NULL;
fs->folder[x].file[fs->folder[x].count - 1].normal = NULL;
fs->folder[x].file[fs->folder[x].count - 1].raw = NULL;
fs->folder[x].file[fs->folder[x].count - 1].audio = NULL;
/*
* If people manually add files, they probably know the contents of
@@ -1209,9 +1211,12 @@ gp_filesystem_get_file (CameraFilesystem *fs, const char *folder,
}
CHECK_RESULT (gp_file_new (&tmp));
gp_file_set_name (tmp, filename);
gp_file_set_type (tmp, type);
result = fs->get_file_func (fs, folder, filename, type, tmp,
fs->file_data);
if (result != GP_OK) {
gp_log (GP_LOG_DEBUG, "gphoto2-fs", "Failed to get file.");
gp_file_unref (tmp);
return (result);
}