00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef TCPTARGET_H
00025 #define TCPTARGET_H
00026
00027 #include "Target.h"
00028 #include "../common/consts.h"
00029 #include "../msg/descriptions-manager.h"
00030 #include <QString>
00031 #include <QDialog>
00032 #include <QQueue>
00033 #include <QTimer>
00034 #include <QThread>
00035 #include <map>
00036 #include <dashel/dashel.h>
00037
00038 class QPushButton;
00039 class QGroupBox;
00040 class QLineEdit;
00041 class QSpinBox;
00042 class QListWidget;
00043 class QComboBox;
00044 class QTranslator;
00045
00046
00047 namespace Dashel
00048 {
00049 class Stream;
00050 }
00051
00052 namespace Aseba
00053 {
00056
00057 class DashelConnectionDialog : public QDialog
00058 {
00059 Q_OBJECT
00060
00061 protected:
00062 QPushButton* connectButton;
00063 QGroupBox* netGroupBox;
00064 QLineEdit* host;
00065 QSpinBox* port;
00066 QGroupBox* serialGroupBox;
00067 QListWidget* serial;
00068 QGroupBox* customGroupBox;
00069 QLineEdit* custom;
00070 QComboBox* languageSelectionBox;
00071
00072 public:
00073 DashelConnectionDialog();
00074 std::string getTarget();
00075 QString getLocaleName();
00076
00077 public slots:
00078 void netGroupChecked();
00079 void serialGroupChecked();
00080 void customGroupChecked();
00081 void setupOkStateFromListSelection();
00082 };
00083
00084 class Message;
00085 class UserMessage;
00086
00087 class DashelInterface: public QThread, public Dashel::Hub
00088 {
00089 Q_OBJECT
00090
00091 public:
00092 Dashel::Stream* stream;
00093 QString language;
00094
00095 public:
00096 DashelInterface(QVector<QTranslator*> translators, const QString& commandLineTarget);
00097
00098 signals:
00099 void messageAvailable(Message *message);
00100 void dashelDisconnection();
00101
00102 protected:
00103
00104 virtual void run();
00105
00106
00107 virtual void incomingData(Dashel::Stream *stream);
00108 virtual void connectionClosed(Dashel::Stream *stream, bool abnormal);
00109 };
00110
00112 class SignalingDescriptionsManager: public QObject, public DescriptionsManager
00113 {
00114 Q_OBJECT
00115
00116 signals:
00117 void nodeDescriptionReceivedSignal(unsigned nodeId);
00118
00119 protected:
00120 virtual void nodeProtocolVersionMismatch(const std::string &nodeName, uint16 protocolVersion);
00121 virtual void nodeDescriptionReceived(unsigned nodeId);
00122 };
00123
00124 class DashelTarget: public Target
00125 {
00126 Q_OBJECT
00127
00128 protected:
00129 struct Node
00130 {
00131 Node();
00132
00133 BytecodeVector debugBytecode;
00134 unsigned steppingInNext;
00135 unsigned lineInNext;
00136 ExecutionMode executionMode;
00137 };
00138
00139 typedef void (DashelTarget::*MessageHandler)(Message *message);
00140 typedef std::map<unsigned, MessageHandler> MessagesHandlersMap;
00141 typedef std::map<unsigned, Node> NodesMap;
00142
00143 DashelInterface dashelInterface;
00144
00145 MessagesHandlersMap messagesHandlersMap;
00146
00147 QQueue<UserMessage *> userEventsQueue;
00148 SignalingDescriptionsManager descriptionManager;
00149 NodesMap nodes;
00150 QTimer userEventsTimer;
00151
00152 public:
00153 DashelTarget(QVector<QTranslator*> translators, const QString& commandLineTarget);
00154 ~DashelTarget();
00155
00156 virtual QString getLanguage() const { return dashelInterface.language; }
00157
00158 virtual void disconnect();
00159
00160 virtual const TargetDescription * const getDescription(unsigned node) const;
00161
00162 virtual void uploadBytecode(unsigned node, const BytecodeVector &bytecode);
00163 virtual void writeBytecode(unsigned node);
00164 virtual void reboot(unsigned node);
00165
00166 virtual void sendEvent(unsigned id, const VariablesDataVector &data);
00167
00168 virtual void setVariables(unsigned node, unsigned start, const VariablesDataVector &data);
00169 virtual void getVariables(unsigned node, unsigned start, unsigned length);
00170
00171 virtual void reset(unsigned node);
00172 virtual void run(unsigned node);
00173 virtual void pause(unsigned node);
00174 virtual void next(unsigned node);
00175 virtual void stop(unsigned node);
00176
00177 virtual void setBreakpoint(unsigned node, unsigned line);
00178 virtual void clearBreakpoint(unsigned node, unsigned line);
00179 virtual void clearBreakpoints(unsigned node);
00180
00181 protected slots:
00182 void updateUserEvents();
00183 void messageFromDashel(Message *message);
00184 void disconnectionFromDashel();
00185 void nodeDescriptionReceived(unsigned node);
00186
00187 protected:
00188 void receivedDescription(Message *message);
00189 void receivedLocalEventDescription(Message *message);
00190 void receivedNativeFunctionDescription(Message *message);
00191 void receivedDisconnected(Message *message);
00192 void receivedVariables(Message *message);
00193 void receivedArrayAccessOutOfBounds(Message *message);
00194 void receivedDivisionByZero(Message *message);
00195 void receivedEventExecutionKilled(Message *message);
00196 void receivedNodeSpecificError(Message *message);
00197 void receivedExecutionStateChanged(Message *message);
00198 void receivedBreakpointSetResult(Message *message);
00199
00200 protected:
00201 bool emitNodeConnectedIfDescriptionComplete(unsigned id, const Node& node);
00202 int getPCFromLine(unsigned node, unsigned line);
00203 int getLineFromPC(unsigned node, unsigned pc);
00204 };
00205
00207 };
00208
00209 #endif