code style.
This commit is contained in:
+7
-7
@@ -61,8 +61,8 @@ void Bus::printBytes() const
|
|||||||
|
|
||||||
int Bus::proceed()
|
int Bus::proceed()
|
||||||
{
|
{
|
||||||
unsigned char byte_recv;
|
unsigned char byte;
|
||||||
ssize_t bytes_recv;
|
ssize_t nbytes;
|
||||||
|
|
||||||
// fetch new message and get bus
|
// fetch new message and get bus
|
||||||
if (m_sendBuffer.size() != 0 && m_sstr.size() == 0) {
|
if (m_sendBuffer.size() != 0 && m_sstr.size() == 0) {
|
||||||
@@ -71,18 +71,18 @@ int Bus::proceed()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait for new data
|
// 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;
|
return RESULT_ERR_DEVICE;
|
||||||
|
|
||||||
for (int i = 0; i < bytes_recv; i++) {
|
for (int i = 0; i < nbytes; i++) {
|
||||||
|
|
||||||
// fetch next byte
|
// fetch next byte
|
||||||
byte_recv = recvByte();
|
byte = recvByte();
|
||||||
|
|
||||||
// store byte
|
// 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;
|
return RESULT_SYN;
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ namespace libebus
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
BusCommand::BusCommand(const std::string commandStr, const bool isPoll)
|
BusCommand::BusCommand(const std::string command, const bool isPoll)
|
||||||
: m_isPoll(isPoll), m_command(commandStr), m_resultCode(RESULT_OK)
|
: m_isPoll(isPoll), m_command(command), m_resultCode(RESULT_OK)
|
||||||
{
|
{
|
||||||
unsigned char dstAddress = m_command[1];
|
unsigned char dstAddress = m_command[1];
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@ BusCommand::BusCommand(const std::string commandStr, const bool isPoll)
|
|||||||
m_type = masterMaster;
|
m_type = masterMaster;
|
||||||
else
|
else
|
||||||
m_type = masterSlave;
|
m_type = masterSlave;
|
||||||
|
|
||||||
pthread_mutex_init(&m_mutex, NULL);
|
pthread_mutex_init(&m_mutex, NULL);
|
||||||
pthread_cond_init(&m_cond, NULL);
|
pthread_cond_init(&m_cond, NULL);
|
||||||
}
|
}
|
||||||
@@ -44,11 +45,6 @@ BusCommand::~BusCommand()
|
|||||||
pthread_cond_destroy(&m_cond);
|
pthread_cond_destroy(&m_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* BusCommand::getResultCodeCStr()
|
|
||||||
{
|
|
||||||
return libebus::getResultCodeCStr(m_resultCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string BusCommand::getMessageStr()
|
const std::string BusCommand::getMessageStr()
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
@@ -62,9 +58,9 @@ const std::string BusCommand::getMessageStr()
|
|||||||
} else {
|
} else {
|
||||||
result = "success";
|
result = "success";
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
result = "error";
|
result = "error";
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,17 +34,22 @@ class BusCommand
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BusCommand(const std::string commandStr, const bool isPoll);
|
BusCommand(const std::string command, const bool isPoll);
|
||||||
~BusCommand();
|
~BusCommand();
|
||||||
|
|
||||||
CommandType getType() const { return m_type; }
|
CommandType getType() const { return m_type; }
|
||||||
bool isPoll() const { return m_isPoll; }
|
bool isPoll() const { return m_isPoll; }
|
||||||
|
|
||||||
SymbolString getCommand() const { return m_command; }
|
SymbolString getCommand() const { return m_command; }
|
||||||
bool isErrorResult() const { return m_resultCode < 0; }
|
|
||||||
const char* getResultCodeCStr();
|
|
||||||
SymbolString getResult() const { return m_result; }
|
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();
|
const std::string getMessageStr();
|
||||||
|
|
||||||
void waitSignal() { pthread_cond_wait(&m_cond, &m_mutex); } // TODO timeout
|
void waitSignal() { pthread_cond_wait(&m_cond, &m_mutex); } // TODO timeout
|
||||||
void sendSignal() { pthread_cond_signal(&m_cond); }
|
void sendSignal() { pthread_cond_signal(&m_cond); }
|
||||||
|
|
||||||
|
|||||||
@@ -86,18 +86,16 @@ ssize_t Device::recvBytes(const long timeout, size_t maxCount)
|
|||||||
return -2; // TODO RESULT_ERR_TIMEOUT
|
return -2; // TODO RESULT_ERR_TIMEOUT
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t bytes_read = sizeof(m_buffer);
|
|
||||||
if (maxCount > sizeof(m_buffer))
|
if (maxCount > sizeof(m_buffer))
|
||||||
maxCount = sizeof(m_buffer);
|
maxCount = sizeof(m_buffer);
|
||||||
|
|
||||||
|
|
||||||
// read bytes from device
|
// 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]);
|
m_recvBuffer.push(m_buffer[i]);
|
||||||
|
|
||||||
return bytes_read;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char Device::getByte()
|
unsigned char Device::getByte()
|
||||||
|
|||||||
Reference in New Issue
Block a user