Merge ../libgpiv-omp into fft-omp
[libgpiv.git] / lib / cam.c
blobb102d2fbf52a8c9fc8a414cdbc895f01dfa400ec
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*
4 libgpiv - library for Particle Image Velocimetry
6 Copyright (C) 2004, 2005
7 Gerber van der Graaf <gerber_graaf@users.sourceforge.net>
8 Julio Soria <julio.soria@eng.monash.edu.au>
10 This file is part of libgpiv.
12 Libgpiv is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ------------------------------------------------------------------------------
29 FILENAME: cam.c
30 LIBRARY: libgpiv
31 EXTERNAL FUNCTIONS:
32 gpiv_cam_get_camvar
33 gpiv_cam_free_camvar
36 LAST MODIFICATION DATE: $Id: cam.c,v 1.3 2007-11-23 16:16:14 gerber Exp $
37 --------------------------------------------------------------------------- */
40 #ifdef ENABLE_CAM
41 #include <stdio.h>
42 #include <gpiv.h>
46 GpivCamVar *
47 gpiv_cam_get_camvar (const gboolean verbose
49 /*-----------------------------------------------------------------------------
50 * DESCRIPTION:
51 * Get variables of connected cameras using firewire
52 *---------------------------------------------------------------------------*/
54 GpivCamVar *cam_var = g_new0 (GpivCamVar, 1);
55 gchar *err_msg = NULL;
56 gint err, i;
58 * Coriander stuff
60 /* Format7Info format7_info; */
61 /* UIInfo *uiinfos; */
64 cam_var->maxspeed = SPEED_400;
66 * port 0 is the first IEEE1394 card. We ONLY probe this one.
68 cam_var->port = 0;
71 * Open ohci and asign handle to it
73 cam_var->handle = dc1394_create_handle(cam_var->port);
74 if (cam_var->handle == NULL) {
75 g_message ("Unable to aquire a raw1394 handle\n\
76 did you insmod the drivers?");
77 return NULL;
80 cam_var->numNodes = raw1394_get_nodecount(cam_var->handle);
81 cam_var->camera_nodes = dc1394_get_camera_nodes(cam_var->handle,
82 &cam_var->numCameras,
83 verbose);
84 fflush(stdout);
86 if (cam_var->numCameras < 1) {
87 raw1394_destroy_handle(cam_var->handle);
88 g_message ("gpiv_cam_get_camvar: no cameras found");
89 return NULL;
93 * to prevent the iso-transfer bug from raw1394 system, check if
94 * camera is highest node. For details see
95 * http://linux1394.sourceforge.net/faq.html#DCbusmgmt
96 * and
97 * http://sourceforge.net/tracker/index.php?func=detail&aid=435107&group_id=8157&atid=108157
99 if (cam_var->camera_nodes[0] == cam_var->numNodes-1) {
100 err_msg = "\n\
101 Sorry, your camera is the highest numbered node\n\
102 of the bus, and has therefore become the root node.\n\
103 The root node is responsible for maintaining \n\
104 the timing of isochronous transactions on the IEEE \n\
105 1394 bus. However, if the root node is not cycle master \n\
106 capable (it doesn't have to be), then isochronous \n\
107 transactions will not work. The host controller card is \n\
108 cycle master capable, however, most cameras are not.\n\
110 The quick solution is to add the parameter \n\
111 attempt_root=1 when loading the OHCI driver as a \n\
112 module. So please do (as root):\n\
114 rmmod ohci1394\n\
115 insmod ohci1394 attempt_root=1\n\
117 for more information see the FAQ at \n\
118 http://linux1394.sourceforge.net/faq.html#DCbusmgmt\n\
119 \n";
120 g_message ("%s", err_msg);
121 return NULL;
125 * from coriander:
126 * allocate memory space for all camera infos & download all infos
127 * to make an array of cam_var variables, create camera struct
128 * with:
129 gint numNodes;
130 gint numCameras;
131 gint maxspeed;
132 gint port;
133 raw1394handle_t handle;
134 nodeid_t *camera_nodes;
136 /* cam_var = (GpivCamVar*) calloc(camera->numCameras, */
137 /* sizeof(dc1394_cameracapture) */
138 /* + sizeof(dc1394_camerainfo) */
139 /* + sizeof(dc1394_feature_info) */
140 /* + sizeof(dc1394_feature_set) */
141 /* + sizeof(dc1394_miscinfo)); */
145 cam_var->capture = (dc1394_cameracapture*) calloc(cam_var->numCameras,
146 sizeof(dc1394_cameracapture));
148 cam_var->camera = (dc1394_camerainfo*) calloc(cam_var->numCameras,
149 sizeof(dc1394_camerainfo));
151 cam_var->feature_info = (dc1394_feature_info*) calloc(cam_var->numCameras,
152 sizeof(dc1394_feature_info));
154 cam_var->feature_set = (dc1394_feature_set*) calloc(cam_var->numCameras,
155 sizeof(dc1394_feature_set));
157 cam_var->misc_info = (dc1394_miscinfo*) calloc(cam_var->numCameras,
158 sizeof(dc1394_miscinfo));
161 err = 1;
162 for (i = 0; i < cam_var->numCameras; i++) {
163 /* err *= dc1394_get_camera_misc_info(camera->handle, */
164 /* cam_var[i]->camera_nodes, */
165 /* &cam_var[i]->misc_info); */
167 err *= dc1394_get_camera_misc_info(cam_var->handle,
168 cam_var->camera_nodes[i],
169 &cam_var->misc_info[i]);
171 err *= dc1394_get_camera_feature(cam_var->handle,
172 cam_var->camera_nodes[i],
173 &cam_var->feature_info[i]);
175 err *= dc1394_get_camera_info(cam_var->handle,
176 cam_var->camera_nodes[i],
177 &cam_var->camera[i]);
179 err *= dc1394_get_camera_feature_set(cam_var->handle,
180 cam_var->camera[i].id,
181 &cam_var->feature_set[i]);
182 if (!err) {
183 g_message ("Could not get camera basic informations!");
184 return NULL;
186 /* GetFormat7Capabilities(handle, camera[i].id, &format7_info[i]); */
187 /* image_pipes[i] = NULL; */
188 /* uiinfos[i].test_pattern = 0; */
189 /* uiinfos[i].want_to_display = 0; */
194 /* return (err_msg); */
195 return cam_var;
200 gchar *
201 gpiv_cam_free_camvar (GpivCamVar *cam_var
203 /*-----------------------------------------------------------------------------
204 * DESCRIPTION:
205 * Free memory variables of connected cameras using firewire
207 * INPUTS:
209 * OUTPUTS:
210 * cam_var: structure of camera variables
212 * RETURNS:
213 * NULL on success or *err_msg on failure
214 *---------------------------------------------------------------------------*/
216 gchar *err_msg = NULL;
217 /* g_free(cam_var.capture); */
218 g_free(cam_var->feature_set);
219 g_free(cam_var->camera);
220 g_free(cam_var->feature_info);
221 g_free(cam_var->misc_info);
223 return (err_msg);
228 #endif /* ENABLE_CAM */