class BusCommand integrated into busloop file.
This commit is contained in:
@@ -8,8 +8,6 @@ bin_PROGRAMS = ebusd
|
|||||||
|
|
||||||
ebusd_SOURCES = dump.cpp \
|
ebusd_SOURCES = dump.cpp \
|
||||||
dump.h \
|
dump.h \
|
||||||
buscommand.cpp \
|
|
||||||
buscommand.h \
|
|
||||||
busloop.cpp \
|
busloop.cpp \
|
||||||
busloop.h \
|
busloop.h \
|
||||||
network.cpp \
|
network.cpp \
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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 BUSCOMMAND_H_
|
|
||||||
#define 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 // BUSCOMMAND_H_
|
|
||||||
|
|
||||||
@@ -25,6 +25,49 @@
|
|||||||
extern Logger& L;
|
extern Logger& L;
|
||||||
extern Appl& A;
|
extern Appl& A;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BusLoop::BusLoop(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)
|
||||||
|
|||||||
+41
-1
@@ -23,13 +23,53 @@
|
|||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
#include "dump.h"
|
#include "dump.h"
|
||||||
#include "buscommand.h"
|
|
||||||
#include "wqueue.h"
|
#include "wqueue.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
#include "symbol.h"
|
||||||
|
#include "result.h"
|
||||||
|
|
||||||
/** 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
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class BusLoop : public Thread
|
class BusLoop : public Thread
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user