jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2011. All Rights Reserved. */
|
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */
|
| 4 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #include "SmartDashboard/SmartDashboard.h"
|
| 8 |
|
| 9 | #include "NetworkCommunication/UsageReporting.h"
|
| 10 | #include "NamedSendable.h"
|
| 11 | #include "WPIErrors.h"
|
| 12 | #include "networktables/NetworkTable.h"
|
| 13 |
|
| 14 | ITable* SmartDashboard::m_table = NULL;
|
| 15 | std::map<ITable *, Sendable *> SmartDashboard::m_tablesToData;
|
| 16 |
|
| 17 | void SmartDashboard::init(){
|
| 18 | m_table = NetworkTable::GetTable("SmartDashboard");
|
| 19 | }
|
| 20 |
|
| 21 | //TODO usage reporting
|
| 22 |
|
| 23 | /**
|
| 24 | * Maps the specified key to the specified value in this table.
|
| 25 | * The key can not be NULL.
|
| 26 | * The value can be retrieved by calling the get method with a key that is equal to the original key.
|
| 27 | * @param keyName the key
|
| 28 | * @param value the value
|
| 29 | */
|
| 30 | void SmartDashboard::PutData(std::string key, Sendable *data)
|
| 31 | {
|
| 32 | if (data == NULL)
|
| 33 | {
|
| 34 | //TODO wpi_setWPIErrorWithContext(NullParameter, "value");
|
| 35 | return;
|
| 36 | }
|
| 37 | ITable* dataTable = m_table->GetSubTable(key);
|
| 38 | dataTable->PutString("~TYPE~", data->GetSmartDashboardType());
|
| 39 | data->InitTable(dataTable);
|
| 40 | m_tablesToData[dataTable] = data;
|
| 41 | }
|
| 42 |
|
| 43 | /**
|
| 44 | * Maps the specified key (where the key is the name of the {@link SmartDashboardNamedData}
|
| 45 | * to the specified value in this table.
|
| 46 | * The value can be retrieved by calling the get method with a key that is equal to the original key.
|
| 47 | * @param value the value
|
| 48 | */
|
| 49 | void SmartDashboard::PutData(NamedSendable *value)
|
| 50 | {
|
| 51 | if (value == NULL)
|
| 52 | {
|
| 53 | //TODO wpi_setWPIErrorWithContext(NullParameter, "value");
|
| 54 | return;
|
| 55 | }
|
| 56 | PutData(value->GetName(), value);
|
| 57 | }
|
| 58 |
|
| 59 | /**
|
| 60 | * Returns the value at the specified key.
|
| 61 | * @param keyName the key
|
| 62 | * @return the value
|
| 63 | */
|
| 64 | //TODO Sendable *SmartDashboard::GetData(std::string key)
|
| 65 | /*{
|
| 66 | ITable* subtable = m_table->GetSubTable(keyName);
|
| 67 | Sendable *data = m_tablesToData[subtable];
|
| 68 | if (data == NULL)
|
| 69 | {
|
| 70 | wpi_setWPIErrorWithContext(SmartDashboardMissingKey, keyName);
|
| 71 | return NULL;
|
| 72 | }
|
| 73 | return data;
|
| 74 | }*/
|
| 75 |
|
| 76 | /**
|
| 77 | * Maps the specified key to the specified complex value (such as an array) in this table.
|
| 78 | * The key can not be NULL.
|
| 79 | * The value can be retrieved by calling the RetrieveValue method with a key that is equal to the original key.
|
| 80 | * @param keyName the key
|
| 81 | * @param value the value
|
| 82 | */
|
| 83 | void SmartDashboard::PutValue(std::string keyName, ComplexData& value)
|
| 84 | {
|
| 85 | m_table->PutValue(keyName, value);
|
| 86 | }
|
| 87 |
|
| 88 | /**
|
| 89 | * Retrieves the complex value (such as an array) in this table into the complex data object
|
| 90 | * The key can not be NULL.
|
| 91 | * @param keyName the key
|
| 92 | * @param value the object to retrieve the value into
|
| 93 | */
|
| 94 | void SmartDashboard::RetrieveValue(std::string keyName, ComplexData& value)
|
| 95 | {
|
| 96 | m_table->RetrieveValue(keyName, value);
|
| 97 | }
|
| 98 |
|
| 99 | /**
|
| 100 | * Maps the specified key to the specified value in this table.
|
| 101 | * The key can not be NULL.
|
| 102 | * The value can be retrieved by calling the get method with a key that is equal to the original key.
|
| 103 | * @param keyName the key
|
| 104 | * @param value the value
|
| 105 | */
|
| 106 | void SmartDashboard::PutBoolean(std::string keyName, bool value)
|
| 107 | {
|
| 108 | m_table->PutBoolean(keyName, value);
|
| 109 | }
|
| 110 |
|
| 111 | /**
|
| 112 | * Returns the value at the specified key.
|
| 113 | * @param keyName the key
|
| 114 | * @return the value
|
| 115 | */
|
| 116 | bool SmartDashboard::GetBoolean(std::string keyName)
|
| 117 | {
|
| 118 | return m_table->GetBoolean(keyName);
|
| 119 | }
|
| 120 |
|
| 121 | /**
|
| 122 | * Maps the specified key to the specified value in this table.
|
| 123 | * The key can not be NULL.
|
| 124 | * The value can be retrieved by calling the get method with a key that is equal to the original key.
|
| 125 | * @param keyName the key
|
| 126 | * @param value the value
|
| 127 | */
|
| 128 | void SmartDashboard::PutNumber(std::string keyName, double value){
|
| 129 | m_table->PutNumber(keyName, value);
|
| 130 | }
|
| 131 |
|
| 132 | /**
|
| 133 | * Returns the value at the specified key.
|
| 134 | * @param keyName the key
|
| 135 | * @return the value
|
| 136 | */
|
| 137 | double SmartDashboard::GetNumber(std::string keyName)
|
| 138 | {
|
| 139 | return m_table->GetNumber(keyName);
|
| 140 | }
|
| 141 |
|
| 142 | /**
|
| 143 | * Maps the specified key to the specified value in this table.
|
| 144 | * Neither the key nor the value can be NULL.
|
| 145 | * The value can be retrieved by calling the get method with a key that is equal to the original key.
|
| 146 | * @param keyName the key
|
| 147 | * @param value the value
|
| 148 | */
|
| 149 | void SmartDashboard::PutString(std::string keyName, std::string value)
|
| 150 | {
|
| 151 | m_table->PutString(keyName, value);
|
| 152 | }
|
| 153 |
|
| 154 | /**
|
| 155 | * Returns the value at the specified key.
|
| 156 | * @param keyName the key
|
| 157 | * @param value the buffer to fill with the value
|
| 158 | * @param valueLen the size of the buffer pointed to by value
|
| 159 | * @return the length of the string
|
| 160 | */
|
| 161 | int SmartDashboard::GetString(std::string keyName, char *outBuffer, unsigned int bufferLen){
|
| 162 | std::string value = m_table->GetString(keyName);
|
| 163 | unsigned int i;
|
| 164 | for(i = 0; i<bufferLen-1&&i<value.length(); ++i)
|
| 165 | outBuffer[i] = (char)value.at(i);
|
| 166 | outBuffer[i] = '\0';
|
| 167 | return i;
|
| 168 | }
|
| 169 |
|
| 170 |
|
| 171 | /**
|
| 172 | * Returns the value at the specified key.
|
| 173 | * @param keyName the key
|
| 174 | * @return the value
|
| 175 | */
|
| 176 | std::string SmartDashboard::GetString(std::string keyName)
|
| 177 | {
|
| 178 | return m_table->GetString(keyName);
|
| 179 | }
|