MotionLib  1.0.0
SamBuCa motion library
MGrblDeviceWrapper.hpp
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-05-13
21  * Author: Michal Mysior <mmysior> <michal.mysior@cern.ch>
22  *
23  */
24 
25 #ifndef MGRBLDEVICEWRAPPER_HPP__
26 #define MGRBLDEVICEWRAPPER_HPP__
27 
28 #include "GrblDeviceBase.hpp"
29 
30 namespace grbl {
49 {
50 public:
51  MGrblDeviceWrapper(size_t instance,
52  const std::shared_ptr<grbl::GrblDeviceBase> &device);
53 
54  void read() override;
55  void write(const std::string &data) override;
56 
66  grbl::ErrorCode send(
67  const std::string &cmd,
68  std::function<bool(const std::string &)> msg =
69  [](const std::string &) { return false; },
70  const std::chrono::milliseconds &timeout = defaultSendTimeout) override;
71 
81  grbl::ErrorCode sendRealtime(
82  const std::string &cmd,
83  std::function<bool(const std::string &)> msg,
84  const std::chrono::milliseconds &timeout = defaultSendTimeout) override;
85 
86  bool wait(const std::chrono::milliseconds &timeout) override;
87 
88  void wake() override;
89 
90 protected:
91  size_t m_instance;
92  std::shared_ptr<grbl::GrblDeviceBase> m_device;
93 };
94 
98 } // namespace grbl
99 
100 #endif
Class for implementing Multi-Grbl functionality on top of GrblDeviceBase.
grbl::ErrorCode send(const std::string &cmd, std::function< bool(const std::string &)> msg=[](const std::string &) { return false;}, const std::chrono::milliseconds &timeout=defaultSendTimeout) override
Send message appending instance id and stripping it off the response provided to handler.
bool wait(const std::chrono::milliseconds &timeout) override
wait for input
void wake() override
wake thread waiting for input
void read() override
fill LineBuffer with incoming bytes
void write(const std::string &data) override
raw write some bytes
grbl::ErrorCode sendRealtime(const std::string &cmd, std::function< bool(const std::string &)> msg, const std::chrono::milliseconds &timeout=defaultSendTimeout) override
Send realtime message appending instance id and stripping it off the response provided to handler.