Skip to content

Instantly share code, notes, and snippets.

@heathhenley
Last active August 10, 2023 13:12
Show Gist options
  • Select an option

  • Save heathhenley/d1f106176e819c7c1e3323f5ce5b2add to your computer and use it in GitHub Desktop.

Select an option

Save heathhenley/d1f106176e819c7c1e3323f5ce5b2add to your computer and use it in GitHub Desktop.
Get in-water target bins out of target data
void publish_subscribe_example()
{
/////////////////////////////////////////////
// ZeroMQ pattern: Publish-subscribe
/////////////////////////////////////////////
zmq::context_t context(1);
zmq::socket_t subscr_target_data(context, ZMQ_SUB);
std::string address = "tcp://" + kHost + ":";
std::string port = "61502";
subscr_target_data.connect(address + port);
subscr_target_data.set(zmq::sockopt::subscribe, "");
while (true)
{
zmq::message_t update;
if (subscr_target_data.recv(update, zmq::recv_flags::dontwait))
{
proto::nav_api::TargetData target_data;
if (target_data.ParseFromArray(update.data(), update.size()))
{
printf("Got TargetData!\n");
printf("Sonar serial number: %s\n", target_data.serial().c_str());
int num_groups = target_data.groups_size();
printf("There are %d groups in this ping.\n", num_groups);
for (size_t i = 0; i < num_groups; ++i) {
proto::nav_api::Group iwt_group = target_data.groups().at(i);
int num_bins_in_group = iwt_group.bins_size();
printf(" There are %d bins in this group.\n", num_bins_in_group);
for (size_t j = 0; j < num_bins_in_group; ++j) {
proto::nav_api::Bin bin = iwt_group.bins().at(j);
printf(" iwt detection at: %.2fm crossrange, %.2fm downrange\n",
bin.cross_range(), bin.down_range());
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment