Dump serial messages to file in order to debug communication issues
This commit is contained in:
parent
f5326c393a
commit
83c91a3538
1 changed files with 23 additions and 0 deletions
|
@ -19,6 +19,12 @@
|
||||||
#include <linux/serial.h>
|
#include <linux/serial.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//#define DEBUG_SERIAL
|
||||||
|
#ifdef DEBUG_SERIAL
|
||||||
|
#include <fstream>
|
||||||
|
std::fstream fs;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
namespace asio = boost::asio;
|
namespace asio = boost::asio;
|
||||||
|
@ -61,6 +67,11 @@ GCodeSender::connect(std::string devname, unsigned int baud_rate)
|
||||||
this->open = true;
|
this->open = true;
|
||||||
this->reset();
|
this->reset();
|
||||||
|
|
||||||
|
/* Initialize debugger */
|
||||||
|
#ifdef DEBUG_SERIAL
|
||||||
|
fs.open("serial.txt", std::fstream::out | std::fstream::trunc);
|
||||||
|
#endif
|
||||||
|
|
||||||
// this gives some work to the io_service before it is started
|
// this gives some work to the io_service before it is started
|
||||||
// (post() runs the supplied function in its thread)
|
// (post() runs the supplied function in its thread)
|
||||||
this->io.post(boost::bind(&GCodeSender::do_read, this));
|
this->io.post(boost::bind(&GCodeSender::do_read, this));
|
||||||
|
@ -131,6 +142,10 @@ GCodeSender::disconnect()
|
||||||
"Error while closing the device"));
|
"Error while closing the device"));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef DEBUG_SERIAL
|
||||||
|
fs.close();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -285,6 +300,10 @@ GCodeSender::on_read(const boost::system::error_code& error,
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(is, line);
|
std::getline(is, line);
|
||||||
if (!line.empty()) {
|
if (!line.empty()) {
|
||||||
|
#ifdef DEBUG_SERIAL
|
||||||
|
fs << "<< " << line;
|
||||||
|
#endif
|
||||||
|
|
||||||
// note that line might contain \r at its end
|
// note that line might contain \r at its end
|
||||||
// parse incoming line
|
// parse incoming line
|
||||||
if (!this->connected
|
if (!this->connected
|
||||||
|
@ -440,6 +459,10 @@ GCodeSender::do_send(const std::string &line)
|
||||||
|
|
||||||
this->last_sent = line;
|
this->last_sent = line;
|
||||||
this->can_send = false;
|
this->can_send = false;
|
||||||
|
|
||||||
|
#ifdef DEBUG_SERIAL
|
||||||
|
fs << ">> " << full_line;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue