diff --git a/.gitignore b/.gitignore index cb55d82..e6dda02 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ cmake_install.cmake serial-port/ lib/ Ymodem*/ -build/ \ No newline at end of file +build/* +*.log +*.jpg \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ce5627..35da6ca 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ add_executable(timeout ${TEST_SRCS}) set(CMAKE_BUILD_TYPE Debug) ## Link libraries -set(BOOST_LIBS date_time system log) +set(BOOST_LIBS date_time system log program_options) find_package(Boost COMPONENTS ${BOOST_LIBS} REQUIRED) target_link_libraries(timeout ${Boost_LIBRARIES}) find_package(Threads REQUIRED) diff --git a/Ymodem.cpp b/Ymodem.cpp index 7214d8b..a33289d 100644 --- a/Ymodem.cpp +++ b/Ymodem.cpp @@ -29,6 +29,11 @@ /* Header includes -----------------------------------------------------------*/ #include "Ymodem.h" #include +#include +#include +#include +#include +#include /* Macro definitions ---------------------------------------------------------*/ /* Type definitions ----------------------------------------------------------*/ @@ -130,6 +135,7 @@ void Ymodem::receive() { case StageNone: { + BOOST_LOG_TRIVIAL(debug) << "receiveStageNone"; receiveStageNone(); break; @@ -137,6 +143,8 @@ void Ymodem::receive() case StageEstablishing: { + + BOOST_LOG_TRIVIAL(debug) << "receiveStageEstablishing"; receiveStageEstablishing(); break; @@ -144,6 +152,7 @@ void Ymodem::receive() case StageEstablished: { + BOOST_LOG_TRIVIAL(debug) << "receiveStageEstablished"; receiveStageEstablished(); break; @@ -151,6 +160,7 @@ void Ymodem::receive() case StageTransmitting: { + BOOST_LOG_TRIVIAL(debug) << "receiveStageTransmitting"; receiveStageTransmitting(); break; @@ -158,6 +168,7 @@ void Ymodem::receive() case StageFinishing: { + BOOST_LOG_TRIVIAL(debug) << "receiveStageFinishing"; receiveStageFinishing(); break; diff --git a/YmodemFileReceive.cpp b/YmodemFileReceive.cpp index 2d5553d..e1f5408 100644 --- a/YmodemFileReceive.cpp +++ b/YmodemFileReceive.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "TimeoutSerial.h" using namespace std; @@ -35,6 +36,11 @@ void YmodemFileReceive::setFilePath(const string &path) filePath = path + "/"; } +void YmodemFileReceive::setDefaultFileName(const string &file) +{ + defaultFileName = file; +} + void YmodemFileReceive::setSerialPort(TimeoutSerial *port) { serialPort = port; @@ -50,8 +56,13 @@ bool YmodemFileReceive::startReceive() progress = 0; status = StatusEstablish; - io.run(); + BOOST_LOG_TRIVIAL(debug) << "Statring receive"; + serialPort->setTimeout(posix_time::seconds(0)); + readTimer.expires_from_now(boost::posix_time::millisec(READ_TIME_OUT)); + readTimer.async_wait(boost::bind(&YmodemFileReceive::readTimeOut,this,_1)); + io.run(); + return true; } @@ -75,7 +86,8 @@ Ymodem::Status YmodemFileReceive::getReceiveStatus() void YmodemFileReceive::readTimeOut(const boost::system::error_code& e) { - readTimer.cancel(); + BOOST_LOG_TRIVIAL(debug) << "Read timeout"; + receive(); @@ -89,7 +101,7 @@ void YmodemFileReceive::readTimeOut(const boost::system::error_code& e) void YmodemFileReceive::writeTimeOut(const boost::system::error_code& e) { writeTimer.cancel(); - serialPort->close(); + //serialPort->close(); receiveStatus(status); } @@ -117,12 +129,19 @@ Ymodem::Code YmodemFileReceive::callback(Status status, uint8_t *buff, uint32_t size[j] = buff[i]; } - fileName = name; + if (defaultFileName != "") { + fileName = defaultFileName; + } else { + fileName = name; + } string file_desc(size); string sizeStr = file_desc.substr(0,file_desc.find_first_of(' ')); fileSize = stol(sizeStr); fileCount = 0; + + BOOST_LOG_TRIVIAL(debug) << "File open: " << filePath + fileName ; + file.open(filePath + fileName, ios::out | ios::binary); if(file.is_open() == true) diff --git a/YmodemFileReceive.h b/YmodemFileReceive.h index 8c7d656..136f885 100644 --- a/YmodemFileReceive.h +++ b/YmodemFileReceive.h @@ -20,6 +20,7 @@ public: ~YmodemFileReceive(); void setFilePath(const string &path); + void setDefaultFileName(const string &path); void setSerialPort(TimeoutSerial *port); TimeoutSerial *getSerialPort(); @@ -52,6 +53,7 @@ private: Status status; string filePath; string fileName; + string defaultFileName = ""; uint64_t fileSize; uint64_t fileCount; }; diff --git a/build/.cmake/api/v1/reply/cache-v2-9de8371d03fa8cbf9def.json b/build/.cmake/api/v1/reply/cache-v2-9de8371d03fa8cbf9def.json deleted file mode 100644 index 0cfab9c..0000000 --- a/build/.cmake/api/v1/reply/cache-v2-9de8371d03fa8cbf9def.json +++ /dev/null @@ -1,1447 +0,0 @@ -{ - "entries" : - [ - { - "name" : "Boost_DATE_TIME_LIBRARY_RELEASE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "" - } - ], - "type" : "STRING", - "value" : "/usr/lib/x86_64-linux-gnu/libboost_date_time.so.1.71.0" - }, - { - "name" : "Boost_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for Boost." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0" - }, - { - "name" : "Boost_INCLUDE_DIR", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Path to a file." - } - ], - "type" : "PATH", - "value" : "/usr/include" - }, - { - "name" : "Boost_LOG_LIBRARY_RELEASE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "" - } - ], - "type" : "STRING", - "value" : "/usr/lib/x86_64-linux-gnu/libboost_log.so.1.71.0" - }, - { - "name" : "Boost_SYSTEM_LIBRARY_RELEASE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "" - } - ], - "type" : "STRING", - "value" : "/usr/lib/x86_64-linux-gnu/libboost_system.so.1.71.0" - }, - { - "name" : "CMAKE_ADDR2LINE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/addr2line" - }, - { - "name" : "CMAKE_AR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/ar" - }, - { - "name" : "CMAKE_BUILD_TYPE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "No help, variable specified on the command line." - } - ], - "type" : "STRING", - "value" : "Debug" - }, - { - "name" : "CMAKE_CACHEFILE_DIR", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "This is the directory where this CMakeCache.txt was created" - } - ], - "type" : "INTERNAL", - "value" : "/home/jaro/serialport-downloader/build" - }, - { - "name" : "CMAKE_CACHE_MAJOR_VERSION", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Major version of cmake used to create the current loaded cache" - } - ], - "type" : "INTERNAL", - "value" : "3" - }, - { - "name" : "CMAKE_CACHE_MINOR_VERSION", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Minor version of cmake used to create the current loaded cache" - } - ], - "type" : "INTERNAL", - "value" : "16" - }, - { - "name" : "CMAKE_CACHE_PATCH_VERSION", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Patch version of cmake used to create the current loaded cache" - } - ], - "type" : "INTERNAL", - "value" : "3" - }, - { - "name" : "CMAKE_COLOR_MAKEFILE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Enable/Disable color output during build." - } - ], - "type" : "BOOL", - "value" : "ON" - }, - { - "name" : "CMAKE_COMMAND", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Path to CMake executable." - } - ], - "type" : "INTERNAL", - "value" : "/usr/bin/cmake" - }, - { - "name" : "CMAKE_CPACK_COMMAND", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Path to cpack program executable." - } - ], - "type" : "INTERNAL", - "value" : "/usr/bin/cpack" - }, - { - "name" : "CMAKE_CTEST_COMMAND", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Path to ctest program executable." - } - ], - "type" : "INTERNAL", - "value" : "/usr/bin/ctest" - }, - { - "name" : "CMAKE_CXX_COMPILER", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "CXX compiler" - } - ], - "type" : "FILEPATH", - "value" : "/bin/c++" - }, - { - "name" : "CMAKE_CXX_COMPILER_AR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "A wrapper around 'ar' adding the appropriate '--plugin' option for the GCC compiler" - } - ], - "type" : "FILEPATH", - "value" : "/bin/gcc-ar-9" - }, - { - "name" : "CMAKE_CXX_COMPILER_RANLIB", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "A wrapper around 'ranlib' adding the appropriate '--plugin' option for the GCC compiler" - } - ], - "type" : "FILEPATH", - "value" : "/bin/gcc-ranlib-9" - }, - { - "name" : "CMAKE_CXX_FLAGS", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the CXX compiler during all build types." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_CXX_FLAGS_DEBUG", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the CXX compiler during DEBUG builds." - } - ], - "type" : "STRING", - "value" : "-g" - }, - { - "name" : "CMAKE_CXX_FLAGS_MINSIZEREL", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the CXX compiler during MINSIZEREL builds." - } - ], - "type" : "STRING", - "value" : "-Os -DNDEBUG" - }, - { - "name" : "CMAKE_CXX_FLAGS_RELEASE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the CXX compiler during RELEASE builds." - } - ], - "type" : "STRING", - "value" : "-O3 -DNDEBUG" - }, - { - "name" : "CMAKE_CXX_FLAGS_RELWITHDEBINFO", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the CXX compiler during RELWITHDEBINFO builds." - } - ], - "type" : "STRING", - "value" : "-O2 -g -DNDEBUG" - }, - { - "name" : "CMAKE_C_COMPILER", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "No help, variable specified on the command line." - } - ], - "type" : "FILEPATH", - "value" : "/bin/mipsel-linux-gnu-gcc-10" - }, - { - "name" : "CMAKE_C_COMPILER_AR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "A wrapper around 'ar' adding the appropriate '--plugin' option for the GCC compiler" - } - ], - "type" : "FILEPATH", - "value" : "/bin/gcc-ar" - }, - { - "name" : "CMAKE_C_COMPILER_RANLIB", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "A wrapper around 'ranlib' adding the appropriate '--plugin' option for the GCC compiler" - } - ], - "type" : "FILEPATH", - "value" : "/bin/gcc-ranlib" - }, - { - "name" : "CMAKE_C_FLAGS", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the C compiler during all build types." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_C_FLAGS_DEBUG", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the C compiler during DEBUG builds." - } - ], - "type" : "STRING", - "value" : "-g" - }, - { - "name" : "CMAKE_C_FLAGS_MINSIZEREL", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the C compiler during MINSIZEREL builds." - } - ], - "type" : "STRING", - "value" : "-Os -DNDEBUG" - }, - { - "name" : "CMAKE_C_FLAGS_RELEASE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the C compiler during RELEASE builds." - } - ], - "type" : "STRING", - "value" : "-O3 -DNDEBUG" - }, - { - "name" : "CMAKE_C_FLAGS_RELWITHDEBINFO", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the C compiler during RELWITHDEBINFO builds." - } - ], - "type" : "STRING", - "value" : "-O2 -g -DNDEBUG" - }, - { - "name" : "CMAKE_DLLTOOL", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "CMAKE_DLLTOOL-NOTFOUND" - }, - { - "name" : "CMAKE_EXECUTABLE_FORMAT", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Executable file format" - } - ], - "type" : "INTERNAL", - "value" : "ELF" - }, - { - "name" : "CMAKE_EXE_LINKER_FLAGS", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during all build types." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_EXE_LINKER_FLAGS_DEBUG", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during DEBUG builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_EXE_LINKER_FLAGS_MINSIZEREL", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during MINSIZEREL builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_EXE_LINKER_FLAGS_RELEASE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during RELEASE builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during RELWITHDEBINFO builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_EXPORT_COMPILE_COMMANDS", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "No help, variable specified on the command line." - } - ], - "type" : "BOOL", - "value" : "TRUE" - }, - { - "name" : "CMAKE_EXTRA_GENERATOR", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Name of external makefile project generator." - } - ], - "type" : "INTERNAL", - "value" : "" - }, - { - "name" : "CMAKE_GENERATOR", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Name of generator." - } - ], - "type" : "INTERNAL", - "value" : "Unix Makefiles" - }, - { - "name" : "CMAKE_GENERATOR_INSTANCE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Generator instance identifier." - } - ], - "type" : "INTERNAL", - "value" : "" - }, - { - "name" : "CMAKE_GENERATOR_PLATFORM", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Name of generator platform." - } - ], - "type" : "INTERNAL", - "value" : "" - }, - { - "name" : "CMAKE_GENERATOR_TOOLSET", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Name of generator toolset." - } - ], - "type" : "INTERNAL", - "value" : "" - }, - { - "name" : "CMAKE_HAVE_LIBC_PTHREAD", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Test CMAKE_HAVE_LIBC_PTHREAD" - } - ], - "type" : "INTERNAL", - "value" : "" - }, - { - "name" : "CMAKE_HAVE_PTHREADS_CREATE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Have library pthreads" - } - ], - "type" : "INTERNAL", - "value" : "" - }, - { - "name" : "CMAKE_HAVE_PTHREAD_CREATE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Have library pthread" - } - ], - "type" : "INTERNAL", - "value" : "1" - }, - { - "name" : "CMAKE_HAVE_PTHREAD_H", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Have include pthread.h" - } - ], - "type" : "INTERNAL", - "value" : "1" - }, - { - "name" : "CMAKE_HOME_DIRECTORY", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Source directory with the top level CMakeLists.txt file for this project" - } - ], - "type" : "INTERNAL", - "value" : "/home/jaro/serialport-downloader" - }, - { - "name" : "CMAKE_INSTALL_PREFIX", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Install path prefix, prepended onto install directories." - } - ], - "type" : "PATH", - "value" : "/usr/local" - }, - { - "name" : "CMAKE_INSTALL_SO_NO_EXE", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Install .so files without execute permission." - } - ], - "type" : "INTERNAL", - "value" : "1" - }, - { - "name" : "CMAKE_LINKER", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/ld" - }, - { - "name" : "CMAKE_MAKE_PROGRAM", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/usr/bin/make" - }, - { - "name" : "CMAKE_MODULE_LINKER_FLAGS", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of modules during all build types." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_MODULE_LINKER_FLAGS_DEBUG", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of modules during DEBUG builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of modules during MINSIZEREL builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_MODULE_LINKER_FLAGS_RELEASE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of modules during RELEASE builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of modules during RELWITHDEBINFO builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_NM", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/nm" - }, - { - "name" : "CMAKE_NUMBER_OF_MAKEFILES", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "number of local generators" - } - ], - "type" : "INTERNAL", - "value" : "1" - }, - { - "name" : "CMAKE_OBJCOPY", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/objcopy" - }, - { - "name" : "CMAKE_OBJDUMP", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/objdump" - }, - { - "name" : "CMAKE_PLATFORM_INFO_INITIALIZED", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Platform information initialized" - } - ], - "type" : "INTERNAL", - "value" : "1" - }, - { - "name" : "CMAKE_PROJECT_DESCRIPTION", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Value Computed by CMake" - } - ], - "type" : "STATIC", - "value" : "" - }, - { - "name" : "CMAKE_PROJECT_HOMEPAGE_URL", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Value Computed by CMake" - } - ], - "type" : "STATIC", - "value" : "" - }, - { - "name" : "CMAKE_PROJECT_NAME", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Value Computed by CMake" - } - ], - "type" : "STATIC", - "value" : "TEST" - }, - { - "name" : "CMAKE_RANLIB", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/ranlib" - }, - { - "name" : "CMAKE_READELF", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/readelf" - }, - { - "name" : "CMAKE_ROOT", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Path to CMake installation." - } - ], - "type" : "INTERNAL", - "value" : "/usr/share/cmake-3.16" - }, - { - "name" : "CMAKE_SHARED_LINKER_FLAGS", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of shared libraries during all build types." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_SHARED_LINKER_FLAGS_DEBUG", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of shared libraries during DEBUG builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of shared libraries during MINSIZEREL builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_SHARED_LINKER_FLAGS_RELEASE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of shared libraries during RELEASE builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of shared libraries during RELWITHDEBINFO builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_SKIP_INSTALL_RPATH", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "If set, runtime paths are not added when installing shared libraries, but are added when building." - } - ], - "type" : "BOOL", - "value" : "NO" - }, - { - "name" : "CMAKE_SKIP_RPATH", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "If set, runtime paths are not added when using shared libraries." - } - ], - "type" : "BOOL", - "value" : "NO" - }, - { - "name" : "CMAKE_STATIC_LINKER_FLAGS", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of static libraries during all build types." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_STATIC_LINKER_FLAGS_DEBUG", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of static libraries during DEBUG builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of static libraries during MINSIZEREL builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_STATIC_LINKER_FLAGS_RELEASE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of static libraries during RELEASE builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Flags used by the linker during the creation of static libraries during RELWITHDEBINFO builds." - } - ], - "type" : "STRING", - "value" : "" - }, - { - "name" : "CMAKE_STRIP", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "Path to a program." - } - ], - "type" : "FILEPATH", - "value" : "/bin/strip" - }, - { - "name" : "CMAKE_UNAME", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "uname command" - } - ], - "type" : "INTERNAL", - "value" : "/usr/bin/uname" - }, - { - "name" : "CMAKE_VERBOSE_MAKEFILE", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo." - } - ], - "type" : "BOOL", - "value" : "FALSE" - }, - { - "name" : "FIND_PACKAGE_MESSAGE_DETAILS_Boost", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Details about finding Boost" - } - ], - "type" : "INTERNAL", - "value" : "[/usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake][cfound components: date_time system log ][v1.71.0()]" - }, - { - "name" : "FIND_PACKAGE_MESSAGE_DETAILS_Threads", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Details about finding Threads" - } - ], - "type" : "INTERNAL", - "value" : "[TRUE][v()]" - }, - { - "name" : "TEST_BINARY_DIR", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Value Computed by CMake" - } - ], - "type" : "STATIC", - "value" : "/home/jaro/serialport-downloader/build" - }, - { - "name" : "TEST_SOURCE_DIR", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "Value Computed by CMake" - } - ], - "type" : "STATIC", - "value" : "/home/jaro/serialport-downloader" - }, - { - "name" : "boost_atomic_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_atomic." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_atomic-1.71.0" - }, - { - "name" : "boost_chrono_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_chrono." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_chrono-1.71.0" - }, - { - "name" : "boost_date_time_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_date_time." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_date_time-1.71.0" - }, - { - "name" : "boost_filesystem_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_filesystem." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_filesystem-1.71.0" - }, - { - "name" : "boost_headers_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_headers." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_headers-1.71.0" - }, - { - "name" : "boost_log_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_log." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_log-1.71.0" - }, - { - "name" : "boost_program_options_DIR", - "properties" : - [ - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_program_options." - } - ], - "type" : "PATH", - "value" : "boost_program_options_DIR-NOTFOUND" - }, - { - "name" : "boost_regex_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_regex." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_regex-1.71.0" - }, - { - "name" : "boost_system_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_system." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_system-1.71.0" - }, - { - "name" : "boost_thread_DIR", - "properties" : - [ - { - "name" : "ADVANCED", - "value" : "1" - }, - { - "name" : "HELPSTRING", - "value" : "The directory containing a CMake configuration file for boost_thread." - } - ], - "type" : "PATH", - "value" : "/usr/lib/x86_64-linux-gnu/cmake/boost_thread-1.71.0" - } - ], - "kind" : "cache", - "version" : - { - "major" : 2, - "minor" : 0 - } -} diff --git a/build/.cmake/api/v1/reply/codemodel-v2-2f061e11e865d7291da7.json b/build/.cmake/api/v1/reply/codemodel-v2-2f061e11e865d7291da7.json deleted file mode 100644 index fde9746..0000000 --- a/build/.cmake/api/v1/reply/codemodel-v2-2f061e11e865d7291da7.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "configurations" : - [ - { - "directories" : - [ - { - "build" : ".", - "minimumCMakeVersion" : - { - "string" : "3.1" - }, - "projectIndex" : 0, - "source" : ".", - "targetIndexes" : - [ - 0 - ] - } - ], - "name" : "Debug", - "projects" : - [ - { - "directoryIndexes" : - [ - 0 - ], - "name" : "TEST", - "targetIndexes" : - [ - 0 - ] - } - ], - "targets" : - [ - { - "directoryIndex" : 0, - "id" : "timeout::@6890427a1f51a3e7e1df", - "jsonFile" : "target-timeout-Debug-d7af418a1b6c2d259633.json", - "name" : "timeout", - "projectIndex" : 0 - } - ] - } - ], - "kind" : "codemodel", - "paths" : - { - "build" : "/home/jaro/serialport-downloader/build", - "source" : "/home/jaro/serialport-downloader" - }, - "version" : - { - "major" : 2, - "minor" : 0 - } -} diff --git a/build/.cmake/api/v1/reply/target-timeout-Debug-d7af418a1b6c2d259633.json b/build/.cmake/api/v1/reply/target-timeout-Debug-d7af418a1b6c2d259633.json deleted file mode 100644 index ae304ad..0000000 --- a/build/.cmake/api/v1/reply/target-timeout-Debug-d7af418a1b6c2d259633.json +++ /dev/null @@ -1,219 +0,0 @@ -{ - "artifacts" : - [ - { - "path" : "timeout" - } - ], - "backtrace" : 1, - "backtraceGraph" : - { - "commands" : - [ - "add_executable", - "target_link_libraries", - "add_definitions" - ], - "files" : - [ - "CMakeLists.txt" - ], - "nodes" : - [ - { - "file" : 0 - }, - { - "command" : 0, - "file" : 0, - "line" : 9, - "parent" : 0 - }, - { - "command" : 1, - "file" : 0, - "line" : 15, - "parent" : 0 - }, - { - "command" : 2, - "file" : 0, - "line" : 8, - "parent" : 0 - } - ] - }, - "compileGroups" : - [ - { - "compileCommandFragments" : - [ - { - "fragment" : "-g " - }, - { - "fragment" : "-std=gnu++11" - } - ], - "defines" : - [ - { - "backtrace" : 2, - "define" : "BOOST_ALL_NO_LIB" - }, - { - "backtrace" : 2, - "define" : "BOOST_ATOMIC_DYN_LINK" - }, - { - "backtrace" : 2, - "define" : "BOOST_CHRONO_DYN_LINK" - }, - { - "backtrace" : 2, - "define" : "BOOST_DATE_TIME_DYN_LINK" - }, - { - "backtrace" : 2, - "define" : "BOOST_FILESYSTEM_DYN_LINK" - }, - { - "backtrace" : 3, - "define" : "BOOST_LOG_DYN_LINK" - }, - { - "backtrace" : 2, - "define" : "BOOST_REGEX_DYN_LINK" - }, - { - "backtrace" : 2, - "define" : "BOOST_SYSTEM_DYN_LINK" - }, - { - "backtrace" : 2, - "define" : "BOOST_THREAD_DYN_LINK" - } - ], - "language" : "CXX", - "sourceIndexes" : - [ - 0, - 1, - 2, - 3 - ] - } - ], - "id" : "timeout::@6890427a1f51a3e7e1df", - "link" : - { - "commandFragments" : - [ - { - "fragment" : "-g", - "role" : "flags" - }, - { - "fragment" : "-rdynamic", - "role" : "flags" - }, - { - "backtrace" : 2, - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_date_time.so.1.71.0", - "role" : "libraries" - }, - { - "backtrace" : 2, - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_system.so.1.71.0", - "role" : "libraries" - }, - { - "backtrace" : 2, - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_log.so.1.71.0", - "role" : "libraries" - }, - { - "fragment" : "-lpthread", - "role" : "libraries" - }, - { - "backtrace" : 2, - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_date_time.so.1.71.0", - "role" : "libraries" - }, - { - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_chrono.so.1.71.0", - "role" : "libraries" - }, - { - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.71.0", - "role" : "libraries" - }, - { - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_regex.so.1.71.0", - "role" : "libraries" - }, - { - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_thread.so.1.71.0", - "role" : "libraries" - }, - { - "fragment" : "/usr/lib/x86_64-linux-gnu/libboost_atomic.so.1.71.0", - "role" : "libraries" - }, - { - "fragment" : "-lpthread", - "role" : "libraries" - } - ], - "language" : "CXX" - }, - "name" : "timeout", - "nameOnDisk" : "timeout", - "paths" : - { - "build" : ".", - "source" : "." - }, - "sourceGroups" : - [ - { - "name" : "Source Files", - "sourceIndexes" : - [ - 0, - 1, - 2, - 3 - ] - } - ], - "sources" : - [ - { - "backtrace" : 1, - "compileGroupIndex" : 0, - "path" : "main.cpp", - "sourceGroupIndex" : 0 - }, - { - "backtrace" : 1, - "compileGroupIndex" : 0, - "path" : "TimeoutSerial.cpp", - "sourceGroupIndex" : 0 - }, - { - "backtrace" : 1, - "compileGroupIndex" : 0, - "path" : "Ymodem.cpp", - "sourceGroupIndex" : 0 - }, - { - "backtrace" : 1, - "compileGroupIndex" : 0, - "path" : "YmodemFileReceive.cpp", - "sourceGroupIndex" : 0 - } - ], - "type" : "EXECUTABLE" -} diff --git a/build/compile_commands.json b/build/compile_commands.json index f88a7a5..cd3afb5 100644 --- a/build/compile_commands.json +++ b/build/compile_commands.json @@ -1,22 +1,22 @@ [ { "directory": "/home/jaro/serialport-downloader/build", - "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/main.cpp.o -c /home/jaro/serialport-downloader/main.cpp", + "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/main.cpp.o -c /home/jaro/serialport-downloader/main.cpp", "file": "/home/jaro/serialport-downloader/main.cpp" }, { "directory": "/home/jaro/serialport-downloader/build", - "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/TimeoutSerial.cpp.o -c /home/jaro/serialport-downloader/TimeoutSerial.cpp", + "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/TimeoutSerial.cpp.o -c /home/jaro/serialport-downloader/TimeoutSerial.cpp", "file": "/home/jaro/serialport-downloader/TimeoutSerial.cpp" }, { "directory": "/home/jaro/serialport-downloader/build", - "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/Ymodem.cpp.o -c /home/jaro/serialport-downloader/Ymodem.cpp", + "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/Ymodem.cpp.o -c /home/jaro/serialport-downloader/Ymodem.cpp", "file": "/home/jaro/serialport-downloader/Ymodem.cpp" }, { "directory": "/home/jaro/serialport-downloader/build", - "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/YmodemFileReceive.cpp.o -c /home/jaro/serialport-downloader/YmodemFileReceive.cpp", + "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_CHRONO_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_LOG_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/YmodemFileReceive.cpp.o -c /home/jaro/serialport-downloader/YmodemFileReceive.cpp", "file": "/home/jaro/serialport-downloader/YmodemFileReceive.cpp" } ] \ No newline at end of file diff --git a/main.cpp b/main.cpp index 7d61c77..6132db4 100755 --- a/main.cpp +++ b/main.cpp @@ -21,19 +21,38 @@ #include #include #include +#include #include #include #include #include + +#include + #include "TimeoutSerial.h" +#include "YmodemFileReceive.h" + +#include using namespace std; using namespace boost; +namespace po = boost::program_options; typedef vector< string > split_vector_type; +enum severity_level +{ + normal, + notification, + warning, + error, + critical +}; + +BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", severity_level) + bool dataHandler(unsigned long blockNo, char* buffer, int size) { cout << "Block No. = " << blockNo << endl; @@ -79,10 +98,11 @@ static void init_log(void) /* console sink */ auto consoleSink = boost::log::add_console_log(std::clog); consoleSink->set_formatter(logFmt); - + consoleSink->set_filter(severity >= warning); /* fs sink */ auto fsSink = boost::log::add_file_log( - boost::log::keywords::file_name = "serial-dw_%Y-%m-%d_%H-%M-%S.%N.log", + // boost::log::keywords::file_name = "serial-dw_%Y-%m-%d_%H-%M-%S.%N.log", + boost::log::keywords::file_name = "serial-downloader.log", boost::log::keywords::rotation_size = 10 * 1024 * 1024, boost::log::keywords::min_free_space = 30 * 1024 * 1024, boost::log::keywords::open_mode = std::ios_base::app); @@ -94,74 +114,132 @@ static void init_log(void) int main(int argc, char* argv[]) { string line; + YmodemFileReceive modem; float temperature = NAN; float humidity= NAN; float pressure = NAN; - + po::variables_map vm; + std::string port,path,filename; + int speed; + init_log(); + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "produce help message") + ("measure", "get and print values") + ("verbose", po::value()->implicit_value("0"), "verbosity level") + ("file", po::value(&filename)->default_value("camera.jpg"),"filename of capture filename") + ("path", po::value(&path)->default_value("/tmp"),"directory for file of capture") + ("capture", "capture photo of camera") + ("port", po::value(&port)->default_value("/dev/ttyUSB0"), "port to read from") + ("speed", po::value(&speed)->default_value(115200), "speed read from port") + ("temperature", "get and print temprature") + ("humidity", "get and print humidity") + ("pressure", "get and print pressure") + ; + try { - BOOST_LOG_TRIVIAL(debug) << "TEST"; - TimeoutSerial serial("/dev/ttyUSB0",115200); - serial.setTimeout(posix_time::seconds(10)); + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help")) { + cout << desc << "\n"; + return 0; + } + + } catch(std::exception& e) { + cerr << "error: " << e.what() << "\n"; + return 1; + } + catch(...) { + cerr << "Exception of unknown type!\n"; + return 1; + } + + try { + BOOST_LOG_TRIVIAL(debug) << "Starting Program on " << port ; + TimeoutSerial serial(port,speed); + serial.setTimeout(posix_time::seconds(5)); serial.setDTR(false); serial.setRTS(false); boost::this_thread::sleep(posix_time::milliseconds(5000)); line = serial.readStringUntil("\n"); trim(line); - cout << line << endl; + BOOST_LOG_TRIVIAL(debug) << line; - serial.writeString("measure\r\n"); - - for (;;) { - line = serial.readStringUntil("\n"); - trim(line); - if (line == "") continue; - // cout << line << endl; + if (vm.count("measure") || vm.count("temperature") || vm.count("pressure") || vm.count("humidity")) { + serial.writeString("measure\r\n"); - split_vector_type SplitVec; // #2: Search for tokens - split( SplitVec, line, is_any_of(" "), token_compress_on ); // SplitVec == { "hello abc","ABC","aBc goodbye" } - - for (vector::iterator t=SplitVec.begin(); t!=SplitVec.end(); ++t) { - split_vector_type kv; - split(kv, *t, is_any_of("="), token_compress_on); - // cout << "kv[0]=" << kv[0] << endl; - if (kv[0] == "temperature") temperature = stof(kv[1]); - if (kv[0] == "humidity") humidity = stof(kv[1]); - if (kv[0] == "pressure") pressure = stof(kv[1]); + for (;;) { + line = serial.readStringUntil("\n"); + trim(line); + if (line == "") continue; + + split_vector_type SplitVec; + split( SplitVec, line, is_any_of(" "), token_compress_on ); + for (vector::iterator t=SplitVec.begin(); t!=SplitVec.end(); ++t) { + split_vector_type kv; + split(kv, *t, is_any_of("="), token_compress_on); + if (kv[0] == "temperature") temperature = stof(kv[1]); + if (kv[0] == "humidity") humidity = stof(kv[1]); + if (kv[0] == "pressure") pressure = stof(kv[1]); + } + + if (pressure > 0.0) break; } - if (pressure > 0.0) break; + if (vm.count("measure")) { + cout << "teplota = " << temperature << endl; + cout << "vlhkost = " << humidity << endl; + cout << "tlak = " << pressure << endl; + } + + if (vm.count("temperature")) { + cout << temperature << endl; + } + + if (vm.count("humidity")) { + cout << humidity << endl; + } + + if (vm.count("pressure")) { + cout << pressure << endl; + } + + return 0; } - cout << "teplota = " << temperature << endl; - cout << "vlhkost = " << humidity << endl; - cout << "tlak = " << pressure << endl; + if (vm.count("capture")) { + serial.writeString("capture\r\n"); + boost::this_thread::sleep(posix_time::milliseconds(100)); - //XModem modem(&serial,dataHandler); + serial.setTimeout(posix_time::milliseconds(500)); - serial.writeString("capture\r\n"); - boost::this_thread::sleep(posix_time::milliseconds(100)); - line = serial.readStringUntil("\r\n"); - cout << line << endl; - line = serial.readStringUntil("\r\n"); - cout << line << endl; - line = serial.readStringUntil("\r\n"); - cout << line << endl; - line = serial.readStringUntil("\r\n"); - cout << line << endl; - // line = serial.readStringUntil("\r\n"); - // cout << line << endl; - - serial.writeString("rb\r\n"); - boost::this_thread::sleep(posix_time::milliseconds(100)); - serial.readChar(1); - serial.readChar(1); - //modem.receive(); - boost::this_thread::sleep(posix_time::milliseconds(100)); - serial.writeString("free\r\n"); + try { + for (;;) { + line = serial.readStringUntil("\r\n"); + cout << line << endl; + } + } catch (...) { + + } + + serial.writeString("rb\r\n"); + boost::this_thread::sleep(posix_time::milliseconds(100)); + serial.readChar(1); + serial.readChar(1); + + modem.setSerialPort(&serial); + modem.setFilePath(path); + modem.setDefaultFileName(filename); + modem.startReceive(); + + boost::this_thread::sleep(posix_time::seconds(1)); + serial.writeString("free\r\n"); + } serial.close(); @@ -170,5 +248,4 @@ int main(int argc, char* argv[]) cout<<"Error: "<