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 615a629 commit 43b06d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 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
30 changes: 17 additions & 13 deletions BoneCentral/Peripherals/Peripherals.SerialAdaptors/src/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

#include "Serial.h"

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

std::mutex Serial::serialLock_;

Serial::Serial(std::string device) {
#ifdef DEBUG
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 @@ -31,15 +33,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 @@ -50,19 +52,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::ackno() {
std::string response = readString();
#ifdef DEBUG
LOG("Arduino Message: " << response << "\n");
DMSG("Arduino Message: " << response << "\n");
#endif
writeByte('R');
}
Expand Down Expand Up @@ -178,14 +180,16 @@ void Serial::writeByte(unsigned char value) {

void Serial::writeData(char* ptr, size_t size) {
#ifdef DEBUG
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);
#else
std::lock_guard<std::mutex> guard(serialLock_);
if(fd == 0) return;
write(fd, ptr, size);
#endif
}
}

#undef DMSG

0 comments on commit 43b06d2

Please sign in to comment.