blob: 285579ec8afb0b675597d0b00703fc22b7075e09 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. 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#ifndef __DASHBOARD_H__
8#define __DASHBOARD_H__
9
10#include "DashboardBase.h"
11#include "NetworkCommunication/FRCComm.h"
12#include <stack>
13#include <vector>
14#include <vxWorks.h>
15
16/**
17 * Pack data into the "user data" field that gets sent to the dashboard laptop
18 * via the driver station.
19 */
20class Dashboard : public DashboardBase
21{
22public:
23 explicit Dashboard(SEM_ID statusDataSemaphore);
24 virtual ~Dashboard();
25
26 enum Type {kI8, kI16, kI32, kU8, kU16, kU32, kFloat, kDouble, kBoolean, kString, kOther};
27 enum ComplexType {kArray, kCluster};
28
29 void AddI8(INT8 value);
30 void AddI16(INT16 value);
31 void AddI32(INT32 value);
32 void AddU8(UINT8 value);
33 void AddU16(UINT16 value);
34 void AddU32(UINT32 value);
35 void AddFloat(float value);
36 void AddDouble(double value);
37 void AddBoolean(bool value);
38 void AddString(char* value);
39 void AddString(char* value, INT32 length);
40
41 void AddArray();
42 void FinalizeArray();
43 void AddCluster();
44 void FinalizeCluster();
45
46 void Printf(const char *writeFmt, ...);
47
48 INT32 Finalize();
49 void GetStatusBuffer(char** userStatusData, INT32* userStatusDataSize);
50 void Flush() {}
51private:
52 static const INT32 kMaxDashboardDataSize = USER_STATUS_DATA_SIZE - sizeof(UINT32) * 3 - sizeof(UINT8); // 13 bytes needed for 3 size parameters and the sequence number
53
54 // Usage Guidelines...
55 DISALLOW_COPY_AND_ASSIGN(Dashboard);
56
57 bool ValidateAdd(INT32 size);
58 void AddedElement(Type type);
59 bool IsArrayRoot();
60
61 char *m_userStatusData;
62 INT32 m_userStatusDataSize;
63 char *m_localBuffer;
64 char *m_localPrintBuffer;
65 char *m_packPtr;
66 std::vector<Type> m_expectedArrayElementType;
67 std::vector<INT32> m_arrayElementCount;
68 std::vector<INT32*> m_arraySizePtr;
69 std::stack<ComplexType> m_complexTypeStack;
70 SEM_ID m_printSemaphore;
71 SEM_ID m_statusDataSemaphore;
72};
73
74#endif
75