1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*-----------------------------------------------------------------------------
4 gpiv_trig - triggers a (double Nd_YAGG) laser on a (CCD) camera
6 Copyright (C) 2005, 2006, 2007, 2008
7 Gerber van der Graaf <gerber_graaf@users.sourceforge.net
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation,
22 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 -----------------------------------------------------------------------------*/
27 #include <sys/types.h>
33 #include <sys/ioctl.h>
43 #define EXIT_FAILURE 1
45 /* char *xmalloc (); */
46 /* char *xrealloc (); */
47 /* char *xstrdup (); */
50 static void usage (int status
);
52 * The name the program was run with, stripped of any leading path.
56 /* getopt_long return codes */
60 /* Option flags and variables */
62 gboolean interactive
; /* --interactive */
63 gboolean verbose
; /* -- verbose output during running process */
65 static struct option
const long_options
[] =
67 {"interactive", no_argument
, 0, 'i'},
68 {"verbose", no_argument
, 0, 'V'},
69 {"help", no_argument
, 0, 'h'},
70 {"version", no_argument
, 0, 'v'},
75 command_args (int argc
,
79 interactive_func(void);
82 initialise (GpivTrigPar
*trig_par
83 /* GpivTrigTime *ttime */
87 * Set all the option flags according to the switches specified.
88 * Return the index of the first non-option argument.
92 command_args (int argc
,
95 /*-----------------------------------------------------------------------------
101 while ((c
= getopt_long (argc
, argv
,
102 "i" /* interactive */
106 long_options
, (int *) 0)) != EOF
) {
108 case 'i': /* --interactive */
111 case 'V': /* --verbose */
115 printf ("gpiv_trig %s\n", VERSION
);
120 usage (EXIT_FAILURE
);
132 /*-----------------------------------------------------------------------------
136 triggers a (double Nd_YAGG) laser on a CCD camera\n"), program_name
);
137 printf (_("Usage: %s [OPTION]... [FILE]...\n"), program_name
);
140 -i, --interactive prompt for confirmation\n\
141 -V, --verbose print more information\n\
142 -h, --help display this help and exit\n\
143 -v, --version output version information and exit\n\
151 initialise (GpivTrigPar
*trig_par
152 /* GpivTrigTime *ttime */
154 /*-----------------------------------------------------------------------------
158 float dtime
, acq_time
, increment
;
162 * private user input variables
163 * hardwire some of the timings ....
166 if (verbose
) printf("\nEntering initialise\n");
167 trig_par
->ttime
.laser_trig_pw
= (RTIME
)(0.02*1000*1000); /* laser trigger pulse width 0.02ms */
168 trig_par
->ttime
.time2laser
= (RTIME
)(0.19*1000*1000); /* time from laser trigger->Hi
169 until laser pulse: 0.19ms */
172 printf("\n\tmode:\n");
173 printf("\t\t1 - indefinite periodic\n");
174 printf("\t\t2 - duration\n");
175 printf("\t\t3 - interrupt one shot\n");
176 printf("\t\t4 - interrupt periodic\n");
177 printf("\t\t5 - incremented dt\n");
178 printf("\t\t6 - double exposure\n");
179 printf("\t\t9 - exit\n");
180 printf("\t(1/2/3/4/5/6/9) > ");
182 trig_par
->ttime
.mode
= mode
;
184 if (trig_par
->ttime
.mode
== 9) {
189 * ask for other timings ....
191 printf("\n\tAcquisition parameters: \n");
193 printf("\ttime between 2 laser exposures in ms > ");
195 trig_par
->ttime
.dt
= (RTIME
)1000 * 1000 * dtime
;
197 /* gpiv_trig_test_parameter(GpivTrigPar * trig_par */
199 if ((trig_par
->ttime
.mode
== GPIV_TIMER_MODE__PERIODIC
)
200 || (trig_par
->ttime
.mode
== GPIV_TIMER_MODE__DURATION
)
201 || (trig_par
->ttime
.mode
== GPIV_TIMER_MODE__TRIGGER_IRQ
)
202 || (trig_par
->ttime
.mode
== GPIV_TIMER_MODE__DOUBLE
)) {
203 printf("\tdouble frame acquisition period in ms (typ. 250 ms) > ");
204 scanf("%f", &acq_time
);
205 trig_par
->ttime
.cam_acq_period
= (RTIME
)1000 * 1000 * acq_time
;
207 trig_par
->ttime
.cam_acq_period
= (trig_par
->ttime
.dt
) * 2;
210 if ((trig_par
->ttime
.mode
== GPIV_TIMER_MODE__DURATION
)
211 || (trig_par
->ttime
.mode
== GPIV_TIMER_MODE__ONE_SHOT_IRQ
)
212 || (trig_par
->ttime
.mode
== GPIV_TIMER_MODE__TRIGGER_IRQ
)
213 || (trig_par
->ttime
.mode
== GPIV_TIMER_MODE__INCREMENT
)) {
214 printf("\tnumber of cycles > ");
215 scanf("%d", &cycles
);
216 trig_par
->ttime
.cycles
= cycles
;
218 trig_par
->ttime
.cycles
= 1;
221 if (trig_par
->ttime
.mode
== GPIV_TIMER_MODE__INCREMENT
) {
222 printf("\tincrement in ms > ");
223 scanf("%f", &increment
);
224 trig_par
->ttime
.increment
= (RTIME
)1000 * 1000 * increment
;
226 trig_par
->ttime
.increment
= 1;
230 if (verbose
) printf("\nLeaving initialise\n");
237 interactive_func (void
239 /*-----------------------------------------------------------------------------
242 GpivTrigPar trig_per
;
243 /* GpivTrigTime ttime = trig_per.ttime; */
244 int init
, start
, stop
, error
; /* file pointer int */
245 int on
= 1, off
= 0, param_ok
;
247 if (verbose
) printf("\nEntering interactive_func\n");
248 if (!gpiv_trig_openrtfs(&init
, &start
, &stop
, &error
)) {
249 printf("\n\nFAIL IN FIFO OPEN, BYE ..... \n\n");
252 printf("\n\n\tProgram to control camera with external triggering & laser\n");
255 if(!initialise(&trig_per
/* timing */)) {
256 printf("\n\nPROBLEM INITIALISING PROGRAM, BYE ..... \n\n");
260 if (trig_per
.ttime
.mode
== 9) {
261 printf("\n\tEx(c)iting program\n\n");
265 printf("\n\tWriting details to RT module\n\n");
267 * write the timing details to /dev/rtf/1
270 if((write(init
, &trig_per
.ttime
, sizeof(GpivTrigTime
))) < 0) {
271 printf("\n\nfail in setting Camera and Laser timing ...\n\n");
275 if((read(error
, ¶m_ok
, sizeof(int))) < 0) {
276 printf("\n\nfail in receipt of confirmation ...\n\n");
281 printf("\n\tInvalid parameters entered \n");
284 printf("\n\tParameters :\n");
285 printf("\t\tcam_acq_period: %lld\n", trig_per
.ttime
.cam_acq_period
);
286 printf("\t\tlaser_trig_pw: %lld\n", trig_per
.ttime
.laser_trig_pw
);
287 printf("\t\ttime2laser: %lld\n", trig_per
.ttime
.time2laser
);
288 printf("\t\tdt: %lld\n", trig_per
.ttime
.dt
);
289 printf("\t\tmode: %d\n", trig_per
.ttime
.mode
);
290 printf("\t\tcycles: %d\n", trig_per
.ttime
.cycles
);
291 printf("\t\tincrement: %d\n", (int) trig_per
.ttime
.increment
);
293 printf("\n\n\tStart on <enter> >");
297 if((write(start
, &on
, sizeof(int))) < 0) {
298 printf("\n\nfail in starting camera and laser timing ...\n\n");
302 printf("\n\tStop on <enter> >");
305 if((write(stop
, &off
, sizeof(int))) < 0) {
306 printf("\nfail in stopping camera and laser timing ...\n\n");
313 if (verbose
) printf("\nLeaving interactive_func\n");
323 /*-----------------------------------------------------------------------------
324 * Main program to send trigger pulses
327 int i
, return_val
= 0;
329 program_name
= argv
[0];
331 i
= command_args (argc
, argv
);
333 return_val
= interactive_func();
341 #else /* ENABLE_TRIG */
347 /*-----------------------------------------------------------------------------
350 g_error("%s: this is dead code as ENABLE_TRIG has not been set during building the program", argv
[0]);
354 #endif /* ENABLE_TRIG */