files buscommand.x and dump.x moved from src/lib/ebus to src/ebusd.

This commit is contained in:
Roland Jax
2014-11-19 21:34:52 +01:00
parent 31246e1431
commit 85c00c9cc7
6 changed files with 10 additions and 10 deletions
-4
View File
@@ -12,16 +12,12 @@ libebus_a_SOURCES = result.cpp \
data.h \
port.cpp \
port.h \
buscommand.cpp \
buscommand.h \
command.cpp \
command.h \
commands.cpp \
commands.h \
configfile.cpp \
configfile.h \
dump.cpp \
dump.h \
decode.cpp \
decode.h \
encode.cpp \
-63
View File
@@ -1,63 +0,0 @@
/*
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
*
* 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/.
*/
#include "buscommand.h"
BusCommand::BusCommand(const std::string commandStr, const bool poll, const bool scan)
: m_poll(poll), m_scan(scan), m_command(commandStr), m_result(), m_resultCode(RESULT_OK)
{
unsigned char dstAddress = m_command[1];
if (dstAddress == BROADCAST)
m_type = broadcast;
else if (isMaster(dstAddress) == true)
m_type = masterMaster;
else
m_type = masterSlave;
pthread_mutex_init(&m_mutex, NULL);
pthread_cond_init(&m_cond, NULL);
}
BusCommand::~BusCommand()
{
pthread_mutex_destroy(&m_mutex);
pthread_cond_destroy(&m_cond);
}
const std::string BusCommand::getMessageStr()
{
std::string result;
if (m_resultCode >= 0) {
if (m_type == masterSlave) {
result = m_command.getDataStr();
result += "00";
result += m_result.getDataStr();
result += "00";
}
else
result = "success";
}
else
result = "error: "+std::string(getResultCodeCStr());
return result;
}
-65
View File
@@ -1,65 +0,0 @@
/*
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
*
* 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 LIBEBUS_BUSCOMMAND_H_
#define LIBEBUS_BUSCOMMAND_H_
#include "symbol.h"
#include "result.h"
enum CommandType { invalid, broadcast, masterMaster, masterSlave };
class BusCommand
{
public:
BusCommand(const std::string command, const bool poll, const bool scan);
~BusCommand();
CommandType getType() const { return m_type; }
bool isPoll() const { return m_poll; }
bool isScan() const { return m_scan; }
SymbolString getCommand() const { return m_command; }
SymbolString getResult() const { return m_result; }
bool isErrorResult() const { return m_resultCode < 0; }
const char* getResultCodeCStr() const { return getResultCode(m_resultCode); }
void setResult(const SymbolString result, const int resultCode)
{ m_result = result; m_resultCode = resultCode; }
const std::string getMessageStr();
void waitSignal() { pthread_cond_wait(&m_cond, &m_mutex); } // TODO timeout
void sendSignal() { pthread_cond_signal(&m_cond); }
private:
CommandType m_type;
bool m_poll;
bool m_scan;
SymbolString m_command;
SymbolString m_result;
int m_resultCode;
pthread_mutex_t m_mutex;
pthread_cond_t m_cond;
};
#endif // LIBEBUS_BUSCOMMAND_H_
-46
View File
@@ -1,46 +0,0 @@
/*
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
*
* 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/.
*/
#include "dump.h"
#include <fstream>
#include <cstdio>
int Dump::write(const char* byte)
{
int ret = 0;
std::ofstream fs(m_filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
if (fs == 0)
return -1;
fs.write(byte, 1);
if (fs.tellp() >= m_filesize * 1024) {
std::string oldfile;
oldfile += m_filename;
oldfile += ".old";
ret = rename(m_filename.c_str(), oldfile.c_str());
}
fs.close();
return ret;
}
-68
View File
@@ -1,68 +0,0 @@
/*
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
*
* 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 LIBEBUS_DUMP_H_
#define LIBEBUS_DUMP_H_
#include <string>
/**
* @brief Class for writing raw bytes to binary file.
*/
class Dump
{
public:
/**
* @brief Create a new instance to write dump files.
* @param filename which will be used for dumping raw bytes.
* @param filesize max. Size of the dump file, before switching.
*/
Dump(std::string filename, long filesize)
: m_filename(filename), m_filesize(filesize) {}
/**
* @brief write byte to dump file.
* @param byte to write
* @return -1 if dump file cannot opened or renaming of dump file failed.
*/
int write(const char* byte);
/**
* @brief setter for dump file name.
* @param filename which will be used for dumping raw bytes.
*/
void setFilename(const std::string& filename) { m_filename = filename; }
/**
* @brief setter for max size of dump file.
* @param filesize max. Size of the dump file, before switching.
*/
void setFilesize(const long filesize) { m_filesize = filesize; }
private:
/** the name of dump file*/
std::string m_filename;
/** max. size of dump file */
long m_filesize;
};
#endif // LIBEBUS_DUMP_H_