JaiaBot  1.12.0+7+gdc1e5561
JaiaBot micro-AUV software
comms.h
Go to the documentation of this file.
1 // Copyright 2023:
2 // JaiaRobotics LLC
3 // File authors:
4 // Toby Schneider <toby@gobysoft.org>
5 //
6 //
7 // This file is part of the JaiaBot Project Libraries
8 // ("The Jaia Libraries").
9 //
10 // The Jaia Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Jaia Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with the Jaia Libraries. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef JAIABOT_SRC_LIB_COMMS_COMMS_H
24 #define JAIABOT_SRC_LIB_COMMS_COMMS_H
25 
26 #include <goby/acomms/acomms_constants.h>
27 
28 #include "jaiabot/exception.h"
29 
30 namespace jaiabot
31 {
32 namespace comms
33 {
34 constexpr int broadcast_modem_id{goby::acomms::BROADCAST_ID};
35 constexpr int hub_modem_id{1};
36 constexpr int bot0_modem_id{2};
37 
38 constexpr int bot_id_min{0};
39 constexpr int bot_id_max{150};
40 constexpr int bot_id_total{bot_id_max - bot_id_min + 1};
41 
42 constexpr int hub_id_min{0};
43 constexpr int hub_id_max{30};
44 constexpr int hub_id_total{hub_id_max - hub_id_min + 1};
45 
46 inline void check_bot_id_bounds(int bot_id)
47 {
48  if (bot_id < bot_id_min)
49  throw(jaiabot::Exception("Bot ID " + std::to_string(bot_id) +
50  " is less than Bot ID minimum"));
51 
52  if (bot_id > bot_id_max)
53  throw(jaiabot::Exception("Bot ID " + std::to_string(bot_id) +
54  " is greater than Bot ID maximum"));
55 }
56 
57 inline void check_hub_id_bounds(int hub_id)
58 {
59  if (hub_id < hub_id_min)
60  throw(jaiabot::Exception("Hub ID " + std::to_string(hub_id) +
61  " is less than Hub ID minimum"));
62 
63  if (hub_id > hub_id_max)
64  throw(jaiabot::Exception("Hub ID " + std::to_string(hub_id) +
65  " is greater than Hub ID maximum"));
66 }
67 
68 inline int modem_id_from_bot_id(int bot_id)
69 {
70  check_bot_id_bounds(bot_id);
71  return bot_id + bot0_modem_id;
72 }
73 
74 inline int bot_id_from_modem_id(int modem_id)
75 {
76  int bot_id = modem_id - bot0_modem_id;
77 
78  if (bot_id > bot_id_max)
79  throw(jaiabot::Exception("Modem ID " + std::to_string(modem_id) +
80  " must be greater than bot0_modem_id"));
81  check_bot_id_bounds(bot_id);
82  return bot_id;
83 }
84 
85 } // namespace comms
86 } // namespace jaiabot
87 
88 #endif
constexpr int broadcast_modem_id
Definition: comms.h:34
constexpr int hub_id_total
Definition: comms.h:44
void check_hub_id_bounds(int hub_id)
Definition: comms.h:57
constexpr int bot0_modem_id
Definition: comms.h:36
constexpr int bot_id_total
Definition: comms.h:40
int bot_id_from_modem_id(int modem_id)
Definition: comms.h:74
int modem_id_from_bot_id(int bot_id)
Definition: comms.h:68
constexpr int hub_id_min
Definition: comms.h:42
void check_bot_id_bounds(int bot_id)
Definition: comms.h:46
constexpr int hub_id_max
Definition: comms.h:43
constexpr int hub_modem_id
Definition: comms.h:35
constexpr int bot_id_max
Definition: comms.h:39
constexpr int bot_id_min
Definition: comms.h:38