Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RemoteState.cc

Go to the documentation of this file.
00001 #include "Shared/RemoteState.h"
00002 #include "Events/RemoteRouter.h"
00003 #include "Events/EventRouter.h"
00004 #include "Events/DataEvent.h"
00005 
00006 const int RemoteState::sizes[] = {
00007     NumOutputs*sizeof(float),
00008   NumButtons*sizeof(float),
00009   NumSensors*sizeof(float),
00010 };
00011 
00012 RemoteState::RemoteState(const RemoteRouter *p) : parent(p) {
00013     unsigned int i = 0;
00014     for (i = 0; i < NumOutputs; i++)
00015         outputs[i] = 0;
00016 }
00017 
00018 RemoteState::~RemoteState() {
00019 
00020 }
00021 
00022 void RemoteState::update(char *data) {
00023     //Get the type of the data, a StateType
00024     StateType t = *(StateType *)data;
00025     data += sizeof(StateType);
00026 
00027     //Get the size of the data, an int
00028     int size = *(int *)data / sizeof(float);
00029     data += sizeof(int);
00030 
00031     //Set up the source and destination arrays
00032     float *src = (float *)data;
00033     float *dest;
00034     
00035     switch (t) {
00036     case OutputState:
00037         dest = outputs;
00038         break;
00039     default:
00040         return;
00041     }
00042 
00043     //Copy the values
00044     int i;
00045     for (i = 0; i < size; i++)
00046         dest[i] = src[i];
00047 
00048     //Post the event
00049   DataEvent<const RemoteState *> event(this, EventBase::remoteStateEGID,
00050                      t, EventBase::statusETID);
00051   
00052     erouter->postEvent(event);
00053 }
00054 

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:50 2016 by Doxygen 1.6.3