MotionLib  1.0.0
SamBuCa motion library
EdgeGrblDevice.cpp
1 /*
2 ** Copyright (C) 2022 CERN
3 **
4 ** This software is provided 'as-is', without any express or implied
5 ** warranty. In no event will the authors be held liable for any damages
6 ** arising from the use of this software.
7 **
8 ** Permission is granted to anyone to use this software for any purpose,
9 ** including commercial applications, and to alter it and redistribute it
10 ** freely, subject to the following restrictions:
11 **
12 ** 1. The origin of this software must not be misrepresented; you must not
13 ** claim that you wrote the original software. If you use this software
14 ** in a product, an acknowledgment in the product documentation would be
15 ** appreciated but is not required.
16 ** 2. Altered source versions must be plainly marked as such, and must not be
17 ** misrepresented as being the original software.
18 ** 3. This notice may not be removed or altered from any source distribution.
19 **
20 ** Created on: 2022-09-22T18:55:32
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #include "EdgeGrblDevice.hpp"
25 
26 #include <chrono>
27 #include <cstdlib>
28 
29 #include <ccut/Regex.hpp>
30 #include <logger/Logger.hpp>
31 
32 #include "Exception.hpp"
33 
34 using namespace logger;
35 using namespace std::chrono;
36 
37 static const ccut::Regex s_grblInit("^GrblHAL.*$");
38 
39 namespace edge {
40 
41 EdgeGrblDevice::EdgeGrblDevice(int lun, const std::string &driverPath)
42 {
43  setenv("GRBL_SIM_INSTANCES", "0", 1);
44  init(lun, driverPath);
45  if (send(
46  std::string(),
47  [](const std::string &msg) {
48  notice(loggerCat) << "<--(init) " << msg;
49  if (s_grblInit.search(msg))
50  throw grbl::ErrorCode{0};
51  return true;
52  },
53  milliseconds{5000}) != grbl::ErrorCode{0})
54  {
55  error(loggerCat) << "Grbl welcome banner not found";
56  throw smc::Exception{smc::ErrorCode::InternalError,
57  std::string{"Failed to get Grbl banner"}};
58  }
59 }
60 
61 } // namespace edge
Exception thrown by MotionController in case of issues with command.
Definition: Exception.hpp:61