trikRuntime
abstractVirtualSensorWorker.h
Go to the documentation of this file.
1 /* Copyright 2014 - 2015 CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/QObject>
18 #include <QtCore/QScopedPointer>
19 #include <QtCore/QString>
20 #include <QtCore/QStringList>
21 
22 #include "deviceInterface.h"
23 #include "deviceState.h"
24 
25 namespace trikHal {
26 class HardwareAbstractionInterface;
27 class FifoInterface;
28 class OutputDeviceFileInterface;
29 class SystemConsoleInterface;
30 }
31 
32 namespace trikControl {
33 
38 class AbstractVirtualSensorWorker : public QObject, public DeviceInterface
39 {
40  Q_OBJECT
41 
42 public:
48  AbstractVirtualSensorWorker(const QString &script, const QString &inputFile, const QString &outputFile
49  , DeviceState &state, trikHal::HardwareAbstractionInterface &hardwareAbstraction);
50 
51  ~AbstractVirtualSensorWorker() override;
52 
53  Status status() const override;
54 
55 signals:
57  void stopped();
58 
59 public slots:
61  virtual void stop();
62 
63 protected:
65  void init();
66 
68  void sendCommand(const QString &command);
69 
70 private slots:
72  void onNewDataInOutputFifo(const QString &data);
73 
74 private:
76  virtual QString sensorName() const = 0;
77 
79  virtual void onNewData(const QString &dataLine) = 0;
80 
82  void initVirtualSensor();
83 
86  bool launchSensorScript(const QString &command);
87 
89  void startVirtualSensor();
90 
92  void openFifos();
93 
95  void deinitialize();
96 
98  void sync();
99 
101  trikHal::SystemConsoleInterface &mSystemConsole;
102 
104  QScopedPointer<trikHal::FifoInterface> mOutputFifo;
105 
107  QString mScript;
108 
111  QScopedPointer<trikHal::OutputDeviceFileInterface> mInputFile;
112 
114  QStringList mCommandQueue;
115 
117  DeviceState &mState;
118 
120  trikHal::HardwareAbstractionInterface &mHardwareAbstraction;
121 
123  const QString mOutputFile;
124 };
125 
126 }
Helper class to track device state (off, starting, ready, stopping, fail).
Definition: deviceState.h:26
Status
Device status.
Definition: deviceInterface.h:33
Definition: trikCommunicator.h:27
TRIK device interface, base interface for everything that can be plugged to a brick or already on boa...
Definition: deviceInterface.h:23
Base class for all virtual sensor workers.
Definition: abstractVirtualSensorWorker.h:38
Definition: brickFactory.h:21
script
Definition: system.py:83
Hardware abstraction, provides devices that are used to communicate with robot hardware or emulate it...
Definition: hardwareAbstractionInterface.h:29
Represents console of an OS.
Definition: systemConsoleInterface.h:22