Homepage Demos Overview Downloads Tutorials Reference
Credits

EventBase.cc

Go to the documentation of this file.
00001 #include "EventBase.h"
00002 #include <stdio.h>
00003 #include <sstream>
00004 
00005 const char* const EventBase::EventGeneratorNames[numEGIDs] = {
00006   "unknownEGID",
00007   "aiEGID",
00008   "audioEGID",
00009   "buttonEGID",
00010   "erouterEGID",
00011   "estopEGID",
00012   "locomotionEGID",
00013   "micOSndEGID",
00014   "micRawEGID",
00015   "micFFTEGID",
00016   "motmanEGID",
00017   "powerEGID",
00018   "sensorEGID",
00019   "stateMachineEGID",
00020   "testmsgEGID",
00021   "timerEGID",
00022   "visOFbkEGID",
00023   "visRawCameraEGID",
00024   "visInterleaveEGID",
00025   "visJPEGEGID",
00026   "visSegmentEGID",
00027   "visRLEEGID",
00028   "visRegionEGID",
00029   "visObjEGID",
00030   "wmVarEGID",
00031   "worldModelEGID",
00032 };
00033 
00034 
00035 EventBase::EventBase()
00036   : LoadSave(), stim_id(), magnitude(0), timestamp(get_time()), nameisgen(true), genID(unknownEGID), typeID(statusETID), sourceID((unsigned int)-1), duration(0)
00037 {
00038   genName();
00039 }
00040 
00041 EventBase::EventBase(EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur)
00042   : LoadSave(), stim_id(), magnitude(0), timestamp(get_time()), nameisgen(true), genID(gid), typeID(tid), sourceID(sid), duration(dur)
00043 {
00044   genName();
00045   if(tid==deactivateETID)
00046     setMagnitude(0.0);
00047   else
00048     setMagnitude(1.0);
00049 }
00050 
00051 EventBase::EventBase(EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur, const std::string& n, float mag)
00052   : LoadSave(), stim_id(n), magnitude(mag), timestamp(get_time()), nameisgen(false), genID(gid), typeID(tid), sourceID(sid), duration(dur)
00053 {
00054   
00055 }
00056 
00057 std::string
00058 EventBase::getDescription(bool /*showTypeSpecific=true*/, unsigned int verbosity/*=0*/) const {
00059   std::ostringstream logdata;
00060   logdata << getName();
00061   char hexstring[30];
00062   snprintf(hexstring,sizeof(hexstring),"0x%x",getSourceID());
00063   logdata << '\t' << hexstring;
00064   switch(getTypeID()) {
00065   case EventBase::activateETID:
00066     logdata << "\tA"; break;
00067   case EventBase::statusETID:
00068     logdata << "\tS"; break;
00069   case EventBase::deactivateETID:
00070     logdata << "\tD"; break;
00071   case EventBase::numETIDs:
00072     logdata << "\tU"; break;  //UNKNOWN TYPE
00073   }
00074   if(verbosity>=1)
00075     logdata << '\t' << getDuration() << '\t' << getTimeStamp();
00076   if(verbosity>=2)
00077     logdata << '\t' << getMagnitude();
00078   return logdata.str();
00079 }
00080 
00081 unsigned int
00082 EventBase::getBinSize() const {
00083   unsigned int used=0;
00084   used+=creatorSize("EventBase");
00085   used+=stim_id.size()+stringpad;
00086   used+=sizeof(magnitude);
00087   used+=sizeof(timestamp);
00088   used+=sizeof(nameisgen);
00089   used+=sizeof(char);
00090   used+=sizeof(char);
00091   used+=sizeof(sourceID);
00092   used+=sizeof(duration);
00093   return used;
00094 }
00095 
00096 unsigned int
00097 EventBase::LoadBuffer(const char buf[], unsigned int len) {
00098   unsigned int origlen=len;
00099   unsigned int used=0;
00100   if(0==(used=checkCreator("EventBase",buf,len,true))) return 0;
00101   len-=used; buf+=used;
00102   if(0==(used=decode(stim_id,buf,len))) return 0;
00103   len-=used; buf+=used;
00104   if(0==(used=decode(magnitude,buf,len))) return 0;
00105   len-=used; buf+=used;
00106   if(0==(used=decode(timestamp,buf,len))) return 0;
00107   len-=used; buf+=used;
00108   if(0==(used=decode(nameisgen,buf,len))) return 0;
00109   len-=used; buf+=used;
00110   char tmp;
00111   if(0==(used=decode(tmp,buf,len))) return 0;
00112   genID=(EventGeneratorID_t)tmp;
00113   len-=used; buf+=used;
00114   if(0==(used=decode(tmp,buf,len))) return 0;
00115   typeID=(EventTypeID_t)tmp;
00116   len-=used; buf+=used;
00117   if(0==(used=decode(sourceID,buf,len))) return 0;
00118   len-=used; buf+=used;
00119   if(0==(used=decode(duration,buf,len))) return 0;
00120   len-=used; buf+=used;
00121   return origlen-len; 
00122 }
00123 
00124 unsigned int
00125 EventBase::SaveBuffer(char buf[], unsigned int len) const {
00126   unsigned int origlen=len;
00127   unsigned int used=0;
00128   if(0==(used=saveCreator("EventBase",buf,len))) return 0;
00129   len-=used; buf+=used;
00130   if(0==(used=encode(stim_id,buf,len))) return 0;
00131   len-=used; buf+=used;
00132   if(0==(used=encode(magnitude,buf,len))) return 0;
00133   len-=used; buf+=used;
00134   if(0==(used=encode(timestamp,buf,len))) return 0;
00135   len-=used; buf+=used;
00136   if(0==(used=encode(nameisgen,buf,len))) return 0;
00137   len-=used; buf+=used;
00138   if(0==(used=encode((char)genID,buf,len))) return 0;
00139   len-=used; buf+=used;
00140   if(0==(used=encode((char)typeID,buf,len))) return 0;
00141   len-=used; buf+=used;
00142   if(0==(used=encode(sourceID,buf,len))) return 0;
00143   len-=used; buf+=used;
00144   if(0==(used=encode(duration,buf,len))) return 0;
00145   len-=used; buf+=used;
00146   return origlen-len;
00147 }
00148 
00149 void
00150 EventBase::genName() {
00151   if(!nameisgen)
00152     return;
00153   if(genID<numEGIDs) {
00154     stim_id=std::string("Evt_");
00155     stim_id+=EventGeneratorNames[genID];
00156   } else {
00157     stim_id=std::string("Evt_InvalidGen");
00158     stim_id+=genID; 
00159   }
00160   stim_id+="::";
00161   char tmp[16];
00162   snprintf(tmp,16,"0x%x",sourceID);
00163   stim_id+=tmp;
00164 }
00165 
00166 /*! @file
00167  * @brief Implements EventBase, the basic class for sending events around the system
00168  * @author ejt (Creator)
00169  *
00170  * $Author: ejt $
00171  * $Name: tekkotsu-2_2_1 $
00172  * $Revision: 1.19 $
00173  * $State: Exp $
00174  * $Date: 2004/09/28 23:07:02 $
00175  */
00176 

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:38 2004 by Doxygen 1.3.9.1