libgphoto2  2.5.27
About: libgphoto2 is a library that can be used by applications to access various digital cameras.
  Fossies Dox: libgphoto2-2.5.27.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

library.c File Reference
#include "config.h"
#include "library.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <gphoto2/gphoto2-port-log.h>
#include "sierra.h"
#include "sierra-usbwrap.h"
Include dependency graph for library.c:

Go to the source code of this file.

Macros

#define _DARWIN_C_SOURCE
 
#define GP_MODULE   "sierra"
 
#define textdomain(String)   (String)
 
#define gettext(String)   (String)
 
#define dgettext(Domain, Message)   (Message)
 
#define dcgettext(Domain, Message, Type)   (Message)
 
#define bindtextdomain(Domain, Directory)   (Domain)
 
#define _(String)   (String)
 
#define N_(String)   (String)
 
#define SIERRA_PACKET_SIZE   32774
 
#define SUBSIERRA_PACKET_COMMAND_FIRST   0x53
 
#define SUBSIERRA_PACKET_COMMAND   0x43
 
#define MAX_DATA_FIELD_LENGTH   2048
 
#define RETRIES   10
 
#define QUICKSLEEP   5
 

Typedefs

typedef enum _SierraPacket SierraPacket
 

Enumerations

enum  _SierraPacket {
  NUL = 0x00 , SIERRA_PACKET_DATA = 0x02 , SIERRA_PACKET_DATA_END = 0x03 , SIERRA_PACKET_ENQ = 0x05 ,
  ACK = 0x06 , SIERRA_PACKET_INVALID = 0x11 , SIERRA_PACKET_NAK = 0x15 , SIERRA_PACKET_COMMAND = 0x1b ,
  SIERRA_PACKET_WRONG_SPEED = 0x8c , SIERRA_PACKET_SESSION_ERROR = 0xfc , SIERRA_PACKET_SESSION_END = 0xff
}
 

Functions

int sierra_change_folder (Camera *camera, const char *folder, GPContext *context)
 
int sierra_list_files (Camera *camera, const char *folder, CameraList *list, GPContext *context)
 
int sierra_list_folders (Camera *camera, const char *folder, CameraList *list, GPContext *context)
 
int sierra_get_picture_folder (Camera *camera, char **folder)
 
int sierra_check_battery_capacity (Camera *camera, GPContext *context)
 
int sierra_get_memory_left (Camera *camera, int *memory, GPContext *context)
 
static int sierra_check_connection (Camera *camera, GPContext *context)
 
static int sierra_write_packet (Camera *camera, char *packet, GPContext *context)
 
static int sierra_clear_usb_halt (Camera *camera)
 
static int sierra_write_nak (Camera *camera, GPContext *context)
 
static int sierra_read_packet (Camera *camera, unsigned char *packet, GPContext *context)
 
static int sierra_read_packet_wait (Camera *camera, char *buf, GPContext *context)
 
static int sierra_transmit_ack (Camera *camera, char *packet, GPContext *context)
 
static int sierra_build_packet (Camera *camera, char type, char subtype, int data_length, char *packet)
 
static int sierra_write_ack (Camera *camera, GPContext *context)
 
int sierra_init (Camera *camera, GPContext *context)
 
int sierra_set_speed (Camera *camera, SierraSpeed speed, GPContext *context)
 
int sierra_sub_action (Camera *camera, SierraAction action, int sub_action, GPContext *context)
 
static int sierra_action (Camera *camera, SierraAction action, GPContext *context)
 
int sierra_set_int_register (Camera *camera, int reg, int value, GPContext *context)
 
int sierra_get_int_register (Camera *camera, int reg, int *value, GPContext *context)
 
int sierra_set_string_register (Camera *camera, int reg, const char *s, long int length, GPContext *context)
 
int sierra_get_string_register (Camera *camera, int reg, int fnumber, CameraFile *file, unsigned char *b, unsigned int *b_len, GPContext *context)
 
int sierra_delete_all (Camera *camera, GPContext *context)
 
int sierra_delete (Camera *camera, int picture_number, GPContext *context)
 
int sierra_end_session (Camera *camera, GPContext *context)
 
int sierra_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
 
int sierra_capture (Camera *camera, CameraCaptureType type, CameraFilePath *filepath, GPContext *context)
 
int sierra_upload_file (Camera *camera, CameraFile *file, GPContext *context)
 
static unsigned int get_int (const unsigned char b[])
 
