int tiger_get_mem(CameraPrivateLibrary *dev, int *num_pics, int *mem_total, int *mem_free) { int result=0; int temp_result; *num_pics=soundvision_photos_taken(dev); if (*num_pics<0) goto get_mem_error; result=soundvision_get_revision(dev,NULL); if (result<0) goto get_mem_error; result=soundvision_send_command(SOUNDVISION_GET_MEM_TOTAL,0,dev); if (result<0) goto get_mem_error; result=soundvision_read(dev, &temp_result, sizeof(temp_result)); if (result<0) goto get_mem_error; *mem_total=le32toh(temp_result); result=soundvision_send_command(SOUNDVISION_GET_MEM_FREE,0,dev); if (result<0) goto get_mem_error; result=soundvision_read(dev, &temp_result, sizeof(temp_result)); if (result<0) goto get_mem_error; *mem_free=le32toh(temp_result); return GP_OK; get_mem_error: GP_DEBUG("Error in tiger_get_mem"); return result; }
/* Yet uploaded file never appears. Why?? */ int tiger_upload_file(CameraPrivateLibrary *dev, const char *filename, const char *data, long size) { int result=0; char return_value[4]; uint32_t our_size; char *our_data=NULL; /* When we upload, the first 3 bytes are little-endian */ /* File-size followed by the actual file */ our_size=size+4; our_data=calloc(our_size,sizeof(char)); if (our_data==NULL) { goto upload_error; } htole32a(&our_data[0],size); memcpy(our_data+4,data,size); GP_DEBUG("File: %s Size=%ld\n",filename,size); /* for(result=0;result<our_size;result++) { printf("%x ",our_data[result]); } */ result=tiger_set_pc_mode(dev); if (result<0) goto upload_error; result=soundvision_get_revision(dev,NULL); if (result<0) goto upload_error; result=soundvision_send_command(SOUNDVISION_GET_MEM_FREE,0,dev); if (result<0) goto upload_error; result=soundvision_read(dev, &return_value, sizeof(return_value)); if (result<0) goto upload_error; result=soundvision_send_command(SOUNDVISION_PUT_FILE,size,dev); if (result<0) goto upload_error; result=soundvision_read(dev, &return_value, sizeof(return_value)); if (result<0) goto upload_error; result=gp_port_write(dev->gpdev,our_data,our_size); if (result<0) goto upload_error; free(our_data); our_data=NULL; #if 0 /* Some traces show the following, though most likely */ /* this is just the windows driver updating the file list */ result=soundvision_photos_taken(dev); result=soundvision_get_file_list(dev); result=soundvision_send_command(SOUNDVISION_GET_PIC_SIZE,0,dev); if (result<0) goto upload_error; result=soundvision_read(dev, &return_value, sizeof(return_value)); if (result<0) goto upload_error; result=soundvision_send_file_command("000VINCE.JPG",dev); result=soundvision_read(dev, &return_value, sizeof(return_value)); if (result<0) goto upload_error; result=soundvision_send_command(SOUNDVISION_DONE_TRANSACTION,0,dev); if (result<0) goto upload_error; #endif return GP_OK; upload_error: if (our_data!=NULL) free(our_data); GP_DEBUG("Error in tiger_upload_file"); return result; }
int tiger_get_file_list(CameraPrivateLibrary *dev) { char *buffer=NULL; int32_t ret, taken, buflen,i; ret=tiger_set_pc_mode(dev); if (ret<0) goto list_files_error; if ( (taken=soundvision_photos_taken(dev)) < 0) { ret=taken; goto list_files_error; } dev->num_pictures = taken; if (taken>0) { buflen = (taken * 13)+1; /* 12 char filenames and space for each */ /* plus trailing NULL */ buffer = malloc(buflen); if (!buffer) { GP_DEBUG("Could not allocate %i bytes!",buflen); ret=GP_ERROR_NO_MEMORY; goto list_files_error; } ret=soundvision_send_command(SOUNDVISION_GET_NAMES, buflen, dev); if (ret < 0) { goto list_files_error; } ret = soundvision_read(dev, (void *)buffer, buflen); if (ret < 0) { goto list_files_error; } if (dev->file_list) free(dev->file_list); dev->file_list = malloc(taken * 13); if (!dev->file_list) { GP_DEBUG("Could not allocate %i bytes!",taken*13); ret=GP_ERROR_NO_MEMORY; goto list_files_error; } for(i=0;i<taken*13;i++) if (buffer[i]==' ') buffer[i]='\0'; memcpy(dev->file_list, buffer, taken * 13); free(buffer); buffer=NULL; } ret=soundvision_send_command(SOUNDVISION_DONE_TRANSACTION, 0, dev); if (ret<0) goto list_files_error; /* If we have >1 pics we should stat a file?*/ /* Some traces do, some don't... */ /* if (taken>0) soundvision_get_pic_size(dev,dev->file_list); */ return GP_OK; list_files_error: if (buffer!=NULL) free(buffer); return ret; }
static int soundvision_file_get (Camera *camera, const char *filename, int thumbnail, unsigned char **data, int *size) { int buflen,throwaway,result; if (thumbnail) GP_DEBUG( "Getting thumbnail '%s'...",filename); else GP_DEBUG( "Getting file '%s'...",filename); if (camera->pl->device_type==SOUNDVISION_TIGERFASTFLICKS) { result=tiger_set_pc_mode(camera->pl); if (thumbnail) buflen=soundvision_get_thumb_size(camera->pl,filename); else buflen=soundvision_get_pic_size(camera->pl,filename); if (buflen < 0) return buflen; } else { soundvision_reset(camera->pl,NULL,NULL); /* Always have to check num photos, * then pic size no matter what. Otherwise * the camera will stop responding */ throwaway=soundvision_photos_taken(camera->pl); if (throwaway<0) { result=throwaway; goto file_get_error; } /* The below two lines might look wrong, but they aren't! */ buflen = soundvision_get_pic_size(camera->pl,filename); if (thumbnail) buflen=soundvision_get_thumb_size(camera->pl,filename); } /* Don't try to download if size equals zero! */ if (buflen) { *data = malloc(buflen+1); if (!*data) { result=GP_ERROR_NO_MEMORY; goto file_get_error; } memset(*data, 0, buflen); if (thumbnail) { result=soundvision_get_thumb(camera->pl, filename, *data, buflen); if (result < 0) { GP_DEBUG("soundvision_get_thumb_failed!"); goto file_get_error; } } else { result=soundvision_get_pic(camera->pl, filename, *data, buflen); if (result < 0) { GP_DEBUG("soundvision_get_pic_failed!"); goto file_get_error; } } if (size) *size = buflen; } return GP_OK; file_get_error: if (*data!=NULL) free(*data); return result; }