Skip to content
Snippets Groups Projects
Commit bcd58267 authored by ckoern's avatar ckoern
Browse files

Added Buffering

- Added Hardware and Software buffering support to the Interface
- Small reformatting
parent 9ba82a86
No related branches found
No related tags found
No related merge requests found
......@@ -48,8 +48,10 @@ public:
bool ResetListModeTimer();
bool DisableListMode();
bool startBuffering();
bool stopBuffering();
bool startHardwareBuffering();
bool stopHardwareBuffering();
bool BufferSpectrum(uint16_t index);
bool BufferAndClearSpectrum(uint16_t index);
std::pair<AmptekSpectrum, AmptekStatus> GetBufferedSpectrum(size_t id);
bool StartCommtestStreaming(uint16_t min_channel,uint16_t max_channel,
......
......@@ -15,6 +15,7 @@ public:
private:
void readConfig(char* configs);
void initConfigs();
std::string buildConfigResponse(char* config_names);
void createStatusData(byte* buffer);
void createSpectrumData(byte* buffer);
......
......@@ -22,6 +22,7 @@ namespace std {
%template(StringVector) vector<std::string>;
%template(DoubleVector) vector<double>;
%template(UIntVector) vector<unsigned int>;
%template(AmptekDataPair) pair<AmptekSpectrum, AmptekStatus>;
}
%except {
try {
......
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.12
# Version 3.0.8
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
def swig_import_helper():
import importlib
pkg = __name__.rpartition('.')[0]
mname = '.'.join((pkg, '_AmptekHardwareInterface')).lstrip('.')
try:
return importlib.import_module(mname)
except ImportError:
return importlib.import_module('_AmptekHardwareInterface')
_AmptekHardwareInterface = swig_import_helper()
del swig_import_helper
elif _swig_python_version_info >= (2, 6, 0):
from sys import version_info
if version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
......@@ -26,27 +19,22 @@ elif _swig_python_version_info >= (2, 6, 0):
except ImportError:
import _AmptekHardwareInterface
return _AmptekHardwareInterface
if fp is not None:
try:
_mod = imp.load_module('_AmptekHardwareInterface', fp, pathname, description)
finally:
if fp is not None:
fp.close()
return _mod
_AmptekHardwareInterface = swig_import_helper()
del swig_import_helper
else:
import _AmptekHardwareInterface
del _swig_python_version_info
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
try:
import builtins as __builtin__
except ImportError:
import __builtin__
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
......@@ -68,22 +56,37 @@ def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_getattr(self, class_type, name):
def _swig_getattr_nondynamic(self, class_type, name, static=1):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
if (not static):
return object.__getattr__(self, name)
else:
raise AttributeError(name)
def _swig_getattr(self, class_type, name):
return _swig_getattr_nondynamic(self, class_type, name, 0)
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
except Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object:
pass
_newclass = 0
def _swig_setattr_nondynamic_method(set):
def set_attr(self, name, value):
......@@ -236,7 +239,7 @@ class IntVector(object):
this = _AmptekHardwareInterface.new_IntVector(*args)
try:
self.this.append(this)
except __builtin__.Exception:
except Exception:
self.this = this
def push_back(self, x):
......@@ -346,7 +349,7 @@ class StringVector(object):
this = _AmptekHardwareInterface.new_StringVector(*args)
try:
self.this.append(this)
except __builtin__.Exception:
except Exception:
self.this = this
def push_back(self, x):
......@@ -456,7 +459,7 @@ class DoubleVector(object):
this = _AmptekHardwareInterface.new_DoubleVector(*args)
try:
self.this.append(this)
except __builtin__.Exception:
except Exception:
self.this = this
def push_back(self, x):
......@@ -566,7 +569,7 @@ class UIntVector(object):
this = _AmptekHardwareInterface.new_UIntVector(*args)
try:
self.this.append(this)
except __builtin__.Exception:
except Exception:
self.this = this
def push_back(self, x):
......@@ -597,10 +600,51 @@ class UIntVector(object):
UIntVector_swigregister = _AmptekHardwareInterface.UIntVector_swigregister
UIntVector_swigregister(UIntVector)
class AmptekDataPair(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __init__(self, *args):
this = _AmptekHardwareInterface.new_AmptekDataPair(*args)
try:
self.this.append(this)
except Exception:
self.this = this
first = _swig_property(_AmptekHardwareInterface.AmptekDataPair_first_get, _AmptekHardwareInterface.AmptekDataPair_first_set)
second = _swig_property(_AmptekHardwareInterface.AmptekDataPair_second_get, _AmptekHardwareInterface.AmptekDataPair_second_set)
def __len__(self):
return 2
def __repr__(self):
return str((self.first, self.second))
def __getitem__(self, index):
if not (index % 2):
return self.first
else:
return self.second
def __setitem__(self, index, val):
if not (index % 2):
self.first = val
else:
self.second = val
__swig_destroy__ = _AmptekHardwareInterface.delete_AmptekDataPair
__del__ = lambda self: None
AmptekDataPair_swigregister = _AmptekHardwareInterface.AmptekDataPair_swigregister
AmptekDataPair_swigregister(AmptekDataPair)
_AmptekHardwareInterface.SPECLEN_swigconstant(_AmptekHardwareInterface)
SPECLEN = _AmptekHardwareInterface.SPECLEN
_AmptekHardwareInterface.NOT_CONNECTED_swigconstant(_AmptekHardwareInterface)
NOT_CONNECTED = _AmptekHardwareInterface.NOT_CONNECTED
_AmptekHardwareInterface.ON_swigconstant(_AmptekHardwareInterface)
ON = _AmptekHardwareInterface.ON
_AmptekHardwareInterface.RECORDING_swigconstant(_AmptekHardwareInterface)
RECORDING = _AmptekHardwareInterface.RECORDING
_AmptekHardwareInterface.ERROR_swigconstant(_AmptekHardwareInterface)
ERROR = _AmptekHardwareInterface.ERROR
class AmptekHardwareInterface(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
......@@ -610,7 +654,7 @@ class AmptekHardwareInterface(object):
this = _AmptekHardwareInterface.new_AmptekHardwareInterface()
try:
self.this.append(this)
except __builtin__.Exception:
except Exception:
self.this = this
__swig_destroy__ = _AmptekHardwareInterface.delete_AmptekHardwareInterface
__del__ = lambda self: None
......@@ -663,11 +707,17 @@ class AmptekHardwareInterface(object):
def DisableListMode(self):
return _AmptekHardwareInterface.AmptekHardwareInterface_DisableListMode(self)
def startBuffering(self):
return _AmptekHardwareInterface.AmptekHardwareInterface_startBuffering(self)
def startHardwareBuffering(self):
return _AmptekHardwareInterface.AmptekHardwareInterface_startHardwareBuffering(self)
def stopHardwareBuffering(self):
return _AmptekHardwareInterface.AmptekHardwareInterface_stopHardwareBuffering(self)
def stopBuffering(self):
return _AmptekHardwareInterface.AmptekHardwareInterface_stopBuffering(self)
def BufferSpectrum(self, index):
return _AmptekHardwareInterface.AmptekHardwareInterface_BufferSpectrum(self, index)
def BufferAndClearSpectrum(self, index):
return _AmptekHardwareInterface.AmptekHardwareInterface_BufferAndClearSpectrum(self, index)
def GetBufferedSpectrum(self, id):
return _AmptekHardwareInterface.AmptekHardwareInterface_GetBufferedSpectrum(self, id)
......@@ -689,6 +739,8 @@ class AmptekHardwareInterface(object):
AmptekHardwareInterface_swigregister = _AmptekHardwareInterface.AmptekHardwareInterface_swigregister
AmptekHardwareInterface_swigregister(AmptekHardwareInterface)
_AmptekHardwareInterface.STATUS_SIZE_swigconstant(_AmptekHardwareInterface)
STATUS_SIZE = _AmptekHardwareInterface.STATUS_SIZE
class AmptekStatus(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
......@@ -698,7 +750,7 @@ class AmptekStatus(object):
this = _AmptekHardwareInterface.new_AmptekStatus(*args)
try:
self.this.append(this)
except __builtin__.Exception:
except Exception:
self.this = this
__swig_destroy__ = _AmptekHardwareInterface.delete_AmptekStatus
__del__ = lambda self: None
......@@ -800,7 +852,7 @@ class AmptekSpectrum(object):
this = _AmptekHardwareInterface.new_AmptekSpectrum(*args)
try:
self.this.append(this)
except __builtin__.Exception:
except Exception:
self.this = this
def AgeMillis(self):
......
......@@ -461,6 +461,27 @@ class AmptekPX5(Device):
f.write( self.create_dp5_config_string() )
f.write( self.create_dpp_status_string() )
@command(dtype_in=(str,) )
def SaveBufferedSpectrumAsMCA(self, args):
buffer_index, filepath = args
buffer_index= int(buffer_index)
if os.path.exists(filepath):
self.set_state(tango.DevState.ALARM)
raise RuntimeError("File already exists!")
if not os.path.exists(os.path.dirname(filepath)):
self.set_state(tango.DevState.ALARM)
raise RuntimeError("Directory %s does not exist (filename: %s)!"%(os.path.dirname(filepath), filepath) )
spectrum, status = self.interface.GetBufferedSpectrum( buffer_index )
with open(filepath, "w+") as f:
f.write( self.create_pmca_spectrum_string() )
f.write( self.create_calibration_string() )
f.write( self.create_data_string() )
f.write( self.create_dp5_config_string() )
f.write( self.create_dpp_status_string() )
@command(dtype_in=(int,))
def StartCommtestStreaming(self, args):
print("test")
......@@ -476,6 +497,18 @@ class AmptekPX5(Device):
def StopCommtestStreaming(self):
self.interface.StopCommtestStreaming()
@command(dtype_in = int)
def BufferSpectrum(self, index):
self.interface.BufferSpectrum(index)
@command(dtype_in = int)
def BufferAndClearSpectrum(self, index):
self.interface.BufferAndClearSpectrum(index)
def set_maxinfoage(self, x):
self._max_info_age = x
......@@ -551,7 +584,7 @@ class AmptekPX5(Device):
@command
def ClearAlarm(self):
self.set_state(DevState.On)
self.set_state(DevState.ON)
self.dev_state()
def set_calibrationslope(self, val):
......@@ -667,7 +700,7 @@ class AmptekPX5(Device):
def create_dpp_status_string(self):
def create_dpp_status_string(self, status = None):
template = ("<<DPP STATUS>>\n"
"Device Type: {dev_type}\n"
"Serial Number: {serial_nb}\n"
......@@ -683,6 +716,7 @@ class AmptekPX5(Device):
"TEC Temp: {detector_temp:.1f}K\n"
"Board Temp: {board_temp:.1f}C\n"
"<<DPP STATUS END>>\n")
if status is None:
status = self.interface.updateStatus(0)
outstring = template.format( dev_type = status.DeviceType(),
......@@ -722,9 +756,11 @@ class AmptekPX5(Device):
def create_calibration_string(self):
return ""
def create_data_string(self):
def create_data_string(self, spectrum = None):
if spectrum is None:
spectrum = self.GetSpectrum(self._max_info_age)
outstring = "<<DATA>>\n"
outstring += "\n".join([str(c) for c in self.GetSpectrum(self._max_info_age)] ) + "\n"
outstring += "\n".join([str(c) for c in spectrum] ) + "\n"
outstring += "<<END>>\n"
return outstring
......
......@@ -553,7 +553,7 @@ bool AmptekHardwareInterface::ResetListModeTimer(){
* @return true on success
* @return false on failure
*/
bool AmptekHardwareInterface::startBuffering(){
bool AmptekHardwareInterface::startHardwareBuffering(){
try{
expectAcknowledge(connection_handler->sendAndReceive( Packet::DP5_PKT_REQUEST_RESTART_SEQ_BUFFERING) );
}
......@@ -572,7 +572,7 @@ bool AmptekHardwareInterface::startBuffering(){
* @return true on success
* @return false on failure
*/
bool AmptekHardwareInterface::stopBuffering(){
bool AmptekHardwareInterface::stopHardwareBuffering(){
try{
expectAcknowledge(connection_handler->sendAndReceive( Packet::DP5_PKT_REQUEST_CANCEL_SEQ_BUFFERING) );
}
......@@ -584,6 +584,33 @@ bool AmptekHardwareInterface::stopBuffering(){
return true;
}
bool AmptekHardwareInterface::BufferAndClearSpectrum(uint16_t index){
try{
expectAcknowledge(connection_handler->sendAndReceive( Packet::generateBufferAndClearRequest(index) ) );
}
catch(AmptekException& e){
std::cerr<< "Failed sending buffer request: " << e.what() << std::endl;
return false;
}
return true;
}
bool AmptekHardwareInterface::BufferSpectrum(uint16_t index){
try{
expectAcknowledge(connection_handler->sendAndReceive( Packet::generateBufferRequest(index) ) );
}
catch(AmptekException& e){
std::cerr<< "Failed sending buffer request: " << e.what() << std::endl;
return false;
}
return true;
}
/**
* @brief Get Status and spectrum stored in an hardware buffer on the detector
*
......
......@@ -44,7 +44,7 @@ Packet AmptekSimulatorConnectionHandler::sendAndReceive( const Packet& request){
p.setData(arr, len);
}
else if (pid1 == Packet::DP5_PKT_REQUEST_SPECTRUM_AND_STATUS.at(PID1)
&& pid2 == Packet::DP5_PKT_REQUEST_SPECTRUM_AND_STATUS.at(PID2))
&& (pid2 == DP5_P2_SPECTRUM_REQUEST_SPECTRUM_STATUS || pid2 == DP5_P2_SPECTRUM_REQUEST_GET_BUFFER) )
{
p.setPid1( DP5_P1_SPECTRUM_RESPONSE );
switch (speclen){
......@@ -86,26 +86,16 @@ Packet AmptekSimulatorConnectionHandler::sendAndReceive( const Packet& request){
p.resize( MIN_PACKET_LEN + len );
p.setData(arr, len);
}
else if (pid1 == 0x20
&& pid2 == 0x03)
else if (pid1 == DP5_P1_TEXTCONFIG_REQUEST
&& pid2 == DP5_P2_TEXTCONFIG_REQUEST_GET)
{
p.setPid1( DP5_P1_DATA_RESPONSE );
p.setPid2( DP5_P2_DATA_RESPONSE_CONFIG_READBACK );
char configs[ request.dataLength + 1 ];
byteToChar( (byte*)&(request.at(DATA)), configs, request.dataLength );
std::cout << configs << std::endl;
string configstring = buildConfigResponse(configs);
std::cout << configstring << std::endl;
// std::stringstream configs;
// configs << "MCAC=" << std::to_string(speclen) << ";PRET=";
// if (acquisition_time > 0){
// configs << std::setw(2) << std::fixed << acquisition_time;
// } else{
// configs << "OFF";
// }
// string configstring = configs.str();
word16 len = configstring.size();
byte arr[len];
charToByte(configstring.c_str(), arr, len);
......@@ -135,14 +125,17 @@ Packet AmptekSimulatorConnectionHandler::sendAndReceive( const Packet& request){
{
return Packet(DP5_P1_ACK, DP5_P2_ACK_OK, nullptr, 0);
}
else if(pid1 == 0x20 //set Text Config
&& pid2 == 0x02)
else if(pid1 == DP5_P1_TEXTCONFIG_REQUEST
&& pid2 == DP5_P2_TEXTCONFIG_REQUEST_SET)
{
char configs[ request.dataLength + 1 ];
byteToChar( (byte*)&(request.at(DATA)), configs, request.dataLength );
readConfig(configs);
return Packet(DP5_P1_ACK, DP5_P2_ACK_OK, nullptr, 0);
}
else{
return Packet(DP5_P1_ACK, DP5_P2_ACK_OK, nullptr, 0);
}
p.calcAndFillChecksum();
return p;
......@@ -151,6 +144,7 @@ Packet AmptekSimulatorConnectionHandler::sendAndReceive( const Packet& request){
AmptekSimulatorConnectionHandler::AmptekSimulatorConnectionHandler(){
spectrum = new unsigned int[speclen];
clear();
initConfigs();
spectrum_thread = new std::thread(
[&]{
auto start_time = std::chrono::system_clock::now();
......@@ -300,3 +294,75 @@ std::string AmptekSimulatorConnectionHandler::buildConfigResponse(char* config_
}
return configresponse_stream.str();
}
void AmptekSimulatorConnectionHandler::initConfigs(){
text_configs["AINP"] = "NEG";
text_configs["AU34"] = "1";
text_configs["AUO1"] = "ICR";
text_configs["AUO2"] = "ICR";
text_configs["BLRD"] = "0";
text_configs["BLRM"] = "OFF";
text_configs["BLRU"] = "0";
text_configs["CON1"] = "DAC";
text_configs["CON2"] = "AUXOUT2";
text_configs["CLCK"] = "AUTO";
text_configs["CLKL"] = "100";
text_configs["CUSP"] = "0";
text_configs["DACF"] = "0";
text_configs["DACO"] = "OFF";
text_configs["GAIA"] = "0";
text_configs["GAIF"] = "1";
text_configs["GAIN"] = "1";
text_configs["GATE"] = "OFF";
text_configs["GPED"] = "FALLING";
text_configs["GPGA"] = "ON";
text_configs["GPIN"] = "AUX1";
text_configs["GPMC"] = "ON";
text_configs["GPME"] = "ON";
text_configs["HVSE"] = "OFF";
text_configs["INOF"] = "DEF";
text_configs["INOG"] = "LOW";
text_configs["MCAC"] = std::to_string(speclen);
text_configs["MCAE"] = "OFF";
text_configs["MCAS"] = "NORM";
text_configs["MCSL"] = "0";
text_configs["MCSH"] = "8191";
text_configs["MCST"] = "1";
text_configs["PAPS"] = "OFF";
text_configs["PAPZ"] = "OFF";
text_configs["PDMD"] = "NORM";
text_configs["PRCL"] = "0";
text_configs["PRCH"] = "8191";
text_configs["PREC"] = "OFF";
text_configs["PREL"] = "OFF";
text_configs["PRER"] = "OFF";
text_configs["PRET"] = "OFF";
text_configs["PURE"] = "OFF";
text_configs["RESL"] = "OFF";
text_configs["RTDD"] = "0";
text_configs["RTDE"] = "OFF";
text_configs["RTDS"] = "0";
text_configs["RTDT"] = "0";
text_configs["RTDW"] = "0";
text_configs["SCAH"] = "0";
text_configs["SCAI"] = "1";
text_configs["SCAL"] = "0";
text_configs["SCAO"] = "OFF";
text_configs["SCAW"] = "100";
text_configs["SCOE"] = "RISING";
text_configs["SCOG"] = "1";
text_configs["SCOT"] = "87";
text_configs["SOFF"] = "OFF";
text_configs["SYNC"] = "INT";
text_configs["TECS"] = "OFF";
text_configs["TFLA"] = "0";
text_configs["THFA"] = "0";
text_configs["THSL"] = "0";
text_configs["TLLD"] = "OFF";
text_configs["TPEA"] = "0.4";
text_configs["TPFA"] = "400";
text_configs["TPMO"] = "OFF";
text_configs["VOLU"] = "OFF";
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment