MotionLib  1.0.0
SamBuCa motion library
GrblPlatformData.hpp
1 /*
2 ** Copyright (C) 2021 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-05-04T09:55:45+02:00
21 ** Author: Sylvain Fargier <sfargier> <sylvain.fargier@cern.ch>
22 **
23 */
24 
25 #ifndef GRBL_PLATFORM_DATA_HPP__
26 #define GRBL_PLATFORM_DATA_HPP__
27 
28 #if !defined(GCC_LINT)
29 #pragma once
30 #endif
31 
32 #include <functional>
33 #include <future>
34 #include <set>
35 
36 #include <ccut/Signal.hpp>
37 
38 #include "GrblPlatform.hpp"
39 #include "util/Promise.hpp"
40 #include "util/grbl/GrblParser.hpp"
41 #include "util/grbl/GrblTypes.hpp"
42 
43 namespace smc {
44 namespace internal {
51 {
52  MotionCmd(std::function<void(MotionCmd &, GrblPlatform::Context &)> run,
53  std::set<grbl::Axis> &&axis,
54  std::string &&message) :
55  run(run),
56  axis(axis),
57  message(message),
58  line(0)
59  {}
60  MotionCmd(MotionCmd &&) = default;
61  MotionCmd(const MotionCmd &) = delete;
62  MotionCmd &operator=(const MotionCmd &) = delete;
63  MotionCmd &operator=(MotionCmd &&) = default;
64 
65  std::function<void(MotionCmd &, GrblPlatform::Context &)> run;
66  std::set<grbl::Axis> axis;
67  std::string message;
68  std::promise<void> prom;
69  GrblPlatform::Line line;
70 };
71 
73 {
74  typedef std::function<void(ImmediateCmd &, Context &)> Function;
75 
76  explicit ImmediateCmd(Function run, PromiseBase *prom) :
77  run(run),
78  prom(prom)
79  {}
80  Function run;
81  std::unique_ptr<PromiseBase> prom;
82 };
83 
85 {
86  Context(const std::string &prefix, const std::string &id);
87 
88  const std::string prefix;
89  const std::string id;
91  std::string getErrorMessage(grbl::ErrorCode code) const;
92  std::string getAlarmMessage(grbl::AlarmCode alarm) const;
93  AxisData &_getAxisData(const std::string &uid);
98  void checkReply(grbl::ErrorCode code);
99 
105  std::set<std::string> listConfig();
106 
112  std::set<std::string> listConfig(grbl::Axis);
113 
119  const grbl::GrblParser::SettingDesc &findSetting(const std::string &name,
120  grbl::Axis axis) const;
121 
127  const std::string &name) const;
128 
133  const std::string findLocalSetting(const std::string &name) const;
134 
138  std::string _sendGetSetting(grbl::SettingId settingId);
139 
143  void _sendSetSetting(grbl::SettingId settingId, const std::string &value);
144 
145  void setSetting(const std::string &name, const std::string &value);
146 
147  void sendHold();
148 
152  void sendReset();
153 
154  static bool isStepperMessage(const std::string &line);
155 
156  /* local settings */
157  bool triggeredMotion = false;
158 
159  /* processing thread only */
160  std::unique_ptr<grbl::GrblDeviceBase> device;
161  std::map<int, std::string> errors;
162  std::map<int, std::string> alarms;
163  std::map<std::string, int> settingGroup;
164  SettingMap setting;
167  GrblPlatform::Line line = 0;
168  std::chrono::steady_clock::time_point nextPoll;
169  LocalSettingMap localSetting;
170 };
171 
173 {
174  std::function<void(Context &, const std::string &)> set;
175  std::function<std::string(Context &)> get;
176 };
178 {
179  grbl::Axis grblAxis;
180  units::Value position;
181 
182  grbl::SettingId resolutionSettingId;
184 };
185 
188 } // namespace internal
189 } // namespace smc
190 
191 #endif
main motion-lib namespace
Definition: Client.cpp:30
structure holding Grbl build-info ($I)
Definition: GrblParser.hpp:134
structure holding Grbl setting description ($ES)
Definition: GrblParser.hpp:177
Struct holding state of Grbl as returned by "?".
Definition: GrblParser.hpp:96
units::Value resolution
resolution in steps_per_mm
void _sendSetSetting(grbl::SettingId settingId, const std::string &value)
set a setting on Grbl
const std::string prefix
uri prefix (ex: grbl://)
const std::string id
uri platform id as in grbl://<id>/
std::set< std::string > listConfig()
list config values
const std::string findLocalSetting(const std::string &name) const
find local setting using its name
void checkReply(grbl::ErrorCode code)
check command result code
const grbl::GrblParser::SettingDesc & findSetting(const std::string &name, grbl::Axis axis) const
find setting id for axis
std::string _sendGetSetting(grbl::SettingId settingId)
retrieve a setting from Grbl, eventually update internal cache
base structure for promise handline
Definition: Promise.hpp:44