diff --git a/.gitignore b/.gitignore index 0865cdd..8f0d7bf 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ bot2-procman/python/src/bot_procman/build_prefix.py pod-build bot2-lcmgl/python/src/bot_lcmgl/__init__.py bot2-procman/python/src/bot_procman/__init__.py +bot2-procman/python/src/bot_procman/*_t.py diff --git a/Makefile b/Makefile index fc9061c..c447f43 100644 --- a/Makefile +++ b/Makefile @@ -1,49 +1,49 @@ +# Default pod makefile distributed with pods version: 12.11.14 -# support only a few flags that might be passed through: -# BUILD_PREFIX, BUILD_TYPE, CMAKE_FLAGS* -CMAKE_FLAGS+=$(strip $(CMAKE_FLAGS1) $(CMAKE_FLAGS2) $(CMAKE_FLAGS3) $(CMAKE_FLAGS4) $(CMAKE_FLAGS5) $(CMAKE_FLAGS6) $(CMAKE_FLAGS7) $(CMAKE_FLAGS8) $(CMAKE_FLAGS9) $(CMAKE_FLAGS10) $(CMAKE_FLAGS11) $(CMAKE_FLAGS12) $(CMAKE_FLAGS13) $(CMAKE_FLAGS14) $(CMAKE_FLAGS15) $(CMAKE_FLAGS16) $(CMAKE_FLAGS17) $(CMAKE_FLAGS18) $(CMAKE_FLAGS19) $(CMAKE_FLAGS20)) -ifneq "$(BUILD_PREFIX)" "" - CMAKE_FLAGS+=-DCMAKE_INSTALL_PREFIX="$(BUILD_PREFIX)" +default_target: all + +# Default to a less-verbose build. If you want all the gory compiler output, +# run "make VERBOSE=1" +$(VERBOSE).SILENT: + +# Figure out where to build the software. +# Use BUILD_PREFIX if it was passed in. +# If not, search up to four parent directories for a 'build' directory. +# Otherwise, use ./build. +ifeq "$(BUILD_PREFIX)" "" +BUILD_PREFIX:=$(shell for pfx in ./ .. ../.. ../../.. ../../../..; do d=`pwd`/$$pfx/build;\ + if [ -d $$d ]; then echo $$d; exit 0; fi; done; echo `pwd`/build) endif +# create the build directory if needed, and normalize its path name +BUILD_PREFIX:=$(shell mkdir -p $(BUILD_PREFIX) && cd $(BUILD_PREFIX) && echo `pwd`) + +# Default to a release build. If you want to enable debugging flags, run +# "make BUILD_TYPE=Debug" ifeq "$(BUILD_TYPE)" "" - BUILD_TYPE="Release" +BUILD_TYPE="Release" endif -CMAKE_FLAGS+=-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -CMAKE_CONFIG=--config $(BUILD_TYPE) -.PHONY: all -all: configure - cmake --build pod-build $(CMAKE_CONFIG) --target all +all: pod-build/Makefile + $(MAKE) -C pod-build all install -pod-build: - cmake -E make_directory pod-build +pod-build/Makefile: + $(MAKE) configure .PHONY: configure -configure: pod-build - @echo Configuring with CMAKE_FLAGS: $(CMAKE_FLAGS) - @cd pod-build && cmake $(CMAKE_FLAGS) .. - -.PHONY: options -options: configure -ifeq ($(OS),Windows_NT) - cmake-gui pod-build -else - ccmake pod-build -endif +configure: + @echo "\nBUILD_PREFIX: $(BUILD_PREFIX)\n\n" -.PHONY: clean -clean: - cmake --build pod-build --target clean - cmake -E remove_directory pod-build - cmake -E remove_directory build + # create the temporary build directory if needed + @mkdir -p pod-build -# other (custom) targets are passed through to the cmake-generated Makefile -%:: - cmake --build pod-build $(CMAKE_CONFIG) --target $@ - -# Default to a less-verbose build. If you want all the gory compiler output, -# run "make VERBOSE=1" -$(VERBOSE).SILENT: + # run CMake to generate and configure the build scripts + @cd pod-build && cmake -DCMAKE_INSTALL_PREFIX=$(BUILD_PREFIX) \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) .. +clean: + -if [ -e pod-build/install_manifest.txt ]; then rm -f `cat pod-build/install_manifest.txt`; fi + -if [ -d pod-build ]; then $(MAKE) -C pod-build clean; rm -rf pod-build; fi -### rules specific to this project (everything above is the generic pods makefile wrapper of a cmake project) +# other (custom) targets are passed through to the cmake-generated Makefile +%:: + $(MAKE) -C pod-build $@ \ No newline at end of file diff --git a/README b/README index e782589..709bbd6 100644 --- a/README +++ b/README @@ -84,6 +84,17 @@ Requirements the Pods core policy. If no other "build" directory is found, it will default to: libbot2/build/ +Catkin +====== +libbot now supports catkin. + +Please add/remove any/all lcm types, executables and libraries to respective the catkin cmake files (catkin/...). + +To build: +1. Clone the code into a catkin workspace (catkin_tools environmnet is recommended). +2. Use rosdep to install dependencies (see https://bitbucket.org/vivan/lcm_catkin for catkin-compatible lcm) +2. Compile the workspace: 'catkin build -s' or 'catkin_make' (depending on which tools you use). + Uninstallation ============== diff --git a/bot2-core/CMakeLists.txt b/bot2-core/CMakeLists.txt index 27f32c5..4e061b8 100644 --- a/bot2-core/CMakeLists.txt +++ b/bot2-core/CMakeLists.txt @@ -4,8 +4,4 @@ set(POD_NAME bot2-core) include(cmake/pods.cmake) -#include(cmake/lcmtypes.cmake) -#lcmtypes_build(C_AGGREGATE_HEADER bot_core.h CPP_AGGREGATE_HEADER bot_core.hpp) - add_subdirectory(src/bot_core) -#add_subdirectory(java) diff --git a/bot2-core/Makefile b/bot2-core/Makefile index 2216901..c447f43 100644 --- a/bot2-core/Makefile +++ b/bot2-core/Makefile @@ -1,4 +1,4 @@ -# Default pod makefile distributed with pods version: 12.09.21 +# Default pod makefile distributed with pods version: 12.11.14 default_target: all diff --git a/bot2-core/cmake/lcmtypes.cmake b/bot2-core/cmake/lcmtypes.cmake deleted file mode 100644 index 72c711a..0000000 --- a/bot2-core/cmake/lcmtypes.cmake +++ /dev/null @@ -1,485 +0,0 @@ -# Macros for automatically compiling LCM types into C, Java, and Python -# libraries. -# -# The primary macro is: -# lcmtypes_build([C_AGGREGATE_HEADER header_fname] -# [C_LIBNAME lib_name] -# [JAVA_DEST_DIR dir_name] -# [PY_DEST_DIR dir_name] -# ) -# -# It expects that the directory ${PROJECT_SOURCE_DIR}/lcmtypes contains all -# the LCM types used by the system. The macro generates C, Java, and Python -# bindings. See the C, Java, and Python sections below for information on -# language specific options and generated results. -# -# After invoking this macro, the following variables will be set: -# -# LCMTYPES_LIBS -# LCMTYPES_JAR -# -# -# C -# == -# -# C bindings will be placed in ${PROJECT_SOURCE_DIR}/lcmtypes/c. -# -# The autogenerated C bindings also get compiled to a static and shared -# library. The library prefix will be stored in LCMTYPES_LIBS on output. -# This prefix can be manually set using the C_LIBNAME option. -# -# Additionally, a header file will be generated that automatically includes -# all of the other automatically generated header files. The name of this -# header file defaults to a cleaned-up version of "${PROJECT_NAME}.h" -# (non-alphanumeric characters replaced with underscores), but can -# be manually set using the C_AGGREGATE_HEADER option. -# -# C++ -# == -# -# C++ bindings will be placed in ${PROJECT_SOURCE_DIR}/lcmtypes/cpp. -# -# The autogenerated CPP bindings are header only, so no library is created. -# -# A header file will be generated that automatically includes -# all of the other automatically generated header files. The name of this -# header file defaults to a cleaned-up version of "${PROJECT_NAME}.hpp" -# (non-alphanumeric characters replaced with underscores), but can -# be manually set using the CPP_AGGREGATE_HEADER option. -# -# -# Java -# ==== -# -# If Java is available, then Java bindings are be generated and placed in -# ${PROJECT_SOURCE_DIR}/lcmtypes/java -# -# This directory can be changed using the JAVA_DEST_DIR option. -# -# Additionally, targets are added to automatically compile the .java files to a -# .jar file. The location of this jar file is stored in LCMTYPES_JAR -# -# and the .jar file will be installed to -# ${CMAKE_INSTALL_PREFIX}/share/java -# -# -# Python -# ====== -# -# If Python is enabled, then python bindings will be generated and placed in -# ${PROJECT_SOURCE_DIR}/lcmtypes/python -# -# This directory can be changed by setting the PY_DEST_DIR option. -# -# Additionally, the .py files will be installed to -# ${CMAKE_INSTALL_PREFIX}/lib/python{X.Y}/dist-packages -# -# where {X.Y} refers to the python version used to build the .py files. -# -# ---- -# File: lcmtypes.cmake -# Distributed with pods version: 12.09.21 - -cmake_minimum_required(VERSION 2.6.0) - -# Policy settings to prevent warnings on 2.6 but ensure proper operation on -# 2.4. -if(COMMAND cmake_policy) - # Logical target names must be globally unique. - cmake_policy(SET CMP0002 OLD) - # Libraries linked via full path no longer produce linker search paths. - cmake_policy(SET CMP0003 OLD) - # Preprocessor definition values are now escaped automatically. - cmake_policy(SET CMP0005 OLD) - if(POLICY CMP0011) - # Included scripts do automatic cmake_policy PUSH and POP. - cmake_policy(SET CMP0011 OLD) - endif(POLICY CMP0011) -endif() - -macro(lcmtypes_get_types msgvar) - # get a list of all LCM types - file(GLOB __tmplcmtypes "${PROJECT_SOURCE_DIR}/lcmtypes/*.lcm") - set(${msgvar} "") - foreach(_msg ${__tmplcmtypes}) - # Try to filter out temporary and backup files - if(${_msg} MATCHES "^[^\\.].*\\.lcm$") - list(APPEND ${msgvar} ${_msg}) - endif(${_msg} MATCHES "^[^\\.].*\\.lcm$") - endforeach(_msg) -endmacro() - -function(lcmgen) - execute_process(COMMAND ${LCM_GEN_EXECUTABLE} ${ARGV} RESULT_VARIABLE lcmgen_result) - if(NOT lcmgen_result EQUAL 0) - message(FATAL_ERROR "lcm-gen failed") - endif() -endfunction() - -function(lcmtypes_add_clean_dir clean_dir) - get_directory_property(acfiles ADDITIONAL_MAKE_CLEAN_FILES) - list(APPEND acfiles ${clean_dir}) - set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${acfiles}") -endfunction() - -function(lcmtypes_build_c) - lcmtypes_get_types(_lcmtypes) - list(LENGTH _lcmtypes _num_lcmtypes) - if(_num_lcmtypes EQUAL 0) - return() - endif() - - string(REGEX REPLACE "[^a-zA-Z0-9]" "_" __sanitized_project_name "${PROJECT_NAME}") - - # set some defaults - - # library name - set(libname "lcmtypes_${PROJECT_NAME}") - - # header file that includes all other generated header files - set(agg_h_bname "${__sanitized_project_name}.h") - - # allow defaults to be overriden by function parameters - set(modewords C_LIBNAME C_AGGREGATE_HEADER) - set(curmode "") - foreach(word ${ARGV}) - list(FIND modewords ${word} mode_index) - if(${mode_index} GREATER -1) - set(curmode ${word}) - elseif(curmode STREQUAL C_AGGREGATE_HEADER) - set(agg_h_bname "${word}") - set(curmode "") - elseif(curmode STREQUAL C_LIBNAME) - set(libname "${word}") - set(curmode "") - endif() - endforeach() - - # generate C bindings for LCM types - set(_lcmtypes_c_dir ${PROJECT_SOURCE_DIR}/lcmtypes/c/lcmtypes) - - # blow away any existing auto-generated files. - file(REMOVE_RECURSE ${_lcmtypes_c_dir}) - - # run lcm-gen now - execute_process(COMMAND mkdir -p ${_lcmtypes_c_dir}) - lcmgen(--lazy -c --c-cpath ${_lcmtypes_c_dir} --c-hpath ${_lcmtypes_c_dir} --cinclude lcmtypes ${_lcmtypes}) - - # run lcm-gen at compile time - add_custom_target(lcmgen_c ALL - COMMAND sh -c '[ -d ${_lcmtypes_c_dir} ] || mkdir -p ${_lcmtypes_c_dir}' - COMMAND sh -c '${LCM_GEN_EXECUTABLE} --lazy -c ${_lcmtypes} --c-cpath ${_lcmtypes_c_dir} --c-hpath ${_lcmtypes_c_dir}') - - # get a list of all generated .c and .h files - file(GLOB _lcmtypes_c_files ${_lcmtypes_c_dir}/*.c) - file(GLOB _lcmtypes_h_files ${_lcmtypes_c_dir}/*.h) - - include_directories(BEFORE ${PROJECT_SOURCE_DIR}/lcmtypes/c) #TODO: don't think this is necessary - include_directories(${LCM_INCLUDE_DIRS}) - - # aggregate into a static library - add_library(${libname} STATIC ${_lcmtypes_c_files}) - set_source_files_properties(${_lcmtypes_c_files} PROPERTIES COMPILE_FLAGS "-fPIC") - # set_target_properties("${libname}-static" PROPERTIES OUTPUT_NAME "${libname}") - set_target_properties(${libname} PROPERTIES PREFIX "lib") - set_target_properties(${libname} PROPERTIES CLEAN_DIRECT_OUTPUT 1) - add_dependencies(${libname} lcmgen_c) - - # add_library("${libname}-static" STATIC ${_lcmtypes_c_files}) - # set_source_files_properties(${_lcmtypes_c_files} PROPERTIES COMPILE_FLAGS "-I${PROJECT_SOURCE_DIR}/lcmtypes/c") - # set_target_properties("${libname}-static" PROPERTIES OUTPUT_NAME "${libname}") - # set_target_properties("${libname}-static" PROPERTIES PREFIX "lib") - # set_target_properties("${libname}-static" PROPERTIES CLEAN_DIRECT_OUTPUT 1) - # add_dependencies("${libname}-static" lcmgen_c) - - # XXX don't build a shared library, as it makes using 3rd-party/external - # LCM types awkward (linker will try to link external symbols at library link time, - # rather than executable link time) - - # # aggregate into a shared library - # add_library(${libname} SHARED ${_lcmtypes_c_files}) - # set_target_properties("${libname}" PROPERTIES CLEAN_DIRECT_OUTPUT 1) - # add_dependencies("${libname}" lcmgen_c) - # target_link_libraries(${libname} ${LCM_LDFLAGS}) - - # create a header file aggregating all of the autogenerated .h files - set(__agg_h_fname "${_lcmtypes_c_dir}/${agg_h_bname}") - file(WRITE ${__agg_h_fname} - "#ifndef __lcmtypes_${__sanitized_project_name}_h__\n" - "#define __lcmtypes_${__sanitized_project_name}_h__\n\n") - foreach(h_file ${_lcmtypes_h_files}) - file(RELATIVE_PATH __tmp_path ${_lcmtypes_c_dir} ${h_file}) - file(APPEND ${__agg_h_fname} "#include \"${__tmp_path}\"\n") - endforeach() - file(APPEND ${__agg_h_fname} "\n#endif\n") - list(APPEND _lcmtypes_h_files ${__agg_h_fname}) - unset(__sanitized_project_name) - unset(__agg_h_fname) - - # make header files and libraries public - pods_install_libraries(${libname}) - pods_install_headers(${_lcmtypes_h_files} DESTINATION lcmtypes) - - # set some compilation variables - set(LCMTYPES_LIBS ${libname} PARENT_SCOPE) - - # create a pkg-config file - pods_install_pkg_config_file(${libname} - CFLAGS - DESCRIPTION "LCM types for ${PROJECT_NAME}" - LIBS -l${libname} - REQUIRES lcm - VERSION 0.0.0) - - lcmtypes_add_clean_dir("${PROJECT_SOURCE_DIR}/lcmtypes/c") -endfunction() - -function(lcmtypes_build_cpp) - lcmtypes_get_types(_lcmtypes) - list(LENGTH _lcmtypes _num_lcmtypes) - if(_num_lcmtypes EQUAL 0) - return() - endif() - - string(REGEX REPLACE "[^a-zA-Z0-9]" "_" __sanitized_project_name "${PROJECT_NAME}") - - # set some defaults - - # header file that includes all other generated header files - set(agg_hpp_bname "${__sanitized_project_name}.hpp") - - # allow defaults to be overriden by function parameters - set(modewords CPP_AGGREGATE_HEADER) - set(curmode "") - foreach(word ${ARGV}) - list(FIND modewords ${word} mode_index) - if(${mode_index} GREATER -1) - set(curmode ${word}) - elseif(curmode STREQUAL CPP_AGGREGATE_HEADER) - set(agg_hpp_bname "${word}") - set(curmode "") - endif() - endforeach() - - # generate CPP bindings for LCM types - set(_lcmtypes_cpp_dir ${PROJECT_SOURCE_DIR}/lcmtypes/cpp/lcmtypes) - - # blow away any existing auto-generated files. - file(REMOVE_RECURSE ${_lcmtypes_cpp_dir}) - - # run lcm-gen now - execute_process(COMMAND mkdir -p ${_lcmtypes_cpp_dir}) - lcmgen(--lazy --cpp --cpp-hpath ${_lcmtypes_cpp_dir} --cpp-include lcmtypes ${_lcmtypes}) - - # run lcm-gen at compile time - add_custom_target(lcmgen_cpp ALL - COMMAND sh -c '[ -d ${_lcmtypes_cpp_dir} ] || mkdir -p ${_lcmtypes_cpp_dir}' - COMMAND sh -c '${LCM_GEN_EXECUTABLE} --lazy --cpp ${_lcmtypes} --cpp-hpath ${_lcmtypes_cpp_dir}') - - # get a list of all generated .hpp files - file(GLOB_RECURSE _lcmtypes_hpp_files ${_lcmtypes_cpp_dir}/*.hpp) - - include_directories(BEFORE ${PROJECT_SOURCE_DIR}/lcmtypes/cpp) #TODO: don't think this is necessary - include_directories(${LCM_INCLUDE_DIRS}) - - # create a header file aggregating all of the autogenerated .hpp files - set(__agg_hpp_fname "${_lcmtypes_cpp_dir}/${agg_hpp_bname}") - file(WRITE ${__agg_hpp_fname} - "#ifndef __lcmtypes_${__sanitized_project_name}_hpp__\n" - "#define __lcmtypes_${__sanitized_project_name}_hpp__\n\n") - foreach(hpp_file ${_lcmtypes_hpp_files}) - file(RELATIVE_PATH __tmp_path ${_lcmtypes_cpp_dir} ${hpp_file}) - file(APPEND ${__agg_hpp_fname} "#include \"${__tmp_path}\"\n") - get_filename_component(__tmp_dir ${__tmp_path} PATH) - pods_install_headers(${hpp_file} DESTINATION lcmtypes/${__tmp_dir}) - endforeach() - file(APPEND ${__agg_hpp_fname} "\n#endif\n") - pods_install_headers(${__agg_hpp_fname} DESTINATION lcmtypes) - unset(__sanitized_project_name) - unset(__agg_hpp_fname) - - - - lcmtypes_add_clean_dir("${PROJECT_SOURCE_DIR}/lcmtypes/cpp") -endfunction() - -function(lcmtypes_build_java) - lcmtypes_get_types(_lcmtypes) - list(LENGTH _lcmtypes _num_lcmtypes) - if(_num_lcmtypes EQUAL 0) - return() - endif() - - # do we have Java? - find_package(Java) - if(JAVA_COMPILE STREQUAL JAVA_COMPILE-NOTFOUND OR - JAVA_ARCHIVE STREQUAL JAVA_ARCHIVE-NOTFOUND) - message(STATUS "Not building Java LCM type bindings (Can't find Java)") - return() - endif() - - # do we have LCM java bindings? where is lcm.jar? - execute_process(COMMAND pkg-config --variable=classpath lcm-java OUTPUT_VARIABLE LCM_JAR_FILE) - if(NOT LCM_JAR_FILE) - message(STATUS "Not building Java LCM type bindings (Can't find lcm.jar)") - return() - endif() - string(STRIP ${LCM_JAR_FILE} LCM_JAR_FILE) - set(LCMTYPES_JAR ${CMAKE_CURRENT_BINARY_DIR}/lcmtypes_${PROJECT_NAME}.jar) - - # generate Java bindings for LCM types - set(_lcmtypes_java_dir ${PROJECT_SOURCE_DIR}/lcmtypes/java) - set(auto_manage_files YES) - - set(modewords JAVA_DEST_DIR) - set(curmode "") - foreach(word ${ARGV}) - list(FIND modewords ${word} mode_index) - if(${mode_index} GREATER -1) - set(curmode ${word}) - elseif(curmode STREQUAL JAVA_DEST_DIR) - set(_lcmtypes_java_dir "${word}") - set(auto_manage_files NO) - set(curmode "") - endif() - endforeach() - - # blow away any existing auto-generated files? - if(auto_manage_files) - file(REMOVE_RECURSE ${_lcmtypes_java_dir}) - endif() - - # run lcm-gen now - execute_process(COMMAND mkdir -p ${_lcmtypes_java_dir}) - lcmgen(--lazy -j ${_lcmtypes} --jpath ${_lcmtypes_java_dir}) - - # run lcm-gen at compile time - add_custom_target(lcmgen_java ALL - COMMAND sh -c '[ -d ${_lcmtypes_java_dir} ] || mkdir -p ${_lcmtypes_java_dir}' - COMMAND sh -c '${LCM_GEN_EXECUTABLE} --lazy -j ${_lcmtypes} --jpath ${_lcmtypes_java_dir}') - - if(NOT auto_manage_files) - return() - endif() - - # get a list of all generated .java files - file(GLOB_RECURSE _lcmtypes_java_files ${_lcmtypes_java_dir}/*.java) - - set(java_classpath ${_lcmtypes_java_dir}:${LCM_JAR_FILE}) - - # search for lcmtypes_*.jar files in well-known places and add them to the - # classpath - foreach(pfx /usr /usr/local ${CMAKE_INSTALL_PREFIX}) - file(GLOB_RECURSE jarfiles ${pfx}/share/java/lcmtypes_*.jar) - foreach(jarfile ${jarfiles}) - set(java_classpath ${java_classpath}:${jarfile}) - # message("found ${jarfile}") - endforeach() - endforeach() - - # convert the list of .java filenames to a list of .class filenames - foreach(javafile ${_lcmtypes_java_files}) - string(REPLACE .java .class __tmp_class_fname ${javafile}) - # add_custom_command(OUTPUT ${__tmp_class_fname} COMMAND - # ${JAVA_COMPILE} -source 6 -cp ${_lcmtypes_java_dir}:${lcm_jar} ${javafile} VERBATIM DEPENDS ${javafile}) - list(APPEND _lcmtypes_class_files ${__tmp_class_fname}) - unset(__tmp_class_fname) - endforeach() - - # add a rule to build the .class files from from the .java files - add_custom_command(OUTPUT ${_lcmtypes_class_files} COMMAND - ${JAVA_COMPILE} -source 6 -target 6 -cp ${java_classpath} ${_lcmtypes_java_files} - DEPENDS ${_lcmtypes_java_files} VERBATIM) - - # add a rule to build a .jar file from the .class files - add_custom_command(OUTPUT lcmtypes_${PROJECT_NAME}.jar COMMAND - ${JAVA_ARCHIVE} cf ${LCMTYPES_JAR} -C ${_lcmtypes_java_dir} . DEPENDS ${_lcmtypes_class_files} VERBATIM) - add_custom_target(lcmtypes_${PROJECT_NAME}_jar ALL DEPENDS ${LCMTYPES_JAR}) - - add_dependencies(lcmtypes_${PROJECT_NAME}_jar lcmgen_java) - - install(FILES ${LCMTYPES_JAR} DESTINATION share/java) - set(LCMTYPES_JAR ${LCMTYPES_JAR} PARENT_SCOPE) - - lcmtypes_add_clean_dir(${_lcmtypes_java_dir}) -endfunction() - -function(lcmtypes_build_python) - lcmtypes_get_types(_lcmtypes) - list(LENGTH _lcmtypes _num_lcmtypes) - if(_num_lcmtypes EQUAL 0) - return() - endif() - - find_package(PythonInterp) - if(NOT PYTHONINTERP_FOUND) - message(STATUS "Not building Python LCM type bindings (Can't find Python)") - return() - endif() - - set(_lcmtypes_python_dir ${PROJECT_SOURCE_DIR}/lcmtypes/python) - set(auto_manage_files YES) - - set(modewords PY_DEST_DIR) - set(curmode "") - foreach(word ${ARGV}) - list(FIND modewords ${word} mode_index) - if(${mode_index} GREATER -1) - set(curmode ${word}) - elseif(curmode STREQUAL PY_DEST_DIR) - set(_lcmtypes_python_dir "${word}") - set(auto_manage_files NO) - set(curmode "") - endif() - endforeach() - - # purge existing files? - if(auto_manage_files) - file(REMOVE_RECURSE ${_lcmtypes_python_dir}) - endif() - - # generate Python bindings for LCM types - execute_process(COMMAND mkdir -p ${_lcmtypes_python_dir}) - execute_process(COMMAND ${LCM_GEN_EXECUTABLE} --lazy -p ${_lcmtypes} --ppath ${_lcmtypes_python_dir}) - - # run lcm-gen at compile time - add_custom_target(lcmgen_python ALL - COMMAND sh -c '${LCM_GEN_EXECUTABLE} --lazy -p ${_lcmtypes} --ppath ${_lcmtypes_python_dir}') - - if(NOT auto_manage_files) - return() - endif() - - pods_install_python_packages(${_lcmtypes_python_dir}) - - lcmtypes_add_clean_dir(${_lcmtypes_python_dir}) -endfunction() - -function(lcmtypes_install_types) - lcmtypes_get_types(_lcmtypes) - list(LENGTH _lcmtypes _num_lcmtypes) - if(_num_lcmtypes EQUAL 0) - return() - endif() - - install(FILES ${_lcmtypes} DESTINATION share/lcmtypes) -endfunction() - -macro(lcmtypes_build) - find_package(PkgConfig REQUIRED) - pkg_check_modules(LCM REQUIRED lcm) - - #find lcm-gen (it may be in the install path) - find_program(LCM_GEN_EXECUTABLE lcm-gen ${EXECUTABLE_OUTPUT_PATH} ${EXECUTABLE_INSTALL_PATH}) - if (NOT LCM_GEN_EXECUTABLE) - message(FATAL_ERROR "lcm-gen not found!\n") - return() - endif() - - lcmtypes_build_c(${ARGV}) - lcmtypes_build_cpp(${ARGV}) - - lcmtypes_build_java(${ARGV}) - lcmtypes_build_python(${ARGV}) - lcmtypes_install_types() -endmacro() diff --git a/bot2-core/cmake/pods.cmake b/bot2-core/cmake/pods.cmake index 7549ffd..36fa280 100644 --- a/bot2-core/cmake/pods.cmake +++ b/bot2-core/cmake/pods.cmake @@ -26,7 +26,7 @@ # # ---- # File: pods.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 # pods_install_headers( ... DESTINATION ) # @@ -191,14 +191,14 @@ function(pods_install_python_script script_name python_module_or_file) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n") + "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} \"$@\"\n") else() get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists? # write the bash script file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n") + "exec ${PYTHON_EXECUTABLE} -m ${py_module} \"$@\"\n") endif() # install it... install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) @@ -223,12 +223,14 @@ function(_pods_install_python_package py_src_dir py_module_name) if(EXISTS "${py_src_dir}/__init__.py") #install the single module - file(GLOB_RECURSE py_files ${py_src_dir}/*.py) - foreach(py_file ${py_files}) - file(RELATIVE_PATH __tmp_path ${py_src_dir} ${py_file}) - get_filename_component(__tmp_dir ${__tmp_path} PATH) - install(FILES ${py_file} - DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + file(GLOB_RECURSE module_files ${py_src_dir}/*) + foreach(file ${module_files}) + if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]") + file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file}) + get_filename_component(__tmp_dir ${__tmp_path} PATH) + install(FILES ${file} + DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + endif() endforeach() else() message(FATAL_ERROR "${py_src_dir} is not a python package!\n") @@ -307,22 +309,21 @@ macro(pods_use_pkg_config_packages target) string(STRIP ${_pods_pkg_ldflags} _pods_pkg_ldflags) # message("ldflags: ${_pods_pkg_ldflags}") include_directories(${_pods_pkg_include_flags}) + target_link_libraries(${target} ${_pods_pkg_ldflags}) # make the target depend on libraries that are cmake targets if (_pods_pkg_ldflags) string(REPLACE " " ";" _split_ldflags ${_pods_pkg_ldflags}) - target_link_libraries(${target} ${_split_ldflags}) - foreach(__ldflag ${_split_ldflags}) string(REGEX REPLACE "^-l" "" __depend_target_name ${__ldflag}) - if(TARGET ${__depend_target_name}) - #message("---- ${target} depends on ${__depend_target_name}") - add_dependencies(${target} ${__depend_target_name}) - endif() + if(TARGET "${__depend_target_name}") + #message("---- ${target} depends on ${libname}") + add_dependencies(${target} ${__depend_target_name}) + endif() endforeach() - unset(_split_ldflags) endif() + unset(_split_ldflags) unset(_pods_pkg_include_flags) unset(_pods_pkg_ldflags) endmacro() diff --git a/bot2-core/lcmtypes/bot_core_image_metadata_t.lcm b/bot2-core/lcmtypes/bot_core_image_metadata_t.lcm deleted file mode 100644 index fc39559..0000000 --- a/bot2-core/lcmtypes/bot_core_image_metadata_t.lcm +++ /dev/null @@ -1,7 +0,0 @@ -package bot_core; - -struct image_metadata_t { - string key; - int32_t n; - byte value[n]; -} diff --git a/bot2-core/lcmtypes/bot_core_image_sync_t.lcm b/bot2-core/lcmtypes/bot_core_image_sync_t.lcm deleted file mode 100644 index e525b61..0000000 --- a/bot2-core/lcmtypes/bot_core_image_sync_t.lcm +++ /dev/null @@ -1,22 +0,0 @@ -package bot_core; - -// image_sync_t is used by libcam plugins to synchronize playback of a libcam -// log file with playback of an LCM log file. -// -// The expected usage scenario is when an image stream is recorded to a libcam -// log file, and a lcm-syncpub unit is in the libcam chain that publishes -// image_sync_t messages to an LCM network, where they may be logged to the -// an LCM logfile. -// -// Later, when playing back an LCM log file, the image_sync_t messages can be -// used by a libcam log playback unit to synchronize its playback of the -// libcam log file with the LCM log file. -// -// The existence of this message type is largely predicated on the notion that -// we may not always want full resolution image data in an LCM log file, and -// may instead store it in a dedicated libcam log file. - -struct image_sync_t -{ - int64_t utime; -} diff --git a/bot2-core/lcmtypes/bot_core_image_t.lcm b/bot2-core/lcmtypes/bot_core_image_t.lcm deleted file mode 100644 index 4ad9a54..0000000 --- a/bot2-core/lcmtypes/bot_core_image_t.lcm +++ /dev/null @@ -1,63 +0,0 @@ -package bot_core; - -// Describes an image -// -// This type should be kept compatible with camlcm.image_t, as defined -// in camunits-extra - -struct image_t -{ - // microseconds since the epoch - int64_t utime; - - int32_t width; - int32_t height; - int32_t row_stride; - - int32_t pixelformat; - - int32_t size; - byte data[size]; - - // metadata dictionary - int32_t nmetadata; - image_metadata_t metadata[nmetadata]; - - // these values are to be kept in sync with the CamPixelFormat enumeration - // in the Camunits library. See camunits/pixels.h in Camunits - const int32_t PIXEL_FORMAT_UYVY = 1498831189; - const int32_t PIXEL_FORMAT_YUYV = 1448695129; - const int32_t PIXEL_FORMAT_IYU1 = 827677001; - const int32_t PIXEL_FORMAT_IYU2 = 844454217; - const int32_t PIXEL_FORMAT_YUV420 = 842093913; - const int32_t PIXEL_FORMAT_YUV411P = 1345401140; - const int32_t PIXEL_FORMAT_I420 = 808596553; - const int32_t PIXEL_FORMAT_NV12 = 842094158; - const int32_t PIXEL_FORMAT_GRAY = 1497715271; - const int32_t PIXEL_FORMAT_RGB = 859981650; - const int32_t PIXEL_FORMAT_BGR = 861030210; - const int32_t PIXEL_FORMAT_RGBA = 876758866; - const int32_t PIXEL_FORMAT_BGRA = 877807426; - const int32_t PIXEL_FORMAT_BAYER_BGGR = 825770306; - const int32_t PIXEL_FORMAT_BAYER_GBRG = 844650584; - const int32_t PIXEL_FORMAT_BAYER_GRBG = 861427800; - const int32_t PIXEL_FORMAT_BAYER_RGGB = 878205016; - const int32_t PIXEL_FORMAT_BE_BAYER16_BGGR = 826360386; - const int32_t PIXEL_FORMAT_BE_BAYER16_GBRG = 843137602; - const int32_t PIXEL_FORMAT_BE_BAYER16_GRBG = 859914818; - const int32_t PIXEL_FORMAT_BE_BAYER16_RGGB = 876692034; - const int32_t PIXEL_FORMAT_LE_BAYER16_BGGR = 826360396; - const int32_t PIXEL_FORMAT_LE_BAYER16_GBRG = 843137612; - const int32_t PIXEL_FORMAT_LE_BAYER16_GRBG = 859914828; - const int32_t PIXEL_FORMAT_LE_BAYER16_RGGB = 876692044; - const int32_t PIXEL_FORMAT_MJPEG = 1196444237; - const int32_t PIXEL_FORMAT_BE_GRAY16 = 357; - const int32_t PIXEL_FORMAT_LE_GRAY16 = 909199180; - const int32_t PIXEL_FORMAT_BE_RGB16 = 358; - const int32_t PIXEL_FORMAT_LE_RGB16 = 1279412050; - const int32_t PIXEL_FORMAT_BE_SIGNED_GRAY16 = 359; - const int32_t PIXEL_FORMAT_BE_SIGNED_RGB16 = 360; - const int32_t PIXEL_FORMAT_FLOAT_GRAY32 = 842221382; - const int32_t PIXEL_FORMAT_INVALID = -2; - const int32_t PIXEL_FORMAT_ANY = -1; -} diff --git a/bot2-core/lcmtypes/bot_core_planar_lidar_t.lcm b/bot2-core/lcmtypes/bot_core_planar_lidar_t.lcm deleted file mode 100644 index 1860c70..0000000 --- a/bot2-core/lcmtypes/bot_core_planar_lidar_t.lcm +++ /dev/null @@ -1,21 +0,0 @@ -package bot_core; - -struct planar_lidar_t -{ - int64_t utime; - - // range data (meters) - int32_t nranges; - float ranges[nranges]; - - // intensity data, in sensor-specific units - int32_t nintensities; - float intensities[nintensities]; - - // the angle (in radians) to the first point in nranges, - // relative to the laser scanner's own coordinate frame. - float rad0; - - // the number of radians between each successive sample - float radstep; -} diff --git a/bot2-core/lcmtypes/bot_core_pose_t.lcm b/bot2-core/lcmtypes/bot_core_pose_t.lcm deleted file mode 100644 index 82e7996..0000000 --- a/bot2-core/lcmtypes/bot_core_pose_t.lcm +++ /dev/null @@ -1,21 +0,0 @@ -package bot_core; - -struct pose_t -{ - int64_t utime; // utime that the actual measurement took place - - double pos[3]; // position x,y,z in meters in local frame - double vel[3]; // velocity in m/s, expressed in local frame, - // _NOT_ body frame - - double orientation[4]; // rotate vector in body coordinate frame - // (X-forward, Z-up) by this to get that vector - // in local frame - - double rotation_rate[3]; // angular velocity vector of the vehicle - // in rad/s. This is expressed in the local - // frame. - - double accel[3]; // Acceleration vector in the local frame in - // m/s/s. Does not include the gravity vector. -} diff --git a/bot2-core/lcmtypes/bot_core_raw_t.lcm b/bot2-core/lcmtypes/bot_core_raw_t.lcm deleted file mode 100644 index 1b20ba6..0000000 --- a/bot2-core/lcmtypes/bot_core_raw_t.lcm +++ /dev/null @@ -1,12 +0,0 @@ -// The raw_t message encapsulates opaque binary data. Expected use cases -// are to transmit raw sensor data via LCM. - -package bot_core; - -struct raw_t -{ - int64_t utime; - - int32_t length; - byte data[length]; -} diff --git a/bot2-core/lcmtypes/bot_core_rigid_transform_t.lcm b/bot2-core/lcmtypes/bot_core_rigid_transform_t.lcm deleted file mode 100644 index d8cc292..0000000 --- a/bot2-core/lcmtypes/bot_core_rigid_transform_t.lcm +++ /dev/null @@ -1,12 +0,0 @@ -package bot_core; - -struct rigid_transform_t -{ - int64_t utime; // utime that the actual measurement took place - - double trans[3]; // translation vector component (x,y,z) - - double quat[4]; // rotation quaternion component (w,x,y,z) - - -} diff --git a/bot2-core/lcmtypes/bot_core_sensor_status_t.lcm b/bot2-core/lcmtypes/bot_core_sensor_status_t.lcm deleted file mode 100644 index d632b76..0000000 --- a/bot2-core/lcmtypes/bot_core_sensor_status_t.lcm +++ /dev/null @@ -1,17 +0,0 @@ -package bot_core; - -struct sensor_status_t -{ - int64_t utime; - string sensor_name; - double rate; - int16_t type; - const int16_t VELODYNE_32 = 0; - const int16_t VELODYNE_64 = 1; - const int16_t SICK_LASER = 2; - const int16_t HOKUYO_LASER = 3; - const int16_t KINECT = 4; - const int16_t IMU = 5; - const int16_t ORC = 6; - const int16_t DYNAMIXEL_SERVO = 7; -} \ No newline at end of file diff --git a/bot2-core/src/bot_core/lcm_util.c b/bot2-core/src/bot_core/lcm_util.c index 0d2c8b8..eca1a0e 100644 --- a/bot2-core/src/bot_core/lcm_util.c +++ b/bot2-core/src/bot_core/lcm_util.c @@ -30,7 +30,7 @@ lcm_message_ready (GIOChannel *source, GIOCondition cond, void *user_data) } static GHashTable *lcm_glib_sources = NULL; -static GStaticMutex lcm_glib_sources_mutex = G_STATIC_MUTEX_INIT; +static GMutex lcm_glib_sources_mutex; static lcm_t *global_lcm = NULL; int @@ -43,7 +43,7 @@ int bot_glib_mainloop_attach_lcm_full (GMainLoop * mainloop, lcm_t *lcm, gboolean quit_on_lcm_fail) { - g_static_mutex_lock (&lcm_glib_sources_mutex); + g_mutex_lock (&lcm_glib_sources_mutex); if (!lcm_glib_sources) { lcm_glib_sources = g_hash_table_new (g_direct_hash, g_direct_equal); @@ -51,7 +51,7 @@ bot_glib_mainloop_attach_lcm_full (GMainLoop * mainloop, lcm_t *lcm, if (g_hash_table_lookup (lcm_glib_sources, lcm)) { dbg ("lcm %p already attached to mainloop\n", lcm); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } @@ -68,17 +68,17 @@ bot_glib_mainloop_attach_lcm_full (GMainLoop * mainloop, lcm_t *lcm, dbg ("inserted lcm %p into glib mainloop\n", lcm); g_hash_table_insert (lcm_glib_sources, lcm, galcm); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return 0; } int bot_glib_mainloop_detach_lcm (lcm_t *lcm) { - g_static_mutex_lock (&lcm_glib_sources_mutex); + g_mutex_lock (&lcm_glib_sources_mutex); if (!lcm_glib_sources) { dbg ("no lcm glib sources\n"); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } @@ -87,7 +87,7 @@ bot_glib_mainloop_detach_lcm (lcm_t *lcm) if (!galcm) { dbg ("couldn't find matching galcm\n"); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } @@ -103,17 +103,17 @@ bot_glib_mainloop_detach_lcm (lcm_t *lcm) lcm_glib_sources = NULL; } - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return 0; } lcm_t * bot_lcm_get_global(const char *provider) { - g_static_mutex_lock (&lcm_glib_sources_mutex); + g_mutex_lock (&lcm_glib_sources_mutex); if(!global_lcm) global_lcm = lcm_create(provider); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return global_lcm; } diff --git a/bot2-core/src/bot_core/tictoc.c b/bot2-core/src/bot_core/tictoc.c index 65edf0c..5e73abd 100644 --- a/bot2-core/src/bot_core/tictoc.c +++ b/bot2-core/src/bot_core/tictoc.c @@ -127,8 +127,7 @@ _tictoc_t_alphCompare(gconstpointer a, gconstpointer b) return strcmp(t1->description, t2->description); } -GStaticMutex tictoc_mutex = -G_STATIC_MUTEX_INIT; +GMutex tictoc_mutex; static int _tictoc_enabled = 1; static int _tictoc_initialized = 0; @@ -161,12 +160,12 @@ bot_tictoc_full(const char *description, double ema_alpha, int64_t * ema) int64_t ret = 0; - g_static_mutex_lock(&tictoc_mutex); //aquire the lock + g_mutex_lock(&tictoc_mutex); //aquire the lock if (!_tictoc_initialized) { _tictoc_initialized = 1; _initializeTictoc(); if (!_tictoc_enabled) { - g_static_mutex_unlock(&tictoc_mutex); //release + g_mutex_unlock(&tictoc_mutex); //release return 0; } @@ -208,7 +207,7 @@ bot_tictoc_full(const char *description, double ema_alpha, int64_t * ema) ret = dt; } - g_static_mutex_unlock(&tictoc_mutex); //release + g_mutex_unlock(&tictoc_mutex); //release return ret; } @@ -226,9 +225,9 @@ bot_tictoc_print_stats(bot_tictoc_sort_type_t sortType) if (!_tictoc_enabled) { return; } - g_static_mutex_lock(&tictoc_mutex); //acquire lock for table + g_mutex_lock(&tictoc_mutex); //acquire lock for table if (!_tictoc_initialized) { - g_static_mutex_unlock(&tictoc_mutex); //release + g_mutex_unlock(&tictoc_mutex); //release return; } GList * list = NULL; @@ -271,5 +270,5 @@ bot_tictoc_print_stats(bot_tictoc_sort_type_t sortType) printf("--------------------------------------------\n"); g_list_free(list); - g_static_mutex_unlock(&tictoc_mutex); //release + g_mutex_unlock(&tictoc_mutex); //release } diff --git a/bot2-frames/Makefile b/bot2-frames/Makefile index 2216901..c447f43 100644 --- a/bot2-frames/Makefile +++ b/bot2-frames/Makefile @@ -1,4 +1,4 @@ -# Default pod makefile distributed with pods version: 12.09.21 +# Default pod makefile distributed with pods version: 12.11.14 default_target: all diff --git a/bot2-frames/cmake/lcmtypes.cmake b/bot2-frames/cmake/lcmtypes.cmake index 72c711a..daca283 100644 --- a/bot2-frames/cmake/lcmtypes.cmake +++ b/bot2-frames/cmake/lcmtypes.cmake @@ -78,7 +78,7 @@ # # ---- # File: lcmtypes.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 cmake_minimum_required(VERSION 2.6.0) @@ -369,7 +369,7 @@ function(lcmtypes_build_java) # search for lcmtypes_*.jar files in well-known places and add them to the # classpath - foreach(pfx /usr /usr/local ${CMAKE_INSTALL_PREFIX}) + foreach(pfx ${CMAKE_INSTALL_PREFIX} /usr /usr/local) file(GLOB_RECURSE jarfiles ${pfx}/share/java/lcmtypes_*.jar) foreach(jarfile ${jarfiles}) set(java_classpath ${java_classpath}:${jarfile}) @@ -388,7 +388,7 @@ function(lcmtypes_build_java) # add a rule to build the .class files from from the .java files add_custom_command(OUTPUT ${_lcmtypes_class_files} COMMAND - ${JAVA_COMPILE} -source 6 -target 6 -cp ${java_classpath} ${_lcmtypes_java_files} + ${JAVA_COMPILE} -source 6 -cp ${java_classpath} ${_lcmtypes_java_files} DEPENDS ${_lcmtypes_java_files} VERBATIM) # add a rule to build a .jar file from the .class files diff --git a/bot2-frames/cmake/pods.cmake b/bot2-frames/cmake/pods.cmake index 6b14caf..36fa280 100644 --- a/bot2-frames/cmake/pods.cmake +++ b/bot2-frames/cmake/pods.cmake @@ -26,7 +26,7 @@ # # ---- # File: pods.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 # pods_install_headers( ... DESTINATION ) # @@ -191,14 +191,14 @@ function(pods_install_python_script script_name python_module_or_file) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n") + "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} \"$@\"\n") else() get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists? # write the bash script file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n") + "exec ${PYTHON_EXECUTABLE} -m ${py_module} \"$@\"\n") endif() # install it... install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) @@ -223,12 +223,14 @@ function(_pods_install_python_package py_src_dir py_module_name) if(EXISTS "${py_src_dir}/__init__.py") #install the single module - file(GLOB_RECURSE py_files ${py_src_dir}/*.py) - foreach(py_file ${py_files}) - file(RELATIVE_PATH __tmp_path ${py_src_dir} ${py_file}) - get_filename_component(__tmp_dir ${__tmp_path} PATH) - install(FILES ${py_file} - DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + file(GLOB_RECURSE module_files ${py_src_dir}/*) + foreach(file ${module_files}) + if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]") + file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file}) + get_filename_component(__tmp_dir ${__tmp_path} PATH) + install(FILES ${file} + DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + endif() endforeach() else() message(FATAL_ERROR "${py_src_dir} is not a python package!\n") @@ -307,21 +309,21 @@ macro(pods_use_pkg_config_packages target) string(STRIP ${_pods_pkg_ldflags} _pods_pkg_ldflags) # message("ldflags: ${_pods_pkg_ldflags}") include_directories(${_pods_pkg_include_flags}) + target_link_libraries(${target} ${_pods_pkg_ldflags}) + # make the target depend on libraries that are cmake targets if (_pods_pkg_ldflags) string(REPLACE " " ";" _split_ldflags ${_pods_pkg_ldflags}) - target_link_libraries(${target} ${_split_ldflags}) - foreach(__ldflag ${_split_ldflags}) string(REGEX REPLACE "^-l" "" __depend_target_name ${__ldflag}) - if(TARGET ${__depend_target_name}) - #message("---- ${target} depends on ${__depend_target_name}") - add_dependencies(${target} ${__depend_target_name}) - endif() + if(TARGET "${__depend_target_name}") + #message("---- ${target} depends on ${libname}") + add_dependencies(${target} ${__depend_target_name}) + endif() endforeach() - unset(_split_ldflags) endif() + unset(_split_ldflags) unset(_pods_pkg_include_flags) unset(_pods_pkg_ldflags) endmacro() diff --git a/bot2-frames/src/CMakeLists.txt b/bot2-frames/src/CMakeLists.txt index c8bd4b5..d119291 100644 --- a/bot2-frames/src/CMakeLists.txt +++ b/bot2-frames/src/CMakeLists.txt @@ -3,6 +3,8 @@ add_definitions(-std=gnu99) add_library(bot2-frames SHARED bot_frames.c) set(REQUIRED_LIBS bot2-core bot2-param-client) +include_directories(bot_frames) + target_link_libraries(bot2-frames lcmtypes_bot2-frames) pods_use_pkg_config_packages(bot2-frames ${REQUIRED_LIBS}) list(APPEND REQUIRED_LIBS lcmtypes_bot2-frames) @@ -13,7 +15,7 @@ set_target_properties(bot2-frames PROPERTIES SOVERSION 2) # make the header public # install it to include/bot2-frames -pods_install_headers(bot_frames.h DESTINATION bot_frames) +pods_install_headers(bot_frames/bot_frames.h DESTINATION bot_frames) # make the library public pods_install_libraries(bot2-frames) diff --git a/bot2-frames/src/bot_frames.c b/bot2-frames/src/bot_frames.c index 3c11236..446765a 100644 --- a/bot2-frames/src/bot_frames.c +++ b/bot2-frames/src/bot_frames.c @@ -54,7 +54,7 @@ struct _BotFrames { lcm_t *lcm; BotParam *bot_param; - GMutex * mutex; + GMutex mutex; int num_frames; char * root_name; GHashTable* frame_handles_by_name; @@ -79,7 +79,7 @@ static void on_transform_update(const lcm_recv_buf_t *rbuf, const char *channel, void *user_data) { BotFrames * bot_frames = (BotFrames *) user_data; - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); BotTrans link_transf; bot_trans_set_from_quat_trans(&link_transf, msg->quat, msg->trans); @@ -87,7 +87,7 @@ static void on_transform_update(const lcm_recv_buf_t *rbuf, const char *channel, assert(frame_handle != NULL); frame_handle->was_updated = 1; bot_ctrans_link_update(frame_handle->ctrans_link, &link_transf, msg->utime); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); _dispatch_update_callbacks(bot_frames, frame_handle->frame_name, frame_handle->relative_to,msg->utime); @@ -97,7 +97,7 @@ static void on_pose_update(const lcm_recv_buf_t *rbuf, const char *channel, cons void *user_data) { BotFrames * bot_frames = (BotFrames *) user_data; - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); BotTrans link_transf; bot_trans_set_from_quat_trans(&link_transf, msg->orientation, msg->pos); @@ -105,7 +105,7 @@ static void on_pose_update(const lcm_recv_buf_t *rbuf, const char *channel, cons assert(frame_handle != NULL); frame_handle->was_updated = 1; bot_ctrans_link_update(frame_handle->ctrans_link, &link_transf, msg->utime); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); _dispatch_update_callbacks(bot_frames, frame_handle->frame_name, frame_handle->relative_to,msg->utime); @@ -115,7 +115,7 @@ static void on_frames_update(const lcm_recv_buf_t *rbuf, const char *channel, co void *user_data) { BotFrames * bot_frames = (BotFrames *) user_data; - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); BotTrans link_transf; bot_trans_set_from_quat_trans(&link_transf, msg->quat, msg->trans); @@ -140,7 +140,7 @@ static void on_frames_update(const lcm_recv_buf_t *rbuf, const char *channel, co fprintf(stderr, "Ignoring link update %s->%s, frame was constructed relative to %s\n", msg->frame, msg->relative_to, frame_handle->relative_to); } - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); _dispatch_update_callbacks(bot_frames, frame_handle->frame_name, frame_handle->relative_to, msg->utime); } @@ -153,9 +153,9 @@ bot_frames_new(lcm_t *lcm, BotParam *bot_param) self->lcm = lcm; self->bot_param = bot_param; - self->mutex = g_mutex_new(); + g_mutex_init(&self->mutex); self->num_frames =0; - g_mutex_lock(self->mutex); + g_mutex_lock(&self->mutex); // setup the coordinate frame graph self->ctrans = bot_ctrans_new(); @@ -293,10 +293,10 @@ bot_frames_new(lcm_t *lcm, BotParam *bot_param) self->update_subscription = bot_frames_update_t_subscribe(self->lcm, BOT_FRAMES_UPDATE_CHANNEL, on_frames_update, (void*) self); g_strfreev(frame_names); - g_mutex_unlock(self->mutex); + g_mutex_unlock(&self->mutex); return self; - fail: g_mutex_unlock(self->mutex); + fail: g_mutex_unlock(&self->mutex); bot_frames_destroy(self); return NULL; @@ -310,7 +310,7 @@ static void _update_handler_t_destroy(void * data, void * user) void bot_frames_destroy(BotFrames * bot_frames) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); bot_ctrans_destroy(bot_frames->ctrans); if(bot_frames->update_subscription!=NULL) @@ -332,8 +332,7 @@ void bot_frames_destroy(BotFrames * bot_frames) g_list_foreach(bot_frames->update_callbacks, _update_handler_t_destroy, NULL); g_list_free(bot_frames->update_callbacks); } - g_mutex_unlock(bot_frames->mutex); - g_mutex_free(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); g_slice_free(BotFrames, bot_frames); } @@ -355,35 +354,35 @@ void bot_frames_add_update_subscriber(BotFrames *bot_frames, bot_frames_link_upd update_handler_t * uh = g_slice_new0(update_handler_t); uh->callback_func = callback_func; uh->user = user; - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); bot_frames->update_callbacks = g_list_append(bot_frames->update_callbacks, uh); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); } int bot_frames_get_latest_timestamp(BotFrames * bot_frames, const char *from_frame, const char *to_frame, int64_t *timestamp){ - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); int status = bot_ctrans_get_trans_latest_timestamp(bot_frames->ctrans, from_frame, to_frame, timestamp); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return status; } int bot_frames_get_trans_with_utime(BotFrames *bot_frames, const char *from_frame, const char *to_frame, int64_t utime, BotTrans *result) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); int status = bot_ctrans_get_trans(bot_frames->ctrans, from_frame, to_frame, utime, result); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return status; } int bot_frames_get_trans(BotFrames *bot_frames, const char *from_frame, const char *to_frame, BotTrans *result) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); int status = bot_ctrans_get_trans_latest(bot_frames->ctrans, from_frame, to_frame, result); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return status; } @@ -428,17 +427,17 @@ int bot_frames_get_trans_mat_4x4_with_utime(BotFrames *bot_frames, const char *f int bot_frames_get_trans_latest_timestamp(BotFrames *bot_frames, const char *from_frame, const char *to_frame, int64_t *timestamp) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); int status = bot_ctrans_get_trans_latest_timestamp(bot_frames->ctrans, from_frame, to_frame, timestamp); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return status; } int bot_frames_have_trans(BotFrames *bot_frames, const char *from_frame, const char *to_frame) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); int status = bot_ctrans_have_trans(bot_frames->ctrans, from_frame, to_frame); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return status; } @@ -464,14 +463,14 @@ int bot_frames_rotate_vec(BotFrames *bot_frames, const char *from_frame, const c int bot_frames_get_n_trans(BotFrames *bot_frames, const char *from_frame, const char *to_frame, int nth_from_latest) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); BotCTransLink *link = bot_ctrans_get_link(bot_frames->ctrans, from_frame, to_frame); int n_trans; if (!link) n_trans = 0; else n_trans = bot_ctrans_link_get_n_trans(link); - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return n_trans; } @@ -482,7 +481,7 @@ int bot_frames_get_n_trans(BotFrames *bot_frames, const char *from_frame, const int bot_frames_get_nth_trans(BotFrames *bot_frames, const char *from_frame, const char *to_frame, int nth_from_latest, BotTrans *btrans, int64_t *timestamp) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); BotCTransLink *link = bot_ctrans_get_link(bot_frames->ctrans, from_frame, to_frame); int status; if (!link) @@ -493,19 +492,19 @@ int bot_frames_get_nth_trans(BotFrames *bot_frames, const char *from_frame, cons bot_trans_invert(btrans); } } - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return status; } const char * bot_frames_get_relative_to(BotFrames * bot_frames, const char * frame_name) { const char * rel_to = NULL; - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); //get a reference to the frame_handle frame_handle_t * frame_handle = (frame_handle_t *) g_hash_table_lookup(bot_frames->frame_handles_by_name, frame_name); //check to see if it was successful if (frame_handle != NULL) rel_to = frame_handle->relative_to; - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return rel_to; } @@ -516,9 +515,9 @@ const char * bot_frames_get_root_name(BotFrames * bot_frames) int bot_frames_get_num_frames(BotFrames * bot_frames) { - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); int num_frames = bot_frames->num_frames; - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return num_frames; } @@ -526,7 +525,7 @@ char ** bot_frames_get_frame_names(BotFrames * bot_frames) { int num_frames = bot_frames_get_num_frames(bot_frames); - g_mutex_lock(bot_frames->mutex); + g_mutex_lock(&bot_frames->mutex); char ** frames = calloc(num_frames + 1, sizeof(char*)); GHashTableIter iter; @@ -537,12 +536,12 @@ char ** bot_frames_get_frame_names(BotFrames * bot_frames) frame_handle_t * han = (frame_handle_t *) value; frames[han->frame_num] = strdup(han->frame_name); } - g_mutex_unlock(bot_frames->mutex); + g_mutex_unlock(&bot_frames->mutex); return frames; } static BotFrames *global_bot_frames = NULL; -static GStaticMutex bot_frames_global_mutex = G_STATIC_MUTEX_INIT; +static GMutex bot_frames_global_mutex; BotFrames* bot_frames_get_global(lcm_t *lcm, BotParam *bot_param) @@ -552,7 +551,7 @@ bot_frames_get_global(lcm_t *lcm, BotParam *bot_param) if (bot_param == NULL) bot_param = bot_param_get_global(lcm, 0); - g_static_mutex_lock(&bot_frames_global_mutex); + g_mutex_lock(&bot_frames_global_mutex); if (global_bot_frames == NULL) { global_bot_frames = bot_frames_new(lcm, bot_param); if (!global_bot_frames) @@ -560,10 +559,10 @@ bot_frames_get_global(lcm_t *lcm, BotParam *bot_param) } BotFrames *result = global_bot_frames; - g_static_mutex_unlock(&bot_frames_global_mutex); + g_mutex_unlock(&bot_frames_global_mutex); return result; - fail: g_static_mutex_unlock(&bot_frames_global_mutex); + fail: g_mutex_unlock(&bot_frames_global_mutex); fprintf(stderr, "ERROR: Could not get global bot_frames!\n"); return NULL; } diff --git a/bot2-frames/src/bot_frames.h b/bot2-frames/src/bot_frames/bot_frames.h similarity index 100% rename from bot2-frames/src/bot_frames.h rename to bot2-frames/src/bot_frames/bot_frames.h diff --git a/bot2-frames/src/renderer/bot_frames_renderers.h b/bot2-frames/src/bot_frames/bot_frames_renderers.h similarity index 100% rename from bot2-frames/src/renderer/bot_frames_renderers.h rename to bot2-frames/src/bot_frames/bot_frames_renderers.h diff --git a/bot2-frames/src/renderer/CMakeLists.txt b/bot2-frames/src/renderer/CMakeLists.txt index cb54da2..9913f58 100644 --- a/bot2-frames/src/renderer/CMakeLists.txt +++ b/bot2-frames/src/renderer/CMakeLists.txt @@ -4,7 +4,8 @@ add_library(bot2-frames-renderers SHARED coord_frames_renderer.c articulated_body_renderer.c frame_modifier_renderer.c) set(REQUIRED_PACKAGES bot2-core bot2-param-client bot2-vis) - + +include_directories(../bot_frames ../) pods_use_pkg_config_packages(bot2-frames-renderers ${REQUIRED_PACKAGES}) target_link_libraries(bot2-frames-renderers bot2-frames @@ -17,7 +18,7 @@ set_target_properties(bot2-frames-renderers PROPERTIES SOVERSION 1) # make the header public # install it to include/bot_frames -pods_install_headers(bot_frames_renderers.h DESTINATION bot_frames) +pods_install_headers(../bot_frames/bot_frames_renderers.h DESTINATION bot_frames) # make the library public pods_install_libraries(bot2-frames-renderers) diff --git a/bot2-frames/src/renderer/frame_modifier_renderer.c b/bot2-frames/src/renderer/frame_modifier_renderer.c index f73a839..1e0d716 100644 --- a/bot2-frames/src/renderer/frame_modifier_renderer.c +++ b/bot2-frames/src/renderer/frame_modifier_renderer.c @@ -115,7 +115,7 @@ static void on_param_widget_changed(BotGtkParamWidget *pw, const char *name, voi self->frameNames[activeSensorNum]), bot_timestamp_now(), self); } else { - bot_viewer_set_status_bar_message(self->viewer, ""); + bot_viewer_set_status_bar_message(self->viewer, " "); bot_gtk_param_widget_set_enabled(self->pw, PARAM_X, 0); bot_gtk_param_widget_set_enabled(self->pw, PARAM_Y, 0); bot_gtk_param_widget_set_enabled(self->pw, PARAM_Z, 0); diff --git a/bot2-frames/src/renderer/test_viewer.c b/bot2-frames/src/renderer/test_viewer.c index 9e0f3c4..4a726df 100644 --- a/bot2-frames/src/renderer/test_viewer.c +++ b/bot2-frames/src/renderer/test_viewer.c @@ -37,7 +37,6 @@ int main(int argc, char *argv[]) { gtk_init(&argc, &argv); glutInit(&argc, argv); - g_thread_init(NULL); // if (argc < 2) { // fprintf(stderr, "usage: %s \n", g_path_get_basename(argv[0])); diff --git a/bot2-lcm-utils/Makefile b/bot2-lcm-utils/Makefile index 2216901..c447f43 100644 --- a/bot2-lcm-utils/Makefile +++ b/bot2-lcm-utils/Makefile @@ -1,4 +1,4 @@ -# Default pod makefile distributed with pods version: 12.09.21 +# Default pod makefile distributed with pods version: 12.11.14 default_target: all diff --git a/bot2-lcm-utils/cmake/pods.cmake b/bot2-lcm-utils/cmake/pods.cmake index 7549ffd..36fa280 100644 --- a/bot2-lcm-utils/cmake/pods.cmake +++ b/bot2-lcm-utils/cmake/pods.cmake @@ -26,7 +26,7 @@ # # ---- # File: pods.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 # pods_install_headers( ... DESTINATION ) # @@ -191,14 +191,14 @@ function(pods_install_python_script script_name python_module_or_file) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n") + "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} \"$@\"\n") else() get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists? # write the bash script file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n") + "exec ${PYTHON_EXECUTABLE} -m ${py_module} \"$@\"\n") endif() # install it... install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) @@ -223,12 +223,14 @@ function(_pods_install_python_package py_src_dir py_module_name) if(EXISTS "${py_src_dir}/__init__.py") #install the single module - file(GLOB_RECURSE py_files ${py_src_dir}/*.py) - foreach(py_file ${py_files}) - file(RELATIVE_PATH __tmp_path ${py_src_dir} ${py_file}) - get_filename_component(__tmp_dir ${__tmp_path} PATH) - install(FILES ${py_file} - DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + file(GLOB_RECURSE module_files ${py_src_dir}/*) + foreach(file ${module_files}) + if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]") + file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file}) + get_filename_component(__tmp_dir ${__tmp_path} PATH) + install(FILES ${file} + DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + endif() endforeach() else() message(FATAL_ERROR "${py_src_dir} is not a python package!\n") @@ -307,22 +309,21 @@ macro(pods_use_pkg_config_packages target) string(STRIP ${_pods_pkg_ldflags} _pods_pkg_ldflags) # message("ldflags: ${_pods_pkg_ldflags}") include_directories(${_pods_pkg_include_flags}) + target_link_libraries(${target} ${_pods_pkg_ldflags}) # make the target depend on libraries that are cmake targets if (_pods_pkg_ldflags) string(REPLACE " " ";" _split_ldflags ${_pods_pkg_ldflags}) - target_link_libraries(${target} ${_split_ldflags}) - foreach(__ldflag ${_split_ldflags}) string(REGEX REPLACE "^-l" "" __depend_target_name ${__ldflag}) - if(TARGET ${__depend_target_name}) - #message("---- ${target} depends on ${__depend_target_name}") - add_dependencies(${target} ${__depend_target_name}) - endif() + if(TARGET "${__depend_target_name}") + #message("---- ${target} depends on ${libname}") + add_dependencies(${target} ${__depend_target_name}) + endif() endforeach() - unset(_split_ldflags) endif() + unset(_split_ldflags) unset(_pods_pkg_include_flags) unset(_pods_pkg_ldflags) endmacro() diff --git a/bot2-lcm-utils/src/tunnel/CMakeLists.txt b/bot2-lcm-utils/src/tunnel/CMakeLists.txt index c31e71d..cafbfa2 100644 --- a/bot2-lcm-utils/src/tunnel/CMakeLists.txt +++ b/bot2-lcm-utils/src/tunnel/CMakeLists.txt @@ -21,6 +21,7 @@ add_executable(bot-lcm-tunnel lcm_tunnel_server.cpp signal_pipe.c lcm_util.c + timestamp.c ${ldpc_sources} ) diff --git a/bot2-lcm-utils/src/tunnel/lcm_tunnel.cpp b/bot2-lcm-utils/src/tunnel/lcm_tunnel.cpp index 8d39393..d3f224d 100644 --- a/bot2-lcm-utils/src/tunnel/lcm_tunnel.cpp +++ b/bot2-lcm-utils/src/tunnel/lcm_tunnel.cpp @@ -63,9 +63,9 @@ LcmTunnel::LcmTunnel(bool verbose, const char *lcm_channel) : init_regex(lcm_channel); //sendThread stuff - sendQueueLock = g_mutex_new(); - sendQueueCond = g_cond_new(); - sendThread = g_thread_create(sendThreadFunc, (void *) this, 1, NULL); + g_mutex_init(&sendQueueLock); + g_cond_init(&sendQueueCond); + sendThread = g_thread_new("tunnel_thread", sendThreadFunc, (void *) this); } @@ -100,21 +100,18 @@ LcmTunnel::~LcmTunnel() } //cleanup the sending thread state - g_mutex_lock(sendQueueLock); + g_mutex_lock(&sendQueueLock); stopSendThread = true; - g_cond_broadcast(sendQueueCond); - g_mutex_unlock(sendQueueLock); + g_cond_broadcast(&sendQueueCond); + g_mutex_unlock(&sendQueueLock); g_thread_join(sendThread); //wait for thread to exit - g_mutex_lock(sendQueueLock); + g_mutex_lock(&sendQueueLock); while (!sendQueue.empty()) { delete sendQueue.front(); sendQueue.pop_front(); } - g_mutex_unlock(sendQueueLock); - - g_mutex_free(sendQueueLock); - g_cond_free(sendQueueCond); + g_mutex_unlock(&sendQueueLock); if (udp_fd >= 0) { @@ -152,7 +149,7 @@ void LcmTunnel::closeTCPSocket() { // fprintf(stderr, "closing TCP socket\n"); if (tcp_sock != NULL) - ssocket_destroy(tcp_sock); + bot_ssocket_destroy(tcp_sock); tcp_sock = NULL; if (tcp_ioc != NULL) g_io_channel_unref(tcp_ioc); @@ -162,7 +159,7 @@ void LcmTunnel::closeTCPSocket() tcp_sid = -1; } -int LcmTunnel::connectToClient(lcm_t * lcm_, introspect_t *introspect_, GMainLoop * mainloop_, ssocket_t * sock_, +int LcmTunnel::connectToClient(lcm_t * lcm_, introspect_t *introspect_, GMainLoop * mainloop_, bot_ssocket_t * sock_, tunnel_server_params_t * server_params_) { //for a client that connected to this server //parameters will be passed over from the client @@ -179,7 +176,7 @@ int LcmTunnel::connectToClient(lcm_t * lcm_, introspect_t *introspect_, GMainLoo snprintf(name, sizeof(name), "%s:%d", inet_ntoa(client_addr.sin_addr), client_port); printf("Accepted connection from %s\n", name); - tcp_ioc = g_io_channel_unix_new(ssocket_get_fd(tcp_sock)); + tcp_ioc = g_io_channel_unix_new(bot_ssocket_get_fd(tcp_sock)); tcp_sid = g_io_add_watch(tcp_ioc, G_IO_IN, on_tcp_data, this); bytes_to_read = 4; @@ -230,12 +227,12 @@ int LcmTunnel::connectToServer(lcm_t * lcm_, introspect_t *introspect_, GMainLoo } // connect - tcp_sock = ssocket_create(); - if (0 != ssocket_connect(tcp_sock, server_addr_str, port)) { + tcp_sock = bot_ssocket_create(); + if (0 != bot_ssocket_connect(tcp_sock, server_addr_str, port)) { perror("connecting"); return 0; } - tcp_ioc = g_io_channel_unix_new(ssocket_get_fd(tcp_sock)); + tcp_ioc = g_io_channel_unix_new(bot_ssocket_get_fd(tcp_sock)); tcp_sid = g_io_add_watch(tcp_ioc, G_IO_IN, on_tcp_data, this); //fill out the name info @@ -255,16 +252,16 @@ int LcmTunnel::connectToServer(lcm_t * lcm_, introspect_t *introspect_, GMainLoo uint8_t * msg = (uint8_t *) calloc(msg_sz, sizeof(uint8_t)); lcm_tunnel_params_t_encode(msg, 0, msg_sz, tun_params_to_send); uint32_t msg_sz_n = htonl(msg_sz); - if (4 != _fileutils_write_fully(ssocket_get_fd(tcp_sock), &msg_sz_n, 4)) { + if (4 != _fileutils_write_fully(bot_ssocket_get_fd(tcp_sock), &msg_sz_n, 4)) { perror("sending subscription data"); - ssocket_destroy(tcp_sock); + bot_ssocket_destroy(tcp_sock); free(msg); lcm_tunnel_params_t_destroy(tun_params_to_send); return 0; } - if (msg_sz != _fileutils_write_fully(ssocket_get_fd(tcp_sock), msg, msg_sz)) { + if (msg_sz != _fileutils_write_fully(bot_ssocket_get_fd(tcp_sock), msg, msg_sz)) { perror("sending subscription data"); - ssocket_destroy(tcp_sock); + bot_ssocket_destroy(tcp_sock); free(msg); lcm_tunnel_params_t_destroy(tun_params_to_send); return 0; @@ -463,7 +460,7 @@ int LcmTunnel::on_tcp_data(GIOChannel * source, GIOCondition cond, void *user_da self->buf_sz = self->bytes_to_read; } - ssize_t nread = read(ssocket_get_fd(self->tcp_sock), self->buf + self->bytes_read, self->bytes_to_read + ssize_t nread = read(bot_ssocket_get_fd(self->tcp_sock), self->buf + self->bytes_read, self->bytes_to_read - self->bytes_read); if (nread <= 0) { @@ -531,12 +528,12 @@ int LcmTunnel::on_tcp_data(GIOChannel * source, GIOCondition cond, void *user_da uint8_t msg[msg_sz]; lcm_tunnel_params_t_encode(msg, 0, msg_sz, &tp_port_msg); uint32_t msg_sz_n = htonl(msg_sz); - if (4 != _fileutils_write_fully(ssocket_get_fd(self->tcp_sock), &msg_sz_n, 4)) { + if (4 != _fileutils_write_fully(bot_ssocket_get_fd(self->tcp_sock), &msg_sz_n, 4)) { perror("sending subscription data"); LcmTunnelServer::disconnectClient(self); return FALSE; } - if (msg_sz != _fileutils_write_fully(ssocket_get_fd(self->tcp_sock), msg, msg_sz)) { + if (msg_sz != _fileutils_write_fully(bot_ssocket_get_fd(self->tcp_sock), msg, msg_sz)) { perror("sending subscription data"); LcmTunnelServer::disconnectClient(self); return FALSE; @@ -653,20 +650,18 @@ gpointer LcmTunnel::sendThreadFunc(gpointer user_data) LcmTunnel *self = (LcmTunnel*) user_data; - g_mutex_lock(self->sendQueueLock); + g_mutex_lock(&self->sendQueueLock); int64_t nextFlushTime = 0; while (!self->stopSendThread) { if (self->sendQueue.empty()) { - g_cond_wait(self->sendQueueCond, self->sendQueueLock); + g_cond_wait(&self->sendQueueCond, &self->sendQueueLock); nextFlushTime = _timestamp_now() + self->tunnel_params->max_delay_ms * 1000; continue; } int64_t now = _timestamp_now(); if (self->tunnel_params->max_delay_ms > 0 && self->bytesInQueue < NUM_BYTES_TO_SEND_IMMEDIATELY && nextFlushTime > now && !self->flushImmediately) { - GTimeVal next_timeout; - _timestamp_to_GTimeVal(nextFlushTime, &next_timeout); - g_cond_timed_wait(self->sendQueueCond, self->sendQueueLock, &next_timeout); + g_cond_wait_until(&self->sendQueueCond, &self->sendQueueLock, nextFlushTime); continue; } @@ -678,18 +673,18 @@ gpointer LcmTunnel::sendThreadFunc(gpointer user_data) tmpQueue.swap(self->sendQueue); uint32_t bytesInTmpQueue = self->bytesInQueue; self->bytesInQueue = 0; - g_mutex_unlock(self->sendQueueLock); + g_mutex_unlock(&self->sendQueueLock); //release lock for sending //process whats in the queue bool success = self->send_lcm_messages(tmpQueue, bytesInTmpQueue); //reaquire lock to go around the loop - g_mutex_lock(self->sendQueueLock); + g_mutex_lock(&self->sendQueueLock); if (!success) break; } - g_mutex_unlock(self->sendQueueLock); + g_mutex_unlock(&self->sendQueueLock); g_thread_exit(NULL); } @@ -706,7 +701,7 @@ void LcmTunnel::send_to_remote(const void *data, uint32_t len, const char *lcm_c void LcmTunnel::send_to_remote(const lcm_recv_buf_t *rbuf, const char *lcm_channel) { - g_mutex_lock(sendQueueLock); + g_mutex_lock(&sendQueueLock); TunnelLcmMessage * new_msg = new TunnelLcmMessage(rbuf, lcm_channel); bytesInQueue += new_msg->encoded_size; sendQueue.push_back(new_msg); @@ -720,8 +715,8 @@ void LcmTunnel::send_to_remote(const lcm_recv_buf_t *rbuf, const char *lcm_chann } //hack to not delay time sync messages flushImmediately = strcmp(lcm_channel, "TIMESYNC") == 0; - g_mutex_unlock(sendQueueLock); - g_cond_broadcast(sendQueueCond); //signal to say there is a message waiting + g_mutex_unlock(&sendQueueLock); + g_cond_broadcast(&sendQueueCond); //signal to say there is a message waiting } void LcmTunnel::on_lcm_message(const lcm_recv_buf_t *rbuf, const char *channel, void *user_data) @@ -864,7 +859,7 @@ bool LcmTunnel::send_lcm_messages(std::deque &msgQueue, uint free(msgBuf); } else { - int cfd = ssocket_get_fd(tcp_sock); + int cfd = bot_ssocket_get_fd(tcp_sock); assert(cfd>0); while (!msgQueue.empty()) { diff --git a/bot2-lcm-utils/src/tunnel/lcm_tunnel.h b/bot2-lcm-utils/src/tunnel/lcm_tunnel.h index 56191aa..8b3d1ac 100644 --- a/bot2-lcm-utils/src/tunnel/lcm_tunnel.h +++ b/bot2-lcm-utils/src/tunnel/lcm_tunnel.h @@ -72,7 +72,7 @@ class LcmTunnel { public: LcmTunnel(bool verbose, const char *channel); //just allocates buffers and whatnot int connectToClient(lcm_t * lcm_, introspect_t *introspect_, GMainLoop * - mainloop_, ssocket_t * sock_, tunnel_server_params_t *server_params_); + mainloop_, bot_ssocket_t * sock_, tunnel_server_params_t *server_params_); int connectToServer(lcm_t * lcm_, introspect_t *introspect_, GMainLoop * mainloop_, char * server_addr_str, int port, char * channels_to_recv, lcm_tunnel_params_t * tunnel_params_, @@ -108,7 +108,7 @@ class LcmTunnel { //tcp socket stuff - ssocket_t * tcp_sock; + bot_ssocket_t * tcp_sock; GIOChannel * tcp_ioc; guint tcp_sid; void closeTCPSocket(); @@ -127,8 +127,8 @@ class LcmTunnel { uint32_t minBytesToSendImmediately; GThread * sendThread; std::deque sendQueue; - GMutex * sendQueueLock; - GCond* sendQueueCond; //thread waits on this + GMutex sendQueueLock; + GCond sendQueueCond; //thread waits on this bool flushImmediately; diff --git a/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.cpp b/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.cpp index 0edeeb9..cf83fd1 100644 --- a/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.cpp +++ b/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.cpp @@ -26,7 +26,7 @@ introspect_t * LcmTunnelServer::introspect; std::list LcmTunnelServer::clients_list; -ssocket_t * LcmTunnelServer::server_sock; +bot_ssocket_t * LcmTunnelServer::server_sock; GIOChannel * LcmTunnelServer::server_sock_ioc; guint LcmTunnelServer::server_sock_sid; @@ -71,12 +71,12 @@ int LcmTunnelServer::initializeServer(tunnel_server_params_t * params_) bot_signal_pipe_glib_quit_on_kill(mainloop); // setup listening socket - server_sock = ssocket_create(); - if (0 != ssocket_listen(server_sock, params.port, 1, 0)) { + server_sock = bot_ssocket_create(); + if (0 != bot_ssocket_listen(server_sock, params.port, 1, 0)) { perror("creating server socket"); return 0; } - server_sock_ioc = g_io_channel_unix_new(ssocket_get_fd(server_sock)); + server_sock_ioc = g_io_channel_unix_new(bot_ssocket_get_fd(server_sock)); server_sock_sid = g_io_add_watch(server_sock_ioc, G_IO_IN, acceptClient, NULL); if (params.verbose) { printf("listening on port %d\n", params.port); @@ -103,7 +103,7 @@ void LcmTunnelServer::destroyServer() delete (*it); clients_list.clear(); - ssocket_destroy(server_sock); + bot_ssocket_destroy(server_sock); introspect_destroy(introspect); lcm_destroy(lcm); g_main_loop_quit(mainloop); @@ -112,7 +112,7 @@ void LcmTunnelServer::destroyServer() int LcmTunnelServer::acceptClient(GIOChannel *source, GIOCondition cond, void *user_data) { - ssocket_t *client_sock = ssocket_accept(server_sock); + bot_ssocket_t *client_sock = bot_ssocket_accept(server_sock); if (!client_sock) return TRUE; LcmTunnel * tunnel_client = new LcmTunnel(params.verbose, NULL); diff --git a/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.h b/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.h index 8224b87..421b78b 100644 --- a/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.h +++ b/bot2-lcm-utils/src/tunnel/lcm_tunnel_server.h @@ -28,7 +28,7 @@ class LcmTunnelServer { static std::list clients_list; - static ssocket_t * server_sock; + static bot_ssocket_t * server_sock; static GIOChannel * server_sock_ioc; static guint server_sock_sid; diff --git a/bot2-lcm-utils/src/tunnel/lcm_util.c b/bot2-lcm-utils/src/tunnel/lcm_util.c index 06a7711..eca1a0e 100644 --- a/bot2-lcm-utils/src/tunnel/lcm_util.c +++ b/bot2-lcm-utils/src/tunnel/lcm_util.c @@ -3,6 +3,7 @@ #include #include "lcm_util.h" +#include "timestamp.h" //#define dbg(...) fprintf (stderr, __VA_ARGS__) #define dbg(...) @@ -29,7 +30,7 @@ lcm_message_ready (GIOChannel *source, GIOCondition cond, void *user_data) } static GHashTable *lcm_glib_sources = NULL; -static GStaticMutex lcm_glib_sources_mutex = G_STATIC_MUTEX_INIT; +static GMutex lcm_glib_sources_mutex; static lcm_t *global_lcm = NULL; int @@ -42,7 +43,7 @@ int bot_glib_mainloop_attach_lcm_full (GMainLoop * mainloop, lcm_t *lcm, gboolean quit_on_lcm_fail) { - g_static_mutex_lock (&lcm_glib_sources_mutex); + g_mutex_lock (&lcm_glib_sources_mutex); if (!lcm_glib_sources) { lcm_glib_sources = g_hash_table_new (g_direct_hash, g_direct_equal); @@ -50,7 +51,7 @@ bot_glib_mainloop_attach_lcm_full (GMainLoop * mainloop, lcm_t *lcm, if (g_hash_table_lookup (lcm_glib_sources, lcm)) { dbg ("lcm %p already attached to mainloop\n", lcm); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } @@ -67,17 +68,17 @@ bot_glib_mainloop_attach_lcm_full (GMainLoop * mainloop, lcm_t *lcm, dbg ("inserted lcm %p into glib mainloop\n", lcm); g_hash_table_insert (lcm_glib_sources, lcm, galcm); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return 0; } int bot_glib_mainloop_detach_lcm (lcm_t *lcm) { - g_static_mutex_lock (&lcm_glib_sources_mutex); + g_mutex_lock (&lcm_glib_sources_mutex); if (!lcm_glib_sources) { dbg ("no lcm glib sources\n"); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } @@ -86,7 +87,7 @@ bot_glib_mainloop_detach_lcm (lcm_t *lcm) if (!galcm) { dbg ("couldn't find matching galcm\n"); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } @@ -102,16 +103,39 @@ bot_glib_mainloop_detach_lcm (lcm_t *lcm) lcm_glib_sources = NULL; } - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return 0; } lcm_t * bot_lcm_get_global(const char *provider) { - g_static_mutex_lock (&lcm_glib_sources_mutex); + g_mutex_lock (&lcm_glib_sources_mutex); if(!global_lcm) global_lcm = lcm_create(provider); - g_static_mutex_unlock (&lcm_glib_sources_mutex); + g_mutex_unlock (&lcm_glib_sources_mutex); return global_lcm; } + + +void bot_lcm_handle_or_timeout(lcm_t * lcm, int64_t timeout) +{ + int lcm_fileno = lcm_get_fileno(lcm); + + fd_set rfds; + int retval; + FD_ZERO(&rfds); + FD_SET(lcm_fileno, &rfds); + struct timeval tv; + bot_timestamp_to_timeval(timeout,&tv); + retval = select(lcm_fileno + 1, &rfds, NULL, NULL, &tv); + if (retval == -1) { + fprintf(stderr, "bot_lcm_handle_or_timeout: select() failed!\n"); + return; + } + if (retval) { + if (FD_ISSET(lcm_fileno, &rfds)) { + lcm_handle(lcm); + } + } +} diff --git a/bot2-lcm-utils/src/tunnel/lcm_util.h b/bot2-lcm-utils/src/tunnel/lcm_util.h index b240475..0bfdcb9 100644 --- a/bot2-lcm-utils/src/tunnel/lcm_util.h +++ b/bot2-lcm-utils/src/tunnel/lcm_util.h @@ -1,5 +1,3 @@ -// lcm_util was copied from bot_core to make lcm_tunnel a standalone pod - #ifndef __bot_lcm_util_h__ #define __bot_lcm_util_h__ @@ -85,6 +83,17 @@ int bot_glib_mainloop_attach_lcm_full(GMainLoop * mainloop, lcm_t *lcm, lcm_t *bot_lcm_get_global(const char *provider); +/** + * bot_lcm_handle_or_timeout: + * @lcm: The lcm_t object. + * @timeout max time to wait in microseconds + * + * Waits for up to @timeout seconds for an LCM message to arrive. + * It handles the first message if one arrives. + * + */ +void bot_lcm_handle_or_timeout(lcm_t * lcm, int64_t timeout); + #ifdef __cplusplus } #endif diff --git a/bot2-lcm-utils/src/tunnel/signal_pipe.h b/bot2-lcm-utils/src/tunnel/signal_pipe.h index e519340..bda4f6b 100644 --- a/bot2-lcm-utils/src/tunnel/signal_pipe.h +++ b/bot2-lcm-utils/src/tunnel/signal_pipe.h @@ -1,5 +1,3 @@ -// signal_pipe was copied from bot_core to make lcm_tunnel a standalone pod - #ifndef __bot_signal_pipe_h__ #define __bot_signal_pipe_h__ diff --git a/bot2-lcm-utils/src/tunnel/ssocket.c b/bot2-lcm-utils/src/tunnel/ssocket.c index 48eb59b..0bcb7a3 100644 --- a/bot2-lcm-utils/src/tunnel/ssocket.c +++ b/bot2-lcm-utils/src/tunnel/ssocket.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -16,44 +15,38 @@ #include #include -#define SSOCKET_UNKNOWN_TYPE 0 -#define SSOCKET_SERVER_TYPE 1 -#define SSOCKET_CLIENT_TYPE 2 +#define BOT_SSOCKET_UNKNOWN_TYPE 0 +#define BOT_SSOCKET_SERVER_TYPE 1 +#define BOT_SSOCKET_CLIENT_TYPE 2 #include "ssocket.h" -ssocket_t *ssocket_create() +bot_ssocket_t *bot_ssocket_create() { - ssocket_t *s = (ssocket_t*) calloc(1, sizeof(ssocket_t)); - s->socket = -1; + bot_ssocket_t *s = (bot_ssocket_t*) calloc(1, sizeof(bot_ssocket_t)); - return s; + return s; } -void ssocket_destroy(ssocket_t *s) +void bot_ssocket_destroy(bot_ssocket_t *s) { - if (s->socket >= 0) - close(s->socket); - free(s); + close(s->socket); + free(s); } -int ssocket_connect(ssocket_t *s, const char *hostname, int port) +int bot_ssocket_connect(bot_ssocket_t *s, const char *hostname, int port) { - struct hostent *host = NULL; - struct sockaddr_in sa, ca; + struct hostent *host; + struct sockaddr_in sa; int thesocket; - + /* let's find out about this host */ - int host_lookup = 0; - if(0 == inet_aton(hostname, &ca.sin_addr)) { - host_lookup = 1; - host=gethostbyname(hostname); - if (host==NULL) - { - // perror(hostname); - return -1; - } - } + host=gethostbyname(hostname); + if (host==NULL) + { + // perror(hostname); + return -1; + } /* create the socket */ thesocket=socket(AF_INET,SOCK_STREAM,0); @@ -73,10 +66,7 @@ int ssocket_connect(ssocket_t *s, const char *hostname, int port) } sa.sin_port=htons(port); - if (host_lookup) - sa.sin_addr=*(struct in_addr *) host->h_addr; - else - sa.sin_addr=ca.sin_addr; + sa.sin_addr=*(struct in_addr *) host->h_addr; if (connect(thesocket, (struct sockaddr *) &sa, sizeof (sa))) { @@ -88,7 +78,7 @@ int ssocket_connect(ssocket_t *s, const char *hostname, int port) } } - s->type=SSOCKET_CLIENT_TYPE; + s->type=BOT_SSOCKET_CLIENT_TYPE; s->socket=thesocket; // prevent "broken pipe" signals. @@ -98,7 +88,7 @@ int ssocket_connect(ssocket_t *s, const char *hostname, int port) } // returns 0 on success -int ssocket_disable_nagle(ssocket_t *s) +int bot_ssocket_disable_nagle(bot_ssocket_t *s) { int n=1; @@ -113,7 +103,7 @@ int ssocket_disable_nagle(ssocket_t *s) return 0; } -int ssocket_listen(ssocket_t *s, int port, int listenqueue, int localhostOnly) +int bot_ssocket_listen(bot_ssocket_t *s, int port, int listenqueue, int localhostOnly) { int thesocket,n; struct sockaddr_in sa; @@ -155,20 +145,20 @@ int ssocket_listen(ssocket_t *s, int port, int listenqueue, int localhostOnly) return -1; } - s->type=SSOCKET_SERVER_TYPE; + s->type=BOT_SSOCKET_SERVER_TYPE; s->socket=thesocket; return 0; } -ssocket_t *ssocket_accept(ssocket_t *s) +bot_ssocket_t *bot_ssocket_accept(bot_ssocket_t *s) { int thesocket; - ssocket_t *cs = ssocket_create(); + bot_ssocket_t *cs = bot_ssocket_create(); s->addrlen=sizeof(struct sockaddr); - if (s->type!=SSOCKET_SERVER_TYPE) + if (s->type!=BOT_SSOCKET_SERVER_TYPE) { printf("not server type\n"); return NULL; @@ -181,13 +171,13 @@ ssocket_t *ssocket_accept(ssocket_t *s) return NULL; } - cs->type = SSOCKET_CLIENT_TYPE; + cs->type = BOT_SSOCKET_CLIENT_TYPE; cs->socket = thesocket; return cs; } -void ssocket_get_remote_ip(ssocket_t *s, int *ip) +void bot_ssocket_get_remote_ip(bot_ssocket_t *s, int *ip) { struct sockaddr addr; socklen_t addrlen; @@ -200,7 +190,7 @@ void ssocket_get_remote_ip(ssocket_t *s, int *ip) ip[3] = (int) (addr.sa_data[5])&0xff; } -int ssocket_get_fd(ssocket_t *s) +int bot_ssocket_get_fd(bot_ssocket_t *s) { return s->socket; } diff --git a/bot2-lcm-utils/src/tunnel/ssocket.h b/bot2-lcm-utils/src/tunnel/ssocket.h index a17c15a..a413873 100644 --- a/bot2-lcm-utils/src/tunnel/ssocket.h +++ b/bot2-lcm-utils/src/tunnel/ssocket.h @@ -1,6 +1,18 @@ -#ifndef _SSOCKET_H -#define _SSOCKET_H +#ifndef __bot_ssocket_h__ +#define __bot_ssocket_h__ +/** + * @defgroup BotCoreSSocket TCP Sockets + * @brief Convenience data structure for using a TCP socket + * @ingroup BotCoreIO + * @include: bot_core/bot_core.h + * + * TODO + * + * Linking: `pkg-config --libs bot2-core` + * + * @{ + */ #include #include @@ -10,9 +22,9 @@ extern "C" { #endif -typedef struct ssocket ssocket_t; +typedef struct bot_ssocket bot_ssocket_t; -struct ssocket +struct bot_ssocket { int type; int socket; @@ -22,28 +34,21 @@ struct ssocket }; -ssocket_t *ssocket_create(void); -void ssocket_destroy(ssocket_t *s); - -// returns < 0 on error -int ssocket_connect(ssocket_t *s, const char *hostname, int port); +bot_ssocket_t *bot_ssocket_create(void); +void bot_ssocket_destroy(bot_ssocket_t *s); +int bot_ssocket_connect(bot_ssocket_t *s, const char *hostname, int port); +int bot_ssocket_disable_nagle(bot_ssocket_t *s); +int bot_ssocket_listen(bot_ssocket_t *s, int port, int listenqueue, int localhostOnly); +bot_ssocket_t *bot_ssocket_accept(bot_ssocket_t *s); +void bot_ssocket_get_remote_ip(bot_ssocket_t *s, int *ip); +int bot_ssocket_get_fd(bot_ssocket_t *s); -int ssocket_disable_nagle(ssocket_t *s); -int ssocket_listen(ssocket_t *s, int port, int listenqueue, int localhostOnly); -ssocket_t *ssocket_accept(ssocket_t *s); +#ifdef __cplusplus +} +#endif /** - * ssocket_get_remote_ip: - * - * retrieves the IP address of the remote end of the connection. each octet of - * the address is stored in a separate array element + * @} */ -void ssocket_get_remote_ip(ssocket_t *s, int ip[4]); - -int ssocket_get_fd(ssocket_t *s); - -#ifdef __cplusplus -} -#endif #endif diff --git a/bot2-lcm-utils/src/tunnel/timestamp.c b/bot2-lcm-utils/src/tunnel/timestamp.c new file mode 100644 index 0000000..6256c63 --- /dev/null +++ b/bot2-lcm-utils/src/tunnel/timestamp.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include + +#include "timestamp.h" + +int64_t bot_timestamp_now() +{ + struct timeval tv; + gettimeofday (&tv, NULL); + return (int64_t) tv.tv_sec * 1000000 + tv.tv_usec; +} + +int64_t bot_timestamp_seconds(int64_t v) +{ + return v/1000000; +} + +int64_t bot_timestamp_useconds(int64_t v) +{ + return v%1000000; +} + +void bot_timestamp_to_timeval(int64_t v, struct timeval *tv) +{ + tv->tv_sec = bot_timestamp_seconds(v); + tv->tv_usec = bot_timestamp_useconds(v); +} + +void bot_timestamp_to_timespec(int64_t v, struct timespec *ts) +{ + ts->tv_sec = bot_timestamp_seconds(v); + ts->tv_nsec = bot_timestamp_useconds(v)*1000; +} + +bot_timestamp_sync_state_t * +bot_timestamp_sync_init (double dev_ticks_per_second, int64_t dev_ticks_wraparound, + double rate) +{ + bot_timestamp_sync_state_t * s; + + s = malloc (sizeof (bot_timestamp_sync_state_t)); + if (!s) + return NULL; + memset (s, 0, sizeof (bot_timestamp_sync_state_t)); + + s->dev_ticks_per_second = dev_ticks_per_second; + s->dev_ticks_wraparound = dev_ticks_wraparound; + s->max_rate_error = rate; + s->is_valid = 0; + + return s; +} + +void +bot_timestamp_sync_free (bot_timestamp_sync_state_t * s) +{ + free (s); +} + +int64_t +bot_timestamp_sync (bot_timestamp_sync_state_t * s, int64_t dev_ticks, + int64_t host_utime) +{ + if (!s->is_valid) { + /* The first sync has no history */ + s->is_valid = 1; + + s->sync_host_time = host_utime; + s->last_dev_ticks = dev_ticks; + s->dev_ticks_since_sync = 0; + + return host_utime; + } + + // how many device ticks since the last invocation? + int64_t dticks = dev_ticks - s->last_dev_ticks; + s->last_dev_ticks = dev_ticks; + if (dticks < 0) + dticks += s->dev_ticks_wraparound; + + s->dev_ticks_since_sync += dticks; + + // overestimate device time by a factor of s->rate + double rate = 1000000.0 / s->dev_ticks_per_second * s->max_rate_error; + + // estimate of the host's time corresponding to the device's time + int64_t dev_utime = s->sync_host_time + (s->dev_ticks_since_sync * rate); + + int64_t time_err = host_utime - dev_utime; + + /* If time_err is very large, resynchronize, emitting a warning. if + * it is negative, we're just adjusting our timebase (it means + * we got a nice new low-latency measurement.) */ + if (time_err > 1000000000LL) { /* 1000 seconds */ + fprintf (stderr, "Warning: Time sync has drifted by more than 1000 seconds\n"); + s->sync_host_time = host_utime; + s->dev_ticks_since_sync = 0; + dev_utime = host_utime; + } + if (time_err < 0) { + s->sync_host_time = host_utime; + s->dev_ticks_since_sync = 0; + dev_utime = host_utime; + } + //printf ("%llu %llu %lld %lld\n", host_utime, dev_utime, time_err, dev_utime + s->time_offset); + + return dev_utime; +} diff --git a/bot2-lcm-utils/src/tunnel/timestamp.h b/bot2-lcm-utils/src/tunnel/timestamp.h new file mode 100644 index 0000000..862b7c7 --- /dev/null +++ b/bot2-lcm-utils/src/tunnel/timestamp.h @@ -0,0 +1,83 @@ +#ifndef __bot_timestamp_h__ +#define __bot_timestamp_h__ + +#include +#include +#include + +/** + * @defgroup BotCoreTimestamp Timestamp + * @brief Retrieving the current time, synchronizing clocks + * @ingroup BotCoreTime + * @include: bot_core/bot_core.h + * + * TODO + * + * Linking: `pkg-config --libs bot2-core` + * + * @{ + */ + +typedef struct bot_timestamp_sync_state bot_timestamp_sync_state_t; + +struct bot_timestamp_sync_state { + double dev_ticks_per_second; // how fast does device clock count? (nominal) + int64_t dev_ticks_wraparound; // device clock counts modulo what? + double max_rate_error; // how fast do we need to count to ensure we're counting faster than device? + + int64_t sync_host_time; // when we last synced, what time was it for the host? + int64_t dev_ticks_since_sync; // how many device ticks have elapsed since the last sync? + + int64_t last_dev_ticks; // what device time was it when we were last called? + + uint8_t is_valid; // have we ever synced? +}; + +#ifdef __cplusplus +extern "C" { +#endif + +int64_t bot_timestamp_now(void); +int64_t bot_timestamp_seconds(int64_t v); +int64_t bot_timestamp_useconds(int64_t v); +void bot_timestamp_to_timeval(int64_t v, struct timeval *tv); +void bot_timestamp_to_timespec(int64_t v, struct timespec *ts); + +/** Create a new time synchronizer. + @param dev_ticks_per_second The nominal rate at which the device time increments + @param dev_ticks_wraparound Assume that dev_ticks wraps around every wraparound ticks + @param rate An upper bound on the rate error + + The syncronization algorithm is described in: + @inproceedings{olson2010, + TITLE = {A Passive Solution to the Sensor Synchronization Problem}, + AUTHOR = { Edwin Olson}, + BOOKTITLE = {Proceedings of the {IEEE/RSJ} International Conference on Intelligent + Robots and Systems {(IROS)}}, + YEAR = {2010}, + MONTH = {October}, + VOLUME = {}, + NUMBER = {}, + PAGES = {}, + KEYWORDS = {sensor calibration, time synchronization}, + ISSN = { }, + } +**/ +bot_timestamp_sync_state_t * +bot_timestamp_sync_init (double dev_ticks_per_second, int64_t dev_ticks_wraparound, + double rate); +void +bot_timestamp_sync_free (bot_timestamp_sync_state_t * s); +int64_t +bot_timestamp_sync (bot_timestamp_sync_state_t * s, int64_t dev_ticks, + int64_t host_utime); + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif diff --git a/bot2-lcmgl/Makefile b/bot2-lcmgl/Makefile index 2216901..c447f43 100644 --- a/bot2-lcmgl/Makefile +++ b/bot2-lcmgl/Makefile @@ -1,4 +1,4 @@ -# Default pod makefile distributed with pods version: 12.09.21 +# Default pod makefile distributed with pods version: 12.11.14 default_target: all diff --git a/bot2-lcmgl/cmake/lcmtypes.cmake b/bot2-lcmgl/cmake/lcmtypes.cmake index 72c711a..daca283 100644 --- a/bot2-lcmgl/cmake/lcmtypes.cmake +++ b/bot2-lcmgl/cmake/lcmtypes.cmake @@ -78,7 +78,7 @@ # # ---- # File: lcmtypes.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 cmake_minimum_required(VERSION 2.6.0) @@ -369,7 +369,7 @@ function(lcmtypes_build_java) # search for lcmtypes_*.jar files in well-known places and add them to the # classpath - foreach(pfx /usr /usr/local ${CMAKE_INSTALL_PREFIX}) + foreach(pfx ${CMAKE_INSTALL_PREFIX} /usr /usr/local) file(GLOB_RECURSE jarfiles ${pfx}/share/java/lcmtypes_*.jar) foreach(jarfile ${jarfiles}) set(java_classpath ${java_classpath}:${jarfile}) @@ -388,7 +388,7 @@ function(lcmtypes_build_java) # add a rule to build the .class files from from the .java files add_custom_command(OUTPUT ${_lcmtypes_class_files} COMMAND - ${JAVA_COMPILE} -source 6 -target 6 -cp ${java_classpath} ${_lcmtypes_java_files} + ${JAVA_COMPILE} -source 6 -cp ${java_classpath} ${_lcmtypes_java_files} DEPENDS ${_lcmtypes_java_files} VERBATIM) # add a rule to build a .jar file from the .class files diff --git a/bot2-lcmgl/cmake/pods.cmake b/bot2-lcmgl/cmake/pods.cmake index 7549ffd..36fa280 100644 --- a/bot2-lcmgl/cmake/pods.cmake +++ b/bot2-lcmgl/cmake/pods.cmake @@ -26,7 +26,7 @@ # # ---- # File: pods.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 # pods_install_headers( ... DESTINATION ) # @@ -191,14 +191,14 @@ function(pods_install_python_script script_name python_module_or_file) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n") + "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} \"$@\"\n") else() get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists? # write the bash script file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n") + "exec ${PYTHON_EXECUTABLE} -m ${py_module} \"$@\"\n") endif() # install it... install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) @@ -223,12 +223,14 @@ function(_pods_install_python_package py_src_dir py_module_name) if(EXISTS "${py_src_dir}/__init__.py") #install the single module - file(GLOB_RECURSE py_files ${py_src_dir}/*.py) - foreach(py_file ${py_files}) - file(RELATIVE_PATH __tmp_path ${py_src_dir} ${py_file}) - get_filename_component(__tmp_dir ${__tmp_path} PATH) - install(FILES ${py_file} - DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + file(GLOB_RECURSE module_files ${py_src_dir}/*) + foreach(file ${module_files}) + if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]") + file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file}) + get_filename_component(__tmp_dir ${__tmp_path} PATH) + install(FILES ${file} + DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + endif() endforeach() else() message(FATAL_ERROR "${py_src_dir} is not a python package!\n") @@ -307,22 +309,21 @@ macro(pods_use_pkg_config_packages target) string(STRIP ${_pods_pkg_ldflags} _pods_pkg_ldflags) # message("ldflags: ${_pods_pkg_ldflags}") include_directories(${_pods_pkg_include_flags}) + target_link_libraries(${target} ${_pods_pkg_ldflags}) # make the target depend on libraries that are cmake targets if (_pods_pkg_ldflags) string(REPLACE " " ";" _split_ldflags ${_pods_pkg_ldflags}) - target_link_libraries(${target} ${_split_ldflags}) - foreach(__ldflag ${_split_ldflags}) string(REGEX REPLACE "^-l" "" __depend_target_name ${__ldflag}) - if(TARGET ${__depend_target_name}) - #message("---- ${target} depends on ${__depend_target_name}") - add_dependencies(${target} ${__depend_target_name}) - endif() + if(TARGET "${__depend_target_name}") + #message("---- ${target} depends on ${libname}") + add_dependencies(${target} ${__depend_target_name}) + endif() endforeach() - unset(_split_ldflags) endif() + unset(_split_ldflags) unset(_pods_pkg_include_flags) unset(_pods_pkg_ldflags) endmacro() diff --git a/bot2-lcmgl/src/lcmgl-viewer/main.c b/bot2-lcmgl/src/lcmgl-viewer/main.c index 6f0a592..42935a6 100644 --- a/bot2-lcmgl/src/lcmgl-viewer/main.c +++ b/bot2-lcmgl/src/lcmgl-viewer/main.c @@ -57,7 +57,6 @@ int main(int argc, char *argv[]) { gtk_init(&argc, &argv); glutInit(&argc, argv); - g_thread_init(NULL); setlinebuf(stdout); diff --git a/bot2-param/CMakeLists.txt b/bot2-param/CMakeLists.txt index 2cb8102..b157cd6 100644 --- a/bot2-param/CMakeLists.txt +++ b/bot2-param/CMakeLists.txt @@ -8,7 +8,7 @@ pods_config_search_paths() # automatically build LCM types. This also defines a number of CMake # variables, see cmake/lcmtypes.cmake for details include(cmake/lcmtypes.cmake) -lcmtypes_build() +lcmtypes_build() #C_AGGREGATE_HEADER bot_param add_subdirectory(src/param_client) add_subdirectory(src/param_server) diff --git a/bot2-param/Makefile b/bot2-param/Makefile index 2216901..c447f43 100644 --- a/bot2-param/Makefile +++ b/bot2-param/Makefile @@ -1,4 +1,4 @@ -# Default pod makefile distributed with pods version: 12.09.21 +# Default pod makefile distributed with pods version: 12.11.14 default_target: all diff --git a/bot2-param/cmake/lcmtypes.cmake b/bot2-param/cmake/lcmtypes.cmake index 72c711a..daca283 100644 --- a/bot2-param/cmake/lcmtypes.cmake +++ b/bot2-param/cmake/lcmtypes.cmake @@ -78,7 +78,7 @@ # # ---- # File: lcmtypes.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 cmake_minimum_required(VERSION 2.6.0) @@ -369,7 +369,7 @@ function(lcmtypes_build_java) # search for lcmtypes_*.jar files in well-known places and add them to the # classpath - foreach(pfx /usr /usr/local ${CMAKE_INSTALL_PREFIX}) + foreach(pfx ${CMAKE_INSTALL_PREFIX} /usr /usr/local) file(GLOB_RECURSE jarfiles ${pfx}/share/java/lcmtypes_*.jar) foreach(jarfile ${jarfiles}) set(java_classpath ${java_classpath}:${jarfile}) @@ -388,7 +388,7 @@ function(lcmtypes_build_java) # add a rule to build the .class files from from the .java files add_custom_command(OUTPUT ${_lcmtypes_class_files} COMMAND - ${JAVA_COMPILE} -source 6 -target 6 -cp ${java_classpath} ${_lcmtypes_java_files} + ${JAVA_COMPILE} -source 6 -cp ${java_classpath} ${_lcmtypes_java_files} DEPENDS ${_lcmtypes_java_files} VERBATIM) # add a rule to build a .jar file from the .class files diff --git a/bot2-param/cmake/pods.cmake b/bot2-param/cmake/pods.cmake index 7549ffd..36fa280 100644 --- a/bot2-param/cmake/pods.cmake +++ b/bot2-param/cmake/pods.cmake @@ -26,7 +26,7 @@ # # ---- # File: pods.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 # pods_install_headers( ... DESTINATION ) # @@ -191,14 +191,14 @@ function(pods_install_python_script script_name python_module_or_file) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n") + "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} \"$@\"\n") else() get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists? # write the bash script file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n") + "exec ${PYTHON_EXECUTABLE} -m ${py_module} \"$@\"\n") endif() # install it... install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) @@ -223,12 +223,14 @@ function(_pods_install_python_package py_src_dir py_module_name) if(EXISTS "${py_src_dir}/__init__.py") #install the single module - file(GLOB_RECURSE py_files ${py_src_dir}/*.py) - foreach(py_file ${py_files}) - file(RELATIVE_PATH __tmp_path ${py_src_dir} ${py_file}) - get_filename_component(__tmp_dir ${__tmp_path} PATH) - install(FILES ${py_file} - DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + file(GLOB_RECURSE module_files ${py_src_dir}/*) + foreach(file ${module_files}) + if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]") + file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file}) + get_filename_component(__tmp_dir ${__tmp_path} PATH) + install(FILES ${file} + DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + endif() endforeach() else() message(FATAL_ERROR "${py_src_dir} is not a python package!\n") @@ -307,22 +309,21 @@ macro(pods_use_pkg_config_packages target) string(STRIP ${_pods_pkg_ldflags} _pods_pkg_ldflags) # message("ldflags: ${_pods_pkg_ldflags}") include_directories(${_pods_pkg_include_flags}) + target_link_libraries(${target} ${_pods_pkg_ldflags}) # make the target depend on libraries that are cmake targets if (_pods_pkg_ldflags) string(REPLACE " " ";" _split_ldflags ${_pods_pkg_ldflags}) - target_link_libraries(${target} ${_split_ldflags}) - foreach(__ldflag ${_split_ldflags}) string(REGEX REPLACE "^-l" "" __depend_target_name ${__ldflag}) - if(TARGET ${__depend_target_name}) - #message("---- ${target} depends on ${__depend_target_name}") - add_dependencies(${target} ${__depend_target_name}) - endif() + if(TARGET "${__depend_target_name}") + #message("---- ${target} depends on ${libname}") + add_dependencies(${target} ${__depend_target_name}) + endif() endforeach() - unset(_split_ldflags) endif() + unset(_split_ldflags) unset(_pods_pkg_include_flags) unset(_pods_pkg_ldflags) endmacro() diff --git a/bot2-param/src/param_client/CMakeLists.txt b/bot2-param/src/param_client/CMakeLists.txt index 47e3cfd..7246277 100644 --- a/bot2-param/src/param_client/CMakeLists.txt +++ b/bot2-param/src/param_client/CMakeLists.txt @@ -13,7 +13,7 @@ list(APPEND REQUIRED_LIBS lcmtypes_bot2-param) set_target_properties(bot2-param-client PROPERTIES SOVERSION 1) # make the header public -pods_install_headers(param_client.h param_util.h DESTINATION bot_param) +pods_install_headers(bot_param/param_client.h bot_param/param_util.h DESTINATION bot_param) # make the library public pods_install_libraries(bot2-param-client) diff --git a/bot2-param/src/param_client/param_client.h b/bot2-param/src/param_client/bot_param/param_client.h similarity index 100% rename from bot2-param/src/param_client/param_client.h rename to bot2-param/src/param_client/bot_param/param_client.h diff --git a/bot2-param/src/param_client/param_util.h b/bot2-param/src/param_client/bot_param/param_util.h similarity index 100% rename from bot2-param/src/param_client/param_util.h rename to bot2-param/src/param_client/bot_param/param_util.h diff --git a/bot2-param/src/param_client/param_internal.c b/bot2-param/src/param_client/param_internal.c index b9302f0..50068ee 100644 --- a/bot2-param/src/param_client/param_internal.c +++ b/bot2-param/src/param_client/param_internal.c @@ -14,10 +14,13 @@ #include #include #include -#include "param_client.h" +#include "bot_param/param_client.h" #include "param_internal.h" #include "misc_utils.h" -#include +#include +#include +#include +#include #include #include @@ -97,7 +100,7 @@ struct _BotParamElement { struct _BotParam { BotParamElement * root; - GMutex * lock; + GMutex lock; int64_t server_id; int64_t sequence_number; @@ -612,7 +615,7 @@ static int write_container(BotParamElement * el, int indent, FILE * f) * f. */ int bot_param_write(BotParam * param, FILE * f) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * child, *root; root = param->root; @@ -624,11 +627,11 @@ int bot_param_write(BotParam * param, FILE * f) write_array(child, 0, f); else { fprintf(stderr, "Error: unknown child (%d)\n", child->type); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return 0; } @@ -684,14 +687,10 @@ static BotParam * _bot_param_new(void) root = new_element(NULL); root->type = BotParamContainer; - if (!g_thread_supported ()) - g_thread_init (NULL); - - BotParam * param; param = calloc(1, sizeof(BotParam)); param->root = root; - param->lock = g_mutex_new(); + g_mutex_init(¶m->lock); param->server_id = -1; param->sequence_number = 0; @@ -709,7 +708,6 @@ static void _update_handler_t_destroy(void * data, void * user) void bot_param_destroy(BotParam * param) { free_element(param->root); - g_mutex_free(param->lock); if (param->update_callbacks != NULL) { g_list_foreach(param->update_callbacks, _update_handler_t_destroy, NULL); @@ -725,9 +723,9 @@ void bot_param_add_update_subscriber(BotParam *param, update_handler_t * uh = g_slice_new0(update_handler_t); uh->callback_func = callback_func; uh->user = user; - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); param->update_callbacks = g_list_append(param->update_callbacks, uh); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); } @@ -768,13 +766,13 @@ static void _on_param_update(const lcm_recv_buf_t *rbuf, const char * channel, c _dispatch_update_callbacks(param,new_params, rbuf->recv_utime); //swap the root; - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); param->sequence_number = msg->sequence_number; BotParamElement * root = new_params->root; new_params->root = param->root; param->root = root; bot_param_destroy(new_params); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); } @@ -1048,21 +1046,21 @@ static double cast_to_double(const char * key, const char * val, double * out) int bot_param_has_key(BotParam *param, const char *key) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); int ret = (find_key(param->root, key, 1) != NULL); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return ret; } int bot_param_get_num_subkeys(BotParam * param, const char * containerKey) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement* el = param->root; if ((NULL != containerKey) && (0 < strlen(containerKey))) el = find_key(param->root, containerKey, 1); if (NULL == el) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } @@ -1071,7 +1069,7 @@ int bot_param_get_num_subkeys(BotParam * param, const char * containerKey) for (child = el->children; child; child = child->next) ++count; - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return count; } @@ -1079,13 +1077,13 @@ int bot_param_get_num_subkeys(BotParam * param, const char * containerKey) char ** bot_param_get_subkeys(BotParam * param, const char * containerKey) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement* el = param->root; if ((NULL != containerKey) && (0 < strlen(containerKey))) el = find_key(param->root, containerKey, 1); if (NULL == el) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return NULL; } @@ -1101,65 +1099,65 @@ bot_param_get_subkeys(BotParam * param, const char * containerKey) result[i] = strdup(child->name); i++; } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return result; } int bot_param_get_int(BotParam * param, const char * key, int * val) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray || el->num_values < 1) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } int ret = cast_to_int(key, el->values[0], val); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return ret; } int bot_param_get_boolean(BotParam * param, const char * key, int * val) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray || el->num_values < 1) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } int ret = cast_to_boolean(key, el->values[0], val); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return ret; } int bot_param_get_double(BotParam * param, const char * key, double * val) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray || el->num_values < 1) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } double ret = cast_to_double(key, el->values[0], val); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return ret; } int bot_param_get_str(BotParam * param, const char * key, char ** val) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray || el->num_values < 1) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } *val = strdup(el->values[0]); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return 0; } @@ -1209,11 +1207,11 @@ char *bot_param_get_str_or_fail(BotParam *param, const char *key) int bot_param_get_int_array(BotParam * param, const char * key, int * vals, int len) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } int i; @@ -1222,7 +1220,7 @@ int bot_param_get_int_array(BotParam * param, const char * key, int * vals, int break; if (cast_to_int(key, el->values[i], vals + i) < 0) { err("WARNING: BotParam: cast error parsing int array %s\n", key); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } } @@ -1231,7 +1229,7 @@ int bot_param_get_int_array(BotParam * param, const char * key, int * vals, int " %s\n", i, len, key); } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return i; } @@ -1249,11 +1247,11 @@ void bot_param_get_int_array_or_fail(BotParam * param, const char * key, int * v int bot_param_get_boolean_array(BotParam * param, const char * key, int * vals, int len) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } int i; @@ -1262,7 +1260,7 @@ int bot_param_get_boolean_array(BotParam * param, const char * key, int * vals, break; if (cast_to_boolean(key, el->values[i], vals + i) < 0) { err("WARNING: BotParam: cast error parsing boolean array %s\n", key); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } } @@ -1271,7 +1269,7 @@ int bot_param_get_boolean_array(BotParam * param, const char * key, int * vals, " %s\n", i, len, key); } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return i; } @@ -1289,11 +1287,11 @@ void bot_param_get_boolean_array_or_fail(BotParam * param, const char * key, int int bot_param_get_double_array(BotParam * param, const char * key, double * vals, int len) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } int i; @@ -1302,7 +1300,7 @@ int bot_param_get_double_array(BotParam * param, const char * key, double * vals break; if (cast_to_double(key, el->values[i], vals + i) < 0) { err("WARNING: BotParam: cast error parsing double array %s\n", key); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } } @@ -1311,7 +1309,7 @@ int bot_param_get_double_array(BotParam * param, const char * key, double * vals " %s\n", i, len, key); } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return i; } @@ -1328,26 +1326,26 @@ void bot_param_get_double_array_or_fail(BotParam * param, const char * key, doub int bot_param_get_array_len(BotParam *param, const char * key) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } int ret = el->num_values; - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return ret; } char ** bot_param_get_str_array_alloc(BotParam * param, const char * key) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 1); if (!el || el->type != BotParamArray) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return NULL; } @@ -1359,7 +1357,7 @@ bot_param_get_str_array_alloc(BotParam * param, const char * key) data[i] = strdup(el->values[i]); } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return data; } @@ -1413,13 +1411,13 @@ create_key(BotParamElement * el, const char * key) static int set_value(BotParam * param, const char * key, const char * val) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement * el = find_key(param->root, key, 0); if (el == NULL) el = create_key(param->root, key); else if (el->type != BotParamArray) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } @@ -1430,7 +1428,7 @@ static int set_value(BotParam * param, const char * key, const char * val) el->values[0] = strdup(val); } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return 1; } @@ -1544,11 +1542,11 @@ int bot_param_set_double_array(BotParam * param, const char * key, double * vals int bot_param_set_str_array(BotParam * param, const char * key, const char ** vals, int len) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); BotParamElement* el = find_key(param->root, key, 0); if ((el != NULL) && (el->type != BotParamArray)) { - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } @@ -1561,33 +1559,33 @@ int bot_param_set_str_array(BotParam * param, const char * key, const char ** va if (0 == add_value(NULL, el, vals[i])) ++num_set; } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return num_set; } int64_t bot_param_get_server_id(BotParam * param) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); int64_t ret = param->server_id; - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return ret; } int bot_param_get_seqno(BotParam * param) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); int ret = param->sequence_number; - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return ret; } static BotParam *global_param = NULL; -static GStaticMutex bot_param_global_mutex = G_STATIC_MUTEX_INIT; +static GMutex bot_param_global_mutex; BotParam* bot_param_get_global(lcm_t * lcm, int keep_updated) { - g_static_mutex_lock(&bot_param_global_mutex); + g_mutex_lock(&bot_param_global_mutex); if (lcm == NULL) lcm = bot_lcm_get_global(NULL); @@ -1603,10 +1601,10 @@ bot_param_get_global(lcm_t * lcm, int keep_updated) } BotParam *result = global_param; - g_static_mutex_unlock(&bot_param_global_mutex); + g_mutex_unlock(&bot_param_global_mutex); return result; - fail: g_static_mutex_unlock(&bot_param_global_mutex); + fail: g_mutex_unlock(&bot_param_global_mutex); fprintf(stderr, "ERROR: Could not get global BotParam!\n"); return NULL; } @@ -1614,15 +1612,15 @@ bot_param_get_global(lcm_t * lcm, int keep_updated) int bot_param_override_local_param(BotParam * param, const char * key, const char * val) { - g_mutex_lock(param->lock); + g_mutex_lock(¶m->lock); if (param->server_id > 0) { fprintf(stderr, "ERROR: bot_param_local_override() with key: %s and val %s called on server that is subscribed to updates!\n", key, val); - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); return -1; } - g_mutex_unlock(param->lock); + g_mutex_unlock(¶m->lock); if (bot_param_has_key(param, key)) fprintf(stderr, "BotParam overriding param key:%s with value %s\n", key, val); diff --git a/bot2-param/src/param_client/param_internal.h b/bot2-param/src/param_client/param_internal.h index 33ddad0..97b0636 100644 --- a/bot2-param/src/param_client/param_internal.h +++ b/bot2-param/src/param_client/param_internal.h @@ -1,4 +1,4 @@ -#include "param_client.h" +#include "bot_param/param_client.h" #define BOT_PARAM_UPDATE_CHANNEL "PARAM_UPDATE" #define BOT_PARAM_REQUEST_CHANNEL "PARAM_REQUEST" diff --git a/bot2-param/src/param_client/param_util.c b/bot2-param/src/param_client/param_util.c index 1360490..aeb142f 100644 --- a/bot2-param/src/param_client/param_util.c +++ b/bot2-param/src/param_client/param_util.c @@ -1,7 +1,7 @@ #include #include #include -#include "param_util.h" +#include "bot_param/param_util.h" #define PLANAR_LIDAR_PREFIX "planar_lidars" #define CAMERA_PREFIX "cameras" diff --git a/bot2-param/src/param_server/param_server.c b/bot2-param/src/param_server/param_server.c index 34725c0..77ea5e9 100644 --- a/bot2-param/src/param_server/param_server.c +++ b/bot2-param/src/param_server/param_server.c @@ -14,7 +14,10 @@ #include "../param_client/misc_utils.h" #include "../param_client/param_internal.h" -#include +#include +#include +#include +#include typedef struct { BotParam * params; @@ -97,7 +100,7 @@ void on_param_set(const lcm_recv_buf_t *rbuf, const char * channel, const bot_pa cur_val++; } } - success = (bot_param_set_str_array(self->params, msg->entries[i].key, vals, len) == len); + success = (bot_param_set_str_array(self->params, msg->entries[i].key, (const char **)&vals, len) == len); } else { success = (bot_param_set_str(self->params, msg->entries[i].key, msg->entries[i].value) == 1); diff --git a/bot2-param/src/param_server/param_tool.c b/bot2-param/src/param_server/param_tool.c index 2e0f370..a582c22 100644 --- a/bot2-param/src/param_server/param_tool.c +++ b/bot2-param/src/param_server/param_tool.c @@ -16,7 +16,10 @@ #include "../param_client/param_internal.h" #include "../param_client/misc_utils.h" -#include +#include +#include +#include +#include int main(int argc, char ** argv) { diff --git a/bot2-param/src/param_tester/param_dump.c b/bot2-param/src/param_tester/param_dump.c index 814cb9a..e530fbe 100644 --- a/bot2-param/src/param_tester/param_dump.c +++ b/bot2-param/src/param_tester/param_dump.c @@ -2,7 +2,10 @@ #include #include -#include +#include +#include +#include +#include #include "../param_client/param_internal.h" static void _on_param_update(const lcm_recv_buf_t *rbuf, const char * channel, const bot_param_update_t * msg, diff --git a/bot2-param/src/param_tester/param_tester.c b/bot2-param/src/param_tester/param_tester.c index 2328f0a..eac09bb 100644 --- a/bot2-param/src/param_tester/param_tester.c +++ b/bot2-param/src/param_tester/param_tester.c @@ -10,7 +10,10 @@ #include #include -#include +#include +#include +#include +#include void param_update_handler(BotParam * old_param,BotParam * new_param, int64_t utime, void *user){ fprintf(stderr, "some parameters were updated %p!\n",user); diff --git a/bot2-procman/Makefile b/bot2-procman/Makefile index 2216901..c447f43 100644 --- a/bot2-procman/Makefile +++ b/bot2-procman/Makefile @@ -1,4 +1,4 @@ -# Default pod makefile distributed with pods version: 12.09.21 +# Default pod makefile distributed with pods version: 12.11.14 default_target: all diff --git a/bot2-procman/cmake/lcmtypes.cmake b/bot2-procman/cmake/lcmtypes.cmake index 72c711a..daca283 100644 --- a/bot2-procman/cmake/lcmtypes.cmake +++ b/bot2-procman/cmake/lcmtypes.cmake @@ -78,7 +78,7 @@ # # ---- # File: lcmtypes.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 cmake_minimum_required(VERSION 2.6.0) @@ -369,7 +369,7 @@ function(lcmtypes_build_java) # search for lcmtypes_*.jar files in well-known places and add them to the # classpath - foreach(pfx /usr /usr/local ${CMAKE_INSTALL_PREFIX}) + foreach(pfx ${CMAKE_INSTALL_PREFIX} /usr /usr/local) file(GLOB_RECURSE jarfiles ${pfx}/share/java/lcmtypes_*.jar) foreach(jarfile ${jarfiles}) set(java_classpath ${java_classpath}:${jarfile}) @@ -388,7 +388,7 @@ function(lcmtypes_build_java) # add a rule to build the .class files from from the .java files add_custom_command(OUTPUT ${_lcmtypes_class_files} COMMAND - ${JAVA_COMPILE} -source 6 -target 6 -cp ${java_classpath} ${_lcmtypes_java_files} + ${JAVA_COMPILE} -source 6 -cp ${java_classpath} ${_lcmtypes_java_files} DEPENDS ${_lcmtypes_java_files} VERBATIM) # add a rule to build a .jar file from the .class files diff --git a/bot2-procman/cmake/pods.cmake b/bot2-procman/cmake/pods.cmake index 7549ffd..36fa280 100644 --- a/bot2-procman/cmake/pods.cmake +++ b/bot2-procman/cmake/pods.cmake @@ -26,7 +26,7 @@ # # ---- # File: pods.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 # pods_install_headers( ... DESTINATION ) # @@ -191,14 +191,14 @@ function(pods_install_python_script script_name python_module_or_file) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n") + "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} \"$@\"\n") else() get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists? # write the bash script file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n") + "exec ${PYTHON_EXECUTABLE} -m ${py_module} \"$@\"\n") endif() # install it... install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) @@ -223,12 +223,14 @@ function(_pods_install_python_package py_src_dir py_module_name) if(EXISTS "${py_src_dir}/__init__.py") #install the single module - file(GLOB_RECURSE py_files ${py_src_dir}/*.py) - foreach(py_file ${py_files}) - file(RELATIVE_PATH __tmp_path ${py_src_dir} ${py_file}) - get_filename_component(__tmp_dir ${__tmp_path} PATH) - install(FILES ${py_file} - DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + file(GLOB_RECURSE module_files ${py_src_dir}/*) + foreach(file ${module_files}) + if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]") + file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file}) + get_filename_component(__tmp_dir ${__tmp_path} PATH) + install(FILES ${file} + DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + endif() endforeach() else() message(FATAL_ERROR "${py_src_dir} is not a python package!\n") @@ -307,22 +309,21 @@ macro(pods_use_pkg_config_packages target) string(STRIP ${_pods_pkg_ldflags} _pods_pkg_ldflags) # message("ldflags: ${_pods_pkg_ldflags}") include_directories(${_pods_pkg_include_flags}) + target_link_libraries(${target} ${_pods_pkg_ldflags}) # make the target depend on libraries that are cmake targets if (_pods_pkg_ldflags) string(REPLACE " " ";" _split_ldflags ${_pods_pkg_ldflags}) - target_link_libraries(${target} ${_split_ldflags}) - foreach(__ldflag ${_split_ldflags}) string(REGEX REPLACE "^-l" "" __depend_target_name ${__ldflag}) - if(TARGET ${__depend_target_name}) - #message("---- ${target} depends on ${__depend_target_name}") - add_dependencies(${target} ${__depend_target_name}) - endif() + if(TARGET "${__depend_target_name}") + #message("---- ${target} depends on ${libname}") + add_dependencies(${target} ${__depend_target_name}) + endif() endforeach() - unset(_split_ldflags) endif() + unset(_split_ldflags) unset(_pods_pkg_include_flags) unset(_pods_pkg_ldflags) endmacro() diff --git a/bot2-procman/python/src/bot_procman/command2_t.py b/bot2-procman/python/src/bot_procman/command2_t.py deleted file mode 100644 index de00303..0000000 --- a/bot2-procman/python/src/bot_procman/command2_t.py +++ /dev/null @@ -1,98 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -class command2_t(object): - __slots__ = ["exec_str", "command_name", "group", "auto_respawn", "stop_signal", "stop_time_allowed", "num_options", "option_names", "option_values"] - - def __init__(self): - self.exec_str = "" - self.command_name = "" - self.group = "" - self.auto_respawn = False - self.stop_signal = 0 - self.stop_time_allowed = 0.0 - self.num_options = 0 - self.option_names = [] - self.option_values = [] - - def encode(self): - buf = StringIO.StringIO() - buf.write(command2_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - __exec_str_encoded = self.exec_str.encode('utf-8') - buf.write(struct.pack('>I', len(__exec_str_encoded)+1)) - buf.write(__exec_str_encoded) - buf.write("\0") - __command_name_encoded = self.command_name.encode('utf-8') - buf.write(struct.pack('>I', len(__command_name_encoded)+1)) - buf.write(__command_name_encoded) - buf.write("\0") - __group_encoded = self.group.encode('utf-8') - buf.write(struct.pack('>I', len(__group_encoded)+1)) - buf.write(__group_encoded) - buf.write("\0") - buf.write(struct.pack(">bbfi", self.auto_respawn, self.stop_signal, self.stop_time_allowed, self.num_options)) - for i0 in range(self.num_options): - __option_names_encoded = self.option_names[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__option_names_encoded)+1)) - buf.write(__option_names_encoded) - buf.write("\0") - for i0 in range(self.num_options): - __option_values_encoded = self.option_values[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__option_values_encoded)+1)) - buf.write(__option_values_encoded) - buf.write("\0") - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != command2_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return command2_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = command2_t() - __exec_str_len = struct.unpack('>I', buf.read(4))[0] - self.exec_str = buf.read(__exec_str_len)[:-1].decode('utf-8', 'replace') - __command_name_len = struct.unpack('>I', buf.read(4))[0] - self.command_name = buf.read(__command_name_len)[:-1].decode('utf-8', 'replace') - __group_len = struct.unpack('>I', buf.read(4))[0] - self.group = buf.read(__group_len)[:-1].decode('utf-8', 'replace') - self.auto_respawn, self.stop_signal, self.stop_time_allowed, self.num_options = struct.unpack(">bbfi", buf.read(10)) - self.option_names = [] - for i0 in range(self.num_options): - __option_names_len = struct.unpack('>I', buf.read(4))[0] - self.option_names.append(buf.read(__option_names_len)[:-1].decode('utf-8', 'replace')) - self.option_values = [] - for i0 in range(self.num_options): - __option_values_len = struct.unpack('>I', buf.read(4))[0] - self.option_values.append(buf.read(__option_values_len)[:-1].decode('utf-8', 'replace')) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if command2_t in parents: return 0 - tmphash = (0xfc82ea7fd014c086) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if command2_t._packed_fingerprint is None: - command2_t._packed_fingerprint = struct.pack(">Q", command2_t._get_hash_recursive([])) - return command2_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/deputy_cmd2_t.py b/bot2-procman/python/src/bot_procman/deputy_cmd2_t.py deleted file mode 100644 index 1b42321..0000000 --- a/bot2-procman/python/src/bot_procman/deputy_cmd2_t.py +++ /dev/null @@ -1,67 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -import command2_t - -class deputy_cmd2_t(object): - __slots__ = ["cmd", "pid", "actual_runid", "exit_code", "cpu_usage", "mem_vsize_bytes", "mem_rss_bytes", "sheriff_id"] - - def __init__(self): - self.cmd = None - self.pid = 0 - self.actual_runid = 0 - self.exit_code = 0 - self.cpu_usage = 0.0 - self.mem_vsize_bytes = 0 - self.mem_rss_bytes = 0 - self.sheriff_id = 0 - - def encode(self): - buf = StringIO.StringIO() - buf.write(deputy_cmd2_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - assert self.cmd._get_packed_fingerprint() == command2_t.command2_t._get_packed_fingerprint() - self.cmd._encode_one(buf) - buf.write(struct.pack(">iiifqqi", self.pid, self.actual_runid, self.exit_code, self.cpu_usage, self.mem_vsize_bytes, self.mem_rss_bytes, self.sheriff_id)) - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != deputy_cmd2_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return deputy_cmd2_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = deputy_cmd2_t() - self.cmd = command2_t.command2_t._decode_one(buf) - self.pid, self.actual_runid, self.exit_code, self.cpu_usage, self.mem_vsize_bytes, self.mem_rss_bytes, self.sheriff_id = struct.unpack(">iiifqqi", buf.read(36)) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if deputy_cmd2_t in parents: return 0 - newparents = parents + [deputy_cmd2_t] - tmphash = (0xe86006ec5c7fbaa+ command2_t.command2_t._get_hash_recursive(newparents)) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if deputy_cmd2_t._packed_fingerprint is None: - deputy_cmd2_t._packed_fingerprint = struct.pack(">Q", deputy_cmd2_t._get_hash_recursive([])) - return deputy_cmd2_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/deputy_cmd_t.py b/bot2-procman/python/src/bot_procman/deputy_cmd_t.py deleted file mode 100644 index ea17219..0000000 --- a/bot2-procman/python/src/bot_procman/deputy_cmd_t.py +++ /dev/null @@ -1,82 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -class deputy_cmd_t(object): - __slots__ = ["name", "nickname", "group", "pid", "actual_runid", "exit_code", "cpu_usage", "mem_vsize_bytes", "mem_rss_bytes", "sheriff_id", "auto_respawn"] - - def __init__(self): - self.name = "" - self.nickname = "" - self.group = "" - self.pid = 0 - self.actual_runid = 0 - self.exit_code = 0 - self.cpu_usage = 0.0 - self.mem_vsize_bytes = 0 - self.mem_rss_bytes = 0 - self.sheriff_id = 0 - self.auto_respawn = False - - def encode(self): - buf = StringIO.StringIO() - buf.write(deputy_cmd_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - __name_encoded = self.name.encode('utf-8') - buf.write(struct.pack('>I', len(__name_encoded)+1)) - buf.write(__name_encoded) - buf.write("\0") - __nickname_encoded = self.nickname.encode('utf-8') - buf.write(struct.pack('>I', len(__nickname_encoded)+1)) - buf.write(__nickname_encoded) - buf.write("\0") - __group_encoded = self.group.encode('utf-8') - buf.write(struct.pack('>I', len(__group_encoded)+1)) - buf.write(__group_encoded) - buf.write("\0") - buf.write(struct.pack(">iiifqqib", self.pid, self.actual_runid, self.exit_code, self.cpu_usage, self.mem_vsize_bytes, self.mem_rss_bytes, self.sheriff_id, self.auto_respawn)) - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != deputy_cmd_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return deputy_cmd_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = deputy_cmd_t() - __name_len = struct.unpack('>I', buf.read(4))[0] - self.name = buf.read(__name_len)[:-1].decode('utf-8', 'replace') - __nickname_len = struct.unpack('>I', buf.read(4))[0] - self.nickname = buf.read(__nickname_len)[:-1].decode('utf-8', 'replace') - __group_len = struct.unpack('>I', buf.read(4))[0] - self.group = buf.read(__group_len)[:-1].decode('utf-8', 'replace') - self.pid, self.actual_runid, self.exit_code, self.cpu_usage, self.mem_vsize_bytes, self.mem_rss_bytes, self.sheriff_id, self.auto_respawn = struct.unpack(">iiifqqib", buf.read(37)) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if deputy_cmd_t in parents: return 0 - tmphash = (0xed5fbe5982ac8353) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if deputy_cmd_t._packed_fingerprint is None: - deputy_cmd_t._packed_fingerprint = struct.pack(">Q", deputy_cmd_t._get_hash_recursive([])) - return deputy_cmd_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/discovery_t.py b/bot2-procman/python/src/bot_procman/discovery_t.py deleted file mode 100644 index 4aacf56..0000000 --- a/bot2-procman/python/src/bot_procman/discovery_t.py +++ /dev/null @@ -1,64 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -class discovery_t(object): - __slots__ = ["utime", "host", "nonce"] - - def __init__(self): - self.utime = 0 - self.host = "" - self.nonce = 0 - - def encode(self): - buf = StringIO.StringIO() - buf.write(discovery_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - buf.write(struct.pack(">q", self.utime)) - __host_encoded = self.host.encode('utf-8') - buf.write(struct.pack('>I', len(__host_encoded)+1)) - buf.write(__host_encoded) - buf.write("\0") - buf.write(struct.pack(">q", self.nonce)) - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != discovery_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return discovery_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = discovery_t() - self.utime = struct.unpack(">q", buf.read(8))[0] - __host_len = struct.unpack('>I', buf.read(4))[0] - self.host = buf.read(__host_len)[:-1].decode('utf-8', 'replace') - self.nonce = struct.unpack(">q", buf.read(8))[0] - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if discovery_t in parents: return 0 - tmphash = (0x888b70fffb199d38) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if discovery_t._packed_fingerprint is None: - discovery_t._packed_fingerprint = struct.pack(">Q", discovery_t._get_hash_recursive([])) - return discovery_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/info2_t.py b/bot2-procman/python/src/bot_procman/info2_t.py deleted file mode 100644 index f94f519..0000000 --- a/bot2-procman/python/src/bot_procman/info2_t.py +++ /dev/null @@ -1,102 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -import deputy_cmd2_t - -class info2_t(object): - __slots__ = ["utime", "host", "cpu_load", "phys_mem_total_bytes", "phys_mem_free_bytes", "swap_total_bytes", "swap_free_bytes", "ncmds", "cmds", "num_options", "option_names", "option_values"] - - def __init__(self): - self.utime = 0 - self.host = "" - self.cpu_load = 0.0 - self.phys_mem_total_bytes = 0 - self.phys_mem_free_bytes = 0 - self.swap_total_bytes = 0 - self.swap_free_bytes = 0 - self.ncmds = 0 - self.cmds = [] - self.num_options = 0 - self.option_names = [] - self.option_values = [] - - def encode(self): - buf = StringIO.StringIO() - buf.write(info2_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - buf.write(struct.pack(">q", self.utime)) - __host_encoded = self.host.encode('utf-8') - buf.write(struct.pack('>I', len(__host_encoded)+1)) - buf.write(__host_encoded) - buf.write("\0") - buf.write(struct.pack(">fqqqqi", self.cpu_load, self.phys_mem_total_bytes, self.phys_mem_free_bytes, self.swap_total_bytes, self.swap_free_bytes, self.ncmds)) - for i0 in range(self.ncmds): - assert self.cmds[i0]._get_packed_fingerprint() == deputy_cmd2_t.deputy_cmd2_t._get_packed_fingerprint() - self.cmds[i0]._encode_one(buf) - buf.write(struct.pack(">i", self.num_options)) - for i0 in range(self.num_options): - __option_names_encoded = self.option_names[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__option_names_encoded)+1)) - buf.write(__option_names_encoded) - buf.write("\0") - for i0 in range(self.num_options): - __option_values_encoded = self.option_values[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__option_values_encoded)+1)) - buf.write(__option_values_encoded) - buf.write("\0") - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != info2_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return info2_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = info2_t() - self.utime = struct.unpack(">q", buf.read(8))[0] - __host_len = struct.unpack('>I', buf.read(4))[0] - self.host = buf.read(__host_len)[:-1].decode('utf-8', 'replace') - self.cpu_load, self.phys_mem_total_bytes, self.phys_mem_free_bytes, self.swap_total_bytes, self.swap_free_bytes, self.ncmds = struct.unpack(">fqqqqi", buf.read(40)) - self.cmds = [] - for i0 in range(self.ncmds): - self.cmds.append(deputy_cmd2_t.deputy_cmd2_t._decode_one(buf)) - self.num_options = struct.unpack(">i", buf.read(4))[0] - self.option_names = [] - for i0 in range(self.num_options): - __option_names_len = struct.unpack('>I', buf.read(4))[0] - self.option_names.append(buf.read(__option_names_len)[:-1].decode('utf-8', 'replace')) - self.option_values = [] - for i0 in range(self.num_options): - __option_values_len = struct.unpack('>I', buf.read(4))[0] - self.option_values.append(buf.read(__option_values_len)[:-1].decode('utf-8', 'replace')) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if info2_t in parents: return 0 - newparents = parents + [info2_t] - tmphash = (0x594fec8cdb8bc81c+ deputy_cmd2_t.deputy_cmd2_t._get_hash_recursive(newparents)) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if info2_t._packed_fingerprint is None: - info2_t._packed_fingerprint = struct.pack(">Q", info2_t._get_hash_recursive([])) - return info2_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/info_t.py b/bot2-procman/python/src/bot_procman/info_t.py deleted file mode 100644 index 821d08f..0000000 --- a/bot2-procman/python/src/bot_procman/info_t.py +++ /dev/null @@ -1,79 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -import deputy_cmd_t - -class info_t(object): - __slots__ = ["utime", "host", "cpu_load", "phys_mem_total_bytes", "phys_mem_free_bytes", "swap_total_bytes", "swap_free_bytes", "ncmds", "cmds"] - - def __init__(self): - self.utime = 0 - self.host = "" - self.cpu_load = 0.0 - self.phys_mem_total_bytes = 0 - self.phys_mem_free_bytes = 0 - self.swap_total_bytes = 0 - self.swap_free_bytes = 0 - self.ncmds = 0 - self.cmds = [] - - def encode(self): - buf = StringIO.StringIO() - buf.write(info_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - buf.write(struct.pack(">q", self.utime)) - __host_encoded = self.host.encode('utf-8') - buf.write(struct.pack('>I', len(__host_encoded)+1)) - buf.write(__host_encoded) - buf.write("\0") - buf.write(struct.pack(">fqqqqi", self.cpu_load, self.phys_mem_total_bytes, self.phys_mem_free_bytes, self.swap_total_bytes, self.swap_free_bytes, self.ncmds)) - for i0 in range(self.ncmds): - assert self.cmds[i0]._get_packed_fingerprint() == deputy_cmd_t.deputy_cmd_t._get_packed_fingerprint() - self.cmds[i0]._encode_one(buf) - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != info_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return info_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = info_t() - self.utime = struct.unpack(">q", buf.read(8))[0] - __host_len = struct.unpack('>I', buf.read(4))[0] - self.host = buf.read(__host_len)[:-1].decode('utf-8', 'replace') - self.cpu_load, self.phys_mem_total_bytes, self.phys_mem_free_bytes, self.swap_total_bytes, self.swap_free_bytes, self.ncmds = struct.unpack(">fqqqqi", buf.read(40)) - self.cmds = [] - for i0 in range(self.ncmds): - self.cmds.append(deputy_cmd_t.deputy_cmd_t._decode_one(buf)) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if info_t in parents: return 0 - newparents = parents + [info_t] - tmphash = (0x925c28f65a35e1d7+ deputy_cmd_t.deputy_cmd_t._get_hash_recursive(newparents)) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if info_t._packed_fingerprint is None: - info_t._packed_fingerprint = struct.pack(">Q", info_t._get_hash_recursive([])) - return info_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/orders2_t.py b/bot2-procman/python/src/bot_procman/orders2_t.py deleted file mode 100644 index f5b755d..0000000 --- a/bot2-procman/python/src/bot_procman/orders2_t.py +++ /dev/null @@ -1,104 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -import sheriff_cmd2_t - -class orders2_t(object): - __slots__ = ["utime", "host", "sheriff_name", "ncmds", "cmds", "num_options", "option_names", "option_values"] - - def __init__(self): - self.utime = 0 - self.host = "" - self.sheriff_name = "" - self.ncmds = 0 - self.cmds = [] - self.num_options = 0 - self.option_names = [] - self.option_values = [] - - def encode(self): - buf = StringIO.StringIO() - buf.write(orders2_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - buf.write(struct.pack(">q", self.utime)) - __host_encoded = self.host.encode('utf-8') - buf.write(struct.pack('>I', len(__host_encoded)+1)) - buf.write(__host_encoded) - buf.write("\0") - __sheriff_name_encoded = self.sheriff_name.encode('utf-8') - buf.write(struct.pack('>I', len(__sheriff_name_encoded)+1)) - buf.write(__sheriff_name_encoded) - buf.write("\0") - buf.write(struct.pack(">i", self.ncmds)) - for i0 in range(self.ncmds): - assert self.cmds[i0]._get_packed_fingerprint() == sheriff_cmd2_t.sheriff_cmd2_t._get_packed_fingerprint() - self.cmds[i0]._encode_one(buf) - buf.write(struct.pack(">i", self.num_options)) - for i0 in range(self.num_options): - __option_names_encoded = self.option_names[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__option_names_encoded)+1)) - buf.write(__option_names_encoded) - buf.write("\0") - for i0 in range(self.num_options): - __option_values_encoded = self.option_values[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__option_values_encoded)+1)) - buf.write(__option_values_encoded) - buf.write("\0") - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != orders2_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return orders2_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = orders2_t() - self.utime = struct.unpack(">q", buf.read(8))[0] - __host_len = struct.unpack('>I', buf.read(4))[0] - self.host = buf.read(__host_len)[:-1].decode('utf-8', 'replace') - __sheriff_name_len = struct.unpack('>I', buf.read(4))[0] - self.sheriff_name = buf.read(__sheriff_name_len)[:-1].decode('utf-8', 'replace') - self.ncmds = struct.unpack(">i", buf.read(4))[0] - self.cmds = [] - for i0 in range(self.ncmds): - self.cmds.append(sheriff_cmd2_t.sheriff_cmd2_t._decode_one(buf)) - self.num_options = struct.unpack(">i", buf.read(4))[0] - self.option_names = [] - for i0 in range(self.num_options): - __option_names_len = struct.unpack('>I', buf.read(4))[0] - self.option_names.append(buf.read(__option_names_len)[:-1].decode('utf-8', 'replace')) - self.option_values = [] - for i0 in range(self.num_options): - __option_values_len = struct.unpack('>I', buf.read(4))[0] - self.option_values.append(buf.read(__option_values_len)[:-1].decode('utf-8', 'replace')) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if orders2_t in parents: return 0 - newparents = parents + [orders2_t] - tmphash = (0x76e9952102b8c9f4+ sheriff_cmd2_t.sheriff_cmd2_t._get_hash_recursive(newparents)) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if orders2_t._packed_fingerprint is None: - orders2_t._packed_fingerprint = struct.pack(">Q", orders2_t._get_hash_recursive([])) - return orders2_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/orders_t.py b/bot2-procman/python/src/bot_procman/orders_t.py deleted file mode 100644 index 4661beb..0000000 --- a/bot2-procman/python/src/bot_procman/orders_t.py +++ /dev/null @@ -1,104 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -import sheriff_cmd_t - -class orders_t(object): - __slots__ = ["utime", "host", "sheriff_name", "ncmds", "cmds", "nvars", "varnames", "varvals"] - - def __init__(self): - self.utime = 0 - self.host = "" - self.sheriff_name = "" - self.ncmds = 0 - self.cmds = [] - self.nvars = 0 - self.varnames = [] - self.varvals = [] - - def encode(self): - buf = StringIO.StringIO() - buf.write(orders_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - buf.write(struct.pack(">q", self.utime)) - __host_encoded = self.host.encode('utf-8') - buf.write(struct.pack('>I', len(__host_encoded)+1)) - buf.write(__host_encoded) - buf.write("\0") - __sheriff_name_encoded = self.sheriff_name.encode('utf-8') - buf.write(struct.pack('>I', len(__sheriff_name_encoded)+1)) - buf.write(__sheriff_name_encoded) - buf.write("\0") - buf.write(struct.pack(">i", self.ncmds)) - for i0 in range(self.ncmds): - assert self.cmds[i0]._get_packed_fingerprint() == sheriff_cmd_t.sheriff_cmd_t._get_packed_fingerprint() - self.cmds[i0]._encode_one(buf) - buf.write(struct.pack(">i", self.nvars)) - for i0 in range(self.nvars): - __varnames_encoded = self.varnames[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__varnames_encoded)+1)) - buf.write(__varnames_encoded) - buf.write("\0") - for i0 in range(self.nvars): - __varvals_encoded = self.varvals[i0].encode('utf-8') - buf.write(struct.pack('>I', len(__varvals_encoded)+1)) - buf.write(__varvals_encoded) - buf.write("\0") - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != orders_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return orders_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = orders_t() - self.utime = struct.unpack(">q", buf.read(8))[0] - __host_len = struct.unpack('>I', buf.read(4))[0] - self.host = buf.read(__host_len)[:-1].decode('utf-8', 'replace') - __sheriff_name_len = struct.unpack('>I', buf.read(4))[0] - self.sheriff_name = buf.read(__sheriff_name_len)[:-1].decode('utf-8', 'replace') - self.ncmds = struct.unpack(">i", buf.read(4))[0] - self.cmds = [] - for i0 in range(self.ncmds): - self.cmds.append(sheriff_cmd_t.sheriff_cmd_t._decode_one(buf)) - self.nvars = struct.unpack(">i", buf.read(4))[0] - self.varnames = [] - for i0 in range(self.nvars): - __varnames_len = struct.unpack('>I', buf.read(4))[0] - self.varnames.append(buf.read(__varnames_len)[:-1].decode('utf-8', 'replace')) - self.varvals = [] - for i0 in range(self.nvars): - __varvals_len = struct.unpack('>I', buf.read(4))[0] - self.varvals.append(buf.read(__varvals_len)[:-1].decode('utf-8', 'replace')) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if orders_t in parents: return 0 - newparents = parents + [orders_t] - tmphash = (0x88ae05f979d423b1+ sheriff_cmd_t.sheriff_cmd_t._get_hash_recursive(newparents)) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if orders_t._packed_fingerprint is None: - orders_t._packed_fingerprint = struct.pack(">Q", orders_t._get_hash_recursive([])) - return orders_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/printf_t.py b/bot2-procman/python/src/bot_procman/printf_t.py deleted file mode 100644 index 1ca098a..0000000 --- a/bot2-procman/python/src/bot_procman/printf_t.py +++ /dev/null @@ -1,71 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -class printf_t(object): - __slots__ = ["utime", "deputy_name", "sheriff_id", "text"] - - def __init__(self): - self.utime = 0 - self.deputy_name = "" - self.sheriff_id = 0 - self.text = "" - - def encode(self): - buf = StringIO.StringIO() - buf.write(printf_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - buf.write(struct.pack(">q", self.utime)) - __deputy_name_encoded = self.deputy_name.encode('utf-8') - buf.write(struct.pack('>I', len(__deputy_name_encoded)+1)) - buf.write(__deputy_name_encoded) - buf.write("\0") - buf.write(struct.pack(">i", self.sheriff_id)) - __text_encoded = self.text.encode('utf-8') - buf.write(struct.pack('>I', len(__text_encoded)+1)) - buf.write(__text_encoded) - buf.write("\0") - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != printf_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return printf_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = printf_t() - self.utime = struct.unpack(">q", buf.read(8))[0] - __deputy_name_len = struct.unpack('>I', buf.read(4))[0] - self.deputy_name = buf.read(__deputy_name_len)[:-1].decode('utf-8', 'replace') - self.sheriff_id = struct.unpack(">i", buf.read(4))[0] - __text_len = struct.unpack('>I', buf.read(4))[0] - self.text = buf.read(__text_len)[:-1].decode('utf-8', 'replace') - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if printf_t in parents: return 0 - tmphash = (0x855d6226c71d3dd6) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if printf_t._packed_fingerprint is None: - printf_t._packed_fingerprint = struct.pack(">Q", printf_t._get_hash_recursive([])) - return printf_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/sheriff_cmd2_t.py b/bot2-procman/python/src/bot_procman/sheriff_cmd2_t.py deleted file mode 100644 index 80bca86..0000000 --- a/bot2-procman/python/src/bot_procman/sheriff_cmd2_t.py +++ /dev/null @@ -1,63 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -import command2_t - -class sheriff_cmd2_t(object): - __slots__ = ["cmd", "desired_runid", "force_quit", "sheriff_id"] - - def __init__(self): - self.cmd = None - self.desired_runid = 0 - self.force_quit = 0 - self.sheriff_id = 0 - - def encode(self): - buf = StringIO.StringIO() - buf.write(sheriff_cmd2_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - assert self.cmd._get_packed_fingerprint() == command2_t.command2_t._get_packed_fingerprint() - self.cmd._encode_one(buf) - buf.write(struct.pack(">ibi", self.desired_runid, self.force_quit, self.sheriff_id)) - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != sheriff_cmd2_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return sheriff_cmd2_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = sheriff_cmd2_t() - self.cmd = command2_t.command2_t._decode_one(buf) - self.desired_runid, self.force_quit, self.sheriff_id = struct.unpack(">ibi", buf.read(9)) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if sheriff_cmd2_t in parents: return 0 - newparents = parents + [sheriff_cmd2_t] - tmphash = (0xc749fe5a5de67849+ command2_t.command2_t._get_hash_recursive(newparents)) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if sheriff_cmd2_t._packed_fingerprint is None: - sheriff_cmd2_t._packed_fingerprint = struct.pack(">Q", sheriff_cmd2_t._get_hash_recursive([])) - return sheriff_cmd2_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/python/src/bot_procman/sheriff_cmd_t.py b/bot2-procman/python/src/bot_procman/sheriff_cmd_t.py deleted file mode 100644 index 88d21e9..0000000 --- a/bot2-procman/python/src/bot_procman/sheriff_cmd_t.py +++ /dev/null @@ -1,78 +0,0 @@ -"""LCM type definitions -This file automatically generated by lcm. -DO NOT MODIFY BY HAND!!!! -""" - -import cStringIO as StringIO -import struct - -class sheriff_cmd_t(object): - __slots__ = ["name", "nickname", "group", "desired_runid", "force_quit", "sheriff_id", "auto_respawn"] - - def __init__(self): - self.name = "" - self.nickname = "" - self.group = "" - self.desired_runid = 0 - self.force_quit = 0 - self.sheriff_id = 0 - self.auto_respawn = False - - def encode(self): - buf = StringIO.StringIO() - buf.write(sheriff_cmd_t._get_packed_fingerprint()) - self._encode_one(buf) - return buf.getvalue() - - def _encode_one(self, buf): - __name_encoded = self.name.encode('utf-8') - buf.write(struct.pack('>I', len(__name_encoded)+1)) - buf.write(__name_encoded) - buf.write("\0") - __nickname_encoded = self.nickname.encode('utf-8') - buf.write(struct.pack('>I', len(__nickname_encoded)+1)) - buf.write(__nickname_encoded) - buf.write("\0") - __group_encoded = self.group.encode('utf-8') - buf.write(struct.pack('>I', len(__group_encoded)+1)) - buf.write(__group_encoded) - buf.write("\0") - buf.write(struct.pack(">ibib", self.desired_runid, self.force_quit, self.sheriff_id, self.auto_respawn)) - - def decode(data): - if hasattr(data, 'read'): - buf = data - else: - buf = StringIO.StringIO(data) - if buf.read(8) != sheriff_cmd_t._get_packed_fingerprint(): - raise ValueError("Decode error") - return sheriff_cmd_t._decode_one(buf) - decode = staticmethod(decode) - - def _decode_one(buf): - self = sheriff_cmd_t() - __name_len = struct.unpack('>I', buf.read(4))[0] - self.name = buf.read(__name_len)[:-1].decode('utf-8', 'replace') - __nickname_len = struct.unpack('>I', buf.read(4))[0] - self.nickname = buf.read(__nickname_len)[:-1].decode('utf-8', 'replace') - __group_len = struct.unpack('>I', buf.read(4))[0] - self.group = buf.read(__group_len)[:-1].decode('utf-8', 'replace') - self.desired_runid, self.force_quit, self.sheriff_id, self.auto_respawn = struct.unpack(">ibib", buf.read(10)) - return self - _decode_one = staticmethod(_decode_one) - - _hash = None - def _get_hash_recursive(parents): - if sheriff_cmd_t in parents: return 0 - tmphash = (0x3fbd1729a0aee378) & 0xffffffffffffffff - tmphash = (((tmphash<<1)&0xffffffffffffffff) + (tmphash>>63)) & 0xffffffffffffffff - return tmphash - _get_hash_recursive = staticmethod(_get_hash_recursive) - _packed_fingerprint = None - - def _get_packed_fingerprint(): - if sheriff_cmd_t._packed_fingerprint is None: - sheriff_cmd_t._packed_fingerprint = struct.pack(">Q", sheriff_cmd_t._get_hash_recursive([])) - return sheriff_cmd_t._packed_fingerprint - _get_packed_fingerprint = staticmethod(_get_packed_fingerprint) - diff --git a/bot2-procman/src/deputy/CMakeLists.txt b/bot2-procman/src/deputy/CMakeLists.txt index 73a8665..12e9612 100644 --- a/bot2-procman/src/deputy/CMakeLists.txt +++ b/bot2-procman/src/deputy/CMakeLists.txt @@ -2,6 +2,7 @@ add_definitions(-std=gnu99) add_executable(bot-procman-deputy lcm_util.c + timestamp.c procinfo.c procman.c procman_deputy.c diff --git a/bot2-procman/src/deputy/lcm_util.c b/bot2-procman/src/deputy/lcm_util.c index 78cf660..eca1a0e 100644 --- a/bot2-procman/src/deputy/lcm_util.c +++ b/bot2-procman/src/deputy/lcm_util.c @@ -3,63 +3,91 @@ #include #include "lcm_util.h" +#include "timestamp.h" //#define dbg(...) fprintf (stderr, __VA_ARGS__) #define dbg(...) -static int -lcm_message_ready (GIOChannel *source, GIOCondition cond, lcm_t *lcm) -{ - lcm_handle (lcm); - return TRUE; -} - typedef struct { GIOChannel *ioc; guint sid; lcm_t *lcm; + gboolean quit_on_lcm_fail; + GMainLoop * mainloop; } glib_attached_lcm_t; +static int +lcm_message_ready (GIOChannel *source, GIOCondition cond, void *user_data) +{ + glib_attached_lcm_t *galcm = (glib_attached_lcm_t*) user_data; + if (0 != lcm_handle (galcm->lcm) && galcm->quit_on_lcm_fail) { + if(galcm->mainloop) { + g_main_loop_quit(galcm->mainloop); + return FALSE; + } + } + return TRUE; +} + static GHashTable *lcm_glib_sources = NULL; +static GMutex lcm_glib_sources_mutex; +static lcm_t *global_lcm = NULL; + +int +bot_glib_mainloop_attach_lcm (lcm_t *lcm) +{ + return bot_glib_mainloop_attach_lcm_full(NULL, lcm, FALSE); +} int -lcmu_glib_mainloop_attach_lcm (lcm_t *lcm) +bot_glib_mainloop_attach_lcm_full (GMainLoop * mainloop, lcm_t *lcm, + gboolean quit_on_lcm_fail) { + g_mutex_lock (&lcm_glib_sources_mutex); + if (!lcm_glib_sources) { lcm_glib_sources = g_hash_table_new (g_direct_hash, g_direct_equal); } if (g_hash_table_lookup (lcm_glib_sources, lcm)) { dbg ("lcm %p already attached to mainloop\n", lcm); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } - glib_attached_lcm_t *galcm = + glib_attached_lcm_t *galcm = (glib_attached_lcm_t*) calloc (1, sizeof (glib_attached_lcm_t)); - galcm->ioc = g_io_channel_unix_new (lcm_get_fileno (lcm)); - galcm->sid = g_io_add_watch (galcm->ioc, G_IO_IN, (GIOFunc) lcm_message_ready, - lcm); galcm->lcm = lcm; + galcm->quit_on_lcm_fail = quit_on_lcm_fail; + galcm->mainloop = mainloop; + galcm->ioc = g_io_channel_unix_new (lcm_get_fileno (lcm)); + galcm->sid = g_io_add_watch (galcm->ioc, G_IO_IN, + (GIOFunc) lcm_message_ready, galcm); dbg ("inserted lcm %p into glib mainloop\n", lcm); g_hash_table_insert (lcm_glib_sources, lcm, galcm); + + g_mutex_unlock (&lcm_glib_sources_mutex); return 0; } int -lcmu_glib_mainloop_detach_lcm (lcm_t *lcm) +bot_glib_mainloop_detach_lcm (lcm_t *lcm) { + g_mutex_lock (&lcm_glib_sources_mutex); if (!lcm_glib_sources) { dbg ("no lcm glib sources\n"); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } - glib_attached_lcm_t *galcm = + glib_attached_lcm_t *galcm = (glib_attached_lcm_t*) g_hash_table_lookup (lcm_glib_sources, lcm); if (!galcm) { dbg ("couldn't find matching galcm\n"); + g_mutex_unlock (&lcm_glib_sources_mutex); return -1; } @@ -74,5 +102,40 @@ lcmu_glib_mainloop_detach_lcm (lcm_t *lcm) g_hash_table_destroy (lcm_glib_sources); lcm_glib_sources = NULL; } + + g_mutex_unlock (&lcm_glib_sources_mutex); return 0; } + +lcm_t * +bot_lcm_get_global(const char *provider) +{ + g_mutex_lock (&lcm_glib_sources_mutex); + if(!global_lcm) + global_lcm = lcm_create(provider); + g_mutex_unlock (&lcm_glib_sources_mutex); + return global_lcm; +} + + +void bot_lcm_handle_or_timeout(lcm_t * lcm, int64_t timeout) +{ + int lcm_fileno = lcm_get_fileno(lcm); + + fd_set rfds; + int retval; + FD_ZERO(&rfds); + FD_SET(lcm_fileno, &rfds); + struct timeval tv; + bot_timestamp_to_timeval(timeout,&tv); + retval = select(lcm_fileno + 1, &rfds, NULL, NULL, &tv); + if (retval == -1) { + fprintf(stderr, "bot_lcm_handle_or_timeout: select() failed!\n"); + return; + } + if (retval) { + if (FD_ISSET(lcm_fileno, &rfds)) { + lcm_handle(lcm); + } + } +} diff --git a/bot2-procman/src/deputy/lcm_util.h b/bot2-procman/src/deputy/lcm_util.h index d0fa34f..0bfdcb9 100644 --- a/bot2-procman/src/deputy/lcm_util.h +++ b/bot2-procman/src/deputy/lcm_util.h @@ -1,8 +1,21 @@ -#ifndef __lc_util_h__ -#define __lc_util_h__ +#ifndef __bot_lcm_util_h__ +#define __bot_lcm_util_h__ #include +/** + * @defgroup BotCoreLcmUtil LcmUtil + * @ingroup BotCoreIO + * @brief Convenience functions for working with LCM + * @include: bot_core/bot_core.h + * + * These functions attach an #lcm_t object to a #GMainLoop so that when there is + * a new message on LCM, lcm_handle() gets called, and your message handlers + * get invoked. + * + * Linking: `pkg-config --libs bot2-core` + */ + #include #ifdef __cplusplus @@ -10,18 +23,76 @@ extern "C" { #endif /** - * lcu_mainloop_attach_lc (lc_t *lc) - * attaches/detaches LC to/from the glib mainloop - * When attached, lc_handle() is invoked "automatically" when a message is - * received over LC. + * bot_glib_mainloop_attach_lcm: + * @lcm: The LCM object to attach to the default #GMainLoop. + * + * Attaches LCM to the default #GMainLoop. When attached, lcm_handle() is + * invoked "automatically" when a message is received over LCM. + * + * Only one instance of #lcm_t can be attached per process. + * + * This is the same as calling + * bot_glib_mainloop_attach_lcm_full(%NULL, @lcm, %NULL, %NULL, %NULL). + * + * Returns: 0 on success, -1 on failure + */ +int bot_glib_mainloop_attach_lcm(lcm_t *lcm); + +/** + * bot_glib_mainloop_detach_lcm: + * @lcm: The LCM object to detach from whichever #GMainLoop it was attached + * to. + * + * Detaches the passed LCM instance from whichever #GMainLoop it was attached + * to. + * + * Returns: 0 on success, -1 on failure. + */ +int bot_glib_mainloop_detach_lcm(lcm_t *lcm); + +/** + * bot_glib_mainloop_attach_lcm_full: + * @mainloop: The mainloop to attach to or %NULL if default. + * @lcm: The #lcm_t object to attach. + * @quit_on_lcm_fail: If %TRUE, calls g_main_loop_quit() when lcm_handle() + * returns an error. + * + * Attaches the passed LCM object to the passed #GMainLoop (or the default one + * if the passed value is %NULL). + * + * Returns: 0 on success, -1 on failure. + */ +int bot_glib_mainloop_attach_lcm_full(GMainLoop * mainloop, lcm_t *lcm, + gboolean quit_on_lcm_fail); + + +/** + * bot_lcm_get_global: + * @provider: The string specifying the LCM network provider. If %NULL, the + * environment variable "LCM_DEFAULT_URL" is used if it is defined, otherwise + * the lcm_create default settings are used. + * + * The first time this function is invoked, it instantiates and returns new + * lcm_t instance via lcm_create(provider). Every subsequent call just returns + * the same lcm_t instance. * - * only one instance of lc_t can be attached per process + * This function is thread-safe, if g_thread_init() has been called. * - * returns 0 on success, -1 on failure + * Returns: pointer to lcm_t */ -int lcmu_glib_mainloop_attach_lcm (lcm_t *lcm); +lcm_t *bot_lcm_get_global(const char *provider); -int lcmu_glib_mainloop_detach_lcm (lcm_t *lcm); + +/** + * bot_lcm_handle_or_timeout: + * @lcm: The lcm_t object. + * @timeout max time to wait in microseconds + * + * Waits for up to @timeout seconds for an LCM message to arrive. + * It handles the first message if one arrives. + * + */ +void bot_lcm_handle_or_timeout(lcm_t * lcm, int64_t timeout); #ifdef __cplusplus } diff --git a/bot2-procman/src/deputy/procman_deputy.c b/bot2-procman/src/deputy/procman_deputy.c index c0467d8..814d1c0 100644 --- a/bot2-procman/src/deputy/procman_deputy.c +++ b/bot2-procman/src/deputy/procman_deputy.c @@ -1168,8 +1168,6 @@ int main (int argc, char **argv) char *hostname_override = NULL; char *lcmurl = NULL; - g_thread_init(NULL); - while ((c = getopt_long (argc, argv, optstring, long_opts, 0)) >= 0) { switch (c) { @@ -1271,7 +1269,7 @@ int main (int argc, char **argv) pmd); // setup LCM handler - lcmu_glib_mainloop_attach_lcm (pmd->lcm); + bot_glib_mainloop_attach_lcm (pmd->lcm); pmd->info_subs = bot_procman_info_t_subscribe(pmd->lcm, "PMD_INFO", @@ -1294,7 +1292,7 @@ int main (int argc, char **argv) // go! g_main_loop_run (pmd->mainloop); - lcmu_glib_mainloop_detach_lcm (pmd->lcm); + bot_glib_mainloop_detach_lcm (pmd->lcm); // cleanup signal_pipe_cleanup(); diff --git a/bot2-procman/src/deputy/timestamp.c b/bot2-procman/src/deputy/timestamp.c new file mode 100644 index 0000000..6256c63 --- /dev/null +++ b/bot2-procman/src/deputy/timestamp.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include + +#include "timestamp.h" + +int64_t bot_timestamp_now() +{ + struct timeval tv; + gettimeofday (&tv, NULL); + return (int64_t) tv.tv_sec * 1000000 + tv.tv_usec; +} + +int64_t bot_timestamp_seconds(int64_t v) +{ + return v/1000000; +} + +int64_t bot_timestamp_useconds(int64_t v) +{ + return v%1000000; +} + +void bot_timestamp_to_timeval(int64_t v, struct timeval *tv) +{ + tv->tv_sec = bot_timestamp_seconds(v); + tv->tv_usec = bot_timestamp_useconds(v); +} + +void bot_timestamp_to_timespec(int64_t v, struct timespec *ts) +{ + ts->tv_sec = bot_timestamp_seconds(v); + ts->tv_nsec = bot_timestamp_useconds(v)*1000; +} + +bot_timestamp_sync_state_t * +bot_timestamp_sync_init (double dev_ticks_per_second, int64_t dev_ticks_wraparound, + double rate) +{ + bot_timestamp_sync_state_t * s; + + s = malloc (sizeof (bot_timestamp_sync_state_t)); + if (!s) + return NULL; + memset (s, 0, sizeof (bot_timestamp_sync_state_t)); + + s->dev_ticks_per_second = dev_ticks_per_second; + s->dev_ticks_wraparound = dev_ticks_wraparound; + s->max_rate_error = rate; + s->is_valid = 0; + + return s; +} + +void +bot_timestamp_sync_free (bot_timestamp_sync_state_t * s) +{ + free (s); +} + +int64_t +bot_timestamp_sync (bot_timestamp_sync_state_t * s, int64_t dev_ticks, + int64_t host_utime) +{ + if (!s->is_valid) { + /* The first sync has no history */ + s->is_valid = 1; + + s->sync_host_time = host_utime; + s->last_dev_ticks = dev_ticks; + s->dev_ticks_since_sync = 0; + + return host_utime; + } + + // how many device ticks since the last invocation? + int64_t dticks = dev_ticks - s->last_dev_ticks; + s->last_dev_ticks = dev_ticks; + if (dticks < 0) + dticks += s->dev_ticks_wraparound; + + s->dev_ticks_since_sync += dticks; + + // overestimate device time by a factor of s->rate + double rate = 1000000.0 / s->dev_ticks_per_second * s->max_rate_error; + + // estimate of the host's time corresponding to the device's time + int64_t dev_utime = s->sync_host_time + (s->dev_ticks_since_sync * rate); + + int64_t time_err = host_utime - dev_utime; + + /* If time_err is very large, resynchronize, emitting a warning. if + * it is negative, we're just adjusting our timebase (it means + * we got a nice new low-latency measurement.) */ + if (time_err > 1000000000LL) { /* 1000 seconds */ + fprintf (stderr, "Warning: Time sync has drifted by more than 1000 seconds\n"); + s->sync_host_time = host_utime; + s->dev_ticks_since_sync = 0; + dev_utime = host_utime; + } + if (time_err < 0) { + s->sync_host_time = host_utime; + s->dev_ticks_since_sync = 0; + dev_utime = host_utime; + } + //printf ("%llu %llu %lld %lld\n", host_utime, dev_utime, time_err, dev_utime + s->time_offset); + + return dev_utime; +} diff --git a/bot2-procman/src/deputy/timestamp.h b/bot2-procman/src/deputy/timestamp.h new file mode 100644 index 0000000..862b7c7 --- /dev/null +++ b/bot2-procman/src/deputy/timestamp.h @@ -0,0 +1,83 @@ +#ifndef __bot_timestamp_h__ +#define __bot_timestamp_h__ + +#include +#include +#include + +/** + * @defgroup BotCoreTimestamp Timestamp + * @brief Retrieving the current time, synchronizing clocks + * @ingroup BotCoreTime + * @include: bot_core/bot_core.h + * + * TODO + * + * Linking: `pkg-config --libs bot2-core` + * + * @{ + */ + +typedef struct bot_timestamp_sync_state bot_timestamp_sync_state_t; + +struct bot_timestamp_sync_state { + double dev_ticks_per_second; // how fast does device clock count? (nominal) + int64_t dev_ticks_wraparound; // device clock counts modulo what? + double max_rate_error; // how fast do we need to count to ensure we're counting faster than device? + + int64_t sync_host_time; // when we last synced, what time was it for the host? + int64_t dev_ticks_since_sync; // how many device ticks have elapsed since the last sync? + + int64_t last_dev_ticks; // what device time was it when we were last called? + + uint8_t is_valid; // have we ever synced? +}; + +#ifdef __cplusplus +extern "C" { +#endif + +int64_t bot_timestamp_now(void); +int64_t bot_timestamp_seconds(int64_t v); +int64_t bot_timestamp_useconds(int64_t v); +void bot_timestamp_to_timeval(int64_t v, struct timeval *tv); +void bot_timestamp_to_timespec(int64_t v, struct timespec *ts); + +/** Create a new time synchronizer. + @param dev_ticks_per_second The nominal rate at which the device time increments + @param dev_ticks_wraparound Assume that dev_ticks wraps around every wraparound ticks + @param rate An upper bound on the rate error + + The syncronization algorithm is described in: + @inproceedings{olson2010, + TITLE = {A Passive Solution to the Sensor Synchronization Problem}, + AUTHOR = { Edwin Olson}, + BOOKTITLE = {Proceedings of the {IEEE/RSJ} International Conference on Intelligent + Robots and Systems {(IROS)}}, + YEAR = {2010}, + MONTH = {October}, + VOLUME = {}, + NUMBER = {}, + PAGES = {}, + KEYWORDS = {sensor calibration, time synchronization}, + ISSN = { }, + } +**/ +bot_timestamp_sync_state_t * +bot_timestamp_sync_init (double dev_ticks_per_second, int64_t dev_ticks_wraparound, + double rate); +void +bot_timestamp_sync_free (bot_timestamp_sync_state_t * s); +int64_t +bot_timestamp_sync (bot_timestamp_sync_state_t * s, int64_t dev_ticks, + int64_t host_utime); + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif diff --git a/bot2-vis/Makefile b/bot2-vis/Makefile index 2216901..c447f43 100644 --- a/bot2-vis/Makefile +++ b/bot2-vis/Makefile @@ -1,4 +1,4 @@ -# Default pod makefile distributed with pods version: 12.09.21 +# Default pod makefile distributed with pods version: 12.11.14 default_target: all diff --git a/bot2-vis/cmake/pods.cmake b/bot2-vis/cmake/pods.cmake index 7549ffd..36fa280 100644 --- a/bot2-vis/cmake/pods.cmake +++ b/bot2-vis/cmake/pods.cmake @@ -26,7 +26,7 @@ # # ---- # File: pods.cmake -# Distributed with pods version: 12.09.21 +# Distributed with pods version: 12.11.14 # pods_install_headers( ... DESTINATION ) # @@ -191,14 +191,14 @@ function(pods_install_python_script script_name python_module_or_file) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n") + "exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} \"$@\"\n") else() get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists? # write the bash script file file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name} "#!/bin/sh\n" "export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n" - "exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n") + "exec ${PYTHON_EXECUTABLE} -m ${py_module} \"$@\"\n") endif() # install it... install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin) @@ -223,12 +223,14 @@ function(_pods_install_python_package py_src_dir py_module_name) if(EXISTS "${py_src_dir}/__init__.py") #install the single module - file(GLOB_RECURSE py_files ${py_src_dir}/*.py) - foreach(py_file ${py_files}) - file(RELATIVE_PATH __tmp_path ${py_src_dir} ${py_file}) - get_filename_component(__tmp_dir ${__tmp_path} PATH) - install(FILES ${py_file} - DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + file(GLOB_RECURSE module_files ${py_src_dir}/*) + foreach(file ${module_files}) + if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]") + file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file}) + get_filename_component(__tmp_dir ${__tmp_path} PATH) + install(FILES ${file} + DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}") + endif() endforeach() else() message(FATAL_ERROR "${py_src_dir} is not a python package!\n") @@ -307,22 +309,21 @@ macro(pods_use_pkg_config_packages target) string(STRIP ${_pods_pkg_ldflags} _pods_pkg_ldflags) # message("ldflags: ${_pods_pkg_ldflags}") include_directories(${_pods_pkg_include_flags}) + target_link_libraries(${target} ${_pods_pkg_ldflags}) # make the target depend on libraries that are cmake targets if (_pods_pkg_ldflags) string(REPLACE " " ";" _split_ldflags ${_pods_pkg_ldflags}) - target_link_libraries(${target} ${_split_ldflags}) - foreach(__ldflag ${_split_ldflags}) string(REGEX REPLACE "^-l" "" __depend_target_name ${__ldflag}) - if(TARGET ${__depend_target_name}) - #message("---- ${target} depends on ${__depend_target_name}") - add_dependencies(${target} ${__depend_target_name}) - endif() + if(TARGET "${__depend_target_name}") + #message("---- ${target} depends on ${libname}") + add_dependencies(${target} ${__depend_target_name}) + endif() endforeach() - unset(_split_ldflags) endif() + unset(_split_ldflags) unset(_pods_pkg_include_flags) unset(_pods_pkg_ldflags) endmacro() diff --git a/bot2-vis/src/bot_vis/param_widget.c b/bot2-vis/src/bot_vis/param_widget.c index f42b6dc..8dae1ea 100644 --- a/bot2-vis/src/bot_vis/param_widget.c +++ b/bot2-vis/src/bot_vis/param_widget.c @@ -290,7 +290,7 @@ int bot_gtk_param_widget_add_text_entry (BotGtkParamWidget *pw, switch(ui_hints) { case BOT_GTK_PARAM_WIDGET_ENTRY: w = gtk_entry_new (); - gtk_entry_set_text (GTK_SPIN_BUTTON(w), initial_value); + gtk_entry_set_text (GTK_ENTRY(GTK_SPIN_BUTTON(w)), initial_value); break; default: err("ERROR: param_widget_add_text_entry - bad ui_hints\n"); diff --git a/bot2-vis/src/bot_vis/viewer.h b/bot2-vis/src/bot_vis/viewer.h index b830735..c9de8c6 100644 --- a/bot2-vis/src/bot_vis/viewer.h +++ b/bot2-vis/src/bot_vis/viewer.h @@ -353,7 +353,7 @@ struct _BotViewer { int64_t movie_frame_last_utime; double movie_actual_fps; double movie_desired_fps; - gzFile *movie_gzf; + gzFile movie_gzf; guint render_timer_id; int is_recording; diff --git a/bot2-vis/src/rwx-viewer/main.c b/bot2-vis/src/rwx-viewer/main.c index 4fce235..39305e7 100644 --- a/bot2-vis/src/rwx-viewer/main.c +++ b/bot2-vis/src/rwx-viewer/main.c @@ -11,7 +11,6 @@ int main(int argc, char *argv[]) { gtk_init(&argc, &argv); glutInit(&argc, argv); - g_thread_init(NULL); if(argc < 2) { fprintf(stderr, "usage: %s \n", diff --git a/bot2-vis/src/wavefront-viewer/main.c b/bot2-vis/src/wavefront-viewer/main.c index 5d3d5bc..44d7ef4 100644 --- a/bot2-vis/src/wavefront-viewer/main.c +++ b/bot2-vis/src/wavefront-viewer/main.c @@ -12,7 +12,6 @@ int main(int argc, char *argv[]) { gtk_init(&argc, &argv); glutInit(&argc, argv); - g_thread_init(NULL); if(argc < 2) { fprintf(stderr, "usage: %s \n", diff --git a/catkin/bot_core/CMakeLists.txt b/catkin/bot_core/CMakeLists.txt new file mode 100644 index 0000000..4f7d962 --- /dev/null +++ b/catkin/bot_core/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_core) +find_package(catkin REQUIRED COMPONENTS +bot_core_lcmtypes +) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 glib-2.0) + +catkin_package( + INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} + LIBRARIES bot_core + CATKIN_DEPENDS bot_core_lcmtypes + DEPENDS GLIB2 + CFG_EXTRAS bot-core-includes.cmake +) + +add_definitions(-std=gnu99) + +file(GLOB c_files ../../bot2-core/src/bot_core/*.c) +file(GLOB h_files ../../bot2-core/src/bot_core/*.h) + +include_directories(../../bot2-core/src/bot_core/ ${GLIB2_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) + +add_library(bot_core SHARED ${c_files}) +target_link_libraries(bot_core ${catkin_LIBRARIES} ${GLIB2_LIBRARIES} m) +set_property(TARGET bot_core APPEND_STRING PROPERTY COMPILE_FLAGS -Wno-unused-result ) + +install(TARGETS bot_core + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) +install(FILES ${h_files} + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) diff --git a/catkin/bot_core/cmake/bot-core-includes.cmake b/catkin/bot_core/cmake/bot-core-includes.cmake new file mode 100644 index 0000000..caa26dd --- /dev/null +++ b/catkin/bot_core/cmake/bot-core-includes.cmake @@ -0,0 +1,4 @@ +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 glib-2.0) + +include_directories(${GLIB2_INCLUDE_DIRS}) diff --git a/catkin/bot_core/package.xml b/catkin/bot_core/package.xml new file mode 100644 index 0000000..06bc32e --- /dev/null +++ b/catkin/bot_core/package.xml @@ -0,0 +1,18 @@ + + + bot_core + 1.0.0 + The bot_core package + Vladimir Ivan + BSD + + catkin + bot_core_lcmtypes + libglib-dev + python-gtk2 + gtk2 + mesa-common-dev + opengl + glut + libjpeg + diff --git a/catkin/bot_frames/CMakeLists.txt b/catkin/bot_frames/CMakeLists.txt new file mode 100644 index 0000000..c180d6e --- /dev/null +++ b/catkin/bot_frames/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_frames) + +add_definitions(-std=gnu99) + +find_package(catkin REQUIRED COMPONENTS +bot_core +bot_param +bot_vis +bot_lcmgl +bot_frames_lcmtypes +) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 glib-2.0) +pkg_check_modules(OPENGL opengl) + +catkin_package( + LIBRARIES bot_frames bot-frames-renderers + CATKIN_DEPENDS bot_core bot_param bot_vis bot_lcmgl bot_frames_lcmtypes + DEPENDS GLIB2 +) + +include_directories(include ../../bot2-frames/src/ ../../bot2-frames/src/bot_frames ../../bot2-frames/src/test ../../bot2-frames/src/renderer ${GLIB2_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) + +add_library(bot-frames SHARED ../../bot2-frames/src/bot_frames.c) +target_link_libraries(bot-frames ${catkin_LIBRARIES} ${GLIB2_LIBRARIES}) +set_target_properties(bot-frames PROPERTIES SOVERSION 2) + +add_library(bot-frames-renderers SHARED ../../bot2-frames/src/renderer/coord_frames_renderer.c ../../bot2-frames/src/renderer/articulated_body_renderer.c ../../bot2-frames/src/renderer/frame_modifier_renderer.c) +target_link_libraries(bot-frames-renderers bot-frames ${catkin_LIBRARIES} ${OPENGL_LIBRARIES}) + +add_executable(test-viewer ../../bot2-frames/src/renderer/test_viewer.c) +target_link_libraries(test-viewer bot-frames-renderers ${catkin_LIBRARIES} -lglut) + +add_executable(coord-frames-test ../../bot2-frames/src/test/coord_frames_test.c) +target_link_libraries(coord-frames-test bot-frames) + +install(TARGETS bot-frames bot-frames-renderers coord-frames-test test-viewer + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) +install(FILES ../../bot2-frames/src/bot_frames/bot_frames.h ../../bot2-frames/src/bot_frames/bot_frames_renderers.h + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) +install(FILES ../../bot2-frames/src/test/test_params.cfg + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}) diff --git a/catkin/bot_frames/package.xml b/catkin/bot_frames/package.xml new file mode 100644 index 0000000..d499d8c --- /dev/null +++ b/catkin/bot_frames/package.xml @@ -0,0 +1,17 @@ + + + bot_frames + 1.0.0 + The bot_frames package + Vladimir Ivan + BSD + catkin + bot_core + bot_param + bot_vis + bot_lcmgl + bot_frames_lcmtypes + libglib-dev + opengl + glut + diff --git a/catkin/bot_frames_lcmtypes/CMakeLists.txt b/catkin/bot_frames_lcmtypes/CMakeLists.txt new file mode 100644 index 0000000..b906074 --- /dev/null +++ b/catkin/bot_frames_lcmtypes/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_frames_lcmtypes) + +find_package(catkin REQUIRED COMPONENTS +lcm_catkin +) + +catkin_package( + LIBRARIES ${PROJECT_NAME} + CATKIN_DEPENDS lcm_catkin +) + +FindLCM(../../bot2-frames/) + +AddLCM( +bot_frames_update_t +) + +GenerateLCM() diff --git a/catkin/bot_frames_lcmtypes/package.xml b/catkin/bot_frames_lcmtypes/package.xml new file mode 100644 index 0000000..fe62511 --- /dev/null +++ b/catkin/bot_frames_lcmtypes/package.xml @@ -0,0 +1,10 @@ + + + bot_frames_lcmtypes + 1.0.0 + The bot_frames_lcmtypes package + Vladimir Ivan + BSD + catkin + lcm_catkin + diff --git a/catkin/bot_lcm_utils/CMakeLists.txt b/catkin/bot_lcm_utils/CMakeLists.txt new file mode 100644 index 0000000..2584dad --- /dev/null +++ b/catkin/bot_lcm_utils/CMakeLists.txt @@ -0,0 +1,83 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_lcm_utils) + +find_package(catkin REQUIRED COMPONENTS +lcm_catkin +) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 glib-2.0) + +catkin_package( +# INCLUDE_DIRS include +# LIBRARIES bot_lcm_utils + CATKIN_DEPENDS lcm_catkin + DEPENDS GLIB2 +) + +set(src ../../bot2-lcm-utils/src) + +include_directories(${src}/who ${src}/tunnel ${GLIB2_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) + +# Log filter +add_executable(bot-lcm-logfilter ${src}/logfilter/lcm-logfilter.c) +target_link_libraries(bot-lcm-logfilter ${catkin_LIBRARIES} ${GLIB2_LIBRARIES}) + +# Log splice +add_executable(bot-lcm-logsplice ${src}/logsplice/lcm-logsplice.c) +target_link_libraries(bot-lcm-logsplice ${catkin_LIBRARIES} ${GLIB2_LIBRARIES}) + +# Who +add_executable(bot-lcm-who ${src}/who/lcm-who.c ${src}/who/signal_pipe.c) +target_link_libraries(bot-lcm-who ${catkin_LIBRARIES} ${GLIB2_LIBRARIES}) + + +set(ldpc_sources + ${src}/tunnel/ldpc/getopt.cpp + ${src}/tunnel/ldpc/ldpc_create_pchk.cpp + ${src}/tunnel/ldpc/ldpc_fec.cpp + ${src}/tunnel/ldpc/ldpc_fec_iterative_decoding.cpp + ${src}/tunnel/ldpc/ldpc_matrix_sparse.cpp + ${src}/tunnel/ldpc/ldpc_rand.cpp + ${src}/tunnel/ldpc/ldpc_scheme.cpp + ${src}/tunnel/ldpc/ldpc_wrapper.cpp + ${src}/tunnel/ldpc/tools.cpp + ) + +# Tunnel +add_executable(bot-lcm-tunnel + ${src}/tunnel/introspect.c + ${src}/tunnel/lcm_tunnel_params_t.c + ${src}/tunnel/lcm_tunnel_sub_msg_t.c + ${src}/tunnel/lcm_tunnel_udp_msg_t.c + ${src}/tunnel/lcm_tunnel_disconnect_msg_t.c + ${src}/tunnel/ssocket.c + ${src}/tunnel/lcm_tunnel.cpp + ${src}/tunnel/lcm_tunnel_server.cpp + ${src}/tunnel/signal_pipe.c + ${src}/tunnel/lcm_util.c + ${src}/tunnel/timestamp.c + ${ldpc_sources} + ) +target_link_libraries(bot-lcm-tunnel ${catkin_LIBRARIES} ${GLIB2_LIBRARIES}) + +# LDPC wrapper test +add_executable(ldpc-wrapper-test + ${src}/tunnel/ldpc/ldpc_wrapper_test.cpp + ${ldpc_sources} + ) + +set_source_files_properties(${src}/tunnel/introspect.c ${src}/tunnel/lcm_tunnel_params_t.c ${src}/tunnel/ssocket.c ${src}/tunnel/signal_pipe.c ${src}/tunnel/lcm_util.c ${src}/tunnel/timestamp.c + PROPERTIES COMPILE_FLAGS "-std=gnu99") + +# Install executables +install(TARGETS bot-lcm-logfilter bot-lcm-logsplice bot-lcm-who bot-lcm-tunnel ldpc-wrapper-test + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) +# Install bot spy +install(PROGRAMS src/bot-spy + DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) + +# Install python modules +install(DIRECTORY ../../bot2-lcm-utils/python/src/ DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}) diff --git a/catkin/bot_lcm_utils/package.xml b/catkin/bot_lcm_utils/package.xml new file mode 100644 index 0000000..068ebc1 --- /dev/null +++ b/catkin/bot_lcm_utils/package.xml @@ -0,0 +1,11 @@ + + + bot_lcm_utils + 0.0.0 + The bot_lcm_utils package + Vladimir Ivan + BSD + catkin + lcm_catkin + libglib-dev + diff --git a/catkin/bot_lcm_utils/src/bot-spy b/catkin/bot_lcm_utils/src/bot-spy new file mode 100755 index 0000000..8e6bde6 --- /dev/null +++ b/catkin/bot_lcm_utils/src/bot-spy @@ -0,0 +1,15 @@ +#!/bin/sh +CLASSPATH=`PKG_CONFIG_PATH=PKG_CONFIG_PATH:/opt/oh-distro/lib/pkgconfig pkg-config --variable=classpath lcm-java` +for d in $(echo $CMAKE_PREFIX_PATH | sed "s/:/ /g"); do + if [ -d $d/share/java ]; then + jd=$d/share/java + echo Checking $jd + for f in $jd/lcmtypes_*.jar $jd/lcmspy_plugins_*.jar; do + if [ -e $f ]; then + echo " Found $f" + CLASSPATH=$CLASSPATH:$f + fi + done + fi +done +exec java -ea -cp $CLASSPATH lcm.spy.Spy $* diff --git a/catkin/bot_lcmgl/CMakeLists.txt b/catkin/bot_lcmgl/CMakeLists.txt new file mode 100644 index 0000000..36cfaa9 --- /dev/null +++ b/catkin/bot_lcmgl/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_lcmgl) + +add_definitions(-std=gnu99) + +find_package(catkin REQUIRED bot_lcmgl_lcmtypes bot_vis) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 REQUIRED glib-2.0) +pkg_check_modules(ZLIB REQUIRED zlib) +pkg_check_modules(OPENGL REQUIRED gl) + +catkin_package( + LIBRARIES bot2-lcmgl-client bot2-lcmgl-renderer + CATKIN_DEPENDS bot_lcmgl_lcmtypes bot_vis + DEPENDS GLIB2 ZLIB OPENGL +) + +include_directories(include ../../bot2-lcmgl/src ../../bot2-lcmgl/src/bot_lcmgl_client ../../bot2-lcmgl/src/bot_lcmgl_renderer ${GLIB2_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) + +# Clinet +add_library(bot2-lcmgl-client SHARED ../../bot2-lcmgl/src/bot_lcmgl_client/lcmgl.c) +target_link_libraries(bot2-lcmgl-client ${ZLIB_LIBRARIES} ${GLIB2_LIBRARIES} ${catkin_LIBRARIES}) + +# Renderer +add_library(bot2-lcmgl-renderer SHARED ../../bot2-lcmgl/src/bot_lcmgl_render/lcmgl_bot_renderer.c ../../bot2-lcmgl/src/bot_lcmgl_render/lcmgl_decode.c) +target_link_libraries(bot2-lcmgl-renderer ${OPENGL_LIBRARIES} ${catkin_LIBRARIES}) + +# Viewer +add_executable(bot-lcmgl-viewer ../../bot2-lcmgl/src/lcmgl-viewer/main.c ../../bot2-lcmgl/src/lcmgl-viewer/udp_util.c ../../bot2-lcmgl/src/lcmgl-viewer/view_menu.c) +target_link_libraries(bot-lcmgl-viewer bot2-lcmgl-renderer -lglut) + +# Install libraries +install(TARGETS bot2-lcmgl-client bot2-lcmgl-renderer bot-lcmgl-viewer + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) +# Install client and rendered header files (into non-standard directories) +install(FILES ../../bot2-lcmgl/src/bot_lcmgl_client/lcmgl.h + DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/bot_lcmgl_client) +install(FILES ../../bot2-lcmgl/src/bot_lcmgl_render/lcmgl_decode.h ../../bot2-lcmgl/src/bot_lcmgl_render/lcmgl_bot_renderer.h + DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/bot_lcmgl_render) + +# Install python modules +install(DIRECTORY ../../bot2-lcmgl/python/src/ DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}) + diff --git a/catkin/bot_lcmgl/package.xml b/catkin/bot_lcmgl/package.xml new file mode 100644 index 0000000..c904d46 --- /dev/null +++ b/catkin/bot_lcmgl/package.xml @@ -0,0 +1,15 @@ + + + bot_lcmgl + 0.0.0 + The bot_lcmgl package + Vladimir Ivan + BSD + catkin + bot_lcmgl_lcmtypes + bot_vis + libglib-dev + zlib + opengl + glut + diff --git a/catkin/bot_lcmgl_lcmtypes/CMakeLists.txt b/catkin/bot_lcmgl_lcmtypes/CMakeLists.txt new file mode 100644 index 0000000..2a01769 --- /dev/null +++ b/catkin/bot_lcmgl_lcmtypes/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_lcmgl_lcmtypes) + +find_package(catkin REQUIRED COMPONENTS +lcm_catkin +) + +catkin_package( + LIBRARIES ${PROJECT_NAME} + CATKIN_DEPENDS lcm_catkin +) + +FindLCM(../../bot2-lcmgl/) + +AddLCM( +bot_lcmgl_data_t +) + +AddJAVA(bot2-lcmgl ../../bot2-lcmgl/java/src/bot_lcmgl/LCMGL.java) + +GenerateLCM() diff --git a/catkin/bot_lcmgl_lcmtypes/package.xml b/catkin/bot_lcmgl_lcmtypes/package.xml new file mode 100644 index 0000000..a328d9b --- /dev/null +++ b/catkin/bot_lcmgl_lcmtypes/package.xml @@ -0,0 +1,10 @@ + + + bot_lcmgl_lcmtypes + 0.0.0 + The bot_lcmgl_lcmtypes package + Vladimir Ivan + BSD + catkin + lcm_catkin + diff --git a/catkin/bot_param/CMakeLists.txt b/catkin/bot_param/CMakeLists.txt new file mode 100644 index 0000000..9943d28 --- /dev/null +++ b/catkin/bot_param/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_param) +find_package(catkin REQUIRED COMPONENTS +bot_core +bot_param_lcmtypes +) + +add_definitions(-std=gnu99) + +catkin_package( + LIBRARIES bot_param_client + CATKIN_DEPENDS bot_core bot_param_lcmtypes +) + +include_directories(include ../../bot2-param/src/param_client ${catkin_INCLUDE_DIRS}) + +# Client +file(GLOB client_c_files ../../bot2-param/src/param_client/*.c) +file(GLOB client_h_files ../../bot2-param/src/param_client/bot_param/*.h) +add_library(bot_param_client SHARED ${client_c_files}) +target_link_libraries(bot_param_client ${catkin_LIBRARIES} m) + +# Server +add_executable(bot-param-server ../../bot2-param/src/param_server/param_server.c ../../bot2-param/src/param_server/lcm_util.c) +target_link_libraries(bot-param-server bot_param_client) +add_executable(bot-param-tool ../../bot2-param/src/param_server/param_tool.c) +target_link_libraries(bot-param-tool bot_param_client) + +#Tester +add_executable(param-tester ../../bot2-param/src/param_tester/param_tester.c) +target_link_libraries(param-tester bot_param_client) +add_executable(bot-param-dump ../../bot2-param/src/param_tester/param_dump.c) +target_link_libraries(bot-param-dump bot_param_client) + +# Install library and executables +install(TARGETS bot_param_client param-tester bot-param-dump bot-param-server bot-param-tool + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) +# Install header files +install(FILES ${client_h_files} + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) diff --git a/catkin/bot_param/package.xml b/catkin/bot_param/package.xml new file mode 100644 index 0000000..df5ccca --- /dev/null +++ b/catkin/bot_param/package.xml @@ -0,0 +1,11 @@ + + + bot_param + 1.0.0 + The bot_param package + Vladimir Ivan + BSD + catkin + bot_core + bot_param_lcmtypes + diff --git a/catkin/bot_param_lcmtypes/CMakeLists.txt b/catkin/bot_param_lcmtypes/CMakeLists.txt new file mode 100644 index 0000000..7e533c7 --- /dev/null +++ b/catkin/bot_param_lcmtypes/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_param_lcmtypes) + +find_package(catkin REQUIRED COMPONENTS +lcm_catkin +) + +catkin_package( + LIBRARIES ${PROJECT_NAME} + CATKIN_DEPENDS lcm_catkin +) + +FindLCM(../../bot2-param/) + +AddLCM( +bot_param_entry_t +bot_param_request_t +bot_param_set_t +bot_param_update_t +) + +GenerateLCM() diff --git a/catkin/bot_param_lcmtypes/package.xml b/catkin/bot_param_lcmtypes/package.xml new file mode 100644 index 0000000..9369891 --- /dev/null +++ b/catkin/bot_param_lcmtypes/package.xml @@ -0,0 +1,10 @@ + + + bot_param_lcmtypes + 1.0.0 + The bot_param_lcmtypes package + Vladimir Ivan + BSD + catkin + lcm_catkin + diff --git a/catkin/bot_procman/CMakeLists.txt b/catkin/bot_procman/CMakeLists.txt new file mode 100644 index 0000000..9613034 --- /dev/null +++ b/catkin/bot_procman/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_procman) + +add_definitions(-std=gnu99) + +find_package(catkin REQUIRED COMPONENTS +bot_procman_lcmtypes +) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 REQUIRED glib-2.0) + +catkin_package( + CATKIN_DEPENDS bot_procman_lcmtypes + DEPENDS GLIB2 +) + +include_directories(include ../../bot2-procman/src ../../bot2-procman/src/deputy ${GLIB2_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) + +# Deputy +add_executable(bot-procman-deputy + ../../bot2-procman/src/deputy/lcm_util.c + ../../bot2-procman/src/deputy/timestamp.c + ../../bot2-procman/src/deputy/procinfo.c + ../../bot2-procman/src/deputy/procman.c + ../../bot2-procman/src/deputy/procman_deputy.c + ../../bot2-procman/src/deputy/signal_pipe.c) +target_link_libraries(bot-procman-deputy util ${GLIB2_LIBRARIES} ${catkin_LIBRARIES}) +# Build prefix for locating glide files +file(WRITE ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION}/bot_procman/build_prefix.py "import inspect, os\nBUILD_PREFIX=os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))), '..', '..', '..', '..'))\n") +file(WRITE ${PROJECT_BINARY_DIR}/python/build_prefix.py "BUILD_PREFIX='${CMAKE_INSTALL_PREFIX}'\n") + +# Install deputy +install(TARGETS bot-procman-deputy + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) +# Install sheriff +install(PROGRAMS ../../bot2-procman/python/scripts/bot-procman-sheriff + DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) + +# Install glade file and it's prefix path generator +install(FILES ../../bot2-procman/python/procman-sheriff.glade DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}) +install(FILES ${PROJECT_BINARY_DIR}/python/build_prefix.py DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}) + +# Install python modules +install(DIRECTORY ../../bot2-procman/python/src/ DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}) diff --git a/catkin/bot_procman/package.xml b/catkin/bot_procman/package.xml new file mode 100644 index 0000000..d7ed1c9 --- /dev/null +++ b/catkin/bot_procman/package.xml @@ -0,0 +1,11 @@ + + + bot_procman + 0.0.0 + The bot_procman package + Vladimir Ivan + BSD + catkin + bot_procman_lcmtypes + libglib-dev + diff --git a/catkin/bot_procman_lcmtypes/CMakeLists.txt b/catkin/bot_procman_lcmtypes/CMakeLists.txt new file mode 100644 index 0000000..cde3a68 --- /dev/null +++ b/catkin/bot_procman_lcmtypes/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_procman_lcmtypes) + +find_package(catkin REQUIRED COMPONENTS +lcm_catkin +) + +catkin_package( + LIBRARIES ${PROJECT_NAME} + CATKIN_DEPENDS lcm_catkin +) + +FindLCM(../../bot2-procman/) + +AddLCM( +bot_procman_command2_t +bot_procman_deputy_cmd2_t +bot_procman_deputy_cmd_t +bot_procman_discovery_t +bot_procman_info2_t +bot_procman_info_t +bot_procman_orders2_t +bot_procman_orders_t +bot_procman_printf_t +bot_procman_sheriff_cmd2_t +bot_procman_sheriff_cmd_t +) + +GenerateLCM() diff --git a/catkin/bot_procman_lcmtypes/package.xml b/catkin/bot_procman_lcmtypes/package.xml new file mode 100644 index 0000000..dfce528 --- /dev/null +++ b/catkin/bot_procman_lcmtypes/package.xml @@ -0,0 +1,10 @@ + + + bot_procman_lcmtypes + 0.0.0 + The bot_procman_lcmtypes package + Vladimir Ivan + BSD + catkin + lcm_catkin + diff --git a/catkin/bot_vis/CMakeLists.txt b/catkin/bot_vis/CMakeLists.txt new file mode 100644 index 0000000..ed01f90 --- /dev/null +++ b/catkin/bot_vis/CMakeLists.txt @@ -0,0 +1,61 @@ +cmake_minimum_required(VERSION 2.8.3) +project(bot_vis) +find_package(catkin REQUIRED COMPONENTS +bot_core +) + +set(ENV{PKG_CONFIG_PATH} "/usr/lib/x86_64-linux-gnu/pkgconfig/:$ENV{PKG_CONFIG_PATH}") + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 REQUIRED glib-2.0) +pkg_check_modules(GTK REQUIRED gtk+-2.0) +pkg_check_modules(OPENGL REQUIRED gl) +pkg_check_modules(GLUT REQUIRED glu) +pkg_check_modules(ZLIB REQUIRED zlib) +pkg_check_modules(X11 REQUIRED x11) + +catkin_package( + INCLUDE_DIRS ${JPEG_INCLUDE_DIR} + LIBRARIES bot_vis + CATKIN_DEPENDS bot_core + DEPENDS GLIB2 OPENGL GLUT JPEG ZLIB X11 GTK +) + +include_directories(include ../../bot2-vis/src ${JPEG_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${GTK_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${X11_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}) + +# Vis library +file(GLOB bot_vis_c_files ../../bot2-vis/src/bot_vis/*.c) +file(GLOB bot_vis_h_files ../../bot2-vis/src/bot_vis/*.h) +list(REMOVE_ITEM bot_vis_h_files glm.h) # Keep the GLM library out of the public API +add_library(bot_vis SHARED ${bot_vis_c_files}) +target_link_libraries(bot_vis ${JPEG_LIBRARIES} ${GLUT_LIBRARIES} ${GTK_LIBRARIES} ${GLIB2_LIBRARIES} ${ZLIB_LIBRARIES} ${X11_LIBRARIES} ${catkin_LIBRARIES} ${OPENGL_LIBRARIES} -lglut -ljpeg) +set_property(TARGET bot_vis APPEND_STRING PROPERTY COMPILE_FLAGS -Wno-unused-result ) + +# RWX viewer (possibly unused) +add_executable(bot-rwx-viewer ../../bot2-vis/src/rwx-viewer/main.c ../../bot2-vis/src/rwx-viewer/renderer_rwx.c) +target_link_libraries(bot-rwx-viewer bot_vis) + +# OBJ viewer (possibly unused) +add_executable(bot-wavefront-viewer ../../bot2-vis/src/wavefront-viewer/main.c ../../bot2-vis/src/wavefront-viewer/renderer_wavefront.c) +target_link_libraries(bot-wavefront-viewer bot_vis) + +# Drawing teste +add_executable(gl_drawing_area_tester ../../bot2-vis/src/testers/gl_drawing_area_tester.c) +target_link_libraries(gl_drawing_area_tester bot_vis) + +# Image test +add_executable(gl_image_area_tester ../../bot2-vis/src/testers/gl_image_area_tester.c) +target_link_libraries(gl_image_area_tester bot_vis) + +# Widget test +add_executable(param_widget_tester ../../bot2-vis/src/testers/param_widget_tester.c) +target_link_libraries(param_widget_tester bot_vis) + +# Install the library and all executables +install(TARGETS bot_vis bot-rwx-viewer bot-wavefront-viewer gl_drawing_area_tester gl_image_area_tester param_widget_tester + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) +# Install the header files +install(FILES ${bot_vis_h_files} + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) diff --git a/catkin/bot_vis/package.xml b/catkin/bot_vis/package.xml new file mode 100644 index 0000000..7ee73e2 --- /dev/null +++ b/catkin/bot_vis/package.xml @@ -0,0 +1,17 @@ + + + bot_vis + 1.0.0 + The bot_vis package + Vladimir Ivan + BSD + catkin + bot_core + libglib-dev + gtk2 + opengl + glut + zlib + libx11-dev + libpng12-dev +