Flash if client or server disconnected
Will flash either if the client is disconnected or server
Change-Id: Ieaa13241a8f7a592da5c1fa26f457f79b84413a8
Signed-off-by: Henry Speiser <henry@speiser.net>
diff --git a/y2022/control_loops/superstructure/BUILD b/y2022/control_loops/superstructure/BUILD
index 669e691..601be56 100644
--- a/y2022/control_loops/superstructure/BUILD
+++ b/y2022/control_loops/superstructure/BUILD
@@ -172,6 +172,7 @@
":superstructure_output_fbs",
":superstructure_status_fbs",
"//aos/events:event_loop",
+ "//aos/network:message_bridge_client_fbs",
"//aos/network:message_bridge_server_fbs",
"//frc971/control_loops:control_loop",
"//frc971/control_loops:control_loops_fbs",
diff --git a/y2022/control_loops/superstructure/led_indicator.cc b/y2022/control_loops/superstructure/led_indicator.cc
index 4ec934d..77d06fd 100644
--- a/y2022/control_loops/superstructure/led_indicator.cc
+++ b/y2022/control_loops/superstructure/led_indicator.cc
@@ -30,9 +30,20 @@
}
namespace {
-bool DisconnectedPi(const aos::message_bridge::ServerStatistics &server_stats) {
- for (const auto *pi_status : *server_stats.connections()) {
- if (pi_status->state() == aos::message_bridge::State::DISCONNECTED) {
+bool DisconnectedPiServer(
+ const aos::message_bridge::ServerStatistics &server_stats) {
+ for (const auto *pi_server_status : *server_stats.connections()) {
+ if (pi_server_status->state() == aos::message_bridge::State::DISCONNECTED) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool DisconnectedPiClient(
+ const aos::message_bridge::ClientStatistics &client_stats) {
+ for (const auto *pi_client_status : *client_stats.connections()) {
+ if (pi_client_status->state() == aos::message_bridge::State::DISCONNECTED) {
return true;
}
}
@@ -50,6 +61,7 @@
superstructure_status_fetcher_.Fetch();
server_statistics_fetcher_.Fetch();
drivetrain_output_fetcher_.Fetch();
+ client_statistics_fetcher_.Fetch();
// Estopped
if (superstructure_status_fetcher_.get() &&
@@ -66,12 +78,14 @@
}
// Pi disconnected
- if (server_statistics_fetcher_.get() &&
- DisconnectedPi(*server_statistics_fetcher_)) {
+ if ((server_statistics_fetcher_.get() &&
+ DisconnectedPiServer(*server_statistics_fetcher_)) ||
+ (client_statistics_fetcher_.get() &&
+ DisconnectedPiClient(*client_statistics_fetcher_))) {
if (disconnected_flash_) {
DisplayLed(255, 0, 0);
} else {
- DisplayLed(0, 0, 255);
+ DisplayLed(0, 255, 0);
}
if (disconnected_counter_ % kFlashIterations == 0) {
diff --git a/y2022/control_loops/superstructure/led_indicator.h b/y2022/control_loops/superstructure/led_indicator.h
index bdcee6c..680b875 100644
--- a/y2022/control_loops/superstructure/led_indicator.h
+++ b/y2022/control_loops/superstructure/led_indicator.h
@@ -2,6 +2,7 @@
#define Y2022_CONTROL_LOOPS_SUPERSTRUCTURE_LED_INDICATOR_H_
#include "aos/events/event_loop.h"
+#include "aos/network/message_bridge_client_generated.h"
#include "aos/network/message_bridge_server_generated.h"
#include "ctre/phoenix/led/CANdle.h"
#include "frc971/control_loops/control_loop.h"
@@ -21,7 +22,7 @@
//
// Red: estopped
// Yellow: not zeroed
- // Flash blue/red: pi disconnected
+ // Flash red/green: pi disconnected
// Purple: driving fast
//
// Statemachine:
@@ -52,6 +53,8 @@
aos::Fetcher<Status> superstructure_status_fetcher_;
aos::Fetcher<aos::message_bridge::ServerStatistics>
server_statistics_fetcher_;
+ aos::Fetcher<aos::message_bridge::ClientStatistics>
+ client_statistics_fetcher_;
size_t disconnected_counter_ = 0;
bool disconnected_flash_ = false;