AnalogRecorder.cpp

Go to the documentation of this file.
00001 
00002 #include "AnalogRecorder.h"
00003 
00004 #include <iostream>
00005 using std::cerr;
00006 using std::endl;
00007 
00008 AnalogRecorder::AnalogRecorder(unsigned samplingTime)
00009   : samplingTime(samplingTime), input(0), summationPoint(0), stepsLeftBeforeSample(samplingTime)
00010 {
00011         
00012 }
00013 
00014 AnalogRecorder::~AnalogRecorder()
00015 {
00016 
00017 }
00018 
00019 
00020 void AnalogRecorder::setAnalogInput(double v, analog_port_id_t port)
00021 {
00022 //      cerr << "recorder set analog input port = " << port << " value = " << v << endl;
00023         if (isActive) 
00024                 summationPoint += v + port;
00025 }
00026 
00027 void AnalogRecorder::setActive(bool active)
00028 {
00029         isActive = active;
00030         if (isActive) {
00031                 summationPoint = 0;
00032                 input = 0;
00033                 stepsLeftBeforeSample = 0;
00034         }
00035                 
00036 }
00037 
00038 
00039 int AnalogRecorder::advance( AdvanceInfo const & )
00040 {
00041 //      cerr << " analog recorder " << this << " advance " << endl;
00042 //      cerr << "analog recorder " << this << " input value = " << input << endl;
00043     if (isActive) {
00044                 summationPoint += input;
00045         //      cerr << "analog recorder " << this << " summationPoint = " << summationPoint << endl;
00046             if (!stepsLeftBeforeSample) {
00047                         values.push_back(summationPoint);
00048                         stepsLeftBeforeSample = samplingTime;
00049             }
00050                 stepsLeftBeforeSample --;    
00051                 summationPoint = 0;
00052                 input = 0;
00053     }
00054         return 0;
00055 }
00056 
00057 int AnalogRecorder::reset( double dt )
00058 {
00059         summationPoint = 0;
00060         stepsLeftBeforeSample = 0;
00061         values.clear();
00062         input = 0;
00063         isActive = true;
00064         return 0;
00065 }
00066 
00067 /* int AnalogRecorder::getFieldOffset(string fieldname)
00068 {
00069         if (fieldname == "input")
00070                 return reinterpret_cast<char *>(&this->input) - reinterpret_cast<char *>(this);
00071     else {
00072         throw( PCSIM::ConstructionException("AnalogRecorder::getFieldOffset() ", "No field named \'" + fieldname + "\' in class " ) );
00073     }
00074     return -1;
00075 } */
00076 
00077 const vector<double> & AnalogRecorder::getRecordedValues() const
00078 {
00079     return values;
00080 }
00081 
00082 vector<double> & AnalogRecorder::analogVec()
00083 {
00084     return values;
00085 }
00086 
00087 
00088 void AnalogRecorder::printAnalogValues() const
00089 {
00090     for (unsigned i = 0 ; i < values.size() ; ++i) {
00091         cerr << values[i] << " ";
00092     }
00093     cerr << endl;
00094 }
00095 

Generated on Wed Jul 9 16:34:38 2008 for PCSIM by  doxygen 1.5.5