diff --git a/.gitignore b/.gitignore index 32a65b8..524bee2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ CMakeCache.txt timeout cmake_install.cmake serial-port/ +lib/ +Ymodem*/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index aa2094d..5eef2a4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,9 @@ project(TEST) ## Target set(CMAKE_CXX_STANDARD 11) -set(TEST_SRCS main.cpp TimeoutSerial.cpp) +set(TEST_SRCS main.cpp TimeoutSerial.cpp XModem.cpp) add_executable(timeout ${TEST_SRCS}) +set(CMAKE_BUILD_TYPE Debug) ## Link libraries set(BOOST_LIBS date_time system) diff --git a/Makefile b/Makefile index 1efcc5a..9555637 100644 --- a/Makefile +++ b/Makefile @@ -150,6 +150,33 @@ TimeoutSerial.cpp.s: $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/TimeoutSerial.cpp.s .PHONY : TimeoutSerial.cpp.s +XModem.o: XModem.cpp.o + +.PHONY : XModem.o + +# target to build an object file +XModem.cpp.o: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/XModem.cpp.o +.PHONY : XModem.cpp.o + +XModem.i: XModem.cpp.i + +.PHONY : XModem.i + +# target to preprocess a source file +XModem.cpp.i: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/XModem.cpp.i +.PHONY : XModem.cpp.i + +XModem.s: XModem.cpp.s + +.PHONY : XModem.s + +# target to generate assembly for a file +XModem.cpp.s: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/XModem.cpp.s +.PHONY : XModem.cpp.s + main.o: main.cpp.o .PHONY : main.o @@ -189,6 +216,9 @@ help: @echo "... TimeoutSerial.o" @echo "... TimeoutSerial.i" @echo "... TimeoutSerial.s" + @echo "... XModem.o" + @echo "... XModem.i" + @echo "... XModem.s" @echo "... main.o" @echo "... main.i" @echo "... main.s" diff --git a/TimeoutSerial.cpp b/TimeoutSerial.cpp index 7337a81..d793cdf 100755 --- a/TimeoutSerial.cpp +++ b/TimeoutSerial.cpp @@ -141,8 +141,11 @@ int TimeoutSerial::readChar(int delay) timeout = posix_time::seconds(delay); try { result = read(1); - return static_cast(result[0]); + std::cerr << std::hex << (uint8_t + )result[0] << endl; + return static_cast(result[0]); } catch (boost::system::system_error& e) { + cerr << "EOF" << endl; return -1; } } diff --git a/XModem.cpp b/XModem.cpp index 0d7d6a8..7ca5c2a 100644 --- a/XModem.cpp +++ b/XModem.cpp @@ -21,7 +21,7 @@ #include #include "XModem.h" -#include "TimeoutSerial.h" + #ifdef UTEST #include "CppUTestExt/MockSupport.h" #endif @@ -32,7 +32,7 @@ const unsigned char XModem::SOH = 1; const unsigned char XModem::EOT = 4; const unsigned char XModem::CAN = 0x18; -const int XModem::receiveDelay=7000; +const int XModem::receiveDelay=7; const int XModem::rcvRetryLimit = 10; @@ -53,7 +53,7 @@ bool XModem::dataAvail(int delay) { if (this->byte != -1) return true; - if ((this->byte = this->recvChar(delay)) != -1) + if ((this->byte = this->serial->readChar(delay)) != -1) return true; else return false; @@ -68,11 +68,11 @@ int XModem::dataRead(int delay) this->byte = -1; return b; } - return this->recvChar(delay); + return this->serial->readChar(delay); } void XModem::dataWrite(char symbol) { - this->sendData(&symbol, 1); + this->serial->write(&symbol, 1); } bool XModem::receiveFrameNo() { @@ -148,7 +148,7 @@ bool XModem::receiveFrames(transfer_t transfer) this->blockNoExt = 1; this->retries = 0; while (1) { - char cmd = this->dataRead(1000); + char cmd = this->dataRead(10); switch(cmd){ case XModem::SOH: if (!this->receiveFrameNo()) { diff --git a/XModem.h b/XModem.h index 442aa42..a091d86 100644 --- a/XModem.h +++ b/XModem.h @@ -16,6 +16,7 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- +#include "TimeoutSerial.h" typedef enum { Crc, diff --git a/build/.cmake/api/v1/query/client-vscode/query.json b/build/.cmake/api/v1/query/client-vscode/query.json new file mode 100644 index 0000000..b9dc05e --- /dev/null +++ b/build/.cmake/api/v1/query/client-vscode/query.json @@ -0,0 +1 @@ +{"requests":[{"kind":"cache","version":2},{"kind":"codemodel","version":2},{"kind":"toolchains","version":1}]} \ No newline at end of file diff --git a/build/.cmake/api/v1/reply/cache-v2-053ee6e25f83c56b3f05.json b/build/.cmake/api/v1/reply/cache-v2-053ee6e25f83c56b3f05.json new file mode 100644 index 0000000..dad5f6e --- /dev/null +++ b/build/.cmake/api/v1/reply/cache-v2-053ee6e25f83c56b3f05.json @@ -0,0 +1,1327 @@ +{ + "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_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 ][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_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_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_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" + } + ], + "kind" : "cache", + "version" : + { + "major" : 2, + "minor" : 0 + } +} diff --git a/build/.cmake/api/v1/reply/codemodel-v2-a67eb6c77230df2253b5.json b/build/.cmake/api/v1/reply/codemodel-v2-a67eb6c77230df2253b5.json new file mode 100644 index 0000000..513008a --- /dev/null +++ b/build/.cmake/api/v1/reply/codemodel-v2-a67eb6c77230df2253b5.json @@ -0,0 +1,59 @@ +{ + "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-6fb942df9d75cf9b39de.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/index-2021-08-22T19-41-54-0321.json b/build/.cmake/api/v1/reply/index-2021-08-22T19-41-54-0321.json new file mode 100644 index 0000000..f854360 --- /dev/null +++ b/build/.cmake/api/v1/reply/index-2021-08-22T19-41-54-0321.json @@ -0,0 +1,94 @@ +{ + "cmake" : + { + "generator" : + { + "name" : "Unix Makefiles" + }, + "paths" : + { + "cmake" : "/usr/bin/cmake", + "cpack" : "/usr/bin/cpack", + "ctest" : "/usr/bin/ctest", + "root" : "/usr/share/cmake-3.16" + }, + "version" : + { + "isDirty" : false, + "major" : 3, + "minor" : 16, + "patch" : 3, + "string" : "3.16.3", + "suffix" : "" + } + }, + "objects" : + [ + { + "jsonFile" : "codemodel-v2-a67eb6c77230df2253b5.json", + "kind" : "codemodel", + "version" : + { + "major" : 2, + "minor" : 0 + } + }, + { + "jsonFile" : "cache-v2-053ee6e25f83c56b3f05.json", + "kind" : "cache", + "version" : + { + "major" : 2, + "minor" : 0 + } + } + ], + "reply" : + { + "client-vscode" : + { + "query.json" : + { + "requests" : + [ + { + "kind" : "cache", + "version" : 2 + }, + { + "kind" : "codemodel", + "version" : 2 + }, + { + "kind" : "toolchains", + "version" : 1 + } + ], + "responses" : + [ + { + "jsonFile" : "cache-v2-053ee6e25f83c56b3f05.json", + "kind" : "cache", + "version" : + { + "major" : 2, + "minor" : 0 + } + }, + { + "jsonFile" : "codemodel-v2-a67eb6c77230df2253b5.json", + "kind" : "codemodel", + "version" : + { + "major" : 2, + "minor" : 0 + } + }, + { + "error" : "unknown request kind 'toolchains'" + } + ] + } + } + } +} diff --git a/build/.cmake/api/v1/reply/target-timeout-Debug-6fb942df9d75cf9b39de.json b/build/.cmake/api/v1/reply/target-timeout-Debug-6fb942df9d75cf9b39de.json new file mode 100644 index 0000000..23d42db --- /dev/null +++ b/build/.cmake/api/v1/reply/target-timeout-Debug-6fb942df9d75cf9b39de.json @@ -0,0 +1,146 @@ +{ + "artifacts" : + [ + { + "path" : "timeout" + } + ], + "backtrace" : 1, + "backtraceGraph" : + { + "commands" : + [ + "add_executable", + "target_link_libraries" + ], + "files" : + [ + "CMakeLists.txt" + ], + "nodes" : + [ + { + "file" : 0 + }, + { + "command" : 0, + "file" : 0, + "line" : 8, + "parent" : 0 + }, + { + "command" : 1, + "file" : 0, + "line" : 14, + "parent" : 0 + } + ] + }, + "compileGroups" : + [ + { + "compileCommandFragments" : + [ + { + "fragment" : "-g " + }, + { + "fragment" : "-std=gnu++11" + } + ], + "defines" : + [ + { + "backtrace" : 2, + "define" : "BOOST_ALL_NO_LIB" + }, + { + "backtrace" : 2, + "define" : "BOOST_DATE_TIME_DYN_LINK" + }, + { + "backtrace" : 2, + "define" : "BOOST_SYSTEM_DYN_LINK" + } + ], + "language" : "CXX", + "sourceIndexes" : + [ + 0, + 1, + 2 + ] + } + ], + "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" + }, + { + "fragment" : "-lpthread", + "role" : "libraries" + } + ], + "language" : "CXX" + }, + "name" : "timeout", + "nameOnDisk" : "timeout", + "paths" : + { + "build" : ".", + "source" : "." + }, + "sourceGroups" : + [ + { + "name" : "Source Files", + "sourceIndexes" : + [ + 0, + 1, + 2 + ] + } + ], + "sources" : + [ + { + "backtrace" : 1, + "compileGroupIndex" : 0, + "path" : "main.cpp", + "sourceGroupIndex" : 0 + }, + { + "backtrace" : 1, + "compileGroupIndex" : 0, + "path" : "TimeoutSerial.cpp", + "sourceGroupIndex" : 0 + }, + { + "backtrace" : 1, + "compileGroupIndex" : 0, + "path" : "XModem.cpp", + "sourceGroupIndex" : 0 + } + ], + "type" : "EXECUTABLE" +} diff --git a/build/Makefile b/build/Makefile new file mode 100644 index 0000000..651af2f --- /dev/null +++ b/build/Makefile @@ -0,0 +1,238 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.16 + +# Default target executed when no arguments are given to make. +default_target: all + +.PHONY : default_target + +# Allow only one "make -f Makefile2" at a time, but pass parallelism. +.NOTPARALLEL: + + +#============================================================================= +# Special targets provided by cmake. + +# Disable implicit rules so canonical targets will work. +.SUFFIXES: + + +# Remove some rules from gmake that .SUFFIXES does not remove. +SUFFIXES = + +.SUFFIXES: .hpux_make_needs_suffix_list + + +# Suppress display of executed commands. +$(VERBOSE).SILENT: + + +# A target that is always out of date. +cmake_force: + +.PHONY : cmake_force + +#============================================================================= +# Set environment variables for the build. + +# The shell in which to execute make rules. +SHELL = /bin/sh + +# The CMake executable. +CMAKE_COMMAND = /usr/bin/cmake + +# The command to remove a file. +RM = /usr/bin/cmake -E remove -f + +# Escaping for special characters. +EQUALS = = + +# The top-level source directory on which CMake was run. +CMAKE_SOURCE_DIR = /home/jaro/serialport-downloader + +# The top-level build directory on which CMake was run. +CMAKE_BINARY_DIR = /home/jaro/serialport-downloader/build + +#============================================================================= +# Targets provided globally by CMake. + +# Special rule for the target rebuild_cache +rebuild_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." + /usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) +.PHONY : rebuild_cache + +# Special rule for the target rebuild_cache +rebuild_cache/fast: rebuild_cache + +.PHONY : rebuild_cache/fast + +# Special rule for the target edit_cache +edit_cache: + @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." + /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. +.PHONY : edit_cache + +# Special rule for the target edit_cache +edit_cache/fast: edit_cache + +.PHONY : edit_cache/fast + +# The main all target +all: cmake_check_build_system + $(CMAKE_COMMAND) -E cmake_progress_start /home/jaro/serialport-downloader/build/CMakeFiles /home/jaro/serialport-downloader/build/CMakeFiles/progress.marks + $(MAKE) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/jaro/serialport-downloader/build/CMakeFiles 0 +.PHONY : all + +# The main clean target +clean: + $(MAKE) -f CMakeFiles/Makefile2 clean +.PHONY : clean + +# The main clean target +clean/fast: clean + +.PHONY : clean/fast + +# Prepare targets for installation. +preinstall: all + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall + +# Prepare targets for installation. +preinstall/fast: + $(MAKE) -f CMakeFiles/Makefile2 preinstall +.PHONY : preinstall/fast + +# clear depends +depend: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 +.PHONY : depend + +#============================================================================= +# Target rules for targets named timeout + +# Build rule for target. +timeout: cmake_check_build_system + $(MAKE) -f CMakeFiles/Makefile2 timeout +.PHONY : timeout + +# fast build rule for target. +timeout/fast: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/build +.PHONY : timeout/fast + +TimeoutSerial.o: TimeoutSerial.cpp.o + +.PHONY : TimeoutSerial.o + +# target to build an object file +TimeoutSerial.cpp.o: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/TimeoutSerial.cpp.o +.PHONY : TimeoutSerial.cpp.o + +TimeoutSerial.i: TimeoutSerial.cpp.i + +.PHONY : TimeoutSerial.i + +# target to preprocess a source file +TimeoutSerial.cpp.i: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/TimeoutSerial.cpp.i +.PHONY : TimeoutSerial.cpp.i + +TimeoutSerial.s: TimeoutSerial.cpp.s + +.PHONY : TimeoutSerial.s + +# target to generate assembly for a file +TimeoutSerial.cpp.s: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/TimeoutSerial.cpp.s +.PHONY : TimeoutSerial.cpp.s + +XModem.o: XModem.cpp.o + +.PHONY : XModem.o + +# target to build an object file +XModem.cpp.o: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/XModem.cpp.o +.PHONY : XModem.cpp.o + +XModem.i: XModem.cpp.i + +.PHONY : XModem.i + +# target to preprocess a source file +XModem.cpp.i: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/XModem.cpp.i +.PHONY : XModem.cpp.i + +XModem.s: XModem.cpp.s + +.PHONY : XModem.s + +# target to generate assembly for a file +XModem.cpp.s: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/XModem.cpp.s +.PHONY : XModem.cpp.s + +main.o: main.cpp.o + +.PHONY : main.o + +# target to build an object file +main.cpp.o: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/main.cpp.o +.PHONY : main.cpp.o + +main.i: main.cpp.i + +.PHONY : main.i + +# target to preprocess a source file +main.cpp.i: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/main.cpp.i +.PHONY : main.cpp.i + +main.s: main.cpp.s + +.PHONY : main.s + +# target to generate assembly for a file +main.cpp.s: + $(MAKE) -f CMakeFiles/timeout.dir/build.make CMakeFiles/timeout.dir/main.cpp.s +.PHONY : main.cpp.s + +# Help Target +help: + @echo "The following are some of the valid targets for this Makefile:" + @echo "... all (the default if no target is provided)" + @echo "... clean" + @echo "... depend" + @echo "... rebuild_cache" + @echo "... edit_cache" + @echo "... timeout" + @echo "... TimeoutSerial.o" + @echo "... TimeoutSerial.i" + @echo "... TimeoutSerial.s" + @echo "... XModem.o" + @echo "... XModem.i" + @echo "... XModem.s" + @echo "... main.o" + @echo "... main.i" + @echo "... main.s" +.PHONY : help + + + +#============================================================================= +# Special targets to cleanup operation of make. + +# Special rule to run CMake to check the build system integrity. +# No rule that depends on this can have commands that come from listfiles +# because they might be regenerated. +cmake_check_build_system: + $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 +.PHONY : cmake_check_build_system + diff --git a/build/compile_commands.json b/build/compile_commands.json new file mode 100644 index 0000000..df3dc6b --- /dev/null +++ b/build/compile_commands.json @@ -0,0 +1,17 @@ +[ +{ + "directory": "/home/jaro/serialport-downloader/build", + "command": "/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_SYSTEM_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_DATE_TIME_DYN_LINK -DBOOST_SYSTEM_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_DATE_TIME_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -g -std=gnu++11 -o CMakeFiles/timeout.dir/XModem.cpp.o -c /home/jaro/serialport-downloader/XModem.cpp", + "file": "/home/jaro/serialport-downloader/XModem.cpp" +} +] \ No newline at end of file diff --git a/main.cpp b/main.cpp index 343a756..eddf5cd 100755 --- a/main.cpp +++ b/main.cpp @@ -9,12 +9,24 @@ #include #include #include "TimeoutSerial.h" +#include "XModem.h" using namespace std; using namespace boost; typedef vector< string > split_vector_type; +bool dataHandler(unsigned long blockNo, char* buffer, int size) +{ + cout << "Block No. = " << blockNo << endl; + for (int i=0 ; i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define xy_dbg(fmt, args...) + +/* Values magic to the protocol */ +#define SOH 0x01 +#define STX 0x02 +#define EOT 0x04 +#define ACK 0x06 +#define BSP 0x08 +#define NAK 0x15 +#define CAN 0x18 + +#define PROTO_XMODEM 0 +#define PROTO_YMODEM 1 +#define PROTO_YMODEM_G 2 +#define MAX_PROTOS 3 + +#define CRC_NONE 0 /* No CRC checking */ +#define CRC_ADD8 1 /* Add of all data bytes */ +#define CRC_CRC16 2 /* CCCIT CRC16 */ +#define MAX_CRCS 3 + +#define MAX_RETRIES 10 +#define MAX_RETRIES_WITH_CRC 5 +#define TIMEOUT_READ (1 * SECOND) +#define TIMEOUT_FLUSH (1 * SECOND) +#define MAX_CAN_BEFORE_ABORT 5 +#define INPUT_FIFO_SIZE (4 * 1024) /* Should always be > 1029 */ + +enum proto_state { + PROTO_STATE_GET_FILENAME = 0, + PROTO_STATE_NEGOCIATE_CRC, + PROTO_STATE_RECEIVE_BODY, + PROTO_STATE_FINISHED_FILE, + PROTO_STATE_FINISHED_XFER, +}; + +/** + * struct xyz_ctxt - context of a x/y modem (g) transfer + * + * @cdev: console device to support *MODEM transfer + * @fifo: fifo to buffer input from serial line + * This is necessary for low hardware FIFOs buffers as UARTs. + * @mode: protocol (XMODEM, YMODEM or YMODEM/G) + * @crc_mode: CRC_NONE, CRC_ADD8 or CRC_CRC16 + * @state: protocol state (as in "state machine") + * @buf: buffer to store the last tranfered buffer chunk + * @filename : filename transmitted by sender (YMODEM* only) + * @fd : file descriptor of the current stored file + * @file_len: length declared by sender (YMODEM* only) + * @nb_received: number of data bytes received since session open + * (this doesn't count resends) + * @total_SOH: number of SOH frames received (128 bytes chunks) + * @total_STX: number of STX frames received (1024 bytes chunks) + * @total_CAN: nubmer of CAN frames received (cancel frames) + */ +struct xyz_ctxt { + struct console_device *cdev; + struct kfifo *fifo; + int mode; + int crc_mode; + enum proto_state state; + char filename[1024]; + int fd; + int file_len; + int nb_received; + int next_blk; + int total_SOH, total_STX, total_CAN, total_retries; +}; + +/** + * struct xy_block - one unitary block of x/y modem (g) transfer + * + * @buf: data buffer + * @len: length of data buffer (can only be 128 or 1024) + * @seq: block sequence number (as in X/Y/YG MODEM protocol) + */ +struct xy_block { + unsigned char buf[1024]; + int len; + int seq; +}; + +/* + * For XMODEM/YMODEM, always try to use the CRC16 versions, called also + * XMODEM/CRC and YMODEM. + * Only fallback to additive CRC (8 bits) if sender doesn't cope with CRC16. + */ +static const char invite_filename_hdr[MAX_PROTOS][MAX_CRCS] = { + { 0, NAK, 'C' }, /* XMODEM */ + { 0, NAK, 'C' }, /* YMODEM */ + { 0, 'G', 'G' }, /* YMODEM-G */ +}; + +static const char invite_file_body[MAX_PROTOS][MAX_CRCS] = { + { 0, NAK, 'C' }, /* XMODEM */ + { 0, NAK, 'C' }, /* YMODEM */ + { 0, 'G', 'G' }, /* YMODEM-G */ +}; + +static const char block_ack[MAX_PROTOS][MAX_CRCS] = { + { 0, ACK, ACK }, /* XMODEM */ + { 0, ACK, ACK }, /* YMODEM */ + { 0, 0, 0 }, /* YMODEM-G */ +}; + +static const char block_nack[MAX_PROTOS][MAX_CRCS] = { + { 0, NAK, NAK }, /* XMODEM */ + { 0, NAK, NAK }, /* YMODEM */ + { 0, 0, 0 }, /* YMODEM-G */ +}; + +static int input_fifo_fill(struct console_device *cdev, struct kfifo *fifo) +{ + while (cdev->tstc(cdev) && kfifo_len(fifo) < INPUT_FIFO_SIZE) + kfifo_putc(fifo, (unsigned char)(cdev->getc(cdev))); + return kfifo_len(fifo); +} + +/* + * This function is optimized to : + * - maximize throughput (ie. read as much as is available in lower layer fifo) + * - minimize latencies (no delay or wait timeout if data available) + * - have a timeout + * This is why standard getc() is not used, and input_fifo_fill() exists. + */ +static int xy_gets(struct console_device *cdev, struct kfifo *fifo, + unsigned char *buf, int len, uint64_t timeout) +{ + int i, rc; + uint64_t start = get_time_ns(); + + for (i = 0, rc = 0; rc >= 0 && i < len; ) { + if (is_timeout(start, timeout)) { + rc = -ETIMEDOUT; + continue; + } + if (input_fifo_fill(cdev, fifo)) + kfifo_getc(fifo, &buf[i++]); + } + + return rc < 0 ? rc : i; +} + +static void xy_putc(struct console_device *cdev, unsigned char c) +{ + cdev->putc(cdev, c); +} + +static void xy_flush(struct console_device *cdev, struct kfifo *fifo) +{ + uint64_t start; + + start = get_time_ns(); + while (cdev->tstc(cdev) && + !is_timeout(start, TIMEOUT_FLUSH)) + cdev->getc(cdev); + mdelay(250); + while (cdev->tstc(cdev) && + !is_timeout(start, TIMEOUT_FLUSH)) + cdev->getc(cdev); + kfifo_reset(fifo); +} + +static int is_xmodem(struct xyz_ctxt *proto) +{ + return proto->mode == PROTO_XMODEM; +} + +static void xy_block_ack(struct xyz_ctxt *proto) +{ + unsigned char c = block_ack[proto->mode][proto->crc_mode]; + + if (c) + xy_putc(proto->cdev, c); +} + +static void xy_block_nack(struct xyz_ctxt *proto) +{ + unsigned char c = block_nack[proto->mode][proto->crc_mode]; + + if (c) + xy_putc(proto->cdev, c); + proto->total_retries++; +} + +static int check_crc(unsigned char *buf, int len, int crc, int crc_mode) +{ + unsigned char crc8 = 0; + uint16_t crc16; + int i; + + switch (crc_mode) { + case CRC_ADD8: + for (i = 0; i < len; i++) + crc8 += buf[i]; + return crc8 == crc ? 0 : -EBADMSG; + case CRC_CRC16: + crc16 = cyg_crc16(buf, len); + xy_dbg("crc16: received = %x, calculated=%x\n", crc, crc16); + return crc16 == crc ? 0 : -EBADMSG; + case CRC_NONE: + return 0; + default: + return -EBADMSG; + } +} + +/** + * xy_read_block - read a X-Modem or Y-Modem(G) block + * @proto: protocol control structure + * @blk: block read + * @timeout: maximal time to get data + * + * This is the pivotal function for block receptions. It attempts to receive one + * block, ie. one 128 bytes or one 1024 bytes block. The received data can also + * be an end of transmission, or a cancel. + * + * Returns : + * >0 : size of the received block + * 0 : last block, ie. end of transmission, ie. EOT + * -EBADMSG : malformed message (ie. sequence bi-bytes are not + * complementary), or CRC check error + * -EILSEQ : block sequence number error wrt previously received block + * -ETIMEDOUT : block not received before timeout passed + * -ECONNABORTED : transfer aborted by sender, ie. CAN + */ +static ssize_t xy_read_block(struct xyz_ctxt *proto, struct xy_block *blk, + uint64_t timeout) +{ + ssize_t rc, data_len = 0; + unsigned char hdr, seqs[2], crcs[2]; + int crc = 0; + bool hdr_found = 0; + uint64_t start = get_time_ns(); + + while (!hdr_found) { + rc = xy_gets(proto->cdev, proto->fifo, &hdr, 1, timeout); + xy_dbg("read 0x%x(%c) -> %d\n", hdr, hdr, rc); + if (rc < 0) + goto out; + if (is_timeout(start, timeout)) + goto timeout; + switch (hdr) { + case SOH: + data_len = 128; + hdr_found = 1; + proto->total_SOH++; + break; + case STX: + data_len = 1024; + hdr_found = 1; + proto->total_STX++; + break; + case CAN: + rc = -ECONNABORTED; + if (proto->total_CAN++ > MAX_CAN_BEFORE_ABORT) + goto out; + break; + case EOT: + rc = 0; + blk->len = 0; + goto out; + default: + break; + } + } + + blk->seq = 0; + rc = xy_gets(proto->cdev, proto->fifo, seqs, 2, timeout); + if (rc < 0) + goto out; + blk->seq = seqs[0]; + if (255 - seqs[0] != seqs[1]) + return -EBADMSG; + + rc = xy_gets(proto->cdev, proto->fifo, blk->buf, data_len, timeout); + if (rc < 0) + goto out; + blk->len = rc; + + switch (proto->crc_mode) { + case CRC_ADD8: + rc = xy_gets(proto->cdev, proto->fifo, crcs, 1, timeout); + crc = crcs[0]; + break; + case CRC_CRC16: + rc = xy_gets(proto->cdev, proto->fifo, crcs, 2, timeout); + crc = (crcs[0] << 8) + crcs[1]; + break; + case CRC_NONE: + rc = 0; + break; + } + if (rc < 0) + goto out; + + rc = check_crc(blk->buf, data_len, crc, proto->crc_mode); + if (rc < 0) + goto out; + return data_len; +timeout: + return -ETIMEDOUT; +out: + return rc; +} + +static int check_blk_seq(struct xyz_ctxt *proto, struct xy_block *blk, + int read_rc) +{ + if (blk->seq == ((proto->next_blk - 1) % 256)) + return -EALREADY; + if (blk->seq != proto->next_blk) + return -EILSEQ; + return read_rc; +} + +static int parse_first_block(struct xyz_ctxt *proto, struct xy_block *blk) +{ + int filename_len; + char *str_num; + + filename_len = strlen(blk->buf); + if (filename_len > blk->len) + return -EINVAL; + strlcpy(proto->filename, blk->buf, sizeof(proto->filename)); + str_num = blk->buf + filename_len + 1; + strsep(&str_num, " "); + proto->file_len = simple_strtoul(blk->buf + filename_len + 1, NULL, 10); + return 1; +} + +static int xy_get_file_header(struct xyz_ctxt *proto) +{ + struct xy_block blk; + int tries, rc = 0; + + memset(&blk, 0, sizeof(blk)); + proto->state = PROTO_STATE_GET_FILENAME; + proto->crc_mode = CRC_CRC16; + for (tries = 0; tries < MAX_RETRIES; tries++) { + xy_putc(proto->cdev, + invite_filename_hdr[proto->mode][proto->crc_mode]); + rc = xy_read_block(proto, &blk, 3 * SECOND); + xy_dbg("read block returned %d\n", rc); + switch (rc) { + case -ECONNABORTED: + goto fail; + case -ETIMEDOUT: + case -EBADMSG: + if (proto->mode != PROTO_YMODEM_G) + xy_flush(proto->cdev, proto->fifo); + break; + case -EALREADY: + default: + proto->next_blk = 1; + xy_block_ack(proto); + proto->state = PROTO_STATE_NEGOCIATE_CRC; + rc = parse_first_block(proto, &blk); + return rc; + } + + if (rc < 0 && tries++ >= MAX_RETRIES_WITH_CRC) + proto->crc_mode = CRC_ADD8; + } + rc = -ETIMEDOUT; +fail: + proto->total_retries += tries; + return rc; +} + +static int xy_await_header(struct xyz_ctxt *proto) +{ + int rc; + + rc = xy_get_file_header(proto); + if (rc < 0) + return rc; + proto->state = PROTO_STATE_NEGOCIATE_CRC; + xy_dbg("header received, filename=%s, file length=%d\n", + proto->filename, proto->file_len); + if (proto->filename[0]) + proto->fd = open(proto->filename, O_WRONLY | O_CREAT); + else + proto->state = PROTO_STATE_FINISHED_XFER; + proto->nb_received = 0; + return rc; +} + +static void xy_finish_file(struct xyz_ctxt *proto) +{ + close(proto->fd); + proto->fd = 0; + proto->state = PROTO_STATE_FINISHED_FILE; +} + +static struct xyz_ctxt *xymodem_open(struct console_device *cdev, + int proto_mode, int xmodem_fd) +{ + struct xyz_ctxt *proto; + + proto = xzalloc(sizeof(struct xyz_ctxt)); + proto->fifo = kfifo_alloc(INPUT_FIFO_SIZE); + proto->mode = proto_mode; + proto->cdev = cdev; + proto->crc_mode = CRC_CRC16; + + if (is_xmodem(proto)) { + proto->fd = xmodem_fd; + proto->state = PROTO_STATE_NEGOCIATE_CRC; + } else { + proto->state = PROTO_STATE_GET_FILENAME; + } + xy_flush(proto->cdev, proto->fifo); + return proto; +} + +static int xymodem_handle(struct xyz_ctxt *proto) +{ + int rc = 0, xfer_max, len = 0, again = 1, remain; + int crc_tries = 0, same_blk_retries = 0; + unsigned char invite; + struct xy_block blk; + + while (again) { + switch (proto->state) { + case PROTO_STATE_GET_FILENAME: + crc_tries = 0; + rc = xy_await_header(proto); + if (rc < 0) + goto fail; + continue; + case PROTO_STATE_FINISHED_FILE: + if (is_xmodem(proto)) + proto->state = PROTO_STATE_FINISHED_XFER; + else + proto->state = PROTO_STATE_GET_FILENAME; + xy_putc(proto->cdev, ACK); + continue; + case PROTO_STATE_FINISHED_XFER: + again = 0; + rc = 0; + goto out; + case PROTO_STATE_NEGOCIATE_CRC: + invite = invite_file_body[proto->mode][proto->crc_mode]; + proto->next_blk = 1; + if (crc_tries++ > MAX_RETRIES_WITH_CRC) + proto->crc_mode = CRC_ADD8; + xy_putc(proto->cdev, invite); + /* Fall through */ + case PROTO_STATE_RECEIVE_BODY: + rc = xy_read_block(proto, &blk, 3 * SECOND); + if (rc > 0) { + rc = check_blk_seq(proto, &blk, rc); + proto->state = PROTO_STATE_RECEIVE_BODY; + } + break; + } + + if (proto->state != PROTO_STATE_RECEIVE_BODY) + continue; + + switch (rc) { + case -ECONNABORTED: + goto fail; + case -ETIMEDOUT: + if (proto->mode == PROTO_YMODEM_G) + goto fail; + xy_flush(proto->cdev, proto->fifo); + xy_block_nack(proto); + break; + case -EBADMSG: + case -EILSEQ: + if (proto->mode == PROTO_YMODEM_G) + goto fail; + xy_flush(proto->cdev, proto->fifo); + xy_block_nack(proto); + break; + case -EALREADY: + xy_block_ack(proto); + break; + case 0: + xy_finish_file(proto); + break; + default: + remain = proto->file_len - proto->nb_received; + if (is_xmodem(proto)) + xfer_max = blk.len; + else + xfer_max = min(blk.len, remain); + rc = write(proto->fd, blk.buf, xfer_max); + proto->next_blk = ((blk.seq + 1) % 256); + proto->nb_received += rc; + len += rc; + xy_block_ack(proto); + break; + } + if (rc < 0) + same_blk_retries++; + else + same_blk_retries = 0; + if (same_blk_retries > MAX_RETRIES) + goto fail; + } +out: + return rc; +fail: + if (proto->fd) + close(proto->fd); + return rc; +} + +static void xymodem_close(struct xyz_ctxt *proto) +{ + xy_flush(proto->cdev, proto->fifo); + printf("\nxyModem - %d(SOH)/%d(STX)/%d(CAN) packets," + " %d retries\n", + proto->total_SOH, proto->total_STX, + proto->total_CAN, proto->total_retries); + kfifo_free(proto->fifo); +} + +int do_load_serial_xmodem(struct console_device *cdev, int fd) +{ + struct xyz_ctxt *proto; + int rc; + + proto = xymodem_open(cdev, PROTO_XMODEM, fd); + do { + rc = xymodem_handle(proto); + } while (rc > 0); + xymodem_close(proto); + return rc < 0 ? rc : 0; +} +EXPORT_SYMBOL(do_load_serial_xmodem); + +int do_load_serial_ymodem(struct console_device *cdev) +{ + struct xyz_ctxt *proto; + int rc; + + proto = xymodem_open(cdev, PROTO_YMODEM, 0); + do { + rc = xymodem_handle(proto); + } while (rc > 0); + xymodem_close(proto); + return rc < 0 ? rc : 0; +} +EXPORT_SYMBOL(do_load_serial_ymodem); + +int do_load_serial_ymodemg(struct console_device *cdev) +{ + struct xyz_ctxt *proto; + int rc; + + proto = xymodem_open(cdev, PROTO_YMODEM_G, 0); + do { + rc = xymodem_handle(proto); + } while (rc > 0); + xymodem_close(proto); + return rc < 0 ? rc : 0; +} +EXPORT_SYMBOL(do_load_serial_ymodemg); diff --git a/ymodem.cpp b/ymodem.cpp new file mode 100644 index 0000000..b1d4314 --- /dev/null +++ b/ymodem.cpp @@ -0,0 +1,671 @@ +/** + ****************************************************************************** + * @file IAP/src/ymodem.c + * @author MCD Application Team + * @version V3.3.0 + * @date 10/15/2010 + * @brief This file provides all the software functions related to the ymodem + * protocol. + ****************************************************************************** + * @copy + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

