Remove old driver station code

We don't need to send status data from the user program anymore

Change-Id: Ifbdb037cfb4e36681914dd7a3a2f5c56cbead6a2
This commit is contained in:
Thomas Clark
2014-08-08 11:23:03 -04:00
parent 8abbcf53f4
commit 5b8279f404
13 changed files with 1 additions and 1151 deletions

View File

@@ -202,9 +202,6 @@ extern "C"
int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons *buttons, uint8_t *count);
void HALSetNewDataSem(pthread_mutex_t *);
int HALSetStatusData(float battery, uint8_t dsDigitalOut, uint8_t updateNumber,
const char *userDataHigh, int userDataHighLength, const char *userDataLow,
int userDataLowLength, int wait_ms);
int HALInitialize(int mode = 0);
void HALNetworkCommunicationObserveUserProgramStarting();

View File

@@ -140,14 +140,6 @@ void HALSetNewDataSem(pthread_mutex_t * param)
setNewDataSem(param);
}
int HALSetStatusData(float battery, uint8_t dsDigitalOut, uint8_t updateNumber,
const char *userDataHigh, int userDataHighLength,
const char *userDataLow, int userDataLowLength, int wait_ms)
{
return setStatusData(battery, dsDigitalOut, updateNumber, userDataHigh,
userDataHighLength, userDataLow, userDataLowLength, wait_ms);
}
/**
* Call this to start up HAL. This is required for robot programs.
*/

View File

@@ -1,70 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* 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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "DashboardBase.h"
#include <stack>
#include <vector>
#include "HAL/HAL.hpp"
#include "HAL/Semaphore.hpp"
/**
* Pack data into the "user data" field that gets sent to the dashboard laptop
* via the driver station.
*/
class Dashboard : public DashboardBase
{
public:
explicit Dashboard(MUTEX_ID statusDataSemaphore);
virtual ~Dashboard();
enum Type {kI8, kI16, kI32, kU8, kU16, kU32, kFloat, kDouble, kBoolean, kString, kOther};
enum ComplexType {kArray, kCluster};
void AddI8(int8_t value);
void AddI16(int16_t value);
void AddI32(int32_t value);
void AddU8(uint8_t value);
void AddU16(uint16_t value);
void AddU32(uint32_t value);
void AddFloat(float value);
void AddDouble(double value);
void AddBoolean(bool value);
void AddString(char* value);
void AddString(char* value, int32_t length);
void AddArray();
void FinalizeArray();
void AddCluster();
void FinalizeCluster();
void Printf(const char *writeFmt, ...);
int32_t Finalize();
void GetStatusBuffer(char** userStatusData, int32_t* userStatusDataSize);
void Flush() {}
private:
static const int32_t kMaxDashboardDataSize = HAL_USER_STATUS_DATA_SIZE - sizeof(uint32_t) * 3 - sizeof(uint8_t); // 13 bytes needed for 3 size parameters and the sequence number
// Usage Guidelines...
DISALLOW_COPY_AND_ASSIGN(Dashboard);
bool ValidateAdd(int32_t size);
void AddedElement(Type type);
bool IsArrayRoot();
char *m_userStatusData;
int32_t m_userStatusDataSize;
char *m_localBuffer;
char *m_localPrintBuffer;
char *m_packPtr;
std::vector<Type> m_expectedArrayElementType;
std::vector<int32_t> m_arrayElementCount;
std::vector<int32_t*> m_arraySizePtr;
std::stack<ComplexType> m_complexTypeStack;
MUTEX_ID m_printSemaphore;
MUTEX_ID m_statusDataSemaphore;
};

View File

@@ -1,23 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* 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. */
/*----------------------------------------------------------------------------*/
#pragma once
#include "HAL/HAL.hpp"
#include "ErrorBase.h"
class DashboardBase : public ErrorBase
{
public:
virtual void GetStatusBuffer(char** userStatusData, int32_t* userStatusDataSize) = 0;
virtual void Flush() = 0;
virtual ~DashboardBase() {}
protected:
DashboardBase()
{
}
private:
DISALLOW_COPY_AND_ASSIGN(DashboardBase);
};

View File

