BUILD_SHARED_LIBS ON
INSTALL_SHARED_LIBS ON
INSTALL_STATIC_LIBS OFF
CMAKE_CONFIGURATION_TYPES Release
REGISTER_INSTALL_PREFIX OFF
#NAMESPACE google;gflags
NAMESPACE google
# - Try to find GFLAGS # # The following variables are optionally searched for defaults # GFLAGS_ROOT_DIR: Base directory where all GFLAGS components are found # # The following are set after configuration is done: # GFLAGS_FOUND # GFLAGS_INCLUDE_DIRS # GFLAGS_LIBRARIES # GFLAGS_LIBRARYRARY_DIRS
# We are testing only a couple of files in the include directories if(WIN32) find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS ${GFLAGS_ROOT_DIR}/src/windows) else() find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h PATHS ${GFLAGS_ROOT_DIR}) endif()
# - Try to find Glog # # The following variables are optionally searched for defaults # GLOG_ROOT_DIR: Base directory where all GLOG components are found # # The following are set after configuration is done: # GLOG_FOUND # GLOG_INCLUDE_DIRS # GLOG_LIBRARIES # GLOG_LIBRARYRARY_DIRS
include(FindPackageHandleStandardArgs)
set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")
# Always include the source and build directories in the include path. set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Set the output folder where your program will be created set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# Find Poco package 1.8.1 find_package(Poco REQUIRED COMPONENTS Foundation Util Net XML JSON)
# no Poco_INCLUDE_DIRS, we have to set by hand if(MSVC) # WIN32 SET(Poco_INCLUDE_DIRS "C:/Program Files/Poco/include") else() SET(Poco_INCLUDE_DIRS "/usr/local/include/Poco") endif(MSVC)
For “sensor streaming” (live display of sensor data) it is important to change the network settings of the Ethernet adapter connected to the sensor from automatic IP address to manual IP address selection and choose:
VLP-16 / HDL-32E IP address: 192.168.1.77 (77 as example, any number except 201 works) Gateway: 255.255.255.0
HDL-64E IP address: 192.168.3.77 (77 as example, any number except 43 works) Gateway: 192.168.3.255
In order for sensor streaming to work properly, it is important to disable firewall restrictions for the Ethernet port. Disable the firewall completely for the ethernet device connected to the sensor or explicitly allow data from that Ethernet port of (including both public and private networks).
config guide
Setting up your computer to communicate with the sensor
Connect the computer to the interface box with an Ethernet Cable.
Apply power to the sensor.
For now, disable the WiFI connection on your computer.
Configure your computer’s IP address on its Ethernet port to manual mode.
Set your computer’s IP address to 192.168.1.77 (“77” can be any number except 0, 255, or 201)
Set the subnet mask to 255.255.255.0
Pull up the sensor’s webserver interface by typing the sensor’s network address, 192.168.1.201, into the address bar in your web browser
steps
windows ip config
set computer IP address on its Ethernet port to to manual mode with ip=192.168.1.77 (77 can be any number except 0,255,201),gateway=192.168.1.1,mask=255.255.255.0
In this article using Velodyne grabber that has implemented in PCL. It returns coordinated Point Cloud data. You don’t need to convert coordinates yourself.
# Boost if(MSVC) # use static boost on windows set(Boost_USE_STATIC_LIBS ON) else() # use release boost on linux set(Boost_USE_RELEASE_LIBS ON) endif(MSVC)
for find_package(GFLAGS REQUIRED) we copy user-defined gflags-config.cmake from caffe project to /usr/local/lib/cmake/gflags for find_package(GLOG REQUIRED) we copy user-defined glog-config.cmake from caffe project to /usr/local/lib/cmake/glog see compile glog and glags on ubuntu 16.04
find_package(Poco REQUIRED COMPONENTS Foundation Util Net XML JSON)
# no Poco_INCLUDE_DIRS, we have to set by hand if(MSVC) # WIN32 SET(Poco_INCLUDE_DIRS "C:/Program Files/Poco/include") else() SET(Poco_INCLUDE_DIRS "/usr/local/include/Poco") endif(MSVC)
# Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library find_package(Qt5Core) find_package(Qt5Widgets) find_package(Qt5Gui) find_package(Qt5OpenGL) find_package(Qt5Xml)
set(GLOG_FOUND TRUE) # auto set(GLOG_VERSION 0.3.5) set(GLOG_ROOT_DIR "C:/car_libs/glog")
find_path(GLOG_INCLUDE_DIR NAMES glog/logging.h PATHS "${GLOG_ROOT_DIR}/include") mark_as_advanced(GLOG_INCLUDE_DIR) # show entry in cmake-gui
find_library(GLOG_LIBRARY NAMES glog.lib PATHS "${GLOG_ROOT_DIR}/lib") mark_as_advanced(GLOG_LIBRARY) # show entry in cmake-gui
# use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR} ) set(GLOG_LIBRARIES ${GLOG_LIBRARY} )
message( "glog-config.cmake "${GLOG_ROOT_DIR})
mysqlconcpp-config.cmake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
set(MYSQLCPPCONN_FOUND TRUE) # auto set(MYSQLCPPCONN_VERSION 1.1) set(MYSQLCPPCONN_ROOT_DIR "C:/car_libs/mysqlcppconn")
find_path(MYSQLCPPCONN_INCLUDE_DIR NAMES cppconn/driver.h PATHS "${MYSQLCPPCONN_ROOT_DIR}/include") mark_as_advanced(MYSQLCPPCONN_INCLUDE_DIR) # show entry in cmake-gui
find_library(MYSQLCPPCONN_LIBRARY NAMES mysqlcppconn.lib PATHS "${MYSQLCPPCONN_ROOT_DIR}/lib/opt") mark_as_advanced(MYSQLCPPCONN_LIBRARY) # show entry in cmake-gui
# use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt set(MYSQLCPPCONN_INCLUDE_DIRS ${MYSQLCPPCONN_INCLUDE_DIR} ) set(MYSQLCPPCONN_LIBRARIES ${MYSQLCPPCONN_LIBRARY} )
# cmake entry will be saved to build/CMakeCache.txt
set(LIBJPEGTURBO_FOUND TRUE) # auto set(LIBJPEGTURBO_VERSION 1.5.4) set(LIBJPEGTURBO_ROOT_DIR "C:/car_libs/libjpeg-turbo64")
find_path(LIBJPEGTURBO_INCLUDE_DIR NAMES jpeglib.h turbojpeg.h PATHS "${LIBJPEGTURBO_ROOT_DIR}/include") mark_as_advanced(LIBJPEGTURBO_INCLUDE_DIR) # show entry in cmake-gui
find_library(LIBJPEGTURBO_JPEG_LIBRARY NAMES jpeg.lib PATHS "${LIBJPEGTURBO_ROOT_DIR}/lib") mark_as_advanced(LIBJPEGTURBO_JPEG_LIBRARY) # show entry in cmake-gui
find_library(LIBJPEGTURBO_TURBOJPEG_LIBRARY NAMES turbojpeg.lib PATHS "${LIBJPEGTURBO_ROOT_DIR}/lib") mark_as_advanced(LIBJPEGTURBO_TURBOJPEG_LIBRARY) # show entry in cmake-gui
# use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt set(LIBJPEGTURBO_INCLUDE_DIRS ${LIBJPEGTURBO_INCLUDE_DIR} ) set(LIBJPEGTURBO_LIBRARIES ${LIBJPEGTURBO_JPEG_LIBRARY}${LIBJPEGTURBO_TURBOJPEG_LIBRARY} )
set(WINPCAP_FOUND TRUE) # auto set(WINPCAP_VERSION 1.0.0) set(WINPCAP_ROOT_DIR "C:/car_libs/winpcap")
find_path(WINPCAP_INCLUDE_DIR NAMES pcap.h PATHS "${WINPCAP_ROOT_DIR}/Include") mark_as_advanced(WINPCAP_INCLUDE_DIR) # show entry in cmake-gui
find_library(WINPCAP_LIBRARY NAMES wpcap.lib PATHS "${WINPCAP_ROOT_DIR}/Lib") mark_as_advanced(WINPCAP_LIBRARY) # show entry in cmake-gui
# use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt set(WINPCAP_INCLUDE_DIRS ${WINPCAP_INCLUDE_DIR} ) set(WINPCAP_LIBRARIES ${WINPCAP_LIBRARY} )
set(OPENNI2_FOUND TRUE) # auto set(OPENNI2_VERSION 1.0.0) set(OPENNI2_ROOT_DIR "C:/car_libs/OpenNI2")
find_path(OPENNI2_INCLUDE_DIR NAMES OpenNI.h PATHS "${OPENNI2_ROOT_DIR}/Include") mark_as_advanced(OPENNI2_INCLUDE_DIR) # show entry in cmake-gui
find_library(OPENNI2_LIBRARY NAMES OpenNI2.lib PATHS "${OPENNI2_ROOT_DIR}/Lib") mark_as_advanced(OPENNI2_LIBRARY) # show entry in cmake-gui
# use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt set(OPENNI2_INCLUDE_DIRS ${OPENNI2_INCLUDE_DIR} ) set(OPENNI2_LIBRARIES ${OPENNI2_LIBRARY} )
do not use offical version,instead use https://github.com/schuhschuh/gflags.git
1 2 3 4 5
git clone https://github.com/schuhschuh/gflags.git cd gflags mkdir windows-build cd windows-build cmake-gui ..
with options
BUILD_SHARED_LIBS ON
INSTALL_SHARED_LIBS ON
INSTALL_STATIC_LIBS OFF
CMAKE_CONFIGURATION_TYPES Release # Release
REGISTER_INSTALL_PREFIX OFF
CMAKE_INSTALL_PREFIX D:/gflags
#NAMESPACE google;gflags
NAMESPACE google
we get include and lib/gflags.lib, and bin/gflags.dll modify CMAKE/CMAKE_INSTALL_PREFIX to a non-system folder, otherwise you will need administrative privileges to run INSTALL project.
glog
Notice: we have to new entry with BUILD_SHARED_LIB with value ON , because by default, glog is static library with extension .lib.
#WITH_GFLAGS ON
#gflags_DIR D:/gflags/lib/cmake/gflags
WITH_GFLAGS OFF
CMAKE_INSTALL_DIR d:/glog
CMAKE_CONFIGURATION_TYPES Release # Release
BUILD_SHARED_LIBS ON # new by hand
generate sln and open with Visual Studio 2015 compile and install.
// Copy the data pointer and its length from the // source object. _data = other._data; _length = other._length;
// Release the data pointer from the source object so that // the destructor does not free the memory multiple times. other._data = nullptr; other._length = 0; }
if (this != &other) { // Free the existing resource. delete[] _data;
// Copy the data pointer and its length from the // source object. _data = other._data; _length = other._length;
// Release the data pointer from the source object so that // the destructor does not free the memory multiple times. other._data = nullptr; other._length = 0; } return *this; }
private: size_t _length; // The length of the resource. int* _data; // The resource. };
// uses the push_back(const T&) overload, which means // we'll incur the cost of copying str v.push_back(str); std::cout << "After copy, str is \"" << str << "\"\n";
// uses the rvalue reference push_back(T&&) overload, // which means no strings will be copied; instead, the contents // of str will be moved into the vector. This is less // expensive, but also means str might now be empty. v.push_back(std::move(str)); std::cout << "After move, str is \"" << str << "\"\n";
std::cout << "The contents of the vector are \"" << v[0] << "\", \"" << v[1] << "\"\n";
/* After copy, str is "Hello" After move, str is "" The contents of the vector are "Hello", "Hello" */ }
configure and generate sln, compile with visual studio 2015 and install.
usage with cmake
libjpegturbo-config.cmake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
set(LIBJPEGTURBO_FOUND TRUE) # auto set(LIBJPEGTURBO_ROOT_DIR "d:/libjpeg-turbo64")
find_path(LIBJPEGTURBO_INCLUDE_DIR NAMES jpeglib.h turbojpeg.h PATHS "${LIBJPEGTURBO_ROOT_DIR}/include") mark_as_advanced(LIBJPEGTURBO_INCLUDE_DIR) # show entry in cmake-gui
find_library(LIBJPEGTURBO_JPEG_LIBRARY NAMES jpeg.lib PATHS "${LIBJPEGTURBO_ROOT_DIR}/lib") mark_as_advanced(LIBJPEGTURBO_JPEG_LIBRARY) # show entry in cmake-gui
find_library(LIBJPEGTURBO_TURBOJPEG_LIBRARY NAMES turbojpeg.lib PATHS "${LIBJPEGTURBO_ROOT_DIR}/lib") mark_as_advanced(LIBJPEGTURBO_TURBOJPEG_LIBRARY) # show entry in cmake-gui
# use xxx_INCLUDE_DIRS and xxx_LIBRARIES in CMakeLists.txt set(LIBJPEGTURBO_INCLUDE_DIRS ${LIBJPEGTURBO_INCLUDE_DIR} ) set(LIBJPEGTURBO_LIBRARIES ${LIBJPEGTURBO_JPEG_LIBRARY}${LIBJPEGTURBO_TURBOJPEG_LIBRARY} )
The easiest serialization method for strings or other blobs with variable size is to serialize first the size as you serialize integers, then just copy the content to the output stream.
When reading you first read the size, then allocate the string and then fill it by reading the correct number of bytes from the stream.
with ostream/istream
native way with ostream/istream for example class MyClass with height,width,name fields.
classMyClass { public: int height; int width; std::string name; }
std::ostream& MyClass::serialize(std::ostream &out)const{ out << height; out << ','//number seperator out << width; out << ','//number seperator out << name.size(); //serialize size of string out << ','//number seperator out << name; //serialize characters of string return out; } std::istream& MyClass::deserialize(std::istream &in){ if (in) { int len=0; char comma; in >> height; in >> comma; //read in the seperator in >> width; in >> comma; //read in the seperator in >> len; //deserialize size of string in >> comma; //read in the seperator if (in && len) { std::vector<char> tmp(len); in.read(tmp.data() , len); //deserialize characters of string name.assign(tmp.data(), len); } } return in; }
boost::archive::binary_iarchive ia(stream); Camera new_cam; ia & (new_cam); std::cout << new_cam << std::endl; } catch (Poco::Exception& exc) { app.logger().log(exc); } }
notes on std::string
Even know you have seen that they do the same, or that .data() calls .c_str(), it is not correct to assume that this will be the case for other compilers. It is also possible that your compiler will change with a future release.
2 reasons to use std::string:
std::string can be used for both text and arbitrary binary data.
rem Usage: rem ------ rem buildwin VS_VERSION [ACTION] [LINKMODE] [CONFIGURATION] [PLATFORM] [SAMPLES] [TESTS] [TOOL] rem VS_VERSION: 90|100|110|120|140|150 rem ACTION: build|rebuild|clean rem LINKMODE: static_mt|static_md|shared|all rem CONFIGURATION: release|debug|both rem PLATFORM: Win32|x64|WinCE|WEC2013 rem SAMPLES: samples|nosamples rem TESTS: tests|notests rem TOOL: devenv|vcexpress|wdexpress|msbuild
we choose to build with visual studio 2015
build_vs140.cmd
1 2
@echo off buildwin 140 build shared release x64 samples
build
1
./build_vs140.cmd
or
1
cmake-gui ..
cmake-gui and open sln to build with release x64and install to C:/Program Files/Poco so that find_package(Poco REQURIED) take effect.
1 2 3 4 5 6 7 8 9 10 11 12 13
$ ls Poco
bin include lib
$ ll Poco/lib
total 3.5M drwxr-xr-x 1 zunli zunli 0 Jan 25 07:39 cmake -rw-r--r-- 1 zunli zunli 1.5M Jan 25 06:59 PocoFoundation.lib -rw-r--r-- 1 zunli zunli 111K Jan 25 06:59 PocoJSON.lib -rw-r--r-- 1 zunli zunli 1007K Jan 25 07:00 PocoNet.lib -rw-r--r-- 1 zunli zunli 320K Jan 25 07:00 PocoUtil.lib -rw-r--r-- 1 zunli zunli 595K Jan 25 07:00 PocoXML.lib
# Always include the source and build directories in the include path. set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Set the output folder where your program will be created set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
find_package(Poco REQUIRED COMPONENTS Foundation Util Net XML JSON)
# no Poco_INCLUDE_DIRS, we have to set by hand if(MSVC) # WIN32 SET(Poco_INCLUDE_DIRS "C:/Program Files/Poco/include") else() SET(Poco_INCLUDE_DIRS "/usr/local/include/Poco") endif(MSVC)
using Poco::Net::ServerSocket; using Poco::Net::HTTPRequestHandler; using Poco::Net::HTTPRequestHandlerFactory; using Poco::Net::HTTPServer; using Poco::Net::HTTPServerRequest; using Poco::Net::HTTPServerResponse; using Poco::Net::HTTPServerParams; using Poco::Timestamp; using Poco::DateTimeFormatter; using Poco::DateTimeFormat; using Poco::ThreadPool; using Poco::Util::ServerApplication; using Poco::Util::Application; using Poco::Util::Option; using Poco::Util::OptionSet; using Poco::Util::OptionCallback; using Poco::Util::HelpFormatter;
voidhandleHelp(const std::string& name, const std::string& value) { HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("OPTIONS"); helpFormatter.setHeader( "A web server that serves the current date and time."); helpFormatter.format(std::cout); stopOptionsProcessing(); _helpRequested = true; }
using Poco::Net::ServerSocket; using Poco::Net::StreamSocket; using Poco::Net::TCPServerConnection; using Poco::Net::TCPServerConnectionFactory; using Poco::Net::TCPServer; using Poco::Timestamp; using Poco::DateTimeFormatter; using Poco::DateTimeFormat; using Poco::Util::ServerApplication; using Poco::Util::Application; using Poco::Util::Option; using Poco::Util::OptionSet; using Poco::Util::HelpFormatter;
classTimeServerConnection : public TCPServerConnection /// This class handles all client connections. /// /// A string with the current date and time is sent back to the client. { public: TimeServerConnection(const StreamSocket& s, const std::string& format) : TCPServerConnection(s), _format(format) { }
classTimeServer : public Poco::Util::ServerApplication /// The main application class. /// /// This class handles command-line arguments and /// configuration files. /// Start the TimeServer executable with the help /// option (/help on Windows, --help on Unix) for /// the available command line options. /// /// To use the sample configuration file (TimeServer.properties), /// copy the file to the directory where the TimeServer executable /// resides. If you start the debug version of the TimeServer /// (TimeServerd[.exe]), you must also create a copy of the configuration /// file named TimeServerd.properties. In the configuration file, you /// can specify the port on which the server is listening (default /// 9911) and the format of the date/time string sent back to the client. /// /// To test the TimeServer you can use any telnet client (telnet localhost 9911). { public: TimeServer() : _helpRequested(false) { }
voiddisplayHelp() { HelpFormatter helpFormatter(options()); helpFormatter.setCommand(commandName()); helpFormatter.setUsage("OPTIONS"); helpFormatter.setHeader("A server application that serves the current date and time."); helpFormatter.format(std::cout); }
intmain(const std::vector<std::string>& args) { if (_helpRequested) { displayHelp(); } else { // get parameters from configuration file unsignedshort port = (unsignedshort)config().getInt("TimeServer.port", 9911); std::string format(config().getString("TimeServer.format", DateTimeFormat::ISO8601_FORMAT));
// set-up a server socket ServerSocket svs(port); // set-up a TCPServer instance TCPServer srv(new TimeServerConnectionFactory(format), svs); // start the TCPServer srv.start(); // wait for CTRL-C or kill waitForTerminationRequest(); // Stop the TCPServer srv.stop(); } return Application::EXIT_OK; }