RunSpectrums.cpp 3.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
 * 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.
 */

19
#include "RunSpectrums.h"
20
21
22
23
24

namespace dielectrics {

using namespace std;
using namespace common;
25
using namespace cameo;
26
27
28
29

const std::string RunSpectrums::TYPE = "dielectrics_run_spectrums";

RunSpectrums::RunSpectrums(const std::string& name) :
30
	Spectrums(name), controller::Stoppable(this), controller::Raz(this) {
31

32
33
34
35
36
37
38
	fr.init(this, SAVE, "fr", "Freq");
	frMin.init(this, SAVE | SPY, "frMin", "Freq Min");
	frMax.init(this, SAVE | SPY, "frMax", "Freq Max");
	N.init(this, SAVE | SPY, "actual_N", "wanted_N", "N");
	time.init(this, SAVE, "actual_time", "wanted_time", "Time");
	comment.init(this, SAVE, "comment", "Comment");
	actualRun.init(this, NOSAVE | SPY, "run", "Run");
39
40
41
42
43
44
45
}

RunSpectrums::~RunSpectrums() {
}

void RunSpectrums::postConfiguration() {

46
47
	Spectrums::postConfiguration();

48
49
50
	registerUpdater(matlabController->applicationState, &RunSpectrums::updateApplicationState, this);
	registerStatus(matlabController, &RunSpectrums::updateState, this);

51
52
53
54
	registerUpdater(matlabController->actualN, &RunSpectrums::updateN, this);
	registerUpdater(matlabController->actualTime, &RunSpectrums::updateTime, this);
	registerUpdater(matlabController->actualRun, &RunSpectrums::updateRun, this);

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
	updateApplicationState();
}

void RunSpectrums::updateApplicationState() {

	int32 state = matlabController->applicationState();

	if (state == application::STARTING) {
		commandStatus.setWarning();
	}
	else if (state == application::RUNNING) {
		commandStatus.setIdle();
	}
	else {
		commandStatus.setError();
	}
}

void RunSpectrums::updateState() {

75
	if (isStarted() && matlabController->commandStatus.isRunning()) {
76
77
78
79
80
		commandStatus.setRunning();
	}
	else {
		commandStatus.setIdle();
	}
81
82
}

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
void RunSpectrums::updateN() {

	if (isStarted()) {
		N = matlabController->actualN();
	}
}

void RunSpectrums::updateTime() {

	if (isStarted()) {
		time = matlabController->actualTime();
	}
}

void RunSpectrums::updateRun() {

	if (isStarted()) {
		actualRun = matlabController->actualRun();
	}
}

104
105
106
107
108
void RunSpectrums::start() {

	matlabController->requestType = RemoteMatlabReq::RUN_SPECTRUMS;
	matlabController->frMin = frMin();
	matlabController->frMax = frMax();
109
	matlabController->nMax = N.setpoint();
110
111
112
	matlabController->comment = comment();

	matlabController->startCommand();
113

114
115
116
117
118
	LogStream logStream = log(Level::s_Info);
	logStream << "Freq min " << frMin << " Freq Max " << frMax << " N Max " << N.setpoint << " Comment '" << comment << "' ";

	logRunNumbers(logStream);
	logStream << endlog;
119
120
121
122
123
124
125
126
}

void RunSpectrums::stop() {
}

void RunSpectrums::raz() {

	matlabController->razCommand();
127
128

	log(Level::s_Info) << "Stopped remote application" << endlog;
129
130
}

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
void RunSpectrums::logRunNumbers(LogStream& logStream) {

	logStream << "run numbers [";

	int32 size = matlabController->values.getSize();
	int32* values = matlabController->values.get();
	for (int32 i = 0; i < size - 1; ++i) {
		logStream << values[i] << ", ";
	}

	if (size > 0) {
		logStream << values[size - 1] << "]";
	}
}

146
}