Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
popoto_driver.h
Go to the documentation of this file.
1// Copyright 2020-2025:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Thomas McCabe <tom.mccabe@missionsystems.com.au>
6// Toby Schneider <toby@gobysoft.org>
7// Jared Silbermann <jared.silbermann@missionsystems.com.au>
8//
9//
10// This file is part of the Goby Underwater Autonomy Project Libraries
11// ("The Goby Libraries").
12//
13// The Goby Libraries are free software: you can redistribute them and/or modify
14// them under the terms of the GNU Lesser General Public License as published by
15// the Free Software Foundation, either version 2.1 of the License, or
16// (at your option) any later version.
17//
18// The Goby Libraries are distributed in the hope that they will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU Lesser General Public License for more details.
22//
23// You should have received a copy of the GNU Lesser General Public License
24// along with Goby. If not, see <http://www.gnu.org/licenses/>.
25
26/************************************************************/
27/* NAME: Thomas McCabe */
28/* ORGN: Mission Systems Pty Ltd */
29/* FILE: Popoto.h */
30/* DATE: Aug 20 2020 */
31/************************************************************/
32
33/* Copyright (c) 2020 mission systems pty ltd */
34
35#ifndef GOBY_ACOMMS_MODEMDRIVER_POPOTO_DRIVER_H
36#define GOBY_ACOMMS_MODEMDRIVER_POPOTO_DRIVER_H
37
38#include <cstddef> // for size_t
39#include <cstdint> // for uint8_t
40#include <map> // for map
41#include <string> // for string
42#include <vector> // for vector
43
44#include "goby/acomms/modemdriver/driver_base.h" // for ModemDriverBase
45#include "goby/acomms/protobuf/driver_base.pb.h" // for DriverConfig
46#include "goby/acomms/protobuf/modem_message.pb.h" // for ModemTransmission
47#include "goby/acomms/protobuf/popoto_driver.pb.h" // for Config, MessageTy...
48#include "goby/util/thirdparty/nlohmann/json.hpp" // for json
49
50namespace goby
51{
52namespace acomms
53{
55{
56 public:
58 ~PopotoDriver() override;
59
60 void startup(const protobuf::DriverConfig& cfg) override;
61 void shutdown() override;
62 void do_work() override;
68 void send_wake(void);
69 void send_range_request(int dest);
70 void popoto_sleep(void);
71
72 private:
73 void parse_in(const std::string& in, std::map<std::string, std::string>* out);
74 void signal_and_write(const std::string& raw);
75
76 // 2 byte header code
77 // std::uint16_t CreateGobyHeader(const protobuf::ModemTransmission& m);
78 std::uint8_t CreateGobyHeader(const protobuf::ModemTransmission& m);
79 void DecodeGobyHeader(std::uint8_t header, std::uint8_t ack_num,
81 void DecodeHeader(std::vector<uint8_t> data, protobuf::ModemTransmission& m);
82 void ProcessJSON(const std::string& message, protobuf::ModemTransmission& modem_msg);
83 std::string change_to_popoto_json(std::string input, size_t pos, std::string setval,
84 std::string num_type);
85 std::string setrate_to_payload_mode(std::string setRate);
86
87 const popoto::protobuf::Config& popoto_driver_cfg() const
88 {
89 return driver_cfg_.GetExtension(popoto::protobuf::config);
90 }
91
92 static std::string binary_to_json(const std::uint8_t* buf, size_t num_bytes)
93 {
94 std::string output;
95
96 for (int i = 0, n = num_bytes; i < n; i++)
97 {
98 output.append(std::to_string((uint8_t)buf[i]));
99 if (i < n - 1)
100 {
101 output.append(",");
102 }
103 }
104 return output;
105 }
106
107 // Convert csv values back to dccl binary for the dccl codec to decode
108 static std::string json_to_binary(const nlohmann::json& element)
109 {
110 std::string output;
111 for (auto& subel : element) { output.append(1, (char)((uint8_t)subel)); }
112 return output;
113 }
114
115 // Remove popoto trash from the incoming serial string
116 static std::string StripString(std::string in, std::string p)
117 {
118 std::string out = std::move(in);
119 std::string::size_type n = p.length();
120 for (std::string::size_type i = out.find(p); i != std::string::npos; i = out.find(p))
121 out.erase(i, n);
122
123 return out;
124 }
125
126 private:
127 protobuf::DriverConfig driver_cfg_;
128 int sender_id_{0};
129 float modem_p;
130 std::uint32_t next_frame_{0};
131 protobuf::ModemTransmission modem_msg_;
132 int application_type;
133
134 static constexpr int DEFAULT_BAUD{115200};
135 static constexpr int DEFAULT_MTU_BYTES{1024};
136 static constexpr int POPOTO_BROADCAST_ID{255};
137
138 enum ConnectionType
139 {
140 SERIAL_CONNECTION = 0, // 0 == Data, 1 == Ack
141 ETHERNET_CONNECTION = 1 // 0 == no ack requested, 1 == ack requested
142 };
143 ConnectionType myConnection;
144
145 // Bitrates with Popoto modem: map these onto 0-5
146 std::vector<std::string> rate_to_speed{"setRate80\n", "setRate640\n", "setRate1280\n",
147 "setRate2560\n", "setRate5120\n", "setRate10240\n"};
148
149 const std::string setvali = "setvaluei";
150 const std::string setvalf = "setvaluef";
151 const std::string getvali = "getvaluei";
152 const std::string getvalf = "getvaluef";
153};
154} // namespace acomms
155} // namespace goby
156
157#endif
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition driver_base.h:59
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