Skip to content
Snippets Groups Projects
Commit 6676778d authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Catch net exceptions and log output

parent 1a338ed3
No related branches found
No related tags found
1 merge request!23Feature/gui implements #53
Pipeline #11116 passed
......@@ -15,23 +15,28 @@ using std::this_thread::sleep_for;
using std::chrono::milliseconds;
bool NetSource::_getCalibration(Universe &net, const UUID &peer, const string &src, ftl::rgbd::CameraParameters &p) {
while(true) {
auto buf = net.call<vector<unsigned char>>(peer_, "source_calibration", src);
if (buf.size() > 0) {
memcpy((char*)&p, buf.data(), buf.size());
if (sizeof(p) != buf.size()) {
LOG(ERROR) << "Corrupted calibration";
return false;
try {
while(true) {
auto buf = net.call<vector<unsigned char>>(peer_, "source_calibration", src);
if (buf.size() > 0) {
memcpy((char*)&p, buf.data(), buf.size());
if (sizeof(p) != buf.size()) {
LOG(ERROR) << "Corrupted calibration";
return false;
}
LOG(INFO) << "Calibration received: " << p.cx << ", " << p.cy << ", " << p.fx << ", " << p.fy;
return true;
} else {
LOG(INFO) << "Could not get calibration, retrying";
sleep_for(milliseconds(500));
}
LOG(INFO) << "Calibration received: " << p.cx << ", " << p.cy << ", " << p.fx << ", " << p.fy;
return true;
} else {
LOG(INFO) << "Could not get calibration, retrying";
sleep_for(milliseconds(500));
}
} catch (...) {
return false;
}
}
......@@ -59,7 +64,11 @@ NetSource::NetSource(nlohmann::json &config, ftl::net::Universe *net)
N_ = 10;
// Initiate stream with request for first 10 frames
net->send(peer_, "get_stream", getURI(), 10, 0, net->id(), getURI());
try {
net->send(peer_, "get_stream", getURI(), 10, 0, net->id(), getURI());
} catch(...) {
LOG(ERROR) << "Could not connect to stream " << getURI();
}
}
NetSource::~NetSource() {
......@@ -81,7 +90,11 @@ void NetSource::_recv(const vector<unsigned char> &jpg, const vector<unsigned ch
void NetSource::setPose(const Eigen::Matrix4f &pose) {
vector<unsigned char> vec((unsigned char*)pose.data(), (unsigned char*)(pose.data()+(pose.size())));
net_->send(peer_, "set_pose", getURI(), vec);
try {
net_->send(peer_, "set_pose", getURI(), vec);
} catch (...) {
}
RGBDSource::setPose(pose);
}
......
......@@ -30,8 +30,10 @@ Streamer::Streamer(nlohmann::json &config, Universe *net)
net_ = net;
net->bind("find_stream", [this](const std::string &uri) -> optional<UUID> {
if (sources_.find(uri) != sources_.end()) return net_->id();
else return {};
if (sources_.find(uri) != sources_.end()) {
LOG(INFO) << "Valid source request received: " << uri;
return net_->id();
} else return {};
});
net->bind("list_streams", [this]() -> vector<string> {
......@@ -91,6 +93,8 @@ void Streamer::add(RGBDSource *src) {
s->src = src;
s->state = 0;
sources_[src->getURI()] = s;
LOG(INFO) << "Added source: " << src->getURI();
}
void Streamer::_addClient(const string &source, int N, int rate, const ftl::UUID &peer, const string &dest) {
......
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