First usable version
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -6,4 +6,6 @@ cmake_install.cmake
|
|||||||
serial-port/
|
serial-port/
|
||||||
lib/
|
lib/
|
||||||
Ymodem*/
|
Ymodem*/
|
||||||
build/
|
build/*
|
||||||
|
*.log
|
||||||
|
*.jpg
|
||||||
@@ -10,7 +10,7 @@ add_executable(timeout ${TEST_SRCS})
|
|||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
|
||||||
## Link libraries
|
## 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)
|
find_package(Boost COMPONENTS ${BOOST_LIBS} REQUIRED)
|
||||||
target_link_libraries(timeout ${Boost_LIBRARIES})
|
target_link_libraries(timeout ${Boost_LIBRARIES})
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|||||||
11
Ymodem.cpp
11
Ymodem.cpp
@@ -29,6 +29,11 @@
|
|||||||
/* Header includes -----------------------------------------------------------*/
|
/* Header includes -----------------------------------------------------------*/
|
||||||
#include "Ymodem.h"
|
#include "Ymodem.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <boost/log/core.hpp>
|
||||||
|
#include <boost/log/common.hpp>
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
|
|
||||||
/* Macro definitions ---------------------------------------------------------*/
|
/* Macro definitions ---------------------------------------------------------*/
|
||||||
/* Type definitions ----------------------------------------------------------*/
|
/* Type definitions ----------------------------------------------------------*/
|
||||||
@@ -130,6 +135,7 @@ void Ymodem::receive()
|
|||||||
{
|
{
|
||||||
case StageNone:
|
case StageNone:
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "receiveStageNone";
|
||||||
receiveStageNone();
|
receiveStageNone();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -137,6 +143,8 @@ void Ymodem::receive()
|
|||||||
|
|
||||||
case StageEstablishing:
|
case StageEstablishing:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "receiveStageEstablishing";
|
||||||
receiveStageEstablishing();
|
receiveStageEstablishing();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -144,6 +152,7 @@ void Ymodem::receive()
|
|||||||
|
|
||||||
case StageEstablished:
|
case StageEstablished:
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "receiveStageEstablished";
|
||||||
receiveStageEstablished();
|
receiveStageEstablished();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -151,6 +160,7 @@ void Ymodem::receive()
|
|||||||
|
|
||||||
case StageTransmitting:
|
case StageTransmitting:
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "receiveStageTransmitting";
|
||||||
receiveStageTransmitting();
|
receiveStageTransmitting();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -158,6 +168,7 @@ void Ymodem::receive()
|
|||||||
|
|
||||||
case StageFinishing:
|
case StageFinishing:
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "receiveStageFinishing";
|
||||||
receiveStageFinishing();
|
receiveStageFinishing();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
#include <boost/log/trivial.hpp>
|
||||||
#include "TimeoutSerial.h"
|
#include "TimeoutSerial.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -35,6 +36,11 @@ void YmodemFileReceive::setFilePath(const string &path)
|
|||||||
filePath = path + "/";
|
filePath = path + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YmodemFileReceive::setDefaultFileName(const string &file)
|
||||||
|
{
|
||||||
|
defaultFileName = file;
|
||||||
|
}
|
||||||
|
|
||||||
void YmodemFileReceive::setSerialPort(TimeoutSerial *port)
|
void YmodemFileReceive::setSerialPort(TimeoutSerial *port)
|
||||||
{
|
{
|
||||||
serialPort = port;
|
serialPort = port;
|
||||||
@@ -50,8 +56,13 @@ bool YmodemFileReceive::startReceive()
|
|||||||
progress = 0;
|
progress = 0;
|
||||||
status = StatusEstablish;
|
status = StatusEstablish;
|
||||||
|
|
||||||
io.run();
|
BOOST_LOG_TRIVIAL(debug) << "Statring receive";
|
||||||
|
|
||||||
serialPort->setTimeout(posix_time::seconds(0));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +86,8 @@ Ymodem::Status YmodemFileReceive::getReceiveStatus()
|
|||||||
|
|
||||||
void YmodemFileReceive::readTimeOut(const boost::system::error_code& e)
|
void YmodemFileReceive::readTimeOut(const boost::system::error_code& e)
|
||||||
{
|
{
|
||||||
readTimer.cancel();
|
BOOST_LOG_TRIVIAL(debug) << "Read timeout";
|
||||||
|
|
||||||
|
|
||||||
receive();
|
receive();
|
||||||
|
|
||||||
@@ -89,7 +101,7 @@ void YmodemFileReceive::readTimeOut(const boost::system::error_code& e)
|
|||||||
void YmodemFileReceive::writeTimeOut(const boost::system::error_code& e)
|
void YmodemFileReceive::writeTimeOut(const boost::system::error_code& e)
|
||||||
{
|
{
|
||||||
writeTimer.cancel();
|
writeTimer.cancel();
|
||||||
serialPort->close();
|
//serialPort->close();
|
||||||
receiveStatus(status);
|
receiveStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,12 +129,19 @@ Ymodem::Code YmodemFileReceive::callback(Status status, uint8_t *buff, uint32_t
|
|||||||
size[j] = buff[i];
|
size[j] = buff[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName = name;
|
if (defaultFileName != "") {
|
||||||
|
fileName = defaultFileName;
|
||||||
|
} else {
|
||||||
|
fileName = name;
|
||||||
|
}
|
||||||
string file_desc(size);
|
string file_desc(size);
|
||||||
string sizeStr = file_desc.substr(0,file_desc.find_first_of(' '));
|
string sizeStr = file_desc.substr(0,file_desc.find_first_of(' '));
|
||||||
fileSize = stol(sizeStr);
|
fileSize = stol(sizeStr);
|
||||||
fileCount = 0;
|
fileCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "File open: " << filePath + fileName ;
|
||||||
|
|
||||||
file.open(filePath + fileName, ios::out | ios::binary);
|
file.open(filePath + fileName, ios::out | ios::binary);
|
||||||
|
|
||||||
if(file.is_open() == true)
|
if(file.is_open() == true)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ public:
|
|||||||
~YmodemFileReceive();
|
~YmodemFileReceive();
|
||||||
|
|
||||||
void setFilePath(const string &path);
|
void setFilePath(const string &path);
|
||||||
|
void setDefaultFileName(const string &path);
|
||||||
|
|
||||||
void setSerialPort(TimeoutSerial *port);
|
void setSerialPort(TimeoutSerial *port);
|
||||||
TimeoutSerial *getSerialPort();
|
TimeoutSerial *getSerialPort();
|
||||||
@@ -52,6 +53,7 @@ private:
|
|||||||
Status status;
|
Status status;
|
||||||
string filePath;
|
string filePath;
|
||||||
string fileName;
|
string fileName;
|
||||||
|
string defaultFileName = "";
|
||||||
uint64_t fileSize;
|
uint64_t fileSize;
|
||||||
uint64_t fileCount;
|
uint64_t fileCount;
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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"
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"directory": "/home/jaro/serialport-downloader/build",
|
"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"
|
"file": "/home/jaro/serialport-downloader/main.cpp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"directory": "/home/jaro/serialport-downloader/build",
|
"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"
|
"file": "/home/jaro/serialport-downloader/TimeoutSerial.cpp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"directory": "/home/jaro/serialport-downloader/build",
|
"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"
|
"file": "/home/jaro/serialport-downloader/Ymodem.cpp"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"directory": "/home/jaro/serialport-downloader/build",
|
"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"
|
"file": "/home/jaro/serialport-downloader/YmodemFileReceive.cpp"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
179
main.cpp
179
main.cpp
@@ -21,19 +21,38 @@
|
|||||||
#include <boost/parameter/keyword.hpp>
|
#include <boost/parameter/keyword.hpp>
|
||||||
#include <boost/log/detail/config.hpp>
|
#include <boost/log/detail/config.hpp>
|
||||||
#include <boost/log/support/date_time.hpp>
|
#include <boost/log/support/date_time.hpp>
|
||||||
|
#include <boost/log/sources/severity_logger.hpp>
|
||||||
|
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
#include "TimeoutSerial.h"
|
#include "TimeoutSerial.h"
|
||||||
|
#include "YmodemFileReceive.h"
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
typedef vector< string > split_vector_type;
|
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)
|
bool dataHandler(unsigned long blockNo, char* buffer, int size)
|
||||||
{
|
{
|
||||||
cout << "Block No. = " << blockNo << endl;
|
cout << "Block No. = " << blockNo << endl;
|
||||||
@@ -79,10 +98,11 @@ static void init_log(void)
|
|||||||
/* console sink */
|
/* console sink */
|
||||||
auto consoleSink = boost::log::add_console_log(std::clog);
|
auto consoleSink = boost::log::add_console_log(std::clog);
|
||||||
consoleSink->set_formatter(logFmt);
|
consoleSink->set_formatter(logFmt);
|
||||||
|
consoleSink->set_filter(severity >= warning);
|
||||||
/* fs sink */
|
/* fs sink */
|
||||||
auto fsSink = boost::log::add_file_log(
|
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::rotation_size = 10 * 1024 * 1024,
|
||||||
boost::log::keywords::min_free_space = 30 * 1024 * 1024,
|
boost::log::keywords::min_free_space = 30 * 1024 * 1024,
|
||||||
boost::log::keywords::open_mode = std::ios_base::app);
|
boost::log::keywords::open_mode = std::ios_base::app);
|
||||||
@@ -94,74 +114,132 @@ static void init_log(void)
|
|||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
string line;
|
string line;
|
||||||
|
YmodemFileReceive modem;
|
||||||
float temperature = NAN;
|
float temperature = NAN;
|
||||||
float humidity= NAN;
|
float humidity= NAN;
|
||||||
float pressure = NAN;
|
float pressure = NAN;
|
||||||
|
po::variables_map vm;
|
||||||
|
std::string port,path,filename;
|
||||||
|
int speed;
|
||||||
|
|
||||||
init_log();
|
init_log();
|
||||||
|
|
||||||
|
po::options_description desc("Allowed options");
|
||||||
|
desc.add_options()
|
||||||
|
("help", "produce help message")
|
||||||
|
("measure", "get and print values")
|
||||||
|
("verbose", po::value<string>()->implicit_value("0"), "verbosity level")
|
||||||
|
("file", po::value<string>(&filename)->default_value("camera.jpg"),"filename of capture filename")
|
||||||
|
("path", po::value<string>(&path)->default_value("/tmp"),"directory for file of capture")
|
||||||
|
("capture", "capture photo of camera")
|
||||||
|
("port", po::value<string>(&port)->default_value("/dev/ttyUSB0"), "port to read from")
|
||||||
|
("speed", po::value<int>(&speed)->default_value(115200), "speed read from port")
|
||||||
|
("temperature", "get and print temprature")
|
||||||
|
("humidity", "get and print humidity")
|
||||||
|
("pressure", "get and print pressure")
|
||||||
|
;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "TEST";
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||||
TimeoutSerial serial("/dev/ttyUSB0",115200);
|
po::notify(vm);
|
||||||
serial.setTimeout(posix_time::seconds(10));
|
|
||||||
|
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.setDTR(false);
|
||||||
serial.setRTS(false);
|
serial.setRTS(false);
|
||||||
boost::this_thread::sleep(posix_time::milliseconds(5000));
|
boost::this_thread::sleep(posix_time::milliseconds(5000));
|
||||||
|
|
||||||
line = serial.readStringUntil("\n");
|
line = serial.readStringUntil("\n");
|
||||||
trim(line);
|
trim(line);
|
||||||
cout << line << endl;
|
BOOST_LOG_TRIVIAL(debug) << line;
|
||||||
|
|
||||||
serial.writeString("measure\r\n");
|
if (vm.count("measure") || vm.count("temperature") || vm.count("pressure") || vm.count("humidity")) {
|
||||||
|
serial.writeString("measure\r\n");
|
||||||
for (;;) {
|
|
||||||
line = serial.readStringUntil("\n");
|
|
||||||
trim(line);
|
|
||||||
if (line == "") continue;
|
|
||||||
// cout << line << endl;
|
|
||||||
|
|
||||||
split_vector_type SplitVec; // #2: Search for tokens
|
for (;;) {
|
||||||
split( SplitVec, line, is_any_of(" "), token_compress_on ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
|
line = serial.readStringUntil("\n");
|
||||||
|
trim(line);
|
||||||
for (vector<string>::iterator t=SplitVec.begin(); t!=SplitVec.end(); ++t) {
|
if (line == "") continue;
|
||||||
split_vector_type kv;
|
|
||||||
split(kv, *t, is_any_of("="), token_compress_on);
|
split_vector_type SplitVec;
|
||||||
// cout << "kv[0]=" << kv[0] << endl;
|
split( SplitVec, line, is_any_of(" "), token_compress_on );
|
||||||
if (kv[0] == "temperature") temperature = stof(kv[1]);
|
for (vector<string>::iterator t=SplitVec.begin(); t!=SplitVec.end(); ++t) {
|
||||||
if (kv[0] == "humidity") humidity = stof(kv[1]);
|
split_vector_type kv;
|
||||||
if (kv[0] == "pressure") pressure = stof(kv[1]);
|
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;
|
if (vm.count("capture")) {
|
||||||
cout << "vlhkost = " << humidity << endl;
|
serial.writeString("capture\r\n");
|
||||||
cout << "tlak = " << pressure << endl;
|
boost::this_thread::sleep(posix_time::milliseconds(100));
|
||||||
|
|
||||||
//XModem modem(&serial,dataHandler);
|
serial.setTimeout(posix_time::milliseconds(500));
|
||||||
|
|
||||||
serial.writeString("capture\r\n");
|
try {
|
||||||
boost::this_thread::sleep(posix_time::milliseconds(100));
|
for (;;) {
|
||||||
line = serial.readStringUntil("\r\n");
|
line = serial.readStringUntil("\r\n");
|
||||||
cout << line << endl;
|
cout << line << endl;
|
||||||
line = serial.readStringUntil("\r\n");
|
}
|
||||||
cout << line << endl;
|
} catch (...) {
|
||||||
line = serial.readStringUntil("\r\n");
|
|
||||||
cout << line << endl;
|
}
|
||||||
line = serial.readStringUntil("\r\n");
|
|
||||||
cout << line << endl;
|
serial.writeString("rb\r\n");
|
||||||
// line = serial.readStringUntil("\r\n");
|
boost::this_thread::sleep(posix_time::milliseconds(100));
|
||||||
// cout << line << endl;
|
serial.readChar(1);
|
||||||
|
serial.readChar(1);
|
||||||
serial.writeString("rb\r\n");
|
|
||||||
boost::this_thread::sleep(posix_time::milliseconds(100));
|
modem.setSerialPort(&serial);
|
||||||
serial.readChar(1);
|
modem.setFilePath(path);
|
||||||
serial.readChar(1);
|
modem.setDefaultFileName(filename);
|
||||||
//modem.receive();
|
modem.startReceive();
|
||||||
boost::this_thread::sleep(posix_time::milliseconds(100));
|
|
||||||
serial.writeString("free\r\n");
|
boost::this_thread::sleep(posix_time::seconds(1));
|
||||||
|
serial.writeString("free\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
serial.close();
|
serial.close();
|
||||||
|
|
||||||
@@ -170,5 +248,4 @@ int main(int argc, char* argv[])
|
|||||||
cout<<"Error: "<<e.what()<<endl;
|
cout<<"Error: "<<e.what()<<endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user