Merge branch 'master' of git://github.com/yuhu-/ebusd
This commit is contained in:
@@ -60,7 +60,7 @@ void ConfigCommands::setType(const FileType type)
|
||||
delete m_configfile;
|
||||
|
||||
switch (type) {
|
||||
case CSV:
|
||||
case ft_csv:
|
||||
m_configfile = new ConfigFileCSV();
|
||||
m_extension = "csv";
|
||||
break;
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
#include <vector>
|
||||
|
||||
/** available file endings / types. */
|
||||
enum FileType { CSV };
|
||||
enum FileType {
|
||||
ft_csv
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief base class for config files.
|
||||
|
||||
+26
-6
@@ -17,6 +17,10 @@
|
||||
* along with ebusd. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "port.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@@ -24,7 +28,10 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#ifdef HAVE_PPOLL
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
bool Device::isOpen()
|
||||
{
|
||||
@@ -64,20 +71,33 @@ ssize_t Device::recvBytes(const long timeout, size_t maxCount)
|
||||
return -1; // TODO RESULT_ERR_DEVICE
|
||||
|
||||
if (timeout > 0) {
|
||||
int ret, nfds = 1;
|
||||
struct pollfd fds[nfds];
|
||||
int ret;
|
||||
struct timespec tdiff;
|
||||
|
||||
// set select timeout
|
||||
tdiff.tv_sec = 0;
|
||||
tdiff.tv_nsec = timeout*1000;
|
||||
|
||||
#ifdef HAVE_PPOLL
|
||||
int nfds = 1;
|
||||
struct pollfd fds[nfds];
|
||||
|
||||
memset(fds, 0, sizeof(fds));
|
||||
|
||||
fds[0].fd = m_fd;
|
||||
fds[0].events = POLLIN;
|
||||
|
||||
ret = ppoll(fds, nfds, &tdiff, NULL);
|
||||
#else
|
||||
#ifdef HAVE_PSELECT
|
||||
fd_set readfds;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(m_fd, &readfds);
|
||||
|
||||
ret = pselect(m_fd + 1, &readfds, NULL, NULL, &tdiff, NULL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (ret == -1) return -1; // TODO RESULT_ERR_DEVICE
|
||||
if (ret == 0) return -2; // TODO RESULT_ERR_TIMEOUT
|
||||
@@ -232,9 +252,9 @@ Port::Port(const std::string deviceName, const bool noDeviceCheck)
|
||||
|
||||
if (strchr(deviceName.c_str(), '/') == NULL &&
|
||||
strchr(deviceName.c_str(), ':') != NULL)
|
||||
setType(NETWORK);
|
||||
setType(dt_network);
|
||||
else
|
||||
setType(SERIAL);
|
||||
setType(dt_serial);
|
||||
}
|
||||
|
||||
void Port::setType(const DeviceType type)
|
||||
@@ -243,10 +263,10 @@ void Port::setType(const DeviceType type)
|
||||
delete m_device;
|
||||
|
||||
switch (type) {
|
||||
case SERIAL:
|
||||
case dt_serial:
|
||||
m_device = new DeviceSerial();
|
||||
break;
|
||||
case NETWORK:
|
||||
case dt_network:
|
||||
m_device = new DeviceNetwork();
|
||||
break;
|
||||
};
|
||||
|
||||
+4
-1
@@ -26,7 +26,10 @@
|
||||
#include <unistd.h>
|
||||
|
||||
/** available device types. */
|
||||
enum DeviceType { SERIAL, NETWORK };
|
||||
enum DeviceType {
|
||||
dt_serial,
|
||||
dt_network,
|
||||
};
|
||||
|
||||
/** max bytes write to bus. */
|
||||
#define MAX_WRITE_SIZE 1
|
||||
|
||||
@@ -51,7 +51,7 @@ void readCSV(std::istream& is, Commands& commands){
|
||||
|
||||
int main()
|
||||
{
|
||||
Commands* commands = ConfigCommands("test", CSV).getCommands();
|
||||
Commands* commands = ConfigCommands("test", ft_csv).getCommands();
|
||||
std::cout << "Commands: " << commands->sizeCmdDB() << std::endl;
|
||||
|
||||
//~ std::string data("g ci password pin1");
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
int main() {
|
||||
|
||||
std::string dir("test");
|
||||
ConfigCommands config(dir, CSV);
|
||||
ConfigCommands config(dir, ft_csv);
|
||||
|
||||
Commands* commands = config.getCommands();
|
||||
|
||||
|
||||
@@ -29,11 +29,14 @@
|
||||
#include <unistd.h>
|
||||
|
||||
/** static char array with logging area names */
|
||||
static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus" };
|
||||
static const char* AreaNames[Size_of_Areas] = { "bas", "net", "bus", "cyc" };
|
||||
|
||||
/** static char array with logging level names */
|
||||
static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "debug" };
|
||||
|
||||
/** inline function of log2 */
|
||||
inline double Log2(double n) { return log(n) / log(2); }
|
||||
|
||||
int calcAreas(const std::string areas)
|
||||
{
|
||||
int m_areas = 0;
|
||||
@@ -120,7 +123,7 @@ void* LogSink::run()
|
||||
void LogConsole::write(const LogMessage& message) const
|
||||
{
|
||||
std::cout << message.getTime() << " ["
|
||||
<< AreaNames[(int)log2(message.getArea())] << " "
|
||||
<< AreaNames[(int)Log2(message.getArea())] << " "
|
||||
<< LevelNames[message.getLevel()] << "] "
|
||||
<< message.getText() << std::endl;
|
||||
}
|
||||
@@ -133,7 +136,7 @@ void LogFile::write(const LogMessage& message) const
|
||||
|
||||
if (file.is_open() == true) {
|
||||
file << message.getTime() << " ["
|
||||
<< AreaNames[(int)log2(message.getArea())] << " "
|
||||
<< AreaNames[(int)Log2(message.getArea())] << " "
|
||||
<< LevelNames[message.getLevel()] << "] "
|
||||
<< message.getText() << std::endl;
|
||||
file.close();
|
||||
|
||||
@@ -33,8 +33,9 @@ enum AreasType {
|
||||
bas=1, // basis
|
||||
net=2, // network
|
||||
bus=4, // ebus
|
||||
all=7, // type for all subsystems
|
||||
Size_of_Areas=3, // number of possible areas
|
||||
cyc=8, // cycle
|
||||
all=15, // type for all subsystems
|
||||
Size_of_Areas=4, // number of possible areas
|
||||
};
|
||||
|
||||
/** available logging levels */
|
||||
|
||||
@@ -137,6 +137,7 @@ public:
|
||||
|
||||
/**
|
||||
* @brief start listening of tcp socket.
|
||||
* @return result of low level functions.
|
||||
*/
|
||||
int start();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user