Initial commit of files
This commit is contained in:
145
daemons/rtcmd/rtcmd.cpp
Normal file
145
daemons/rtcmd/rtcmd.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
//
|
||||
// RTCM Daemon (rtcmd.cpp)
|
||||
// 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 "RtcmDaemon.h"
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
extern int optind, opterr, optopt;
|
||||
|
||||
//
|
||||
// This was written because gpsd didn't have working RTCM104_SERVICE
|
||||
// or the ability to do UDP broadcasts.
|
||||
//
|
||||
|
||||
static const char *helptext =
|
||||
"rtcm -r dgpsip://host [options]\n"
|
||||
"\t-d debug (foreground with stdio)\n"
|
||||
"\t-h help\n"
|
||||
"\t-m network UDP broadcast RTCM data\n"
|
||||
"\t-r uri dgpsip://host or ntrip://user@pass:host:port/mount\n"
|
||||
"\t-t uri OpenGTS server\n"
|
||||
"\t-w WDM DSRC broadcast RTCM corrections\n"
|
||||
"\t-S service TCP service (default=2101)\n"
|
||||
"\t-T timeout reconnect timeout in seconds (default=15)\n";
|
||||
|
||||
static RtcmDaemon Rtcm;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char c; /* we have character */
|
||||
|
||||
/* options */
|
||||
int debug = 0; // run in foreground, leaves stdio open
|
||||
int dsrc_wsm = 0;
|
||||
int timeout = 15;
|
||||
|
||||
/* dgpsip server */
|
||||
char *host = NULL;
|
||||
|
||||
/* service/port */
|
||||
char *service = (char *)"2101"; // "rtcm-sc104"
|
||||
|
||||
/* udp broadcast */
|
||||
char *mcast = NULL;
|
||||
|
||||
/* log */
|
||||
char *outfile = NULL;
|
||||
|
||||
// add command line args
|
||||
while ( (c = getopt( argc, argv, "dhm:o:r:s:t:S:T:" )) > 0 )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'd':
|
||||
debug = 1;
|
||||
break;
|
||||
case 'h':
|
||||
puts( helptext );
|
||||
return 0;
|
||||
case 'm': // udp broadcast
|
||||
mcast = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
break;
|
||||
case 'r': // rtcm-sc104 host
|
||||
host = optarg;
|
||||
break;
|
||||
case 't':
|
||||
break;
|
||||
case 'S':
|
||||
service = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
timeout = atoi(optarg);
|
||||
if ( timeout == 0 )
|
||||
timeout = 30;
|
||||
break;
|
||||
case 'w': // DSRC WSM broadcast or listen
|
||||
fprintf( stderr, "DSRC WSM support not yet available!\n" );
|
||||
// dsrc_wsm = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf( stderr, "Unknown option -%c\n", c );
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// input
|
||||
if ( host )
|
||||
{
|
||||
Rtcm.SetTimeout( timeout * 1000000L );
|
||||
|
||||
// RTCM server
|
||||
int remote = Rtcm.RtcmConnect( host );
|
||||
|
||||
if ( remote < 0 )
|
||||
{
|
||||
fprintf( stderr, "Unable to connect to rtcm-sc104 source host: %s\n", host );
|
||||
if ( debug )
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// output
|
||||
if ( mcast )
|
||||
{
|
||||
int bcast = Rtcm.RtcmBroadcast( mcast );
|
||||
|
||||
if ( bcast < 0 )
|
||||
{
|
||||
fprintf( stderr, "Unable to create UDP broadcast!\n" );
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else if ( dsrc_wsm )
|
||||
{
|
||||
}
|
||||
|
||||
if ( outfile )
|
||||
Rtcm.LogOpen( outfile, 0 );
|
||||
|
||||
// TCP listener
|
||||
if ( Rtcm.StartService( RTCMD_NAME, NULL, service, debug ) >= 0 )
|
||||
return Rtcm.RunService();
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user