Skip to content

Commit

Permalink
Renamed LOG to DMSG
Browse files Browse the repository at this point in the history
  • Loading branch information
TekuConcept committed Apr 19, 2017
1 parent 6255e0c commit 6514cbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <iostream>
#include <iomanip>

#define LOG(x) std::cerr << x

class Serial {
private:
static std::mutex serialLock_;
Expand Down
28 changes: 16 additions & 12 deletions BoneCentral/Peripherals/Peripherals.SerialAdaptors/src/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
#define IFDEBUG if(false)
#endif

#define DMSG(x) std::cerr << x

std::mutex Serial::serialLock_;

Serial::Serial(std::string device) {
IFDEBUG {
LOG("\nReceived Device Name: " << device);
LOG("\nEntering Serial Debug Mode\n");
DMSG("\nReceived Device Name: " << device);
DMSG("\nEntering Serial Debug Mode\n");
fd = 0;
} else {
if((fd = open(device.c_str(), O_RDWR)) < 0) {
LOG("Device failed to open... entering dummy mode.\n");
DMSG("Device failed to open... entering dummy mode.\n");
fd = 0;
return;
}
Expand All @@ -37,15 +39,15 @@ Serial::~Serial() {
void Serial::configure() {
struct termios topts;
if(tcgetattr(fd, &topts)) {
LOG("Failed to get terminal ios options from file descriptor.\n");
DMSG("Failed to get terminal ios options from file descriptor.\n");
throw 1;
}
if(cfsetispeed(&topts, B115200)) {
LOG("Failed to set input baud rate.\n");
DMSG("Failed to set input baud rate.\n");
throw 1;
}
if(cfsetospeed(&topts, B115200)) {
LOG("Failed to set output baud rate.\n");
DMSG("Failed to set output baud rate.\n");
throw 1;
}
topts.c_cflag &= ~(PARENB|CSTOPB|CSIZE|CRTSCTS);
Expand All @@ -56,19 +58,19 @@ void Serial::configure() {
topts.c_cc[VMIN] = 1;
topts.c_cc[VTIME] = 0;
if(tcsetattr(fd, TCSANOW, &topts)) {
LOG("Failed to set terminal ios options for file descriptor.\n");
DMSG("Failed to set terminal ios options for file descriptor.\n");
throw 1;
}
if(tcflush(fd, TCIFLUSH)) {
LOG("Failed to flush file descriptor.\n");
DMSG("Failed to flush file descriptor.\n");
throw 1;
}
}

void Serial::acknowledge() {
std::string response = readString();
IFDEBUG {
LOG("Arduino Message: " << response << "\n");
DMSG("Arduino Message: " << response << "\n");
}
writeByte('R');
}
Expand Down Expand Up @@ -174,11 +176,11 @@ void Serial::writeByte(unsigned char value) {

void Serial::writeData(char* ptr, size_t size) {
IFDEBUG {
LOG("Serial Write: " << std::hex << std::setw(2));
DMSG("Serial Write: " << std::hex << std::setw(2));
for(size_t i = 0; i < size; i++) {
LOG((unsigned short)ptr[i]);
DMSG((unsigned short)ptr[i]);
}
LOG(std::dec << std::endl);
DMSG(std::dec << std::endl);
return;
}
std::lock_guard<std::mutex> guard(serialLock_);
Expand All @@ -188,4 +190,6 @@ void Serial::writeData(char* ptr, size_t size) {

#ifdef IFDEBUG
#undef IFDEBUG

#undef DMSG
#endif

0 comments on commit 6514cbf

Please sign in to comment.