blob: 38b169ae4e87f882fe148fbc6602aaa93edaa862 [file] [log] [blame]
Brian Silverman431500a2013-10-28 19:50:15 -07001#include "aos/common/network/team_number.h"
2
3#include <netinet/in.h>
Brian Silverman8f8b06f2013-10-30 22:04:27 -07004#include <inttypes.h>
Brian Silverman431500a2013-10-28 19:50:15 -07005
6#include "aos/common/once.h"
Brian Silverman14fd0fb2014-01-14 21:42:01 -08007#include "aos/linux_code/configuration.h"
Brian Silverman8f8b06f2013-10-30 22:04:27 -07008#include "aos/common/logging/logging.h"
Brian Silverman431500a2013-10-28 19:50:15 -07009
10namespace aos {
11namespace network {
12namespace {
13
Brian Silvermande0a53a2014-02-10 22:27:44 -080014uint16_t override_team = 0;
15
Brian Silverman431500a2013-10-28 19:50:15 -070016uint16_t *DoGetTeamNumber() {
Brian Silvermande0a53a2014-02-10 22:27:44 -080017 if (override_team != 0) return &override_team;
Brian Silverman431500a2013-10-28 19:50:15 -070018 const in_addr &address = configuration::GetOwnIPAddress();
Brian Silverman8f8b06f2013-10-30 22:04:27 -070019 static uint16_t r =
20 (((address.s_addr & 0xFF00) >> 8) * 100) +
21 (((address.s_addr & 0xFF0000) >> 16) & 0xFF);
22 LOG(INFO, "team number is %" PRIu16 "\n", r);
Brian Silverman431500a2013-10-28 19:50:15 -070023 return &r;
24}
25
26} // namespace
27
28uint16_t GetTeamNumber() {
29 static Once<uint16_t> once(DoGetTeamNumber);
30 return *once.Get();
31}
32
Brian Silvermande0a53a2014-02-10 22:27:44 -080033void OverrideTeamNumber(uint16_t team) { override_team = team; }
34
Brian Silverman431500a2013-10-28 19:50:15 -070035} // namespace network
36} // namespace aos