© COPYRIGHT 2010 STMicroelectronics

+ */ + +#include +#include +#include +#include +#include +#include "ymodem.h" + +uint8_t file_name[FILE_NAME_LENGTH]; +uint32_t FlashDestination = ApplicationAddress; /* Flash user program offset */ +uint16_t PageSize = PAGE_SIZE; +uint32_t EraseCounter = 0x0; +uint32_t NbrOfPage = 0; +FLASH_Status FLASHStatus = FLASH_COMPLETE; +uint32_t RamSource; +extern uint8_t tab_1024[1024]; + +/* Private function prototypes -----------------------------------------------*/ +/* Private functions ---------------------------------------------------------*/ + +/** + * @brief Receive byte from sender + * @param c: Character + * @param timeout: Timeout + * @retval 0: Byte received + * -1: Timeout + */ +static int32_t Receive_Byte (uint8_t *c, uint32_t timeout) +{ + while (timeout-- > 0) + { + if (SerialKeyPressed(c) == 1) + { + return 0; + } + } + return -1; +} + +/** + * @brief Send a byte + * @param c: Character + * @retval 0: Byte sent + */ +static uint32_t Send_Byte (uint8_t c) +{ + SerialPutChar(c); + return 0; +} + +/** + * @brief Receive a packet from sender + * @param data + * @param length + * @param timeout + * 0: end of transmission + * -1: abort by sender + * >0: packet length + * @retval 0: normally return + * -1: timeout or packet error + * 1: abort by user + */ +static int32_t Receive_Packet (uint8_t *data, int32_t *length, uint32_t timeout) +{ + uint16_t i, packet_size; + uint8_t c; + *length = 0; + if (Receive_Byte(&c, timeout) != 0) + { + return -1; + } + switch (c) + { + case SOH: + packet_size = PACKET_SIZE; + break; + case STX: + packet_size = PACKET_1K_SIZE; + break; + case EOT: + return 0; + case CA: + if ((Receive_Byte(&c, timeout) == 0) && (c == CA)) + { + *length = -1; + return 0; + } + else + { + return -1; + } + case ABORT1: + case ABORT2: + return 1; + default: + return -1; + } + *data = c; + for (i = 1; i < (packet_size + PACKET_OVERHEAD); i ++) + { + if (Receive_Byte(data + i, timeout) != 0) + { + return -1; + } + } + if (data[PACKET_SEQNO_INDEX] != ((data[PACKET_SEQNO_COMP_INDEX] ^ 0xff) & 0xff)) + { + return -1; + } + *length = packet_size; + return 0; +} + +/** + * @brief Receive a file using the ymodem protocol + * @param buf: Address of the first byte + * @retval The size of the file + */ +int32_t Ymodem_Receive (uint8_t *buf) +{ + uint8_t packet_data[PACKET_1K_SIZE + PACKET_OVERHEAD], file_size[FILE_SIZE_LENGTH], *file_ptr, *buf_ptr; + int32_t i, j, packet_length, session_done, file_done, packets_received, errors, session_begin, size = 0; + + /* Initialize FlashDestination variable */ + FlashDestination = ApplicationAddress; + + for (session_done = 0, errors = 0, session_begin = 0; ;) + { + for (packets_received = 0, file_done = 0, buf_ptr = buf; ;) + { + switch (Receive_Packet(packet_data, &packet_length, NAK_TIMEOUT)) + { + case 0: + errors = 0; + switch (packet_length) + { + /* Abort by sender */ + case - 1: + Send_Byte(ACK); + return 0; + /* End of transmission */ + case 0: + Send_Byte(ACK); + file_done = 1; + break; + /* Normal packet */ + default: + if ((packet_data[PACKET_SEQNO_INDEX] & 0xff) != (packets_received & 0xff)) + { + Send_Byte(NAK); + } + else + { + if (packets_received == 0) + { + /* Filename packet */ + if (packet_data[PACKET_HEADER] != 0) + { + /* Filename packet has valid data */ + for (i = 0, file_ptr = packet_data + PACKET_HEADER; (*file_ptr != 0) && (i < FILE_NAME_LENGTH);) + { + file_name[i++] = *file_ptr++; + } + file_name[i++] = '\0'; + for (i = 0, file_ptr ++; (*file_ptr != ' ') && (i < FILE_SIZE_LENGTH);) + { + file_size[i++] = *file_ptr++; + } + file_size[i++] = '\0'; + Str2Int(file_size, &size); + + /* Test the size of the image to be sent */ + /* Image size is greater than Flash size */ + if (size > (FLASH_SIZE - 1)) + { + /* End session */ + Send_Byte(CA); + Send_Byte(CA); + return -1; + } + + /* Erase the needed pages where the user application will be loaded */ + /* Define the number of page to be erased */ + NbrOfPage = FLASH_PagesMask(size); + + /* Erase the FLASH pages */ + for (EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) + { + FLASHStatus = FLASH_ErasePage(FlashDestination + (PageSize * EraseCounter)); + } + Send_Byte(ACK); + Send_Byte(CRC16); + } + /* Filename packet is empty, end session */ + else + { + Send_Byte(ACK); + file_done = 1; + session_done = 1; + break; + } + } + /* Data packet */ + else + { + memcpy(buf_ptr, packet_data + PACKET_HEADER, packet_length); + RamSource = (uint32_t)buf; + for (j = 0;(j < packet_length) && (FlashDestination < ApplicationAddress + size);j += 4) + { + /* Program the data received into STM32F10x Flash */ + FLASH_ProgramWord(FlashDestination, *(uint32_t*)RamSource); + + if (*(uint32_t*)FlashDestination != *(uint32_t*)RamSource) + { + /* End session */ + Send_Byte(CA); + Send_Byte(CA); + return -2; + } + FlashDestination += 4; + RamSource += 4; + } + Send_Byte(ACK); + } + packets_received ++; + session_begin = 1; + } + } + break; + case 1: + Send_Byte(CA); + Send_Byte(CA); + return -3; + default: + if (session_begin > 0) + { + errors ++; + } + if (errors > MAX_ERRORS) + { + Send_Byte(CA); + Send_Byte(CA); + return 0; + } + Send_Byte(CRC16); + break; + } + if (file_done != 0) + { + break; + } + } + if (session_done != 0) + { + break; + } + } + return (int32_t)size; +} + +/** + * @brief check response using the ymodem protocol + * @param buf: Address of the first byte + * @retval The size of the file + */ +int32_t Ymodem_CheckResponse(uint8_t c) +{ + return 0; +} + +/** + * @brief Prepare the first block + * @param timeout + * 0: end of transmission + */ +void Ymodem_PrepareIntialPacket(uint8_t *data, const uint8_t* fileName, uint32_t *length) +{ + uint16_t i, j; + uint8_t file_ptr[10]; + + /* Make first three packet */ + data[0] = SOH; + data[1] = 0x00; + data[2] = 0xff; + + /* Filename packet has valid data */ + for (i = 0; (fileName[i] != '\0') && (i < FILE_NAME_LENGTH);i++) + { + data[i + PACKET_HEADER] = fileName[i]; + } + + data[i + PACKET_HEADER] = 0x00; + + Int2Str (file_ptr, *length); + for (j =0, i = i + PACKET_HEADER + 1; file_ptr[j] != '\0' ; ) + { + data[i++] = file_ptr[j++]; + } + + for (j = i; j < PACKET_SIZE + PACKET_HEADER; j++) + { + data[j] = 0; + } +} + +/** + * @brief Prepare the data packet + * @param timeout + * 0: end of transmission + */ +void Ymodem_PreparePacket(uint8_t *SourceBuf, uint8_t *data, uint8_t pktNo, uint32_t sizeBlk) +{ + uint16_t i, size, packetSize; + uint8_t* file_ptr; + + /* Make first three packet */ + packetSize = sizeBlk >= PACKET_1K_SIZE ? PACKET_1K_SIZE : PACKET_SIZE; + size = sizeBlk < packetSize ? sizeBlk :packetSize; + if (packetSize == PACKET_1K_SIZE) + { + data[0] = STX; + } + else + { + data[0] = SOH; + } + data[1] = pktNo; + data[2] = (~pktNo); + file_ptr = SourceBuf; + + /* Filename packet has valid data */ + for (i = PACKET_HEADER; i < size + PACKET_HEADER;i++) + { + data[i] = *file_ptr++; + } + if ( size <= packetSize) + { + for (i = size + PACKET_HEADER; i < packetSize + PACKET_HEADER; i++) + { + data[i] = 0x1A; /* EOF (0x1A) or 0x00 */ + } + } +} + +/** + * @brief Update CRC16 for input byte + * @param CRC input value + * @param input byte + * @retval None + */ +uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte) +{ + uint32_t crc = crcIn; + uint32_t in = byte|0x100; + do + { + crc <<= 1; + in <<= 1; + if(in&0x100) + ++crc; + if(crc&0x10000) + crc ^= 0x1021; + } + while(!(in&0x10000)); + return crc&0xffffu; +} + + +/** + * @brief Cal CRC16 for YModem Packet + * @param data + * @param length + * @retval None + */ +uint16_t Cal_CRC16(const uint8_t* data, uint32_t size) +{ + uint32_t crc = 0; + const uint8_t* dataEnd = data+size; + while(data> 8); + Send_Byte(tempCRC & 0xFF); + } + else + { + tempCheckSum = CalChecksum (&packet_data[3], PACKET_SIZE); + Send_Byte(tempCheckSum); + } + + /* Wait for Ack and 'C' */ + if (Receive_Byte(&receivedC[0], 10000) == 0) + { + if (receivedC[0] == ACK) + { + /* Packet transfered correctly */ + ackReceived = 1; + } + } + else + { + errors++; + } + }while (!ackReceived && (errors < 0x0A)); + + if (errors >= 0x0A) + { + return errors; + } + buf_ptr = buf; + size = sizeFile; + blkNumber = 0x01; + /* Here 1024 bytes package is used to send the packets */ + + + /* Resend packet if NAK for a count of 10 else end of commuincation */ + while (size) + { + /* Prepare next packet */ + Ymodem_PreparePacket(buf_ptr, &packet_data[0], blkNumber, size); + ackReceived = 0; + receivedC[0]= 0; + errors = 0; + do + { + /* Send next packet */ + if (size >= PACKET_1K_SIZE) + { + pktSize = PACKET_1K_SIZE; + + } + else + { + pktSize = PACKET_SIZE; + } + Ymodem_SendPacket(packet_data, pktSize + PACKET_HEADER); + /* Send CRC or Check Sum based on CRC16_F */ + /* Send CRC or Check Sum based on CRC16_F */ + if (CRC16_F) + { + tempCRC = Cal_CRC16(&packet_data[3], pktSize); + Send_Byte(tempCRC >> 8); + Send_Byte(tempCRC & 0xFF); + } + else + { + tempCheckSum = CalChecksum (&packet_data[3], pktSize); + Send_Byte(tempCheckSum); + } + + /* Wait for Ack */ + if ((Receive_Byte(&receivedC[0], 100000) == 0) && (receivedC[0] == ACK)) + { + ackReceived = 1; + if (size > pktSize) + { + buf_ptr += pktSize; + size -= pktSize; + if (blkNumber == (FLASH_IMAGE_SIZE/1024)) + { + return 0xFF; /* error */ + } + else + { + blkNumber++; + } + } + else + { + buf_ptr += pktSize; + size = 0; + } + } + else + { + errors++; + } + }while(!ackReceived && (errors < 0x0A)); + /* Resend packet if NAK for a count of 10 else end of commuincation */ + + if (errors >= 0x0A) + { + return errors; + } + + } + ackReceived = 0; + receivedC[0] = 0x00; + errors = 0; + do + { + Send_Byte(EOT); + /* Send (EOT); */ + /* Wait for Ack */ + if ((Receive_Byte(&receivedC[0], 10000) == 0) && receivedC[0] == ACK) + { + ackReceived = 1; + } + else + { + errors++; + } + }while (!ackReceived && (errors < 0x0A)); + + if (errors >= 0x0A) + { + return errors; + } + + /* Last packet preparation */ + ackReceived = 0; + receivedC[0] = 0x00; + errors = 0; + + packet_data[0] = SOH; + packet_data[1] = 0; + packet_data [2] = 0xFF; + + for (i = PACKET_HEADER; i < (PACKET_SIZE + PACKET_HEADER); i++) + { + packet_data [i] = 0x00; + } + + do + { + /* Send Packet */ + Ymodem_SendPacket(packet_data, PACKET_SIZE + PACKET_HEADER); + /* Send CRC or Check Sum based on CRC16_F */ + tempCRC = Cal_CRC16(&packet_data[3], PACKET_SIZE); + Send_Byte(tempCRC >> 8); + Send_Byte(tempCRC & 0xFF); + + /* Wait for Ack and 'C' */ + if (Receive_Byte(&receivedC[0], 10000) == 0) + { + if (receivedC[0] == ACK) + { + /* Packet transfered correctly */ + ackReceived = 1; + } + } + else + { + errors++; + } + + }while (!ackReceived && (errors < 0x0A)); + /* Resend packet if NAK for a count of 10 else end of commuincation */ + if (errors >= 0x0A) + { + return errors; + } + + do + { + Send_Byte(EOT); + /* Send (EOT); */ + /* Wait for Ack */ + if ((Receive_Byte(&receivedC[0], 10000) == 0) && receivedC[0] == ACK) + { + ackReceived = 1; + } + else + { + errors++; + } + }while (!ackReceived && (errors < 0x0A)); + + if (errors >= 0x0A) + { + return errors; + } + return 0; /* file trasmitted successfully */ +} + +/** + * @} + */ + +/*******************(C)COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ diff --git a/ymodem.h b/ymodem.h new file mode 100644 index 0000000..ee59de4 --- /dev/null +++ b/ymodem.h @@ -0,0 +1,63 @@ +/** + ****************************************************************************** + * @file IAP/inc/ymodem.h + * @author MCD Application Team + * @version V3.3.0 + * @date 10/15/2010 + * @brief This file provides all the software function headers of the ymodem.c + * file. + ****************************************************************************** + * @copy + * + * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS + * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE + * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY + * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING + * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE + * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. + * + *

