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:
parent
78569133ec
commit
09a14965ed
@ -1,32 +1,29 @@
|
||||
cmake_minimum_required(VERSION 2.4.6)
|
||||
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
|
||||
|
||||
# Set the build type. Options are:
|
||||
# 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)
|
||||
project(Serial)
|
||||
|
||||
rosbuild_init()
|
||||
# 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)
|
||||
ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
|
||||
# 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)
|
||||
ENDIF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
|
||||
|
||||
#set the default path for built executables to the "bin" directory
|
||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||
#set the default path for built libraries to the "lib" directory
|
||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
||||
# add the include folder to the include path
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
#uncomment if you have defined messages
|
||||
#rosbuild_genmsg()
|
||||
#uncomment if you have defined services
|
||||
#rosbuild_gensrv()
|
||||
# Find Boost
|
||||
find_package(Boost COMPONENTS system filesystem thread REQUIRED)
|
||||
|
||||
#common commands for building c++ executables and libraries
|
||||
rosbuild_add_library(${PROJECT_NAME} src/serial.cpp)
|
||||
#target_link_libraries(${PROJECT_NAME} another_library)
|
||||
rosbuild_add_boost_directories()
|
||||
rosbuild_link_boost(${PROJECT_NAME} system filesystem thread)
|
||||
rosbuild_add_executable(test_serial src/test_serial.cpp)
|
||||
# Compile the Serial Library
|
||||
add_library(serial src/serial.cpp include/serial.h)
|
||||
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)
|
||||
|
||||
# Check for OS X and if so disable kqueue support in asio
|
||||
|
||||
13
Makefile
Normal file
13
Makefile
Normal 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
|
||||
@ -1,5 +1,3 @@
|
||||
#include "ros/ros.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
@ -26,34 +24,17 @@ std::string toHex(std::string input) {
|
||||
|
||||
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.usbmodemfa141");
|
||||
|
||||
serial = new Serial(port, 9600, 250);
|
||||
|
||||
ros::Rate loop_rate(0.5);
|
||||
|
||||
int count = 0;
|
||||
while (ros::ok() and count != 30) {
|
||||
while (count != 30) {
|
||||
// serial->write("Testing.");
|
||||
// ROS_INFO("Out of write");
|
||||
std::string result = serial->read(1);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user