Main Page | Namespace List | Alphabetical List | Class List | Directories | File List | Class Members | File Members

UDPSynchronizedClient.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Simulation                                                *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
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 General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 #ifndef UDPSYNCHRONIZEDCLIENT_H
00024 #define UDPSYNCHRONIZEDCLIENT_H
00025 
00026 //Other includes
00027 #include <arpa/inet.h>
00028 #include <string>
00029 using namespace std;
00030 
00031 
00032 //---------------------- UDP Synchronized Client ---------------------------
00033 /*! Thread that listens for incoming UDP messages and calculates the update
00034         time between them to enable the simulation to change its update rate
00035         to match that of the external device. */
00036 //--------------------------------------------------------------------------
00037 
00038 class UDPSynchronizedClient {
00039 
00040         public:
00041                 UDPSynchronizedClient(unsigned int neurGrpWidth, unsigned int neurGrpLength);
00042                 ~UDPSynchronizedClient();
00043                 bool clientThreadRunning();
00044                 bool closeDevice();
00045                 bool deviceOpen();
00046                 unsigned int getExternalComputeTime_us();
00047                 bool getExternalSyncDelay();
00048                 void lockMutex();
00049                 bool openSocket(string groupAddress, int port);
00050                 void run();//Public so it can be started by thread
00051                 void start();
00052                 void stop();
00053                 void unlockMutex();
00054 
00055 
00056                 //========================== VARIABLES ==============================
00057                 /*! Number of spikes in the spike buffer.*/
00058                 unsigned int spikeCount;
00059 
00060                 /*! Buffer holding the spikes that have been received by this class from
00061                         the external device.*/
00062                 unsigned int* spikeBuffer;
00063 
00064 
00065         private:
00066                 //========================== VARIABLES ==============================
00067                 /*! Neuron group width.*/
00068                 unsigned int neuronGrpWidth;
00069                 
00070                 /*! The first ID in the neuron group.*/
00071                 unsigned int neuronGrpLength;
00072 
00073                 /*! Controls whether the thread is running.*/
00074                 bool threadRunning;
00075 
00076                 /*! Records whether the socket has been opened.*/
00077                 bool socketOpen;
00078 
00079                 /*! Thread to listen for incoming packets from broadcast group.*/
00080                 pthread_t clientThread;
00081 
00082                 /*! External device is delaying its time steps.*/
00083                 bool externalSyncDelay;
00084 
00085                 /*! Compute time of external device.*/
00086                 unsigned int externalComputeTime_us;
00087 
00088                 /*! Counter to record the number of time steps that have taken place 
00089                         in the absence of input from the external process.*/
00090                 unsigned int timeStepsNoMessagesCount;
00091 
00092                 /*! Integer used to access the socket.*/
00093                 int socketHandle;
00094 
00095                 /*! Address of the socket.*/
00096                 struct sockaddr_in socketAddress;
00097 
00098                 /*! Buffer used to receive messages from the network.*/
00099                 unsigned char* messageBuffer;
00100 
00101 
00102                 //=========================== METHODS ===============================
00103                 /*! Declare copy constructor private so it cannot be used inadvertently.*/
00104                 UDPSynchronizedClient (const UDPSynchronizedClient&);
00105 
00106                 /*! Declare assignment private so it cannot be used.*/
00107                 UDPSynchronizedClient operator = (const UDPSynchronizedClient&);
00108 
00109 };
00110 
00111 
00112 #endif//UDPSYNCHRONIZEDCLIENT_H
00113 
00114 
00115 
00116 
00117 

Generated on Mon Sep 3 22:24:34 2007 for SpikeStream Simulation by  doxygen 1.4.4