MotionLib  1.0.0
SamBuCa motion library
MGrblSim.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-02T16:05:04+02:00
21 ** Author: Sylvain Fargier <sfargier> <sylvain.fargier@cern.ch>
22 **
23 */
24 
25 #ifndef MGRBLSIM_HPP__
26 #define MGRBLSIM_HPP__
27 
28 #include <cstdint>
29 #include <memory>
30 #include <vector>
31 
32 #include "GrblSim.hpp"
33 #include "MGrblDeviceBase.hpp"
34 #include "MGrblParser.hpp"
35 
36 namespace mgrbl {
44 class MGrblSim : public grbl::MGrblDeviceBase<grbl::GrblDeviceBase>
45 {
46 public:
47  explicit MGrblSim(size_t instances = defaultInstancesCount);
48  ~MGrblSim() override;
49 
50  void read() override;
51  void write(const std::string &data) override;
52  bool wait(const std::chrono::milliseconds &timeout) override;
53  void wake() override;
54 
55  bool takeLine(std::string &out) override;
56 
57  static constexpr size_t defaultInstancesCount = 8;
58  static constexpr size_t axisCount = 8;
59 
60 protected:
61  std::vector<std::unique_ptr<grbl::GrblSim>> m_instances;
62  Layout m_layout;
63 
64  size_t getTxInstance(const std::string &line);
65  void processCtrl(const std::string &line);
66  void ctrlWrite(const std::string &line);
67 
68  bool trigArmed;
69 };
70 
74 } // namespace mgrbl
75 
76 #endif
base class for multi-grbl devices
void read() override
fill LineBuffer with incoming bytes
Definition: MGrblSim.cpp:69
void write(const std::string &data) override
raw write some bytes
Definition: MGrblSim.cpp:75
bool takeLine(std::string &out) override
consume line from buffer
Definition: MGrblSim.cpp:118
void wake() override
wake thread waiting for input
Definition: MGrblSim.cpp:101
bool wait(const std::chrono::milliseconds &timeout) override
wait for input
Definition: MGrblSim.cpp:137