MotionLib  1.0.0
SamBuCa motion library
MGrblPlatform_Context.cpp
1 /*
2 ** Copyright (C) 2025 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: 2025-04-17T13:11:08
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #include <ccut/yml.hpp>
25 
26 #include "MGrblPlatform.hpp"
27 
28 using namespace smc;
29 using namespace smc::internal;
30 namespace yml = ccut::yml;
31 
32 inline static std::string getDeviceId(const ccut::yml::NodeRef &ref)
33 {
34  std::string id;
35  yml::get(ref, "id") >> yml::default_to(id, "0");
36  return id;
37 }
38 
39 MGrblPlatform::Context::Context(const std::string &prefix,
40  const ccut::yml::NodeRef &ref) :
41  prefix{prefix},
42  id{getDeviceId(ref)}
43 {}
44 
45 void MGrblPlatform::Context::checkReply(grbl::ErrorCode rc)
46 {
47  if (rc != 0)
48  throw Exception(ErrorCode::Runtime,
49  "command failed, err=" + std::to_string(rc));
50 }
Exception thrown by MotionController in case of issues with command.
Definition: Exception.hpp:61
const std::string & to_string(Axis::State state)
convert State to string
Definition: Axis.cpp:78
main motion-lib namespace
Definition: Client.cpp:30