Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #34 from forno/upgrade/v1.3.0
Browse files Browse the repository at this point in the history
Upgrade to v1.3.0
  • Loading branch information
forno authored Nov 27, 2016
2 parents 71b2ee9 + f115b38 commit 0e6346f
Show file tree
Hide file tree
Showing 24 changed files with 981 additions and 942 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build/
bin/
**/*.swp
/build
Makefile
*.swp
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "thirdpatry/googletest"]
path = thirdpatry/googletest
url = https://github.com/google/googletest.git
ignore = dirty
27 changes: 15 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
language: cpp
sudo: false
dist: trusty
group: beta
dist: trusty
sudo: false
compiler:
- g++
- clang++
- g++
- clang++
before_install:
- cd thirdpatry/googletest/googletest
- cmake -DCMAKE_BUILD_TYPE=RELEASE .
- make
- cd -
- mkdir build
- cd build
install:
- make
- mkdir cbuild
- cd cbuild
- cmake .. -DCMAKE_INSTALL_PREFIX=install
- make
- make install
- cd ..
- cmake .. -DCMAKE_INSTALL_PREFIX=install -DENABLE_TEST=ON
- make
- make install
script:
./bin/test
- ctest
135 changes: 72 additions & 63 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,86 +1,95 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.1)
project(ics3 CXX)

SET(PROJECT_VER_MAJOR 1)
SET(PROJECT_VER_MINOR 2)
SET(PROJECT_VER_PATCH 6)
SET(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
SET(PROJECT_APIVER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")

IF(NOT DEFINED CMAKE_BUILD_TYPE)
# No effect for multi-configuration generators (e.g. for Visual Studio)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose: RelWithDebInfo Release Debug MinSizeRel None")
ENDIF()

SET(MY_DIR ${ics3_SOURCE_DIR})

OPTION(BUILD_SHARED_LIBS "Build shared (ON) or static (OFF) libraries" ON)
OPTION(ENABLE_CXX11 "Enable C++11 support" ON)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

SET(HAVE_CXX11 disabled)
IF(ENABLE_CXX11)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
IF(COMPILER_SUPPORTS_CXX11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(LIBICS3_WITH_CXX11_SUPPORT 1)
SET(HAVE_CXX11 yes)
ELSEIF(COMPILER_SUPPORTS_CXX0X)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
SET(HAVE_CXX11 c++0x)
ELSE()
SET(HAVE_CXX11 no)
MESSAGE(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
ENDIF()
ENDIF(ENABLE_CXX11)
cmake_minimum_required(VERSION 2.8.12.1)
project(ics3 C CXX)

set(PROJECT_VER_MAJOR 1)
set(PROJECT_VER_MINOR 3)
set(PROJECT_VER_PATCH 0)
set(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
set(PROJECT_APIVER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")

if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose: RelWithDebInfo Release Debug MinSizeRel None")
endif()

option(BUILD_SHARED_LIBS "Build shared (ON) or static (OFF) libraries" ON)
option(ENABLE_TEST "Enable test program building" OFF)

set(MY_DIR ${ics3_SOURCE_DIR})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

#set the default path for built executables to the "bin" directory
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

#set the default path for built libraries to the "lib" directory
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

# Add includes
INCLUDE_DIRECTORIES(
"${MY_DIR}/include"
${PROJECT_BINARY_DIR} # for generated headers
include_directories(
${MY_DIR}/include
)

FILE(GLOB ICS3_SOURCES
file(GLOB ICS3_SOURCES
${MY_DIR}/src/*.cpp
)

LIST(REMOVE_ITEM ICS3_SOURCES ${MY_DIR}/src/test.cpp)

FILE(GLOB ICS3_HEADERS
file(GLOB ICS3_HEADERS
${MY_DIR}/include/ics3/*.hpp
${MY_DIR}/include/core.hpp
)

SET(SOURCES
set(SOURCES
${ICS3_HEADERS}
${ICS3_SOURCES}
)

ADD_LIBRARY(ics3 ${SOURCES})
SET_TARGET_PROPERTIES(ics3 PROPERTIES
add_library(ics3 ${SOURCES})
set_target_properties(ics3 PROPERTIES
VERSION ${PROJECT_VER}
SOVERSION ${PROJECT_APIVER}
)

TARGET_LINK_LIBRARIES(ics3)
INSTALL(TARGETS ics3 DESTINATION lib RUNTIME DESTINATION bin)
INSTALL(DIRECTORY "${MY_DIR}/include/${PROJECT_NAME}" DESTINATION include)

GET_CMAKE_PROPERTY(vars VARIABLES)
MESSAGE(STATUS "Feature list:")
FOREACH(var ${vars})
IF(var MATCHES ^HAVE_)
STRING(REPLACE HAVE_ "" feature ${var})
MESSAGE(STATUS " ${feature} ${${var}}")
ENDIF()
ENDFOREACH()
target_link_libraries(ics3)

if(ENABLE_TEST)
set(GTEST_ROOT ${MY_DIR}/thirdpatry/googletest/googletest)
find_package(GTest REQUIRED)
find_package(Threads)

include_directories(${GTEST_INCLUDE_DIRS})
add_executable(integrate test/integrate.cpp)
target_link_libraries(integrate ics3 ${GTEST_BOTH_LIBRARIES})
if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(PUBLIC integrate "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(integrate "${CMAKE_THREAD_LIBS_INIT}")
endif()

enable_testing()
add_test(AllTestInIntegrate ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/integrate)
endif()

install(TARGETS ics3 DESTINATION lib RUNTIME DESTINATION bin)
install(DIRECTORY "${MY_DIR}/include/${PROJECT_NAME}" DESTINATION include)

get_cmake_property(vars VARIABLES)
message(STATUS "Feature list:")
foreach(var ${vars})
if(var MATCHES ^HAVE_)
string(REPLACE HAVE_ "" feature ${var})
message(STATUS " ${feature} ${${var}}")
endif()
endforeach()
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ex)[KRS series servo moters produced by KONDO KAGAKU co., ltd.](http://kondo-rob
1. This software require c++11 compiler. In ubuntu 14.04 or after version have compiler support c++11.
2. This software only support serial mode. You should lock the serial mode for never turn on PWM mode.
3. Linux need serial device that mounted for use it. `script/setup.sh` will mount it to `/dev/ttyUSB0`.
4. The Makefile for debuging. You should take CMake for installation.

## API Reference
Reference [the libics3 wiki](https://github.com/forno/libics3/wiki)
Expand Down
73 changes: 38 additions & 35 deletions include/core.hpp → include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,43 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LIBICS3_ICS3_CORE_H_
#define LIBICS3_ICS3_CORE_H_

#include<array>
#include<memory>
#include<string>
#include<vector>
#include<termios.h>

namespace ics {
class Core {
public:
using value_type = uint8_t;
using Container = std::vector<value_type>;
using IDContainerTx = std::array<value_type, 4>;
using IDContainerRx = std::array<value_type, 5>;
explicit Core(const std::string&, speed_t); // touch by only libics3
~Core() noexcept;
Core(const Core&) = delete;
Core& operator=(const Core&) = delete;
Core(Core&&) noexcept;
Core& operator=(Core&&) noexcept;

static std::shared_ptr<Core> getCore(const std::string&, speed_t);
void communicate(const Container&, Container&);
void communicateID(const IDContainerTx&, IDContainerRx&);
private:
void closeThis() const noexcept;

static termios getTermios() noexcept;

int fd;
termios oldTio;
};
#ifndef LIBICS3_ICS3_CORE_H
#define LIBICS3_ICS3_CORE_H

#include <array>
#include <memory>
#include <string>
#include <vector>

#include <termios.h>

namespace ics
{
class Core
{
public:
using value_type = uint8_t;
using Container = std::vector<value_type>;
using IDContainerTx = std::array<value_type, 4>;
using IDContainerRx = std::array<value_type, 5>;
explicit Core(const std::string&, speed_t); // touch by only libics3
~Core() noexcept;
Core(const Core&) = delete;
Core& operator=(const Core&) = delete;
Core(Core&&) noexcept;
Core& operator=(Core&&) noexcept;

static std::shared_ptr<Core> getCore(const std::string&, speed_t);
void communicate(const Container&, Container&);
void communicateID(const IDContainerTx&, IDContainerRx&);
private:
void closeThis() const noexcept;

static termios getTermios() noexcept;

int fd;
termios oldTio;
};
}

#endif // LIBICS3_ICS3_CORE_H_
#endif // LIBICS3_ICS3_CORE_H
Loading

0 comments on commit 0e6346f

Please sign in to comment.