Squashed 'third_party/allwpilib_2016/' content from commit 7f61816

Change-Id: If9d9245880859cdf580f5d7f77045135d0521ce7
git-subtree-dir: third_party/allwpilib_2016
git-subtree-split: 7f618166ed253a24629934fcf89c3decb0528a3b
diff --git a/hal/lib/Shared/FRC_NetworkCommunication/FRCComm.h b/hal/lib/Shared/FRC_NetworkCommunication/FRCComm.h
new file mode 100644
index 0000000..54c9463
--- /dev/null
+++ b/hal/lib/Shared/FRC_NetworkCommunication/FRCComm.h
@@ -0,0 +1,111 @@
+/*************************************************************

+ * 					NOTICE

+ *

+ * 	These are the only externally exposed functions to the

+ *   NetworkCommunication library

+ *

+ * This is an implementation of FRC Spec for Comm Protocol

+ * Revision 4.5, June 30, 2008

+ *

+ * Copyright (c) National Instruments 2008.  All Rights Reserved.

+ *

+ *************************************************************/

+

+//This file must compile on ALL PLATFORMS. Be very careful what you put in here.

+

+#ifndef __FRC_COMM_H__

+#define __FRC_COMM_H__

+

+#ifdef _WIN32

+	#ifdef USE_THRIFT

+		#define EXPORT_FUNC

+	#else

+		#define EXPORT_FUNC __declspec(dllexport) __cdecl

+	#endif

+#else

+	#include <stdint.h>

+	#include <pthread.h>

+	#define EXPORT_FUNC

+#endif

+

+#define ERR_FRCSystem_NetCommNotResponding -44049

+#define ERR_FRCSystem_NoDSConnection -44018

+

+enum AllianceStationID_t {

+	kAllianceStationID_red1,

+	kAllianceStationID_red2,

+	kAllianceStationID_red3,

+	kAllianceStationID_blue1,

+	kAllianceStationID_blue2,

+	kAllianceStationID_blue3,

+};

+

+enum MatchType_t {

+	kMatchType_none,

+	kMatchType_practice,

+	kMatchType_qualification,

+	kMatchType_elimination,

+};

+

+struct ControlWord_t {

+	uint32_t enabled : 1;

+	uint32_t autonomous : 1;

+	uint32_t test :1;

+	uint32_t eStop : 1;

+	uint32_t fmsAttached:1;

+	uint32_t dsAttached:1;

+	uint32_t control_reserved : 26;

+};

+

+struct JoystickAxes_t {

+	uint16_t count;

+	int16_t axes[1];

+};

+

+struct JoystickPOV_t {

+	uint16_t count;

+	int16_t povs[1];

+};

+

+#ifdef __cplusplus

+extern "C" {

+#endif

+	int EXPORT_FUNC FRC_NetworkCommunication_Reserve(void *instance);

+#ifndef SIMULATION

+	void EXPORT_FUNC getFPGAHardwareVersion(uint16_t *fpgaVersion, uint32_t *fpgaRevision);

+#endif

+	int EXPORT_FUNC setStatusData(float battery, uint8_t dsDigitalOut, uint8_t updateNumber,

+			const char *userDataHigh, int userDataHighLength,

+			const char *userDataLow, int userDataLowLength, int wait_ms);

+	int EXPORT_FUNC setErrorData(const char *errors, int errorsLength, int wait_ms);

+

+#ifdef SIMULATION

+	void EXPORT_FUNC setNewDataSem(HANDLE);

+#else

+	void EXPORT_FUNC setNewDataSem(pthread_cond_t *);

+#endif

+

+	// this uint32_t is really a LVRefNum

+	int EXPORT_FUNC setNewDataOccurRef(uint32_t refnum);

+

+	int EXPORT_FUNC FRC_NetworkCommunication_getControlWord(struct ControlWord_t *controlWord);

+	int EXPORT_FUNC FRC_NetworkCommunication_getAllianceStation(enum AllianceStationID_t *allianceStation);

+	int EXPORT_FUNC FRC_NetworkCommunication_getMatchTime(float *matchTime);

+	int EXPORT_FUNC FRC_NetworkCommunication_getJoystickAxes(uint8_t joystickNum, struct JoystickAxes_t *axes, uint8_t maxAxes);

+	int EXPORT_FUNC FRC_NetworkCommunication_getJoystickButtons(uint8_t joystickNum, uint32_t *buttons, uint8_t *count);

+	int EXPORT_FUNC FRC_NetworkCommunication_getJoystickPOVs(uint8_t joystickNum, struct JoystickPOV_t *povs, uint8_t maxPOVs);

+	int EXPORT_FUNC FRC_NetworkCommunication_setJoystickOutputs(uint8_t joystickNum, uint32_t hidOutputs, uint16_t leftRumble, uint16_t rightRumble);

+	int EXPORT_FUNC FRC_NetworkCommunication_getJoystickDesc(uint8_t joystickNum, uint8_t *isXBox, uint8_t *type, char *name,

+		uint8_t *axisCount, uint8_t *axisTypes, uint8_t *buttonCount, uint8_t *povCount);

+

+	void EXPORT_FUNC FRC_NetworkCommunication_getVersionString(char *version);

+	int EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramStarting(void);

+	void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramDisabled(void);

+	void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramAutonomous(void);

+	void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTeleop(void);

+	void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTest(void);

+#ifdef __cplusplus

+}

