Commit 427eb66b authored by Elaazzouzi Abdelali's avatar Elaazzouzi Abdelali
Browse files

first

parent 5363fff9
/*
* 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 "PerfectPslDriver.h"
#include <stdlib.h>
#include "PslDef.h"
#include "PslDriver.h"
namespace psl {
/*
* Constructor
*/
PerfectPslDriver::PerfectPslDriver(PslDriver* owner) :
PslState(owner) {
/* Empty */
}
/*
* Destructor
*/
PerfectPslDriver::~PerfectPslDriver() {
/* Empty */
}
void PerfectPslDriver::init() {
}
/*
* clearvme/daugther/Psl
*/
void PerfectPslDriver::clear() {
// Read command
owner()->time = 0;
owner()->counts = 0;
owner()->counts2 = 0;
owner()->counts3 = 0;
}
/*
* writeParam
*/
void PerfectPslDriver::writeParam() {
}
/*
* synchroniseRead
*/
void PerfectPslDriver::synchroniseRead() {
read();
owner()->m_SynchroniseReadTerminated = true;
}
/*
* read
*/
void PerfectPslDriver::read() {
// Read command
int32 size = owner()->dataSize();
int32 *tab = owner()->data();
int32 sum = 0;
// if (m_FirstRead) {
// for (uint32 i=0;i<size;i++) {
// tab[i] = i + 1;
// sum = sum + tab[i];
// }
// m_FirstRead = false;
// } else {
// for (uint32 i=0;i<size;i++) {
// tab[i] = tab[i] + 1;
// sum = sum + tab[i];
// }
// }
for (int32 i = 0; i < size; i++) {
tab[i] = i;
sum = sum + tab[i];
}
owner()->sum = sum;
owner()->data.sendEvent();
}
/*
* pause
*/
void PerfectPslDriver::pause() {
}
/*
* continue
*/
void PerfectPslDriver::resume() {
}
/*
* start
*/
void PerfectPslDriver::start() {
owner()->time = owner()->time.setpoint();
}
/*
* stop
*/
void PerfectPslDriver::stop() {
}
/*
* readStatus
*/
void PerfectPslDriver::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 PerfectPslDriver::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 PERFECTPSLDRIVER_H
#define PERFECTPSLDRIVER_H
#include "PslState.h"
namespace psl {
/*!
* \class PerfectPslDriver
* \brief Perfect 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 PerfectPslDriver: public PslState {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PerfectPslDriver(PslDriver* owner);
/*!
* \brief Destructor
*/
virtual ~PerfectPslDriver();
/*!
* \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 //PERFECTPSLDRIVER_H
/*
* 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 PSLDEF_H
#define PSLDEF_H
namespace psl {
static const std::string MILLISEC = "Millisec";
static const std::string SECOND = "Second";
static const std::string STANDARD = "Standard"; // turn the camera Standard'
static const std::string AVERAGE = "Average"; // turn the camera Average'
static const std::string SUMMATION = "Summation"; // turn the camera Summation'
static const std::string ACCUMULATION = "Accumulation"; // turn the camera Accumulation'
static const std::string OPEN = "Open"; // turn the camera on'
static const std::string CLOSE = "Close"; // turn the camera off
static const std::string RESET= "Reset"; //turn off then turn on the camera
static const std::string SNAP = "Snap"; //Capture an image
static const std::string ABORT_SNAP = "AbortSnap"; //'AbortSnap' => Abort an image acquisition
static const std::string SAVE_IMG = "Save"; //'Save' => save the captured image at:
static const std::string FILE_DIRECTORY = "FileDirectory"; //'FileDirectory'\ 'FilePreffix'+'FileRefNumber'+'.'+'FileFormat'
static const std::string CONNECTED = "CLIENT_CONNECTED"; //'CLIENT_CONNECTED' => return: "!!!Welcome on PSL server!!!" (str)
static const std::string GET_IMAGE = "GetImage"; //'GetImage' => return: ((width,height), data) ((int,int),str)
static const std::string GET_MODE = "GetMode"; //'GetMode' => return: image data type. Could be {'L', 'I;16', 'I', 'F'}.
static const std::string GET_EXPOSURE = "GetExposure"; //'GetExposure' => return: Exposure (float) in milliseconds
static const std::string GET_BINNING = "GetBinning"; //'GetBinning' => return: (xbin,ybin) (int,int)
static const std::string GET_SUB_AREA = "GetSubArea"; //'GetSubArea' => return: (left,top,right,bottom) (int,int,int,int)
static const std::string GET_TRIGGER_MODE = "GetTriggerModes"; //'GetTriggerModes' => return: TriggerMode (str)
static const std::string GET_FILE_DIRECTORY = "GetFileDirectory"; //'GetFileDirectory' => return: FileDirectory (str)
static const std::string GET_FILE_PREFIX = "GetFilePreffix"; //'GetFilePreffix' => return: FilePreffix (str)
static const std::string GET_FILE_SUFFIX = "GetFileSuffix"; //'GetFileSuffix' => return: FileSuffix (str)
static const std::string GET_FILE_REF_NUMBER = "GetFileRefNumber"; //'GetFileRefNumber' => return: FileRefNumber (str)
static const std::string GET_FILE_FORMAT = "GetFileFormat"; //'GetFileFormat' => return: FileFormat (str)
static const std::string SET_EXPOSURE = "SetExposure"; //'SetExposure;1.33'
static const std::string SET_SHOW_AVERAGE = "SetShowAverage"; //'SetShowAverage;1.33'
static const std::string SET_AUTO_SAVE = "SetAutoSave"; //'SetAutoSave;1.33'
static const std::string SET_BRIGHTPIXEL = "SetBrightPixel"; //'SetBrightPixel'
static const std::string SET_NB_FRAME = "SetFrameNumber"; //'SetFrameNumber'
static const std::string SET_BINNING = "SetBinning"; //'SetBinning;2;2'
static const std::string SET_GAIN = "SetIntensifierGain"; //'SetIntensifierGain'
static const std::string SET_ACQ_MODE = "SetAcquisitionMode"; //'SetAcquisitionMode'
static const std::string SET_SUB_AREA = "SetSubArea"; //'SetSubArea;100;100;800;800'
static const std::string SET_TRIGGER_MODE = "SetTriggerModes"; //'SetTriggerModes
static const std::string SOFTWARE = "Software"; //trigger_modes = Software
static const std::string FREERUN = "FreeRunning"; //trigger_modes = FreeRunning
static const std::string HARDWARE_FALLING = "Hardware_Falling"; //trigger_modes =Hardware_Falling
static const std::string HARDWARE_RISING = "Hardware_Rising"; //trigger_modes =Hardware_Rising
static const std::string PIPLINE_FALLING = "Pipeline_Falling"; //trigger_modes =Pipeline_Falling
static const std::string PIPLINE_RISING = "Pipeline_Rising"; //trigger_modes =Pipeline_Rising
static const std::string PIPLINE_SOFTWARE = "Pipeline_Software"; //trigger_modes =Pipeline_Software
static const std::string SET_FILE_DIRECTORY = "SetFileDirectory"; //'SetFileDirectory;.'
static const std::string SET_FILE_PREFIX = "SetFilePreffix"; //'SetFilePreffix;pref'
static const std::string SET_FILE_SUFFIX = "SetFileSuffix"; //'SetFileSuffix;suf'
static const std::string SET_FILE_REF_NUMBER = "SetFileRefNumber"; //'SetFileRefNumber;1234'
static const std::string GET_FILE_RW_FLAG = "SetFileRWFlag"; //'SetFileRWFlag;True'
static const std::string SET_FILE_FORMAT = "SetFileFormat"; //'SetFileFormat;tiff'
static const std::string SEPARATOR = ";"; //Note: for all “Set*” commands use “;” as separator.
static const std::string WAIT_FOR_IMAGE = "WaitForImage"; //WaitForImage
enum
{
READOUT_NOT_ACTIVE = 0,
EXPOSURE_IN_PROGRESS,
READOUT_IN_PROGRESS,
READOUT_COMPLETE,
FRAME_AVAILABLE = READOUT_COMPLETE,
READOUT_FAILED,
ACQUISITION_IN_PROGRESS,
MAX_CAMERA_STATUS
};
enum
{
MILLISEC_MODE,
SECOND_MODE,
};
static const std::string RGB = "RGB";
static const std::string PNG = "PNG";
static const int32 RGB24BIT = 24;
static const int32 XSIZE = 1024;
static const int32 YSIZE = 768;
static const int32 COUNT_IGNORE = 3; // frame count for initilize camera
#define CAM_NAME_LEN 32
#define PARAM_SER_SIZE ((2<<16) + (6<<24) + 58)
#define PARAM_PAR_SIZE ((2<<16) + (6<<24) + 57)
#define ERROR_MSG_LEN 255
#define DEFAULT_TIME 0.1
#define DEFAULT_HEIGHT 2048
#define DEFAULT_WIDTH 2048
static const std::string TERMINATOR = "\r";
static const int32 COUNTING = 1;
static const int32 END = 2;
}
#endif //PSLDEF_H
/*
* 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 "PslDriver.h"
#include <math.h>
#include "PslState.h"
#include "PerfectPslDriver.h"
#include "PslDef.h"
#include "RealPslDriver.h"
using namespace std;
namespace psl {
const std::string PslDriver::TYPE = "psl";
const std::string PslDriver::ON_COMMAND = "on";
const std::string PslDriver::OFF_COMMAND = "off";
/*
* Constructor
*/
PslDriver::PslDriver(const string& name):
acquisition::NoTofAcquisitionCommon(name),acquisition::KineticAcquisitionCommon(name),
acquisition::TimeGateCommon(name),
acquisition::DetectorCommon(name)
{
registerStates(new RealPslDriver(this), new PerfectPslDriver(this), new PerfectPslDriver(this));
driver::SocketTcp::init(name);
/*
* Init the device command list
*/
address.init(this, SAVE, "address");
height.init(this, SAVE, "height");
width.init(this, SAVE, "width");
acqmode.init(this, SAVE, "acqmode");
readout.init(this, SAVE, "readout");
gain.init(this, SAVE, "gain");
initCommand(driver::INIT_COMMAND);
initCommand(driver::READ_COMMAND);
initCommand(driver::SYNCHRONIZE_READ_COMMAND);
initCommand(driver::START_COMMAND);
initCommand(driver::RESUME_COMMAND);
initCommand(driver::PAUSE_COMMAND);
initCommand(driver::STOP_COMMAND);
initCommand(driver::STATUS_COMMAND);
initCommand(driver::READ_INFOS_COMMAND);
initCommand(DetectorCommon::CLEAR_COMMAND);
initCommand(DetectorCommon::REGROUP_COMMAND);
initCommand(AcquisitionCommon::WRITE_PARAMETERS_COMMAND);
initCommand(driver::INIT_COMMAND);
initCommand(ON_COMMAND);
initCommand(OFF_COMMAND);
// Init functions
registerFunction(NONE_FUNCTION);
deviceType = LEAF_DEVICE_TYPE_DEVICE_CONTAINER;
m_DoSynchroniseRead = false;
m_SynchroniseReadActivated = false;
m_SynchroniseReadTerminated = false;
m_DataShort = NULL;
registerObserverCommand(COMMAND_STATUS_DEVICE_CONTAINER, 50);
registerObserverCommand(COMMAND_READ_DEVICE_CONTAINER, 50);
registerSpyCommand(COMMAND_READ_DEVICE_CONTAINER, 5);
}
/*
* Destructor
*/
PslDriver::~PslDriver() {
}
/*
* refreshDataSizeProperty
*/
void PslDriver::refreshDataSizeProperty(int32 value) throw (CannotSetValue) {
if (m_DataShort != NULL) {
delete[] m_DataShort;
}
m_DataShort = new uint16[value];
if (m_DataShort == NULL) {
sendErrorEvent(NOTENOUGH_MEMORY_ERROR, "Can't create data table");
throw CannotSetValue();
}
DetectorCommon::refreshDataSizeProperty(value);
}
/*
* refreshModeProperty
*/
void PslDriver::refreshModeProperty(int32 value) throw (CannotSetValue) {
if (value != acquisition::GateCommon::TIME_MODE) {
throw CannotSetValue();
}
}
/*
* execute
*/
void PslDriver::execute(const std::string& aCommand) {
if ((aCommand != driver::PAUSE_COMMAND) && (aCommand != driver::STOP_COMMAND) && (aCommand != driver::STATUS_COMMAND)
&& (aCommand != driver::READ_COMMAND)) {
commandProgression = PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER;
}
PslState* currentState = dynamic_cast<PslState*>(getCurrentState());
// Check command
if (aCommand == driver::INIT_COMMAND) {
// Init command
currentState->init();
} else if (aCommand == driver::READ_COMMAND) {
// Read command
currentState->read();
} else if (aCommand == driver::SYNCHRONIZE_READ_COMMAND) {
// Read command
if (m_DoSynchroniseRead == true) {
m_SynchroniseReadActivated = true;
m_SynchroniseReadTerminated = false;
currentState->synchroniseRead();
m_DoSynchroniseRead = false;
}
else {
m_SynchroniseReadActivated = false;
m_SynchroniseReadTerminated = false;
}
} else if (aCommand == driver::START_COMMAND) {
// Start command
startActivated = true;
m_DoSynchroniseRead = true;
currentState->start();
} else if (aCommand == driver::RESUME_COMMAND) {
// Continue command
currentState->resume();
} else if (aCommand == driver::PAUSE_COMMAND) {
// Stop command
currentState->pause();
} else if (aCommand == driver::STOP_COMMAND) {
// Stop command
currentState->stop();
startActivated = false;
} else if (aCommand == driver::STATUS_COMMAND) {
// Status command
currentState->readStatus();
} else if (aCommand == driver::READ_INFOS_COMMAND) {
// Info command
currentState->readInfos();
} else if (aCommand == DetectorCommon::CLEAR_COMMAND) {
// Move command
sum = 0;
currentState->clear();
} else if (aCommand == AcquisitionCommon::WRITE_PARAMETERS_COMMAND) {
// Write command
currentState->writeParam();
} else {
//Error bad command
//Todo , normaly it will be detect it device action driver
}
}
/*
* calculateProgression
*/
void PslDriver::calculateProgression() {
int32 progression = 0;
float64 setpoint = 0.0;
float64 actual = 0.0;
setpoint = time.setpoint();
actual = time();
if (setpoint == 0.0) {
commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
} else {
progression = (int32) (actual / setpoint * PROGRESSION_RATIO_DEVICE_CONTAINER);
// Be sure that progression > 0%
if (progression < PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER)
progression = 0;
// Be sure that only Phased status put 100%
if (progression >= PROGRESSION_END_DEVICE_CONTAINER)
progression = PROGRESSION_END_DEVICE_CONTAINER - 1;
commandProgression = progression;
}
}
/*
* PslDriver
*/
void PslDriver::computeGateStatus(int32 value) {
int32 valueout = 0;
if (value == COUNTING) {
valueout |= GateCommon::RUNNING_STATUS;
} else if (value == END) {
valueout |= GateCommon::END_STATUS;
}
status.update(value);
gateStatus.update(valueout);
}
/*
* PslDriver
*/
void PslDriver::computeDetectorStatus(int32 value) {