Commit 9b0da85a authored by Cristina Cocho's avatar Cristina Cocho
Browse files

Improved CountWithSpectro "special" module

parent 28501f10
......@@ -18,6 +18,8 @@
#include "CountWithSpectro.h"
#include "controllers/common/family/Families.h"
#include "PersistenceServices/DataFile/NexusDataFile.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <common/base/Date.h>
namespace d22special {
......@@ -35,7 +37,7 @@ CountWithSpectro::CountWithSpectro(const std::string & name) :
spectro.init(this, "spectro");
count.init(this, "count");
integrationTime.init(this, SAVE, "integration_time"); //It is in seconds!
integrationTime.init(this, SAVE, "integration_time"); //in microseconds!
numSpectroMeasures.init(this, SAVE, "num_spectro");
timeType.init(this, SAVE, "time_type");
countTime.init(this, SAVE, "count_time");
......@@ -45,7 +47,8 @@ CountWithSpectro::CountWithSpectro(const std::string & name) :
zSize.init(this, SAVE, "z_size");
totalYData.init(this, NOSAVE, "total_yData");
initialTime.init(this, NOSAVE, "initial_time");
measureDuration.init(this, NOSAVE, "measure_duration");
}
CountWithSpectro::~CountWithSpectro() {
......@@ -64,6 +67,8 @@ void CountWithSpectro::postConfiguration() {
void CountWithSpectro::refreshNumSpectroMeasures(int32 number) {
ySize = number; //This property is only used to save the data in nexus file
//initialize here the dynamic properties
measureDuration.resize(number);
}
void CountWithSpectro::updateProgression() {
......@@ -71,12 +76,11 @@ void CountWithSpectro::updateProgression() {
}
void CountWithSpectro::start() {
//Important! convert the time (seconds) into microseconds -> the driver needs it in that unit
float64 timeInMicrosec = integrationTime() * 1000000;
spectro->integrationTime = timeInMicrosec;
//Time already in microseconds!
spectro->integrationTime = integrationTime();
//check the total time of spectro measurement is smaller than the count time
float64 spectroTime = integrationTime() * numSpectroMeasures();
float64 spectroTime = integrationTime() * 0.000001 * numSpectroMeasures(); //should be in seconds
float64 countTime = getCountTimeInSec(); //count->time.setpoint();
if (spectroTime < countTime) {
......@@ -110,8 +114,8 @@ void CountWithSpectro::start() {
void CountWithSpectro::stop() {
if (commandStatus.isRunning()) {
count->stopCommand();
spectro->stopCommand();
count->stopParallel();
spectro->stopParallel();
}
commandStatus.setWarning();
......@@ -124,7 +128,6 @@ void CountWithSpectro::saveSpectroData() {
int32 numor = any_cast<int32>(count->getValue("numor"));
NexusDataFile::appendTo(numor, "NxD22SpecialServerFile.xml", "NxD22SpecialClientFile.xml");
}
void CountWithSpectro::startCount() {
......@@ -133,16 +136,26 @@ void CountWithSpectro::startCount() {
void CountWithSpectro::startSpectro() {
common::Date startTime = common::Date();
initialTime = startTime.toString("%H:%M:%S");
common::Date formerTime = startTime;
for (int i = 0; i < numSpectroMeasures(); i++) {
if (commandStatus.isRunning()) {
common::Date time = common::Date();
common::Duration duration = time - formerTime;
measureDuration.set(i, duration.getMilliseconds());
spectro->startCommand();
int32 ySize = spectro->yData.getSize(); //be careful, maybe the driver gives us a different size
int32 ySize = YSIZE;
float64* tempYData = spectro->yData();
for (int32 j = 0; j < ySize; j++) {
m_totalYData[ySize * i + j] = tempYData[j];
}
formerTime = time;
}
}
}
......@@ -163,6 +176,7 @@ void CountWithSpectro::initArray() {
memset(m_totalYData, 0, totalSize * sizeof(int32)); //set to zero
totalYData.update(m_totalYData);
totalYData.setSize(totalSize);
}
float64 CountWithSpectro::getCountTimeInSec() {
......
......@@ -55,6 +55,8 @@ public:
Property<int32> zSize;
ArrayProperty<int32> totalYData;
DynamicProperty<int32> measureDuration;
Property<std::string> initialTime;
void refreshNumSpectroMeasures(int32 number);
void updateProgression();
......
count_with_spectro.integration_timePrefix=Integration time
count_with_spectro.integration_timeSuffix=s
count_with_spectro.integration_timeSuffix=~mus
count_with_spectro.numSpectro=Num. Spectros
count_with_spectro.countTime=Time
......
<plugin>
<controller type="count_with_spectro" role="count_with_spectro1" />
<text role="count_with_spectro1" property="count_time" prefix="count_with_spectro.countTime"/>
<text role="count_with_spectro1" property="count_time" prefix="count_with_spectro.countTime" key="countTimeText"/>
<radio role="count_with_spectro1" property="time_type" valuesAndLabels="count_with_spectro.h,count_with_spectro.m,count_with_spectro.s" spaceBefore="false" />
<text role="count_with_spectro1" property="integration_time" prefix="count_with_spectro.integration_timePrefix" suffix="count_with_spectro.integration_timeSuffix"/>
<text role="count_with_spectro1" property="num_spectro" prefix="count_with_spectro.numSpectro"/>
<text role="count_with_spectro1" property="integration_time" prefix="count_with_spectro.integration_timePrefix" suffix="count_with_spectro.integration_timeSuffix" key="spectroTimeText"/>
<text role="count_with_spectro1" property="num_spectro" prefix="count_with_spectro.numSpectro" key="numSpectroMeasuresText"/>
</plugin>
\ No newline at end of file
<controller_plugin_config type="count_with_spectro">
<image key="COUNT"/>
<settings view="count_with_spectroView.xml"/>
<command view="count_with_spectroCommandView.xml"/>
<image key="COUNT" />
<settings view="count_with_spectroView.xml">
<swt_plugin_peer class="SWTCountWithSpectroControllerSetupPluginPeer" />
</settings>
<command view="count_with_spectroCommandView.xml">
<swt_plugin_peer class="SWTCountWithSpectroControllerCommandPluginPeer" />
</command>
</controller_plugin_config>
\ No newline at end of file
<controller type="count_with_spectro">
<property name="num_spectro" type="int32" max_length="3"/>
</controller>
\ No newline at end of file
<plugin>
<controller type="count_with_spectro" role="count_with_spectro1" />
<group title="count_with_spectro.countGroup">
<text role="count_with_spectro1" property="count_time" prefix="count_with_spectro.countTime"/>
<text role="count_with_spectro1" property="count_time" prefix="count_with_spectro.countTime" key="countTimeText"/>
<radio role="count_with_spectro1" property="time_type" valuesAndLabels="count_with_spectro.h,count_with_spectro.m,count_with_spectro.s" spaceBefore="false" />
</group>
<newline />
<group title="count_with_spectro.spectroGroup">
<text role="count_with_spectro1" property="integration_time" prefix="count_with_spectro.integration_timePrefix" suffix="count_with_spectro.integration_timeSuffix"/>
<text role="count_with_spectro1" property="num_spectro" prefix="count_with_spectro.numSpectro"/>
<text role="count_with_spectro1" property="integration_time" prefix="count_with_spectro.integration_timePrefix" suffix="count_with_spectro.integration_timeSuffix" key="spectroTimeText"/>
<text role="count_with_spectro1" property="num_spectro" prefix="count_with_spectro.numSpectro" key="numSpectroMeasuresText"/>
</group>
</plugin>
\ No newline at end of file
......@@ -18,7 +18,7 @@
#include "QE65000Driver.h"
#include "RealQE65000Driver.h"
#include "PerfectQE65000Driver.h"
#include "SimulatedQE65000Driver.h"
#include "QE65000State.h"
#include "drivers/global/DriversCommands.h"
......@@ -33,7 +33,7 @@ QE65000Driver::QE65000Driver(const std::string& name) : DeviceDriver(name) {
registerParentFunction(RS232_FUNCTION); //need to specify parent function
//Register states --> up to now only RealState
registerStates(new RealQE65000Driver(this), new PerfectQE65000Driver(this), new PerfectQE65000Driver(this));
registerStates(new RealQE65000Driver(this), new SimulatedQE65000Driver(this), new SimulatedQE65000Driver(this));
//Init Properties
integrationTime.init(this, SAVE, "integration_time");
......
......@@ -30,7 +30,7 @@ public:
static const int32 PLUGGED;
static const int32 UNPLUGGED;
Property<int32> integrationTime;
Property<int32> integrationTime; //Time in microseconds!!
Property<bool> isActive;
ArrayProperty<float64> yData;
......
......@@ -16,32 +16,48 @@
* limitations under the Licence.
*/
#include "PerfectQE65000Driver.h"
#include "SimulatedQE65000Driver.h"
namespace oceanoptics {
PerfectQE65000Driver::PerfectQE65000Driver(QE65000Driver* owner) : QE65000State(owner) {
SimulatedQE65000Driver::SimulatedQE65000Driver(QE65000Driver* owner) : QE65000State(owner) {
}
PerfectQE65000Driver::~PerfectQE65000Driver() {
SimulatedQE65000Driver::~SimulatedQE65000Driver() {
}
void PerfectQE65000Driver::init() {
void SimulatedQE65000Driver::init() {
}
void PerfectQE65000Driver::measure() {
cout << "measuring in perfect mode!" << endl;
void SimulatedQE65000Driver::measure() {
//Simulate integrationTime taken into account
usleep(owner()->integrationTime());
//Assume spectrum length is always the same (1044)
int32 length = 1044;
float64* tempXData = new float64[length];
float64* tempYData = new float64[length];
for (int32 j = 0; j < length; j++) {
tempXData[j] = j;
tempYData[j] = j + 100;
}
owner()->xData.set(tempXData);
owner()->xData.setSize(length);
owner()->yData.set(tempYData);
owner()->yData.setSize(length);
}
void PerfectQE65000Driver::stop() {
cout << "stopping in perfect mode"<< endl;
void SimulatedQE65000Driver::stop() {
m_owner->sendProgressEvent(PROGRESSION_END_DEVICE_CONTAINER);
}
void PerfectQE65000Driver::readStatus() {
void SimulatedQE65000Driver::readStatus() {
// cout << "reading status in perfect mode" << endl;
}
......
......@@ -24,11 +24,11 @@
namespace oceanoptics {
class PerfectQE65000Driver: public QE65000State {
class SimulatedQE65000Driver: public QE65000State {
public:
PerfectQE65000Driver(QE65000Driver* owner);
virtual ~PerfectQE65000Driver();
SimulatedQE65000Driver(QE65000Driver* owner);
virtual ~SimulatedQE65000Driver();
virtual void init();
virtual void measure();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment