| | |
| | | } |
| | | |
| | | |
| | | int turn_camera(char *status) |
| | | { |
| | | FILE *fp = NULL; |
| | | char buf[256]; |
| | | int pid; |
| | | int running; |
| | | char cmd[256]; |
| | | |
| | | |
| | | /* use lsusb command check Logic C920 camera exist or not */ |
| | | fp = popen("lsusb | grep -v grep | grep C920", "r"); |
| | | if( !fp ) |
| | | { |
| | | log_err("popen to check C920 failure: %s\n", strerror(errno)); |
| | | return -1; |
| | | } |
| | | |
| | | memset(buf, 0, sizeof(buf)); |
| | | fgets(buf, sizeof(buf), fp); |
| | | if( !strstr(buf, "C920") ) |
| | | { |
| | | log_err("Logic C920 camera not exist\n"); |
| | | return -2; |
| | | } |
| | | log_nrml("Logic C920 camera exist\n"); |
| | | |
| | | |
| | | fp=popen("ps aux | grep mjpg_streamer | grep -v grep | awk '{print $2}'", "r"); |
| | | if( !fp ) |
| | | { |
| | | log_err("popen to check mjpg_streamer failure: %s\n", strerror(errno)); |
| | | return -1; |
| | | } |
| | | |
| | | memset(buf, 0, sizeof(buf)); |
| | | fgets(buf, sizeof(buf), fp); |
| | | |
| | | pid = atoi(buf); |
| | | if( pid > 1 ) |
| | | { |
| | | log_nrml("mjpg_streamer already working as pid[%d] now\n", pid); |
| | | running = 1; |
| | | } |
| | | else |
| | | { |
| | | log_nrml("mjpg_streamer not running now\n"); |
| | | running = 0; |
| | | } |
| | | |
| | | if( running && strcasestr(status, "off") ) |
| | | { |
| | | log_warn("Stop mjpg_streamer working on C920 now\n"); |
| | | system("/bin/video stop"); |
| | | return 0; |
| | | } |
| | | |
| | | if( !running && strcasestr(status, "on") ) |
| | | { |
| | | log_nrml("Start mjpg_streamer working on C920 now\n"); |
| | | system("/bin/video start"); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | void proc_json_items(cJSON *root) |
| | | { |
| | | int i; |
| | |
| | | if( NULL != (led_item=cJSON_GetObjectItem(array , "C920")) ) |
| | | { |
| | | log_nrml("turn Logic C920 camera '%s'\n", led_item->valuestring); |
| | | turn_camera( led_item->valuestring ); |
| | | } |
| | | } |
| | | } |