Skip to content
Snippets Groups Projects
Commit b1f3cf64 authored by Marco Kurzynski's avatar Marco Kurzynski
Browse files

checkpoint

parent 8424a252
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,8 @@ using grpc::CompletionQueue; ...@@ -39,7 +39,8 @@ using grpc::CompletionQueue;
using grpc::Status; using grpc::Status;
using shs::Image; using shs::Image;
using shs::Node; using shs::Node;
using shs::Request; using shs::ImageRequest;
using shs::Telemetry;
template <size_t NUM_CHANNELS> class NodeClient { template <size_t NUM_CHANNELS> class NodeClient {
public: public:
...@@ -50,8 +51,8 @@ public: ...@@ -50,8 +51,8 @@ public:
} }
} }
void Exposure() { void FetchImage() {
Request request; ImageRequest request;
request.set_milliseconds(2); request.set_milliseconds(2);
for (int i = 0; i < NUM_CHANNELS; i++) { for (int i = 0; i < NUM_CHANNELS; i++) {
readers_[i] = readers_[i] =
...@@ -71,8 +72,8 @@ public: ...@@ -71,8 +72,8 @@ public:
private: private:
class Reader : public grpc::ClientReadReactor<Image> { class Reader : public grpc::ClientReadReactor<Image> {
public: public:
Reader(Node::Stub *stub, const Request &request, int i) : i_(i) { Reader(Node::Stub *stub, const ImageRequest &request, int i) : i_(i) {
stub->async()->Exposure(&context_, &request, this); stub->async()->FetchImage(&context_, &request, this);
StartCall(); StartCall();
StartRead(&reply_); StartRead(&reply_);
} }
...@@ -84,6 +85,31 @@ private: ...@@ -84,6 +85,31 @@ private:
} }
} }
void OnDone(const Status &s) override { void OnDone(const Status &s) override {
Telemetry reply;
ClientContext context;
std::mutex mu;
std::condition_variable cv;
bool done = false;
Status status;
stub_->async()->FetchTelemetry(&context, &request, &reply,
[&mu, &cv, &done, &status](Status s) {
status = std::move(s);
std::lock_guard<std::mutex> lock(mu);
done = true;
cv.notify_one();
});
std::unique_lock<std::mutex> lock(mu);
cv.wait(lock, []{ return done; });
if (!status.ok()) {
std::cout << status.error_code() << ": " << status.error_message()
<< std::endl;
return;
}
uint64_t unixseconds = reply.unixseconds();
// save picture // save picture
int status = 0; int status = 0;
long naxes[] = {1920, 1200}; long naxes[] = {1920, 1200};
...@@ -129,7 +155,7 @@ int main(int argc, char **argv) { ...@@ -129,7 +155,7 @@ int main(int argc, char **argv) {
grpc::InsecureChannelCredentials()), grpc::InsecureChannelCredentials()),
}; };
NodeClient<1> Node(channels); NodeClient<1> Node(channels);
Node.Exposure(); Node.FetchImage();
return 0; return 0;
} }
...@@ -22,7 +22,7 @@ using grpc::ServerWriteReactor; ...@@ -22,7 +22,7 @@ using grpc::ServerWriteReactor;
using grpc::Status; using grpc::Status;
using shs::Image; using shs::Image;
using shs::Node; using shs::Node;
using shs::Request; using shs::ImageRequest;
using shs::Image; using shs::Image;
...@@ -30,14 +30,13 @@ static AtikCamerasSDKApp app; ...@@ -30,14 +30,13 @@ static AtikCamerasSDKApp app;
class NodeServiceImpl final : public Node::CallbackService { class NodeServiceImpl final : public Node::CallbackService {
public: public:
ServerWriteReactor<Image> *Exposure(CallbackServerContext *context, ServerWriteReactor<Image> *FetchImage(CallbackServerContext *context,
const Request *request) override { const ImageRequest *request) override {
class Streamer : public ServerWriteReactor<Image> { class Streamer : public ServerWriteReactor<Image> {
public: public:
Streamer(const Request *request) { Streamer(const ImageRequest *request) {
app.Start(); app.Start();
memcpy(buff, app.StartExposure(request->milliseconds()), buff = (uint16_t*)app.StartExposure(request->milliseconds());
1920 * 1200 * sizeof(uint16_t));
NextWrite(); NextWrite();
} }
void OnDone() override { void OnDone() override {
...@@ -47,7 +46,7 @@ public: ...@@ -47,7 +46,7 @@ public:
void OnWriteDone(bool) override { NextWrite(); } void OnWriteDone(bool) override { NextWrite(); }
private: private:
uint16_t buff[1920 * 1200]; uint16_t* buff;
AtikCamerasSDKApp app; AtikCamerasSDKApp app;
Image image_; Image image_;
int i_ = 0; int i_ = 0;
......
...@@ -17,13 +17,17 @@ syntax = "proto3"; ...@@ -17,13 +17,17 @@ syntax = "proto3";
package shs; package shs;
service Node { service Node {
rpc Exposure (Request) returns (stream Image) {} rpc FetchImage (ImageRequest) returns (Image) {}
rpc FetchTelemetry (google.protobuf.Empty) returns (Telemetry) {}
} }
message Request { message ImageRequest {
uint32 milliseconds = 1; uint32 milliseconds = 1;
} }
message Image { message Image {
bytes imagedata = 1; bytes imagedata = 1;
} }
message Telemetry {
uint64 unixseconds = 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment