2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Control Utility, $Date$, $Revision$
|
2003-01-12 02:22:27 +08:00
|
|
|
// Copyright (C) 2003 Philip Coombes
|
2002-09-24 06:08:50 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
2002-09-16 17:19:24 +08:00
|
|
|
#include <getopt.h>
|
|
|
|
#include "zm.h"
|
|
|
|
|
2003-01-16 22:53:26 +08:00
|
|
|
void Usage( int status=-1 )
|
2002-11-01 06:12:53 +08:00
|
|
|
{
|
2003-03-06 01:22:39 +08:00
|
|
|
fprintf( stderr, "zmu <-d device_no> [-v] [function]\n" );
|
2003-01-16 22:53:26 +08:00
|
|
|
fprintf( stderr, "zmu [-m monitor_id] [-v] [function]\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, "Options:\n" );
|
2003-01-16 22:53:26 +08:00
|
|
|
fprintf( stderr, " -d, --device <device_no> : Get the current video device settings for /dev/video<device_no>\n" );
|
2002-12-11 07:29:22 +08:00
|
|
|
fprintf( stderr, " -m, --monitor <monitor_id> : Specify which monitor to address, default 1 if absent\n" );
|
2003-01-16 22:53:26 +08:00
|
|
|
fprintf( stderr, " -v, --verbose : Produce more verbose output\n" );
|
2003-03-06 01:22:39 +08:00
|
|
|
fprintf( stderr, " -q, --query : Query the current settings for the device or monitor\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, " -s, --state : Output the current monitor state, 0 = idle, 1 = alarm, 2 = alert\n" );
|
2002-11-01 06:17:23 +08:00
|
|
|
fprintf( stderr, " -i, --image [image_index] : Write captured image to disk as <monitor_name>.jpg, last image captured\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, " or specified ring buffer index if given.\n" );
|
|
|
|
fprintf( stderr, " -t, --timestamp [image_index] : Output captured image timestamp, last image captured or specified\n" );
|
|
|
|
fprintf( stderr, " ring buffer index if given\n" );
|
|
|
|
fprintf( stderr, " -r, --read_index : Output ring buffer read index\n" );
|
|
|
|
fprintf( stderr, " -w, --write_index : Output ring buffer write index\n" );
|
2002-11-28 00:23:04 +08:00
|
|
|
fprintf( stderr, " -e, --event : Output last event index\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, " -f, --fps : Output last Frames Per Second captured reading\n" );
|
|
|
|
fprintf( stderr, " -z, --zones : Write last captured image overlaid with zones to <monitor_name>-Zones.jpg\n" );
|
2002-12-11 07:29:22 +08:00
|
|
|
fprintf( stderr, " -a, --alarm : Force alarm in monitor, this will trigger recording until cancelled with -c\n" );
|
|
|
|
fprintf( stderr, " -c, --cancel : Cancel a forced alarm in monitor, required after being enabled with -a\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, " -h, --help - This screen\n" );
|
2003-03-06 01:22:39 +08:00
|
|
|
fprintf( stderr, "Note, only the -q/--query option is valid with -d/--device\n" );
|
2002-11-01 06:12:53 +08:00
|
|
|
|
2003-01-16 22:53:26 +08:00
|
|
|
exit( status );
|
2002-11-01 06:12:53 +08:00
|
|
|
}
|
|
|
|
|
2002-10-28 22:33:57 +08:00
|
|
|
int main( int argc, char *argv[] )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
static struct option long_options[] = {
|
2003-01-16 22:53:26 +08:00
|
|
|
{"device", 1, 0, 'd'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{"monitor", 1, 0, 'm'},
|
2003-01-16 22:53:26 +08:00
|
|
|
{"verbose", 0, 0, 'v'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{"image", 2, 0, 'i'},
|
|
|
|
{"timestamp", 2, 0, 't'},
|
|
|
|
{"state", 0, 0, 's'},
|
|
|
|
{"read_index", 0, 0, 'r'},
|
|
|
|
{"write_index", 0, 0, 'w'},
|
2002-11-28 00:23:04 +08:00
|
|
|
{"event", 0, 0, 'e'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{"fps", 0, 0, 'f'},
|
|
|
|
{"zones", 0, 0, 'z'},
|
2002-12-11 07:29:22 +08:00
|
|
|
{"alarm", 0, 0, 'a'},
|
|
|
|
{"cancel", 0, 0, 'c'},
|
2003-03-06 01:14:17 +08:00
|
|
|
{"query", 0, 0, 'q'},
|
2002-11-01 06:12:53 +08:00
|
|
|
{"help", 0, 0, 'h'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2003-01-16 22:53:26 +08:00
|
|
|
int dev_id = -1;
|
|
|
|
int mon_id = 1;
|
|
|
|
bool verbose = false;
|
2003-01-13 18:51:52 +08:00
|
|
|
typedef enum {
|
|
|
|
BOGUS=0x0000,
|
|
|
|
STATE=0x0001,
|
|
|
|
IMAGE=0x0002,
|
|
|
|
TIME=0x0004,
|
|
|
|
READ_IDX=0x0008,
|
|
|
|
WRITE_IDX=0x0010,
|
|
|
|
EVENT=0x0020,
|
|
|
|
FPS=0x0040,
|
|
|
|
ZONES=0x0080,
|
|
|
|
ALARM=0x0100,
|
2003-03-06 01:14:17 +08:00
|
|
|
CANCEL=0x0200,
|
|
|
|
QUERY=0x0400
|
2003-01-13 18:51:52 +08:00
|
|
|
} Function;
|
|
|
|
Function function = BOGUS;
|
|
|
|
|
2002-09-16 17:19:24 +08:00
|
|
|
int image_idx = -1;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int this_option_optind = optind ? optind : 1;
|
|
|
|
int option_index = 0;
|
2002-11-01 06:12:53 +08:00
|
|
|
int opterr = 1;
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2003-03-06 01:14:17 +08:00
|
|
|
int c = getopt_long (argc, argv, "d:m:vsrwie::t::fzacqh", long_options, &option_index);
|
2002-09-16 17:19:24 +08:00
|
|
|
if (c == -1)
|
2002-11-01 06:12:53 +08:00
|
|
|
{
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
2002-11-01 06:12:53 +08:00
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
2003-01-16 22:53:26 +08:00
|
|
|
case 'd':
|
|
|
|
dev_id = atoi(optarg);
|
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case 'm':
|
2003-01-16 22:53:26 +08:00
|
|
|
mon_id = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = true;
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
case 's':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | STATE);
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
case 'i':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | IMAGE);
|
2002-09-16 17:19:24 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
image_idx = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | TIME);
|
2002-09-16 17:19:24 +08:00
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
image_idx = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | READ_IDX);
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
case 'w':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | WRITE_IDX);
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
2002-11-28 00:23:04 +08:00
|
|
|
case 'e':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | EVENT);
|
2002-11-28 00:23:04 +08:00
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case 'f':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | FPS);
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
case 'z':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | ZONES);
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
2002-12-11 07:29:22 +08:00
|
|
|
case 'a':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | ALARM);
|
2002-12-11 07:29:22 +08:00
|
|
|
break;
|
|
|
|
case 'c':
|
2003-01-13 18:51:52 +08:00
|
|
|
function = Function(function | CANCEL);
|
2002-12-11 07:29:22 +08:00
|
|
|
break;
|
2003-03-06 01:14:17 +08:00
|
|
|
case 'q':
|
|
|
|
function = Function(function | QUERY);
|
|
|
|
break;
|
2002-11-01 06:12:53 +08:00
|
|
|
case 'h':
|
2003-01-16 22:53:26 +08:00
|
|
|
Usage( 0 );
|
2002-11-01 06:12:53 +08:00
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case '?':
|
2002-11-01 06:12:53 +08:00
|
|
|
Usage();
|
2002-09-16 17:19:24 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//fprintf( stderr, "?? getopt returned character code 0%o ??\n", c );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
{
|
2002-11-01 06:12:53 +08:00
|
|
|
fprintf( stderr, "Extraneous options, " );
|
2002-09-16 17:19:24 +08:00
|
|
|
while (optind < argc)
|
2003-01-16 22:53:26 +08:00
|
|
|
fprintf( stderr, "%s ", argv[optind++]);
|
|
|
|
fprintf( stderr, "\n");
|
2002-11-01 06:12:53 +08:00
|
|
|
Usage();
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|
|
|
|
|
2003-03-06 01:22:39 +08:00
|
|
|
if ( dev_id >= 0 && function != QUERY )
|
2003-01-16 22:53:26 +08:00
|
|
|
{
|
2003-03-06 01:22:39 +08:00
|
|
|
fprintf( stderr, "Error, -d option cannot be used with this options\n" );
|
2003-01-16 22:53:26 +08:00
|
|
|
Usage();
|
|
|
|
}
|
|
|
|
//printf( "Monitor %d, Function %d\n", mon_id, function );
|
2002-09-16 17:19:24 +08:00
|
|
|
|
|
|
|
dbg_name = "zmu";
|
2002-09-21 03:52:02 +08:00
|
|
|
dbg_level = -1;
|
2002-09-16 17:19:24 +08:00
|
|
|
|
|
|
|
DbgInit();
|
|
|
|
|
|
|
|
if ( !mysql_init( &dbconn ) )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't initialise structure: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
2003-01-11 01:03:03 +08:00
|
|
|
if ( !mysql_connect( &dbconn, ZM_DB_SERVER, ZM_DB_USERB, ZM_DB_PASSB ) )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't connect to server: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
2003-01-11 01:03:03 +08:00
|
|
|
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't select database: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( dev_id >= 0 )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
2003-01-16 22:53:26 +08:00
|
|
|
char vid_string[1024] = "";
|
2003-03-21 06:34:25 +08:00
|
|
|
bool ok = LocalCamera::GetCurrentSettings( dev_id, vid_string, verbose );
|
2003-01-16 22:53:26 +08:00
|
|
|
printf( "%s", vid_string );
|
|
|
|
exit( ok?0:-1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-03-06 01:14:17 +08:00
|
|
|
Monitor *monitor = Monitor::Load( mon_id, function&QUERY );
|
2003-01-16 22:53:26 +08:00
|
|
|
|
|
|
|
if ( monitor )
|
2003-01-13 18:51:52 +08:00
|
|
|
{
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
printf( "Monitor %d(%s)\n", monitor->Id(), monitor->Name() );
|
|
|
|
}
|
|
|
|
char separator = ' ';
|
|
|
|
bool have_output = false;
|
|
|
|
if ( function & STATE )
|
|
|
|
{
|
|
|
|
Monitor::State state = monitor->GetState();
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Current state: %s\n", state==Monitor::ALARM?"Alarm":(state==Monitor::ALERT?"Alert":"Idle") );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", state );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( function & TIME )
|
|
|
|
{
|
2003-03-11 23:17:30 +08:00
|
|
|
struct timeval timestamp = monitor->GetTimestamp( image_idx );
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
char timestamp_str[64] = "None";
|
2003-03-11 23:17:30 +08:00
|
|
|
if ( timestamp.tv_sec )
|
|
|
|
strftime( timestamp_str, sizeof(timestamp_str), "%Y-%m-%d %H:%M:%S", localtime( ×tamp.tv_sec ) );
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( image_idx == -1 )
|
2003-03-11 23:17:30 +08:00
|
|
|
printf( "Time of last image capture: %s.%02d\n", timestamp_str, timestamp.tv_usec/10000 );
|
2003-01-16 22:53:26 +08:00
|
|
|
else
|
2003-03-11 23:17:30 +08:00
|
|
|
printf( "Time of image %d capture: %s.%02d\n", image_idx, timestamp_str, timestamp.tv_usec/10000 );
|
2003-01-16 22:53:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
2003-03-11 23:17:30 +08:00
|
|
|
printf( "%d.%02d", timestamp.tv_sec, timestamp.tv_usec/10000 );
|
2003-01-16 22:53:26 +08:00
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( function & READ_IDX )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Last read index: %d\n", monitor->GetLastReadIndex() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", monitor->GetLastReadIndex() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( function & WRITE_IDX )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Last write index: %d\n", monitor->GetLastWriteIndex() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", monitor->GetLastWriteIndex() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( function & EVENT )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Last event id: %d\n", monitor->GetLastEvent() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%d", monitor->GetLastEvent() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( function & FPS )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Current capture rate: %.2f frames per second\n", monitor->GetLastEvent() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( have_output ) printf( "%c", separator );
|
|
|
|
printf( "%.2f", monitor->GetFPS() );
|
|
|
|
have_output = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( function & IMAGE )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
{
|
|
|
|
if ( image_idx == -1 )
|
|
|
|
printf( "Dumping last image captured to %s.jpg\n", monitor->Name() );
|
|
|
|
else
|
|
|
|
printf( "Dumping buffer image %d to %s.jpg\n", image_idx, monitor->Name() );
|
|
|
|
}
|
|
|
|
monitor->GetImage( image_idx );
|
|
|
|
}
|
|
|
|
if ( function & ZONES )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Dumping zone image to %s-Zones.jpg\n", monitor->Name() );
|
|
|
|
monitor->ReloadZones();
|
|
|
|
}
|
|
|
|
if ( function & ALARM )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Forcing alarm\n" );
|
|
|
|
monitor->ForceAlarm();
|
|
|
|
}
|
|
|
|
if ( function & CANCEL )
|
|
|
|
{
|
|
|
|
if ( verbose )
|
|
|
|
printf( "Cancelling alarm\n" );
|
|
|
|
monitor->CancelAlarm();
|
|
|
|
}
|
2003-03-06 01:14:17 +08:00
|
|
|
if ( function & QUERY )
|
|
|
|
{
|
|
|
|
char mon_string[1024] = "";
|
|
|
|
monitor->DumpSettings( mon_string, verbose );
|
|
|
|
printf( "%s\n", mon_string );
|
|
|
|
}
|
2003-01-16 22:53:26 +08:00
|
|
|
if ( have_output )
|
|
|
|
{
|
|
|
|
printf( "\n" );
|
|
|
|
}
|
|
|
|
if ( !function )
|
|
|
|
{
|
|
|
|
Usage();
|
|
|
|
}
|
2003-01-13 18:51:52 +08:00
|
|
|
}
|
2003-01-16 22:53:26 +08:00
|
|
|
else
|
2002-11-01 06:12:53 +08:00
|
|
|
{
|
2003-01-16 22:53:26 +08:00
|
|
|
fprintf( stderr, "Error, invalid monitor id %d", mon_id );
|
|
|
|
exit( -1 );
|
2002-11-01 06:12:53 +08:00
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|
2002-10-28 22:33:57 +08:00
|
|
|
return( 0 );
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|