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-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<ITable> SmartDashboard::m_table = nullptr;
|
|
|
|
|
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() {
|
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code
in wpilibC++Devices and a substantial portion of it in
wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests
are untouched except where it is necessary to make them
work with the rest of the libraries.
There is still a lot to do in the following areas:
-The HAL (which we may not want to touch at all).
-The I2C, Serial, and SPI interfaces in wpilibC++Devices,
which I haven't gotten around to doing yet.
-Most wpilibC++Devices classes have void* pointers
for interacting with the HAL.
-InterruptableSensorBase passes a void *params for
the interrupt handler.
-I haven't converted all the const char* to std::strings.
-There are plenty of other cases of raw pointers still
existing.
-This doesn't fall directly under raw pointer stuff,
but move syntax and rvalue references could be introduced
in many places.
-I haven't touched vision code.
-The Resource classes conflict (one is in the hal, the other
in wpilibC++). Someone should figure out a more
permanent fix (eg, just renaming them), then doing
what I did (making a new namespace for one of them,
essentially the same as renaming it).
A few other things:
-I created a NullDeleter class which is marked as deprecated.
What this does is it can be passed as the deleter to a
std::shared_ptr so that when you are converting raw pointers
to shared_ptrs the shared_ptr doesn't do any deletion if
someone else owns the raw pointer. This should only be
used in making old raw pointer UIs.
-I had to alter the build.gradle so that it did not
emit errors when deprecated functions called deprecated
functions. Unfortunately, gradle doesn't appear to be
actually printing out gcc warnigns for some reason.
The best way I have found to fix this is to patch
the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff)
so that a deprecated function calling a deprecated
function is fine but a non-deprecated function calling
a deprecated function will throw a warning (which we
then elevate with -Werror). I believe that clang
deals with this properly, although I have not
tried it myself.
Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
|
|
|
m_table.reset(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-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::PutData(std::string 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-06-25 15:07:55 -04:00
|
|
|
Sendable *SmartDashboard::GetData(std::string 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-06-25 15:07:55 -04:00
|
|
|
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key.c_str());
|
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-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::PutValue(std::string keyName, ComplexData &value) {
|
|
|
|
|
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-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::RetrieveValue(std::string keyName, ComplexData &value) {
|
|
|
|
|
m_table->RetrieveValue(keyName, value);
|
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-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::PutBoolean(std::string keyName, bool value) {
|
|
|
|
|
m_table->PutBoolean(keyName, value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Returns the value at the specified key. Throws an exception if the key is not
|
|
|
|
|
* found in the table
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SmartDashboard::GetBoolean(std::string keyName) {
|
|
|
|
|
return m_table->GetBoolean(keyName);
|
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-06-25 15:07:55 -04:00
|
|
|
bool SmartDashboard::GetBoolean(std::string keyName, bool defaultValue) {
|
|
|
|
|
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-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::PutNumber(std::string keyName, double value) {
|
|
|
|
|
m_table->PutNumber(keyName, value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Returns the value at the specified key. Throws an exception if the key is not
|
|
|
|
|
* found in the table.
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
double SmartDashboard::GetNumber(std::string keyName) {
|
|
|
|
|
return m_table->GetNumber(keyName);
|
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-06-25 15:07:55 -04:00
|
|
|
double SmartDashboard::GetNumber(std::string keyName, double defaultValue) {
|
|
|
|
|
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-06-25 15:07:55 -04:00
|
|
|
void SmartDashboard::PutString(std::string keyName, std::string value) {
|
|
|
|
|
m_table->PutString(keyName, value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the value at the specified key.
|
|
|
|
|
* @param keyName the key
|
|
|
|
|
* @param value the buffer to fill with the value
|
|
|
|
|
* @param valueLen the size of the buffer pointed to by value
|
|
|
|
|
* @return the length of the string
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
int SmartDashboard::GetString(std::string keyName, char *outBuffer,
|
|
|
|
|
unsigned int bufferLen) {
|
|
|
|
|
std::string value = m_table->GetString(keyName);
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < bufferLen - 1 && i < value.length(); ++i)
|
|
|
|
|
outBuffer[i] = (char)value.at(i);
|
|
|
|
|
outBuffer[i] = '\0';
|
|
|
|
|
return i;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Returns the value at the specified key. Throws an exception if the key is not
|
|
|
|
|
* found in the table
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
std::string SmartDashboard::GetString(std::string keyName) {
|
|
|
|
|
return m_table->GetString(keyName);
|
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-06-25 15:07:55 -04:00
|
|
|
std::string SmartDashboard::GetString(std::string keyName,
|
|
|
|
|
std::string defaultValue) {
|
|
|
|
|
return m_table->GetString(keyName, defaultValue);
|
2014-10-15 17:03:04 -04:00
|
|
|
}
|