00001 00002 #include "AnalogDelayObject.h" 00003 00004 #include <iostream> 00005 using std::cerr; 00006 using std::endl; 00007 00008 00009 AnalogDelayObject::AnalogDelayObject(delay_t minimumDelay) 00010 : minDelay(minimumDelay) 00011 { 00012 delay_queue = NULL; 00013 addedForAdvanceCycle = false; 00014 maxDelay = 1; 00015 } 00016 00017 AnalogDelayObject::~AnalogDelayObject() 00018 { 00019 if (delay_queue != NULL) 00020 delete delay_queue; 00021 } 00022 00023 00024 void AnalogDelayObject::announceDelayedRead(delay_t delay) 00025 { 00026 if (delay > maxDelay) 00027 maxDelay = delay; 00028 } 00029 00030 int AnalogDelayObject::init(InitializeInfo *ii) 00031 { 00032 delay_queue = new CircularQueue<double>(maxDelay + minDelay, 0); 00033 output = 0; 00034 return 0; 00035 } 00036 00037 int AnalogDelayObject::initDistributedMode() 00038 { 00039 delay_queue = new CircularQueue<double>(maxDelay, 0); 00040 output = 0; 00041 return 0; 00042 } 00043 00044 int AnalogDelayObject::reset( double dt ) 00045 { 00046 output = 0; 00047 delay_queue->reset(0); 00048 return 0; 00049 } 00050 00051 void AnalogDelayObject::setAnalogInput(double value, analog_port_id_t port) 00052 { 00053 input = value; 00054 } 00055 00056 double AnalogDelayObject::getAnalogOutput(analog_port_id_t port) const 00057 { 00058 return delay_queue->get(port-1); 00059 } 00060 00061 void AnalogDelayObject::advanceCycle() 00062 { 00063 delay_queue->moveMark(minDelay); 00064 } 00065 00066 00067 int AnalogDelayObject::advance(AdvanceInfo const &ai) 00068 { 00069 delay_queue->put(input); 00070 output = delay_queue->get(); 00071 return 0; 00072 } 00073 00074 int AnalogDelayObject::getFieldOffset(string fieldname) 00075 { 00076 if (fieldname == "input") 00077 return reinterpret_cast<char *>(&(this->input)) - reinterpret_cast<char *>(this); 00078 00079 if (fieldname == "output") 00080 return reinterpret_cast<char *>(&(this->output)) - reinterpret_cast<char *>(this); 00081 00082 return -1; 00083 } 00084 00085