DashelTarget.h
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef TCPTARGET_H
00022 #define TCPTARGET_H
00023 
00024 #include "Target.h"
00025 #include "../common/consts.h"
00026 #include "../msg/descriptions-manager.h"
00027 #include <QString>
00028 #include <QDialog>
00029 #include <QQueue>
00030 #include <QTimer>
00031 #include <QThread>
00032 #include <map>
00033 #include <dashel/dashel.h>
00034 
00035 class QPushButton;
00036 class QGroupBox;
00037 class QLineEdit;
00038 class QSpinBox;
00039 class QListWidget;
00040 class QComboBox;
00041 class QTranslator;
00042 
00043 
00044 namespace Dashel
00045 {
00046         class Stream;
00047 }
00048 
00049 namespace Aseba
00050 {
00053         
00054         class DashelConnectionDialog : public QDialog
00055         {
00056                 Q_OBJECT
00057                 
00058         protected:
00059                 QPushButton* connectButton;
00060                 QGroupBox* netGroupBox;
00061                 QLineEdit* host;
00062                 QSpinBox* port;
00063                 QGroupBox* serialGroupBox;
00064                 QListWidget* serial;
00065                 QGroupBox* customGroupBox;
00066                 QLineEdit* custom;
00067                 QComboBox* languageSelectionBox;
00068                 
00069         public:
00070                 DashelConnectionDialog();
00071                 std::string getTarget();
00072                 QString getLocaleName();
00073                 
00074         public slots:
00075                 void netGroupChecked();
00076                 void serialGroupChecked();
00077                 void customGroupChecked();
00078                 void setupOkStateFromListSelection();
00079         };
00080         
00081         class Message;
00082         class UserMessage;
00083         
00084         class DashelInterface: public QThread, public Dashel::Hub
00085         {
00086                 Q_OBJECT
00087                 
00088         public:
00089                 bool isRunning;
00090                 Dashel::Stream* stream;
00091                 std::string lastConnectedTarget;
00092                 QString language;
00093                 
00094         public:
00095                 DashelInterface(QVector<QTranslator*> translators, const QString& commandLineTarget);
00096                 bool attemptToReconnect();
00097                 
00098                 // from Dashel::Hub
00099                 virtual void stop();
00100                 
00101         signals:
00102                 void messageAvailable(Message *message);
00103                 void dashelDisconnection();
00104         
00105         protected:
00106                 // from QThread
00107                 virtual void run();
00108                 
00109                 // from Dashel::Hub
00110                 virtual void incomingData(Dashel::Stream *stream);
00111                 virtual void connectionClosed(Dashel::Stream *stream, bool abnormal);
00112         };
00113         
00115         class SignalingDescriptionsManager: public QObject, public DescriptionsManager
00116         {
00117                 Q_OBJECT
00118         
00119         signals:
00120                 void nodeDescriptionReceivedSignal(unsigned nodeId);
00121         
00122         protected:
00123                 virtual void nodeProtocolVersionMismatch(const std::string &nodeName, uint16 protocolVersion);
00124                 virtual void nodeDescriptionReceived(unsigned nodeId);
00125         };
00126         
00127         class DashelTarget: public Target
00128         {
00129                 Q_OBJECT
00130                 
00131         protected:
00132                 struct Node
00133                 {
00134                         Node();
00135                         
00136                         BytecodeVector debugBytecode; 
00137                         BytecodeVector::EventAddressesToIdsMap eventAddressToId; 
00138                         unsigned steppingInNext; 
00139                         unsigned lineInNext; 
00140                         ExecutionMode executionMode; 
00141                 };
00142                 
00143                 typedef void (DashelTarget::*MessageHandler)(Message *message);
00144                 typedef std::map<unsigned, MessageHandler> MessagesHandlersMap;
00145                 typedef std::map<unsigned, Node> NodesMap;
00146                 
00147                 DashelInterface dashelInterface;
00148                 
00149                 MessagesHandlersMap messagesHandlersMap;
00150                 
00151                 QQueue<UserMessage *> userEventsQueue;
00152                 SignalingDescriptionsManager descriptionManager;
00153                 NodesMap nodes;
00154                 QTimer userEventsTimer;
00155                 bool writeBlocked; 
00156                 
00157         public:
00158                 friend class InvasivePlugin;
00159                 DashelTarget(QVector<QTranslator*> translators, const QString& commandLineTarget);
00160                 ~DashelTarget();
00161                 
00162                 virtual QString getLanguage() const { return dashelInterface.language; }
00163                 
00164                 virtual void disconnect();
00165                 
00166                 virtual const TargetDescription * const getDescription(unsigned node) const;
00167                 
00168                 virtual void broadcastGetDescription();
00169                 
00170                 virtual void uploadBytecode(unsigned node, const BytecodeVector &bytecode);
00171                 virtual void writeBytecode(unsigned node);
00172                 virtual void reboot(unsigned node);
00173                 
00174                 virtual void sendEvent(unsigned id, const VariablesDataVector &data);
00175                 
00176                 virtual void setVariables(unsigned node, unsigned start, const VariablesDataVector &data);
00177                 virtual void getVariables(unsigned node, unsigned start, unsigned length);
00178                 
00179                 virtual void reset(unsigned node);
00180                 virtual void run(unsigned node);
00181                 virtual void pause(unsigned node);
00182                 virtual void next(unsigned node);
00183                 virtual void stop(unsigned node);
00184                 
00185                 virtual void setBreakpoint(unsigned node, unsigned line);
00186                 virtual void clearBreakpoint(unsigned node, unsigned line);
00187                 virtual void clearBreakpoints(unsigned node);
00188         
00189         protected:
00190                 virtual void blockWrite();
00191                 virtual void unblockWrite();
00192         
00193         protected slots:
00194                 void updateUserEvents();
00195                 void messageFromDashel(Message *message);
00196                 void disconnectionFromDashel();
00197                 void nodeDescriptionReceived(unsigned node);
00198         
00199         protected:
00200                 void receivedDescription(Message *message);
00201                 void receivedLocalEventDescription(Message *message);
00202                 void receivedNativeFunctionDescription(Message *message);
00203                 void receivedDisconnected(Message *message);
00204                 void receivedVariables(Message *message);
00205                 void receivedArrayAccessOutOfBounds(Message *message);
00206                 void receivedDivisionByZero(Message *message);
00207                 void receivedEventExecutionKilled(Message *message);
00208                 void receivedNodeSpecificError(Message *message);
00209                 void receivedExecutionStateChanged(Message *message);
00210                 void receivedBreakpointSetResult(Message *message);
00211                 void receivedBootloaderAck(Message *message);
00212                 
00213         protected:
00214                 bool emitNodeConnectedIfDescriptionComplete(unsigned id, const Node& node);
00215                 int getPCFromLine(unsigned node, unsigned line);
00216                 int getLineFromPC(unsigned node, unsigned pc);
00217 
00218         protected:
00219                 void handleDashelException(Dashel::DashelException e);
00220         };
00221         
00223 }; // Aseba
00224 
00225 #endif


aseba
Author(s): Stéphane Magnenat
autogenerated on Thu Jan 2 2014 11:17:16