damaris-backends/machines/damaris.cpp

191 lines
6.0 KiB
C++
Raw Permalink Normal View History

/* **************************************************************************
Author: Markus Rosenstihl
Created: February 2017
****************************************************************************/
#include "machines/hardware.h"
#include "core/core.h"
#include "drivers/PTS-Synthesizer/PTS.h"
#include "drivers/Spectrum-MI40xxSeries/Spectrum-MI40xxSeries.h"
#include "drivers/SpinCore-PulseBlaster24Bit/SpinCore-PulseBlaster24Bit.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <iostream>
#include <drivers/dummy/dummy.h>
/**
\defgroup damaris Backend configurable by config files
\ingroup machines
Uses Spincore Pulseblaster 24 Bit and Spectrum MI4021, PTS310 with cabledriver with phase control and a synchronization board
or dummy or tempcontrol or ...
\li line 0 for gate
\li line 1 for pulse
\li line 17 for trigger
\li line 16 for synchronization
\par Starting the hardware
This procedure should assure the correct initialisation of the hardware:
\li Switch off main switches of SpinCore Pulseblaster and Computer (the main switch of the computer is at the rear)
\li Switch on Computer and start Linux
@{
*/
class Mobile_hardware: public hardware
{
boost::property_tree::ptree device_configuration;
public:
Mobile_hardware()
{
}
result* experiment(const state& exp)
{
result* r = NULL;
for (size_t tries = 0; r == NULL && core::term_signal == 0 && tries < 102; ++tries)
{
state* work_copy = exp.copy_flat();
if (work_copy == NULL)
return new error_result(1, "could not create work copy of experiment sequence");
try
{
/**
* this section configures the frequency generator
*/
std::string fg_driver = device_configuration.get<std::string>("PTS.driver");
if (fg_driver == "pts310") {
PTS* the_fg;
the_fg = new PTS_latched(0);
}
else if (fg_driver == "dummy"){
dummy* the_fg;
the_fg = new dummy();
}
if (the_fg != NULL)
the_fg->set_frequency(*work_copy);
/**
* this section configures the ADC driver
*/
std::string adc_driver = device_configuration.get<std::string>("ADC.driver");
if (adc_driver == "mi40xx") {
ttlout trigger;
trigger.id = device_configuration.get<int>("ADC.id");
trigger.ttls = 1 << device_configuration.get<int>("ADC.trigger_line"); /* trigger on line 17 */
the_adc = new SpectrumMI40xxSeries(trigger);
}
else if (adc_driver == "dummy") {
dummy* my_adc;
the_adc = new dummy();
}
if (the_adc != NULL)
the_adc->set_daq(*work_copy);
/**
* this section configures the pulse generator
*/
std::string pg_driver = device_configuration.get<std::string>("PB.driver");
if (pg_driver =="pb24") {
// device_id=0, clock=100MHz, sync_mask: Bit 16
int pg_id = device_configuration.get<int>("PB.id");
unsigned int pg_sync = device_configuration.get<unsigned int>("PB.sync_mask");
double pg_clock = device_configuration.get<double>("PB.refclock");
SpinCorePulseBlaster24Bit* the_pg;
if (pg_sync == 128){
the_pg = new SpinCorePulseBlaster24Bit(pg_id, pg_clock, 0);
the_pg->run_pulse_program(*work_copy);
}
else {
the_pg = new SpinCorePulseBlaster24Bit(pg_id, pg_clock, 1 << pg_sync);
the_pg->run_pulse_program_w_sync(*work_copy, the_adc->get_sample_clock_frequency());
}
}
else if (pg_driver == "dummy"){
dummy* the_pg = new dummy();
the_pg->run_pulse_program(*work_copy);
}
//
if (the_pg == NULL) {
throw(DamarisException("Pulse generator not set, aborting"));
}
// wait for pulse generator
the_pg->wait_till_end();
// after that, the result must be available
if (the_adc != NULL)
r = the_adc->get_samples();
else
r = new adc_result(1, 0, NULL);
}
catch (const RecoverableException &e)
{
r = new error_result(1, e.what());
}
delete work_copy;
if (core::quit_signal != 0)
break;
}
return r;
}
virtual ~Mobile_hardware()
{
if (the_adc != NULL)
delete the_adc;
if (the_fg != NULL)
delete the_fg;
if (the_pg != NULL)
delete the_pg;
}
};
/**
\brief brings standard core together with the Mobile NMR hardware
*/
class Mobile_core: public core
{
std::string the_name;
public:
Mobile_core(const core_config& conf) :
core(conf)
{
the_hardware = new Mobile_hardware();
the_name = "Mobile core";
}
virtual const std::string& core_name() const
{
return the_name;
}
};
/**
@}
*/
int main(int argc, const char** argv)
{
int return_result = 0;
try
{
core_config my_conf(argv, argc);
// setup input and output
Mobile_core my_core(my_conf);
// start core application
my_core.run();
}
catch (const DamarisException& e)
{
fprintf(stderr, "%s\n", e.what());
return_result = 1;
}
return return_result;
}