reworked main loop, switched command line argument parsing to argp

This commit is contained in:
john30
2015-01-25 19:06:02 +01:00
parent a721fe28dc
commit 89349e7d21
+68 -68
View File
@@ -1,68 +1,68 @@
/*
* Copyright (C) John Baier 2014-2015 <ebusd@johnm.de>
*
* This file is part of ebusd.
*
* ebusd 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 3 of the License, or
* (at your option) any later version.
*
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
*/
#ifndef MAIN_H_
#define MAIN_H_
#include "result.h"
#include "data.h"
#include "message.h"
/** \file main.h */
/** A structure holding all program options. */
struct options
{
const char* device; //!< eBUS device (serial device or ip:port) [/dev/ttyUSB0]
bool noDeviceCheck; //!< skip serial eBUS device test
const char* configPath; //!< path to CSV configuration files [/etc/ebusd]
bool checkConfig; //!< only check CSV config files, then stop
int pollInterval; //!< poll interval in seconds, 0 to disable [5]
unsigned char address; //!< own bus address [FF]
bool answer; //!< answer to requests from other masters
int acquireTimeout; //!< bus acquisition timeout in us [9400]
int acquireRetries; //!< number of retries for bus acquisition [2]
int sendRetries; //!< number of retries for failed sends [2]
int receiveTimeout; //!< timeout for receiving answer from slave in us [15000]
int numberMasters; //!< expected number of masters for arbitration [5]
bool foreground; //!< run in foreground
int port; //!< port to listen for client connections [8888]
bool localhost; //!< listen on 127.0.0.1 interface only
const char* logFile; //!< log file name [/var/log/ebusd.log]
bool logRaw; //!< log each received/sent byte on the bus
bool dump; //!< dump received bytes
const char* dumpFile; //!< dump file name [/tmp/ebus_dump.bin]
int dumpSize; //!< maximum size of dump file in kB [100]
};
/**
* Load the message definitions from the configuration files.
* @param templates the @a DataFieldTemplates to load the templates into.
* @param messages the @a MessageMap to load the messages into.
* @param verbose whether to verbosely log problems.
* @return the result code.
*/
result_t loadConfigFiles(DataFieldTemplates* templates, MessageMap* messages, bool verbose=false);
#endif // MAIN_H_
/*
* Copyright (C) John Baier 2014-2015 <ebusd@johnm.de>
*
* This file is part of ebusd.
*
* ebusd 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 3 of the License, or
* (at your option) any later version.
*
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
*/
#ifndef MAIN_H_
#define MAIN_H_
#include "result.h"
#include "data.h"
#include "message.h"
/** \file main.h */
/** A structure holding all program options. */
struct options
{
const char* device; //!< eBUS device (serial device or ip:port) [/dev/ttyUSB0]
bool noDeviceCheck; //!< skip serial eBUS device test
const char* configPath; //!< path to CSV configuration files [/etc/ebusd]
bool checkConfig; //!< only check CSV config files, then stop
int pollInterval; //!< poll interval in seconds, 0 to disable [5]
unsigned char address; //!< own bus address [FF]
bool answer; //!< answer to requests from other masters
int acquireTimeout; //!< bus acquisition timeout in us [9400]
int acquireRetries; //!< number of retries for bus acquisition [2]
int sendRetries; //!< number of retries for failed sends [2]
int receiveTimeout; //!< timeout for receiving answer from slave in us [15000]
int numberMasters; //!< expected number of masters for arbitration [5]
bool foreground; //!< run in foreground
int port; //!< port to listen for client connections [8888]
bool localhost; //!< listen on 127.0.0.1 interface only
const char* logFile; //!< log file name [/var/log/ebusd.log]
bool logRaw; //!< log each received/sent byte on the bus
bool dump; //!< dump received bytes
const char* dumpFile; //!< dump file name [/tmp/ebus_dump.bin]
int dumpSize; //!< maximum size of dump file in kB [100]
};
/**
* Load the message definitions from the configuration files.
* @param templates the @a DataFieldTemplates to load the templates into.
* @param messages the @a MessageMap to load the messages into.
* @param verbose whether to verbosely log problems.
* @return the result code.
*/
result_t loadConfigFiles(DataFieldTemplates* templates, MessageMap* messages, bool verbose=false);
#endif // MAIN_H_