int sierra_get_pic_info (Camera *camera, unsigned int n, SierraPicInfo *pic_info, GPContext *context)
 
int sierra_set_locked (Camera *camera, unsigned int n, SierraLocked locked, GPContext *context)
 
int sierra_get_size (Camera *camera, int reg, unsigned int n, int *value, GPContext *context)
 

Variables

struct {
   SierraSpeed   speed
 
   int   bit_rate
 
SierraSpeeds []
 

Macro Definition Documentation

◆ _

#define _ (   String)    (String)

Definition at line 52 of file library.c.

◆ _DARWIN_C_SOURCE

#define _DARWIN_C_SOURCE

Definition at line 20 of file library.c.

◆ bindtextdomain

#define bindtextdomain (   Domain,
  Directory 
)    (Domain)

Definition at line 51 of file library.c.

◆ dcgettext

#define dcgettext (   Domain,
  Message,
  Type 
)    (Message)

Definition at line 50 of file library.c.

◆ dgettext

#define dgettext (   Domain,
  Message 
)    (Message)

Definition at line 49 of file library.c.

◆ gettext

#define gettext (   String)    (String)

Definition at line 48 of file library.c.

◆ GP_MODULE

#define GP_MODULE   "sierra"

Definition at line 35 of file library.c.

◆ MAX_DATA_FIELD_LENGTH

#define MAX_DATA_FIELD_LENGTH   2048

Definition at line 79 of file library.c.

◆ N_

#define N_ (   String)    (String)

Definition at line 53 of file library.c.

◆ QUICKSLEEP

#define QUICKSLEEP   5

Definition at line 83 of file library.c.

◆ RETRIES

#define RETRIES   10

Definition at line 81 of file library.c.

◆ SIERRA_PACKET_SIZE

#define SIERRA_PACKET_SIZE   32774

Definition at line 72 of file library.c.

◆ SUBSIERRA_PACKET_COMMAND

#define SUBSIERRA_PACKET_COMMAND   0x43

Definition at line 76 of file library.c.

◆ SUBSIERRA_PACKET_COMMAND_FIRST

#define SUBSIERRA_PACKET_COMMAND_FIRST   0x53

Definition at line 75 of file library.c.

◆ textdomain

#define textdomain (   String)    (String)

Definition at line 47 of file library.c.

Typedef Documentation

◆ SierraPacket

Definition at line 1 of file library.c.

Enumeration Type Documentation

◆ _SierraPacket

Enumerator
NUL 
SIERRA_PACKET_DATA 
SIERRA_PACKET_DATA_END 
SIERRA_PACKET_ENQ 
ACK 
SIERRA_PACKET_INVALID 
SIERRA_PACKET_NAK 
SIERRA_PACKET_COMMAND 
SIERRA_PACKET_WRONG_SPEED 
SIERRA_PACKET_SESSION_ERROR 
SIERRA_PACKET_SESSION_END 

Definition at line 56 of file library.c.

Function Documentation

◆ get_int()

static unsigned int get_int ( const unsigned char  b[])
static

Definition at line 1463 of file library.c.

Referenced by sierra_get_pic_info().

◆ sierra_action()

static int sierra_action ( Camera camera,
SierraAction  action,
GPContext context 
)
static

Definition at line 1038 of file library.c.

References sierra_sub_action().

Referenced by sierra_capture(), sierra_capture_preview(), sierra_delete(), sierra_delete_all(), sierra_end_session(), and sierra_upload_file().

Here is the call graph for this function:

◆ sierra_build_packet()

static int sierra_build_packet ( Camera camera,
char  type,
char  subtype,
int  data_length,
char *  packet 
)
static

◆ sierra_capture()

int sierra_capture ( Camera camera,
CameraCaptureType  type,
CameraFilePath filepath,
GPContext context 
)

◆ sierra_capture_preview()

int sierra_capture_preview ( Camera camera,
CameraFile file,
GPContext context 
)

Definition at line 1344 of file library.c.

References CHECK, gp_file_set_mime_type(), GP_MIME_JPEG, GP_OK, sierra_action(), SIERRA_ACTION_PREVIEW, sierra_get_int_register(), sierra_get_string_register(), and size.

Referenced by camera_capture_preview().

Here is the call graph for this function:

◆ sierra_change_folder()

int sierra_change_folder ( Camera camera,
const char *  folder,
GPContext context 
)

Definition at line 85 of file library.c.

