Commit 4e8b7634 authored by Locatelli's avatar Locatelli
Browse files

Psl driver simulated:

Add possibility to load image from tif file
parent 624a7ea0
<module name="psl">
<driver class="psl::PslDriver"/>
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
<link path="/usr/lib/x86_64-linux-gnu" lib="tiff"/>
</module>
......@@ -24,6 +24,7 @@
#include "PerfectPslDriver.h"
#include "PslDef.h"
#include "RealPslDriver.h"
#include "SimulatedPslDriver.h"
using namespace std;
......@@ -41,7 +42,7 @@ PslDriver::PslDriver(const string& name):
acquisition::DetectorCommon(name)
{
registerStates(new RealPslDriver(this), new PerfectPslDriver(this), new PerfectPslDriver(this));
registerStates(new RealPslDriver(this), new PerfectPslDriver(this), new SimulatedPslDriver(this));
driver::SocketTcp::init(name);
......@@ -56,7 +57,8 @@ PslDriver::PslDriver(const string& name):
gain.init(this, SAVE, "gain");
nbFrame.init(this, SAVE, "nbFrame");
bpixel.init(this, SAVE, "bpixel");
fileSimu.init(this, SAVE, "file_simu");
indexSimu.init(this, SAVE, "index_simu");
initCommand(driver::INIT_COMMAND);
initCommand(driver::READ_COMMAND);
......@@ -83,7 +85,6 @@ PslDriver::PslDriver(const string& name):
registerObserverCommand(COMMAND_STATUS_DEVICE_CONTAINER, 50);
registerObserverCommand(COMMAND_READ_DEVICE_CONTAINER, 50);
registerSpyCommand(COMMAND_READ_DEVICE_CONTAINER, 5);
}
/*
......
......@@ -85,6 +85,10 @@ public:
Property<int32> bpixel;
Property<int32> gain;
Property<std::string> fileSimu;
Property<int32> indexSimu;
private:
/*!
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "SimulatedPslDriver.h"
#include <stdlib.h>
#include "tiffio.h"
#include "PslDef.h"
#include "PslDriver.h"
namespace psl {
/*
* Constructor
*/
SimulatedPslDriver::SimulatedPslDriver(PslDriver* owner) :
PslState(owner) {
/* Empty */
}
/*
* Destructor
*/
SimulatedPslDriver::~SimulatedPslDriver() {
/* Empty */
}
void SimulatedPslDriver::init() {
}
/*
* clearvme/daugther/Psl
*/
void SimulatedPslDriver::clear() {
// Read command
owner()->time = 0;
owner()->counts = 0;
owner()->counts2 = 0;
owner()->counts3 = 0;
}
/*
* writeParam
*/
void SimulatedPslDriver::writeParam() {
}
/*
* synchroniseRead
*/
void SimulatedPslDriver::synchroniseRead() {
read();
owner()->m_SynchroniseReadTerminated = true;
}
/*
* read
*/
void SimulatedPslDriver::read() {
int32 size = owner()->dataSize();
int32 *tab = owner()->data();
float64 sum = 0;
boost::filesystem::path file = owner()->fileSimu();
TIFF* tif = TIFFOpen(file.string().c_str(), "r");
if (tif) {
int32 dircount = 0;
while (dircount < owner()->indexSimu()) {
if (TIFFReadDirectory(tif) <= 0) break;
++dircount;
};
uint32 w, h;
int32 npixels;
tdata_t buf;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
npixels = w * h;
if (npixels == size) {
tmsize_t scanlinesize = TIFFScanlineSize(tif);
buf = _TIFFmalloc(scanlinesize);
if (buf != NULL) {
uint16* data;
for (uint32 row = 0; row < h; row++) {
TIFFReadScanline(tif, buf, row, 0);
data = (uint16*) buf;
for(uint32 i = 0; i < w;++i) {
tab[row + i * h] = data[i];
sum = sum + data[i];
}
}
owner()->sum = sum;
owner()->data.sendEvent();
_TIFFfree(buf);
}
}
TIFFClose(tif);
}
// Read command
// for (int32 i = 0; i < size; i++) {
// tab[i] = i;
// sum = sum + tab[i];
// }
}
/*
* pause
*/
void SimulatedPslDriver::pause() {
}
/*
* continue
*/
void SimulatedPslDriver::resume() {
}
/*
* start
*/
void SimulatedPslDriver::start() {
owner()->time = owner()->time.setpoint();
}
/*
* stop
*/
void SimulatedPslDriver::stop() {
}
/*
* readStatus
*/
void SimulatedPslDriver::readStatus() {
owner()->startActivated = false;
// Status command
owner()->computeGateStatus(psl::READOUT_COMPLETE);
owner()->computeAcquisitionStatus(0);
owner()->computeDetectorStatus(0);
if (owner()->m_SynchroniseReadActivated == true) {
if (owner()->m_SynchroniseReadTerminated == true) {
owner()->m_SynchroniseReadActivated = false;
owner()->m_SynchroniseReadTerminated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
} else {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
/*
* readInfos
*/
void SimulatedPslDriver::readInfos() {
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef SIMULATEDPSLDRIVER_H
#define SIMULATEDPSLDRIVER_H
#include "PslState.h"
namespace psl {
/*!
* \class SimulatedPslDriver
* \brief Simulated implementation class for the Psl device driver
*
* This class is a perfect implementation of Psl device driver.
* On start command, all actual values become target's ones.
*/
class SimulatedPslDriver: public PslState {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
SimulatedPslDriver(PslDriver* owner);
/*!
* \brief Destructor
*/
virtual ~SimulatedPslDriver();
/*!
* \brief Init command implementation
*/
virtual void init();
/*!
* \brief Clear command implementation
*/
virtual void clear();
/*!
* \brief Write Param command implementation
*/
virtual void writeParam();
/*!
* \brief Read command implementation
*/
virtual void read();
/*!
* \brief Synchronize Read command implementation
*/
virtual void synchroniseRead();
/*!
* \brief Start command implementation
*/
virtual void start();
/*!
* \brief Resume command implementation
*/
virtual void resume();
/*!
* \brief Pause command implementation
*/
virtual void pause();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief Read Infos command implementation
*/
virtual void readStatus();
/*!
* \brief Read Infos command implementation
*/
virtual void readInfos();
};
}
#endif //SIMULATEDPSLDRIVER_H
......@@ -125,3 +125,5 @@ startstop.pauseImage=WARNING_STATUS
psl.version=Version
psl.precision=Frequency
psl.filenamePrefix=Tif File
psl.index_simuPrefix=Image index
\ No newline at end of file
......@@ -2,10 +2,10 @@
<controller type="psl">
<property name="gate_wanted_time" type="Double" max_length="8">
<property name="gate_wanted_time" type="float64" max_length="8">
</property>
<property name="gate_actual_time" type="Double" max_length="8" >
<property name="gate_actual_time" type="float64" max_length="8" >
</property>
<property name="status" type="Long">
</property>
......@@ -18,5 +18,11 @@
<property name="nbFrame" type="Long">
</property>
<property name="state" type="string">
</property>
<property name="file_simu" type="string" max_length="50">
</property>
<property name="index_simu" type="int32">
</property>
</controller>
<plugin>
<controller type="psl" role="psl1" />
<property_switcher role="psl1" property="state" switcher_key="psl.stateSwitchKey" />
<label role="psl1" property="version" prefix="psl.version" />
<newLine />
......@@ -28,7 +29,10 @@
</group>
<newLine />
<switchable_composite switch_values="simulated" switcher_key="psl.stateSwitchKey">
<file_text role="psl1" property="file_simu" prefix="psl.filenamePrefix" extensions="dat"/>
<text role="psl1" property="index_simu" prefix="psl.index_simuPrefix" />
</switchable_composite>
<summary>
<summary_content>
......
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