2023-04-27 15:53:44 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
|
|
namespace grbl {
|
|
|
|
|
|
|
|
|
|
struct transport;
|
|
|
|
|
|
|
|
|
|
struct transport_callbacks {
|
|
|
|
|
virtual void on_connected(transport*) = 0;
|
|
|
|
|
virtual void on_disconnected(transport*) = 0;
|
|
|
|
|
virtual void on_line_received(std::string line, transport* ) = 0;
|
2023-04-27 18:10:48 +03:00
|
|
|
virtual void on_banner(std::string version, transport* ) = 0;
|
2023-04-27 15:53:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct transport {
|
|
|
|
|
virtual void open(transport_callbacks& cb) = 0;
|
|
|
|
|
virtual void close() = 0;
|
|
|
|
|
virtual void send(std::string line) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct tcp_transport : public transport {
|
|
|
|
|
virtual ~tcp_transport();
|
|
|
|
|
tcp_transport(std::string address, uint16_t port);
|
|
|
|
|
|
|
|
|
|
void open(transport_callbacks& cb) override;
|
|
|
|
|
void close() override;
|
|
|
|
|
void send(std::string line) override;
|
|
|
|
|
|
2023-04-27 18:10:48 +03:00
|
|
|
void request_realtime_report();
|
|
|
|
|
|
|
|
|
|
void request_cycle_start();
|
|
|
|
|
|
|
|
|
|
void request_feed_hold();
|
|
|
|
|
|
|
|
|
|
void parser_state_report();
|
|
|
|
|
|
2023-04-27 15:53:44 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
void worker();
|
|
|
|
|
|
|
|
|
|
std::string ip;
|
|
|
|
|
uint16_t port;
|
|
|
|
|
transport_callbacks *listener = nullptr;
|
|
|
|
|
int fd = -1;
|
|
|
|
|
volatile bool is_connected = false;
|
|
|
|
|
std::thread live_check_thread;
|
|
|
|
|
std::queue<std::string> send_queue;
|
|
|
|
|
volatile bool should_quit = false;
|
2023-04-27 18:10:48 +03:00
|
|
|
static bool is_empty_line(const std::string& line);
|
|
|
|
|
|
|
|
|
|
void send_single_char_command(uint8_t data) const;
|
2023-04-27 15:53:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|