References CHECK, _CameraPrivateLibrary::folder, _CameraPrivateLibrary::folders, GP_OK, _Camera::pl, and sierra_set_string_register().

Referenced by delete_all_func(), delete_file_func(), get_file_func(), get_info_func(), set_info_func(), sierra_list_files(), and sierra_list_folders().

Here is the call graph for this function:

◆ sierra_check_battery_capacity()

int sierra_check_battery_capacity ( Camera camera,
GPContext context 
)

sierra_check_battery_capacity: @camera : camera data structure

Check if the battery capacity is high enough.

Returns: a gphoto2 error code

Definition at line 296 of file library.c.

References _, gp_context_error(), GP_ERROR, GP_OK, and sierra_get_int_register().

Referenced by put_file_func().

Here is the call graph for this function:

◆ sierra_check_connection()

static int sierra_check_connection ( Camera camera,
GPContext context 
)
static

Definition at line 345 of file library.c.

References _, CHECK, gp_context_error(), GP_ERROR, GP_ERROR_IO_READ, GP_ERROR_TIMEOUT, GP_OK, gp_port_get_timeout(), gp_port_read(), GP_PORT_SERIAL, gp_port_set_timeout(), _Camera::port, sierra_init(), SIERRA_PACKET_SESSION_END, sierra_set_speed(), SIERRA_SPEED_19200, and _GPPort::type.

Referenced by sierra_write_packet().

Here is the call graph for this function:

◆ sierra_clear_usb_halt()

static int sierra_clear_usb_halt ( Camera camera)
static

Definition at line 470 of file library.c.

References _CameraPrivateLibrary::flags, GP_OK, GP_PORT_USB, gp_port_usb_clear_halt(), GP_PORT_USB_ENDPOINT_IN, _Camera::pl, _Camera::port, SIERRA_NO_USB_CLEAR, SIERRA_WRAP_USB_MASK, and _GPPort::type.

Referenced by sierra_read_packet(), sierra_write_ack(), and sierra_write_nak().

Here is the call graph for this function:

◆ sierra_delete()

int sierra_delete ( Camera camera,
int  picture_number,
GPContext context 
)

Definition at line 1326 of file library.c.

References CHECK, GP_OK, sierra_action(), SIERRA_ACTION_DELETE, and sierra_set_int_register().

Referenced by delete_file_func().

Here is the call graph for this function:

◆ sierra_delete_all()

int sierra_delete_all ( Camera camera,
GPContext context 
)

Definition at line 1318 of file library.c.

References CHECK, GP_OK, sierra_action(), and SIERRA_ACTION_DELETE_ALL.

Referenced by delete_all_func().

Here is the call graph for this function:

◆ sierra_end_session()

int sierra_end_session ( Camera camera,
GPContext context 
)

Definition at line 1336 of file library.c.

References CHECK, GP_OK, sierra_action(), and SIERRA_ACTION_END.

Here is the call graph for this function:

◆ sierra_get_int_register()

◆ sierra_get_memory_left()

int sierra_get_memory_left ( Camera camera,
int *  memory,
GPContext context 
)

sierra_get_memory_left: @camera : camera data structure @memory : memory left

Provide the available memory left

Returns: a gphoto2 error code

Definition at line 330 of file library.c.

References _, gp_context_error(), GP_OK, and sierra_get_int_register().

Referenced by put_file_func().

Here is the call graph for this function:

◆ sierra_get_pic_info()

int sierra_get_pic_info ( Camera camera,
unsigned int  n,
SierraPicInfo pic_info,
GPContext context 
)

◆ sierra_get_picture_folder()

int sierra_get_picture_folder ( Camera camera,
char **  folder 
)

sierra_get_picture_folder: @camera : camera data structure @folder : folder name (to be freed by the caller)

Return the name of the folder that stores pictures. It is assumed that the camera conforms with the JEIDA standard. Thus, look for the picture folder into the /DCIM directory.

Returns: a gphoto2 error code

Definition at line 245 of file library.c.

References CHECK, _CameraPrivateLibrary::folders, _Camera::fs, GP_ERROR_DIRECTORY_NOT_FOUND, gp_filesystem_list_folders(), gp_list_count(), gp_list_free(), gp_list_get_name(), gp_list_new(), GP_OK, name, and _Camera::pl.

Referenced by put_file_func().

Here is the call graph for this function:

◆ sierra_get_size()

int sierra_get_size ( Camera camera,
int  reg,
unsigned int  n,
int *  value,
GPContext context 
)

Definition at line 1558 of file library.c.

