Update wpilibc to use new NetworkTables package and interfaces.

This commit is contained in:
Peter Johnson
2017-09-02 00:17:43 -07:00
parent 4e80570c4c
commit 040a8c6bcc
74 changed files with 937 additions and 721 deletions

View File

@@ -67,7 +67,7 @@ Command::Command(const std::string& name, double timeout) {
}
Command::~Command() {
if (m_table != nullptr) m_table->RemoveTableListener(this);
if (m_runningListener != 0) m_runningEntry.RemoveListener(m_runningListener);
}
/**
@@ -146,7 +146,7 @@ void Command::Removed() {
m_initialized = false;
m_canceled = false;
m_running = false;
if (m_table != nullptr) m_table->PutBoolean(kRunning, false);
if (m_runningEntry) m_runningEntry.SetBoolean(false);
}
/**
@@ -297,9 +297,7 @@ void Command::SetParent(CommandGroup* parent) {
} else {
LockChanges();
m_parent = parent;
if (m_table != nullptr) {
m_table->PutBoolean(kIsParented, true);
}
if (m_isParentedEntry) m_isParentedEntry.SetBoolean(true);
}
}
@@ -325,7 +323,7 @@ void Command::ClearRequirements() { m_requirements.clear(); }
void Command::StartRunning() {
m_running = true;
m_startTime = -1;
if (m_table != nullptr) m_table->PutBoolean(kRunning, true);
if (m_runningEntry) m_runningEntry.SetBoolean(true);
}
/**
@@ -435,25 +433,27 @@ std::string Command::GetName() const { return m_name; }
std::string Command::GetSmartDashboardType() const { return "Command"; }
void Command::InitTable(std::shared_ptr<ITable> subtable) {
if (m_table != nullptr) m_table->RemoveTableListener(this);
void Command::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
if (m_runningListener != 0) m_runningEntry.RemoveListener(m_runningListener);
m_table = subtable;
if (m_table != nullptr) {
m_table->PutString(kName, GetName());
m_table->PutBoolean(kRunning, IsRunning());
m_table->PutBoolean(kIsParented, m_parent != nullptr);
m_table->AddTableListener(kRunning, this, false);
m_table->GetEntry(kName).SetString(GetName());
m_runningEntry = m_table->GetEntry(kRunning);
m_runningEntry.SetBoolean(IsRunning());
m_isParentedEntry = m_table->GetEntry(kIsParented);
m_isParentedEntry.SetBoolean(m_parent != nullptr);
m_runningListener = m_runningEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsBoolean()) return;
if (event.value->GetBoolean()) {
if (!IsRunning()) Start();
} else {
if (IsRunning()) Cancel();
}
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
}
}
std::shared_ptr<ITable> Command::GetTable() const { return m_table; }
void Command::ValueChanged(ITable* source, llvm::StringRef key,
std::shared_ptr<nt::Value> value, bool isNew) {
if (!value->IsBoolean()) return;
if (value->GetBoolean()) {
if (!IsRunning()) Start();
} else {
if (IsRunning()) Cancel();
}
}
std::shared_ptr<nt::NetworkTable> Command::GetTable() const { return m_table; }

View File

@@ -67,7 +67,7 @@ double PIDCommand::GetPosition() { return ReturnPIDInput(); }
std::string PIDCommand::GetSmartDashboardType() const { return "PIDCommand"; }
void PIDCommand::InitTable(std::shared_ptr<ITable> subtable) {
void PIDCommand::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_controller->InitTable(subtable);
Command::InitTable(subtable);
}

View File

@@ -242,7 +242,7 @@ double PIDSubsystem::PIDGet() { return ReturnPIDInput(); }
std::string PIDSubsystem::GetSmartDashboardType() const { return "PIDCommand"; }
void PIDSubsystem::InitTable(std::shared_ptr<ITable> subtable) {
void PIDSubsystem::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_controller->InitTable(subtable);
Subsystem::InitTable(subtable);
}

View File

@@ -219,6 +219,9 @@ void Scheduler::ResetAll() {
m_additions.clear();
m_commands.clear();
m_table = nullptr;
m_namesEntry = nt::NetworkTableEntry();
m_idsEntry = nt::NetworkTableEntry();
m_cancelEntry = nt::NetworkTableEntry();
}
/**
@@ -228,7 +231,7 @@ void Scheduler::ResetAll() {
void Scheduler::UpdateTable() {
if (m_table != nullptr) {
// Get the list of possible commands to cancel
auto new_toCancel = m_table->GetValue("Cancel");
auto new_toCancel = m_cancelEntry.GetValue();
if (new_toCancel)
toCancel = new_toCancel->GetDoubleArray();
else
@@ -248,7 +251,7 @@ void Scheduler::UpdateTable() {
}
}
toCancel.resize(0);
m_table->PutValue("Cancel", nt::Value::MakeDoubleArray(toCancel));
m_cancelEntry.SetDoubleArray(toCancel);
}
// Set the running commands
@@ -261,8 +264,8 @@ void Scheduler::UpdateTable() {
commands.push_back(c->GetName());
ids.push_back(c->GetID());
}
m_table->PutValue("Names", nt::Value::MakeStringArray(commands));
m_table->PutValue("Ids", nt::Value::MakeDoubleArray(ids));
m_namesEntry.SetStringArray(commands);
m_idsEntry.SetDoubleArray(ids);
}
}
}
@@ -273,12 +276,22 @@ std::string Scheduler::GetType() const { return "Scheduler"; }
std::string Scheduler::GetSmartDashboardType() const { return "Scheduler"; }
void Scheduler::InitTable(std::shared_ptr<ITable> subTable) {
void Scheduler::InitTable(std::shared_ptr<nt::NetworkTable> subTable) {
m_table = subTable;
m_table->PutValue("Names", nt::Value::MakeStringArray(commands));
m_table->PutValue("Ids", nt::Value::MakeDoubleArray(ids));
m_table->PutValue("Cancel", nt::Value::MakeDoubleArray(toCancel));
if (m_table) {
m_namesEntry = m_table->GetEntry("Names");
m_idsEntry = m_table->GetEntry("Ids");
m_cancelEntry = m_table->GetEntry("Cancel");
m_namesEntry.SetStringArray(commands);
m_idsEntry.SetDoubleArray(ids);
m_cancelEntry.SetDoubleArray(toCancel);
} else {
m_namesEntry = nt::NetworkTableEntry();
m_idsEntry = nt::NetworkTableEntry();
m_cancelEntry = nt::NetworkTableEntry();
}
}
std::shared_ptr<ITable> Scheduler::GetTable() const { return m_table; }
std::shared_ptr<nt::NetworkTable> Scheduler::GetTable() const {
return m_table;
}

View File

@@ -66,10 +66,10 @@ void Subsystem::SetDefaultCommand(Command* command) {
}
if (m_table != nullptr) {
if (m_defaultCommand != nullptr) {
m_table->PutBoolean("hasDefault", true);
m_table->PutString("default", m_defaultCommand->GetName());
m_hasDefaultEntry.SetBoolean(true);
m_defaultEntry.SetString(m_defaultCommand->GetName());
} else {
m_table->PutBoolean("hasDefault", false);
m_hasDefaultEntry.SetBoolean(false);
}
}
}
@@ -121,10 +121,10 @@ void Subsystem::ConfirmCommand() {
if (m_currentCommandChanged) {
if (m_table != nullptr) {
if (m_currentCommand != nullptr) {
m_table->PutBoolean("hasCommand", true);
m_table->PutString("command", m_currentCommand->GetName());
m_hasCommandEntry.SetBoolean(true);
m_commandEntry.SetString(m_currentCommand->GetName());
} else {
m_table->PutBoolean("hasCommand", false);
m_hasCommandEntry.SetBoolean(false);
}
}
m_currentCommandChanged = false;
@@ -135,22 +135,29 @@ std::string Subsystem::GetName() const { return m_name; }
std::string Subsystem::GetSmartDashboardType() const { return "Subsystem"; }
void Subsystem::InitTable(std::shared_ptr<ITable> subtable) {
void Subsystem::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_table = subtable;
if (m_table != nullptr) {
m_hasDefaultEntry = m_table->GetEntry("hasDefault");
m_defaultEntry = m_table->GetEntry("default");
m_hasCommandEntry = m_table->GetEntry("hasCommand");
m_commandEntry = m_table->GetEntry("command");
if (m_defaultCommand != nullptr) {
m_table->PutBoolean("hasDefault", true);
m_table->PutString("default", m_defaultCommand->GetName());
m_hasDefaultEntry.SetBoolean(true);
m_defaultEntry.SetString(m_defaultCommand->GetName());
} else {
m_table->PutBoolean("hasDefault", false);
m_hasDefaultEntry.SetBoolean(false);
}
if (m_currentCommand != nullptr) {
m_table->PutBoolean("hasCommand", true);
m_table->PutString("command", m_currentCommand->GetName());
m_hasCommandEntry.SetBoolean(true);
m_commandEntry.SetString(m_currentCommand->GetName());
} else {
m_table->PutBoolean("hasCommand", false);
m_hasCommandEntry.SetBoolean(false);
}
}
}
std::shared_ptr<ITable> Subsystem::GetTable() const { return m_table; }
std::shared_ptr<nt::NetworkTable> Subsystem::GetTable() const {
return m_table;
}