Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
mac_manager.h
Go to the documentation of this file.
1// Copyright 2010-2023:
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//
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_AMAC_MAC_MANAGER_H
26#define GOBY_ACOMMS_AMAC_MAC_MANAGER_H
27
28#include <boost/signals2/signal.hpp> // for signal
29#include <boost/smart_ptr/shared_ptr.hpp> // for shared_ptr
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
101 unsigned cycle_count() { return std::list<protobuf::ModemTransmission>::size(); }
103
104 const std::string& glog_mac_group() const { return glog_mac_group_; }
105
106 private:
107 void begin_slot();
108 time::SystemClock::time_point next_cycle_time();
109
110 void increment_slot();
111
112 void restart_timer();
113 void stop_timer();
114
115 unsigned cycle_sum();
116 void position_blank();
117
118 // allowed offset from actual end of slot
119
120 const time::SystemClock::duration allowed_skew_{std::chrono::seconds(2)};
121
122 private:
123 MACManager(const MACManager&);
124 MACManager& operator=(const MACManager&);
125
126 protobuf::MACConfig cfg_;
127
128 // start of the next cycle (cycle = all slots)
129 time::SystemClock::time_point next_cycle_t_;
130 // start of the next slot
132
133 std::list<protobuf::ModemTransmission>::iterator current_slot_;
134
135 unsigned cycles_since_reference_;
136
137 bool started_up_{false};
138
139 std::string glog_mac_group_;
140 static int count_;
141};
142
143namespace protobuf
144{
145inline bool operator==(const ModemTransmission& a, const ModemTransmission& b)
146{
147 return a.SerializeAsString() == b.SerializeAsString();
148}
149} // namespace protobuf
150
151std::ostream& operator<<(std::ostream& os, const MACManager& mac);
152
153} // namespace acomms
154} // namespace goby
155
156#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.