Goby3 3.4.0
2026.04.13
Loading...
Searching...
No Matches
popoto_driver.h
Go to the documentation of this file.
1// Copyright 2020-2026:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6// Thomas McCabe <tom.mccabe@missionsystems.com.au>
7//
8//
9// This file is part of the Goby Underwater Autonomy Project Libraries
10// ("The Goby Libraries").
11//
12// The Goby Libraries are free software: you can redistribute them and/or modify
13// them under the terms of the GNU Lesser General Public License as published by
14// the Free Software Foundation, either version 2.1 of the License, or
15// (at your option) any later version.
16//
17// The Goby Libraries are distributed in the hope that they will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with Goby. If not, see <http://www.gnu.org/licenses/>.
24
25/************************************************************/
26/* NAME: Thomas McCabe */
27/* ORGN: Mission Systems Pty Ltd */
28/* FILE: Popoto.h */
29/* DATE: Aug 20 2020 */
30/************************************************************/
31
32/* Copyright (c) 2020 mission systems pty ltd */
33
34#ifndef GOBY_ACOMMS_MODEMDRIVER_POPOTO_DRIVER_H
35#define GOBY_ACOMMS_MODEMDRIVER_POPOTO_DRIVER_H
36
37#include <cstddef> // for size_t
38#include <cstdint> // for uint8_t
39#include <map> // for map
40#include <string> // for string
41#include <vector> // for vector
42
43#include "goby/acomms/modemdriver/driver_base.h" // for ModemDriverBase
44#include "goby/acomms/protobuf/driver_base.pb.h" // for DriverConfig
45#include "goby/acomms/protobuf/modem_message.pb.h" // for ModemTransmission
46#include "goby/acomms/protobuf/popoto_driver.pb.h" // for Config, MessageTy...
47#include "goby/util/thirdparty/nlohmann/json.hpp" // for json
48
49namespace goby
50{
51namespace acomms
52{
54{
55 public:
57 ~PopotoDriver() override;
58
59 void startup(const protobuf::DriverConfig& cfg) override;
60 void shutdown() override;
61 void do_work() override;
67 void send_wake(void);
68 void send_range_request(int dest);
69 void popoto_sleep(void);
70
71 private:
72 void parse_in(const std::string& in, std::map<std::string, std::string>* out);
73
74 void set_popoto_value(const std::string& key, int val)
75 {
76 send_popoto_command("SetValue", key + " int " + std::to_string(val));
77 }
78 void set_popoto_value(const std::string& key, float val)
79 {
80 send_popoto_command("SetValue", key + " float " + std::to_string(val));
81 }
82
83 void get_popoto_value(const std::string& key) { send_popoto_command("GetValue", key); }
84
85 void send_popoto_command(const std::string& command)
86 {
87 // https://github.com/Delresearch/PopotoAPI/blob/2b511ff2109b6cde85b2261aec414882a332e8eb/CPP/popoto_client/include/TCPCmdClient.hpp#L50
88 send_popoto_command(command, " Unused Arguments");
89 }
90 void send_popoto_command(const std::string& command, const nlohmann::json& args);
91
92 std::uint8_t create_goby_header(const protobuf::ModemTransmission& m);
93 void decode_goby_header(std::uint8_t header, protobuf::ModemTransmission& m);
94 void decode_popoto_header(std::vector<uint8_t> data, protobuf::ModemTransmission& m);
95 void process_popoto_json(const std::string& message, protobuf::ModemTransmission& modem_msg);
96
97 const popoto::protobuf::Config& popoto_driver_cfg() const
98 {
99 return driver_cfg_.GetExtension(popoto::protobuf::config);
100 }
101
102 static std::string json_to_binary(const nlohmann::json& element)
103 {
104 std::string output;
105 for (auto& subel : element) { output.append(1, (char)((uint8_t)subel)); }
106 return output;
107 }
108
109 // Remove popoto trash from the incoming serial string
110 static std::string clean_popoto_string(std::string in, std::string p)
111 {
112 std::string out = std::move(in);
113 std::string::size_type n = p.length();
114 for (std::string::size_type i = out.find(p); i != std::string::npos; i = out.find(p))
115 out.erase(i, n);
116
117 return out;
118 }
119
120 private:
121 protobuf::DriverConfig driver_cfg_;
122 int sender_id_{0};
123 float modem_power_;
124 std::uint32_t next_frame_{0};
125
126 protobuf::ModemTransmission modem_msg_;
127 bool modem_msg_complete_ = false;
128
129 int application_type_;
130
131 static constexpr int DEFAULT_BAUD{115200};
132 static constexpr int DEFAULT_MTU_BYTES{1024};
133 static constexpr int POPOTO_BROADCAST_ID{255};
134
135 // Bitrates with Popoto modem: map these onto 0-5
136 std::vector<std::string> rate_to_speed{"setRate80", "setRate640", "setRate1280",
137 "setRate2560", "setRate5120", "setRate10240"};
138
139 bool startup_done_{false};
140};
141} // namespace acomms
142} // namespace goby
143
144#endif
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition driver_base.h:58
void send_ping(protobuf::ModemTransmission &msg)
void do_work() override
Allows the modem driver to do its work.
void send_range_request(int dest)
void popoto_update_power(protobuf::ModemTransmission &msg)
void send(protobuf::ModemTransmission &msg)
void shutdown() override
Shuts down the modem driver.
void handle_initiate_transmission(const protobuf::ModemTransmission &m) override
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...
void startup(const protobuf::DriverConfig &cfg) override
Starts the modem driver. Must be called before poll().
void play_file(protobuf::ModemTransmission &msg)
_proto_TypeTraits::Singular::ConstType GetExtension(const ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< DriverConfig, _proto_TypeTraits, _field_type, _is_packed > &id) const
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::acomms::popoto::protobuf::Config >, 11, false > config
The global namespace for the Goby project.
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::MessageOptions, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg