1 /**********************************************************************
2 * Minolta Dimage V digital camera communication library *
3 * Copyright 2000,2001 Gus Hartmann *
4 * *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation; either version 2 of *
8 * the License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
19 * *
20 **********************************************************************/
21
22 /* $Id$ */
23
24 #include "config.h"
25
26 #include "dimagev.h"
27
28 #define GP_MODULE "dimagev"
29
dimagev_delete_picture(dimagev_t * dimagev,int file_number)30 int dimagev_delete_picture(dimagev_t *dimagev, int file_number) {
31 dimagev_packet *p, *raw;
32 unsigned char command_buffer[3];
33 char char_buffer = 0;
34
35 if ( dimagev == NULL ) {
36 GP_DEBUG( "dimagev_delete_picture::unable to use NULL dimagev_t");
37 return GP_ERROR_BAD_PARAMETERS;
38 }
39
40 dimagev_dump_camera_status(dimagev->status);
41 /* An image can only be deleted if the card is normal or full. */
42 if ( dimagev->status->card_status > (unsigned char) 1 ) {
43 GP_DEBUG( "dimagev_delete_picture::memory card does not permit deletion");
44 return GP_ERROR;
45 }
46
47 if ( dimagev->data->host_mode != (unsigned char) 1 ) {
48
49 dimagev->data->host_mode = (unsigned char) 1;
50
51 if ( dimagev_send_data(dimagev) < GP_OK ) {
52 GP_DEBUG( "dimagev_delete_picture::unable to set host mode");
53 return GP_ERROR_IO;
54 }
55 }
56
57
58 /* First make the command packet. */
59 command_buffer[0] = 0x05;
60 command_buffer[1] = (unsigned char)( file_number / 256 );
61 command_buffer[2] = (unsigned char)( file_number % 256 );
62 if ( ( p = dimagev_make_packet(command_buffer, 3, 0) ) == NULL ) {
63 GP_DEBUG( "dimagev_delete_picture::unable to allocate command packet");
64 return GP_ERROR_NO_MEMORY;
65 }
66
67 if ( gp_port_write(dimagev->dev, (char *)p->buffer, p->length) < GP_OK ) {
68 GP_DEBUG( "dimagev_delete_picture::unable to send set_data packet");
69 free(p);
70 return GP_ERROR_IO;
71 } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) < GP_OK ) {
72 GP_DEBUG( "dimagev_delete_picture::no response from camera");
73 free(p);
74 return GP_ERROR_IO;
75 }
76
77 free(p);
78
79 switch ( char_buffer ) {
80 case DIMAGEV_ACK:
81 break;
82 case DIMAGEV_NAK:
83 GP_DEBUG( "dimagev_delete_picture::camera did not acknowledge transmission");
84 return GP_ERROR_IO;
85 case DIMAGEV_CAN:
86 GP_DEBUG( "dimagev_delete_picture::camera cancels transmission");
87 return GP_ERROR_IO;
88 default:
89 GP_DEBUG( "dimagev_delete_picture::camera responded with unknown value %x", char_buffer);
90 return GP_ERROR_IO;
91 }
92
93
94 if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
95 GP_DEBUG( "dimagev_delete_picture::unable to read packet");
96 return GP_ERROR_IO;
97 }
98
99 if ( ( raw = dimagev_strip_packet(p) ) == NULL ) {
100 GP_DEBUG( "dimagev_delete_picture::unable to strip packet");
101 free(p);
102 return GP_ERROR;
103 }
104
105 free(p);
106
107 if ( raw->buffer[0] != (unsigned char) 0 ) {
108 GP_DEBUG( "dimagev_delete_picture::delete returned error code");
109 free(raw);
110 return GP_ERROR_NO_MEMORY;
111 }
112 free(raw);
113
114 char_buffer=DIMAGEV_EOT;
115 if ( gp_port_write(dimagev->dev, &char_buffer, 1) < GP_OK ) {
116 GP_DEBUG( "dimagev_delete_picture::unable to send ACK");
117 return GP_ERROR_IO;
118 }
119
120 if ( gp_port_read(dimagev->dev, &char_buffer, 1) < GP_OK ) {
121 GP_DEBUG( "dimagev_delete_picture::no response from camera");
122 return GP_ERROR_IO;
123 }
124
125 switch ( char_buffer ) {
126 case DIMAGEV_ACK:
127 break;
128 case DIMAGEV_NAK:
129 GP_DEBUG( "dimagev_delete_picture::camera did not acknowledge transmission");
130 return GP_ERROR_IO;
131 case DIMAGEV_CAN:
132 GP_DEBUG( "dimagev_delete_picture::camera cancels transmission");
133 return GP_ERROR_IO;
134 default:
135 GP_DEBUG( "dimagev_delete_picture::camera responded with unknown value %x", char_buffer);
136 return GP_ERROR_IO;
137 }
138
139 return GP_OK;
140 }
141
dimagev_delete_all(dimagev_t * dimagev)142 int dimagev_delete_all(dimagev_t *dimagev) {
143 dimagev_packet *p, *raw;
144 unsigned char command_buffer[3];
145 char char_buffer;
146
147 if ( dimagev == NULL ) {
148 GP_DEBUG( "dimagev_delete_all::unable to use NULL dimagev_t");
149 return GP_ERROR_BAD_PARAMETERS;
150 }
151
152 dimagev_dump_camera_status(dimagev->status);
153 /* An image can only be deleted if the card is normal or full. */
154 if ( dimagev->status->card_status > (unsigned char) 1 ) {
155 GP_DEBUG( "dimagev_delete_all::memory card does not permit deletion");
156 return GP_ERROR;
157 }
158
159 if ( dimagev->data->host_mode != (unsigned char) 1 ) {
160
161 dimagev->data->host_mode = (unsigned char) 1;
162
163 if ( dimagev_send_data(dimagev) < GP_OK ) {
164 GP_DEBUG( "dimagev_delete_all::unable to set host mode");
165 return GP_ERROR_IO;
166 }
167 }
168
169
170 /* First make the command packet. */
171 command_buffer[0] = 0x06;
172 if ( ( p = dimagev_make_packet(command_buffer, 1, 0) ) == NULL ) {
173 GP_DEBUG( "dimagev_delete_all::unable to allocate command packet");
174 return GP_ERROR_IO;
175 }
176
177 if ( gp_port_write(dimagev->dev, (char *)p->buffer, p->length) < GP_OK ) {
178 GP_DEBUG( "dimagev_delete_all::unable to send set_data packet");
179 free(p);
180 return GP_ERROR_IO;
181 } else if ( gp_port_read(dimagev->dev, &char_buffer, 1) < GP_OK ) {
182 GP_DEBUG( "dimagev_delete_all::no response from camera");
183 free(p);
184 return GP_ERROR_IO;
185 }
186
187 free(p);
188
189 switch ( char_buffer ) {
190 case DIMAGEV_ACK:
191 break;
192 case DIMAGEV_NAK:
193 GP_DEBUG( "dimagev_delete_all::camera did not acknowledge transmission");
194 return GP_ERROR_IO;
195 case DIMAGEV_CAN:
196 GP_DEBUG( "dimagev_delete_all::camera cancels transmission");
197 return GP_ERROR_IO;
198 default:
199 GP_DEBUG( "dimagev_delete_all::camera responded with unknown value %x", char_buffer);
200 return GP_ERROR_IO;
201 }
202
203
204 if ( ( p = dimagev_read_packet(dimagev) ) == NULL ) {
205 GP_DEBUG( "dimagev_delete_all::unable to read packet");
206 return GP_ERROR_IO;
207 }
208
209 if ( ( raw = dimagev_strip_packet(p) ) == NULL ) {
210 GP_DEBUG( "dimagev_delete_all::unable to strip packet");
211 free(p);
212 return GP_ERROR_NO_MEMORY;
213 }
214
215 free(p);
216
217 if ( raw->buffer[0] != (unsigned char) 0 ) {
218 GP_DEBUG( "dimagev_delete_all::delete returned error code");
219 free(raw);
220 return GP_ERROR;
221 }
222 free(raw);
223
224 char_buffer=DIMAGEV_EOT;
225 if ( gp_port_write(dimagev->dev, &char_buffer, 1) < GP_OK ) {
226 GP_DEBUG( "dimagev_delete_all::unable to send ACK");
227 return GP_ERROR_IO;
228 }
229
230 if ( gp_port_read(dimagev->dev, &char_buffer, 1) < GP_OK ) {
231 GP_DEBUG( "dimagev_delete_all::no response from camera");
232 return GP_ERROR_IO;
233 }
234
235 switch ( char_buffer ) {
236 case DIMAGEV_ACK:
237 break;
238 case DIMAGEV_NAK:
239 GP_DEBUG( "dimagev_delete_all::camera did not acknowledge transmission");
240 return GP_ERROR_IO;
241 case DIMAGEV_CAN:
242 GP_DEBUG( "dimagev_delete_all::camera cancels transmission");
243 return GP_ERROR_IO;
244 default:
245 GP_DEBUG( "dimagev_delete_all::camera responded with unknown value %x", char_buffer);
246 return GP_ERROR_IO;
247 }
248
249 return GP_OK;
250 }
251