#include <signal.h>#include <GpCoreTools.h>#include "CubeDevice.h"#include "CubeTcpServer.h"#include "CubeDaemonApplication.h"#include "dascubedVersion.h"#include "dascubedInstallPath.h"Functions | |
| ApplicationHelp * | help () |
| int | main (int argc, char **argv) |
| PACKAGE_INFO (dascubed, DASCUBED) | |
| ApplicationHelp * help | ( | ) |
References GpCoreTools::ApplicationHelp::addGroup(), GpCoreTools::ApplicationHelp::addOption(), GpCoreTools::ApplicationHelp::setComments(), GpCoreTools::ApplicationHelp::setOptionSummary(), and TRACE.
Referenced by QGpGuiTools::Application::Application(), QGpCoreTools::CoreApplication::CoreApplication(), GpCoreTools::CoreApplication::CoreApplication(), GpCoreTools::DaemonApplication::DaemonApplication(), main(), modeGui(), modeImportanceSampling(), modeNeighborhoodOptimization(), modeSnoopOptimization(), GpCoreTools::CoreApplication::showHelp(), and QGpCoreTools::CoreApplicationPrivate::showHelp().
{
TRACE;
ApplicationHelp * h = new ApplicationHelp;
h->setOptionSummary( "[OPTIONS] plugin_name" );
h->setComments( "Forwards serial data from a DASCube digitizer to Seiscomp and controls "
"DASCube (parameters, start/stop,...).\n"
"'plugin_name' is not used but accepted for Seiscomp compatibility.\n"
"This daemon never goes into background (option -N is useless).");
h->addGroup("", "main");
h->addOption("-d <DEVICE>", "Defines DASCube device (mandatory, automatic completion).");
h->addOption("-s <STATION>", "Set station name, usually the hostname (default=unamed).");
h->addOption("-p <PORT>", "Listen on port PORT (default=2976).");
h->addOption("-no-auto-start", "Do not start automatically DASCube after a successfull "
"connection (default=auto start, debug only).");
h->addOption("-dp <PORT>", "Display port (default=2977).");
return h;
}
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
References GpCoreTools::EventLoop::addStream(), GpCoreTools::CoreApplication::applicationName(), CubeDaemonApplication::close(), CubeDaemonApplication::cubeThread(), GpCoreTools::EventLoop::exec(), help(), GpCoreTools::TcpServerStream::listen(), CubeDevice::setAutoStart(), CubeDaemonApplication::setCubeThread(), GpCoreTools::DaemonApplication::start(), and GpCoreTools::PThread::start().
{
CubeDaemonApplication a(argc, argv, help);
// Options
std::string devicePath;
std::string stationName("unamed");
uint16_t port=2976;
uint16_t displayPort=2977;
bool autoStart=true;
// Check arguments
int i, j = 1;
for (i=1; i<argc; i++) {
const char * arg=argv[i];
if (arg[0]=='-') {
if (strcmp(arg, "-p")==0) {
CoreApplication::checkOptionArg(i, argc, argv, true);
port=atoi(argv[i]);
} else if (strcmp(arg, "-d")==0) {
CoreApplication::checkOptionArg(i, argc, argv, true);
devicePath=argv[i];
} else if (strcmp(arg, "-s")==0) {
CoreApplication::checkOptionArg(i, argc, argv, true);
stationName=argv[i];
} else if(strcmp(arg, "-no-auto-start")==0) {
autoStart=false;
} else if(strcmp(arg, "-dp")==0) {
CoreApplication::checkOptionArg(i, argc, argv, true);
displayPort=atoi(argv[i]);
} else {
ScreenClient::write(0, 2, "Bad daemon option! ");
fprintf(stderr, "%s: bad option %s, see -help\n", a.applicationName(), argv[i]);
CoreApplication::exit(2);
}
} else {
argv[j++] = argv[i];
}
}
if(j<argc) {
argv[j]=0;
argc=j;
}
a.start(); // Never fork
EventLoop loop;
// Use external LCD to show status
ScreenClient * display=new ScreenClient(Address::me(), displayPort);
loop.addStream(display);
ScreenClient::write(0, 2, " ");
// Check path to device
if(devicePath.size()==0) {
ScreenClient::write(0, 2, "Missing option -d! ");
Log::write(0, "[ERROR] missing device path, see -help\n");
Log::write(0, "stop daemon with pid %i\n",getpid());
CoreApplication::exit(2);
}
std::vector<std::string> * devicePaths=File::complete(devicePath);
switch(devicePaths->size()) {
case 0:
ScreenClient::write(0, 2, "No Cube connected! ");
Log::write(0, "[ERROR] no device named %s\n", devicePath.data());
delete devicePaths;
Log::write(0, "stop daemon with pid %i\n",getpid());
CoreApplication::exit(2);
case 1:
devicePath=devicePaths->front();
delete devicePaths;
break;
default:
ScreenClient::write(0, 2, "Two Cubes connected!");
Log::write(0, "[ERROR] more than one device named %s\n", devicePath.data());
delete devicePaths;
Log::write(0, "stop daemon with pid %i\n",getpid());
CoreApplication::exit(2);
}
CubeTcpServer * server=new CubeTcpServer;
while(!server->listen(port, 50)) {
Log::write(1, "cannot listen to port %hu, retry in 10 seconds\n", port);
sleep(10);
}
loop.addStream(server);
a.setCubeThread(new CubeDevice(stationName, devicePath, server));
a.cubeThread()->setAutoStart(autoStart); // Acquisition auto-start
a.cubeThread()->start();
loop.exec();
a.close();
ScreenClient::write(0, 2, " ");
return 0;
}
| PACKAGE_INFO | ( | dascubed | , |
| DASCUBED | |||
| ) |