Now you can download a copy of these docs so you can use them offline! Download now
SmartDashboard.cpp
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 
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 
50 {
51  if (value == NULL)
52  {
53  //TODO wpi_setWPIErrorWithContext(NullParameter, "value");
54  return;
55  }
56  PutData(value->GetName(), value);
57 }
58 
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 
83 void SmartDashboard::PutValue(std::string keyName, ComplexData& value)
84 {
85  m_table->PutValue(keyName, value);
86 }
87 
94 void SmartDashboard::RetrieveValue(std::string keyName, ComplexData& value)
95 {
96  m_table->RetrieveValue(keyName, value);
97 }
98 
106 void SmartDashboard::PutBoolean(std::string keyName, bool value)
107 {
108  m_table->PutBoolean(keyName, value);
109 }
110 
116 bool SmartDashboard::GetBoolean(std::string keyName)
117 {
118  return m_table->GetBoolean(keyName);
119 }
120 
128 void SmartDashboard::PutNumber(std::string keyName, double value){
129  m_table->PutNumber(keyName, value);
130 }
131 
137 double SmartDashboard::GetNumber(std::string keyName)
138 {
139  return m_table->GetNumber(keyName);
140 }
141 
149 void SmartDashboard::PutString(std::string keyName, std::string value)
150 {
151  m_table->PutString(keyName, value);
152 }
153 
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 
176 std::string SmartDashboard::GetString(std::string keyName)
177 {
178  return m_table->GetString(keyName);
179 }
static void PutData(std::string key, Sendable *data)
virtual void PutNumber(std::string key, double value)=0
static NetworkTable * GetTable(std::string key)
Definition: ITable.h:26
virtual ITable * GetSubTable(std::string key)=0
static void PutBoolean(std::string keyName, bool value)
virtual void InitTable(ITable *subtable)=0
static void PutValue(std::string keyName, ComplexData &value)
virtual void PutBoolean(std::string key, bool value)=0
static bool GetBoolean(std::string keyName)
virtual double GetNumber(std::string key)=0
static void PutNumber(std::string keyName, double value)
static int GetString(std::string keyName, char *value, unsigned int valueLen)
virtual std::string GetSmartDashboardType()=0
virtual void PutValue(std::string key, ComplexData &value)=0
static double GetNumber(std::string keyName)
virtual std::string GetString(std::string key)=0
static void PutString(std::string keyName, std::string value)
virtual std::string GetName()=0
static void RetrieveValue(std::string keyName, ComplexData &value)
virtual bool GetBoolean(std::string key)=0
virtual void PutString(std::string key, std::string value)=0

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6