Commit 47d2fd67 authored by yannick legoc's avatar yannick legoc
Browse files

Receiving events from Windeta app

parent e6b76b41
......@@ -37,7 +37,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), Test(this) {
ExperimentController(name), controller::Stoppable(this), controller::Raz(this), Test(this) {
setFamily(family::ACQUISITION, family::POLARIZATIONS);
......@@ -49,7 +49,7 @@ RemoteWindeta::RemoteWindeta(const std::string& name) :
}
RemoteWindeta::RemoteWindeta(const RemoteWindeta& controller) :
ExperimentController(controller), controller::Stoppable(this), Test(this) {
ExperimentController(controller), controller::Stoppable(this), controller::Raz(this), Test(this) {
}
RemoteWindeta::~RemoteWindeta() {
......@@ -134,10 +134,10 @@ bool RemoteWindeta::initApplication() {
}
// Create a new subscriber.
// m_subscriber = application::Subscriber::create(*m_windetaApplication, PUBLISHER_NAME);
//
// // Start the subscriber loop
// m_subscriberThread.reset(new boost::thread(boost::bind(&RemoteWindeta::subscriberLoop, this)));
m_subscriber = application::Subscriber::create(*m_windetaApplication, PUBLISHER_NAME);
// Start the subscriber loop
m_subscriberThread.reset(new boost::thread(boost::bind(&RemoteWindeta::subscriberLoop, this)));
// Application initialized.
initialized = true;
......@@ -190,10 +190,8 @@ void RemoteWindeta::start() {
windeta::StartMeasure requestMessage;
requestMessage.set_preset("preset");
requestMessage.set_path("");
requestMessage.set_filename("test");
// // Send the message.
// Send the message.
m_requester->sendTwoBinaryParts(requestType.SerializeAsString(), requestMessage.SerializeAsString());
cout << getName() << " sent request " << static_cast<int>(requestType.type()) << endl;
......@@ -208,7 +206,10 @@ void RemoteWindeta::start() {
cout << "received response " << response.errorcode() << endl;
// Sleep before two requests?
// Loop on the status...
sleep(1);
commandStatus.setIdle();
}
void RemoteWindeta::stop() {
......@@ -217,28 +218,12 @@ void RemoteWindeta::stop() {
return;
}
// Serialize the request.
windeta::Request requestType;
requestType.set_type(windeta::Request::STOP_MEASURE);
windeta::StopMeasure requestMessage;
// Send the message.
m_requester->sendTwoBinaryParts(requestType.SerializeAsString(), requestMessage.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 << "stop to be implemented" << endl;
}
cout << "received response " << response.errorcode() << endl;
void RemoteWindeta::raz() {
commandStatus.setIdle();
stopApplication();
}
void RemoteWindeta::test() {
......@@ -309,9 +294,34 @@ void RemoteWindeta::stopApplication() {
void RemoteWindeta::subscriberLoop() {
// Loop on events
string data;
while (m_subscriber->receiveBinary(data)) {
string data1;
string data2;
while (m_subscriber->receiveTwoBinaryParts(data1, data2)) {
windeta::Event event;
event.ParseFromString(data1);
if (event.type() == windeta::Event::STATUS) {
windeta::Status status;
status.ParseFromString(data2);
if (status.type() == windeta::Status::STARTED) {
cout << "Started" << endl;
}
else if (status.type() == windeta::Status::FINISHED) {
cout << "Finished" << endl;
}
else if (status.type() == windeta::Status::ERROR) {
cout << "Error" << endl;
}
}
else if (event.type() == windeta::Event::DATA) {
windeta::Data data;
data.ParseFromString(data2);
cout << "Data " << data.points() << " points" << endl;
}
}
}
......
......@@ -43,6 +43,7 @@ public:
class RemoteWindeta : public ExperimentController,
public controller::Stoppable,
public controller::Raz,
public Test {
public:
......@@ -60,6 +61,7 @@ public:
virtual void start();
virtual void stop();
virtual void raz();
virtual void test();
Property<std::string> serverEndpoint;
......
package windeta;
option optimize_for = LITE_RUNTIME;
message Request {
enum Type {
START_MEASURE = 1;
STOP_MEASURE = 2;
STOP_SERVER = 3;
TEST = 4;
}
required Type type = 1;
enum Type {
START_MEASURE = 1;
STOP_SERVER = 2;
TEST = 3;
}
required Type type = 1;
}
message StartMeasure {
required string preset = 1;
required string path = 2;
required string filename = 3;
}
message StopMeasure {
required string preset = 1;
}
message StopServer {
}
message Response {
required int32 errorCode = 1;
required int32 errorCode = 1;
}
message Event {
enum Type {
STATUS = 1;
DATA = 2;
}
required Type type = 1;
}
message Status {
enum Type {
STARTED = 1;
FINISHED = 2;
ERROR = 3;
}
required Type type = 1;
}
message Data {
required int32 points = 1;
required string data = 2;
}
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