25 #include "GrblTester.hpp"
27 #include <logger/Logger.hpp>
29 #include "Exception.hpp"
31 static const std::string s_loggerCat{
"smc:edgegrbltester:sim"};
32 static const std::string s_crnl(
"\r\n");
34 using namespace logger;
35 using namespace std::chrono;
39 const milliseconds GrblTester::defaultExpectTimeout{500};
41 GrblTester::GrblTester(std::unique_ptr<GrblDeviceBase> grblDevice) :
42 m_grblDevice{std::move(grblDevice)}
45 bool GrblTester::expect(
const std::string ®ex,
46 std::chrono::milliseconds timeout)
48 const ccut::Regex re(regex);
49 return expect(re, timeout);
52 bool GrblTester::expect(
const ccut::Regex ®ex,
53 std::chrono::milliseconds timeout)
55 const steady_clock::time_point deadline = steady_clock::now() + timeout;
57 while (steady_clock::now() <= deadline)
59 steady_clock::time_point now = steady_clock::now();
60 const milliseconds remaining = (now < deadline) ?
61 duration_cast<milliseconds>(deadline - now) :
66 m_grblDevice->wait(remaining);
70 error(s_loggerCat) << ex.what();
75 while (m_grblDevice->takeLine(line))
77 if (regex.search(line))
79 debug(s_loggerCat) <<
"<-- " << line;
84 debug(s_loggerCat) <<
"x<- " << line;
91 void GrblTester::sendCmd(
const std::string &command)
93 debug(s_loggerCat) <<
"--> " << command;
94 m_grblDevice->write(command);
95 m_grblDevice->write(s_crnl);
Exception thrown by MotionController in case of issues with command.