From b437b34836be318c8f24c38e1551e1dc6b2dfa7f Mon Sep 17 00:00:00 2001 From: Roland Jax Date: Sun, 2 Nov 2014 11:21:04 +0100 Subject: [PATCH] code style. --- src/libebus/bus.cpp | 14 +++++++------- src/libebus/buscommand.cpp | 14 +++++--------- src/libebus/buscommand.h | 13 +++++++++---- src/libebus/port.cpp | 8 +++----- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/libebus/bus.cpp b/src/libebus/bus.cpp index 6748371c..5fa3fcc9 100644 --- a/src/libebus/bus.cpp +++ b/src/libebus/bus.cpp @@ -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; diff --git a/src/libebus/buscommand.cpp b/src/libebus/buscommand.cpp index 59a6d891..0a09c52e 100644 --- a/src/libebus/buscommand.cpp +++ b/src/libebus/buscommand.cpp @@ -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; } diff --git a/src/libebus/buscommand.h b/src/libebus/buscommand.h index b469ae3c..bf06e37d 100644 --- a/src/libebus/buscommand.h +++ b/src/libebus/buscommand.h @@ -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); } diff --git a/src/libebus/port.cpp b/src/libebus/port.cpp index 8b1dd1c8..1951ed8a 100644 --- a/src/libebus/port.cpp +++ b/src/libebus/port.cpp @@ -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()