2014-11-26 21:30:25 +00:00
|
|
|
#ifndef slic3r_GCodeSender_hpp_
|
|
|
|
#define slic3r_GCodeSender_hpp_
|
|
|
|
#ifdef BOOST_LIBS
|
|
|
|
|
|
|
|
#include <myinit.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);
|
2014-11-26 21:30:25 +00:00
|
|
|
void send(const std::vector<std::string> &lines);
|
|
|
|
void send(const std::string &s);
|
2014-12-27 21:57:20 +00:00
|
|
|
void disconnect();
|
|
|
|
bool error_status() const;
|
|
|
|
bool is_connected() const;
|
|
|
|
size_t queue_size() const;
|
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;
|
|
|
|
boost::asio::streambuf read_buffer;
|
|
|
|
bool open; // whether the serial socket is connected
|
|
|
|
bool connected; // whether the printer is online
|
|
|
|
bool error;
|
|
|
|
mutable boost::mutex error_mutex;
|
|
|
|
|
|
|
|
mutable boost::mutex queue_mutex;
|
|
|
|
std::queue<std::string> queue;
|
|
|
|
bool can_send;
|
|
|
|
size_t sent;
|
2014-11-26 21:30:25 +00:00
|
|
|
|
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);
|
|
|
|
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
|