void check(tree_node_t *tree) { if (tree == NULL) return; if(tree->data->pid == PID_UNDEFINED) { if (tree->first_child != NULL) { kill_all(tree->first_child); } start_self(tree); if (tree->first_child != NULL) { start_all(tree->first_child); } } else { if (tree->first_child != NULL) { check(tree->first_child); } } if (tree->next_sibling != NULL) { check(tree->next_sibling); } }
static void *process_runall(void *m) { ALOGI("[%s] start,", __FUNCTION__); if(m == NULL) return NULL; module_info *mod = (module_info *) m; sem_init(&g_sem_mod_complete, 0, 0); layout *lay = g_layout_map[mod->config_list[KEY_LAYOUT]]; if(lay == NULL) { ALOGE("No layout for :%s", mod->config_list[KEY_LAYOUT].c_str()); return NULL; } button *btn = lay->find_button_by_name(KEY_MAIN_RUNALL); if(btn != NULL) { if(btn->get_disabled()) { ALOGI("The previous RUN ALL action is not finished, please wait"); return NULL; } else { btn->set_disabled(true); } } /**start all automation cases*/ start_all(true); ALOGI("%s,start manual test.", __FUNCTION__); /**start manually test cases*/ if(lay != NULL && lay->m_listview != NULL && lay->m_listview->get_items() != NULL) { list < item_t * >*items = lay->m_listview->get_items(); list < item_t * >::iterator iter; for(iter = items->begin(); iter != items->end(); iter++) { item_t *item = (item_t *) (*iter); module_info *tmod = item->mod; if(tmod != NULL && !tmod->config_list[KEY_AUTOMATION].compare("0")) { usleep(100); switch_module(tmod); ALOGI("%s:testing %s", __FUNCTION__, tmod->module); sem_wait(&g_sem_mod_complete); ALOGI("%s:testing %s, finished", __FUNCTION__, tmod->module); } } } if(btn != NULL) btn->set_disabled(false); return NULL; }
void QUrlQueueServer::dispatch(msgpack::rpc::request req) { try { std::string method; req.method().convert(&method); if(method == "push") { msgpack::type::tuple<int, std::string, std::string> params; req.params().convert(¶ms); push_url(req, params.get<0>(), params.get<1>(), params.get<2>()); } else if(method == "pop") { pop_url(req); } else if(method == "push_url_front") { msgpack::type::tuple<int, std::string, std::string> params; req.params().convert(¶ms); push_url_front(req, params.get<0>(), params.get<1>(), params.get<2>()); } else if(method == "start_dump_all") { start_dump_all(req); } else if(method == "dump_all") { dump_all(req); } else if(method == "stats") { stats(req); } else if(method == "set_default_interval") { msgpack::type::tuple<int> params; req.params().convert(¶ms); set_default_interval(req, params.get<0>()); } else if(method == "set_site_interval") { msgpack::type::tuple<std::string, int> params; req.params().convert(¶ms); set_site_interval(req, params.get<0>(), params.get<1>()); } else if(method == "stat_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stat_site(req, params.get<0>()); } else if(method == "dump_ordered_site") { msgpack::type::tuple<int> params; req.params().convert(¶ms); dump_ordered_site(req, params.get<0>()); } else if(method == "start_all") { start_all(req); } else if(method == "stop_all") { stop_all(req); } else if(method == "start_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); start_site(req, params.get<0>()); } else if(method == "stop_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); stop_site(req, params.get<0>()); } else if(method == "clear_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); clear_site(req, params.get<0>()); } else if(method == "start_dump_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); start_dump_site(req, params.get<0>()); } else if(method == "dump_site") { msgpack::type::tuple<std::string> params; req.params().convert(¶ms); dump_site(req, params.get<0>()); } else if(method == "clear_empty_site") { clear_empty_site(req); } else { req.error(msgpack::rpc::NO_METHOD_ERROR); } } catch (msgpack::type_error& e) { req.error(msgpack::rpc::ARGUMENT_ERROR); return; } catch (std::exception& e) { req.error(std::string(e.what())); return; } }
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; }
int main (int argc, char* argv[]) { MMAL_STATUS_T status; int i, max, fd, length, cam_setting; unsigned long int cam_setting_long; char readbuf[20]; char *filename_temp, *filename_temp2, *cmd_temp; bcm_host_init(); // // read arguments // unsigned char of_set = 0; for(i=1; i<argc; i++) { if(strcmp(argv[i], "--version") == 0) { printf("RaspiMJPEG Version "); printf(VERSION); printf("\n"); exit(0); } else if(strcmp(argv[i], "-w") == 0) { i++; width = atoi(argv[i]); } else if(strcmp(argv[i], "-h") == 0) { i++; height = atoi(argv[i]); } else if(strcmp(argv[i], "-wp") == 0) { i++; width_pic = atoi(argv[i]); } else if(strcmp(argv[i], "-hp") == 0) { i++; height_pic = atoi(argv[i]); } else if(strcmp(argv[i], "-q") == 0) { i++; quality = atoi(argv[i]); } else if(strcmp(argv[i], "-d") == 0) { i++; divider = atoi(argv[i]); } else if(strcmp(argv[i], "-p") == 0) { mp4box = 1; } else if(strcmp(argv[i], "-ic") == 0) { i++; image2_cnt = atoi(argv[i]); } else if(strcmp(argv[i], "-vc") == 0) { i++; video_cnt = atoi(argv[i]); } else if(strcmp(argv[i], "-of") == 0) { i++; jpeg_filename = argv[i]; of_set = 1; } else if(strcmp(argv[i], "-if") == 0) { i++; jpeg2_filename = argv[i]; of_set = 1; } else if(strcmp(argv[i], "-cf") == 0) { i++; pipe_filename = argv[i]; } else if(strcmp(argv[i], "-vf") == 0) { i++; h264_filename = argv[i]; } else if(strcmp(argv[i], "-sf") == 0) { i++; status_filename = argv[i]; } else if(strcmp(argv[i], "-pa") == 0) { autostart = 0; idle = 1; } else if(strcmp(argv[i], "-md") == 0) { motion_detection = 1; } else if(strcmp(argv[i], "-fp") == 0) { preview_mode = RES_4_3; } else if(strcmp(argv[i], "-audio") == 0) { audio_mode = 1; } else error("Invalid arguments"); } if(!of_set) error("Output file not specified"); // // init // if(autostart) start_all(); if(motion_detection) { if(system("motion") == -1) error("Could not start Motion"); } // // run // if(autostart) { if(pipe_filename != 0) printf("MJPEG streaming, ready to receive commands\n"); else printf("MJPEG streaming\n"); } else { if(pipe_filename != 0) printf("MJPEG idle, ready to receive commands\n"); else printf("MJPEG idle\n"); } struct sigaction action; memset(&action, 0, sizeof(struct sigaction)); action.sa_handler = term; sigaction(SIGTERM, &action, NULL); sigaction(SIGINT, &action, NULL); if(status_filename != 0) { status_file = fopen(status_filename, "w"); if(!status_file) error("Could not open/create status-file"); if(autostart) { if(!motion_detection) { fprintf(status_file, "ready"); } else fprintf(status_file, "md_ready"); } else fprintf(status_file, "halted"); fclose(status_file); } while(running) { if(pipe_filename != 0) { fd = open(pipe_filename, O_RDONLY | O_NONBLOCK); if(fd < 0) error("Could not open PIPE"); fcntl(fd, F_SETFL, 0); length = read(fd, readbuf, 20); close(fd); if(length) { if((readbuf[0]=='p') && (readbuf[1]=='m')) { stop_all(); readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; if(strcmp(readbuf, " 4_3") == 0) preview_mode = RES_4_3; else if(strcmp(readbuf, " 16_9_STD") == 0) preview_mode = RES_16_9_STD; else if(strcmp(readbuf, " 16_9_WIDE") == 0) preview_mode = RES_16_9_WIDE; start_all(); printf("Changed preview mode\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } } else if((readbuf[0]=='c') && (readbuf[1]=='a')) { if(readbuf[3]=='1') { if(!capturing) { status = mmal_component_enable(h264encoder); if(status != MMAL_SUCCESS) error("Could not enable h264encoder"); pool_h264encoder = mmal_port_pool_create(h264encoder->output[0], h264encoder->output[0]->buffer_num, h264encoder->output[0]->buffer_size); if(!pool_h264encoder) error("Could not create pool"); status = mmal_connection_create(&con_cam_h264, camera->output[1], h264encoder->input[0], MMAL_CONNECTION_FLAG_TUNNELLING | MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT); if(status != MMAL_SUCCESS) error("Could not create connecton camera -> video converter"); status = mmal_connection_enable(con_cam_h264); if(status != MMAL_SUCCESS) error("Could not enable connection camera -> video converter"); currTime = time(NULL); localTime = localtime (&currTime); if(mp4box) { asprintf(&filename_temp, h264_filename, video_cnt, localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); asprintf(&filename_temp2, "%s.h264", filename_temp); } else { asprintf(&filename_temp2, h264_filename, video_cnt, localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); } h264output_file = fopen(filename_temp2, "wb"); free(filename_temp2); if(mp4box) { if(audio_mode) { asprintf(&cmd_temp, "/usr/bin/arecord -q -D hw:1,0 -f S16_LE -t wav | /usr/bin/lame - %s.mp3 -S &", filename_temp); printf("Audio recording with \"%s\\n", cmd_temp); if(system(cmd_temp) == -1) error("Could not start audio recording"); } free(filename_temp); } if(!h264output_file) error("Could not open/create video-file"); status = mmal_port_enable(h264encoder->output[0], h264encoder_buffer_callback); if(status != MMAL_SUCCESS) error("Could not enable video port"); max = mmal_queue_length(pool_h264encoder->queue); for(i=0;i<max;i++) { MMAL_BUFFER_HEADER_T *h264buffer = mmal_queue_get(pool_h264encoder->queue); if(!h264buffer) error("Could not create video pool header"); status = mmal_port_send_buffer(h264encoder->output[0], h264buffer); if(status != MMAL_SUCCESS) error("Could not send buffers to video port"); } mmal_port_parameter_set_boolean(camera->output[1], MMAL_PARAMETER_CAPTURE, 1); if(status != MMAL_SUCCESS) error("Could not start capture"); printf("Capturing started\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); if(!motion_detection) fprintf(status_file, "video"); else fprintf(status_file, "md_video"); fclose(status_file); } capturing = 1; } } else { if(capturing) { mmal_port_parameter_set_boolean(camera->output[1], MMAL_PARAMETER_CAPTURE, 0); if(status != MMAL_SUCCESS) error("Could not stop capture"); status = mmal_port_disable(h264encoder->output[0]); if(status != MMAL_SUCCESS) error("Could not disable video port"); status = mmal_connection_destroy(con_cam_h264); if(status != MMAL_SUCCESS) error("Could not destroy connection camera -> video encoder"); mmal_port_pool_destroy(h264encoder->output[0], pool_h264encoder); if(status != MMAL_SUCCESS) error("Could not destroy video buffer pool"); status = mmal_component_disable(h264encoder); if(status != MMAL_SUCCESS) error("Could not disable video converter"); fclose(h264output_file); h264output_file = NULL; printf("Capturing stopped\n"); if(mp4box) { printf("Boxing started\n"); status_file = fopen(status_filename, "w"); if(!motion_detection) fprintf(status_file, "boxing"); else fprintf(status_file, "md_boxing"); fclose(status_file); asprintf(&filename_temp, h264_filename, video_cnt, localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday, localTime->tm_hour, localTime->tm_min, localTime->tm_sec); if(audio_mode) { asprintf(&cmd_temp, "/usr/bin/killall arecord > /dev/null"); if(system(cmd_temp) == -1) error("Could not stop audio recording"); free(cmd_temp); asprintf(&cmd_temp, "MP4Box -fps 25 -add %s.h264 -add %s.mp3 %s > /dev/null", filename_temp, filename_temp, filename_temp); } else { asprintf(&cmd_temp, "MP4Box -fps 25 -add %s.h264 %s > /dev/null", filename_temp, filename_temp); } if(system(cmd_temp) == -1) error("Could not start MP4Box"); asprintf(&filename_temp2, "%s.h264", filename_temp); remove(filename_temp2); free(filename_temp2); if (audio_mode) { asprintf(&filename_temp2, "%s.mp3", filename_temp); remove(filename_temp2); free(filename_temp2); } free(filename_temp); free(cmd_temp); printf("Boxing stopped\n"); } video_cnt++; if(status_filename != 0) { status_file = fopen(status_filename, "w"); if(!motion_detection) fprintf(status_file, "ready"); else fprintf(status_file, "md_ready"); fclose(status_file); } capturing = 0; } } } else if((readbuf[0]=='i') && (readbuf[1]=='m')) { capt_img(); } else if((readbuf[0]=='t') && (readbuf[1]=='l')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; time_between_pic = atoi(readbuf); if(time_between_pic) { if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "timelapse"); fclose(status_file); } timelapse = 1; printf("Timelapse started\n"); } else { if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } timelapse = 0; printf("Timelapse stopped\n"); } } else if((readbuf[0]=='s') && (readbuf[1]=='h')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_SHARPNESS, value); if(status != MMAL_SUCCESS) error("Could not set sharpness"); printf("Sharpness: %d\n", cam_setting); } else if((readbuf[0]=='c') && (readbuf[1]=='o')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_CONTRAST, value); if(status != MMAL_SUCCESS) error("Could not set contrast"); printf("Contrast: %d\n", cam_setting); } else if((readbuf[0]=='b') && (readbuf[1]=='r')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_BRIGHTNESS, value); if(status != MMAL_SUCCESS) error("Could not set brightness"); printf("Brightness: %d\n", cam_setting); } else if((readbuf[0]=='s') && (readbuf[1]=='a')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); MMAL_RATIONAL_T value = {cam_setting, 100}; status = mmal_port_parameter_set_rational(camera->control, MMAL_PARAMETER_SATURATION, value); if(status != MMAL_SUCCESS) error("Could not set saturation"); printf("Saturation: %d\n", cam_setting); } else if((readbuf[0]=='i') && (readbuf[1]=='s')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_uint32(camera->control, MMAL_PARAMETER_ISO, cam_setting); if(status != MMAL_SUCCESS) error("Could not set ISO"); printf("ISO: %d\n", cam_setting); } else if((readbuf[0]=='v') && (readbuf[1]=='s')) { if(readbuf[3]=='1') { status = mmal_port_parameter_set_boolean(camera->control, MMAL_PARAMETER_VIDEO_STABILISATION, 1); printf("Video Stabilisation ON\n"); } else { status = mmal_port_parameter_set_boolean(camera->control, MMAL_PARAMETER_VIDEO_STABILISATION, 0); printf("Video Stabilisation OFF\n"); } if(status != MMAL_SUCCESS) error("Could not set video stabilisation"); } else if((readbuf[0]=='e') && (readbuf[1]=='c')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_int32(camera->control, MMAL_PARAMETER_EXPOSURE_COMP, cam_setting); if(status != MMAL_SUCCESS) error("Could not set exposure compensation"); printf("Exposure Compensation: %d\n", cam_setting); } else if((readbuf[0]=='e') && (readbuf[1]=='m')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; MMAL_PARAM_EXPOSUREMODE_T mode = MMAL_PARAM_EXPOSUREMODE_OFF; if(strcmp(readbuf, " auto") == 0) mode = MMAL_PARAM_EXPOSUREMODE_AUTO; else if(strcmp(readbuf, " night") == 0) mode = MMAL_PARAM_EXPOSUREMODE_NIGHT; else if(strcmp(readbuf, " nightpreview") == 0) mode = MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW; else if(strcmp(readbuf, " backlight") == 0) mode = MMAL_PARAM_EXPOSUREMODE_BACKLIGHT; else if(strcmp(readbuf, " spotlight") == 0) mode = MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT; else if(strcmp(readbuf, " sports") == 0) mode = MMAL_PARAM_EXPOSUREMODE_SPORTS; else if(strcmp(readbuf, " snow") == 0) mode = MMAL_PARAM_EXPOSUREMODE_SNOW; else if(strcmp(readbuf, " beach") == 0) mode = MMAL_PARAM_EXPOSUREMODE_BEACH; else if(strcmp(readbuf, " verylong") == 0) mode = MMAL_PARAM_EXPOSUREMODE_VERYLONG; else if(strcmp(readbuf, " fixedfps") == 0) mode = MMAL_PARAM_EXPOSUREMODE_FIXEDFPS; else if(strcmp(readbuf, " antishake") == 0) mode = MMAL_PARAM_EXPOSUREMODE_ANTISHAKE; else if(strcmp(readbuf, " fireworks") == 0) mode = MMAL_PARAM_EXPOSUREMODE_FIREWORKS; MMAL_PARAMETER_EXPOSUREMODE_T exp_mode = {{MMAL_PARAMETER_EXPOSURE_MODE,sizeof(exp_mode)}, mode}; status = mmal_port_parameter_set(camera->control, &exp_mode.hdr); if(status != MMAL_SUCCESS) error("Could not set exposure mode"); printf("Exposure mode changed\n"); } else if((readbuf[0]=='w') && (readbuf[1]=='b')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; MMAL_PARAM_AWBMODE_T awb_mode = MMAL_PARAM_AWBMODE_OFF; if(strcmp(readbuf, " auto") == 0) awb_mode = MMAL_PARAM_AWBMODE_AUTO; else if(strcmp(readbuf, " auto") == 0) awb_mode = MMAL_PARAM_AWBMODE_AUTO; else if(strcmp(readbuf, " sun") == 0) awb_mode = MMAL_PARAM_AWBMODE_SUNLIGHT; else if(strcmp(readbuf, " cloudy") == 0) awb_mode = MMAL_PARAM_AWBMODE_CLOUDY; else if(strcmp(readbuf, " shade") == 0) awb_mode = MMAL_PARAM_AWBMODE_SHADE; else if(strcmp(readbuf, " tungsten") == 0) awb_mode = MMAL_PARAM_AWBMODE_TUNGSTEN; else if(strcmp(readbuf, " fluorescent") == 0) awb_mode = MMAL_PARAM_AWBMODE_FLUORESCENT; else if(strcmp(readbuf, " incandescent") == 0) awb_mode = MMAL_PARAM_AWBMODE_INCANDESCENT; else if(strcmp(readbuf, " flash") == 0) awb_mode = MMAL_PARAM_AWBMODE_FLASH; else if(strcmp(readbuf, " horizon") == 0) awb_mode = MMAL_PARAM_AWBMODE_HORIZON; MMAL_PARAMETER_AWBMODE_T param = {{MMAL_PARAMETER_AWB_MODE,sizeof(param)}, awb_mode}; status = mmal_port_parameter_set(camera->control, ¶m.hdr); if(status != MMAL_SUCCESS) error("Could not set white balance"); printf("White balance changed\n"); } else if((readbuf[0]=='r') && (readbuf[1]=='o')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_int32(camera->output[0], MMAL_PARAMETER_ROTATION, cam_setting); if(status != MMAL_SUCCESS) error("Could not set rotation (0)"); status = mmal_port_parameter_set_int32(camera->output[1], MMAL_PARAMETER_ROTATION, cam_setting); if(status != MMAL_SUCCESS) error("Could not set rotation (1)"); status = mmal_port_parameter_set_int32(camera->output[2], MMAL_PARAMETER_ROTATION, cam_setting); if(status != MMAL_SUCCESS) error("Could not set rotation (2)"); printf("Rotation: %d\n", cam_setting); } else if((readbuf[0]=='q') && (readbuf[1]=='u')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting = atoi(readbuf); status = mmal_port_parameter_set_uint32(jpegencoder2->output[0], MMAL_PARAMETER_JPEG_Q_FACTOR, cam_setting); if(status != MMAL_SUCCESS) error("Could not set quality"); printf("Quality: %d\n", cam_setting); } else if((readbuf[0]=='b') && (readbuf[1]=='i')) { readbuf[0] = ' '; readbuf[1] = ' '; readbuf[length] = 0; cam_setting_long = strtoull(readbuf, NULL, 0); h264encoder->output[0]->format->bitrate = cam_setting_long; status = mmal_port_format_commit(h264encoder->output[0]); if(status != MMAL_SUCCESS) error("Could not set bitrate"); printf("Bitrate: %lu\n", cam_setting_long); } else if((readbuf[0]=='r') && (readbuf[1]=='u')) { if(readbuf[3]=='0') { stop_all(); idle = 1; printf("Stream halted\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "halted"); fclose(status_file); } } else { start_all(); idle = 0; printf("Stream continued\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } } } else if((readbuf[0]=='m') && (readbuf[1]=='d')) { if(readbuf[3]=='0') { motion_detection = 0; if(system("killall motion") == -1) error("Could not stop Motion"); printf("Motion detection stopped\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "ready"); fclose(status_file); } } else { motion_detection = 1; if(system("motion") == -1) error("Could not start Motion"); printf("Motion detection started\n"); if(status_filename != 0) { status_file = fopen(status_filename, "w"); fprintf(status_file, "md_ready"); fclose(status_file); } } } } } if(timelapse) { tl_cnt++; if(tl_cnt >= time_between_pic) { if(capturing == 0) { capt_img(); tl_cnt = 0; } } } usleep(100000); } printf("SIGINT/SIGTERM received, stopping\n"); // // tidy up // if(!idle) stop_all(); return 0; }
void process_cmd(char *readbuf, int length) { typedef enum pipe_cmd_type{ca,im,tl,px,bo,tv,an,as,at,ac,ab,sh,co,br,sa,is,vs,rl,ec,em,wb,mm,ie,ce,ro,fl,ri,ss,qu,pv,bi,ru,md,sc,rs,bu,mn,mt,mi,mb,me,mx,mf,vm,vp,wd,sy,cn,st} pipe_cmd_type; char pipe_cmds[] = "ca,im,tl,px,bo,tv,an,as,at,ac,ab,sh,co,br,sa,is,vs,rl,ec,em,wb,mm,ie,ce,ro,fl,ri,ss,qu,pv,bi,ru,md,sc,rs,bu,mn,mt,mi,mb,me,mx,mf,vm,vp,wd,sy,cn,st"; pipe_cmd_type pipe_cmd; int parcount; char pars[128][10]; long int par0; char cmd[3]; char par[MAX_COMMAND_LEN]; char *parstring=0, *temp; int key = -1; if (length < 2 || length > (MAX_COMMAND_LEN - 2)) return; //Get cmd strncpy(cmd, readbuf, 2); //find 2 letter command and translate into enum temp = strstr(pipe_cmds, cmd); if (temp == NULL) return; pipe_cmd = (pipe_cmd_type)((temp - pipe_cmds) / 3); if(length > 3) { strcpy(par, readbuf + 3); par[length-3] = 0; //extract space separated numeric parameters // and make separate string parameter (strtok changes the original) asprintf(&parstring, "%s", par); parcount = 0; temp = strtok(par, " "); while(parcount<10 && temp != NULL) { strcpy(pars[parcount], temp); parcount++; temp = strtok(NULL, " "); } par0 = strtol(pars[0], NULL, 10); } else { par0 = 0; } switch(pipe_cmd) { case ca: if(par0 == 1) { if (parcount > 1) { long vtime = strtol(pars[1], NULL, 10); video_stoptime = time(NULL) + vtime; printLog("Capturing %d seconds\n", vtime); } start_video(0); } else { stop_video(0); } break; case im: capt_img(); break; case tl: if(par0) { timelapse = 1; lapse_cnt = 1; updateStatus(); printLog("Timelapse started\n"); } else { image2_cnt++; timelapse = 0; updateStatus(); printLog("Timelapse stopped\n"); } break; case px: stop_all(); addUserValue(c_video_width, pars[0]); addUserValue(c_video_height, pars[1]); addUserValue(c_video_fps, pars[2]); addUserValue(c_MP4Box_fps, pars[3]); addUserValue(c_image_width, pars[4]); addUserValue(c_image_height, pars[5]); start_all(0); break; case bo: addUserValue(c_MP4Box, pars[0]); break; case tv: addUserValue(c_tl_interval, pars[0]); break; case an: addUserValue(c_annotation, parstring); break; case as: addUserValue(c_anno_text_size, pars[0]); break; case at: addUserValue(c_anno3_custom_text_colour, pars[0]); addUserValue(c_anno3_custom_text_Y, pars[1]); addUserValue(c_anno3_custom_text_U, pars[2]); addUserValue(c_anno3_custom_text_V, pars[3]); break; case ac: addUserValue(c_anno3_custom_background_colour, pars[0]); addUserValue(c_anno3_custom_background_Y, pars[1]); addUserValue(c_anno3_custom_background_U, pars[2]); addUserValue(c_anno3_custom_background_V, pars[3]); break; case ab: addUserValue(c_anno_background, pars[0]); break; case sh: key = c_sharpness; break; case co: key = c_contrast; break; case br: key = c_brightness; break; case sa: key = c_saturation; break; case is: key = c_iso; break; case vs: key = c_video_stabilisation; break; case rl: key = c_raw_layer; break; case ec: key = 1000 + c_exposure_compensation; break; case em: key = 1000 + c_exposure_mode; break; case wb: key = 1000 + c_white_balance; break; case mm: key = 1000 + c_metering_mode; break; case ie: key = 1000 + c_image_effect; break; case ce: addUserValue(c_colour_effect_u, pars[1]); addUserValue(c_colour_effect_v, pars[2]); key = c_colour_effect_en; break; case ro: key = c_rotation; break; case fl: if(par0 & 1) addUserValue(c_hflip, "1"); else addUserValue(c_hflip, "0"); if((par0 >> 1) & 1) addUserValue(c_vflip, "1"); else addUserValue(c_vflip, "0"); cam_set(c_hflip); break; case ri: addUserValue(c_sensor_region_y, pars[1]); addUserValue(c_sensor_region_w, pars[2]); addUserValue(c_sensor_region_h, pars[3]); key = c_sensor_region_x; break; case ss: addUserValue(c_shutter_speed, pars[0]); key = c_shutter_speed; break; case qu: key = c_image_quality; break; case pv: stop_all(); addUserValue(c_quality, pars[0]); addUserValue(c_width, pars[1]); addUserValue(c_divider, pars[2]); start_all(0); break; case bi: stop_all(); addUserValue(c_video_bitrate, pars[0]); start_all(0); break; case st: stop_all(); addUserValue(c_stat_pass, pars[0]); start_all(0); break; case wd: addUserValue(c_watchdog_interval, pars[0]); addUserValue(c_watchdog_errors, pars[1]); break; case ru: if (par0 == 0) { stop_all(); idle = 1; printLog("Stream halted\n"); } else { start_all(1); idle = 0; printLog("Stream continued\n"); } updateStatus(); break; case mx: key = c_motion_external; //If switching to internal with motion detection on then try to kill external motion if (cfg_val[c_motion_detection] != 0 && !par0) { if(system("killall motion") == -1) error("Could not stop external motion", 1); printLog("External motion detection stopped\n"); } break; case md: exec_macro(cfg_stru[c_do_cmd], readbuf); stop_all(); if (cfg_val[c_motion_external]) { if(par0 == 0) { if(system("killall motion") == -1) error("Could not stop external motion", 1); printLog("External motion detection stopped\n"); } else { if (cfg_val[c_motion_detection] == 0) { if(system("motion") == -1) error("Could not start external motion", 1); printLog("External motion detection started\n"); } else { printLog("Motion already running. md 1 ignored\n"); } } } else { if(par0 == 0) { printLog("Internal motion detection stopped\n"); } else { printLog("Internal motion detection started\n"); } } cfg_val[c_motion_detection] = par0?1:0; start_all(0); updateStatus(); break; case sc: set_counts(); printLog("Scan for highest count\n"); break; case rs: printLog("Reset settings to defaults\n"); stop_all(); read_config("/etc/raspimjpeg", 1); saveUserConfig(cfg_stru[c_user_config]); start_all(0); break; case bu: key = c_video_buffer; break; case vp: stop_all(); addUserValue(c_vector_preview, pars[0]); start_all(0); break; case mn: key = c_motion_noise; break; case mt: key = c_motion_threshold; break; case mi: key = c_motion_image + 1000; break; case mb: key = c_motion_startframes; break; case me: key = c_motion_stopframes; break; case mf: key = c_motion_file; break; case vm: key = c_vector_mode; break; case sy: exec_macro(parstring, NULL); break; case cn: stop_all(); addUserValue(c_camera_num, pars[0]); start_all(0); break; default: printLog("Unrecognised pipe command\n"); break; }