Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

EventBase.cc

Go to the documentation of this file.
00001 #include "EventBase.h"
00002 #include <stdio.h>
00003 
00004 const char* const EventBase::EventGeneratorNames[numEGIDs] = {
00005   "UnknownGen",
00006   "Vision",
00007   "Button",
00008   "WorldModel",
00009   "AI",
00010   "Audio",
00011   "Sensor",
00012   "Power",
00013   "Timer",
00014   "StateMachine",
00015   "Locomotion",
00016   "TextMsg",
00017   "EStop",
00018   "MotionManager"
00019 };
00020 
00021 
00022 EventBase::EventBase()
00023   : LoadSave(), stim_id(), magnitude(0), timestamp(get_time()), nameisgen(true), genID(unknownEGID), typeID(statusETID), sourceID((unsigned int)-1), duration(0)
00024 {
00025   genName();
00026 }
00027 
00028 EventBase::EventBase(EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur)
00029   : LoadSave(), stim_id(), magnitude(0), timestamp(get_time()), nameisgen(true), genID(gid), typeID(tid), sourceID(sid), duration(dur)
00030 {
00031   genName();
00032   if(tid==deactivateETID)
00033     setMagnitude(0.0);
00034   else
00035     setMagnitude(1.0);
00036 }
00037 
00038 EventBase::EventBase(EventGeneratorID_t gid, unsigned int sid, EventTypeID_t tid, unsigned int dur, const std::string& n, float mag)
00039   : LoadSave(), stim_id(n), magnitude(mag), timestamp(get_time()), nameisgen(false), genID(gid), typeID(tid), sourceID(sid), duration(dur)
00040 {
00041   
00042 }
00043 
00044 
00045 unsigned int
00046 EventBase::getBinSize() const {
00047   unsigned int used=0;
00048   used+=creatorSize("EventBase");
00049   used+=stim_id.size()+stringpad;
00050   used+=sizeof(magnitude);
00051   used+=sizeof(timestamp);
00052   used+=sizeof(nameisgen);
00053   used+=sizeof(char);
00054   used+=sizeof(char);
00055   used+=sizeof(sourceID);
00056   used+=sizeof(duration);
00057   return used;
00058 }
00059 
00060 unsigned int
00061 EventBase::LoadBuffer(const char buf[], unsigned int len) {
00062   unsigned int origlen=len;
00063   unsigned int used=0;
00064   if(0==(used=checkCreator("EventBase",buf,len,true))) return 0;
00065   len-=used; buf+=used;
00066   if(0==(used=decode(stim_id,buf,len))) return 0;
00067   len-=used; buf+=used;
00068   if(0==(used=decode(magnitude,buf,len))) return 0;
00069   len-=used; buf+=used;
00070   if(0==(used=decode(timestamp,buf,len))) return 0;
00071   len-=used; buf+=used;
00072   if(0==(used=decode(nameisgen,buf,len))) return 0;
00073   len-=used; buf+=used;
00074   char tmp;
00075   if(0==(used=decode(tmp,buf,len))) return 0;
00076   genID=(EventGeneratorID_t)tmp;
00077   len-=used; buf+=used;
00078   if(0==(used=decode(tmp,buf,len))) return 0;
00079   typeID=(EventTypeID_t)tmp;
00080   len-=used; buf+=used;
00081   if(0==(used=decode(sourceID,buf,len))) return 0;
00082   len-=used; buf+=used;
00083   if(0==(used=decode(duration,buf,len))) return 0;
00084   len-=used; buf+=used;
00085   return origlen-len; 
00086 }
00087 
00088 unsigned int
00089 EventBase::SaveBuffer(char buf[], unsigned int len) const {
00090   unsigned int origlen=len;
00091   unsigned int used=0;
00092   if(0==(used=saveCreator("EventBase",buf,len))) return 0;
00093   len-=used; buf+=used;
00094   if(0==(used=encode(stim_id,buf,len))) return 0;
00095   len-=used; buf+=used;
00096   if(0==(used=encode(magnitude,buf,len))) return 0;
00097   len-=used; buf+=used;
00098   if(0==(used=encode(timestamp,buf,len))) return 0;
00099   len-=used; buf+=used;
00100   if(0==(used=encode(nameisgen,buf,len))) return 0;
00101   len-=used; buf+=used;
00102   if(0==(used=encode((char)genID,buf,len))) return 0;
00103   len-=used; buf+=used;
00104   if(0==(used=encode((char)typeID,buf,len))) return 0;
00105   len-=used; buf+=used;
00106   if(0==(used=encode(sourceID,buf,len))) return 0;
00107   len-=used; buf+=used;
00108   if(0==(used=encode(duration,buf,len))) return 0;
00109   len-=used; buf+=used;
00110   return origlen-len;
00111 }
00112 
00113 void
00114 EventBase::genName() {
00115   if(!nameisgen)
00116     return;
00117   if(genID<numEGIDs) {
00118     stim_id=std::string("Evt_");
00119     stim_id+=EventGeneratorNames[genID];
00120   } else {
00121     stim_id=std::string("Evt_InvalidGen");
00122     stim_id+=genID; 
00123   }
00124   stim_id+="::";
00125   char tmp[16];
00126   snprintf(tmp,16,"0x%x",sourceID);
00127   stim_id+=tmp;
00128   /*  switch(genID) {
00129   case unknownEGID:
00130     stim_id="Evt_UknownGen::"; break;
00131   case visionEGID:
00132     stim_id="Evt_Vision::"; break;
00133   case buttonEGID:
00134     stim_id="Evt_Button::"; break;
00135   case worldModelEGID:
00136     stim_id="Evt_WorldModel::"; break;
00137   case aiEGID:
00138     stim_id="Evt_AI::"; break;
00139   case audioEGID:
00140     stim_id="Evt_Audio::"; break;
00141   case sensorEGID:
00142     stim_id="Evt_Sensor::"; break;
00143   case powerEGID:
00144     stim_id="Evt_Power::"; break;
00145   case timerEGID:
00146     stim_id="Evt_Timer::"; break;
00147   case eventRouterEGID:
00148     stim_id="Evt_EventRouter::"; break;
00149   default:
00150     stim_id="Evt_InvalidGen"; stim_id+=genID; stim_id+="::"; break;
00151     }*/
00152   /*  stim_id+=sourceID;*/
00153   // don't want to do this because it will cause AI to see them as separate stimuli
00154   /*stim_id+="::";
00155     switch(typeID) {
00156     case activateETID:
00157     stim_id+="act"; break;
00158     case statusETID:
00159     stim_id+="stat"; break;
00160     case deactivateETID:
00161     stim_id+="deact"; break;
00162     default:
00163     stim_id+="inv"; break;
00164     }*/
00165 }
00166 
00167 /*! @file
00168  * @brief Implements EventBase, the basic class for sending events around the system
00169  * @author ejt (Creator)
00170  *
00171  * $Author: ejt $
00172  * $Name: tekkotsu-1_4_1 $
00173  * $Revision: 1.10 $
00174  * $State: Exp $
00175  * $Date: 2003/04/25 18:22:39 $
00176  */
00177 

Tekkotsu v1.4
Generated Sat Jul 19 00:06:30 2003 by Doxygen 1.3.2