View Single Post
  #5   Spotlight this post!  
Unread 28-12-2009, 21:37
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: replace WPILib part

Header:
PHP Code:
#ifndef __DASHBOARD_H__
#define __DASHBOARD_H__

#include "ErrorBase.h"
#include "NetworkCommunication/FRCComm.h"

#include <VxWorks.h>
#include <stack>
#include <vector>
using namespace std;
typedef unsigned int uint;
/**
 * Pack data into the "user data" field that gets sent to the dashboard laptop
 * via the driver station.
 */
class Dashboard : public ErrorBase
{
        
// Can only be constructed by the DriverStation class.
        
friend class DriverStation;

    public:
        
        
inline void Add(string namestring value);
        
inline void Add(string nameint value);
        
inline void Add(string namefloat value);
        
inline void Add(string namedouble value);
        
inline void Add(const charnameint value);
        
inline void Add(const charnamefloat value);
        
inline void Add(const charnamedouble value);
        
inline void Add(const charname, const charvalue);

        
void AddDebugVariable(const charname, const charvalue);
        
inline void AddDebugVariable(string namestring value);
        
inline void AddDebugVariable(string nameint value);
        
inline void AddDebugVariable(string namefloat value);
        
inline void AddDebugVariable(string namedouble value);
        
inline void AddDebugVariable(const charnameint value);
        
inline void AddDebugVariable(const charnamefloat value);
        
inline void AddDebugVariable(const charnamedouble value);

        
//AddDebugVariable renamed for convenience
        
inline void var(const charname, const charvalue);
        
inline void var(string namestring value);
        
inline void var(string nameint value);
        
inline void var(string namefloat value);
        
inline void var(string namedouble value);
        
inline void var(const charnameint value);
        
inline void var(const charnamefloat value);
        
inline void var(const charnamedouble value);

        
void AddRaw(const char *rawuint length);

        
INT32 Send();
    private:
        
Dashboard(char **userStatus);
        
virtual ~Dashboard();

        static const 
INT32 kMaxDashboardDataSizeUSER_STATUS_DATA_SIZE sizeof(UINT32) * sizeof(UINT8); // 13 bytes needed for 3 size parameters and the sequence number

        // Usage Guidelines...
        
DISALLOW_COPY_AND_ASSIGN(Dashboard)
        ;

        
int location;
        
char **m_userStatus;
        
char *m_localBuffer;
        
char *raw;
        
uint rawLength;
        
SEM_ID m_printSemaphore;
        
UINT8 m_sequence;
};

#endif 
Source:
PHP Code:
//include my dashboard heade
#include "Dashboard.h"
#include "Synchronized.h"
#include "Utility.h"
#include "WPIStatus.h"
#include <strLib.h>
#include <sstream>

using namespace std;
/**
 * Dashboard constructor.
 * 
 * This is only called once when the DriverStation constructor is called.
 */
Dashboard::Dashboard(char **userStatus):
    
m_userStatus(userStatus), m_localBuffer(NULL), m_printSemaphore(0), m_sequence(0)
{
    
//Syntax: @@@451:|name=value|dbg=name: value|name=value|:451@@@
    
m_localBuffer = new char[kMaxDashboardDataSize 2];
    
    
m_localBuffer[0] = '@';
    
m_localBuffer[1] = '@';
    
m_localBuffer[2] = '@';
    
m_localBuffer[3] = '4';
    
m_localBuffer[4] = '5';
    
m_localBuffer[5] = '1';
    
m_localBuffer[6] = ':';
    
m_localBuffer[7] = '|';
    
m_localBuffer[8] = 0;
    
raw = new char[kMaxDashboardDataSize 2];
    
raw[0]=4;
    
raw[1]=5;
    
raw[2]=1;
    
raw[3]=32;
    
m_printSemaphore semMCreate(SEM_DELETE_SAFE SEM_INVERSION_SAFE); // synchronize access to multi-value registers
}

/**
 * Dashboard destructor.
 * 
 * Called only when the DriverStation class is destroyed.
 */
Dashboard::~Dashboard()
{
    
m_userStatus NULL;
    
delete [] m_localBuffer;
    
m_localBuffer NULL;
}

