2014-11-26 21:30:25 +00:00
|
|
|
#ifndef slic3r_GCodeSender_hpp_
|
|
|
|
#define slic3r_GCodeSender_hpp_
|
|
|
|
#ifdef BOOST_LIBS
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2014-12-27 21:57:20 +00:00
|
|
|
#include <queue>
|
2014-11-26 21:30:25 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <boost/asio.hpp>
|
2014-12-27 21:57:20 +00:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
#include <boost/thread.hpp>
|
2014-11-26 21:30:25 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
namespace asio = boost::asio;
|
|
|
|
|
2014-12-27 21:57:20 +00:00
|
|
|
class GCodeSender : private boost::noncopyable {
|
2014-11-26 21:30:25 +00:00
|
|
|
public:
|
2014-12-31 18:10:46 +00:00
|
|
|
GCodeSender();
|
|
|
|
~GCodeSender();
|
|
|
|
bool connect(std::string devname, unsigned int baud_rate);
|
2015-01-04 17:17:15 +00:00
|
|
|
void send(const std::vector<std::string> &lines, bool priority = false);
|
|
|
|
void send(const std::string &s, bool priority = false);
|
2014-12-27 21:57:20 +00:00
|
|
|
void disconnect();
|
|
|
|
bool error_status() const;
|
|
|
|
bool is_connected() const;
|
2015-11-02 19:34:36 +00:00
|
|
|
bool wait_connected(unsigned int timeout = 3) const;
|
2014-12-27 21:57:20 +00:00
|
|
|
size_t queue_size() const;
|
2015-01-03 22:25:55 +00:00
|
|
|
void pause_queue();
|
|
|
|
void resume_queue();
|
2015-11-08 09:10:54 +00:00
|
|
|
void purge_queue(bool priority = false);
|
2015-01-04 22:18:23 +00:00
|
|
|
std::vector<std::string> purge_log();
|
|
|
|
std::string getT() const;
|
|
|
|
std::string getB() const;
|
2015-11-19 12:17:52 +00:00
|
|
|
void set_DTR(bool on);
|
|
|
|
void reset();
|
2014-11-26 21:30:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
asio::io_service io;
|
|
|
|
asio::serial_port serial;
|
2014-12-27 21:57:20 +00:00
|
|
|
boost::thread background_thread;
|
2016-03-13 17:27:02 +00:00
|
|
|
boost::asio::streambuf read_buffer, write_buffer;
|
2014-12-27 21:57:20 +00:00
|
|
|
bool open; // whether the serial socket is connected
|
|
|
|
bool connected; // whether the printer is online
|
|
|
|
bool error;
|
|
|
|
mutable boost::mutex error_mutex;
|
|
|
|
|
2015-01-04 17:17:15 +00:00
|
|
|
// this mutex guards queue, priqueue, can_send, queue_paused, sent, last_sent
|
2014-12-27 21:57:20 +00:00
|
|
|
mutable boost::mutex queue_mutex;
|
2016-03-13 17:27:02 +00:00
|
|
|
std::queue<std::string> queue;
|
|
|
|
std::list<std::string> priqueue;
|
2014-12-27 21:57:20 +00:00
|
|
|
bool can_send;
|
2015-01-03 22:25:55 +00:00
|
|
|
bool queue_paused;
|
2014-12-27 21:57:20 +00:00
|
|
|
size_t sent;
|
2016-03-13 17:27:02 +00:00
|
|
|
std::vector<std::string> last_sent;
|
2014-11-26 21:30:25 +00:00
|
|
|
|
2015-01-04 22:18:23 +00:00
|
|
|
// this mutex guards log, T, B
|
|
|
|
mutable boost::mutex log_mutex;
|
|
|
|
std::queue<std::string> log;
|
|
|
|
std::string T, B;
|
|
|
|
|
2014-12-31 18:10:46 +00:00
|
|
|
void set_baud_rate(unsigned int baud_rate);
|
2014-12-27 21:57:20 +00:00
|
|
|
void set_error_status(bool e);
|
2015-11-19 12:17:52 +00:00
|
|
|
void do_send();
|
2016-03-13 17:27:02 +00:00
|
|
|
void on_write(const boost::system::error_code& error, size_t bytes_transferred);
|
2014-12-27 21:57:20 +00:00
|
|
|
void do_close();
|
|
|
|
void do_read();
|
|
|
|
void on_read(const boost::system::error_code& error, size_t bytes_transferred);
|
|
|
|
void send();
|
2014-11-26 21:30:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|