Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console_bridge functions updated #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/LMS1xx/lms_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class LMSBuffer
if (ret > 0)
{
total_length_ += ret;
logDebug("Read %d bytes from fd, total length is %d.", ret, total_length_);
CONSOLE_BRIDGE_logDebug("Read %d bytes from fd, total length is %d.", ret, total_length_);
}
else
{

logWarn("Buffer read() returned error.");
CONSOLE_BRIDGE_logWarn("Buffer read() returned error.");
}
}

Expand All @@ -60,7 +60,7 @@ class LMSBuffer
if (total_length_ == 0)
{
// Buffer is empty, no scan data present.
logDebug("Empty buffer, nothing to return.");
CONSOLE_BRIDGE_logDebug("Empty buffer, nothing to return.");
return NULL;
}

Expand All @@ -71,13 +71,13 @@ class LMSBuffer
if (start_of_message == NULL)
{
// None found, buffer reset.
logWarn("No STX found, dropping %d bytes from buffer.", total_length_);
CONSOLE_BRIDGE_logWarn("No STX found, dropping %d bytes from buffer.", total_length_);
total_length_ = 0;
}
else if (buffer_ != start_of_message)
{
// Start of message found, ahead of the start of buffer. Therefore shift the buffer back.
logWarn("Shifting buffer, dropping %d bytes, %d bytes remain.",
CONSOLE_BRIDGE_logWarn("Shifting buffer, dropping %d bytes, %d bytes remain.",
(start_of_message - buffer_), total_length_ - (start_of_message - buffer_));
shiftBuffer(start_of_message);
}
Expand All @@ -87,7 +87,7 @@ class LMSBuffer
if (end_of_first_message_ == NULL)
{
// No end of message found, therefore no message to parse and return.
logDebug("No ETX found, nothing to return.");
CONSOLE_BRIDGE_logDebug("No ETX found, nothing to return.");
return NULL;
}

Expand Down
52 changes: 26 additions & 26 deletions src/LMS1xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void LMS1xx::connect(std::string host, int port)
{
if (!connected_)
{
logDebug("Creating non-blocking socket.");
CONSOLE_BRIDGE_logDebug("Creating non-blocking socket.");
socket_fd_ = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (socket_fd_)
{
Expand All @@ -57,13 +57,13 @@ void LMS1xx::connect(std::string host, int port)
stSockAddr.sin_port = htons(port);
inet_pton(AF_INET, host.c_str(), &stSockAddr.sin_addr);

logDebug("Connecting socket to laser.");
CONSOLE_BRIDGE_logDebug("Connecting socket to laser.");
int ret = ::connect(socket_fd_, (struct sockaddr *) &stSockAddr, sizeof(stSockAddr));

if (ret == 0)
{
connected_ = true;
logDebug("Connected succeeded.");
CONSOLE_BRIDGE_logDebug("Connected succeeded.");
}
}
}
Expand Down Expand Up @@ -92,9 +92,9 @@ void LMS1xx::startMeas()

int len = read(socket_fd_, buf, 100);
if (buf[0] != 0x02)
logWarn("invalid packet recieved");
CONSOLE_BRIDGE_logWarn("invalid packet recieved");
buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);
}

void LMS1xx::stopMeas()
Expand All @@ -106,9 +106,9 @@ void LMS1xx::stopMeas()

int len = read(socket_fd_, buf, 100);
if (buf[0] != 0x02)
logWarn("invalid packet recieved");
CONSOLE_BRIDGE_logWarn("invalid packet recieved");
buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);
}

status_t LMS1xx::queryStatus()
Expand All @@ -120,9 +120,9 @@ status_t LMS1xx::queryStatus()

int len = read(socket_fd_, buf, 100);
if (buf[0] != 0x02)
logWarn("invalid packet recieved");
CONSOLE_BRIDGE_logWarn("invalid packet recieved");
buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);

int ret;
sscanf((buf + 10), "%d", &ret);
Expand Down Expand Up @@ -156,9 +156,9 @@ void LMS1xx::login()

int len = read(socket_fd_, buf, 100);
if (buf[0] != 0x02)
logWarn("invalid packet recieved");
CONSOLE_BRIDGE_logWarn("invalid packet recieved");
buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);
}

scanCfg LMS1xx::getScanCfg() const
Expand All @@ -171,9 +171,9 @@ scanCfg LMS1xx::getScanCfg() const

int len = read(socket_fd_, buf, 100);
if (buf[0] != 0x02)
logWarn("invalid packet recieved");
CONSOLE_BRIDGE_logWarn("invalid packet recieved");
buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);

