First usable version

This commit is contained in:
2021-08-26 18:48:27 +02:00
parent 1b64b4de81
commit ca0fdd3428
10 changed files with 172 additions and 1786 deletions

View File

@@ -5,6 +5,7 @@
#include <boost/bind.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/log/trivial.hpp>
#include "TimeoutSerial.h"
using namespace std;
@@ -35,6 +36,11 @@ void YmodemFileReceive::setFilePath(const string &path)
filePath = path + "/";
}
void YmodemFileReceive::setDefaultFileName(const string &file)
{
defaultFileName = file;
}
void YmodemFileReceive::setSerialPort(TimeoutSerial *port)
{
serialPort = port;
@@ -50,8 +56,13 @@ bool YmodemFileReceive::startReceive()
progress = 0;
status = StatusEstablish;
io.run();
BOOST_LOG_TRIVIAL(debug) << "Statring receive";
serialPort->setTimeout(posix_time::seconds(0));
readTimer.expires_from_now(boost::posix_time::millisec(READ_TIME_OUT));
readTimer.async_wait(boost::bind(&YmodemFileReceive::readTimeOut,this,_1));
io.run();
return true;
}
@@ -75,7 +86,8 @@ Ymodem::Status YmodemFileReceive::getReceiveStatus()
void YmodemFileReceive::readTimeOut(const boost::system::error_code& e)
{
readTimer.cancel();
BOOST_LOG_TRIVIAL(debug) << "Read timeout";
receive();
@@ -89,7 +101,7 @@ void YmodemFileReceive::readTimeOut(const boost::system::error_code& e)
void YmodemFileReceive::writeTimeOut(const boost::system::error_code& e)
{
writeTimer.cancel();
serialPort->close();
//serialPort->close();
receiveStatus(status);
}
@@ -117,12 +129,19 @@ Ymodem::Code YmodemFileReceive::callback(Status status, uint8_t *buff, uint32_t
size[j] = buff[i];
}
fileName = name;
if (defaultFileName != "") {
fileName = defaultFileName;
} else {
fileName = name;
}
string file_desc(size);
string sizeStr = file_desc.substr(0,file_desc.find_first_of(' '));
fileSize = stol(sizeStr);
fileCount = 0;
BOOST_LOG_TRIVIAL(debug) << "File open: " << filePath + fileName ;
file.open(filePath + fileName, ios::out | ios::binary);
if(file.is_open() == true)