class EBusLoop renamed to BusLoop; class Dump cleared.
This commit is contained in:
@@ -6,14 +6,14 @@ AM_CXXFLAGS = -fpic \
|
|||||||
|
|
||||||
bin_PROGRAMS = ebusd
|
bin_PROGRAMS = ebusd
|
||||||
|
|
||||||
ebusd_SOURCES = network.cpp \
|
ebusd_SOURCES = dump.cpp \
|
||||||
network.h \
|
|
||||||
dump.cpp \
|
|
||||||
dump.h \
|
dump.h \
|
||||||
buscommand.cpp \
|
buscommand.cpp \
|
||||||
buscommand.h \
|
buscommand.h \
|
||||||
ebusloop.cpp \
|
busloop.cpp \
|
||||||
ebusloop.h \
|
busloop.h \
|
||||||
|
network.cpp \
|
||||||
|
network.h \
|
||||||
baseloop.cpp \
|
baseloop.cpp \
|
||||||
baseloop.h \
|
baseloop.h \
|
||||||
ebusd.cpp
|
ebusd.cpp
|
||||||
|
|||||||
+16
-16
@@ -34,9 +34,9 @@ BaseLoop::BaseLoop()
|
|||||||
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
|
L.log(bas, event, " cycle DB: %d ", m_commands->sizeCycDB());
|
||||||
L.log(bas, event, " polling DB: %d ", m_commands->sizePollDB());
|
L.log(bas, event, " polling DB: %d ", m_commands->sizePollDB());
|
||||||
|
|
||||||
// create ebusloop
|
// create busloop
|
||||||
m_ebusloop = new EBusLoop(m_commands);
|
m_busloop = new BusLoop(m_commands);
|
||||||
m_ebusloop->start("ebusloop");
|
m_busloop->start("busloop");
|
||||||
|
|
||||||
// create network
|
// create network
|
||||||
m_network = new Network(A.getOptVal<bool>("localhost"), &m_netQueue);
|
m_network = new Network(A.getOptVal<bool>("localhost"), &m_netQueue);
|
||||||
@@ -49,11 +49,11 @@ BaseLoop::~BaseLoop()
|
|||||||
if (m_network != NULL)
|
if (m_network != NULL)
|
||||||
delete m_network;
|
delete m_network;
|
||||||
|
|
||||||
// free ebusloop
|
// free busloop
|
||||||
if (m_ebusloop != NULL) {
|
if (m_busloop != NULL) {
|
||||||
m_ebusloop->stop();
|
m_busloop->stop();
|
||||||
m_ebusloop->join();
|
m_busloop->join();
|
||||||
delete m_ebusloop;
|
delete m_busloop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// free commands DB
|
// free commands DB
|
||||||
@@ -152,7 +152,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
||||||
L.log(bas, trace, " msg: %s", ebusCommand.c_str());
|
L.log(bas, trace, " msg: %s", ebusCommand.c_str());
|
||||||
// send busCommand
|
// send busCommand
|
||||||
m_ebusloop->addBusCommand(busCommand);
|
m_busloop->addBusCommand(busCommand);
|
||||||
busCommand->waitSignal();
|
busCommand->waitSignal();
|
||||||
|
|
||||||
if (!busCommand->isErrorResult()) {
|
if (!busCommand->isErrorResult()) {
|
||||||
@@ -205,7 +205,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
||||||
L.log(bas, event, " msg: %s", ebusCommand.c_str());
|
L.log(bas, event, " msg: %s", ebusCommand.c_str());
|
||||||
// send busCommand
|
// send busCommand
|
||||||
m_ebusloop->addBusCommand(busCommand);
|
m_busloop->addBusCommand(busCommand);
|
||||||
busCommand->waitSignal();
|
busCommand->waitSignal();
|
||||||
|
|
||||||
if (!busCommand->isErrorResult()) {
|
if (!busCommand->isErrorResult()) {
|
||||||
@@ -274,7 +274,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
BusCommand* busCommand = new BusCommand(ebusCommand, false, false);
|
||||||
L.log(bas, trace, " msg: %s", ebusCommand.c_str());
|
L.log(bas, trace, " msg: %s", ebusCommand.c_str());
|
||||||
// send busCommand
|
// send busCommand
|
||||||
m_ebusloop->addBusCommand(busCommand);
|
m_busloop->addBusCommand(busCommand);
|
||||||
busCommand->waitSignal();
|
busCommand->waitSignal();
|
||||||
|
|
||||||
if (busCommand->isErrorResult()) {
|
if (busCommand->isErrorResult()) {
|
||||||
@@ -291,13 +291,13 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
case scan:
|
case scan:
|
||||||
if (cmd.size() == 1) {
|
if (cmd.size() == 1) {
|
||||||
m_ebusloop->scan();
|
m_busloop->scan();
|
||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(cmd[1].c_str(), "FULL") == 0) {
|
if (strcasecmp(cmd[1].c_str(), "FULL") == 0) {
|
||||||
m_ebusloop->scan(true);
|
m_busloop->scan(true);
|
||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -346,7 +346,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ebusloop->raw();
|
m_busloop->raw();
|
||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ebusloop->dump();
|
m_busloop->dump();
|
||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
delete m_commands;
|
delete m_commands;
|
||||||
m_commands = commands;
|
m_commands = commands;
|
||||||
m_ebusloop->reload(m_commands);
|
m_busloop->reload(m_commands);
|
||||||
|
|
||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "ebusloop.h"
|
#include "busloop.h"
|
||||||
|
|
||||||
class BaseLoop
|
class BaseLoop
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Commands* m_commands;
|
Commands* m_commands;
|
||||||
EBusLoop* m_ebusloop;
|
BusLoop* m_busloop;
|
||||||
Network* m_network;
|
Network* m_network;
|
||||||
|
|
||||||
WQueue<NetMessage*> m_netQueue;
|
WQueue<NetMessage*> m_netQueue;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
* along with ebusd. If not, see http://www.gnu.org/licenses/.
|
* along with ebusd. If not, see http://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ebusloop.h"
|
#include "busloop.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "appl.h"
|
#include "appl.h"
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
extern Logger& L;
|
extern Logger& L;
|
||||||
extern Appl& A;
|
extern Appl& A;
|
||||||
|
|
||||||
EBusLoop::EBusLoop(Commands* commands)
|
BusLoop::BusLoop(Commands* commands)
|
||||||
: m_commands(commands), m_stop(false), m_lockCounter(0),
|
: m_commands(commands), m_stop(false), m_lockCounter(0),
|
||||||
m_priorRetry(false), m_scan(false), m_scanFull(false), m_scanIndex(0)
|
m_priorRetry(false), m_scan(false), m_scanFull(false), m_scanIndex(0)
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,7 @@ EBusLoop::EBusLoop(Commands* commands)
|
|||||||
m_acquireTime = A.getOptVal<long>("acquiretime");
|
m_acquireTime = A.getOptVal<long>("acquiretime");
|
||||||
}
|
}
|
||||||
|
|
||||||
EBusLoop::~EBusLoop()
|
BusLoop::~BusLoop()
|
||||||
{
|
{
|
||||||
if (m_port->isOpen() == true)
|
if (m_port->isOpen() == true)
|
||||||
m_port->close();
|
m_port->close();
|
||||||
@@ -60,7 +60,7 @@ EBusLoop::~EBusLoop()
|
|||||||
delete m_dump;
|
delete m_dump;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* EBusLoop::run()
|
void* BusLoop::run()
|
||||||
{
|
{
|
||||||
int sendRetries = 0;
|
int sendRetries = 0;
|
||||||
int lockRetries = 0;
|
int lockRetries = 0;
|
||||||
@@ -191,7 +191,7 @@ void* EBusLoop::run()
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char EBusLoop::fetchByte()
|
unsigned char BusLoop::fetchByte()
|
||||||
{
|
{
|
||||||
unsigned char byte;
|
unsigned char byte;
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ unsigned char EBusLoop::fetchByte()
|
|||||||
return byte;
|
return byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EBusLoop::collectCycData(const int numRecv)
|
void BusLoop::collectCycData(const int numRecv)
|
||||||
{
|
{
|
||||||
// cycle bytes
|
// cycle bytes
|
||||||
for (int i = 0; i < numRecv; i++) {
|
for (int i = 0; i < numRecv; i++) {
|
||||||
@@ -242,7 +242,7 @@ void EBusLoop::collectCycData(const int numRecv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EBusLoop::analyseCycData()
|
void BusLoop::analyseCycData()
|
||||||
{
|
{
|
||||||
static bool skipfirst = false;
|
static bool skipfirst = false;
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ void EBusLoop::analyseCycData()
|
|||||||
skipfirst = true;
|
skipfirst = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EBusLoop::addPollCommand()
|
void BusLoop::addPollCommand()
|
||||||
{
|
{
|
||||||
int index = m_commands->nextPollCommand();
|
int index = m_commands->nextPollCommand();
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
@@ -301,7 +301,7 @@ void EBusLoop::addPollCommand()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int EBusLoop::acquireBus()
|
int BusLoop::acquireBus()
|
||||||
{
|
{
|
||||||
unsigned char recvByte, sendByte;
|
unsigned char recvByte, sendByte;
|
||||||
ssize_t numRecv, numSend;
|
ssize_t numRecv, numSend;
|
||||||
@@ -358,7 +358,7 @@ int EBusLoop::acquireBus()
|
|||||||
return RESULT_ERR_EXTRA_DATA;
|
return RESULT_ERR_EXTRA_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
BusCommand* EBusLoop::sendCommand()
|
BusCommand* BusLoop::sendCommand()
|
||||||
{
|
{
|
||||||
unsigned char recvByte;
|
unsigned char recvByte;
|
||||||
std::string result;
|
std::string result;
|
||||||
@@ -470,7 +470,7 @@ on_exit:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int EBusLoop::sendByte(const unsigned char sendByte)
|
int BusLoop::sendByte(const unsigned char sendByte)
|
||||||
{
|
{
|
||||||
unsigned char recvByte;
|
unsigned char recvByte;
|
||||||
ssize_t numRecv, numSend;
|
ssize_t numRecv, numSend;
|
||||||
@@ -495,7 +495,7 @@ int EBusLoop::sendByte(const unsigned char sendByte)
|
|||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EBusLoop::recvSlaveAck(unsigned char& recvByte)
|
int BusLoop::recvSlaveAck(unsigned char& recvByte)
|
||||||
{
|
{
|
||||||
ssize_t numRecv;
|
ssize_t numRecv;
|
||||||
|
|
||||||
@@ -522,7 +522,7 @@ int EBusLoop::recvSlaveAck(unsigned char& recvByte)
|
|||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int EBusLoop::recvSlaveData(SymbolString& result)
|
int BusLoop::recvSlaveData(SymbolString& result)
|
||||||
{
|
{
|
||||||
unsigned char recvByte, calcCrc = 0;
|
unsigned char recvByte, calcCrc = 0;
|
||||||
ssize_t numRecv;
|
ssize_t numRecv;
|
||||||
@@ -568,7 +568,7 @@ int EBusLoop::recvSlaveData(SymbolString& result)
|
|||||||
return RESULT_OK;
|
return RESULT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EBusLoop::collectSlave()
|
void BusLoop::collectSlave()
|
||||||
{
|
{
|
||||||
std::vector<unsigned char>::iterator it;
|
std::vector<unsigned char>::iterator it;
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ void EBusLoop::collectSlave()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EBusLoop::addScanCommand()
|
void BusLoop::addScanCommand()
|
||||||
{
|
{
|
||||||
std::string ebusCommand(A.getOptVal<const char*>("address"));
|
std::string ebusCommand(A.getOptVal<const char*>("address"));
|
||||||
std::stringstream sstr;
|
std::stringstream sstr;
|
||||||
@@ -17,8 +17,8 @@
|
|||||||
* along with ebusd. If not, see http://www.gnu.org/licenses/.
|
* along with ebusd. If not, see http://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EBUSLOOP_H_
|
#ifndef BUSLOOP_H_
|
||||||
#define EBUSLOOP_H_
|
#define BUSLOOP_H_
|
||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
@@ -30,12 +30,12 @@
|
|||||||
/** the maximum time [us] allowed for retrieving a byte from an addressed slave */
|
/** the maximum time [us] allowed for retrieving a byte from an addressed slave */
|
||||||
#define RECV_TIMEOUT 10000
|
#define RECV_TIMEOUT 10000
|
||||||
|
|
||||||
class EBusLoop : public Thread
|
class BusLoop : public Thread
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EBusLoop(Commands* commands);
|
BusLoop(Commands* commands);
|
||||||
~EBusLoop();
|
~BusLoop();
|
||||||
|
|
||||||
void* run();
|
void* run();
|
||||||
void stop() { m_stop = true; }
|
void stop() { m_stop = true; }
|
||||||
@@ -92,4 +92,4 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EBUSLOOP_H_
|
#endif // BUSLOOP_H_
|
||||||
+4
-4
@@ -25,18 +25,18 @@ int Dump::write(const char* byte)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
std::ofstream fs(m_filename.c_str(), std::ios::out | std::ios::binary | std::ios::app);
|
std::ofstream fs(m_name.c_str(), std::ios::out | std::ios::binary | std::ios::app);
|
||||||
|
|
||||||
if (fs == 0)
|
if (fs == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fs.write(byte, 1);
|
fs.write(byte, 1);
|
||||||
|
|
||||||
if (fs.tellp() >= m_filesize * 1024) {
|
if (fs.tellp() >= m_size * 1024) {
|
||||||
std::string oldfile;
|
std::string oldfile;
|
||||||
oldfile += m_filename;
|
oldfile += m_name;
|
||||||
oldfile += ".old";
|
oldfile += ".old";
|
||||||
ret = rename(m_filename.c_str(), oldfile.c_str());
|
ret = rename(m_name.c_str(), oldfile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.close();
|
fs.close();
|
||||||
|
|||||||
+14
-14
@@ -23,19 +23,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Class for writing raw bytes to binary file.
|
* @brief class for writing raw bytes to binary file.
|
||||||
*/
|
*/
|
||||||
class Dump
|
class Dump
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Create a new instance to write dump files.
|
* @brief create a new instance to write dump files.
|
||||||
* @param filename which will be used for dumping raw bytes.
|
* @param name the file name of dump file.
|
||||||
* @param filesize max. Size of the dump file, before switching.
|
* @param size the max. size of the dump file, before switching.
|
||||||
*/
|
*/
|
||||||
Dump(std::string filename, long filesize)
|
Dump(std::string name, long size)
|
||||||
: m_filename(filename), m_filesize(filesize) {}
|
: m_name(name), m_size(size) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief write byte to dump file.
|
* @brief write byte to dump file.
|
||||||
@@ -45,23 +45,23 @@ public:
|
|||||||
int write(const char* byte);
|
int write(const char* byte);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setter for dump file name.
|
* @brief set the name of dump file.
|
||||||
* @param filename which will be used for dumping raw bytes.
|
* @param name the file name of dump file.
|
||||||
*/
|
*/
|
||||||
void setFilename(const std::string& filename) { m_filename = filename; }
|
void setName(const std::string& name) { m_name = name; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief setter for max size of dump file.
|
* @brief set the max size of dump file.
|
||||||
* @param filesize max. Size of the dump file, before switching.
|
* @param size the max. size of the dump file, before switching.
|
||||||
*/
|
*/
|
||||||
void setFilesize(const long filesize) { m_filesize = filesize; }
|
void setSize(const long size) { m_size = size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** the name of dump file*/
|
/** the name of dump file*/
|
||||||
std::string m_filename;
|
std::string m_name;
|
||||||
|
|
||||||
/** max. size of dump file */
|
/** max. size of dump file */
|
||||||
long m_filesize;
|
long m_size;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user