1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
/*
* agfa_cl18.c
*
* Command set specific to agfa-ephoto-CL18
*
* Copyright 2001-2002 Vince Weaver <vince@deater.net>
*/
#include "config.h"
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#ifdef OS2
#include <db.h>
#endif
#include <unistd.h>
#include <gphoto2/gphoto2.h>
#include "gphoto2-endian.h"
#include "soundvision.h"
#include "commands.h"
#define GP_MODULE "soundvision"
/* Below contributed by Ben Hague <benhague@btinternet.com> */
int agfa_capture(CameraPrivateLibrary *dev, CameraFilePath *path) {
/*FIXME: Not fully implemented according to the gphoto2 spec.*/
/*Should also save taken picture, and then delete it from the camera*/
/*but when I try to do that it just hangs*/
int ret;
ret=soundvision_send_command(SOUNDVISION_SETPC1,0,dev);
if (ret < 0) return ret;
ret=soundvision_send_command(SOUNDVISION_SETPC2,0,dev);
if (ret < 0) return ret;
ret=soundvision_send_command(SOUNDVISION_TAKEPIC3,0,dev);
if (ret < 0) return ret;
ret=soundvision_send_command(SOUNDVISION_SETPC2,0,dev);
if (ret < 0) return ret;
/*Not sure if this delay is necessary, but it was used in the windows driver*/
/*delay(20); */
sleep(20);
/*Again, three times in windows driver*/
soundvision_photos_taken(dev);
soundvision_photos_taken(dev);
soundvision_photos_taken(dev);
/*This seems to do some kind of reset, but does cause the camera to start responding again*/
ret=soundvision_send_command(SOUNDVISION_GET_NAMES, 0, dev);
if (ret < 0) return ret;
return GP_OK;
}
/* Seems to work OK though sometimes camera is left in */
/* unknown state after completing */
/* thanks to heathhey3@hotmail.com for sending me the trace */
/* to implement this */
int agfa_delete_picture(CameraPrivateLibrary *dev, const char *filename) {
int32_t ret,temp,taken;
uint8_t data[4],*buffer;
uint32_t size=4,buflen;
/* yes, we do this twice?? */
taken=soundvision_photos_taken(dev);
taken=soundvision_photos_taken(dev);
ret = soundvision_send_command(SOUNDVISION_GET_PIC_SIZE,0,dev);
if (ret<0) return ret;
/* always returns ff 0f 00 00 ??? */
ret = soundvision_read(dev, &temp, sizeof(temp));
if (ret<0) return ret;
/* Some traces show sending other than the file we want deleted? */
ret=soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, data, size);
if (ret<0) return ret;
/* Check num taken AGAIN */
taken=soundvision_photos_taken(dev);
ret = soundvision_send_command(SOUNDVISION_GET_PIC_SIZE,0,dev);
if (ret<0) return ret;
/* always returns ff 0f 00 00 ??? */
ret = soundvision_read(dev, &temp, sizeof(temp));
if (ret<0) return ret;
ret=soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, data, size);
if (ret<0) return ret;
/* Check num taken AGAIN */
taken=soundvision_photos_taken(dev);
ret=soundvision_send_command(SOUNDVISION_DELETE,0,dev);
if (ret<0) return ret;
/* read ff 0f ??? */
ret = soundvision_read(dev, data, size);
if (ret<0) return ret;
ret = soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
/* This is the point we notices that in fact a pic is missing */
/* Why do it 4 times??? Timing?? Who knows */
taken=soundvision_photos_taken(dev);
taken=soundvision_photos_taken(dev);
taken=soundvision_photos_taken(dev);
taken=soundvision_photos_taken(dev);
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);
return (GP_ERROR_NO_MEMORY);
}
ret=soundvision_send_command(SOUNDVISION_GET_NAMES, buflen,dev);
if (ret < 0) {
free(buffer);
return ret;
}
ret = soundvision_read(dev, (void *)buffer, buflen);
if (ret < 0) {
free(buffer);
return ret;
}
if (dev->file_list) free(dev->file_list);
dev->file_list = (char *)buffer;
ret=soundvision_send_command(SOUNDVISION_GET_PIC_SIZE,0,dev);
if (ret<0) return ret;
/* always returns ff 0f 00 00 ??? */
ret = soundvision_read(dev, &temp, sizeof(temp));
if (ret<0) return ret;
ret=soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, data, size);
if (ret<0) return ret;
return GP_OK;
}
int agfa_get_file_list(CameraPrivateLibrary *dev) {
char *buffer;
int32_t ret, taken, buflen,i;
/* It seems we need to do a "reset" packet before reading names?? */
soundvision_reset(dev,NULL,NULL);
if ( (taken=soundvision_photos_taken(dev)) < 0)
return taken;
dev->num_pictures = taken;
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);
return GP_ERROR_NO_MEMORY;
}
ret=soundvision_send_command(SOUNDVISION_GET_NAMES, buflen, dev);
if (ret < 0) {
free(buffer);
return ret;
}
ret = soundvision_read(dev, (void *)buffer, buflen);
if (ret < 0) {
free(buffer);
return ret;
}
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);
free(buffer);
return (GP_ERROR_NO_MEMORY);
}
for(i=0;i<taken*13;i++) if (buffer[i]==' ') buffer[i]='\0';
memcpy(dev->file_list, buffer, taken * 13);
free(buffer);
#if 0
taken=soundvision_photos_taken(dev);
soundvision_get_thumb_size(dev,dev->file_list);
#endif
return GP_OK;
}
int agfa_get_pic(CameraPrivateLibrary *dev, const char *filename,
unsigned char *data,int size) {
int32_t ret,temp;
ret = soundvision_send_command(SOUNDVISION_GET_PIC,0,dev);
if (ret<0) return ret;
/* always returns ff 0f 00 00 ??? */
ret = soundvision_read(dev, &temp, sizeof(temp));
if (ret<0) return ret;
ret=soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, data, size);
if (ret<0) return ret;
#if 0
/* Have to do this after getting pic ? */
ret=soundvision_send_command(SOUNDVISION_DONE_PIC,0,dev);
if (ret<0) return ret;
#endif
return GP_OK;
}
int agfa_get_pic_size(CameraPrivateLibrary *dev, const char *filename) {
int32_t ret,temp;
uint32_t size;
ret=soundvision_send_command(SOUNDVISION_GET_PIC_SIZE,0,dev);
if (ret<0) return ret;
/* always returns ff 0f 00 00 ??? */
ret = soundvision_read(dev, &temp, sizeof(temp));
if (ret<0) return ret;
ret=soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, &size, sizeof(size));
if (ret<0) return ret;
return le32toh(size);
}
int agfa_get_thumb_size(CameraPrivateLibrary *dev, const char *filename) {
int32_t ret,temp;
uint32_t size;
ret=soundvision_send_command(SOUNDVISION_GET_THUMB_SIZE,0,dev);
if (ret<0) return ret;
/* always returns ff 0f 00 00 ??? */
ret = soundvision_read(dev, &temp, sizeof(temp));
if (ret<0) return ret;
ret = soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, &size, sizeof(size));
if (ret<0) return ret;
return le32toh(size);
}
int agfa_get_thumb(CameraPrivateLibrary *dev, const char *filename,
unsigned char *data,int size) {
int32_t ret,temp;
ret = soundvision_send_command(SOUNDVISION_GET_THUMB,0,dev);
if (ret<0) return ret;
/* always returns ff 0f 00 00 ??? */
ret = soundvision_read(dev, &temp, sizeof(temp));
if (ret<0) return ret;
ret=soundvision_send_file_command(filename,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, data, size);
if (ret<0) return ret;
#if 0
/* Is this needed? */
soundvision_photos_taken(dev,&ret);
ret=soundvision_send_command(SOUNDVISION_END_OF_THUMB,0,dev);
if (ret<0) return ret;
ret = soundvision_read(dev, temp_string, 8);
if (ret<0) return ret;
#endif
return GP_OK;
}
|