コード例 #1
0
ファイル: RaspiMMotion.c プロジェクト: bgao/userland
void send_motion_stop() {
   send_schedulecmd("0");   
}
コード例 #2
0
ファイル: RaspiMJPEG.c プロジェクト: nikaidokenichi/userland
int main (int argc, char* argv[]) {
   monitor();
   int i, fd, length;
   int watchdog = 0, watchdog_errors = 0;
   int onesec_check = 0;
   time_t last_pv_time = 0, pv_time;
   char readbuf[MAX_COMMAND_LEN];

   bcm_host_init();
   //
   // read arguments
   //
   for(i=1; i<argc; i++) {
      if(strcmp(argv[i], "--version") == 0) {
         printf("RaspiMJPEG Version %s\n", VERSION);
         exit(0);
      }
      else if(strcmp(argv[i], "-md") == 0) {
         cfg_val[c_motion_detection] = 1;
      }
   }

   //default base media path
   asprintf(&cfg_stru[c_media_path], "%s", "/var/www/media");
   
   //
   // read configs and init
   //
   read_config("/etc/raspimjpeg", 1);
   if (cfg_stru[c_user_config] != 0)
      read_config(cfg_stru[c_user_config], 0);

   createPath(cfg_stru[c_log_file], cfg_stru[c_base_path]);
   if (cfg_stru[c_boxing_path] != NULL) {
      char *bpath;
      asprintf(&bpath, "%s/temp", cfg_stru[c_boxing_path]);
      createPath(bpath, cfg_stru[c_base_path]);
      free(bpath);
   }
   
   printLog("RaspiMJPEG Version %s\n", VERSION);
   
   if(cfg_val[c_autostart]) start_all(0);

   //
   // run
   //
   if(cfg_val[c_autostart]) {
      if(cfg_stru[c_control_file] != 0){
         printLog("MJPEG streaming, ready to receive commands\n");
         //kick off motion detection at start if required.
         if(cfg_val[c_motion_detection] && cfg_val[c_motion_external]) {
            printLog("Autostart external motion kill any runnng motion\n");
            if(system("killall motion") == -1) error("Could not stop external motion", 1);
            sleep(1);
            printLog("Autostart external motion start external motion\n");
            if(system("motion") == -1) error("Could not start external motion", 1);
         }
      } else {
         printLog("MJPEG streaming\n");
      }
   }
   else {
      if(cfg_stru[c_control_file] != 0) printLog("MJPEG idle, ready to receive commands\n");
      else printLog("MJPEG idle\n");
   }

   updateStatus();
 
   struct sigaction action;
   memset(&action, 0, sizeof(struct sigaction));
   action.sa_handler = term;
   sigaction(SIGTERM, &action, NULL);
   sigaction(SIGINT, &action, NULL);
   
   //Clear out anything in FIFO first
   do {
      fd = open(cfg_stru[c_control_file], O_RDONLY | O_NONBLOCK);
      if(fd < 0) error("Could not open PIPE", 1);
      fcntl(fd, F_SETFL, 0);
      length = read(fd, readbuf, 60);
      close(fd);
   } while (length != 0); 
  
  //Send restart signal to scheduler
  send_schedulecmd("9");
   // Main forever loop
   while(running) {
      if(cfg_stru[c_control_file] != 0) {

         fd = open(cfg_stru[c_control_file], O_RDONLY | O_NONBLOCK);
         if(fd < 0) error("Could not open PIPE", 1);
         fcntl(fd, F_SETFL, 0);
         length = read(fd, readbuf, MAX_COMMAND_LEN -2);
         close(fd);

         if(length) {
            process_cmd(readbuf, length);
         }

      }
      if(timelapse) {
         tl_cnt++;
         if(tl_cnt >= cfg_val[c_tl_interval]) {
            if(i_capturing == 0) {
               capt_img();
               tl_cnt = 0;
            }
         }
      }
      // check to see if image preview changing
      if (!idle && cfg_val[c_watchdog_interval] > 0) {
         if(watchdog++ > cfg_val[c_watchdog_interval]) {
            watchdog = 0;
            pv_time = get_mtime(cfg_stru[c_preview_path]);
            if (pv_time == 0) {
               watchdog_errors++;
            } else {
               if (pv_time > last_pv_time) {
                  watchdog_errors = 0;
               } else {
                  watchdog_errors++;
               }
               last_pv_time = pv_time;
            }
            if (watchdog_errors >= cfg_val[c_watchdog_errors]) {
               printLog("Watchdog detected problem. Stopping");
               running = 0;
            }
         }
      } else {
         watchdog_errors = 0;
      }
      if (++onesec_check >= 10) {
         //run check on background boxing every 10 ticks and check for video timer if capturing
         onesec_check = 0;
         check_box_files();
         if (v_capturing && video_stoptime > 0) {
            if (time(NULL) >= video_stoptime) {
               printLog("Stopping video from timer\n");
               stop_video(0);
            }
         }
      }
      usleep(100000);
   }
   if(system("killall motion") == -1) error("Could not stop external motion", 1);
  
   printLog("SIGINT/SIGTERM received, stopping\n");
   //
   // tidy up
   //
   if(!idle) stop_all();
   return 0;
}
コード例 #3
0
ファイル: RaspiMMotion.c プロジェクト: bgao/userland
void send_motion_start() {
   send_schedulecmd("1");
}