Convert aos over to flatbuffers
Everything builds, and all the tests pass. I suspect that some entries
are missing from the config files, but those will be found pretty
quickly on startup.
There is no logging or live introspection of queue messages.
Change-Id: I496ee01ed68f202c7851bed7e8786cee30df29f5
diff --git a/frc971/wpilib/joystick_sender.cc b/frc971/wpilib/joystick_sender.cc
index 31ecc6c..2fec111 100644
--- a/frc971/wpilib/joystick_sender.cc
+++ b/frc971/wpilib/joystick_sender.cc
@@ -1,9 +1,10 @@
#include "frc971/wpilib/joystick_sender.h"
-#include "aos/init.h"
-#include "aos/logging/queue_logging.h"
+#include "aos/input/driver_station_data.h"
+#include "aos/logging/logging.h"
#include "aos/network/team_number.h"
-#include "aos/robot_state/robot_state.q.h"
+#include "aos/realtime.h"
+#include "aos/robot_state/joystick_state_generated.h"
#include "frc971/wpilib/ahal/DriverStation.h"
#include "hal/HAL.h"
@@ -11,12 +12,13 @@
namespace frc971 {
namespace wpilib {
+using aos::Joystick;
+
JoystickSender::JoystickSender(::aos::EventLoop *event_loop)
: event_loop_(event_loop),
joystick_state_sender_(
- event_loop_->MakeSender<::aos::JoystickState>(".aos.joystick_state")),
+ event_loop_->MakeSender<::aos::JoystickState>("/aos")),
team_id_(::aos::network::GetTeamNumber()) {
-
event_loop_->SetRuntimeRealtimePriority(29);
event_loop_->OnRun([this]() {
@@ -27,36 +29,65 @@
// variable / mutex needs to get exposed all the way out or something).
while (event_loop_->is_running()) {
ds->RunIteration([&]() {
- auto new_state = joystick_state_sender_.MakeMessage();
+ auto builder = joystick_state_sender_.MakeBuilder();
HAL_MatchInfo match_info;
auto status = HAL_GetMatchInfo(&match_info);
- if (status == 0) {
- new_state->switch_left = match_info.gameSpecificMessage[0] == 'L' ||
- match_info.gameSpecificMessage[0] == 'l';
- new_state->scale_left = match_info.gameSpecificMessage[1] == 'L' ||
- match_info.gameSpecificMessage[1] == 'l';
- }
- new_state->test_mode = ds->IsTestMode();
- new_state->fms_attached = ds->IsFmsAttached();
- new_state->enabled = ds->IsEnabled();
- new_state->autonomous = ds->IsAutonomous();
- new_state->team_id = team_id_;
- new_state->fake = false;
+ std::array<flatbuffers::Offset<Joystick>,
+ aos::input::driver_station::JoystickFeature::kJoysticks>
+ joysticks;
- for (uint8_t i = 0;
- i < sizeof(new_state->joysticks) / sizeof(::aos::Joystick); ++i) {
- new_state->joysticks[i].buttons = ds->GetStickButtons(i);
- for (int j = 0; j < 6; ++j) {
- new_state->joysticks[i].axis[j] = ds->GetStickAxis(i, j);
+ for (size_t i = 0;
+ i < aos::input::driver_station::JoystickFeature::kJoysticks; ++i) {
+ std::array<double, aos::input::driver_station::JoystickAxis::kAxes>
+ axis;
+ for (int j = 0; j < aos::input::driver_station::JoystickAxis::kAxes;
+ ++j) {
+ axis[j] = ds->GetStickAxis(i, j);
}
+
+ flatbuffers::Offset<flatbuffers::Vector<double>> axis_offset =
+ builder.fbb()->CreateVector(axis.begin(), axis.size());
+
+ Joystick::Builder joystick_builder = builder.MakeBuilder<Joystick>();
+
+ joystick_builder.add_buttons(ds->GetStickButtons(i));
+
if (ds->GetStickPOVCount(i) > 0) {
- new_state->joysticks[i].pov = ds->GetStickPOV(i, 0);
+ joystick_builder.add_pov(ds->GetStickPOV(i, 0));
}
- AOS_LOG_STRUCT(DEBUG, "joystick_state", *new_state);
+
+ joystick_builder.add_axis(axis_offset);
+
+ joysticks[i] = joystick_builder.Finish();
}
- if (!new_state.Send()) {
+
+ flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Joystick>>>
+ joysticks_offset = builder.fbb()->CreateVector(joysticks.begin(),
+ joysticks.size());
+
+ aos::JoystickState::Builder joystick_state_builder =
+ builder.MakeBuilder<aos::JoystickState>();
+
+ joystick_state_builder.add_joysticks(joysticks_offset);
+
+ if (status == 0) {
+ joystick_state_builder.add_switch_left(
+ match_info.gameSpecificMessage[0] == 'L' ||
+ match_info.gameSpecificMessage[0] == 'l');
+ joystick_state_builder.add_scale_left(
+ match_info.gameSpecificMessage[1] == 'L' ||
+ match_info.gameSpecificMessage[1] == 'l');
+ }
+
+ joystick_state_builder.add_test_mode(ds->IsTestMode());
+ joystick_state_builder.add_fms_attached(ds->IsFmsAttached());
+ joystick_state_builder.add_enabled(ds->IsEnabled());
+ joystick_state_builder.add_autonomous(ds->IsAutonomous());
+ joystick_state_builder.add_team_id(team_id_);
+
+ if (!builder.Send(joystick_state_builder.Finish())) {
AOS_LOG(WARNING, "sending joystick_state failed\n");
}
});