1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

Completely removed ROS dependency, builds with cmake and has a auto cmake && make Makefile. To build just type make.

This commit is contained in:
William Woodall 2011-03-19 14:50:34 -05:00
parent 78569133ec
commit 09a14965ed
3 changed files with 34 additions and 43 deletions

View File

@ -1,32 +1,29 @@
cmake_minimum_required(VERSION 2.4.6) cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# Set the build type. Options are: project(Serial)
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)
rosbuild_init()
# set the default path for built executables to the "bin" directory # set the default path for built executables to the "bin" directory
IF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
# set the default path for built libraries to the "lib" directory # set the default path for built libraries to the "lib" directory
IF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
ENDIF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
#uncomment if you have defined messages # add the include folder to the include path
#rosbuild_genmsg() include_directories(${PROJECT_SOURCE_DIR}/include)
#uncomment if you have defined services
#rosbuild_gensrv()
#common commands for building c++ executables and libraries # Find Boost
rosbuild_add_library(${PROJECT_NAME} src/serial.cpp) find_package(Boost COMPONENTS system filesystem thread REQUIRED)
#target_link_libraries(${PROJECT_NAME} another_library)
rosbuild_add_boost_directories() # Compile the Serial Library
rosbuild_link_boost(${PROJECT_NAME} system filesystem thread) add_library(serial src/serial.cpp include/serial.h)
rosbuild_add_executable(test_serial src/test_serial.cpp) target_link_libraries(serial ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
# Compile the Test program
add_executable(test_serial src/test_serial.cpp)
# Link the Test program to the Serial library
target_link_libraries(test_serial serial) target_link_libraries(test_serial serial)
# Check for OS X and if so disable kqueue support in asio # Check for OS X and if so disable kqueue support in asio

13
Makefile Normal file
View File

@ -0,0 +1,13 @@
all:
@mkdir -p build
-mkdir -p bin
cd build && cmake $(CMAKE_FLAGS) ..
ifneq ($(MAKE),)
cd build && $(MAKE)
else
cd build && make
endif
clean:
-cd build && make clean
rm -rf build bin lib

View File

@ -1,5 +1,3 @@
#include "ros/ros.h"
#include <string> #include <string>
#include <iostream> #include <iostream>
@ -26,34 +24,17 @@ std::string toHex(std::string input) {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
ros::init(argc, argv, "serial_test_node");
ros::NodeHandle n;
std::string port("/dev/tty.usbserial-A900cfJA"); std::string port("/dev/tty.usbserial-A900cfJA");
// std::string port("/dev/tty.usbmodemfa141"); // std::string port("/dev/tty.usbmodemfa141");
serial = new Serial(port, 9600, 250); serial = new Serial(port, 9600, 250);
ros::Rate loop_rate(0.5);
int count = 0; int count = 0;
while (ros::ok() and count != 30) { while (count != 30) {
// serial->write("Testing."); // serial->write("Testing.");
// ROS_INFO("Out of write");
std::string result = serial->read(1); std::string result = serial->read(1);
std::cout << ">" << result << std::endl; std::cout << ">" << result << std::endl;
// ROS_INFO("Here.");
// ROS_INFO(result.c_str());
// ROS_INFO("%d,%s", result.length(), toHex(result).c_str());
ros::spinOnce();
// loop_rate.sleep();
// count += 1; // count += 1;
} }