FileSystemSensorSource.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_FileSystemSensorSource_h_
00003 #define INCLUDED_FileSystemSensorSource_h_
00004
00005 #include "FileSystemDataSource.h"
00006 #include "Motion/PostureEngine.h"
00007
00008
00009 class FileSystemSensorSource : public FileSystemDataSource {
00010 public:
00011
00012 FileSystemSensorSource(LoggedDataDriver& p, const std::string& filter) : FileSystemDataSource(p,filter) {}
00013
00014 virtual void registerSource() {
00015 FileSystemDataSource::registerSource();
00016 for(unsigned int i=0; i<NumOutputs; i++)
00017 providingOutput(i);
00018 }
00019
00020 virtual void deregisterSource() {
00021 for(unsigned int i=0; i<NumOutputs; i++)
00022 ignoringOutput(i);
00023 FileSystemDataSource::deregisterSource();
00024 }
00025
00026 protected:
00027 virtual bool sendData() {
00028 SensorInfo& sensors = dynamic_cast<SensorInfo&>(**curfile);
00029 if(!sensors.isValid())
00030 return false;
00031
00032 MarkScope l(getSensorWriteLock());
00033 for(unsigned int i=0; i<NumOutputs; ++i)
00034 if(sensors.getOutput(i).weight>0)
00035 setOutputValue(i, sensors.getOutput(i).value);
00036 for(std::map<unsigned int,float>::const_iterator it=sensors.getButtons().begin(); it!=sensors.getButtons().end(); ++it)
00037 setButtonValue(it->first, it->second);
00038 for(std::map<unsigned int,float>::const_iterator it=sensors.getSensors().begin(); it!=sensors.getSensors().end(); ++it)
00039 setSensorValue(it->first, it->second);
00040 for(std::map<unsigned int,float>::const_iterator it=sensors.getPIDDuties().begin(); it!=sensors.getPIDDuties().end(); ++it)
00041 setPIDDutyValue(it->first, it->second);
00042 return true;
00043 }
00044
00045
00046 class SensorInfo : public FileInfo {
00047 public:
00048
00049 SensorInfo(const std::string& name, double time) : FileInfo(name,time), pose(), sensors(), valid(false) {}
00050
00051
00052 virtual void prepare() {
00053 if(pose.getLoadedSensors()==NULL) {
00054 pose.setLoadedSensors(&sensors);
00055 FileInfo::prepare();
00056 if(data==NULL)
00057 return;
00058 valid = pose.loadBuffer(data,size,filename.c_str());
00059 }
00060 }
00061 virtual void release() {
00062 pose.setLoadedSensors(NULL);
00063 valid=false;
00064 }
00065
00066 bool isValid() const { return valid; }
00067 const OutputCmd& getOutput(unsigned int i) const { return pose(i); }
00068 const std::map<unsigned int,float>& getButtons() const { return sensors.buttons; }
00069 const std::map<unsigned int,float>& getSensors() const { return sensors.sensors; }
00070 const std::map<unsigned int,float>& getPIDDuties() const { return sensors.pidduties; }
00071
00072 protected:
00073 PostureEngine pose;
00074 PostureEngine::SensorInfo sensors;
00075 bool valid;
00076 };
00077
00078 virtual void enqueueFile(const std::string& name, double lifetime) { files.push_back(new SensorInfo(name,lifetime)); }
00079 };
00080
00081
00082
00083
00084
00085
00086 #endif