References CHECK, GP_OK, sierra_get_int_register(), and sierra_set_int_register().

Referenced by get_file_func(), and sierra_get_pic_info().

Here is the call graph for this function:

◆ sierra_get_string_register()

int sierra_get_string_register ( Camera camera,
int  reg,
int  fnumber,
CameraFile file,
unsigned char *  b,
unsigned int *  b_len,
GPContext context 
)

◆ sierra_init()

int sierra_init ( Camera camera,
GPContext context 
)

◆ sierra_list_files()

int sierra_list_files ( Camera camera,
const char *  folder,
CameraList list,
GPContext context 
)

Definition at line 133 of file library.c.

References _, CHECK, count, _CameraPrivateLibrary::flags, gp_context_error(), GP_ERROR_NOT_SUPPORTED, gp_list_append(), gp_list_populate(), GP_OK, _Camera::pl, sierra_change_folder(), sierra_get_int_register(), sierra_get_string_register(), and SIERRA_NO_51.

Referenced by file_list_func().

Here is the call graph for this function:

◆ sierra_list_folders()

int sierra_list_folders ( Camera camera,
const char *  folder,
CameraList list,
GPContext context 
)

Definition at line 201 of file library.c.

References CHECK, count, _CameraPrivateLibrary::folders, gp_list_append(), GP_OK, _Camera::pl, sierra_change_folder(), sierra_get_int_register(), sierra_get_string_register(), and sierra_set_int_register().

Referenced by folder_list_func().

Here is the call graph for this function:

◆ sierra_read_packet()

static int sierra_read_packet ( Camera camera,
unsigned char *  packet,
GPContext context 
)
static

sierra_read_packet: @camera : camera data structure @packet : to return the read packet

Read a data packet from the camera.

Method: Two kinds of packet may be received from the camera :

  • either single byte length packet,
  • or several byte length packet.

Structure of the several byte length packet is the following : Offset Length Meaning 0 1 Packet type 1 1 Packet subtype/sequence 2 2 Length of data 4 variable Data -2 2 Checksum

The operation is successful when the packet is recognised and is completely retrieved without IO errors.

Returns: error code

  • GP_OK if the operation is successful (see description),
  • GP_ERROR_UNKNOWN_PORT if no port was specified within the camera data structure,
  • GP_ERROR_CORRUPTED_DATA if the received data are invalid,
  • GP_ERROR_IO_* on other IO error.

Definition at line 525 of file library.c.

References _, ACK, _CameraPrivateLibrary::flags, gp_context_error(), GP_ERROR_CORRUPTED_DATA, GP_ERROR_IO, GP_ERROR_IO_READ, GP_ERROR_TIMEOUT, GP_ERROR_UNKNOWN_PORT, GP_OK, gp_port_read(), GP_PORT_SERIAL, GP_PORT_USB, GP_PORT_USB_SCSI, gp_result_as_string(), NUL, _Camera::pl, _Camera::port, result, RETRIES, sierra_clear_usb_halt(), SIERRA_PACKET_COMMAND, SIERRA_PACKET_DATA, SIERRA_PACKET_DATA_END, SIERRA_PACKET_ENQ, SIERRA_PACKET_INVALID, SIERRA_PACKET_NAK, SIERRA_PACKET_SESSION_END, SIERRA_PACKET_SESSION_ERROR, SIERRA_PACKET_SIZE, SIERRA_PACKET_WRONG_SPEED, SIERRA_WRAP_USB_MASK, sierra_write_nak(), _GPPort::type, and usb_wrap_read_packet().

Referenced by sierra_get_string_register(), sierra_init(), and sierra_read_packet_wait().

Here is the call graph for this function:

◆ sierra_read_packet_wait()

static int sierra_read_packet_wait ( Camera camera,
char *  buf,
GPContext context 
)
static

Definition at line 731 of file library.c.

References _, CHECK, gp_context_cancel(), gp_context_error(), GP_CONTEXT_FEEDBACK_CANCEL, GP_ERROR, GP_ERROR_CANCEL, GP_ERROR_TIMEOUT, GP_OK, QUICKSLEEP, result, and sierra_read_packet().

Referenced by sierra_get_int_register(), sierra_sub_action(), and sierra_transmit_ack().

Here is the call graph for this function:

◆ sierra_set_int_register()

int sierra_set_int_register ( Camera camera,
int  reg,
int  value,
GPContext context 
)

Definition at line 1044 of file library.c.

