23 #include "MGrblDeviceWrapper.hpp"
25 #include <logger/Logger.hpp>
27 using namespace logger;
31 static const std::string s_loggerCat{
"smc:grbl:mgrbldevice"};
33 MGrblDeviceWrapper::MGrblDeviceWrapper(
35 const std::shared_ptr<grbl::GrblDeviceBase> &device) :
40 void MGrblDeviceWrapper::read()
44 void MGrblDeviceWrapper::write(
const std::string &data)
46 warning(s_loggerCat) <<
"raw write called on MGrblDeviceWrapper";
47 m_device->write(data);
50 grbl::ErrorCode MGrblDeviceWrapper::send(
51 const std::string &cmd,
52 std::function<
bool(
const std::string &)> msg,
53 const std::chrono::milliseconds &timeout)
55 char id =
static_cast<char>(
'0' + m_instance);
57 return m_device->send(
59 [
this, msg,
id](
const std::string &line) {
60 if (!line.empty() && line[0] ==
id)
61 return msg(line.substr(1));
66 return m_device->send(
id + cmd, {}, timeout);
69 grbl::ErrorCode MGrblDeviceWrapper::sendRealtime(
70 const std::string &cmd,
71 std::function<
bool(
const std::string &)> msg,
72 const std::chrono::milliseconds &timeout)
74 char id =
static_cast<char>(
'0' + m_instance);
76 return m_device->sendRealtime(
78 [
this, msg,
id](
const std::string &line) {
79 if (!line.empty() && line[0] ==
id)
80 return msg(line.substr(1));
85 return m_device->sendRealtime(
id + cmd, {}, timeout);
88 bool MGrblDeviceWrapper::wait(
const std::chrono::milliseconds &timeout)
90 return m_device->wait(timeout);
93 void MGrblDeviceWrapper::wake()