@@ -5,7 +5,6 @@
/*----------------------------------------------------------------------------*/
#pragma once
#include "Dashboard.h"
#include "SensorBase.h"
#include "Task.h"
@@ -48,45 +47,6 @@ public:
double GetMatchTime();
float GetBatteryVoltage();
// Get the default dashboard packers. These instances stay around even after
// a call to SetHigh|LowPriorityDashboardPackerToUse() changes which packer
// is in use. You can restore the default high priority packer by calling
// SetHighPriorityDashboardPackerToUse(&GetHighPriorityDashboardPacker()).
Dashboard& GetHighPriorityDashboardPacker()
{
return m_dashboardHigh;
}
Dashboard& GetLowPriorityDashboardPacker()
{
return m_dashboardLow;
}
// Get/set the dashboard packers to use. This can sideline or restore the
// default packers. Initializing SmartDashboard changes the high priority
// packer in use so beware that the default packer will then be idle. These
// methods support any kind of DashboardBase, e.g. a Dashboard or a
// SmartDashboard.
DashboardBase* GetHighPriorityDashboardPackerInUse()
{
return m_dashboardInUseHigh;
}
DashboardBase* GetLowPriorityDashboardPackerInUse()
{
return m_dashboardInUseLow;
}
void SetHighPriorityDashboardPackerToUse(DashboardBase* db)
{
m_dashboardInUseHigh = db;
}
void SetLowPriorityDashboardPackerToUse(DashboardBase* db)
{
m_dashboardInUseLow = db;
}
void IncrementUpdateNumber()
{
m_updateNumber++;
}
MUTEX_ID GetUserStatusDataSem()
{
return m_statusDataSemaphore;
@@ -142,10 +102,6 @@ private:
uint8_t m_digitalOut;
MUTEX_ID m_statusDataSemaphore;
Task m_task;
Dashboard m_dashboardHigh; // the default dashboard packers
Dashboard m_dashboardLow;
DashboardBase* m_dashboardInUseHigh; // the current dashboard packers in use
DashboardBase* m_dashboardInUseLow;
SEMAPHORE_ID m_newControlData;
MUTEX_ID m_packetDataAvailableSem;
MULTIWAIT_ID m_waitForDataSem;

View File

@@ -36,7 +36,6 @@
#include "Commands/WaitUntilCommand.h"
#include "Compressor.h"
#include "Counter.h"
#include "Dashboard.h"
#include "DigitalInput.h"
#include "DigitalOutput.h"
#include "DigitalSource.h"

View File

@@ -1,400 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* 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 "Dashboard.h"
#include "DriverStation.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.hpp"
#include "WPIErrors.h"
#include <string.h>
#include <stdarg.h>
const int32_t Dashboard::kMaxDashboardDataSize;
/**
* Dashboard contructor.
*
* This is only called once when the DriverStation constructor is called.
*/
Dashboard::Dashboard(MUTEX_ID statusDataSem)
: m_userStatusData (NULL)
, m_userStatusDataSize (0)
, m_localBuffer (NULL)
, m_localPrintBuffer (NULL)
, m_packPtr (NULL)
, m_printSemaphore (0)
, m_statusDataSemaphore (statusDataSem)
{
m_userStatusData = new char[kMaxDashboardDataSize];
m_localBuffer = new char[kMaxDashboardDataSize];
m_localPrintBuffer = new char[kMaxDashboardDataSize * 2];
m_localPrintBuffer[0] = 0;
m_packPtr = m_localBuffer;
m_printSemaphore = initializeMutexNormal();
}
/**
* Dashboard destructor.
*
* Called only when the DriverStation class is destroyed.
*/
Dashboard::~Dashboard()
{
deleteMutex(m_printSemaphore);
m_packPtr = NULL;
delete [] m_localPrintBuffer;
m_localPrintBuffer = NULL;
delete [] m_localBuffer;
m_localBuffer = NULL;
delete [] m_userStatusData;
m_userStatusData = NULL;
}
/**
* Pack a signed 8-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddI8(int8_t value)
{
if (!ValidateAdd(sizeof(int8_t))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kI8);
}
/**
* Pack a signed 16-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddI16(int16_t value)
{
if (!ValidateAdd(sizeof(int16_t))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kI16);
}
/**
* Pack a signed 32-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddI32(int32_t value)
{
if (!ValidateAdd(sizeof(int32_t))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kI32);
}
/**
* Pack an unsigned 8-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddU8(uint8_t value)
{
if (!ValidateAdd(sizeof(uint8_t))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kU8);
}
/**
* Pack an unsigned 16-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddU16(uint16_t value)
{
if (!ValidateAdd(sizeof(uint16_t))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kU16);
}
/**
* Pack an unsigned 32-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddU32(uint32_t value)
{
if (!ValidateAdd(sizeof(uint32_t))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kU32);
}
/**
* Pack a 32-bit floating point number into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddFloat(float value)
{
if (!ValidateAdd(sizeof(float))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kFloat);
}
/**
* Pack a 64-bit floating point number into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddDouble(double value)
{
if (!ValidateAdd(sizeof(double))) return;
memcpy(m_packPtr, (char*)&value, sizeof(value));
m_packPtr += sizeof(value);
AddedElement(kDouble);
}
/**
* Pack a boolean into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddBoolean(bool value)
{
if (!ValidateAdd(sizeof(char))) return;
*m_packPtr = value ? 1 : 0;
m_packPtr += sizeof(char);
AddedElement(kBoolean);
}
/**
* Pack a NULL-terminated string of 8-bit characters into the dashboard data structure.
* @param value Data to be packed into the structure.
*/
void Dashboard::AddString(char* value)
{
AddString(value, strlen(value));
}
/**
* Pack a string of 8-bit characters of specified length into the dashboard data structure.
* @param value Data to be packed into the structure.
* @param length The number of bytes in the string to pack.
*/
void Dashboard::AddString(char* value, int32_t length)
{
if (!ValidateAdd(length + sizeof(length))) return;
memcpy(m_packPtr, (char*)&length, sizeof(length));
m_packPtr += sizeof(length);
memcpy(m_packPtr, value, length);
m_packPtr += length;
AddedElement(kString);
}
/**
* Start an array in the packed dashboard data structure.
*
* After calling AddArray(), call the appropriate Add method for each element of the array.
* Make sure you call the same add each time. An array must contain elements of the same type.
* You can use clusters inside of arrays to make each element of the array contain a structure of values.
* You can also nest arrays inside of other arrays.
* Every call to AddArray() must have a matching call to FinalizeArray().
*/
void Dashboard::AddArray()
{
if (!ValidateAdd(sizeof(int32_t))) return;
m_complexTypeStack.push(kArray);
m_arrayElementCount.push_back(0);
m_arraySizePtr.push_back((int32_t*)m_packPtr);
m_packPtr += sizeof(int32_t);
}
/**
* Indicate the end of an array packed into the dashboard data structure.
*
* After packing data into the array, call FinalizeArray().
* Every call to AddArray() must have a matching call to FinalizeArray().
*/
void Dashboard::FinalizeArray()
{
if (m_complexTypeStack.top() != kArray)
{
wpi_setWPIError(MismatchedComplexTypeClose);
return;
}
m_complexTypeStack.pop();
*(m_arraySizePtr.back()) = m_arrayElementCount.back();
m_arraySizePtr.pop_back();
if (m_arrayElementCount.back() != 0)
{
m_expectedArrayElementType.pop_back();
}
m_arrayElementCount.pop_back();
AddedElement(kOther);
}
/**
* Start a cluster in the packed dashboard data structure.
*
* After calling AddCluster(), call the appropriate Add method for each element of the cluster.
* You can use clusters inside of arrays to make each element of the array contain a structure of values.
* Every call to AddCluster() must have a matching call to FinalizeCluster().
*/
void Dashboard::AddCluster()
{
m_complexTypeStack.push(kCluster);
}
/**
* Indicate the end of a cluster packed into the dashboard data structure.
*
* After packing data into the cluster, call FinalizeCluster().
* Every call to AddCluster() must have a matching call to FinalizeCluster().
*/
void Dashboard::FinalizeCluster()
{
if (m_complexTypeStack.top() != kCluster)
{
wpi_setWPIError(MismatchedComplexTypeClose);
return;
}
m_complexTypeStack.pop();
AddedElement(kOther);
}
/**
* Print a string to the UserData text on the Dashboard.
*
* This will add text to the buffer to send to the dashboard.
* You must call Finalize() periodically to actually send the buffer to the dashboard if you are not using the packed dashboard data.
*/
void Dashboard::Printf(const char *writeFmt, ...)
{
va_list args;
int32_t size;
// Check if the buffer has already been used for packing.
if (m_packPtr != m_localBuffer)
{
wpi_setWPIError(DashboardDataCollision);
return;
}
va_start (args, writeFmt);
{
Synchronized sync(m_printSemaphore);
vsprintf(m_localPrintBuffer + strlen(m_localPrintBuffer), writeFmt, args);
size = strlen(m_localPrintBuffer);
}
if (size > kMaxDashboardDataSize)
{
wpi_setWPIError(DashboardDataOverflow);
}
va_end (args);
}
/**
* Indicate that the packing is complete and commit the buffer to the DriverStation.
*
* The packing of the dashboard packet is complete.
* If you are not using the packed dashboard data, you can call Finalize() to commit the Printf() buffer and the error string buffer.
* In effect, you are packing an empty structure.
* Prepares a packet to go to the dashboard...
* @return The total size of the data packed into the userData field of the status packet.
*/
int32_t Dashboard::Finalize()
{
if (!m_complexTypeStack.empty())
{
wpi_setWPIError(MismatchedComplexTypeClose);
return 0;
}
static bool reported = false;
if (!reported)
{
HALReport(HALUsageReporting::kResourceType_Dashboard, 0);
reported = true;
}
Synchronized sync(m_statusDataSemaphore);
// Sequence number
DriverStation::GetInstance()->IncrementUpdateNumber();
// Packed Dashboard Data
m_userStatusDataSize = m_packPtr - m_localBuffer;
memcpy(m_userStatusData, m_localBuffer, m_userStatusDataSize);
m_packPtr = m_localBuffer;
return m_userStatusDataSize;
}
/**
* Called by the DriverStation class to retrieve buffers, sizes, etc. for writing
* to the NetworkCommunication task.
* This function is called while holding the m_statusDataSemaphore.
*/
void Dashboard::GetStatusBuffer(char **userStatusData, int32_t* userStatusDataSize)
{
// User printed strings
if (m_localPrintBuffer[0] != 0)
{
// Sequence number
DriverStation::GetInstance()->IncrementUpdateNumber();
int32_t printSize;
Synchronized syncPrint(m_printSemaphore);
printSize = strlen(m_localPrintBuffer);
m_userStatusDataSize = printSize;
memcpy(m_userStatusData, m_localPrintBuffer, m_userStatusDataSize);
m_localPrintBuffer[0] = 0;
}
*userStatusData = m_userStatusData;
*userStatusDataSize = m_userStatusDataSize;
}
/**
* Validate that the data being packed will fit in the buffer.
*/
bool Dashboard::ValidateAdd(int32_t size)
{
if ((m_packPtr - m_localBuffer) + size > kMaxDashboardDataSize)
{
wpi_setWPIError(DashboardDataOverflow);
return false;
}
// Make sure printf is not being used at the same time.
if (m_localPrintBuffer[0] != 0)
{
wpi_setWPIError(DashboardDataCollision);
return false;
}
return true;
}
/**
* Check for consistent types when adding elements to an array and keep track of the number of elements in the array.
*/
void Dashboard::AddedElement(Type type)
{
if(IsArrayRoot())
{
if (m_arrayElementCount.back() == 0)
{
m_expectedArrayElementType.push_back(type);
}
else
{
if (type != m_expectedArrayElementType.back())
{
wpi_setWPIError(InconsistentArrayValueAdded);
}
}
m_arrayElementCount.back() = m_arrayElementCount.back() + 1;
}
}
/**
* If the top of the type stack an array?
*/
bool Dashboard::IsArrayRoot()
{
return !m_complexTypeStack.empty() && m_complexTypeStack.top() == kArray;
}

View File

@@ -24,7 +24,6 @@ TLogLevel dsLogLevel = logDEBUG;
const uint32_t DriverStation::kJoystickPorts;
const uint32_t DriverStation::kJoystickAxes;
DriverStation* DriverStation::m_instance = NULL;
uint8_t DriverStation::m_updateNumber = 0;
/**
* DriverStation contructor.
@@ -35,10 +34,6 @@ DriverStation::DriverStation()
: m_digitalOut (0)
, m_statusDataSemaphore (initializeMutexNormal())
, m_task ("DriverStation", (FUNCPTR)DriverStation::InitTask)
, m_dashboardHigh(m_statusDataSemaphore)
, m_dashboardLow(m_statusDataSemaphore)
, m_dashboardInUseHigh(&m_dashboardHigh)
, m_dashboardInUseLow(&m_dashboardLow)
, m_newControlData(0)
, m_packetDataAvailableSem (0)
, m_waitForDataSem(0)
@@ -88,7 +83,6 @@ void DriverStation::Run()
while (true)
{
takeMutex(m_packetDataAvailableSem);
SetData();
GetData();
giveMultiWait(m_waitForDataSem);
if (++period >= 4)
@@ -119,8 +113,6 @@ DriverStation* DriverStation::GetInstance()
return m_instance;
}
#include <iostream>
/**
* Copy data from the DS task for the user.
* If no new data exists, it will just be returned, otherwise
@@ -160,29 +152,6 @@ void DriverStation::GetData()
giveSemaphore(m_newControlData);
}
/**
* Copy status data from the DS task for the user.
*/
void DriverStation::SetData()
{
char *userStatusDataHigh;
int32_t userStatusDataHighSize;
char *userStatusDataLow;
int32_t userStatusDataLowSize;
Synchronized sync(m_statusDataSemaphore);
m_dashboardInUseHigh->GetStatusBuffer(&userStatusDataHigh, &userStatusDataHighSize);
m_dashboardInUseLow->GetStatusBuffer(&userStatusDataLow, &userStatusDataLowSize);
//TODO ???
//HALSetStatusData(GetBatteryVoltage(), m_digitalOut, m_updateNumber,
// userStatusDataHigh, userStatusDataHighSize, userStatusDataLow, userStatusDataLowSize, HAL_WAIT_FOREVER);
m_dashboardInUseHigh->Flush();
m_dashboardInUseLow->Flush();
}
/**
* Read the battery voltage.
*

View File

@@ -1,371 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import java.util.Stack;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
/**
* Pack data into the "user data" field that gets sent to the dashboard laptop
* via the driver station.
*/
public class Dashboard implements IDashboard {
protected class MemAccess {
byte[] m_bytes;
protected MemAccess(byte[] bytes) {
m_bytes = bytes;
}
protected MemAccess(int length) {
m_bytes = new byte[length];
}
public void setByte(int index, byte value) {
m_bytes[index] = value;
}
public void setShort(int index, short value) {
setByte(index++, (byte) (value >>> 8));
setByte(index++, (byte) (value));
}
public void setInt(int index, int value) {
setByte(index++, (byte) (value >>> 24));
setByte(index++, (byte) (value >>> 16));
setByte(index++, (byte) (value >>> 8));
setByte(index++, (byte) (value));
}
public void setFloat(int index, float value) {
setInt(index, Float.floatToIntBits(value));
}
public void setDouble(int index, double value) {
setInt(index, (int) (Double.doubleToLongBits(value) >>> 32));
setInt(index + 4, (int) Double.doubleToLongBits(value));
}
public void setString(int index, String value) {
setBytes(index, value.getBytes(), 0, value.length());
}
public void setBytes(int index, byte[] value, int offset, int number) {
for (int i = 0; i < number; i++) {
m_bytes[i + index] = value[i + offset];
}
}
}
private static final String kArray = "Array";
private static final String kCluster = "Cluster";
private static final Integer kByte = new Integer(0);
private static final Integer kShort = new Integer(1);
private static final Integer kInt = new Integer(2);
private static final Integer kFloat = new Integer(3);
private static final Integer kDouble = new Integer(4);
private static final Integer kString = new Integer(5);
private static final Integer kOther = new Integer(6);
private static final Integer kBoolean = new Integer(7);
private static final int kMaxDashboardDataSize = DriverStation.USER_STATUS_DATA_SIZE -
4 * 3 - 1; // 13 bytes needed for 3 size parameters and the sequence number
private static boolean m_reported = false;
protected MemAccess m_userStatus;
protected int m_userStatusSize = 0;
private MemAccess m_localBuffer;
private int m_packPtr;
private Stack m_expectedArrayElementType = new Stack();
private Stack m_arrayElementCount = new Stack();
private Stack m_arraySizePtr = new Stack();
private Stack m_complexTypeStack = new Stack();
private final Object m_statusDataSemaphore;
/**
* Dashboard constructor.
*
* This is only called once when the DriverStation constructor is called.
* @param statusDataSemaphore the object to synchronize on
*/
protected Dashboard(Object statusDataSemaphore) {
m_userStatus = new MemAccess(kMaxDashboardDataSize);
m_localBuffer = new MemAccess(kMaxDashboardDataSize);
m_packPtr = 0;
m_statusDataSemaphore = statusDataSemaphore;
}
/**
* Pack a signed 8-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
* @return True on success
*/
public boolean addByte(byte value) {
if (!validateAdd(1)) {
return false;
}
m_localBuffer.setByte(m_packPtr, value);
m_packPtr += 1;
return addedElement(kByte);
}
/**
* Pack a signed 16-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
* @return True on success
*/
public boolean addShort(short value) {
if (!validateAdd(2)) {
return false;
}
m_localBuffer.setShort(m_packPtr, value);
m_packPtr += 2;
return addedElement(kShort);
}
/**
* Pack a signed 32-bit int into the dashboard data structure.
* @param value Data to be packed into the structure.
* @return True on success
*/
public boolean addInt(int value) {
if (!validateAdd(4)) {
return false;
}
m_localBuffer.setInt(m_packPtr, value);
m_packPtr += 4;
return addedElement(kInt);
}
/**
* Pack a 32-bit floating point number into the dashboard data structure.
* @param value Data to be packed into the structure.
* @return True on success
*/
public boolean addFloat(float value) {
if (!validateAdd(4)) {
return false;
}
m_localBuffer.setFloat(m_packPtr, value);
m_packPtr += 4;
return addedElement(kFloat);
}
/**
* Pack a 64-bit floating point number into the dashboard data structure.
* @param value Data to be packed into the structure.
* @return True on success
*/
public boolean addDouble(double value) {
if (!validateAdd(8)) {
return false;
}
m_localBuffer.setDouble(m_packPtr, value);
m_packPtr += 8;
return addedElement(kDouble);
}
/**
* Pack a boolean into the dashboard data structure.
* @param value Data to be packed into the structure.
* @return True on success
*/
public boolean addBoolean(boolean value) {
if (!validateAdd(1)) {
return false;
}
m_localBuffer.setByte(m_packPtr, (byte) (value ? 1 : 0));
m_packPtr += 1;
return addedElement(kBoolean);
}
/**
* Pack a NULL-terminated string of 8-bit characters into the dashboard data structure.
* @param value Data to be packed into the structure.
* @return True on success
*/
public boolean addString(String value) {
if (!validateAdd(value.length() + 4)) {
return false;
}
m_localBuffer.setInt(m_packPtr, value.length());
m_packPtr += 4;
m_localBuffer.setString(m_packPtr, value);
m_packPtr += value.length();
return addedElement(kString);
}
/**
* Pack a string of 8-bit characters of specified length into the dashboard data structure.
* @param value Data to be packed into the structure.
* @param length The number of bytes in the string to pack.
* @return True on success
*/
public boolean addString(String value, int length) {
return addString(value.substring(0, length));
}
/**
* Start an array in the packed dashboard data structure.
*
* After calling addArray(), call the appropriate Add method for each element of the array.
* Make sure you call the same add each time. An array must contain elements of the same type.
* You can use clusters inside of arrays to make each element of the array contain a structure of values.
* You can also nest arrays inside of other arrays.
* Every call to addArray() must have a matching call to finalizeArray().
* @return True on success
*/
public boolean addArray() {
if (!validateAdd(4)) {
return false;
}
m_complexTypeStack.push(kArray);
m_arrayElementCount.push(new Integer(0));
m_arraySizePtr.push(new Integer(m_packPtr));
m_packPtr += 4;
return true;
}
/**
* Indicate the end of an array packed into the dashboard data structure.
*
* After packing data into the array, call finalizeArray().
* Every call to addArray() must have a matching call to finalizeArray().
* @return True on success
*/
public boolean finalizeArray() {
if (m_complexTypeStack.peek() != kArray) {
System.err.println("Attempted to finalize an array in the middle of a cluster or without starting the array");
return false;
}
m_complexTypeStack.pop();
m_localBuffer.setInt(((Integer) m_arraySizePtr.pop()).intValue(),
((Integer) m_arrayElementCount.peek()).intValue());
if (((Integer) m_arrayElementCount.peek()).intValue() != 0) {
m_expectedArrayElementType.pop();
}
m_arrayElementCount.pop();
return addedElement(kOther);
}
/**
* Start a cluster in the packed dashboard data structure.
*
* After calling addCluster(), call the appropriate Add method for each element of the cluster.
* You can use clusters inside of arrays to make each element of the array contain a structure of values.
* Every call to addCluster() must have a matching call to finalizeCluster().
* @return True on success
*/
public boolean addCluster() {
m_complexTypeStack.push(kCluster);
return true;
}
/**
* Indicate the end of a cluster packed into the dashboard data structure.
*
* After packing data into the cluster, call finalizeCluster().
* Every call to addCluster() must have a matching call to finalizeCluster
* @return True on success
*/
public boolean finalizeCluster() {
if (m_complexTypeStack.peek() != kCluster) {
System.err.println("Attempted to close a cluster on an open array or without starting the cluster");
return false;
}
m_complexTypeStack.pop();
return addedElement(kOther);
}
/**
* Indicate that the packing is complete and commit the buffer to the DriverStation.
*
* The packing of the dashboard packet is complete.
* If you are not using the packed dashboard data, you can call commit() to commit the Printf() buffer and the error string buffer.
* In effect, you are packing an empty structure.
* Prepares a packet to go to the dashboard...
* Pack the sequence number, Printf() buffer, the errors messages (not implemented yet), and packed dashboard data buffer.
* @return The total size of the data packed into the userData field of the status packet.
*/
public synchronized int commit() {
if (!m_complexTypeStack.empty()) {
System.err.println("didn't finish complex type");
m_packPtr = 0;
System.err.println("didn't finish complex type");
return 0;
}
if(!m_reported) {
UsageReporting.report(tResourceType.kResourceType_Dashboard, 0);
m_reported = true;
}
synchronized (m_statusDataSemaphore) {
// Sequence number
DriverStation.getInstance().incrementUpdateNumber();
// Packed Dashboard Data
m_userStatusSize = m_packPtr;
m_userStatus.setBytes(0, m_localBuffer.m_bytes, 0, m_userStatusSize);
m_packPtr = 0;
}
return m_userStatusSize;
}
/**
* Validate that the data being packed will fit in the buffer.
*/
private boolean validateAdd(int size) {
if (m_packPtr + size > kMaxDashboardDataSize) {
m_packPtr = 0;
System.err.println("Dashboard data is too long to send");
return false;
}
return true;
}
/**
* Check for consistent types when adding elements to an array and keep track of the number of elements in the array.
*/
private boolean addedElement(Integer type) {
if (isArrayRoot()) {
if (((Integer) m_arrayElementCount.peek()).intValue() == 0) {
m_expectedArrayElementType.push(type);
} else {
if (type != m_expectedArrayElementType.peek()) {
System.err.println("Attempted to add multiple datatypes to the same array");
return false;
}
}
m_arrayElementCount.push(new Integer(((Integer) m_arrayElementCount.pop()).intValue() + 1));
}
return true;
}
/**
* If the top of the type stack an array?
*/
private boolean isArrayRoot() {
return !m_complexTypeStack.empty() && m_complexTypeStack.peek() == kArray;
}
public byte[] getBytes() {
return m_userStatus.m_bytes;
}
public int getBytesLength() {
return m_userStatusSize;
}
public void flush() {
}
}

View File

@@ -67,10 +67,6 @@ public class DriverStation implements RobotState.Interface {
private final Object m_dataSem;
private int m_digitalOut;
private volatile boolean m_thread_keepalive = true;
private final Dashboard m_dashboardDefaultHigh;
private final Dashboard m_dashboardDefaultLow;
private IDashboard m_dashboardInUseHigh;
private IDashboard m_dashboardInUseLow;
private int m_updateNumber = 0;
private double m_approxMatchTimeOffset = -1.0;
private boolean m_userInDisabled = false;
@@ -99,11 +95,7 @@ public class DriverStation implements RobotState.Interface {
m_semaphore = new Object();
m_dataSem = new Object();
m_dashboardInUseHigh = m_dashboardDefaultHigh = new Dashboard(m_semaphore);
m_dashboardInUseLow = m_dashboardDefaultLow = new Dashboard(m_semaphore);
m_packetDataAvailableSem = HALUtil.initializeMutexNormal();
m_packetDataAvailableSem = ByteBuffer.allocateDirect(4);
// set the byte order
m_packetDataAvailableSem.order(ByteOrder.LITTLE_ENDIAN);
@@ -131,7 +123,6 @@ public class DriverStation implements RobotState.Interface {
HALUtil.takeMutex(m_packetDataAvailableSem);
synchronized (this) {
getData();
setData();
}
synchronized (m_dataSem) {
m_dataSem.notifyAll();
@@ -212,25 +203,6 @@ public class DriverStation implements RobotState.Interface {
m_newControlData = true;
}
/**
* Copy status data from the DS task for the user.
* This is used primarily to set digital outputs on the DS.
*/
protected void setData() {
synchronized (m_semaphore) {
// TODO ???
/*FRCNetworkCommunicationsLibrary.setStatusData((float) getBatteryVoltage(),
(byte) m_digitalOut,
(byte) m_updateNumber,
new String(m_dashboardInUseHigh.getBytes()),
m_dashboardInUseHigh.getBytesLength(),
new String(m_dashboardInUseLow.getBytes()),
m_dashboardInUseLow.getBytesLength());
m_dashboardInUseHigh.flush();
m_dashboardInUseLow.flush();*/
}
}
/**
* Read the battery voltage.
*
@@ -385,93 +357,6 @@ public class DriverStation implements RobotState.Interface {
}
}
/**
* Sets the dashboard packer to use for sending high priority user data to a
* dashboard receiver. This can idle or restore the default packer.
* (Initializing SmartDashboard sets the high priority packer in use, so
* beware that the default packer will then be idle. You can restore the
* default high priority packer by calling
* {@code setDashboardPackerToUseHigh(getDashboardPackerHigh())}.)
*
* @param dashboard any kind of IDashboard object
*/
public void setDashboardPackerToUseHigh(IDashboard dashboard) {
m_dashboardInUseHigh = dashboard;
}
/**
* Gets the default dashboard packer for sending high priority user data to
* a dashboard receiver. This instance stays around even after a call to
* {@link #setDashboardPackerToUseHigh} changes which packer is in use.
*
* @return the default Dashboard object; it may be idle
*/
public Dashboard getDashboardPackerHigh() {
return m_dashboardDefaultHigh;
}
/**
* Gets the dashboard packer that's currently in use for sending high
* priority user data to a dashboard receiver. This can be any kind of
* IDashboard.
*
* @return the current IDashboard object
*/
public IDashboard getDashboardPackerInUseHigh() {
return m_dashboardInUseHigh;
}
/**
* Sets the dashboard packer to use for sending low priority user data to a
* dashboard receiver. This can idle or restore the default packer.
*
* @param dashboard any kind of IDashboard object
*/
public void setDashboardPackerToUseLow(IDashboard dashboard) {
m_dashboardInUseLow = dashboard;
}
/**
* Gets the default dashboard packer for sending low priority user data to
* a dashboard receiver. This instance stays around even after a call to
* {@link #setDashboardPackerToUseLow} changes which packer is in use.
*
* @return the default Dashboard object; it may be idle
*/
public Dashboard getDashboardPackerLow() {
return m_dashboardDefaultLow;
}
/**
* Gets the dashboard packer that's currently in use for sending low
* priority user data to a dashboard receiver. This can be any kind of
* IDashboard.
*
* @return the current IDashboard object
*/
public IDashboard getDashboardPackerInUseLow() {
return m_dashboardInUseLow;
}
/**
* Gets the status data monitor
* @return The status data monitor for use with IDashboard objects which must
* send data across the network.
*/
public Object getStatusDataMonitor() {
return m_semaphore;
}
/**
* Increments the internal update number sent across the network along with
* status data.
*/
void incrementUpdateNumber() {
synchronized (m_semaphore) {
m_updateNumber++;
}
}
/**
* Is the driver station attached to a Field Management System?
* Note: This does not work with the Blue DS.

View File

@@ -1,34 +0,0 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
/**
* Represents a Dashboard which can provide data to be sent by the DriverStation
* class.
* @author pmalmsten
*/
public interface IDashboard {
/**
* Gets a reference to the current data to be sent to the dashboard.
* @return Byte array of data.
*/
public byte[] getBytes();
/**
* Gets the length of the current data to be sent to the
* dashboard.
* @return The length of the data array to be sent to the dashboard.
*/
public int getBytesLength();
/**
* If the dashboard had data buffered to be sent, calling this method
* will reset the output buffer.
*/
public void flush();
}

View File

@@ -361,30 +361,6 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
public static native int FRCNetworkCommunicationUsageReportingReport(byte resource, byte instanceNumber, byte context, String feature);
/**
* Original signature : <code>void getFPGAHardwareVersion(uint16_t*, uint32_t*)</code><br>
* <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:124</i><br>
* @deprecated use the safer methods {@link #getFPGAHardwareVersion(java.nio.ShortBuffer, java.nio.IntBuffer)} and {@link #getFPGAHardwareVersion(com.sun.jna.ptr.ShortByReference, com.sun.jna.ptr.IntByReference)} instead
*/
//@Deprecated
//public static native void getFPGAHardwareVersion(ShortByReference fpgaVersion, IntByReference fpgaRevision);
/**
* Original signature : <code>void getFPGAHardwareVersion(uint16_t*, uint32_t*)</code><br>
* <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:124</i>
*/
public static native void getFPGAHardwareVersion(ShortBuffer fpgaVersion, IntBuffer fpgaRevision);
/**
* Original signature : <code>int getRecentStatusData(uint8_t*, uint8_t*, uint8_t*, int)</code><br>
* <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:128</i><br>
* @deprecated use the safer methods {@link #getRecentStatusData(java.nio.ByteBuffer, java.nio.ByteBuffer, java.nio.ByteBuffer, int)} and {@link #getRecentStatusData(com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, int)} instead
*/
//@Deprecated
//public static native int getRecentStatusData(Pointer batteryInt, Pointer batteryDec, Pointer dsDigitalOut, int wait_ms);
/**
* Original signature : <code>int getRecentStatusData(uint8_t*, uint8_t*, uint8_t*, int)</code><br>
* <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:128</i>
*/
public static native int getRecentStatusData(ByteBuffer batteryInt, ByteBuffer batteryDec, ByteBuffer dsDigitalOut, int wait_ms);
/**
* Original signature : <code>int setStatusData(float, uint8_t, uint8_t, const char*, int, const char*, int, int)</code><br>
* <i>native declaration : src\main\include\NetworkCommunication\FRCComm.h:124</i><br>
* @deprecated use the safer methods {@link #getFPGAHardwareVersion(java.nio.ShortBuffer, java.nio.IntBuffer)} and {@link #getFPGAHardwareVersion(com.sun.jna.ptr.ShortByReference, com.sun.jna.ptr.IntByReference)} instead
*/

View File

@@ -134,32 +134,6 @@ jfieldID FPGAChecksum1FieldID;
jfieldID FPGAChecksum2FieldID;
jfieldID FPGAChecksum3FieldID;
jfieldID versionDataFieldID;
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: getRecentStatusData
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;I)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_getRecentStatusData
(JNIEnv *, jclass, jobject, jobject, jobject, jint)
{
assert(false);
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: setStatusData
* Signature: (FBBLjava/lang/String;ILjava/lang/String;II)I
*/
JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_communication_FRCNetworkCommunicationsLibrary_setStatusData
(JNIEnv * env, jclass, jfloat paramBattery, jbyte param1, jbyte param2, jstring paramUserDataHigh, jint param4, jstring paramUserDataLow, jint param6)
{
//NETCOMM_LOG(logDEBUG) << "Voltage - " << paramBattery;
const char * userDataHighStr = env->GetStringUTFChars(paramUserDataHigh, NULL);
const char * userDataLowStr = env->GetStringUTFChars(paramUserDataLow, NULL);
jint returnValue = HALSetStatusData(paramBattery, param1, param2, userDataHighStr, param4, userDataLowStr, param6, HAL_WAIT_FOREVER );
env->ReleaseStringUTFChars(paramUserDataHigh,userDataHighStr);
env->ReleaseStringUTFChars(paramUserDataLow,userDataLowStr);
return returnValue;
}
/*
* Class: edu_wpi_first_wpilibj_communication_FRC_NetworkCommunicationsLibrary
* Method: setErrorData