1 | /** \file |
2 | * |
3 | * \author Copyright 2001 Lutz Mueller <lutz@users.sf.net> |
4 | * |
5 | * \par License |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * \par |
12 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Lesser General Public License for more details. |
16 | * |
17 | * \par |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the |
20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | * Boston, MA 02110-1301 USA |
22 | */ |
23 | |
24 | #ifndef __GPHOTO2_PORT_H__ |
25 | #define __GPHOTO2_PORT_H__ |
26 | |
27 | #include <gphoto2/gphoto2-port-info-list.h> |
28 | |
29 | /* For portability */ |
30 | #include <gphoto2/gphoto2-port-portability.h> |
31 | #ifdef OS2 |
32 | #include <gphoto2/gphoto2-port-portability-os2.h> |
33 | #include <os2.h> |
34 | #endif |
35 | |
36 | #ifdef __cplusplus |
37 | extern "C" { |
38 | #endif /* __cplusplus */ |
39 | |
40 | #ifndef TRUE |
41 | #define TRUE (0==0) |
42 | #endif |
43 | |
44 | #ifndef FALSE |
45 | #define FALSE (1==0) |
46 | #endif |
47 | |
48 | /** |
49 | * \brief Serial parity |
50 | * |
51 | * Parity of the serial port. |
52 | */ |
53 | typedef enum _GPPortSerialParity |
54 | { |
55 | GP_PORT_SERIAL_PARITY_OFF = 0, /**< \brief Parity is off (disabled) */ |
56 | GP_PORT_SERIAL_PARITY_EVEN, /**< \brief Parity is even. */ |
57 | GP_PORT_SERIAL_PARITY_ODD /**< \brief Parity is odd. */ |
58 | } GPPortSerialParity; |
59 | |
60 | /** \brief Maximum length of receive buffer */ |
61 | #define GP_PORT_MAX_BUF_LEN 4096 |
62 | |
63 | /** |
64 | * \brief Port settings for serial ports. |
65 | */ |
66 | typedef struct _GPPortSettingsSerial { |
67 | char port[128]; /**< The portname (/dev/ttyX)*/ |
68 | int speed; /**< The baudrate of the device. */ |
69 | int bits; /**< How many bits data. */ |
70 | GPPortSerialParity parity; /**< parity data, see GP_PORT_SERIAL_PARITY_ |
71 | defines */ |
72 | int stopbits; /**< How many stop bits are used. */ |
73 | } GPPortSettingsSerial; |
74 | |
75 | /** |
76 | * \brief Port settings for USB ports. |
77 | */ |
78 | typedef struct _GPPortSettingsUSB { |
79 | int inep; /**< \brief Bulk IN endpoint used. */ |
80 | int outep; /**< \brief Bulk OUT endpoint used. */ |
81 | int intep; /**< \brief Interrupt endpoint used. */ |
82 | int config; /**< \brief USB bConfigurationValue used. */ |
83 | int interface; /**< \brief USB Interface number used. */ |
84 | int altsetting; /**< \brief USB Alternative Setting used. */ |
85 | |
86 | int maxpacketsize; /**< \brief Maximum USB packetsize of the IN endpoint. (r/o) */ |
87 | |
88 | /* must be last to avoid binary incompatibility. |
89 | * luckily we just need to make sure this struct does not |
90 | * get larger than _GPPortSettingsSerial. */ |
91 | char port[64]; /**< \brief USB Portname. Specific to lowlevel USB. */ |
92 | } GPPortSettingsUSB; |
93 | |
94 | /** |
95 | * \brief Port settings for USB mass storage direct IO ports. |
96 | */ |
97 | typedef struct _GPPortSettingsUsbDiskDirect { |
98 | char path[128]; /**< /brief The ports device node path (/dev/sdX)*/ |
99 | } GPPortSettingsUsbDiskDirect; |
100 | |
101 | /** |
102 | * \brief Port settings for USB Mass Storage raw SCSI ports. |
103 | */ |
104 | typedef struct _GPPortSettingsUsbScsi { |
105 | char path[128]; /**< /brief The ports device node path (/dev/sg#)*/ |
106 | } GPPortSettingsUsbScsi; |
107 | |
108 | /** |
109 | * \brief Union of port settings. |
110 | * |
111 | * This contains a shared union of possible settings for ports needing |
112 | * them. |
113 | */ |
114 | typedef union _GPPortSettings { |
115 | GPPortSettingsSerial serial; /**< \brief Serial specific settings */ |
116 | GPPortSettingsUSB usb; /**< \brief USB specific settings */ |
117 | GPPortSettingsUsbDiskDirect usbdiskdirect; /**< \brief usb disk direct port specific settings */ |
118 | GPPortSettingsUsbScsi usbscsi; /**< \brief usb scsi port specific settings */ |
119 | } GPPortSettings; |
120 | |
121 | enum { |
122 | GP_PORT_USB_ENDPOINT_IN, /**< \brief USB bulk IN ep */ |
123 | GP_PORT_USB_ENDPOINT_OUT, /**< \brief USB bulk OUT ep */ |
124 | GP_PORT_USB_ENDPOINT_INT /**< \brief USB Interrupt ep */ |
125 | }; |
126 | |
127 | typedef struct _GPPortPrivateLibrary GPPortPrivateLibrary; |
128 | typedef struct _GPPortPrivateCore GPPortPrivateCore; |
129 | |
130 | /** |
131 | * \brief The GPhoto port structure. |
132 | * |
133 | * This structure tracks the physical connection of the device. |
134 | * It can correspond the various methods of lowlevel access, serial |
135 | * usb and others and abstracts them as much as possible. |
136 | * |
137 | * Frontends should consider this structure opaque and only use accessor |
138 | * functions. |
139 | * |
140 | * Camera drivers should only access the type and pl members directly, |
141 | * and use accessor functions for the rest. |
142 | */ |
143 | typedef struct _GPPort { |
144 | /* For your convenience */ |
145 | GPPortType type; /**< \brief Actual type of this port */ |
146 | |
147 | GPPortSettings settings; /**< \brief Current port settings. */ |
148 | GPPortSettings settings_pending;/**< \brief Settings to be committed. */ |
149 | |
150 | int timeout; /**< \brief Port timeout in milliseconds. */ |
151 | |
152 | GPPortPrivateLibrary *pl; /**< \brief Camera driver private data pointer. */ |
153 | GPPortPrivateCore *pc; /**< \brief Port library private data pointer. */ |
154 | } GPPort; |
155 | |
156 | int gp_port_new (GPPort **port); |
157 | int gp_port_free (GPPort *port); |
158 | |
159 | int gp_port_set_info (GPPort *port, GPPortInfo info); |
160 | int gp_port_get_info (GPPort *port, GPPortInfo *info); |
161 | |
162 | int gp_port_open (GPPort *port); |
163 | int gp_port_close (GPPort *port); |
164 | |
165 | int gp_port_reset (GPPort *port); |
166 | |
167 | int gp_port_write (GPPort *port, const char *data, int size); |
168 | int gp_port_read (GPPort *port, char *data, int size); |
169 | int gp_port_check_int (GPPort *port, char *data, int size); |
170 | int gp_port_check_int_fast (GPPort *port, char *data, int size); |
171 | |
172 | int gp_port_get_timeout (GPPort *port, int *timeout); |
173 | int gp_port_set_timeout (GPPort *port, int timeout); |
174 | |
175 | int gp_port_set_settings (GPPort *port, GPPortSettings settings); |
176 | int gp_port_get_settings (GPPort *port, GPPortSettings *settings); |
177 | |
178 | /** |
179 | * \brief Serial pins. |
180 | * |
181 | * A number of serial pins to trigger and pull. This is necessary |
182 | * for some devices that have more than just the regular 3 or 4 wires. |
183 | */ |
184 | typedef enum _GPPin { |
185 | GP_PIN_RTS, /**< \brief RTS line */ |
186 | GP_PIN_DTR, /**< \brief DTR line */ |
187 | GP_PIN_CTS, /**< \brief CTS line */ |
188 | GP_PIN_DSR, /**< \brief DSR line */ |
189 | GP_PIN_CD, /**< \brief Carrier Detect line */ |
190 | GP_PIN_RING /**< \brief RING (Modem) line */ |
191 | } GPPin; |
192 | |
193 | /** |
194 | * \brief Level to pull specific lines. |
195 | * |
196 | * The level on which to pull some of the serial lines. |
197 | */ |
198 | typedef enum _GPLevel { |
199 | GP_LEVEL_LOW = 0, /**< \brief Pull to low (0V) */ |
200 | GP_LEVEL_HIGH = 1 /**< \brief Pull to high (nV) */ |
201 | } GPLevel; |
202 | |
203 | int gp_port_get_pin (GPPort *port, GPPin pin, GPLevel *level); |
204 | int gp_port_set_pin (GPPort *port, GPPin pin, GPLevel level); |
205 | |
206 | int gp_port_send_break (GPPort *port, int duration); |
207 | int gp_port_flush (GPPort *port, int direction); |
208 | |
209 | int gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct); |
210 | int gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol); |
211 | int gp_port_usb_clear_halt (GPPort *port, int ep); |
212 | int gp_port_usb_msg_write (GPPort *port, int request, int value, |
213 | int index, char *bytes, int size); |
214 | int gp_port_usb_msg_read (GPPort *port, int request, int value, |
215 | int index, char *bytes, int size); |
216 | int gp_port_usb_msg_interface_write (GPPort *port, int request, |
217 | int value, int index, char *bytes, int size); |
218 | int gp_port_usb_msg_interface_read (GPPort *port, int request, |
219 | int value, int index, char *bytes, int size); |
220 | int gp_port_usb_msg_class_write (GPPort *port, int request, |
221 | int value, int index, char *bytes, int size); |
222 | int gp_port_usb_msg_class_read (GPPort *port, int request, |
223 | int value, int index, char *bytes, int size); |
224 | |
225 | int gp_port_seek (GPPort *port, int offset, int whence); |
226 | |
227 | int gp_port_send_scsi_cmd (GPPort *port, int to_dev, |
228 | char *cmd, int cmd_size, |
229 | char *sense, int sense_size, |
230 | char *data, int data_size); |
231 | |
232 | /* Error reporting */ |
233 | int gp_port_set_error (GPPort *port, const char *format, ...) |
234 | #ifdef __GNUC__ |
235 | __attribute__((__format__(printf,2,3))) |
236 | #endif |
237 | ; |
238 | const char *gp_port_get_error (GPPort *port); |
239 | |
240 | /* DEPRECATED */ |
241 | /** \deprecated internal typedef */ |
242 | typedef GPPort gp_port; |
243 | /** \deprecated internal typedef */ |
244 | typedef GPPortSettings gp_port_settings; |
245 | /** \deprecated internal define */ |
246 | #define PIN_CTS GP_PIN_CTS |
247 | |
248 | #ifdef __cplusplus |
249 | } |
250 | #endif /* __cplusplus */ |
251 | |
252 | #endif /* __GPHOTO2_PORT_H__ */ |
253 | |