Commit 09e1359e authored by ics's avatar ics

Add different type of property response (int32 and float64)

parent f93ba00e
......@@ -5,8 +5,13 @@ option optimize_for = LITE_RUNTIME;
message PropertyRequest {
required string controllerName = 1;
required string propertyName = 2;
required string propertyType = 3;
}
message PropertyResponse {
message PropertyFloat64Response {
required double value = 1;
}
message PropertyInt32Response {
required int32 value = 1;
}
......@@ -40,7 +40,12 @@ RemotePropertyController::RemotePropertyController(const string& name) :
nbProperties.init(this, SAVE, "nb_properties");
controllerNames.init(this, SAVE, "controller_names");
propertyNames.init(this, SAVE, "property_names");
propertyTypes.init(this, SAVE, "property_types");
loopTimeSec.init(this, SAVE, "loop_time_sec");
loopTimeSec.update(5);
retryTimeSec.init(this, SAVE, "retry_time_sec");
retryTimeSec.update(60);
serverEndpoint.init(this, SAVE, "cameo_server");
initialized.init(this, NOSAVE, "initialized");
......@@ -67,12 +72,18 @@ RemotePropertyController::RemotePropertyController(const RemotePropertyControlle
*/
RemotePropertyController::~RemotePropertyController() {
map<pair<string, string>, Property<float64>*>::iterator iter = m_Properties.begin();
while (iter != m_Properties.end()) {
map<pair<string, string>, Property<float64>*>::iterator iter = m_Float64Properties.begin();
while (iter != m_Float64Properties.end()) {
Property<float64>* prop = iter->second;
delete prop;
++iter;
}
map<pair<string, string>, Property<int32>*>::iterator iter2 = m_Int32Properties.begin();
while (iter2 != m_Int32Properties.end()) {
Property<int32>* prop = iter2->second;
delete prop;
++iter2;
}
if (initialized()) {
_active = false;
// Stop the remote application.
......@@ -94,14 +105,26 @@ void RemotePropertyController::postConfiguration() {
// Create property
for (int32 i = 0; i < controllerNames.getSize(); ++i) {
Property<float64>* prop = new Property<float64>();
ostringstream pname;
if (serverEndpoint().empty() == false) {
pname << serverEndpoint() << "_";
if (propertyTypes.get(i) == "int32") {
Property<int32>* prop = new Property<int32>();
ostringstream pname;
if (serverEndpoint().empty() == false) {
pname << serverEndpoint() << "_";
}
pname << controllerNames.get(i) << "_" << propertyNames.get(i);
prop->init(this, NOSAVE, pname.str());
m_Int32Properties[make_pair(controllerNames.get(i), propertyNames.get(i))] = prop;
}
else {
Property<float64>* prop = new Property<float64>();
ostringstream pname;
if (serverEndpoint().empty() == false) {
pname << serverEndpoint() << "_";
}
pname << controllerNames.get(i) << "_" << propertyNames.get(i);
prop->init(this, NOSAVE, pname.str());
m_Float64Properties[make_pair(controllerNames.get(i), propertyNames.get(i))] = prop;
}
pname << controllerNames.get(i) << "_" << propertyNames.get(i);
prop->init(this, NOSAVE, pname.str());
m_Properties[make_pair(controllerNames.get(i), propertyNames.get(i))] = prop;
}
if (m_driver->state() == REAL_DEVICE_CONTAINER) {
......@@ -119,6 +142,7 @@ void RemotePropertyController::refreshNbProperties(int32 value) throw (CannotSet
}
controllerNames.resize(value);
propertyNames.resize(value);
propertyTypes.resize(value);
}
bool RemotePropertyController::initApplication() {
......@@ -177,20 +201,27 @@ bool RemotePropertyController::initApplication() {
void RemotePropertyController::executeLoop() {
while (_active) {
if (initialized() == true) {
map<pair<string, string>, Property<float64>*>::iterator iter = m_Properties.begin();
while (iter != m_Properties.end()) {
map<pair<string, string>, Property<float64>*>::iterator iter = m_Float64Properties.begin();
while (iter != m_Float64Properties.end()) {
Property<float64>* prop = iter->second;
pair<string, string> names = iter->first;
prop->update(getPropertyValue(names.first, names.second));
++iter;
}
map<pair<string, string>, Property<int32>*>::iterator iter2 = m_Int32Properties.begin();
while (iter2 != m_Int32Properties.end()) {
Property<int32>* prop = iter2->second;
pair<string, string> names = iter2->first;
prop->update(getPropertyInt32Value(names.first, names.second));
++iter2;
}
if (!m_application->exists()) {
initialized = false;
sleep(60);
sleep(retryTimeSec());
}
sleep(5);
sleep(loopTimeSec());
} else {
sleep(60);
sleep(retryTimeSec());
initialized = initApplication();
}
}
......@@ -213,6 +244,35 @@ float64 RemotePropertyController::getPropertyValue(const string& cname, const st
request.set_controllername(cname);
request.set_propertyname(pname);
request.set_propertytype("float64");
// Send the message.
m_requester->sendBinary(request.SerializeAsString());
// cout << getName() << " sent property request " << cname << ":" << pname << 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);
proto::PropertyFloat64Response response;
response.ParseFromString(data);
return response.value();
}
/*
* getPropertyInt32Value
*/
int32 RemotePropertyController::getPropertyInt32Value(const string& cname, const string& pname) {
// Serialize the request.
proto::PropertyRequest request;
request.set_controllername(cname);
request.set_propertyname(pname);
request.set_propertytype("int32");
// Send the message.
m_requester->sendBinary(request.SerializeAsString());
......@@ -224,7 +284,7 @@ float64 RemotePropertyController::getPropertyValue(const string& cname, const st
string data;
m_requester->receiveBinary(data);
proto::PropertyResponse response;
proto::PropertyInt32Response response;
response.ParseFromString(data);
return response.value();
......@@ -232,8 +292,16 @@ float64 RemotePropertyController::getPropertyValue(const string& cname, const st
Property<float64>* RemotePropertyController::getProperty(const std::string& controllerName, const std::string& propertyName) {
Property<float64>* prop = nullptr;
if (m_Properties.find(make_pair(controllerName, propertyName)) != m_Properties.end()) {
prop = m_Properties[make_pair(controllerName, propertyName)];
if (m_Float64Properties.find(make_pair(controllerName, propertyName)) != m_Float64Properties.end()) {
prop = m_Float64Properties[make_pair(controllerName, propertyName)];
}
return prop;
}
Property<int32>* RemotePropertyController::getInt32Property(const std::string& controllerName, const std::string& propertyName) {
Property<int32>* prop = nullptr;
if (m_Int32Properties.find(make_pair(controllerName, propertyName)) != m_Int32Properties.end()) {
prop = m_Int32Properties[make_pair(controllerName, propertyName)];
}
return prop;
}
......
......@@ -62,20 +62,26 @@ public:
Property<int32> nbProperties;
DynamicProperty<std::string> controllerNames;
DynamicProperty<std::string> propertyNames;
DynamicProperty<std::string> propertyTypes;
Property<int32> loopTimeSec;
Property<int32> retryTimeSec;
Property<std::string> serverEndpoint;
Property<bool> initialized;
Property<float64>* getProperty(const std::string& controllerName, const std::string& propertyName);
Property<int32>* getInt32Property(const std::string& controllerName, const std::string& propertyName);
private:
bool initApplication();
float64 getPropertyValue(const std::string& cname, const std::string& pname);
int32 getPropertyInt32Value(const std::string& cname, const std::string& pname);
static void executeStaticLoop(RemotePropertyController* instance);
void executeLoop();
void refreshNbProperties(int32 value) throw(CannotSetValue);
std::map<std::pair<std::string, std::string>, Property<float64>* > m_Properties;
std::map<std::pair<std::string, std::string>, Property<float64>* > m_Float64Properties;
std::map<std::pair<std::string, std::string>, Property<int32>* > m_Int32Properties;
static const std::string REMOTE_APPLICATION;
static const std::string RESPONDER;
......
......@@ -11,13 +11,13 @@
<controller class="utilities::CommandZoneSpy"/>
<controller class="utilities::CommentController"/>
<controller class="utilities::CountSpy"/>
<controller class="utilities::CountSpy"/>
<controller class="utilities::DataParams"/>
<controller class="utilities::InstrumentSettingController"/>
<controller class="utilities::MaintenanceController"/>
<controller class="utilities::NotificationController"/>
<controller class="utilities::ReactorPowerController"/>
<controller class="utilities::RemoteCountSynchro"/>
<controller class="utilities::StatisticEstimator"/>
<controller class="utilities::WaitController"/>
<controller class="utilities::InstrumentSettingController"/>
<controller class="utilities::NotificationController"/>
<controller class="utilities::MaintenanceController"/>
</module>
\ No newline at end of file
/*
* 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 <controllers/common/utilities/RemoteCountSynchro.h>
#include "controllers/common/family/Families.h"
using namespace std;
namespace utilities {
const string RemoteCountSynchro::TYPE = "remote_count_synchro";
/*
* Constructor
*/
RemoteCountSynchro::RemoteCountSynchro(const string& name) :
ExperimentController(name) {
countStatus.init(this, NOSAVE, "count_status");
setFamily(family::HIDDEN);
registerFunction(TYPE);
m_Remote.init(this, "remote");
m_Count.init(this, "count");
m_First = true;
}
/*
* Destructor
*/
RemoteCountSynchro::~RemoteCountSynchro() {
}
void RemoteCountSynchro::postConfiguration() {
registerUpdater(*(m_Remote->getInt32Property("Count", "commandStatus")), &RemoteCountSynchro::updateCountStatus, this);
countStatus.update((*(m_Remote->getInt32Property("Count", "commandStatus")))());
}
void RemoteCountSynchro::updateCountStatus() {
int32 newstatus = (*(m_Remote->getInt32Property("Count", "commandStatus")))();
if (m_First == true) {
m_First = false;
}
else {
if (countStatus() != 2) {
if (newstatus == 2) {
// start acquisition
if (m_Count->commandStatus.isRunning() == true) {
m_Count->stopParallel(true);
}
m_Count->startParallel(true);
}
}
}
countStatus.update(newstatus);
}
}
/*
* 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 REMOTECOUNTSYNCHROCONTROLLER_H
#define REMOTECOUNTSYNCHROCONTROLLER_H
#include <Controller.h>
#include "controllers/common/remote/RemotePropertyController.h"
#include "controllers/common/acquisition/Count.h"
namespace utilities {
/*!
* \class RemoteCountSynchro
* \brief Class described the pressure controller functionality
*/
class RemoteCountSynchro: public ExperimentController {
public:
//! Type of controller
static const std::string TYPE;
/*!
* \brief Constructor
* \param[in] name the name of the experiment controller
*/
RemoteCountSynchro(const std::string& name);
/**
* The destructor of the class Pressure Controller
*/
virtual ~RemoteCountSynchro();
/*!
* \brief Method called before changing the property value
*
* This method is called after setting configuration during the creation of controller.
*/
virtual void postConfiguration();
/*!
* Properties
*/
Property<int32> countStatus;
private:
void updateCountStatus();
ControllerPtr<remote::RemotePropertyController> m_Remote; //! remote controller
ControllerPtr<acquisition::Count> m_Count; //! count
bool m_First;
};
}
#endif //REMOTECOUNTSYNCHROCONTROLLER_H
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