Commit 5fd4e9b3 authored by yannick legoc's avatar yannick legoc
Browse files

Implemented automatic presets refresh in DielectricsRemoteWindeta

parent 58eae7a9
......@@ -47,7 +47,7 @@ const std::string RemoteWindeta::NUMOR_VALUE = "numor";
const std::string RemoteWindeta::NUMOR_1_VALUE = "numor+1";
RemoteWindeta::RemoteWindeta(const std::string& name) :
ExperimentController(name), controller::Stoppable(this), controller::Raz(this), Test(this), m_independentDataFileId(0), m_stopped(false) {
ExperimentController(name), controller::Stoppable(this), controller::Init(this), controller::Raz(this), Test(this), m_independentDataFileId(0), m_stopped(false) {
setFamily(family::ACQUISITION, family::POLARIZATIONS);
......@@ -78,13 +78,17 @@ RemoteWindeta::RemoteWindeta(const std::string& name) :
dataFilenameFormat.setEnumeratedValues(dataFilenameFormatValues);
dataFilenameFormat.setEnumeratedLabels(dataFilenameFormatLabels);
presetsChanged.init(this, NOSAVE, "presets_changed");
presetsSize.init(this, NOSAVE, "presets_size");
presets.init(this, NOSAVE, "presets");
m_driver.init(this, "driver");
initIndependentDataFileId();
}
RemoteWindeta::RemoteWindeta(const RemoteWindeta& controller) :
ExperimentController(controller), controller::Stoppable(this), controller::Raz(this), Test(this), m_independentDataFileId(0), m_stopped(false) {
ExperimentController(controller), controller::Stoppable(this), controller::Init(this), controller::Raz(this), Test(this), m_independentDataFileId(0), m_stopped(false) {
}
RemoteWindeta::~RemoteWindeta() {
......@@ -181,6 +185,9 @@ bool RemoteWindeta::initApplication() {
cout << "Windeta application initialized" << endl;
// Request for the presets.
initPresets();
return true;
} catch (const std::exception & e) {
......@@ -191,6 +198,35 @@ bool RemoteWindeta::initApplication() {
return false;
}
void RemoteWindeta::initPresets() {
// Serialize the request.
windeta::Request requestType;
requestType.set_type(windeta::Request::PRESETS);
// Send the message.
m_requester->sendTwoBinaryParts(requestType.SerializeAsString(), "");
cout << getName() << " sent request " << static_cast<int>(requestType.type()) << endl;
// Wait for the response synchronously.
// Note that responses can be processed asynchronously if the server is able to.
string data;
m_requester->receiveBinary(data);
windeta::Response response;
response.ParseFromString(data);
cout << "received response " << response.errorcode() << endl;
}
void RemoteWindeta::init() {
// Do not initialise if the controller is disabled.
if (isEnabled()) {
initialized = initApplication();
}
}
void RemoteWindeta::reset() {
......@@ -359,6 +395,9 @@ void RemoteWindeta::stopApplication() {
applicationState = m_windetaApplication->waitFor();
cout << "Windeta application terminated with state " << application::toString(applicationState()) << endl;
// Reset initialized.
initialized = false;
}
void RemoteWindeta::initIndependentDataFileId() {
......@@ -494,6 +533,25 @@ void RemoteWindeta::subscriberLoop() {
cout << "Data " << data.points() << " points" << endl;
}
else if (event.type() == windeta::Event::PRESETS) {
windeta::Presets messagePresets;
messagePresets.ParseFromString(data2);
cout << "Presets" << endl;
int size = messagePresets.list_size();
presets.resize(size);
for (int i = 0; i < size; ++i) {
presets.set(i, messagePresets.list(i));
cout << " " << presets.get(i) << endl;
}
presetsSize = size;
presetsChanged = presetsChanged() + 1;
}
}
}
......
......@@ -28,7 +28,7 @@ namespace dielectrics {
/*!
* \brief Test command.
*/
class Test: private controller::Command {
class Test : private controller::Command {
public:
Test(ExperimentController * c) :
......@@ -43,6 +43,7 @@ public:
class RemoteWindeta : public ExperimentController,
public controller::Stoppable,
public controller::Init,
public controller::Raz,
public Test {
......@@ -59,6 +60,7 @@ public:
virtual void setEnabled(bool all, bool postconf = true);
virtual void setDisabled(bool all = false);
virtual void init();
virtual void start();
virtual void stop();
virtual void raz();
......@@ -77,12 +79,17 @@ public:
DynamicProperty<std::string> dataFilenameFormatValues;
DynamicProperty<std::string> dataFilenameFormatLabels;
Property<int32> presetsChanged;
Property<int32> presetsSize;
DynamicProperty<std::string> presets;
private:
void reset();
bool initApplication();
void stopApplication();
void subscriberLoop();
void initPresets();
void initIndependentDataFileId();
void setDataFilename();
void saveData(const std::string& data);
......
package windeta;
option optimize_for = LITE_RUNTIME;
......@@ -8,7 +7,8 @@ message Request {
enum Type {
START_MEASURE = 1;
STOP_SERVER = 2;
TEST = 3;
PRESETS = 3;
TEST = 4;
}
required Type type = 1;
......@@ -31,6 +31,7 @@ message Event {
enum Type {
STATUS = 1;
DATA = 2;
PRESETS = 3;
}
required Type type = 1;
......@@ -47,6 +48,11 @@ message Status {
required Type type = 1;
}
message Presets {
repeated string list = 1;
}
message Data {
required int32 points = 1;
......
dielectrics_remote_windeta.razPrefix=Stop application
dielectrics_remote_windeta.stopControlPrefix=Stop control
dielectrics_remote_windeta.remote_application=Remote application
dielectrics_remote_windeta.serverPrefix=Server endpoint
dielectrics_remote_windeta.presetPrefix=Preset
......
......@@ -2,7 +2,7 @@
<controller type="dielectrics_remote_windeta" role="dielectrics_remote_windeta1"/>
<composite>
<text role="dielectrics_remote_windeta1" property="preset" prefix="dielectrics_remote_windeta.presetPrefix"/>
<combo role="dielectrics_remote_windeta1" property="preset" prefix="dielectrics_remote_windeta.presetPrefix" key="wantedPresetKey"/>
<property_combo role="dielectrics_remote_windeta1" property="data_filename_format" prefix="dielectrics_remote_windeta.dataFilenameFormatPrefix"/>
</composite>
</plugin>
......@@ -2,7 +2,14 @@
<image key="FREQGEN_CTRL"/>
<settings view="dielectrics_remote_windetaView.xml"/>
<command view="dielectrics_remote_windetaCommandView.xml" backgroundable="true"/>
<settings view="dielectrics_remote_windetaView.xml">
<plugin class="DielectricsRemoteWindetaControllerSetupPlugin"/>
<swt_plugin_peer class="SWTDielectricsRemoteWindetaControllerSetupPluginPeer"/>
</settings>
<command view="dielectrics_remote_windetaCommandView.xml" backgroundable="false">
<plugin class="DielectricsRemoteWindetaControllerCommandPlugin"/>
<swt_plugin_peer class="SWTDielectricsRemoteWindetaControllerCommandPluginPeer"/>
</command>
</controller_plugin_config>
......@@ -11,4 +11,8 @@
<dynamic_property name="data_filename_format_values" type="string" size_property="data_filename_format_size"/>
<dynamic_property name="data_filename_format_labels" type="string" size_property="data_filename_format_size"/>
<property name="presets_changed" type="int32"/>
<property name="presets_size" type="int32"/>
<dynamic_property name="presets" type="string" size_property="presets_size"/>
</controller>
......@@ -13,7 +13,7 @@
<simple_label prefix="dielectrics_remote_windeta.startTimeoutPrefix"/>
<text role="dielectrics_remote_windeta1" property="start_timeout"/>
<simple_label prefix="dielectrics_remote_windeta.presetPrefix"/>
<text role="dielectrics_remote_windeta1" property="preset"/>
<combo role="dielectrics_remote_windeta1" property="preset" key="wantedPresetKey"/>
<simple_label prefix="dielectrics_remote_windeta.dataFilenameFormatPrefix"/>
<property_combo role="dielectrics_remote_windeta1" property="data_filename_format"/>
</table_composite>
......
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