Commit a9ab80ad authored by yannick legoc's avatar yannick legoc
Browse files

First command box and settings for Dielectrics WinDeta

parent 47d2fd67
......@@ -21,6 +21,7 @@
#include <boost/lexical_cast.hpp>
#include <common/base/ServerProperties.h>
#include "controllers/common/family/Families.h"
#include <thread>
#include <fstream>
#include <iostream>
......@@ -37,7 +38,7 @@ const std::string RemoteWindeta::RESPONDER_NAME = "dielectrics_controller";
const std::string RemoteWindeta::PUBLISHER_NAME = "dielectrics_pub";
RemoteWindeta::RemoteWindeta(const std::string& name) :
ExperimentController(name), controller::Stoppable(this), controller::Raz(this), Test(this) {
ExperimentController(name), controller::Stoppable(this), controller::Raz(this), Test(this), m_stopped(false) {
setFamily(family::ACQUISITION, family::POLARIZATIONS);
......@@ -45,11 +46,15 @@ RemoteWindeta::RemoteWindeta(const std::string& name) :
initialized.init(this, NOSAVE, "initialized");
applicationState.init(this, NOSAVE, "remote_state");
preset.init(this, SAVE | SPY, "preset", "Preset");
numberOfPoints.init(this, NOSAVE | SPY, "number_of_points", "Points");
startTimeout.init(this, SAVE, "start_timeout");
m_driver.init(this, "driver");
}
RemoteWindeta::RemoteWindeta(const RemoteWindeta& controller) :
ExperimentController(controller), controller::Stoppable(this), controller::Raz(this), Test(this) {
ExperimentController(controller), controller::Stoppable(this), controller::Raz(this), Test(this), m_stopped(false) {
}
RemoteWindeta::~RemoteWindeta() {
......@@ -182,14 +187,20 @@ void RemoteWindeta::start() {
return;
}
commandStatus.setRunning();
// Check initial status.
if (commandStatus.isRunning()) {
log(Level::s_Error) << name << "cannot start because it is already running" << endlog;
return;
}
log(Level::s_Debug) << name << cursor << "preset " << preset() << endlog;
// Serialize the request.
windeta::Request requestType;
requestType.set_type(windeta::Request::START_MEASURE);
windeta::StartMeasure requestMessage;
requestMessage.set_preset("preset");
requestMessage.set_preset(preset());
// Send the message.
m_requester->sendTwoBinaryParts(requestType.SerializeAsString(), requestMessage.SerializeAsString());
......@@ -206,10 +217,36 @@ void RemoteWindeta::start() {
cout << "received response " << response.errorcode() << endl;
// Loop on the status...
sleep(1);
m_stopped = false;
// The status must pass to running within a timeout.
int i = 0;
int timeout = startTimeout();
while (!commandStatus.isRunning() && i < timeout) {
std::this_thread::sleep_for(std::chrono::seconds(1));
i++;
}
if (!commandStatus.isRunning()) {
log(Level::s_Error) << name << "preset " << preset() << " start timeout" << endlog;
return;
}
// Loop on the status.
while (commandStatus.isRunning() && !m_stopped) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
if (m_stopped) {
log(Level::s_Info) << name << "preset " << preset() << " stopped" << endlog;
} else if (commandStatus.isError()) {
log(Level::s_Error) << name << "preset " << preset() << " on error" << endlog;
}
else {
log(Level::s_Info) << name << "preset " << preset() << " finished" << endlog;
}
commandStatus.setIdle();
}
void RemoteWindeta::stop() {
......@@ -218,7 +255,7 @@ void RemoteWindeta::stop() {
return;
}
cout << "stop to be implemented" << endl;
m_stopped = true;
}
void RemoteWindeta::raz() {
......@@ -307,13 +344,19 @@ void RemoteWindeta::subscriberLoop() {
status.ParseFromString(data2);
if (status.type() == windeta::Status::STARTED) {
cout << "Started" << endl;
log(Level::s_Debug) << name << " started" << endlog;
commandStatus.setRunning();
}
else if (status.type() == windeta::Status::FINISHED) {
cout << "Finished" << endl;
log(Level::s_Debug) << name << " finished" << endlog;
commandStatus.setIdle();
}
else if (status.type() == windeta::Status::ERROR) {
cout << "Error" << endl;
log(Level::s_Debug) << name << " error" << endlog;
commandStatus.setError();
}
}
else if (event.type() == windeta::Event::DATA) {
......
......@@ -68,6 +68,10 @@ public:
Property<bool> initialized;
Property<int32> applicationState;
Property<std::string> preset;
Property<int32> numberOfPoints;
Property<int32> startTimeout;
private:
void reset();
bool initApplication();
......@@ -85,6 +89,8 @@ private:
std::unique_ptr<boost::thread> m_subscriberThread;
DriverPtr<driver::NullDriver> m_driver;
bool m_stopped;
};
}
......
dielectrics_remote_windeta.razPrefix=Stop application
dielectrics_remote_windeta.remote_application=Remote application
dielectrics_remote_windeta.serverPrefix=Server endpoint
dielectrics_remote_windeta.presetPrefix=Preset
dielectrics_remote_windeta.startTimeoutPrefix=Start timeout
\ No newline at end of file
<plugin>
<controller type="dielectrics_remote_windeta" role="dielectrics_remote_windeta1"/>
<composite>
<text role="dielectrics_remote_windeta1" property="preset" prefix="dielectrics_remote_windeta.presetPrefix"/>
</composite>
</plugin>
<controller_plugin_config type="dielectrics_remote_windeta">
<image key="FREQGEN_CTRL"/>
<settings view="dielectrics_remote_windetaView.xml"/>
<command view="dielectrics_remote_windetaCommandView.xml" backgroundable="true"/>
</controller_plugin_config>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<controller type="dielectrics_remote_windeta">
<property name="cameo_server" type="string" max_length="30"/>
<property name="preset" type="string" max_length="30"/>
<property name="number_of_points" type="int32"/>
<property name="start_timeout" type="int32"/>
</controller>
<plugin>
<controller type="dielectrics_remote_windeta" role="dielectrics_remote_windeta1"/>
<simple_label prefix="dielectrics_remote_windeta.serverPrefix" font_size="9" hAlignment="left"/>
<text role="dielectrics_remote_windeta1" property="cameo_server"/>
<button role="dielectrics_remote_windeta1" command="raz" prefix="dielectrics_remote_windeta.razPrefix"/>
<text role="dielectrics_remote_windeta1" property="start_timeout" prefix="dielectrics_remote_windeta.startTimeoutPrefix"/>
<newLine/>
<newLine/>
<text role="dielectrics_remote_windeta1" property="preset" prefix="dielectrics_remote_windeta.presetPrefix"/>
</plugin>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment