Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
janus_driver.h
Go to the documentation of this file.
1// Copyright 2011-2025:
2// GobySoft, LLC (2013-)
3// Massachusetts Institute of Technology (2007-2014)
4// Community contributors (see AUTHORS file)
5// File authors:
6// Jared Silbermann <jared.silbermann@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#ifndef GOBY_ACOMMS_MODEMDRIVER_JANUS_DRIVER_H
26#define GOBY_ACOMMS_MODEMDRIVER_JANUS_DRIVER_H
27
28#include <cstdint> // for uint8_t
29#include <map> // for map
30#include <string> // for string
31#include <vector> // for vector
32
33#include "goby/acomms/modemdriver/driver_base.h" // for ModemDriverBase
34#include "goby/acomms/protobuf/driver_base.pb.h" // for DriverConfig
35#include "goby/acomms/protobuf/modem_message.pb.h" // for ModemTransmission
36#include "goby/acomms/protobuf/janus_driver.pb.h" // for Config, MessageTy...
37#include "goby/util/thirdparty/nlohmann/json.hpp" // for json
38
39extern "C" {
40#include <janus/janus.h>
41#include <janus/defaults.h>
42#include <janus/simple_tx.h>
43#include <janus/simple_rx.h>
44#include <janus/rx.h>
45#include <janus/dump.h>
46#include <janus/parameters.h>
47#include <janus/utils/go_cfar.h>
48}
49
50// todo: probably should move this inside the class
52
54 std::string cargo_hex;
55 std::string cargo;
60
61};
62namespace goby
63{
64namespace acomms
65{
66namespace protobuf
67{
68class ModemTransmission;
69} // namespace protobuf
70
74
76{
77 public:
79 ~JanusDriver() override;
80 void startup(const protobuf::DriverConfig& cfg) override;
81 void shutdown() override;
82 void do_work() override;
85 void pad_message(std::vector<uint8_t> &vec);
86 void send_janus_packet(const protobuf::ModemTransmission& msg, std::vector<std::uint8_t> payload, bool ack = false);
87 void append_crc16(std::vector<std::uint8_t> &vec);
89 void send_janus_packet_thread(const protobuf::ModemTransmission& msg, std::vector<std::uint8_t> payload, bool ack);
90 void send_ack(unsigned int src, unsigned int dest,unsigned int frame_number);
91 void DecodeGobyHeader(std::uint8_t header, protobuf::ModemTransmission& m);
94 janus_rx_msg_pkt parse_janus_packet(const janus_packet_t pkt, bool verbosity);
95 unsigned int get_frame_num(std::string cargo);
96 janus_simple_tx_t init_janus_tx();
97 janus_simple_rx_t init_janus_rx();
98 janus_parameters_t get_janus_params(const janus::protobuf::Config& config);
99
100 janus_parameters_t params_tx;
101 janus_parameters_t params_rx;
102 unsigned int acomms_id;
105 unsigned int tx_class_id;
106 unsigned int rx_class_id;
107 std::uint32_t next_frame_{0};
108 static constexpr int DEFAULT_MTU_BYTES{1024};
109 janus_simple_tx_t simple_tx;
110 janus_simple_rx_t simple_rx;
111 janus_packet_t packet_rx = 0;
112 janus_rx_state_t state_rx = 0;
114 janus_carrier_sensing_t carrier_sensing;
116
117 private:
118 const janus::protobuf::Config& janus_driver_rx_cfg() const
119 {
120 return driver_cfg_.GetExtension(janus::protobuf::rx_config);
121 }
122
123 const janus::protobuf::Config& janus_driver_tx_cfg() const
124 {
125 return driver_cfg_.GetExtension(janus::protobuf::tx_config);
126 }
127
128
129 private:
130 enum
131 {
132 DEFAULT_BAUD = 4800
133 };
134
135
136 protobuf::DriverConfig driver_cfg_; // configuration given to you at launch
137 // rest is up to you!
138};
139} // namespace acomms
140} // namespace goby
141#endif
provides an API to the imaginary ABC modem (as an example how to write drivers)
janus_rx_state_t state_rx
janus_parameters_t params_rx
void send_janus_packet(const protobuf::ModemTransmission &msg, std::vector< std::uint8_t > payload, bool ack=false)
void send_ack(unsigned int src, unsigned int dest, unsigned int frame_number)
unsigned int get_frame_num(std::string cargo)
protobuf::ModemTransmission modem_msg
janus_simple_tx_t simple_tx
std::uint8_t CreateGobyHeader(const protobuf::ModemTransmission &m)
janus_simple_tx_t init_janus_tx()
janus_simple_rx_t init_janus_rx()
static constexpr int DEFAULT_MTU_BYTES
std::uint8_t get_goby_header(const protobuf::ModemTransmission &msg)
void DecodeGobyHeader(std::uint8_t header, protobuf::ModemTransmission &m)
void handle_initiate_transmission(const protobuf::ModemTransmission &m) override
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...
void shutdown() override
Shuts down the modem driver.
janus_simple_rx_t simple_rx
unsigned int tx_application_type
janus_parameters_t get_janus_params(const janus::protobuf::Config &config)
unsigned int rx_application_type
void pad_message(std::vector< uint8_t > &vec)
void startup(const protobuf::DriverConfig &cfg) override
Starts the modem driver. Must be called before poll().
void do_work() override
Allows the modem driver to do its work.
janus_parameters_t params_tx
void append_crc16(std::vector< std::uint8_t > &vec)
void send_janus_packet_thread(const protobuf::ModemTransmission &msg, std::vector< std::uint8_t > payload, bool ack)
void handle_ack_transmission(const protobuf::ModemTransmission &m)
janus_carrier_sensing_t carrier_sensing
janus_rx_msg_pkt parse_janus_packet(const janus_packet_t pkt, bool verbosity)
void to_modem_transmission(janus_rx_msg_pkt packet, protobuf::ModemTransmission &msg)
provides an abstract base class for acoustic modem drivers. This is subclassed by the various drivers...
Definition driver_base.h:59
_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::janus::protobuf::Config >, 11, false > rx_config
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::goby::acomms::protobuf::DriverConfig, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::acomms::janus::protobuf::Config >, 11, false > tx_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
std::string cargo_hex
std::string cargo