sscanf(buf + 1, "%*s %*s %X %*d %X %X %X", &cfg.scaningFrequency,
&cfg.angleResolution, &cfg.startAngle, &cfg.stopAngle);
Expand Down Expand Up @@ -201,7 +201,7 @@ void LMS1xx::setScanDataCfg(const scanDataCfg &cfg)
"sWN LMDscandatacfg", cfg.outputChannel, cfg.remission ? 1 : 0,
cfg.resolution, cfg.encoder, cfg.position ? 1 : 0,
cfg.deviceName ? 1 : 0, cfg.timestamp ? 1 : 0, cfg.outputInterval, 0x03);
logDebug("TX: %s", buf);
CONSOLE_BRIDGE_logDebug("TX: %s", buf);
write(socket_fd_, buf, strlen(buf));

int len = read(socket_fd_, buf, 100);
Expand Down Expand Up @@ -233,10 +233,10 @@ void LMS1xx::scanContinous(int start)
int len = read(socket_fd_, buf, 100);

if (buf[0] != 0x02)
logError("invalid packet recieved");
CONSOLE_BRIDGE_logError("invalid packet recieved");

buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);
}

bool LMS1xx::getScanData(scanData* scan_data)
Expand All @@ -254,9 +254,9 @@ bool LMS1xx::getScanData(scanData* scan_data)
tv.tv_sec = 0;
tv.tv_usec = 100000;

logDebug("entering select()", tv.tv_usec);
CONSOLE_BRIDGE_logDebug("entering select()", tv.tv_usec);
int retval = select(socket_fd_ + 1, &rfds, NULL, NULL, &tv);
logDebug("returned %d from select()", retval);
CONSOLE_BRIDGE_logDebug("returned %d from select()", retval);
if (retval)
{
buffer_.readFrom(socket_fd_);
Expand Down Expand Up @@ -313,7 +313,7 @@ void LMS1xx::parseScanData(char* buffer, scanData* data)
tok = strtok(NULL, " "); //NumberChannels16Bit
int NumberChannels16Bit;
sscanf(tok, "%d", &NumberChannels16Bit);
logDebug("NumberChannels16Bit : %d", NumberChannels16Bit);
CONSOLE_BRIDGE_logDebug("NumberChannels16Bit : %d", NumberChannels16Bit);

for (int i = 0; i < NumberChannels16Bit; i++)
{
Expand Down Expand Up @@ -344,7 +344,7 @@ void LMS1xx::parseScanData(char* buffer, scanData* data)
tok = strtok(NULL, " "); //NumberData
int NumberData;
sscanf(tok, "%X", &NumberData);
logDebug("NumberData : %d", NumberData);
CONSOLE_BRIDGE_logDebug("NumberData : %d", NumberData);

if (type == 0)
{
Expand Down Expand Up @@ -392,7 +392,7 @@ void LMS1xx::parseScanData(char* buffer, scanData* data)
tok = strtok(NULL, " "); //NumberChannels8Bit
int NumberChannels8Bit;
sscanf(tok, "%d", &NumberChannels8Bit);
logDebug("NumberChannels8Bit : %d\n", NumberChannels8Bit);
CONSOLE_BRIDGE_logDebug("NumberChannels8Bit : %d\n", NumberChannels8Bit);

for (int i = 0; i < NumberChannels8Bit; i++)
{
Expand Down Expand Up @@ -423,7 +423,7 @@ void LMS1xx::parseScanData(char* buffer, scanData* data)
tok = strtok(NULL, " "); //NumberData
int NumberData;
sscanf(tok, "%X", &NumberData);
logDebug("NumberData : %d\n", NumberData);
CONSOLE_BRIDGE_logDebug("NumberData : %d\n", NumberData);

if (type == 0)
{
Expand Down Expand Up @@ -477,9 +477,9 @@ void LMS1xx::saveConfig()
int len = read(socket_fd_, buf, 100);

if (buf[0] != 0x02)
logWarn("invalid packet recieved");
CONSOLE_BRIDGE_logWarn("invalid packet recieved");
buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);
}

void LMS1xx::startDevice()
Expand All @@ -492,7 +492,7 @@ void LMS1xx::startDevice()
int len = read(socket_fd_, buf, 100);

if (buf[0] != 0x02)
logWarn("invalid packet recieved");
CONSOLE_BRIDGE_logWarn("invalid packet recieved");
buf[len] = 0;
logDebug("RX: %s", buf);
CONSOLE_BRIDGE_logDebug("RX: %s", buf);
}