apps/autocampars/autocampars.c

Go to the documentation of this file.
00001 /*!***************************************************************************
00002 *! FILE NAME  : autocampars.c
00003 *! DESCRIPTION: Daemon to save/restore parameter (calls autocampars.php)
00004 *!              This program is needed not to have an extra instance of
00005 *!              PHP (2+ MB) just waiting as a daemon.
00006 *! Copyright (C) 2008 Elphel, Inc.
00007 *! -----------------------------------------------------------------------------**
00008 *!  This program is free software: you can redistribute it and/or modify
00009 *!  it under the terms of the GNU General Public License as published by
00010 *!  the Free Software Foundation, either version 3 of the License, or
00011 *!  (at your option) any later version.
00012 *!
00013 *!  This program is distributed in the hope that it will be useful,
00014 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 *!  GNU General Public License for more details.
00017 *!
00018 *!  You should have received a copy of the GNU General Public License
00019 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *! -----------------------------------------------------------------------------**
00021 *!
00022 *!  $Log: autocampars.c,v $
00023 *!  Revision 1.1.1.1  2008/11/27 20:04:01  elphel
00024 *!
00025 *!
00026 *!  Revision 1.4  2008/11/22 05:52:47  elphel
00027 *!  added TODO
00028 *!
00029 *!  Revision 1.3  2008/11/18 07:37:10  elphel
00030 *!  snapshot
00031 *!
00032 *!  Revision 1.2  2008/11/17 23:42:59  elphel
00033 *!  snapshot
00034 *!
00035 *!  Revision 1.1  2008/11/17 06:41:20  elphel
00036 *!  8.0.alpha18 - started autocampars - camera parameters save/restore/init manager
00037 *!
00038 *!
00039 */ 
00040 #include <unistd.h>
00041 #include <stdio.h>
00042 #include <stdlib.h>
00043 #include <signal.h>
00044 #include <fcntl.h>
00045 #include <errno.h>
00046 
00047 #include <asm/elphel/c313a.h>
00048 int main (int argc, char *argv[]) {
00049   const char framepars_driver_name[]="/dev/frameparsall";
00050 //  const char php_path[]="/usr/local/sbin/php";
00051   const char script_path[]="/usr/html/autocampars.php";
00052   int fd_fparmsall= open(framepars_driver_name, O_RDWR);
00053   unsigned long write_data[4]; 
00054   int rslt;
00055   if (fd_fparmsall <0) {
00056      ELP_FERR(fprintf(stderr, "Open failed: (%s)\n", framepars_driver_name));
00057      exit (1);
00058   }
00066   while (1) {
00067    lseek(fd_fparmsall, LSEEK_DAEMON_FRAME+DAEMON_BIT_AUTOCAMPARS, SEEK_END);   
00068    write_data[0]= FRAMEPARS_SETFRAMEREL;
00069    write_data[1]= 1;
00070    write_data[2]= P_DAEMON_EN_AUTOCAMPARS;
00071    write_data[3]= 0;
00072    rslt=write(fd_fparmsall, write_data, sizeof(write_data));
00073    if (rslt < sizeof(write_data)) {
00074      ELP_FERR(fprintf(stderr, "Failed writing to %s\n", framepars_driver_name));
00075      exit (1); 
00076    }
00077    fprintf(stderr, "autocampars triggered\n");
00078    signal(SIGCHLD, SIG_IGN); // no zombies
00080    if (fork() == 0) {
00081        fflush(stdout);
00082        fflush(stderr);
00083 //       rslt= execl(php_path, "-q", script_path, "", "--daemon", (char *) NULL); /// We do not need to pass any parameters here, but if we had to - first argument is lost (probably to "-q" in the script line 1
00084        rslt= execl(script_path, "", "--daemon", (char *) NULL); 
00085        ELP_FERR(fprintf(stderr, "execl failed, returned %d, errno=%d\n", rslt,errno));
00086       _exit(2);
00087    } // end of child process
00088    lseek(fd_fparmsall, LSEEK_FRAME_WAIT_REL+1, SEEK_END);   
00089   }
00090   return 0;
00091 }
00092 

Generated on Fri Nov 28 00:06:21 2008 for elphel by  doxygen 1.5.1