2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Copyright (c) FIRST 2011. All Rights Reserved.
|
|
|
|
|
*/
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "SmartDashboard/SmartDashboard.h"
|
|
|
|
|
|
2014-01-06 10:12:21 -05:00
|
|
|
//#include "NetworkCommunication/UsageReporting.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "SmartDashboard/NamedSendable.h"
|
|
|
|
|
#include "WPIErrors.h"
|
|
|
|
|
#include "networktables/NetworkTable.h"
|
2014-08-08 17:05:49 -04:00
|
|
|
#include "HLUsageReporting.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-11-23 00:46:05 -08:00
|
|
|
std::shared_ptr<ITable> SmartDashboard::m_table;
|
2015-07-29 16:48:04 -04:00
|
|
|
std::map<std::shared_ptr<ITable> , Sendable *> SmartDashboard::m_tablesToData;
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::init() {
|
2015-08-13 23:17:19 -07:00
|
|
|
m_table = NetworkTable::GetTable("SmartDashboard");
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
HLUsageReporting::ReportSmartDashboard();
|
2014-08-04 14:43:31 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2015-06-23 04:49:51 -07:00
|
|
|
* The key can not be nullptr.
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @param value the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
void SmartDashboard::PutData(llvm::StringRef key, Sendable *data) {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (data == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<ITable> dataTable(m_table->GetSubTable(key));
|
2015-06-25 15:07:55 -04:00
|
|
|
dataTable->PutString("~TYPE~", data->GetSmartDashboardType());
|
|
|
|
|
data->InitTable(dataTable);
|
|
|
|
|
m_tablesToData[dataTable] = data;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Maps the specified key (where the key is the name of the {@link
|
|
|
|
|
* SmartDashboardNamedData}
|
2013-12-15 18:30:16 -05:00
|
|
|
* to the specified value in this table.
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param value the value
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::PutData(NamedSendable *value) {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (value == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PutData(value->GetName(), value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the value at the specified key.
|
|
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
Sendable *SmartDashboard::GetData(llvm::StringRef key) {
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<ITable> subtable(m_table->GetSubTable(key));
|
2015-06-25 15:07:55 -04:00
|
|
|
Sendable *data = m_tablesToData[subtable];
|
2015-06-23 04:49:51 -07:00
|
|
|
if (data == nullptr) {
|
2015-08-13 23:17:19 -07:00
|
|
|
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
|
2015-06-23 04:49:51 -07:00
|
|
|
return nullptr;
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
|
|
|
|
return data;
|
2014-08-04 14:43:31 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Maps the specified key to the specified complex value (such as an array) in
|
|
|
|
|
* this table.
|
2015-06-23 04:49:51 -07:00
|
|
|
* The key can not be nullptr.
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the RetrieveValue method with a key
|
|
|
|
|
* that is equal to the original key.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @param value the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
void SmartDashboard::PutValue(llvm::StringRef keyName,
|
|
|
|
|
std::shared_ptr<nt::Value> value) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table->PutValue(keyName, value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Retrieves the complex value (such as an array) in this table into the complex
|
|
|
|
|
* data object
|
2015-06-23 04:49:51 -07:00
|
|
|
* The key can not be nullptr.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @param value the object to retrieve the value into
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
std::shared_ptr<nt::Value> SmartDashboard::GetValue(llvm::StringRef keyName) {
|
|
|
|
|
return m_table->GetValue(keyName);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2015-06-23 04:49:51 -07:00
|
|
|
* The key can not be nullptr.
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @param value the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
void SmartDashboard::PutBoolean(llvm::StringRef keyName, bool value) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table->PutBoolean(keyName, value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 17:03:04 -04:00
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Returns the value at the specified key. If the key is not found, returns the
|
|
|
|
|
* default value.
|
2014-10-15 17:03:04 -04:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
bool SmartDashboard::GetBoolean(llvm::StringRef keyName, bool defaultValue) {
|
2015-06-25 15:07:55 -04:00
|
|
|
return m_table->GetBoolean(keyName, defaultValue);
|
2014-10-15 17:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2015-06-23 04:49:51 -07:00
|
|
|
* The key can not be nullptr.
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @param value the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
void SmartDashboard::PutNumber(llvm::StringRef keyName, double value) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table->PutNumber(keyName, value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 17:03:04 -04:00
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Returns the value at the specified key. If the key is not found, returns the
|
|
|
|
|
* default value.
|
2014-10-15 17:03:04 -04:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
double SmartDashboard::GetNumber(llvm::StringRef keyName, double defaultValue) {
|
2015-06-25 15:07:55 -04:00
|
|
|
return m_table->GetNumber(keyName, defaultValue);
|
2014-10-15 17:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2015-06-23 04:49:51 -07:00
|
|
|
* Neither the key nor the value can be nullptr.
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @param value the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
void SmartDashboard::PutString(llvm::StringRef keyName, llvm::StringRef value) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table->PutString(keyName, value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 17:03:04 -04:00
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Returns the value at the specified key. If the key is not found, returns the
|
|
|
|
|
* default value.
|
2014-10-15 17:03:04 -04:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
std::string SmartDashboard::GetString(llvm::StringRef keyName,
|
|
|
|
|
llvm::StringRef defaultValue) {
|
2015-06-25 15:07:55 -04:00
|
|
|
return m_table->GetString(keyName, defaultValue);
|
2014-10-15 17:03:04 -04:00
|
|
|
}
|