blob: 7b9acbbebddb5c5e6a3e508723f5bb3788f4d4e3 [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#ifndef AOS_NETWORK_TEAM_NUMBER_H_
2#define AOS_NETWORK_TEAM_NUMBER_H_
Brian Silverman431500a2013-10-28 19:50:15 -07003
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cstdint>
Brian Silverman3dfbfb12020-02-17 20:35:18 -08005#include <optional>
Austin Schuh4c84abb2021-06-20 18:16:32 -07006#include <string_view>
Austin Schuhdf5591e2015-12-19 22:36:50 -08007
Jim Ostrowski2192ddb2020-06-24 19:07:31 -07008#include "glog/logging.h"
9
10DECLARE_string(override_hostname);
11
Brian Silverman431500a2013-10-28 19:50:15 -070012namespace aos {
13namespace network {
14
15// Retrieves the current team number based off of the network address.
16// This function will only do the complicated stuff once so it is cheap to call
17// repeatedly.
18uint16_t GetTeamNumber();
19
Austin Schuh288479d2019-12-18 19:47:52 -080020// Returns the current hostname.
21::std::string GetHostname();
22
Brian Silvermande0a53a2014-02-10 22:27:44 -080023// Overrides the team number returned from GetTeamNumber(). Must be called
24// before GetTeamNumber() is ever called.
25// Overriding to team 0 won't work.
26// Intended only for tests.
Philipp Schraderf75a8bf2015-02-02 05:30:16 +000027// Guaranteed to be safe to call during static initialization time.
Brian Silvermande0a53a2014-02-10 22:27:44 -080028void OverrideTeamNumber(uint16_t team);
29
Jim Ostrowskicb8b4082024-01-21 02:23:46 -080030// Returns the number for a pi/orin formatted hostname. pi-team#-pi# (e.g., 5
31// for pi-971-5 or 2 for orin-9971-2)
32std::optional<uint16_t> ParsePiOrOrinNumber(const std::string_view hostname);
Austin Schuh1f2996e2020-03-15 23:09:00 -070033
Jim Ostrowski3dc21642024-01-22 16:08:40 -080034// Returns whether the device is a "pi" or an "orin" based on hostname
35std::optional<std::string_view> ParsePiOrOrin(const std::string_view hostname);
36
Brian Silverman3dfbfb12020-02-17 20:35:18 -080037namespace team_number_internal {
38
Austin Schuh4c84abb2021-06-20 18:16:32 -070039std::optional<uint16_t> ParseRoborioTeamNumber(const std::string_view hostname);
Brian Silverman3dfbfb12020-02-17 20:35:18 -080040
Jim Ostrowskicb8b4082024-01-21 02:23:46 -080041// Returns the team number for a pi/orin formatted hostname. pi-team#-pi#
42// (e.g., 971 for pi-971-5 or 9971 for orin-9971-2)
43std::optional<uint16_t> ParsePiOrOrinTeamNumber(
44 const std::string_view hostname);
Brian Silverman5f06ed22020-02-17 21:49:42 -080045
Brian Silverman3dfbfb12020-02-17 20:35:18 -080046} // namespace team_number_internal
Brian Silverman431500a2013-10-28 19:50:15 -070047} // namespace network
48} // namespace aos
49
John Park33858a32018-09-28 23:05:48 -070050#endif // AOS_NETWORK_TEAM_NUMBER_H_