Commit 19f98e21 authored by yannick legoc's avatar yannick legoc
Browse files

migrated UsbPVCam driver

parent 19aa433c
......@@ -5,6 +5,12 @@ path=$currentPath/`dirname $0`
cd $path
# remove the deps directory if it exists
# necessary when some directories are moved
rm -fr obj/src/.deps
# remove the gen directory too
rm -fr gen
cd ../src
java -classpath ../build/modgen.jar generator.Main -config $NOMAD_MODULE_CONFIG
......
......@@ -5,4 +5,5 @@
<link path="/usr/lib/jvm/default-java/jre/lib/amd64/server" lib="jvm"/>
<include path="/opt/OmniDriver/include"/>
<include path="/usr/lib/jvm/default-java/include"/>
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
</module>
\ No newline at end of file
<module name="usbpvcam">
<driver class="UsbPVCamDriver"/>
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
<link lib="raw1394"/>
<link lib="pvcam"/>
</module>
\ No newline at end of file
/*
* 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 <stdlib.h>
#include "PerfectUsbPVCamDriver.h"
#include "UsbPVCamDriver.h"
#include "UsbPVCamDef.h"
#include "drivers/legacy/def/DetectorDef.h"
#include "drivers/legacy/def/GateDef.h"
// Trace include
using namespace boost;
/*
* Constructor
*/
PerfectUsbPVCamDriver::PerfectUsbPVCamDriver(UsbPVCamDriver* owner) :
UsbPVCamState(owner) {
/* Empty */
}
/*
* Destructor
*/
PerfectUsbPVCamDriver::~PerfectUsbPVCamDriver() {
/* Empty */
}
void PerfectUsbPVCamDriver::init() {
}
/*
* clearvme/daugther/UsbPVCam
*/
void PerfectUsbPVCamDriver::clear() const {
// Read command
m_owner->updateValue(GATE_ACTUAL_TIME_DEVICE_CONTAINER, 0.0);
m_owner->updateValue(GATE_ACTUAL_COUNTER1_DEVICE_CONTAINER, 0);
m_owner->updateValue(GATE_ACTUAL_COUNTER2_DEVICE_CONTAINER, 0);
m_owner->updateValue(GATE_ACTUAL_COUNTER3_DEVICE_CONTAINER, 0);
}
/*
* write
*/
void PerfectUsbPVCamDriver::write() const {
}
/*
* writeParam
*/
void PerfectUsbPVCamDriver::writeParam() const {
}
/*
* synchroniseRead
*/
void PerfectUsbPVCamDriver::synchroniseRead() {
read();
dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadTerminated = true;
}
/*
* read
*/
void PerfectUsbPVCamDriver::read() {
// Read command
uint32 size = static_cast<uint32> (any_cast<int32> (
m_owner->getValue(DETECTOR_DATA_SIZE_DEVICE_CONTAINER)));
uint32 *tab = reinterpret_cast<uint32*> (any_cast<int32*> (
m_owner->getValue(DETECTOR_DATA_DEVICE_CONTAINER)));
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 (uint32 i = 0; i < size; i++) {
tab[i] = i;
sum = sum + tab[i];
}
}
/*
* pause
*/
void PerfectUsbPVCamDriver::pause() {
}
/*
* continue
*/
void PerfectUsbPVCamDriver::continu() {
}
/*
* start
*/
void PerfectUsbPVCamDriver::start() {
m_owner->updateValue(GATE_ACTUAL_TIME_DEVICE_CONTAINER, any_cast<float64> (
m_owner->getValue(GATE_WANTED_TIME_DEVICE_CONTAINER)));
}
/*
* stop
*/
void PerfectUsbPVCamDriver::stop() {
}
/*
* readStatus
*/
void PerfectUsbPVCamDriver::readStatus() {
dynamic_cast<UsbPVCamDriver*> (m_owner)->m_StartActivated = false;
// Status command
m_owner->updateValue(STATUS_DEVICE_CONTAINER, (int32 ) pvcam::READOUT_COMPLETE);
// Set category status before ending, synchronism for controller
m_owner->setCategoryStatus();
if (dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadActivated
== true) {
if (dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadTerminated
== true) {
dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadActivated
= false;
dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadTerminated
= false;
m_owner->sendProgressEvent(PROGRESSION_END_DEVICE_CONTAINER);
}
} else {
m_owner->sendProgressEvent(PROGRESSION_END_DEVICE_CONTAINER);
}
}
/*
* readInfos
*/
void PerfectUsbPVCamDriver::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 PERFECTUSBPVCAMDRIVER_H
#define PERFECTUSBPVCAMDRIVER_H
#include "UsbPVCamState.h"
class UsbPVCamDriver;
/**
* Real Implementation part of the vme card called UsbPVCam made in Princeton. It needs a board called Men A201.
*/
class PerfectUsbPVCamDriver: public UsbPVCamState {
public:
/**
* Constructor.
*
* @param Link to the class which used the state
*/
PerfectUsbPVCamDriver(UsbPVCamDriver* owner);
/**
* Destructor.
*/
virtual ~PerfectUsbPVCamDriver();
/**
* Initialisation of the device.
* Perform a Read of the gate counter.
*/
virtual void init();
/**
* Clear the gate.
* Perform a clear of the device to the clear all counters.
*/
virtual void clear() const;
/**
* Write the gate.
* Perform a preset of the all counters and registers.
*/
virtual void write() const;
/**
* Write the gate.
* Perform a preset of the all counters and registers.
*/
virtual void writeParam() const;
/**
* Read the gate.
* Perform a Read of the gate counter.
*/
virtual void read();
virtual void synchroniseRead();
/**
* Start the gate.
* Perform a start of the device to the preset given in the the parameter.
*/
virtual void start();
/**
* Continue the gate.
* Perform a start of the device to the preset given in the the parameter.
*/
virtual void continu();
/**
* Set the gate to mode pause.
* Set the gate to the pause mode.
*/
virtual void stop();
/**
* Set the gate to mode pause.
* Set the gate to the pause mode.
*/
virtual void pause();
/**
* Read status of the gate.
* Read the status on the gate.
*/
virtual void readStatus();
/**
* Read the informations of the hardware.
* Read the version, the date,the signatures and local device parameters.
*/
virtual void readInfos();
};
#endif //PERFECTUSBPVCAMDRIVER_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 "RealUsbPVCamDriver.h"
#include "UsbPVCamDriver.h"
#include "drivers/legacy/def/GateDef.h"
#include "drivers/legacy/def/DetectorDef.h"
// Trace include
#include <cstdio>
/*
* Constructor
*/
RealUsbPVCamDriver::RealUsbPVCamDriver(UsbPVCamDriver* owner) :
UsbPVCamState(owner) {
/* Empty */
}
/*
* Destructor
*/
RealUsbPVCamDriver::~RealUsbPVCamDriver() {
plExpUninitSeq();
plCamClose(m_Handle);
plPVCamUninit();
}
/*
* init
*/
void RealUsbPVCamDriver::init() {
if (!plPVCamInit()) {
cerr << "failed to init pvcam" << endl;
print_pv_error();
} else {
char cam_name[CAM_NAME_LEN];
if (plCamGetName(0, cam_name)) {
cerr << "camname for cam 0 is " << cam_name << endl;
if (plCamOpen(cam_name, &m_Handle)) {
} else {
cerr << "camera " << cam_name << " didn't open" << endl;
print_pv_error();
}
} else {
cerr << "didn't get cam name" << endl;
print_pv_error();
}
}
readInfos();
readStatus();
}
/*
* clear
*/
void RealUsbPVCamDriver::clear() const {
memset(dynamic_cast<UsbPVCamDriver*> (m_owner)->m_Data, 0, dynamic_cast<UsbPVCamDriver*> (m_owner)->m_DataSize * sizeof(int32 ));
}
/*
* write
*/
void RealUsbPVCamDriver::write() const {
}
/*
* writeParam
*/
void RealUsbPVCamDriver::writeParam() const {
}
/*
* synchroniseRead
*/
void RealUsbPVCamDriver::synchroniseRead() {
uint16* datas = dynamic_cast<UsbPVCamDriver*> (m_owner)->m_DataShort;
/*
* Calculate the detector sum here
*/
int32* data = dynamic_cast<UsbPVCamDriver*> (m_owner)->m_Data;
int32* mask = dynamic_cast<UsbPVCamDriver*> (m_owner)->m_Mask;
float64 sum = 0;
if (datas!=NULL ){
for(int32 i=0;i<dynamic_cast<UsbPVCamDriver*> (m_owner)->m_DataSize;++i) {
data[mask[i]] = datas[i];
//data[i] = datas[i];
sum += (float64) data[i];
}
}
else{
cerr << "error mask "<< endl;
}
m_owner->updateValue(DETECTOR_SUM_DEVICE_CONTAINER, sum);
m_owner->sendArrayEvent(DETECTOR_DATA_DEVICE_CONTAINER);
/* Finish the sequence */
plExpFinishSeq(m_Handle, (void*)datas, 0);
/*Uninit the sequence */
//plExpUninitSeq();
dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadTerminated = true;
}
/*
* read
*/
void RealUsbPVCamDriver::read() {
}
/*
* start
*/
void RealUsbPVCamDriver::start() {
Trace::getInstance()->trace("DeviceContainer", "RealUsbPVCamDriver",
"start", Level::s_Info, "");
uint32 exp_time = (uint32) (any_cast<float64> (m_owner->getValue(
GATE_WANTED_TIME_DEVICE_CONTAINER)) * any_cast<int32> (
m_owner->getValue(GATE_PRECISION_DEVICE_CONTAINER)));
unsigned long size;
void *region = allocRegion();
if (region) {
uint16 param;
setS1(region, 0);
plGetParam(m_Handle, PARAM_SER_SIZE, pvcam::ATTR_DEFAULT, (void *) &param);
setS2(region, 1023);
setSBin(region, 1);
setP1(region, 0);
plGetParam(m_Handle, PARAM_PAR_SIZE, pvcam::ATTR_DEFAULT, (void *) &param);
setP2(region, 1023);
setPBin(region, 1);
if (plExpInitSeq()) {
if (plExpSetupSeq(m_Handle, 1, 1, region, pvcam::TIMED_MODE, exp_time, &size)) {
uint16* datas = dynamic_cast<UsbPVCamDriver*> (m_owner)->m_DataShort;
if (plExpStartSeq(m_Handle, (void*) datas)){
m_TimeCounter.clear();
}else{
print_pv_error();
}
} else {
cerr << "experiment setup failed" << endl;
}
} else {
cerr << "init_seq failed" << endl;
}
free(region);
}
}
/*
* continu
*/
void RealUsbPVCamDriver::continu() {
Trace::getInstance()->trace("DeviceContainer", "RealUsbPVCamDriver",
"continu", Level::s_Info, "");
}
/*
* pause
*/
void RealUsbPVCamDriver::pause() {
Trace::getInstance()->trace("DeviceContainer", "RealUsbPVCamDriver",
"pause", Level::s_Info, "");
}
/*
* stop
*/
void RealUsbPVCamDriver::stop() {
Trace::getInstance()->trace("DeviceContainer", "RealUsbPVCamDriver",
"stop", Level::s_Info, "");
plExpAbort(m_Handle, pvcam::CCS_HALT_CLOSE_SHTR);
}
/*
* readStatus
*/
void RealUsbPVCamDriver::readStatus() {
/*
* Read the status card
*/
int16 value;
unsigned long not_needed;
plExpCheckStatus(m_Handle, &value, &not_needed);
Trace::getInstance()->trace("DeviceContainer", "RealUsbPVCamDriver",
"readStatus", Level::s_Info, "value=%d", value);
m_owner->updateValue(STATUS_DEVICE_CONTAINER, (int32 ) value);
// Set category status before ending, synchronism for controller
m_owner->setCategoryStatus();
if (dynamic_cast<UsbPVCamDriver*> (m_owner)->m_StartActivated == true) {
if ((value == pvcam::READOUT_COMPLETE) || (value == pvcam::READOUT_FAILED)) {
if (value == pvcam::READOUT_FAILED) {
cerr << "Data collection error: " << plErrorCode() << endl;
}
dynamic_cast<UsbPVCamDriver*> (m_owner)->m_StartActivated = false;
synchroniseRead();
m_owner->updateValue(GATE_ACTUAL_TIME_DEVICE_CONTAINER,m_owner->getValue(GATE_WANTED_TIME_DEVICE_CONTAINER));
m_owner->sendProgressEvent(PROGRESSION_END_DEVICE_CONTAINER);
} else {
float64 aTime = m_TimeCounter.getTime();
if (aTime <= any_cast<float64>(m_owner->getValue(GATE_WANTED_TIME_DEVICE_CONTAINER))) {
m_owner->updateValue(GATE_ACTUAL_TIME_DEVICE_CONTAINER,aTime);
}
dynamic_cast<UsbPVCamDriver *> (m_owner)->calculateProgression();
}
} else {
if (dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadActivated
== true) {
if (dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadTerminated
== true) {
dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadActivated
= false;
dynamic_cast<UsbPVCamDriver *> (m_owner)->m_SynchroniseReadTerminated
= false;
m_owner->sendProgressEvent(PROGRESSION_END_DEVICE_CONTAINER);
}
} else {
m_owner->sendProgressEvent(PROGRESSION_END_DEVICE_CONTAINER);
}
}
// }
}
/*
* readInfos
*/
void RealUsbPVCamDriver::readInfos() {
}
/*
* print_pv_error
*/
void RealUsbPVCamDriver::print_pv_error() {
char msg[ERROR_MSG_LEN];
int16 i;
i = plErrorCode();
plErrorMessage(i, msg);
printf(" [%i]%s\n", i, msg);
}
/*
* 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 REALUSBPVCAMDRIVER_H
#define REALUSBPVCAMDRIVER_H