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

Tekkotsu v1.5
Generated Fri Oct 10 15:51:58 2003 by Doxygen 1.3.4