References CHECK, GP_OK, sierra_build_packet(), SIERRA_PACKET_COMMAND, and sierra_transmit_ack().

Referenced by cam_desc_set_register(), camera_init(), camera_set_config_epson(), camera_set_config_olympus(), sierra_delete(), sierra_get_size(), sierra_get_string_register(), sierra_list_folders(), sierra_set_locked(), sierra_set_speed(), and sierra_upload_file().

Here is the call graph for this function:

◆ sierra_set_locked()

int sierra_set_locked ( Camera camera,
unsigned int  n,
SierraLocked  locked,
GPContext context 
)

Definition at line 1549 of file library.c.

References CHECK, GP_OK, SIERRA_ACTION_PROT_STATE, sierra_set_int_register(), and sierra_sub_action().

Referenced by set_info_func().

Here is the call graph for this function:

◆ sierra_set_speed()

int sierra_set_speed ( Camera camera,
SierraSpeed  speed,
GPContext context 
)

◆ sierra_set_string_register()

int sierra_set_string_register ( Camera camera,
int  reg,
const char *  s,
long int  length,
GPContext context 
)

Definition at line 1147 of file library.c.

References _, CHECK, gp_context_progress_start(), gp_context_progress_stop(), gp_context_progress_update(), GP_OK, MAX_DATA_FIELD_LENGTH, sierra_build_packet(), SIERRA_PACKET_COMMAND, SIERRA_PACKET_DATA, SIERRA_PACKET_DATA_END, sierra_transmit_ack(), and size.

Referenced by cam_desc_set_register(), camera_init(), sierra_change_folder(), and sierra_upload_file().

Here is the call graph for this function:

◆ sierra_sub_action()

int sierra_sub_action ( Camera camera,
SierraAction  action,
int  sub_action,
GPContext context 
)

Definition at line 1008 of file library.c.

References _, ACK, CHECK, gp_context_error(), GP_ERROR, GP_OK, sierra_build_packet(), SIERRA_PACKET_COMMAND, SIERRA_PACKET_ENQ, SIERRA_PACKET_SIZE, sierra_read_packet_wait(), and sierra_transmit_ack().

Referenced by cam_desc_set_register(), sierra_action(), and sierra_set_locked().

Here is the call graph for this function:

◆ sierra_transmit_ack()

static int sierra_transmit_ack ( Camera camera,
char *  packet,
GPContext context 
)
static

◆ sierra_upload_file()

int sierra_upload_file ( Camera camera,
CameraFile file,
GPContext context 
)

Definition at line 1443 of file library.c.

References CHECK, data, gp_file_get_data_and_size(), GP_OK, sierra_action(), SIERRA_ACTION_UPLOAD, sierra_set_int_register(), and sierra_set_string_register().

Referenced by put_file_func().

Here is the call graph for this function:

◆ sierra_write_ack()

static int sierra_write_ack ( Camera camera,
GPContext context 
)
static

Definition at line 859 of file library.c.

References ACK, CHECK, GP_OK, sierra_clear_usb_halt(), and sierra_write_packet().

Referenced by sierra_get_int_register(), and sierra_get_string_register().

Here is the call graph for this function:

◆ sierra_write_nak()

static int sierra_write_nak ( Camera camera,
GPContext context 
)
static

Definition at line 481 of file library.c.

References sierra_clear_usb_halt(), SIERRA_PACKET_NAK, and sierra_write_packet().

Referenced by sierra_get_int_register(), sierra_get_string_register(), and sierra_read_packet().

Here is the call graph for this function:

◆ sierra_write_packet()

static int sierra_write_packet ( Camera camera,
char *  packet,
GPContext context 
)
static

Variable Documentation

◆ bit_rate

int bit_rate

Definition at line 943 of file library.c.

◆ 

struct { ... } SierraSpeeds[]
Initial value:
= {
{SIERRA_SPEED_19200 , 19200},
{SIERRA_SPEED_38400 , 38400},
{SIERRA_SPEED_57600 , 57600},
{0, 0}
}
@ SIERRA_SPEED_38400
Definition: library.h:103
@ SIERRA_SPEED_19200
Definition: library.h:102
@ SIERRA_SPEED_115200
Definition: library.h:105
@ SIERRA_SPEED_9600
Definition: library.h:101
@ SIERRA_SPEED_57600
Definition: library.h:104

Referenced by sierra_set_speed().

◆ speed

SierraSpeed speed

Definition at line 942 of file library.c.