2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Control Utility, $Date$, $Revision$
|
2002-09-24 06:08:50 +08:00
|
|
|
// Copyright (C) 2002 Philip Coombes
|
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2002-11-01 06:12:53 +08:00
|
|
|
void Usage()
|
|
|
|
{
|
|
|
|
fprintf( stderr, "zmu [-m monitor_id] [function]\n" );
|
|
|
|
fprintf( stderr, "Options:\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" );
|
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" );
|
|
|
|
|
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
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[] = {
|
|
|
|
{"monitor", 1, 0, 'm'},
|
|
|
|
{"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'},
|
2002-11-01 06:12:53 +08:00
|
|
|
{"help", 0, 0, 'h'},
|
2002-09-16 17:19:24 +08:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
int id = 1;
|
2002-12-11 07:29:22 +08:00
|
|
|
enum { BOGUS, STATE, IMAGE, TIME, READ_IDX, WRITE_IDX, EVENT, FPS, ZONES, ALARM, CANCEL } 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
|
|
|
|
2002-12-11 07:29:22 +08:00
|
|
|
int c = getopt_long (argc, argv, "m:srwie::t::fzach", 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)
|
|
|
|
{
|
|
|
|
case 'm':
|
|
|
|
id = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
function = STATE;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
function = IMAGE;
|
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
image_idx = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
function = TIME;
|
|
|
|
if ( optarg )
|
|
|
|
{
|
|
|
|
image_idx = atoi( optarg );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
function = READ_IDX;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
function = WRITE_IDX;
|
|
|
|
break;
|
2002-11-28 00:23:04 +08:00
|
|
|
case 'e':
|
|
|
|
function = EVENT;
|
|
|
|
break;
|
2002-09-16 17:19:24 +08:00
|
|
|
case 'f':
|
|
|
|
function = FPS;
|
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
function = ZONES;
|
|
|
|
break;
|
2002-12-11 07:29:22 +08:00
|
|
|
case 'a':
|
|
|
|
function = ALARM;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
function = CANCEL;
|
|
|
|
break;
|
2002-11-01 06:12:53 +08:00
|
|
|
case 'h':
|
|
|
|
Usage();
|
|
|
|
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)
|
|
|
|
printf ("%s ", argv[optind++]);
|
|
|
|
printf ("\n");
|
2002-11-01 06:12:53 +08:00
|
|
|
Usage();
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//printf( "Monitor %d, Function %d, ImageIdx %d\n", id, function, image_idx );
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Monitor *monitor = Monitor::Load( id );
|
|
|
|
|
|
|
|
if ( monitor )
|
|
|
|
{
|
|
|
|
if ( function == STATE )
|
|
|
|
{
|
|
|
|
printf( "%d\n", monitor->GetState() );
|
|
|
|
}
|
|
|
|
else if ( function == IMAGE )
|
|
|
|
{
|
|
|
|
monitor->GetImage( image_idx );
|
|
|
|
}
|
|
|
|
else if ( function == TIME )
|
|
|
|
{
|
|
|
|
printf( "%d\n", monitor->GetTimestamp( image_idx ) );
|
|
|
|
}
|
|
|
|
else if ( function == READ_IDX )
|
|
|
|
{
|
|
|
|
printf( "%d\n", monitor->GetLastReadIndex() );
|
|
|
|
}
|
|
|
|
else if ( function == WRITE_IDX )
|
|
|
|
{
|
|
|
|
printf( "%d\n", monitor->GetLastWriteIndex() );
|
|
|
|
}
|
2002-11-28 00:23:04 +08:00
|
|
|
else if ( function == EVENT )
|
|
|
|
{
|
|
|
|
printf( "%d\n", monitor->GetLastEvent() );
|
|
|
|
}
|
2002-09-16 17:19:24 +08:00
|
|
|
else if ( function == FPS )
|
|
|
|
{
|
|
|
|
printf( "%.2f\n", monitor->GetFPS() );
|
|
|
|
}
|
|
|
|
else if ( function == ZONES )
|
|
|
|
{
|
|
|
|
monitor->ReloadZones();
|
|
|
|
}
|
2002-12-11 07:29:22 +08:00
|
|
|
else if ( function == ALARM )
|
|
|
|
{
|
|
|
|
monitor->ForceAlarm();
|
|
|
|
}
|
|
|
|
else if ( function == CANCEL )
|
|
|
|
{
|
|
|
|
monitor->CancelAlarm();
|
|
|
|
}
|
2002-11-01 06:12:53 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Usage();
|
|
|
|
}
|
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
|
|
|
}
|