Initial commit of files
This commit is contained in:
132
daemons/trackd/trackd.cpp
Normal file
132
daemons/trackd/trackd.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
//
|
||||
// Serial Daemon (similar to ser2net)
|
||||
// Neal Probert
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "TrackDaemon.h"
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
extern int optind, opterr, optopt;
|
||||
|
||||
//
|
||||
// any port
|
||||
//
|
||||
|
||||
static const char *helptext =
|
||||
"stdiod [options]\n"
|
||||
"\t-d debug (foreground with stdio)\n"
|
||||
"\t-g host gpsd\n"
|
||||
"\t-h help\n"
|
||||
"\t-i id set my id\n"
|
||||
"\t-c uri host:port source data (CardiacMonitor)\n"
|
||||
"\t-o logfile format:/path/to/file.log\n"
|
||||
"\t-r uri remote web host for upload\n"
|
||||
"\t-S service TCP service\n";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char c; /* we have character */
|
||||
|
||||
TrackDaemon Track;
|
||||
|
||||
/* options */
|
||||
int debug = 0; // run in foreground, leaves stdio open
|
||||
|
||||
/* connections */
|
||||
char *gpsd = NULL; // "localhost";
|
||||
char *host = NULL;
|
||||
char *id = NULL;
|
||||
char *log = NULL;
|
||||
char *service = TRACKD_PORT;
|
||||
|
||||
// add command line args
|
||||
while ( (c = getopt( argc, argv, "dg:hi:o:r:S:" )) > 0 )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'd':
|
||||
debug = 1;
|
||||
break;
|
||||
case 'g':
|
||||
gpsd = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
puts( helptext );
|
||||
return 0;
|
||||
case 'i':
|
||||
id = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
log = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
host = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
service = optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf( stderr, "Unknown option -%c\n", c );
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// set my id (hostname by default)
|
||||
if ( id )
|
||||
Track.SetId( id );
|
||||
|
||||
// monitor
|
||||
if ( gpsd )
|
||||
{
|
||||
// GPSd
|
||||
int remote = Track.GpsdServer( gpsd );
|
||||
|
||||
if ( remote < 0 )
|
||||
{
|
||||
fprintf( stderr, "Unable to connect to gpsd: %s\n", gpsd );
|
||||
// exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// output
|
||||
if ( host )
|
||||
{
|
||||
if ( Track.TrackOpen( host ) < 0 )
|
||||
{
|
||||
fprintf( stderr, "Unable to open vehicle location server: %s!\n", host );
|
||||
// exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if ( log )
|
||||
{
|
||||
if ( !Track.LogOpen( log ) )
|
||||
{
|
||||
fprintf( stderr, "Unable to open log file: %s!\n", log );
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// TCP listener
|
||||
if ( Track.StartService( TRACKD_NAME, NULL, service, debug ) >= 0 )
|
||||
return Track.RunService();
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user