© COPYRIGHT 2010 STMicroelectronics

+ */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef _YMODEM_H_ +#define _YMODEM_H_ + +/* Includes ------------------------------------------------------------------*/ + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +#define PACKET_SEQNO_INDEX (1) +#define PACKET_SEQNO_COMP_INDEX (2) + +#define PACKET_HEADER (3) +#define PACKET_TRAILER (2) +#define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER) +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) + +#define FILE_NAME_LENGTH (256) +#define FILE_SIZE_LENGTH (16) + +#define SOH (0x01) /* start of 128-byte data packet */ +#define STX (0x02) /* start of 1024-byte data packet */ +#define EOT (0x04) /* end of transmission */ +#define ACK (0x06) /* acknowledge */ +#define NAK (0x15) /* negative acknowledge */ +#define CA (0x18) /* two of these in succession aborts transfer */ +#define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */ + +#define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ +#define ABORT2 (0x61) /* 'a' == 0x61, abort by user */ + +#define NAK_TIMEOUT (0x100000) +#define MAX_ERRORS (5) + +/* Exported macro ------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------- */ +int32_t Ymodem_Receive (uint8_t *); +uint8_t Ymodem_Transmit (uint8_t *,const uint8_t* , uint32_t ); + +#endif /* _YMODEM_H_ */ + +/*******************(C)COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/