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

Updated D22AutoConfig

parent 9c1e97f6
......@@ -39,7 +39,7 @@ const std::string AutoConfig::REMOTE_APPLICATION = "autoconfig";
const std::string AutoConfig::RESPONDER = "responder";
AutoConfig::AutoConfig(const std::string& name) :
ExperimentController(name), controller::Start(this), Apply(this),
ExperimentController(name), controller::Start(this),
m_countSpy(nullptr) {
setFamily(family::ACQUISITION, family::SETTING);
......@@ -47,8 +47,8 @@ AutoConfig::AutoConfig(const std::string& name) :
serverEndpoint.init(this, SAVE, "cameo_server");
initialized.init(this, NOSAVE, "initialized");
scatterModelType.init(this, NOSAVE, "scatter_model_type");
sampleParameters.init(this, NOSAVE, "sample_parameters");
scatterModelType.init(this, NOSAVE | SPY, "scatter_model_type", "Model");
sampleParameters.init(this, NOSAVE | SPY, "sample_parameters", "Sample");
resultSize.init(this, NOSAVE, "result_size");
type.init(this, NOSAVE, "type");
......@@ -56,7 +56,10 @@ AutoConfig::AutoConfig(const std::string& name) :
wavelength.init(this, NOSAVE, "wavelength");
collimation.init(this, NOSAVE, "collimation");
wantedType.init(this, NOSAVE, "wanted_type");
wantedType.init(this, SAVE | SPY, "wanted_type", "Type");
wantedDistance.init(this, SAVE | SPY, "wanted_distance", "Distance");
wantedWavelength.init(this, SAVE | SPY, "wanted_wavelength", "Wavelength");
wantedCollimation.init(this, SAVE | SPY, "wanted_collimation", "Collimation");
wantedType.setEnumeratedValues(type);
wantedType.setEnumeratedLabels(type);
......@@ -67,7 +70,7 @@ AutoConfig::AutoConfig(const std::string& name) :
}
AutoConfig::AutoConfig(const AutoConfig& controller) :
ExperimentController(controller), controller::Start(this), Apply(this),
ExperimentController(controller), controller::Start(this),
m_countSpy(nullptr) {
}
......@@ -135,6 +138,41 @@ bool AutoConfig::initApplication() {
return false;
}
// Create the requester
m_requester = application::Requester::create(*m_remoteApplication, RESPONDER);
if (m_requester.get() == nullptr) {
cout << "requester error" << endl;
return false;
}
// Initialize the list of types.
// Define the type of request.
lssautoconfig::Request requestType;
requestType.set_type(lssautoconfig::Request::Init);
// Send the request.
m_requester->sendBinary(requestType.SerializeAsString());
// Wait for the response from the server.
string response;
m_requester->receiveBinary(response);
lssautoconfig::InitResponse autoConfigResponse;
autoConfigResponse.ParseFromString(response);
int size = autoConfigResponse.types_size();
resultSize = size;
type.resize(size);
distance.resize(size);
wavelength.resize(size);
collimation.resize(size);
for (int i = 0; i < size; ++i) {
type.set(i, autoConfigResponse.types(i));
}
// Application initialized
initialized = true;
......@@ -188,17 +226,13 @@ void AutoConfig::start() {
return;
}
// Create the requester
unique_ptr<application::Requester> requester = application::Requester::create(*m_remoteApplication, RESPONDER);
if (requester.get() == nullptr) {
cout << "requester error" << endl;
return;
}
// Start date.
Date begin;
// Define the type of request.
lssautoconfig::Request requestType;
requestType.set_type(lssautoconfig::Request::Numor);
// Prepare the request.
lssautoconfig::NumorRequest request;
......@@ -238,18 +272,18 @@ void AutoConfig::start() {
request.set_data(string(reinterpret_cast<const char *>(data), sizeof(int32) * xSize * ySize));
// Send the request.
requester->sendBinary(request.SerializeAsString());
m_requester->sendTwoBinaryParts(requestType.SerializeAsString(), request.SerializeAsString());
// Wait for the response from the server.
string response;
requester->receiveBinary(response);
m_requester->receiveBinary(response);
// Print the duration.
Date end;
double ms = (end - begin).getMilliseconds();
cout << "Request processed in " << ms << " ms" << endl;
lssautoconfig::Response autoConfigResponse;
lssautoconfig::NumorResponse autoConfigResponse;
autoConfigResponse.ParseFromString(response);
int size = autoConfigResponse.results_size();
......@@ -276,6 +310,8 @@ void AutoConfig::start() {
int i = autoConfigResponse.sampleparameters_size() - 1;
sampleParametersString += autoConfigResponse.sampleparameters(i).type() + " " + to_string(autoConfigResponse.sampleparameters(i).value());
sampleParameters = sampleParametersString;
apply();
}
void AutoConfig::apply() {
......@@ -284,6 +320,10 @@ void AutoConfig::apply() {
for (int i = 0; i < size; ++i) {
if (type.get(i) == wantedType()) {
wantedDistance = distance.get(i);
wantedWavelength = wavelength.get(i);
wantedCollimation = collimation.get(i);
m_d22settings->detPosition.setpoint = distance.get(i);
m_d22settings->wavelengthPosition.setpoint = wavelength.get(i);
......
......@@ -28,23 +28,8 @@
namespace d22 {
class Apply : private controller::Command {
public:
Apply(ExperimentController * c) :
controller::Command(c, "apply", &Apply::apply, this) {
}
virtual void apply() = 0;
void applyCommand(bool logging = false) {
command(logging, true);
}
};
class AutoConfig : public ExperimentController,
public controller::Start,
public Apply {
public controller::Start {
public:
//! Type of controller
......@@ -56,8 +41,9 @@ public:
virtual void postConfiguration();
void apply();
virtual void start();
virtual void apply();
Property<std::string> serverEndpoint;
Property<bool> initialized;
......@@ -72,6 +58,9 @@ public:
DynamicProperty<float64> collimation;
Property<std::string> wantedType;
Property<float64> wantedDistance;
Property<float64> wantedWavelength;
Property<float64> wantedCollimation;
private:
bool initApplication();
......@@ -82,6 +71,7 @@ private:
std::unique_ptr<cameo::Server> m_server;
std::unique_ptr<cameo::application::Instance> m_remoteApplication;
std::unique_ptr<cameo::application::Requester> m_requester;
ControllerPtr<D22Settings> m_d22settings;
ControllerPtr<remotelsssimulation::RemoteLSSSimulation> m_simulation;
......
......@@ -2,6 +2,15 @@ package lssautoconfig;
option optimize_for = LITE_RUNTIME;
message Request {
enum Type {
Init = 1;
Numor = 2;
}
required Type type = 1;
}
message InstrumentParameters {
......@@ -37,7 +46,12 @@ message Result {
required string type = 2;
}
message Response {
message InitResponse {
repeated string types = 1;
}
message NumorResponse {
required string scatterModelType = 1;
repeated SampleParameters sampleParameters = 2;
......
<plugin>
<controller type="d22_auto_config" role="d22_auto_config1"/>
<number_of_lines nb_lines="1"/>
<property_combo role="d22_auto_config1" property="wanted_type" prefix="d22_auto_config.wantedTypePrefix"/>
</plugin>
......@@ -32,7 +32,6 @@
<group title="d22_auto_config.applyPrefix">
<property_combo role="d22_auto_config1" property="wanted_type" prefix="d22_auto_config.wantedTypePrefix"/>
<button role="d22_auto_config1" command="apply" prefix="d22_auto_config.applyPrefix"/>
</group>
</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