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

[cob_sick_s300] Propose to use portable serial library for cross-platform #404

Open
wants to merge 2 commits into
base: noetic-devel
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
6 changes: 4 additions & 2 deletions cob_sick_s300/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8.3)
project(cob_sick_s300)

find_package(catkin REQUIRED COMPONENTS diagnostic_msgs roscpp sensor_msgs std_msgs)
find_package(catkin REQUIRED COMPONENTS diagnostic_msgs roscpp sensor_msgs std_msgs serial)

find_package(Boost REQUIRED COMPONENTS date_time thread)

Expand All @@ -16,7 +16,6 @@ include_directories(

add_executable(${PROJECT_NAME}
common/src/ScannerSickS300.cpp
common/src/SerialIO.cpp
ros/src/${PROJECT_NAME}.cpp
)

Expand All @@ -26,6 +25,9 @@ add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS})
add_dependencies(cob_scan_filter ${catkin_EXPORTED_TARGETS})

target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
if(WIN32)
target_link_libraries(${PROJECT_NAME} ws2_32)
endif()
target_link_libraries(cob_scan_filter ${catkin_LIBRARIES})

### INSTALL ###
Expand Down
4 changes: 2 additions & 2 deletions cob_sick_s300/common/include/cob_sick_s300/ScannerSickS300.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <math.h>
#include <stdio.h>

#include <cob_sick_s300/SerialIO.h>
#include <serial/serial.h>
#include <cob_sick_s300/TelegramS300.h>

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ class ScannerSickS300
bool m_bInStandby;

// Components
SerialIO m_SerialIO;
serial::Serial m_SerialIO;
TelegramParser tp_;

// Functions
Expand Down
214 changes: 0 additions & 214 deletions cob_sick_s300/common/include/cob_sick_s300/SerialIO.h

This file was deleted.

4 changes: 4 additions & 0 deletions cob_sick_s300/common/include/cob_sick_s300/TelegramS300.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

#pragma once

#ifdef _WIN32
#include <winsock.h>
#else
#include <arpa/inet.h>
#endif

/*
* S300 header format in continuous mode:
Expand Down
45 changes: 22 additions & 23 deletions cob_sick_s300/common/src/ScannerSickS300.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ScannerSickS300::ScannerSickS300()
//-------------------------------------------
ScannerSickS300::~ScannerSickS300()
{
m_SerialIO.closeIO();
m_SerialIO.close();
}


Expand All @@ -108,34 +108,33 @@ bool ScannerSickS300::open(const char* pcPort, int iBaudRate, int iScanId=7)
m_iScanId = iScanId;

// initialize Serial Interface
m_SerialIO.setBaudRate(iBaudRate);
m_SerialIO.setDeviceName(pcPort);
m_SerialIO.setBufferSize(READ_BUF_SIZE - 10 , WRITE_BUF_SIZE -10 );
m_SerialIO.setHandshake(SerialIO::HS_NONE);
m_SerialIO.setMultiplier(m_dBaudMult);
bRetSerial = m_SerialIO.openIO();
m_SerialIO.setTimeout(0.0);
m_SerialIO.SetFormat(8, SerialIO::PA_NONE, SerialIO::SB_ONE);

if(bRetSerial == 0)
{
// Clears the read and transmit buffer.
m_iPosReadBuf2 = 0;
m_SerialIO.purge();
return true;
}
else
{
return false;
}
try
{
m_SerialIO.setBaudrate(iBaudRate * m_dBaudMult);
m_SerialIO.setPort(pcPort);
m_SerialIO.setFlowcontrol(serial::flowcontrol_none);
m_SerialIO.setParity(serial::parity_none);
m_SerialIO.setStopbits(serial::stopbits_one);
m_SerialIO.setBytesize(serial::eightbits);
serial::Timeout timeout = serial::Timeout::simpleTimeout(0);
m_SerialIO.setTimeout(timeout);
m_SerialIO.open();
}
catch(...)
{
return false;
}

// Clears the read and transmit buffer.
m_iPosReadBuf2 = 0;
return true;
}


//-------------------------------------------
void ScannerSickS300::purgeScanBuf()
{
m_iPosReadBuf2 = 0;
m_SerialIO.purge();
}


Expand Down Expand Up @@ -169,7 +168,7 @@ bool ScannerSickS300::getScan(std::vector<double> &vdDistanceM, std::vector<doub
if(SCANNER_S300_READ_BUF_SIZE-2-m_actualBufferSize<=0)
m_actualBufferSize=0;

iNumRead2 = m_SerialIO.readBlocking((char*)m_ReadBuf+m_actualBufferSize, SCANNER_S300_READ_BUF_SIZE-2-m_actualBufferSize);
iNumRead2 = m_SerialIO.read((uint8_t*)m_ReadBuf+m_actualBufferSize, SCANNER_S300_READ_BUF_SIZE-2-m_actualBufferSize);
if(iNumRead2<=0) return false;

m_actualBufferSize = m_actualBufferSize + iNumRead2;
Expand Down
Loading