Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/shared/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ static const std::unordered_map<int, std::string> ROBOT_MULTICAST_CHANNELS = {
{12, "ff02::c3d0:42d2:bb12"}, {13, "ff02::c3d0:42d2:bb13"},
{14, "ff02::c3d0:42d2:bb14"}, {15, "ff02::c3d0:42d2:bb15"}};

// the name of the loopback network interface, which differs across platforms
#ifdef __APPLE__
static const std::string LOOPBACK_INTERFACE = "lo0";
#else
static const std::string LOOPBACK_INTERFACE = "lo";
#endif

// PlotJuggler's default host and port
static const std::string PLOTJUGGLER_GUI_DEFAULT_HOST = "ff02::c3d0:42d2:aaaa";
static const short unsigned int PLOTJUGGLER_GUI_DEFAULT_PORT = 9870;
Expand Down
3 changes: 2 additions & 1 deletion src/software/logger/plotjuggler_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>

#include "proto/visualization.pb.h"
#include "shared/constants.h"
#include "software/logger/custom_logging_levels.h"
#include "software/networking/udp/threaded_udp_sender.h"

Expand All @@ -20,7 +21,7 @@ class PlotJugglerSink
*
* @param interface The interface to send Plotjuggler UDP packets on
*/
PlotJugglerSink(const std::string& interface = "lo");
PlotJugglerSink(const std::string& interface = LOOPBACK_INTERFACE);

~PlotJugglerSink() = default;

Expand Down
3 changes: 3 additions & 0 deletions src/software/networking/udp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cc_test(
],
deps = [
":network_utils",
"//shared:constants",
"//shared/test_util:tbots_gtest_main",
],
)
Expand Down Expand Up @@ -68,6 +69,7 @@ cc_test(
],
deps = [
":threaded_proto_udp_listener",
"//shared:constants",
"//shared/test_util:tbots_gtest_main",
"@protobuf//:empty_cc_proto",
],
Expand All @@ -90,6 +92,7 @@ cc_test(
],
deps = [
":threaded_proto_udp_sender",
"//shared:constants",
"//shared/test_util:tbots_gtest_main",
"@protobuf//:empty_cc_proto",
],
Expand Down
4 changes: 3 additions & 1 deletion src/software/networking/udp/network_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

#include <gtest/gtest.h>

#include "shared/constants.h"

TEST(NetworkUtilsTest, getLocalIpValidInterface)
{
std::string interface = "lo";
std::string interface = LOOPBACK_INTERFACE;
std::optional<std::string> local_ip = getLocalIp(interface, true);
EXPECT_TRUE(local_ip);
EXPECT_EQ(local_ip.value(), "127.0.0.1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gtest/gtest.h>

#include "google/protobuf/empty.pb.h"
#include "shared/constants.h"
#include "software/networking/tbots_network_exception.h"

TEST(ThreadedProtoUdpListenerTest, error_finding_local_ip_address)
Expand All @@ -17,12 +18,12 @@ TEST(ThreadedProtoUdpListenerTest, error_creating_socket)
{
// This will always fail because it requires root privileges to open this port
EXPECT_THROW(ThreadedProtoUdpListener<google::protobuf::Empty>(
"224.5.23.1", 1023, "lo", [](const auto&) {}, true),
"224.5.23.1", 1023, LOOPBACK_INTERFACE, [](const auto&) {}, true),
TbotsNetworkException);
}

TEST(ThreadedProtoUdpListenerTest, no_error_creating_socket)
{
ThreadedProtoUdpListener<google::protobuf::Empty>(
"224.5.23.0", 40000, "lo", [](const auto&) {}, true);
"224.5.23.0", 40000, LOOPBACK_INTERFACE, [](const auto&) {}, true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <gtest/gtest.h>

#include "google/protobuf/empty.pb.h"
#include "shared/constants.h"
#include "software/networking/tbots_network_exception.h"

TEST(ThreadedProtoUdpSenderTest, error_finding_local_ip_address)
Expand All @@ -14,5 +15,6 @@ TEST(ThreadedProtoUdpSenderTest, error_finding_local_ip_address)

TEST(ThreadedProtoUdpSenderTest, no_error_creating_socket)
{
ThreadedProtoUdpSender<google::protobuf::Empty>("224.5.23.1", 40000, "lo", true);
ThreadedProtoUdpSender<google::protobuf::Empty>("224.5.23.1", 40000,
LOOPBACK_INTERFACE, true);
}
Loading