Commit 70857ad2 authored by Cristina Cocho's avatar Cristina Cocho
Browse files

After merge with collisions. Corrections related to Cameo

parents 1c2e1d98 d4a59f54
......@@ -50,6 +50,7 @@ AxisRecorder::~AxisRecorder() {
void AxisRecorder::postConfiguration() {
m_experimentControllersMap = InstrumentManager::getInstance()->getAllInstalledExperimentControllersMap(m_Clone);
map<string, ExperimentController*>::iterator it;
for (it = m_experimentControllersMap.begin(); it != m_experimentControllersMap.end(); it++) {
......
......@@ -47,8 +47,7 @@ CyclopsDataHeader::CyclopsDataHeader(const string& name) :
m_ScanInfo.init(this, "scan_info");
m_CyclopsSetting.init(this, "cyclops_setting");
map<string, ExperimentController*> experimentControllersMap =
InstrumentManager::getInstance()->getAllInstalledExperimentControllersMap(m_Clone);
map<string, ExperimentController*> experimentControllersMap = InstrumentManager::getInstance()->getAllInstalledExperimentControllersMap(m_Clone);
map<string, ExperimentController*>::iterator it;
for (it = experimentControllersMap.begin(); it != experimentControllersMap.end(); it++) {
if (dynamic_cast<axis::AxisController*>(it->second) != 0) {
......
......@@ -69,9 +69,9 @@ GpCamComController::~GpCamComController() {
m_remoteApplication->stop();
// Wait for the termination
application::State state = m_remoteApplication->waitFor();
cameo::State state = m_remoteApplication->waitFor();
cout << "Remote application " << m_remoteApplication->getName() << " terminated with state " << application::toString(state) << endl;
cout << "Remote application " << m_remoteApplication->getName() << " terminated with state " << cameo::toString(state) << endl;
}
}
......@@ -81,11 +81,12 @@ void GpCamComController::postConfiguration() {
// Create a new server if it is not already created.
// In case of a simulated server, avoid the real remote endpoint.
if (serverEndpoint() == "" || m_driver->state() != REAL_DEVICE_CONTAINER) {
m_server.reset(new Server(application::This::getServer().getEndpoint()));
m_server = cameo::Server::create(cameo::This::getServer().getEndpoint());
}
else {
m_server.reset(new Server(serverEndpoint(), 1000));
m_server = cameo::Server::create(serverEndpoint(), 1000);
}
m_server->init();
}
initialized = initApplication();
......@@ -161,38 +162,41 @@ bool GpCamComController::initApplication() {
cout << "Remote server is connected" << endl;
m_remoteApplication = m_server->connect(REMOTE_APPLICATION);
if (m_remoteApplication->exists()) {
if (m_remoteApplication) {
// The application exists from a previous server session
m_remoteApplication->kill();
application::State state = m_remoteApplication->waitFor();
cout << "Terminated remote application with state " << application::toString(state) << endl;
cameo::State state = m_remoteApplication->waitFor();
cout << "Terminated remote application with state " << cameo::toString(state) << endl;
}
m_remoteApplication = m_server->start(REMOTE_APPLICATION);
if (!m_remoteApplication->exists()) {
try {
m_remoteApplication = m_server->start(REMOTE_APPLICATION);
} catch (...) {
cout << "No remote application" << endl;
return false;
}
// Create the requester
m_requester = application::Requester::create(*m_remoteApplication, RESPONDER);
m_requester = coms::Requester::create(*m_remoteApplication, RESPONDER);
if (m_requester.get() == 0) {
cout << "requester error" << endl;
return false;
}
m_requester->init();
// Create the subscriber.
m_subscriber = application::Subscriber::create(*m_remoteApplication, "publisher");
m_subscriber = coms::Subscriber::create(*m_remoteApplication, "publisher");
m_subscriber->init();
m_subscriberThread.reset(new std::thread([this] {
string event;
std::optional<std::string> event;
while (m_subscriber->receive(event)) {
while (event = m_subscriber->receive()) {
cout << "Received " << event << endl;
cout << "Received " << event.value() << endl;
}
}));
......@@ -237,16 +241,15 @@ void GpCamComController::start() {
// Init gpCAM.
m_requester->send(createInitRequest());
string responseMessage;
m_requester->receive(responseMessage);
std::optional<std::string> responseMessage = m_requester->receive();
cout << "Init response " << responseMessage << endl;
cout << "Init response " << responseMessage.value()<< endl;
// Test next point.
m_requester->send(createNextPointRequest());
m_requester->receive(responseMessage);
responseMessage = m_requester->receive();
cout << "Next point response " << responseMessage << endl;
cout << "Next point response " << responseMessage.value() << endl;
}
void GpCamComController::stop() {
......
......@@ -23,7 +23,7 @@
#include <controllers/common/acquisition/ExperimentData.h>
#include <controllers/common/utilities/CountSpy.h>
#include <drivers/utilities/null/NullDriver.h>
#include <cameo/cameo.h>
#include <cameo/api/cameo.h>
namespace gpcam {
......@@ -61,9 +61,9 @@ private:
static const std::string PUBLISHER;
std::unique_ptr<cameo::Server> m_server;
std::unique_ptr<cameo::application::Instance> m_remoteApplication;
std::unique_ptr<cameo::application::Requester> m_requester;
std::unique_ptr<cameo::application::Subscriber> m_subscriber;
std::unique_ptr<cameo::App> m_remoteApplication;
std::unique_ptr<cameo::coms::Requester> m_requester;
std::unique_ptr<cameo::coms::Subscriber> m_subscriber;
std::unique_ptr<std::thread> m_subscriberThread;
std::vector<scan::GenericScan1D*> m_scanControllers;
......
......@@ -125,15 +125,16 @@ void GpCamComSlave::postConfiguration() {
// Create a new server if it is not already created.
// In case of a simulated server, avoid the real remote endpoint.
if (gpCAMServerEndpoint() == "" || m_driver->state() != REAL_DEVICE_CONTAINER) {
m_gpCAMServer.reset(new Server(application::This::getServer().getEndpoint()));
m_gpCAMServer = Server::create(cameo::This::getServer().getEndpoint());
}
else {
m_gpCAMServer.reset(new Server(gpCAMServerEndpoint(), 1000));
m_gpCAMServer = Server::create(gpCAMServerEndpoint(), 1000);
}
}
// Create the responder.
m_responder = application::Responder::create("gpcam-responder");
m_responder = coms::basic::Responder::create("gpcam-responder");
m_responder->init();
// Register the property updaters.
registerFloat64PropertyUpdater(m_tasSettings->as, as);
......@@ -168,7 +169,7 @@ bool GpCamComSlave::initApplication() {
cout << "gpCAM server is connected" << endl;
m_gpCAMApplication = m_gpCAMServer->connect(GPCAM_APPLICATION);
if (m_gpCAMApplication->exists()) {
if (m_gpCAMApplication) {
// The application already exists.
gpCAMMode = MANUAL;
......@@ -180,9 +181,9 @@ bool GpCamComSlave::initApplication() {
gpCAMMode = AUTOMATIC;
// We start the app.
m_gpCAMApplication = m_gpCAMServer->start(GPCAM_APPLICATION);
if (!m_gpCAMApplication->exists()) {
try {
m_gpCAMApplication = m_gpCAMServer->start(GPCAM_APPLICATION);
} catch (...) {
cout << "No remote application" << endl;
return false;
}
......@@ -380,7 +381,7 @@ void GpCamComSlave::start() {
cout << "Waiting for request" << endl;
// Get the request.
unique_ptr<application::Request> request = m_responder->receive();
unique_ptr<coms::basic::Request> request = m_responder->receive();
// The responder is canceled.
if (request.get() == nullptr) {
......@@ -571,9 +572,9 @@ void GpCamComSlave::stop() {
cout << "Stopping gpCAM" << endl;
m_gpCAMApplication->stop();
application::State state = m_gpCAMApplication->waitFor();
cameo::State state = m_gpCAMApplication->waitFor();
cout << "gpCAM application " << m_gpCAMApplication->getName() << " terminated with state " << application::toString(state) << endl;
cout << "gpCAM application " << m_gpCAMApplication->getName() << " terminated with state " << cameo::toString(state) << endl;
}
else {
cout << "Do not stop gpCAM in mode " << gpCAMMode() << endl;
......
......@@ -27,7 +27,7 @@
#include "controllers/tas/common/IncidentBeam.h"
#include "controllers/tas/common/TasScatteredBeam.h"
#include <drivers/utilities/null/NullDriver.h>
#include <cameo/cameo.h>
#include <cameo/api/cameo.h>
namespace gpcam {
......@@ -104,9 +104,9 @@ private:
ControllerPtr<tas::IncidentBeam> m_incidentBeam;
ControllerPtr<tas::TasScatteredBeam> m_scatteredBeam;
std::unique_ptr<cameo::application::Responder> m_responder;
std::unique_ptr<cameo::coms::basic::Responder> m_responder;
std::unique_ptr<cameo::Server> m_gpCAMServer;
std::unique_ptr<cameo::application::Instance> m_gpCAMApplication;
std::unique_ptr<cameo::App> m_gpCAMApplication;
static constexpr float64 WE = 2.702;
......
......@@ -89,9 +89,9 @@ ReductionController::~ReductionController() {
m_remoteApplication->stop();
// Wait for the termination
application::State state = m_remoteApplication->waitFor();
cameo::State state = m_remoteApplication->waitFor();
cout << "Remote application " << m_remoteApplication->getName() << " terminated with state " << application::toString(state) << endl;
cout << "Remote application " << m_remoteApplication->getName() << " terminated with state " << cameo::toString(state) << endl;
}
}
......@@ -101,11 +101,12 @@ void ReductionController::postConfiguration() {
// Create a new server if it is not already created.
// In case of a simulated server, avoid the real remote endpoint.
if (serverEndpoint() == "" || m_driver->state() != REAL_DEVICE_CONTAINER) {
m_server.reset(new Server(application::This::getServer().getEndpoint()));
m_server = Server::create(This::getServer().getEndpoint());
}
else {
m_server.reset(new Server(serverEndpoint(), 1000));
m_server = Server::create(serverEndpoint(), 1000);
}
m_server->init();
}
initialized = initApplication();
......@@ -212,40 +213,42 @@ bool ReductionController::initApplication() {
cout << "Remote server is connected" << endl;
m_remoteApplication = m_server->connect(REMOTE_APPLICATION);
if (m_remoteApplication->exists()) {
if (m_remoteApplication) {
// The application exists from a previous server session
m_remoteApplication->kill();
application::State state = m_remoteApplication->waitFor();
cout << "Terminated remote application with state " << application::toString(state) << endl;
cameo::State state = m_remoteApplication->waitFor();
cout << "Terminated remote application with state " << cameo::toString(state) << endl;
}
m_remoteApplication = m_server->start(REMOTE_APPLICATION);
if (!m_remoteApplication->exists()) {
try {
m_remoteApplication = m_server->start(REMOTE_APPLICATION);
} catch (...) {
cout << "No remote application" << endl;
return false;
}
// Create the requester
m_requester = application::Requester::create(*m_remoteApplication, RESPONDER);
m_requester = coms::Requester::create(*m_remoteApplication, RESPONDER);
if (m_requester.get() == 0) {
cout << "requester error" << endl;
return false;
}
m_requester->init();
// Create the subscriber.
m_subscriber = application::Subscriber::create(*m_remoteApplication, "publisher");
m_subscriber = coms::Subscriber::create(*m_remoteApplication, "publisher");
m_subscriber->init();
m_subscriberThread.reset(new std::thread([this] {
string result;
std::optional<std::string> result;
while (m_subscriber->receiveBinary(result)) {
while (result = m_subscriber->receive()) {
// Parse the response.
madman::Result fileResult;
fileResult.ParseFromString(result);
fileResult.ParseFromString(result.value());
// Write the file to disk.
writeFile(PROCESSED_FILE, fileResult.content());
......@@ -554,11 +557,10 @@ void ReductionController::resetReduction() {
madman::EmptyRequest request;
// Send the file content to the server.
m_requester->sendTwoBinaryParts(type.SerializeAsString(), request.SerializeAsString());
m_requester->sendTwoParts(type.SerializeAsString(), request.SerializeAsString());
// Wait for the response from the server.
string response;
m_requester->receive(response);
std::optional<std::string> response = m_requester->receive();
}
void ReductionController::startReduction() {
......@@ -598,11 +600,10 @@ void ReductionController::startReduction() {
request.set_content(fileContent);
// Send the file content to the server.
m_requester->sendTwoBinaryParts(type.SerializeAsString(), request.SerializeAsString());
m_requester->sendTwoParts(type.SerializeAsString(), request.SerializeAsString());
// Wait for the response from the server.
string response;
m_requester->receive(response);
std::optional<std::string> response = m_requester->receive();
}
......
......@@ -23,7 +23,7 @@
#include <controllers/common/acquisition/ExperimentData.h>
#include <controllers/common/utilities/CountSpy.h>
#include <drivers/utilities/null/NullDriver.h>
#include <cameo/cameo.h>
#include <cameo/api/cameo.h>
namespace mantid {
......@@ -94,9 +94,9 @@ private:
static const std::string PROCESSED_AUTO;
std::unique_ptr<cameo::Server> m_server;
std::unique_ptr<cameo::application::Instance> m_remoteApplication;
std::unique_ptr<cameo::application::Requester> m_requester;
std::unique_ptr<cameo::application::Subscriber> m_subscriber;
std::unique_ptr<cameo::App> m_remoteApplication;
std::unique_ptr<cameo::coms::Requester> m_requester;
std::unique_ptr<cameo::coms::Subscriber> m_subscriber;
std::unique_ptr<std::thread> m_subscriberThread;
std::vector<scan::GenericScan1D*> m_scanControllers;
......
<module name="nomad3d">
<controller class="nomad3d::Nomad3DController"/>
<controller class="nomad3d::Parameters3d"/>
<controller class="nomad3d::Nomad3DControllerFilter"/>
<include path="$(NOMAD_HOME)/../nomad-modules/src"/>
<include path="$(NOMAD_HOME)/../NomadModules/src"/>
......
/*
* 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.
*/
#include "Nomad3D.h"
#include "DataProvider/Units.h" //!!
#include "InstrumentManager/InstrumentManager.h"
using namespace std;
using namespace rapidjson;
namespace nomad3d {
const std::string Nomad3D::TYPE = "nomad3d";
Nomad3D::Nomad3D(const std::string &name) :
ExperimentController(name), controller::Init(this) {
axisPositions.init(this, NOSAVE, "axis_positions");
}
Nomad3D::Nomad3D(const Nomad3D &controller) :
ExperimentController(controller) {
}
Nomad3D::~Nomad3D() {
}
void Nomad3D::init() {
map<string, ExperimentController*> experimentControllersMap = InstrumentManager::getInstance()->getAllInstalledExperimentControllersMap(m_Clone);
map<string, ExperimentController*>::iterator it;
int i = 0;
// Iterate the controllers.
for (it = experimentControllersMap.begin(); it != experimentControllersMap.end(); it++) {
// Get the AxisController controllers.
if (dynamic_cast<axis::AxisController*>(it->second) != 0) {
axis::AxisController *controller = dynamic_cast<axis::AxisController*>(it->second);
if (addData(controller)) {
controller->attach(this); //Attach it to in order to be able to receive propertyChanged events.
AxisControllerData data;
data.controller = controller;
data.name = controller->getName();
data.coef = getUnitCoef(controller->unit());
data.minPosition = controller->minPosition();
data.maxPosition = controller->maxPosition();
data.initPosition = (0.5 * (controller->minPosition() + controller->maxPosition())) * data.coef;
m_axisControllers.push_back(data);
registerUpdater(controller->position, &Nomad3D::updateActualPosition, this, i);
++i;
}
}
// Get the VirtualAxisController controllers.
if (dynamic_cast<axis::VirtualAxisController*>(it->second) != 0) {
axis::VirtualAxisController *controller = dynamic_cast<axis::VirtualAxisController*>(it->second);
if (addData(controller)) {
controller->attach(this); //Attach it to in order to be able to receive propertyChanged events.
VirtualAxisControllerData data;
data.controller = controller;
data.name = controller->getName();
data.coef = getUnitCoef(controller->unit());
data.minPosition = controller->minPosition();
data.maxPosition = controller->maxPosition();
data.initPosition = (0.5 * (controller->minPosition() + controller->maxPosition())) * data.coef;
m_virtualAxisControllers.push_back(data);
registerUpdater(controller->position, &Nomad3D::updateActualPosition, this, i);
++i;
}
}
}
}
void Nomad3D::obtainPositionsContent(rapidjson::Writer<rapidjson::StringBuffer>& writer) {
for (auto data : m_axisControllers) {
writer.Key(data.name.c_str());
// Do not apply the offset.
float64 position = data.controller->position();
writer.Double(position * data.coef); // only send the position
}
// Write the virtual axis controllers.
for (auto data : m_virtualAxisControllers) {
writer.Key(data.name.c_str());
// Do not apply the offset.
writer.Double(data.controller->position() * data.coef);
}
}
double Nomad3D::getUnitCoef(const std::string &unit) {
if (unit == unit::DEGREE) {
return 1.;
}
if (unit == unit::MILLIMETER) {
return 1.;
}
if (unit == unit::CENTIMETER) {
return 10.;
}
if (unit == unit::DECIMETER) {
return 100.;
}
if (unit == unit::METER) {
return 1000.;
}
std::cerr << "Unit " << unit << " not supported" << std::endl;
return 1; // Default value changed!!!! In Nomad3DController is 0!
}
bool Nomad3D::addData(axis::AxisController *controller) {
return true;
}
bool Nomad3D::addData(axis::VirtualAxisController *controller) {
return true;
}
}
/*
* 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.
*/
#ifndef SRC_CONTROLLERS_NOMAD3D_NOMAD3D_H_
#define SRC_CONTROLLERS_NOMAD3D_NOMAD3D_H_
#include <string>
#include <iostream>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <Controller.h>
#include "controllers/common/axis/AxisController.h"
#include "controllers/common/axis/VirtualAxisController.h"
namespace nomad3d {
class Nomad3D : public ExperimentController, public controller::Init {
public:
static const std::string TYPE;
Nomad3D(const std::string& name);
Nomad3D(const Nomad3D& controller);
virtual ~Nomad3D();
virtual void postConfiguration() {};
virtual void init();
void obtainPositionsContent(rapidjson::Writer<rapidjson::StringBuffer>& writer);
static double getUnitCoef(const std::string& unit);
protected:
struct AxisControllerData {
axis::AxisController* controller;
std::string name;
double coef;
float64 minPosition;
float64 maxPosition;
float64 initPosition; // for filtering
};
std::vector<AxisControllerData> m_axisControllers;
struct VirtualAxisControllerData {
axis::VirtualAxisController* controller;
std::string name;
double coef;
float64 minPosition;
float64 maxPosition;
float64 initPosition; // for filtering
};
std::vector<VirtualAxisControllerData> m_virtualAxisControllers;
virtual void updateActualPosition(int32 i) {};
virtual bool addData(axis::AxisController *controller);
virtual bool addData(axis::VirtualAxisController *controller);
Property<std::string> axisPositions;
rapidjson::StringBuffer s;
};