4 * Command set for the digita cameras
6 * Copyright 1999-2001 Johannes Erdfelt
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
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., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
36 #include "gphoto2-endian.h"
38 #define GP_MODULE "digita"
40 #include <gphoto2/gphoto2-port.h>
42 static void build_command(struct digita_command *cmd, int length, short command)
44 memset(cmd, 0, sizeof(*cmd));
46 /* Length is the sizeof the digita_command minus the length */
47 /* parameter, plus whatever other data we send */
48 cmd->length = htonl(sizeof(struct digita_command) -
49 sizeof(unsigned int) + length);
50 cmd->command = htons(command);
53 struct storage_status {
54 struct digita_command cmd;
56 unsigned int takencount;
57 unsigned int availablecount;
61 int digita_get_storage_status(CameraPrivateLibrary *dev, int *taken,
62 int *available, int *rawcount)
64 struct digita_command cmd;
65 struct storage_status ss;
68 build_command(&cmd, 0, DIGITA_GET_STORAGE_STATUS);
70 ret = dev->send(dev, &cmd, sizeof(cmd));
72 GP_DEBUG("digita_get_storage_status: error sending command (ret = %d)", ret);
76 ret = dev->read(dev, (unsigned char *)&ss, sizeof(ss));
78 GP_DEBUG("digita_get_storage_status: error getting count (ret = %d)", ret);
83 *taken = ntohl(ss.takencount);
85 *available = ntohl(ss.availablecount);
87 *rawcount = ntohl(ss.rawcount);
92 int digita_get_file_list(CameraPrivateLibrary *dev)
94 struct digita_command cmd;
95 struct get_file_list gfl;
97 int ret, taken, buflen;
100 if (digita_get_storage_status(dev, &taken, NULL, NULL) < 0)
103 dev->num_pictures = taken;
105 buflen = (taken * sizeof(struct file_item)) + sizeof(cmd) + 4;
106 buffer = malloc(buflen);
108 GP_DEBUG("digita_get_file_list: error allocating %d bytes", buflen);
112 build_command(&gfl.cmd, sizeof(gfl) - sizeof(gfl.cmd), DIGITA_GET_FILE_LIST);
113 gfl.listorder = htonl(1);
115 ret = dev->send(dev, (void *)&gfl, sizeof(gfl));
117 GP_DEBUG("digita_get_file_list: error sending command (ret = %d)", ret);
122 ret = dev->read(dev, (void *)buffer, buflen);
124 GP_DEBUG("digita_get_file_list: error receiving data (ret = %d)", ret);
130 free(dev->file_list);
132 dev->file_list = malloc(taken * sizeof(struct file_item));
133 if (!dev->file_list) {
134 GP_DEBUG("digita_get_file_list: error allocating file_list memory (ret = %d)", ret);
139 memcpy(dev->file_list, buffer + sizeof(cmd) + 4, taken * sizeof(struct file_item));
148 #define GFD_BUFSIZE 19432
149 int digita_get_file_data(CameraPrivateLibrary *dev, int thumbnail,
150 struct filename *filename, struct partial_tag *tag, void *buffer)
152 struct get_file_data_send gfds;
153 struct get_file_data_receive *gfdr;
157 build_command(&gfds.cmd, sizeof(gfds) - sizeof(gfds.cmd), DIGITA_GET_FILE_DATA);
159 memcpy(&gfds.fn, filename, sizeof(gfds.fn));
160 memcpy(&gfds.tag, tag, sizeof(gfds.tag));
161 gfds.dataselector = htonl(thumbnail);
163 tbuf = malloc(GFD_BUFSIZE + sizeof(*gfdr));
165 GP_DEBUG("digita_get_file_data: unable to allocate %ud bytes",
166 (unsigned int)(GFD_BUFSIZE + sizeof(*gfdr)));
170 gfdr = (struct get_file_data_receive *)tbuf;
172 ret = dev->send(dev, &gfds, sizeof(gfds));
174 GP_DEBUG("digita_get_file_data: error sending command (ret = %d)", ret);
179 ret = dev->read(dev, gfdr, GFD_BUFSIZE + sizeof(*gfdr));
181 GP_DEBUG("digita_get_file_data: error reading data (ret = %d)", ret);
185 if (gfdr->cmd.result) {
186 GP_DEBUG("digita_get_file_data: bad result (%d)", gfdr->cmd.result);
187 return gfdr->cmd.result;
190 memcpy(buffer, tbuf + sizeof(*gfdr), ntohl(gfdr->tag.length) + (thumbnail ? 16 : 0));
191 memcpy(tag, &gfdr->tag, sizeof(*tag));
198 int digita_delete_picture(CameraPrivateLibrary *dev, struct filename *filename)
200 struct erase_file ef;
201 struct digita_command response;
204 build_command(&ef.cmd, sizeof(ef.fn), DIGITA_ERASE_FILE);
206 memcpy(&ef.fn, filename, sizeof(ef.fn));
209 ret = dev->send(dev, (unsigned char *)&ef, sizeof(ef));
211 GP_DEBUG("error sending command (ret = %d)", ret);
215 ret = dev->read(dev, (unsigned char *)&response, sizeof(response));
217 GP_DEBUG("error reading reply (ret = %d)", ret);