code style.

This commit is contained in:
Roland Jax
2014-11-02 11:21:04 +01:00
parent e304d45f65
commit b437b34836
4 changed files with 24 additions and 25 deletions
+7 -7
View File
@@ -61,8 +61,8 @@ void Bus::printBytes() const
int Bus::proceed()
{
unsigned char byte_recv;
ssize_t bytes_recv;
unsigned char byte;
ssize_t nbytes;
// fetch new message and get bus
if (m_sendBuffer.size() != 0 && m_sstr.size() == 0) {
@@ -71,18 +71,18 @@ int Bus::proceed()
}
// wait for new data
bytes_recv = m_port->recv(0);
nbytes = m_port->recv(0);
if (bytes_recv < 0)
if (nbytes < 0)
return RESULT_ERR_DEVICE;
for (int i = 0; i < bytes_recv; i++) {
for (int i = 0; i < nbytes; i++) {
// fetch next byte
byte_recv = recvByte();
byte = recvByte();
// store byte
return proceedCycData(byte_recv); // TODO what if more than one byte was received?
return proceedCycData(byte); // TODO what if more than one byte was received?
}
return RESULT_SYN;
+5 -9
View File
@@ -23,8 +23,8 @@ namespace libebus
{
BusCommand::BusCommand(const std::string commandStr, const bool isPoll)
: m_isPoll(isPoll), m_command(commandStr), m_resultCode(RESULT_OK)
BusCommand::BusCommand(const std::string command, const bool isPoll)
: m_isPoll(isPoll), m_command(command), m_resultCode(RESULT_OK)
{
unsigned char dstAddress = m_command[1];
@@ -34,6 +34,7 @@ BusCommand::BusCommand(const std::string commandStr, const bool isPoll)
m_type = masterMaster;
else
m_type = masterSlave;
pthread_mutex_init(&m_mutex, NULL);
pthread_cond_init(&m_cond, NULL);
}
@@ -44,11 +45,6 @@ BusCommand::~BusCommand()
pthread_cond_destroy(&m_cond);
}
const char* BusCommand::getResultCodeCStr()
{
return libebus::getResultCodeCStr(m_resultCode);
}
const std::string BusCommand::getMessageStr()
{
std::string result;
@@ -62,9 +58,9 @@ const std::string BusCommand::getMessageStr()
} else {
result = "success";
}
}
else
} else {
result = "error";
}
return result;
}
+9 -4
View File
@@ -34,17 +34,22 @@ class BusCommand
{
public:
BusCommand(const std::string commandStr, const bool isPoll);
BusCommand(const std::string command, const bool isPoll);
~BusCommand();
CommandType getType() const { return m_type; }
bool isPoll() const { return m_isPoll; }
SymbolString getCommand() const { return m_command; }
bool isErrorResult() const { return m_resultCode < 0; }
const char* getResultCodeCStr();
SymbolString getResult() const { return m_result; }
void setResult(const SymbolString result, const int resultCode) { m_result = result; m_resultCode = resultCode; }
bool isErrorResult() const { return m_resultCode < 0; }
const char* getResultCodeCStr() const { return libebus::getResultCodeCStr(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); }
+3 -5
View File
@@ -86,18 +86,16 @@ ssize_t Device::recvBytes(const long timeout, size_t maxCount)
return -2; // TODO RESULT_ERR_TIMEOUT
}
ssize_t bytes_read = sizeof(m_buffer);
if (maxCount > sizeof(m_buffer))
maxCount = sizeof(m_buffer);
// read bytes from device
bytes_read = read(m_fd, m_buffer, maxCount);
ssize_t nbytes = read(m_fd, m_buffer, maxCount);
for (int i = 0; i < bytes_read; i++)
for (int i = 0; i < nbytes; i++)
m_recvBuffer.push(m_buffer[i]);
return bytes_read;
return nbytes;
}
unsigned char Device::getByte()