Goby3 3.5.1
2026.06.04
Loading...
Searching...
No Matches
mac_manager.h
Go to the documentation of this file.
1// Copyright 2010-2026:
2// GobySoft, LLC (2013-)
3// Massachusetts Institute of Technology (2007-2014)
4// Community contributors (see AUTHORS file)
5// File authors:
6// Toby Schneider <toby@gobysoft.org>
7// Copilot <198982749+Copilot@users.noreply.github.com>
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#ifndef GOBY_ACOMMS_AMAC_MAC_MANAGER_H
27#define GOBY_ACOMMS_AMAC_MAC_MANAGER_H
28
29#include <boost/signals2/signal.hpp> // for signal
30#include <chrono> // for seconds
31#include <iosfwd> // for ostream
32#include <list> // for list, list<>::ite...
33#include <string> // for operator==, string
34
35#include "goby/acomms/protobuf/amac_config.pb.h" // for MACConfig
36#include "goby/acomms/protobuf/modem_message.pb.h" // for ModemTransmission
37#include "goby/time/system_clock.h" // for SystemClock, Syst...
38
39namespace goby
40{
41namespace acomms
42{
44
45
50class MACManager : public std::list<protobuf::ModemTransmission>
51{
52 public:
54
55
57 MACManager(int id);
60
62
63
67 void startup(const protobuf::MACConfig& cfg);
68
70 void restart();
71
73 void shutdown();
74
76 void do_work();
77
79 void update();
80
81 bool running() { return started_up_; }
82
84
86
87
90 boost::signals2::signal<void(const protobuf::ModemTransmission& m)>
92
96
97 boost::signals2::signal<void(const protobuf::ModemTransmission& m)> signal_slot_start;
98
100 // goby3_example_amac_simple
101
102 unsigned cycle_count() { return std::list<protobuf::ModemTransmission>::size(); }
104
105 const std::string& glog_mac_group() const { return glog_mac_group_; }
106
107 private:
108 void begin_slot();
109 time::SystemClock::time_point next_cycle_time();
110
111 void increment_slot();
112
113 void restart_timer();
114 void stop_timer();
115
116 unsigned cycle_sum();
117 void position_blank();
118
119 // allowed offset from actual end of slot
120
121 const time::SystemClock::duration allowed_skew_{std::chrono::seconds(2)};
122
123 private:
124 MACManager(const MACManager&);
125 MACManager& operator=(const MACManager&);
126
127 protobuf::MACConfig cfg_;
128
129 // start of the next cycle (cycle = all slots)
130 time::SystemClock::time_point next_cycle_t_;
131 // start of the next slot
133
134 std::list<protobuf::ModemTransmission>::iterator current_slot_;
135
136 unsigned cycles_since_reference_;
137
138 bool started_up_{false};
139
140 std::string glog_mac_group_;
141 static int count_;
142};
143
144namespace protobuf
145{
146inline bool operator==(const ModemTransmission& a, const ModemTransmission& b)
147{
148 return a.SerializeAsString() == b.SerializeAsString();
149}
150} // namespace protobuf
151
152std::ostream& operator<<(std::ostream& os, const MACManager& mac);
153
154} // namespace acomms
155} // namespace goby
156
157#endif
provides an API to the goby-acomms MAC library. MACManager is essentially a std::list<protobuf::Modem...
Definition mac_manager.h:51
void startup(const protobuf::MACConfig &cfg)
Starts the MAC with given configuration.
void update()
You must call this after any change to the underlying list that would invalidate iterators or change ...
boost::signals2::signal< void(const protobuf::ModemTransmission &m)> signal_slot_start
Signals the start of all transmissions (even when we don't transmit)
Definition mac_manager.h:97
void do_work()
Allows the MAC timer to do its work. Does not block.
time::SystemClock::duration cycle_duration()
boost::signals2::signal< void(const protobuf::ModemTransmission &m)> signal_initiate_transmission
Signals when it is time for this platform to begin transmission of an acoustic message at the start o...
Definition mac_manager.h:91
const std::string & glog_mac_group() const
void restart()
Restarts the MAC with original configuration.
MACManager()
Default constructor.
void shutdown()
Shutdown the MAC.
std::ostream & operator<<(std::ostream &os, const MACManager &mac)
The global namespace for the Goby project.
std::chrono::time_point< SystemClock > time_point
std::chrono::microseconds duration
Duration type.