gps_rtk.cpp
Go to the documentation of this file.
1 
9 /*
10  * Copyright 2018 Alexis Paques.
11  *
12  * This file is part of the mavros package and subject to the license terms
13  * in the top-level LICENSE file of the mavros repository.
14  * https://github.com/mavlink/mavros/tree/master/LICENSE.md
15  */
16 
17 #include <mavros/mavros_plugin.h>
18 #include <mavros_msgs/RTCM.h>
19 #include <algorithm>
20 
21 namespace mavros {
22 namespace extra_plugins {
29 public:
31  gps_rtk_nh("~gps_rtk")
32  { }
33 
34  void initialize(UAS &uas_)
35  {
37  gps_rtk_sub = gps_rtk_nh.subscribe("send_rtcm", 10, &GpsRtkPlugin::rtcm_cb, this);
38  }
39 
41  {
42  return {};
43  }
44 
45 private:
48 
49  /* -*- callbacks -*- */
57  {
58  mavlink::common::msg::GPS_RTCM_DATA rtcm_data;
59  const size_t max_frag_len = rtcm_data.data.size();
60 
61  uint8_t seq_u5 = uint8_t(msg->header.seq & 0x1F) << 3;
62 
63  if (msg->data.size() > 4 * max_frag_len) {
64  ROS_FATAL("gps_rtk: RTCM message received is bigger than the maximal possible size.");
65  return;
66  }
67 
68  auto data_it = msg->data.begin();
69  auto end_it = msg->data.end();
70 
71  if (msg->data.size() <= max_frag_len) {
72  rtcm_data.len = msg->data.size();
73  rtcm_data.flags = seq_u5;
74  std::copy(data_it, end_it, rtcm_data.data.begin());
75  std::fill(rtcm_data.data.begin() + rtcm_data.len, rtcm_data.data.end(), 0);
76  UAS_FCU(m_uas)->send_message(rtcm_data);
77  } else {
78  for (uint8_t fragment_id = 0; fragment_id < 4 && data_it < end_it; fragment_id++) {
79  uint8_t len = std::min((size_t) std::distance(data_it, end_it), max_frag_len);
80  rtcm_data.flags = 1; // LSB set indicates message is fragmented
81  rtcm_data.flags |= fragment_id << 1; // Next 2 bits are fragment id
82  rtcm_data.flags |= seq_u5; // Next 5 bits are sequence id
83  rtcm_data.len = len;
84 
85  std::copy(data_it, data_it + len, rtcm_data.data.begin());
86  std::fill(rtcm_data.data.begin() + len, rtcm_data.data.end(), 0);
87  UAS_FCU(m_uas)->send_message(rtcm_data);
88  std::advance(data_it, len);
89  }
90  }
91  }
92 };
93 } // namespace extra_plugins
94 } // namespace mavros
95 
std::shared_ptr< MAVConnInterface const > ConstPtr
#define ROS_FATAL(...)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ssize_t len
void rtcm_cb(const mavros_msgs::RTCM::ConstPtr &msg)
Handle mavros_msgs::RTCM message It converts the message to the MAVLink GPS_RTCM_DATA message for GPS...
Definition: gps_rtk.cpp:56
#define UAS_FCU(uasobjptr)
std::vector< HandlerInfo > Subscriptions
void initialize(UAS &uas_)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


mavros_extras
Author(s): Vladimir Ermakov
autogenerated on Mon Jul 8 2019 03:20:18