Skip to content

Commit

Permalink
Merge pull request ros-industrial#33 from ros-industrial/issue25_recv…
Browse files Browse the repository at this point in the history
…_bytes

Issue ros-industrial#25 fix
  • Loading branch information
JeremyZoss committed Aug 23, 2013
2 parents c1581b6 + ed2d24f commit dd0490e
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 135 deletions.
6 changes: 5 additions & 1 deletion simple_message/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ include_directories(include
${catkin_INCLUDE_DIRS}
)

# NOTE: All test files require TEST_PORT_BASE to be defined. Defining different
# ports for each test executable allows them to run in parallel.

# DEFAULT LIBRARY (SAME ENDIAN)
add_library(simple_message ${SRC_FILES})
target_link_libraries(simple_message ${catkin_LIBRARIES})
add_dependencies(simple_message ${industrial_msgs_EXPORTED_TARGETS})

catkin_add_gtest(utest ${UTEST_SRC_FILES})
set_target_properties(utest PROPERTIES COMPILE_DEFINITIONS "TEST_PORT_BASE=11000")
target_link_libraries(utest simple_message)

# ALTERNATIVE LIBRARY (DIFFERENT ENDIAN)
Expand All @@ -107,6 +110,7 @@ target_link_libraries(simple_message_bswap ${catkin_LIBRARIES})
add_dependencies(simple_message_bswap ${industrial_msgs_EXPORTED_TARGETS})

catkin_add_gtest(utest_byte_swapping ${UTEST_SRC_FILES})
set_target_properties(utest_byte_swapping PROPERTIES COMPILE_DEFINITIONS "TEST_PORT_BASE=12000")
target_link_libraries(utest_byte_swapping simple_message_bswap)

# ALTERNATIVE LIBRARY (64-bit floats)
Expand All @@ -116,7 +120,7 @@ target_link_libraries(simple_message_float64 ${catkin_LIBRARIES})
add_dependencies(simple_message_float64 ${industrial_msgs_EXPORTED_TARGETS})

catkin_add_gtest(utest_float64 ${UTEST_SRC_FILES})
set_target_properties(utest_float64 PROPERTIES COMPILE_DEFINITIONS "FLOAT64")
set_target_properties(utest_float64 PROPERTIES COMPILE_DEFINITIONS "TEST_PORT_BASE=13000;FLOAT64")
target_link_libraries(utest_float64 simple_message_float64)


Expand Down
23 changes: 22 additions & 1 deletion simple_message/include/simple_message/socket/simple_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ class SimpleSocket : public industrial::smpl_msg_connection::SmplMsgConnection
* in order to avoid dynamic memory allocation)
*/
static const int MAX_BUFFER_SIZE = 1024;

/**
* \brief socket ready polling timeout (ms)
*/
static const int SOCKET_POLL_TO = 1000;

/**
* \brief internal data buffer for receiving
*/
Expand All @@ -207,14 +213,29 @@ class SimpleSocket : public industrial::smpl_msg_connection::SmplMsgConnection
LOG_ERROR("%s, rc: %d. Error: '%s' (errno: %d)", msg, rc, strerror(errno_), errno_);
}

/**
* \brief polls socket for data or error
*
* \param timeout (ms) negative or zero values result in blocking
* \param ready true if ready
* \param except true if exception
*
* \return true if function DID NOT timeout (must check flags)
*/
bool poll(int timeout, bool & ready, bool & error);

/**
* \brief returns true if socket data is ready to receive
*
* \param timeout (ms) negative or zero values result in blocking
*
* \return true if data is ready to recieve
*/
bool isReadyReceive(int timeout);
bool isReadyReceive(int timeout)
{
bool r, e;
return poll(timeout, r, e);
}

// Send/Receive functions (inherited classes should override raw methods
// Virtual
Expand Down
Loading

0 comments on commit dd0490e

Please sign in to comment.