+#endif

+

+#endif

diff --git a/hal/lib/Shared/HAL.cpp b/hal/lib/Shared/HAL.cpp
new file mode 100644
index 0000000..9781278
--- /dev/null
+++ b/hal/lib/Shared/HAL.cpp
@@ -0,0 +1,128 @@
+//This file must compile on ALL PLATFORMS. Be very careful what you put in here.
+#include "HAL/HAL.hpp"
+#include "FRC_NetworkCommunication/FRCComm.h"
+#include <cstring>
+
+int HALGetControlWord(HALControlWord *data)
+{
+	return FRC_NetworkCommunication_getControlWord((ControlWord_t*) data);
+}
+
+void HALSetNewDataSem(MULTIWAIT_ID sem)
+{
+	setNewDataSem(sem->native_handle());
+}
+
+int HALGetAllianceStation(enum HALAllianceStationID *allianceStation)
+{
+	return FRC_NetworkCommunication_getAllianceStation((AllianceStationID_t*) allianceStation);
+}
+
+int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes *axes)
+{
+	return FRC_NetworkCommunication_getJoystickAxes(joystickNum, (JoystickAxes_t*) axes, kMaxJoystickAxes);
+}
+
+int HALGetJoystickPOVs(uint8_t joystickNum, HALJoystickPOVs *povs)
+{
+	return FRC_NetworkCommunication_getJoystickPOVs(joystickNum, (JoystickPOV_t*) povs, kMaxJoystickPOVs);
+}
+
+int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons *buttons)
+{
+	return FRC_NetworkCommunication_getJoystickButtons(joystickNum, &buttons->buttons, &buttons->count);
+}
+
+int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor *desc)
+{
+	return FRC_NetworkCommunication_getJoystickDesc(joystickNum, &desc->isXbox, &desc->type, (char *)(&desc->name),
+		&desc->axisCount, (uint8_t *)&desc->axisTypes, &desc->buttonCount, &desc->povCount);
+}
+
+int HALGetJoystickIsXbox(uint8_t joystickNum)
+{
+	HALJoystickDescriptor joystickDesc;
+	if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0)
+	{
+		return 0;
+	}else
+	{
+	return joystickDesc.isXbox;
+	}
+}
+
+int HALGetJoystickType(uint8_t joystickNum)
+{
+	HALJoystickDescriptor joystickDesc;
+	if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0)
+	{
+		return -1;
+	} else
+	{
+	return joystickDesc.type;
+	}
+}
+
+char* HALGetJoystickName(uint8_t joystickNum)
+{
+	HALJoystickDescriptor joystickDesc;
+	if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0)
+	{
+		char* name = (char*)std::malloc(1);
+		name[0] = '\0';
+		return name;
+	} else
+	{
+		size_t len = std::strlen(joystickDesc.name);
+		char* name = (char*)std::malloc(len+1);
+		std::strcpy(name, joystickDesc.name);
+		return name;
+	}
+}
+
+int HALGetJoystickAxisType(uint8_t joystickNum, uint8_t axis)
+{
+	HALJoystickDescriptor joystickDesc;
+	if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0)
+	{
+		return -1;
+	} else
+	{
+	return joystickDesc.axisTypes[axis];
+	}
+}
+
+int HALSetJoystickOutputs(uint8_t joystickNum, uint32_t outputs, uint16_t leftRumble, uint16_t rightRumble)
+{
+	return FRC_NetworkCommunication_setJoystickOutputs(joystickNum, outputs, leftRumble, rightRumble);
+}
+
+int HALGetMatchTime(float *matchTime)
+{
+	return FRC_NetworkCommunication_getMatchTime(matchTime);
+}
+
+void HALNetworkCommunicationObserveUserProgramStarting(void)
+{
+	FRC_NetworkCommunication_observeUserProgramStarting();
+}
+
+void HALNetworkCommunicationObserveUserProgramDisabled(void)
+{
+	FRC_NetworkCommunication_observeUserProgramDisabled();
+}
+
+void HALNetworkCommunicationObserveUserProgramAutonomous(void)
+{
+	FRC_NetworkCommunication_observeUserProgramAutonomous();
+}
+
+void HALNetworkCommunicationObserveUserProgramTeleop(void)
+{
+	FRC_NetworkCommunication_observeUserProgramTeleop();
+}
+
+void HALNetworkCommunicationObserveUserProgramTest(void)
+{
+	FRC_NetworkCommunication_observeUserProgramTest();
+}