Goby3 3.1.5a
2024.05.23
Loading...
Searching...
No Matches
popoto_driver.h
Go to the documentation of this file.
1// Copyright 2020-2021:
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;
66 void send_wake(void);
67 void send_range_request(int dest);
68 void popoto_sleep(void);
69
70 private:
71 void parse_in(const std::string& in, std::map<std::string, std::string>* out);
72 void signal_and_write(const std::string& raw);
73
74 std::uint8_t CreateGobyHeader(const protobuf::ModemTransmission& m);
75
76 void DecodeHeader(std::vector<uint8_t> data, protobuf::ModemTransmission& m);
77 void DecodeGobyHeader(std::uint8_t header, protobuf::ModemTransmission& m);
78 void ProcessJSON(const std::string& message, protobuf::ModemTransmission& m);
79
80 const popoto::protobuf::Config& popoto_driver_cfg() const
81 {
82 return driver_cfg_.GetExtension(popoto::protobuf::config);
83 }
84
85 static std::string json_to_binary(const nlohmann::json& element);
86 static std::string binary_to_json(const std::uint8_t* buf, size_t num_bytes);
87 static std::string StripString(std::string in, const std::string& p);
88
89 private:
90 protobuf::DriverConfig driver_cfg_;
91 int sender_id_{0};
92 protobuf::ModemTransmission modem_msg_;
93
94 static constexpr int DEFAULT_BAUD{115200};
95 static constexpr int DEFAULT_MTU_BYTES{1024};
96 static constexpr int POPOTO_BROADCAST_ID{255};
97
98 enum GobyHeaderBits
99 {
100 GOBY_HEADER_TYPE = 0, // 0 == Data, 1 == Ack
101 GOBY_HEADER_ACK_REQUEST = 1 // 0 == no ack requested, 1 == ack requested
102 };
103};
104} // namespace acomms
105} // namespace goby
106
107#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 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