-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaseba.h
80 lines (73 loc) · 2.6 KB
/
aseba.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef ASEBA_CLIENT_H
#define ASEBA_CLIENT_H
#include <QVariantMap>
#include <QThread>
#include <QTimer>
#include "dashel/dashel.h"
#include "aseba/common/msg/msg.h"
#include "aseba/common/msg/NodesManager.h"
#include "aseba/compiler/compiler.h"
class DashelHub: public QObject, public Dashel::Hub {
Q_OBJECT
public slots:
void start(QString target);
void send(Dashel::Stream* stream, const Aseba::Message& message);
signals:
void connectionCreated(Dashel::Stream* stream) Q_DECL_OVERRIDE;
void incomingData(Dashel::Stream* stream) Q_DECL_OVERRIDE;
void connectionClosed(Dashel::Stream* stream, bool abnormal) Q_DECL_OVERRIDE;
void error(QString source, QString reason);
private:
void exception(Dashel::DashelException&);
};
class AsebaDescriptionsManager: public QObject, public Aseba::NodesManager {
Q_OBJECT
signals:
void nodeProtocolVersionMismatch(unsigned nodeId, const std::wstring &nodeName, uint16_t protocolVersion) Q_DECL_OVERRIDE;
void nodeDescriptionReceived(unsigned nodeId) Q_DECL_OVERRIDE;
void nodeConnected(unsigned nodeId) Q_DECL_OVERRIDE;
void nodeDisconnected(unsigned nodeId) Q_DECL_OVERRIDE;
void sendMessage(const Aseba::Message& message) Q_DECL_OVERRIDE;
public slots:
void pingNetwork() { Aseba::NodesManager::pingNetwork(); }
};
class AsebaNode;
class AsebaClient: public QObject {
Q_OBJECT
Q_PROPERTY(const QList<QObject*> nodes MEMBER nodes NOTIFY nodesChanged)
QThread thread;
DashelHub hub;
AsebaDescriptionsManager manager;
QTimer managerTimer;
Dashel::Stream* stream;
QList<QObject*> nodes;
public:
AsebaClient();
~AsebaClient();
public slots:
void start(QString target = ASEBA_DEFAULT_TARGET);
void send(const Aseba::Message& message);
void receive(Aseba::Message* message);
void sendUserMessage(int eventId, QList<int> args);
signals:
void userMessage(unsigned type, QList<int> data);
void nodesChanged();
void connectionError(QString source, QString reason);
};
class AsebaNode: public QObject {
Q_OBJECT
Q_PROPERTY(QString name READ name CONSTANT)
unsigned nodeId;
Aseba::TargetDescription description;
Aseba::VariablesMap variablesMap;
public:
explicit AsebaNode(AsebaClient* parent, unsigned nodeId, const Aseba::TargetDescription* description);
AsebaClient* parent() const { return static_cast<AsebaClient*>(QObject::parent()); }
unsigned id() const { return nodeId; }
QString name() { return QString::fromStdWString(description.name); }
static Aseba::CommonDefinitions commonDefinitionsFromEvents(QVariantMap events);
public slots:
void setVariable(QString name, QList<int> value);
QString setProgram(QVariantMap events, QString source);
};
#endif // ASEBA_CLIENT_H