/**
 * 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::Add(string namestring value)
{
    
this->Add(name.c_str(), value.c_str());
}
void Dashboard::Add(string nameint value)
{
    
stringstream out;
    
out << value;
    
this->Add(name.c_str(), out.str().c_str());
}
//Add clones removed...

void Dashboard::AddDebugVariable(string namestring value)
{
    
this->AddDebugVariable(name.c_str(), value.c_str());
}
void Dashboard::AddDebugVariable(string nameint value)
{
    
stringstream out;
    
out << value;
    
this->AddDebugVariable(name.c_str(), out.str().c_str());
}
//AddDebugVariable clones removed...
//AddDebugVariable renamed for convenience
void Dashboard::var(const charname, const charvalue)
{
    
this->AddDebugVariable(namevalue);
}
void Dashboard::var(string namestring value)
{
    
this->AddDebugVariable(namevalue);
}
//var clones removed...
void Dashboard::AddRaw(const char *rawuint length)
{
    {
        
Synchronized sync(m_printSemaphore);
        
memcpy(this->raw+4rawlength);//keep intact the beginning

        
this->rawLength=length;
    }
    if (
length+(uint)strlen(m_localBuffer) > (uint)kMaxDashboardDataSize)
    {
        
wpi_fatal(DashboardDataOverflow);
    }
    
}
void Dashboard::AddDebugVariable(const charname, const charvalue)
{
    
string fv=name;
    
fv+=": ";
    
fv+=value;
    
this->Add("dbg",fv.c_str());//TEST:this might fail the cast
}
void Dashboard::Add(const charname, const charvalue)
{
    
INT32 size;
    {
        
Synchronized sync(m_printSemaphore);
        
memcpy(m_localBuffer strlen(m_localBuffer), namestrlen(name));
        
m_localBuffer[strlen(m_localBuffer)+1]=0;//keep null to allow strlen to function
        
m_localBuffer[strlen(m_localBuffer)]='=';
        
memcpy(m_localBuffer strlen(m_localBuffer), valuestrlen(value));
        
m_localBuffer[strlen(m_localBuffer)+1]=0;//keep null to allow strlen to function
                
m_localBuffer[strlen(m_localBuffer)]='|';
        
//m_localBuffer + strlen(m_localBuffer), writeFmt, args);
        
size strlen(m_localBuffer);
    }
    if (
size kMaxDashboardDataSize)
    {
        
wpi_fatal(DashboardDataOverflow);
    }
}

/**
 * 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...
 * 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.
 */
INT32 Dashboard::Send()
{
    if (*
m_userStatus == NULL)
    {
        
wpi_fatal(NullParameter);
        return 
0;
    }
    
    
INT32 size 0;
    
// QUE: Is this necessary? 
    // Sequence number
    
memcpy(*m_userStatus size, &m_sequencesizeof(m_sequence));
    
size += sizeof(m_sequence);
    
m_sequence++;
    
    
INT32 printSize;
    {
        
//Raw data (images, etc)
        
Synchronized sync(m_printSemaphore);
        
        
memcpy(*m_userStatus size, &rawLengthsizeof(rawLength));
        
size += sizeof(rawLength);
        
memcpy(*m_userStatus sizerawrawLength);
        
size += printSize;
        
//        raw[0]=4;
        //        raw[1]=5;
        //        raw[2]=1;
        //        raw[3]=32;
        //skip this because don't ever overwrite it

        // User printed strings
        
printSize strlen(m_localBuffer);
        
memcpy(*m_userStatus sizem_localBufferprintSize);
        
size += printSize;
        
string end="|:451@@@";
        
memcpy(*m_userStatus sizeend.c_str(), end.length());
                
size += end.length();
        
m_localBuffer[0] = '@';
        
m_localBuffer[1] = '@';
        
m_localBuffer[2] = '@';
        
m_localBuffer[3] = '4';
        
m_localBuffer[4] = '5';
        
m_localBuffer[5] = '1';
        
m_localBuffer[6] = ':';
        
m_localBuffer[7] = '|';
        
m_localBuffer[8] = 0;
    }
    
    return 
size;

main code:
PHP Code:
//...
DriverStation::GetInstance()->ds.GetDashboardPacker().Add("gsgs","fsdfds");
DriverStation::GetInstance()->ds.GetDashboardPacker().Send();
//... 
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote