Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/MessageQueue/LogPlayer.h

Go to the documentation of this file.
00001 /**
00002 * @file LogPlayer.h
00003 *
00004 * Definition of class LogPlayer
00005 *
00006 * @author Martin Lötzsch
00007 */
00008 
00009 #ifndef __LogPlayer_h_
00010 #define __LogPlayer_h_
00011 
00012 #include "MessageQueue.h"
00013 
00014 /**
00015 * @class LogPlayer
00016 *
00017 * A message queue that can record and play logfiles.
00018 * The messages are played in the same time sequence as they were recorded.
00019 *
00020 * @author Martin Lötzsch
00021 */
00022 class LogPlayer : public MessageQueue
00023 {
00024 public:
00025   /** 
00026   * Constructor 
00027   * @param targetQueue The queue into that messages from played logfiles shall be stored.
00028   */
00029   LogPlayer(MessageQueue& targetQueue);
00030 
00031   /** different states of the logplayer */
00032   enum LogPlayerState
00033   {
00034     initial, recording, paused, playing
00035   };
00036 
00037   /** Returns the state of the queue */
00038   LogPlayerState getState();
00039 
00040   /** Deletes all messages from the queue */
00041   void _new();
00042 
00043   /** 
00044   * Opens a log file and reads all messages into the queue.
00045   * @param fileName the name of the file to open
00046   * @return if the reading was successful
00047   */
00048   bool open(const char* fileName);
00049 
00050   /** 
00051   * Playes the queue. 
00052   * Note that you have to call onIdle() regularely if you want to use that function
00053   */
00054   void play();
00055 
00056   /** Pauses playing the queue. */
00057   void pause();
00058 
00059   /** Stops playing the queue, resets the position in the queue to the first message */
00060   void stop();
00061 
00062   /** Plays the next message in the queue */
00063   void stepForward();
00064 
00065   /** Plays the previous message in the queue */
00066   void stepBackward();
00067 
00068   /** repeats the current message in the queue */
00069   void stepRepeat();
00070   
00071   /** jumps to given message-number in the queue */
00072   void jumpFrame(int frame);
00073   
00074   /** 
00075   * Starts / Stops recording.
00076   * Note that you have to notify the queue on new messages with handleMessage().
00077   */
00078   void record();
00079 
00080   /** Activates/deactivates jpeg image smoothing */
00081   void smooth();
00082   
00083   /** 
00084   * Writes all messages in the log player queue to a log file.
00085   * @param fileName the name of the file to write
00086   * @return if the writing was successful
00087   */
00088   bool save(const char* fileName);
00089 
00090   /** 
00091   * Writes all messages in the log player queue to an AIBOVision compatibile movie file.
00092   * Images are encoded in a raw YUV format.
00093   * @param fileName the name of the file to write
00094   * @return if the writing was successful
00095   */
00096   bool saveAMV(const char* fileName);
00097 
00098   /** 
00099   * Writes an row of doubles to an comma separated value file.
00100   * @param file the open file to write to
00101   * @param row a row containing the doubles to be written
00102   * @param rowLen number of entries in row
00103   */
00104   void saveCSVrow(OutTextRawFile& file, double* row, unsigned int rowLen);
00105   
00106   /** 
00107   * Writes a couple of message types in the log player queue to an comma separated value file with a common time line.
00108   * @param fileName the name of the file to write
00109   * @return if the writing was successful
00110   */
00111   bool saveCSV(const char* fileName);
00112 
00113 
00114   /** 
00115   * Synchronizes the RemoteCamWorldstates with the robots timestamps and writes a resorted version of the logfile.
00116   * Condition: Logfile must contain TimeSynchronziation Messages from robot and remoteCam.
00117   * @param fileName the name of the file to write
00118   * @return if the writing was successful
00119   */
00120   bool saveSynchronized (const char* fileName);
00121 
00122   /** 
00123   * Writes all images in the log player queue to a bunch of files (*.bmp or *.jpg).
00124   * @param fileName the name of one file to write, all files will be enumerated by appending a 3 digit number to the filename.
00125   * @return if the writing of all files was successful
00126   */
00127   bool saveImages(const char* fileName);
00128 
00129   /** 
00130   * Sets the playing speed of the log player.
00131   * "2" playes the messages double as fast as they were recorded, 
00132   * "0.5" plays the messages with the half speed.
00133   */
00134   void setPlaySpeed(double speed);
00135 
00136   /** 
00137   * Adds the message to the queue depending on isRecording. 
00138   * That function should be called for every message in the queue that the 
00139   * log player shall work on.
00140   */
00141   void handleMessage(InMessage& message);
00142 
00143   /** 
00144   * If playing a log file, that function checks if it is time to release the next
00145   * message dependend on the time stamp. Call that function whenever there is some
00146   * processing time left.
00147   */
00148   void onIdle();
00149 
00150   /** Returns the number of stored messages */
00151   int getNumberOfMessages() const;
00152 
00153   /** Returns the number of the current message */
00154   int getCurrentMessageNumber() const;
00155 
00156   /** Returns the type of the current message */
00157   MessageID getCurrentMessageID() const;
00158   
00159   /**
00160   * The functions filters the message queue.
00161   * @param messageIDs An null-terminated array of message ids that should be kept.
00162   */
00163   void keep(MessageID* messageIDs);
00164 
00165   /**
00166   * The functions filters the message queue.
00167   * @param messageIDs An null-terminated array of message ids that should be removed.
00168   */
00169   void remove(MessageID* messageIDs);
00170 
00171   /**
00172   * The function creates a histogram on the message ids contained in the log file.
00173   * @param frequency An array that is filled with the frequency of message ids.
00174   */
00175   void statistics(int frequency[numOfMessageIDs]);
00176 
00177   /** Returns the status of the smoothing flag */
00178   inline bool isSmoothingEnabled() const
00179   {
00180     return smoothingEnabled;
00181   };
00182 
00183 private:
00184 
00185   /** the state of the log player */
00186   LogPlayerState state;
00187 
00188   /* The queue into that messages from played logfiles shall be stored. */
00189   MessageQueue& targetQueue;
00190 
00191   /** little routine to convert an integer into C style string*/
00192   void convertIntString(char* str, int value);
00193 
00194   /** 
00195   * A factor, how fast the messages are played. 
00196   * "2" playes the messages double as fast as they were recorded, 
00197   * "0.5" plays the messages with the half speed.
00198   */
00199   double playSpeed;
00200 
00201   /**
00202   * Returns the time stamp of a given message.
00203   * @param message The number of the message 
00204   * @return The time stamp
00205   */
00206   unsigned long getTimeStamp(int message);
00207 
00208 protected:
00209   /** The number of the current message */
00210   int currentMessageNumber;
00211 
00212   friend class CRemoteCamToolBar;
00213   friend class CLogAnalyzerBase;
00214 private:
00215 
00216   /** The time when the first message was played */
00217   unsigned long timeWhenFirstMessageWasPlayed;
00218 
00219   /** The time stamp of the first played message */
00220   unsigned long timeOfFirstPlayedMessage;
00221 
00222   /** Flag which triggers smoothing of jpeg compressed images */
00223   bool smoothingEnabled;
00224 
00225 };
00226 
00227 
00228 #endif //__LogPlayer_h_

Generated on Mon Mar 20 22:00:07 2006 for GT2005 by doxygen 1.3.6