- Fixed a weird error message + string length bug

This commit is contained in:
Stefan Reutter 2014-08-01 14:18:05 +00:00
parent 5545917824
commit 8b9aa05595
4 changed files with 17 additions and 13 deletions

View File

@ -54,8 +54,7 @@ class error_result: public result {
the errormessage should give a hint, what happened, not only which function found an error
*/
error_result(size_t _no, const std::string& s):result(_no) {
error_message=s;
error_result(size_t _no, const std::string& s) : result(_no), error_message(s) {
}
};

View File

@ -9,6 +9,8 @@
#include "core/xml_states.h"
#include "Spectrum-MI40xxSeries.h"
#include <sstream>
#ifndef SPC_DEBUG
# define SPC_DEBUG 0
#endif
@ -363,19 +365,14 @@ void SpectrumMI40xxSeries::collect_config_recursive(state_sequent& exp, Spectrum
double time_required=delayed_gating_time+gating_time;
// check time requirements
if (a_state->length < gating_time) {
char parameter_info[512];
snprintf(parameter_info,sizeof(parameter_info),
"(%" SIZETPRINTFLETTER " samples, %g samplerate, %e time required, %e state time)",
inputs.front()->samples,
settings.samplefreq,
time_required,
a_state->length);
#if SPC_DEBUG
fprintf(stderr, "state is shorter than acquisition time %e time required, %e state time\n", gating_time, a_state->length);
#endif
// update the state length if it's shorter than the gate. this is usually due to rounding to 10 ns for the pulseblaster
if (ceil(1e8*a_state->length)/1e8 < time_required) {
throw ADC_exception(std::string("state is shorter than acquisition time")+parameter_info);
if (ceil(1e8*(a_state->length))/1e8 < time_required) { // + 3.0f/settings.samplefreq
std::stringstream parameter_inf;
parameter_inf << "state is (" << inputs.front()->samples << " samples, " << settings.samplefreq << " sampling rate, " << time_required << " time required, " << a_state->length << " state time)" << std::endl;
throw ADC_exception(parameter_inf.str());
} else {
a_state->length = time_required;
}

View File

@ -11,7 +11,7 @@
#include <drivers/pulsegen.h>
#ifndef SP_DEBUG
# define SP_DEBUG 1
# define SP_DEBUG 0
#endif
class SpinCorePulseBlaster_error: public pulse_exception

View File

@ -11,6 +11,8 @@
#include "drivers/SpinCore-PulseBlaster24Bit/SpinCore-PulseBlaster24Bit.h"
#include <glib.h>
#include <fstream>
/**
\defgroup General NMR Spectrometer
\ingroup machines
@ -175,7 +177,13 @@ public:
}
catch (const RecoverableException &e)
{
r = new error_result(1, e.what());
// there is a weird bug with string memory allocation for large messages, resize manually to cure this
std::string str;
str.resize(strlen(e.what()));
str = e.what();
fprintf(stderr, "test %s\n", str.c_str());
r = new error_result(1, str);
fprintf(stderr, "test2 %s\n", dynamic_cast<error_result*>(r)->error_message.c_str());
}
delete work_copy;
if (core::quit_signal != 0)