Goby3  3.1.5a
2024.05.23
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 
49 namespace goby
50 {
51 namespace acomms
52 {
54 {
55  public:
56  PopotoDriver();
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
goby::acomms::protobuf::DriverConfig
Definition: driver_base.pb.h:123
goby::acomms::protobuf::ModemTransmission
Definition: modem_message.pb.h:166
goby::acomms::PopotoDriver::send
void send(protobuf::ModemTransmission &msg)
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
modem_message.pb.h
goby::acomms::PopotoDriver::PopotoDriver
PopotoDriver()
goby::acomms::popoto::protobuf::Config
Definition: popoto_driver.pb.h:113
goby::acomms::PopotoDriver::shutdown
void shutdown() override
Shuts down the modem driver.
driver_base.h
goby::acomms::PopotoDriver
Definition: popoto_driver.h:53
driver_base.pb.h
goby::msg
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
Definition: option_extensions.pb.h:1327
goby::acomms::PopotoDriver::send_wake
void send_wake(void)
json.hpp
goby::acomms::PopotoDriver::popoto_sleep
void popoto_sleep(void)
goby::acomms::PopotoDriver::do_work
void do_work() override
Allows the modem driver to do its work.
goby::acomms::PopotoDriver::send_ping
void send_ping(protobuf::ModemTransmission &msg)
json
basic_json<> json
default specialization
Definition: json.hpp:3404
goby::acomms::PopotoDriver::handle_initiate_transmission
void handle_initiate_transmission(const protobuf::ModemTransmission &m) override
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...
goby::acomms::ModemDriverBase
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition: driver_base.h:58
goby::acomms::popoto::protobuf::config
extern ::google::protobuf::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::google::protobuf::internal::MessageTypeTraits< ::goby::acomms::popoto::protobuf::Config >, 11, false > config
Definition: popoto_driver.pb.h:534
goby::acomms::PopotoDriver::play_file
void play_file(protobuf::ModemTransmission &msg)
goby::acomms::PopotoDriver::send_range_request
void send_range_request(int dest)
popoto_driver.pb.h
goby::acomms::PopotoDriver::~PopotoDriver
~PopotoDriver() override
goby::acomms::PopotoDriver::startup
void startup(const protobuf::DriverConfig &cfg) override
Starts the modem driver. Must be called before poll().