JNI for java

Normal vs recursive mutex
HAL delineation
This commit is contained in:
charris
2014-01-06 10:12:21 -05:00
parent b62b606110
commit f7146d4230
134 changed files with 2377 additions and 3358 deletions

View File

@@ -18,16 +18,16 @@
</properties>
<repositories>
<repository>
<!-- repository>
<id>sonatype</id>
<name>Sonatype OSS Snapshots Repository</name>
<url>http://oss.sonatype.org/content/groups/public</url>
</repository>
</repository-->
<!-- For old snapshots, please use groupId `com.jnaerator` and the following repo -->
<repository>
<!-- repository>
<id>nativelibs4java-repo</id>
<url>http://nativelibs4java.sourceforge.net/maven</url>
</repository>
</repository-->
<repository>
<id>WPILib Repository</id>
@@ -92,28 +92,28 @@
<outputDirectory>${java-zip}/lib</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>WPILibJ</artifactId>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaFinal</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>jar</type>
<destFileName>WPILib.jar</destFileName>
<outputDirectory>${java-zip}/lib</outputDirectory>
</artifactItem>
<artifactItem>
<!-- artifactItem>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.0.0</version>
<type>jar</type>
<outputDirectory>${java-zip}/lib</outputDirectory>
</artifactItem>
<artifactItem>
</artifactItem-->
<!-- artifactItem>
<groupId>com.nativelibs4java</groupId>
<artifactId>jnaerator-runtime</artifactId>
<version>0.12-SNAPSHOT</version>
<type>jar</type>
<destFileName>jnaerator-runtime.jar</destFileName>
<outputDirectory>${java-zip}/lib</outputDirectory>
</artifactItem>
</artifactItem-->
<!-- Library sources for debugging WPILib on the Athena -->
<artifactItem>
<groupId>edu.wpi.first.wpilib.networktables.java</groupId>
@@ -124,8 +124,8 @@
<destFileName>NetworkTables-sources.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>WPILibJ</artifactId>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
<classifier>sources</classifier>
<outputDirectory>${java-zip}/lib</outputDirectory>
@@ -134,8 +134,8 @@
<!-- Javadoc -->
<artifactItem>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>WPILibJ</artifactId>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>javadoc</type>
<outputDirectory>${java-zip}/javadoc-jar</outputDirectory>
@@ -230,23 +230,23 @@
<type>jar</type>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>WPILibJ</artifactId>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJavaFinal</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<!-- dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.0.0</version>
<type>jar</type>
</dependency>
<dependency>
</dependency-->
<!-- dependency>
<groupId>com.nativelibs4java</groupId>
<artifactId>jnaerator-runtime</artifactId>
<version>0.12-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependency-->
<!-- Library sources for debugging WPILib on the Athena -->
<dependency>
@@ -256,16 +256,16 @@
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>WPILibJ</artifactId>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
<classifier>sources</classifier>
</dependency>
<!-- Javadoc -->
<dependency>
<groupId>edu.wpi.first.wpilib</groupId>
<artifactId>WPILibJ</artifactId>
<groupId>edu.wpi.first.wpilibj</groupId>
<artifactId>wpilibJava</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>javadoc</type>
</dependency>

View File

@@ -12,9 +12,10 @@ wpilib.jar=${wpilib.lib}/WPILib.jar
wpilib.sources=${wpilib.lib}/WPILib-sources.jar
networktables.jar=${wpilib.lib}/NetworkTables.jar
networktables.sources=${wpilib.lib}/NetworkTables-sources.jar
jna.jar=${wpilib.lib}/jna-4.0.0.jar
jnaerator.jar=${wpilib.lib}/jnaerator-runtime.jar
classpath=${wpilib.jar}:${networktables.jar}:${jna.jar}:${jnaerator.jar}
#jna.jar=${wpilib.lib}/jna-4.0.0.jar
#jnaerator.jar=${wpilib.lib}/jnaerator-runtime.jar
#classpath=${wpilib.jar}:${networktables.jar}:${jna.jar}:${jnaerator.jar}
classpath=${wpilib.jar}:${networktables.jar}
# Ant support
wpilib.ant.dir=${wpilib}/ant

View File

@@ -24,7 +24,7 @@
</modules>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
<tycho-version>0.18.1</tycho-version>
</properties>

View File

@@ -10,6 +10,7 @@
<groupId>edu.wpi.first.wpilib.templates.athena</groupId>
<artifactId>static-library</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../maven-utilities/athena/static-library</relativePath>
</parent>
<repositories>

View File

@@ -44,7 +44,7 @@ bool analogSystemInitialized = false;
*/
void initializeAnalog(int32_t *status) {
if (analogSystemInitialized) return;
analogRegisterWindowSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
analogRegisterWindowSemaphore = initializeMutexRecursive();
analogSystem = tAI::create(status);
setAnalogNumChannelsToActivate(kAnalogPins);
setAnalogSampleRate(kDefaultSampleRate, status);

View File

@@ -67,15 +67,15 @@ void initializeDigital(int32_t *status) {
if (digitalSystemsInitialized) return;
// Create a semaphore to protect changes to the digital output values
digitalDIOSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
digitalDIOSemaphore = initializeMutexRecursive();
// Create a semaphore to protect changes to the relay values
digitalRelaySemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
digitalRelaySemaphore = initializeMutexRecursive();
// Create a semaphore to protect changes to the DO PWM config
digitalPwmSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
digitalPwmSemaphore = initializeMutexRecursive();
digitalI2CSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
digitalI2CSemaphore = initializeMutexRecursive();
Resource::CreateResourceObject(&DIOChannels, tDIO::kNumSystems * kDigitalPins);
Resource::CreateResourceObject(&DO_PWMGenerators, tDIO::kNumPWMDutyCycleElements);
@@ -420,9 +420,9 @@ bool allocateDIO(void* digital_port_pointer, bool input, int32_t *status) {
uint32_t bitToSet = 1 << (remapDigitalChannel(port->port.pin - 1, status));
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
if (input) {
outputEnable.value = outputEnable.value & (~bitToSet); // clear the bit for read
outputEnable.Headers = outputEnable.Headers & (~bitToSet); // clear the bit for read
} else {
outputEnable.value = outputEnable.value | bitToSet; // set the bit for write
outputEnable.Headers = outputEnable.Headers | bitToSet; // set the bit for write
}
digitalSystem->writeOutputEnable(outputEnable, status);
}
@@ -497,7 +497,7 @@ bool getDIODirection(void* digital_port_pointer, int32_t *status) {
//AND it against the currentOutputEnable
//if it == 0, then return false
//else return true
return ((currentOutputEnable.value >> remapDigitalChannel(port->port.pin - 1, status)) & 1) != 0;
return ((currentOutputEnable.Headers >> remapDigitalChannel(port->port.pin - 1, status)) & 1) != 0;
}
/**
@@ -510,7 +510,7 @@ bool getDIODirection(void* digital_port_pointer, int32_t *status) {
void pulse(void* digital_port_pointer, double pulseLength, int32_t *status) {
DigitalPort* port = (DigitalPort*) digital_port_pointer;
tDIO::tPulse pulse;
pulse.value = 1 << remapDigitalChannel(port->port.pin - 1, status);
pulse.Headers = 1 << remapDigitalChannel(port->port.pin - 1, status);
digitalSystem->writePulseLength((uint8_t)(1.0e9 * pulseLength / (pwmSystem->readLoopTiming(status) * 25)), status);
digitalSystem->writePulse(pulse, status);
}
@@ -524,7 +524,7 @@ bool isPulsing(void* digital_port_pointer, int32_t *status) {
DigitalPort* port = (DigitalPort*) digital_port_pointer;
uint16_t mask = 1 << remapDigitalChannel(port->port.pin - 1, status);
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
return (pulseRegister.value & mask) != 0;
return (pulseRegister.Headers & mask) != 0;
}
/**
@@ -543,7 +543,7 @@ bool isAnyPulsing(int32_t *status) {
*/
bool isAnyPulsingWithModule(uint8_t module, int32_t *status) {
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
return pulseRegister.value != 0;
return pulseRegister.Headers != 0;
}

View File

@@ -4,6 +4,8 @@
#include "Port.h"
#include "HAL/Errors.h"
#include "ChipObject.h"
#include "NetworkCommunication/FRCComm.h"
#include "NetworkCommunication/UsageReporting.h"
// XXX: What to do with solenoids? const uint32_t solenoid_kNumDO7_0Elements = tSolenoid::kNumDO7_0Elements;
const uint32_t dio_kNumSystems = tDIO::kNumSystems;
@@ -107,6 +109,80 @@ int32_t getFPGALED(int32_t *status) {
return 0; // XXX: Dummy value
}
int HALSetErrorData(const char *errors, int errorsLength, int wait_ms)
{
return setErrorData(errors, errorsLength, wait_ms);
}
int HALSetUserDsLcdData(const char *userDsLcdData, int userDsLcdDataLength, int wait_ms)
{
return setUserDsLcdData(userDsLcdData, userDsLcdDataLength, wait_ms);
}
int HALOverrideIOConfig(const char *ioConfig, int wait_ms)
{
return overrideIOConfig(ioConfig, wait_ms);
}
int HALGetDynamicControlData(uint8_t type, char *dynamicData, int32_t maxLength, int wait_ms)
{
return getDynamicControlData( type, dynamicData, maxLength, wait_ms);
}
int HALGetCommonControlData(HALCommonControlData *data, int wait_ms)
{
return getCommonControlData( (FRCCommonControlData*)data, wait_ms );
}
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);
}
void HALNetworkCommunicationReserve()
{
FRC_NetworkCommunication_Reserve();
}
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();
}
uint32_t HALReport(uint8_t resource, uint8_t instanceNumber, uint8_t context, const char *feature)
{
return FRC_NetworkCommunication_nUsageReporting_report( resource, instanceNumber, context, feature);
}
// TODO: HACKS
void NumericArrayResize() {}
void RTSetCleanupProc() {}

View File

@@ -188,6 +188,8 @@ extern "C" {
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramAutonomous(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTeleop(void);
void EXPORT_FUNC FRC_NetworkCommunication_observeUserProgramTest(void);
void EXPORT_FUNC FRC_NetworkCommunication_Reserve();
};
#endif

View File

@@ -2,6 +2,14 @@
#include "HAL/Semaphore.h"
#include "ChipObject.h"
#include "Log.h"
// set the logging level
TLogLevel semaphoreLogLevel = logDEBUG;
#define SEMAPHORE_LOG(level) \
if (level > semaphoreLogLevel) ; \
else Log().Get(level)
// See: http://www.vxdev.com/docs/vx55man/vxworks/ref/semMLib.html
const uint32_t SEMAPHORE_Q_FIFO= 0x01; // TODO: Support
@@ -15,7 +23,8 @@ const int32_t SEMAPHORE_WAIT_FOREVER = -1;
const uint32_t SEMAPHORE_EMPTY = 0;
const uint32_t SEMAPHORE_FULL = 1;
MUTEX_ID initializeMutex(uint32_t flags) {
MUTEX_ID initializeMutexRecursive()
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
@@ -25,38 +34,47 @@ MUTEX_ID initializeMutex(uint32_t flags) {
return sem;
}
void deleteMutex(MUTEX_ID sem) {
pthread_mutex_destroy(sem);
delete sem;
MUTEX_ID initializeMutexNormal()
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
MUTEX_ID sem = new pthread_mutex_t();
pthread_mutex_init(sem, &attr);
pthread_mutexattr_destroy(&attr);
return sem;
}
void deleteMutex(MUTEX_ID sem)
{
pthread_mutex_destroy(sem);
delete sem;
}
/**
* Lock the semaphore, blocking until it's available.
* @return 0 for success, -1 for error. If -1, the error will be in errno.
*/
int8_t takeMutex(MUTEX_ID sem, int32_t timeout) {
if (timeout == SEMAPHORE_NO_WAIT) {
return pthread_mutex_trylock(sem);
} else if (timeout == SEMAPHORE_WAIT_FOREVER) {
int8_t takeMutex(MUTEX_ID sem)
{
return pthread_mutex_lock(sem);
} else {
// struct timespec test;
// return pthread_mutex_timedlock(sem, );
return -1; // TODO: implement timed wait
}
}
int8_t tryTakeMutex(MUTEX_ID sem)
{
return pthread_mutex_trylock(sem);
}
/**
* Unlock the semaphore.
* @return 0 for success, -1 for error. If -1, the error will be in errno.
*/
int8_t giveMutex(MUTEX_ID sem) {
// return semGive(sem);
// return sem_post(sem);
return pthread_mutex_unlock(sem);
int8_t giveMutex(MUTEX_ID sem)
{
return pthread_mutex_unlock(sem);
}
SEMAPHORE_ID initializeSemaphore(uint32_t flags, uint32_t initial_value) {
SEMAPHORE_ID initializeSemaphore(uint32_t initial_value) {
SEMAPHORE_ID sem = new sem_t;
sem_init(sem, 0, initial_value);
return sem;
@@ -71,22 +89,22 @@ void deleteSemaphore(SEMAPHORE_ID sem) {
* Lock the semaphore, blocking until it's available.
* @return 0 for success, -1 for error. If -1, the error will be in errno.
*/
int8_t takeSemaphore(SEMAPHORE_ID sem, int32_t timeout) {
if (timeout == SEMAPHORE_NO_WAIT) {
return sem_trywait(sem);
} else if (timeout == SEMAPHORE_WAIT_FOREVER) {
int8_t takeSemaphore(SEMAPHORE_ID sem)
{
return sem_wait(sem);
} else {
// return sem_timedwait(sem, );
return -1; // TODO: implement timed wait
}
}
int8_t tryTakeSemaphore(SEMAPHORE_ID sem)
{
return sem_trywait(sem);
}
/**
* Unlock the semaphore.
* @return 0 for success, -1 for error. If -1, the error will be in errno.
*/
int8_t giveSemaphore(SEMAPHORE_ID sem) {
int8_t giveSemaphore(SEMAPHORE_ID sem)
{
return sem_post(sem);
}
@@ -106,8 +124,8 @@ void deleteMultiWait(MULTIWAIT_ID sem) {
}
int8_t takeMultiWait(MULTIWAIT_ID sem, int32_t timeout) {
MUTEX_ID m = initializeMutex(NULL);
takeMutex(m, SEMAPHORE_WAIT_FOREVER);
MUTEX_ID m = initializeMutexNormal();
takeMutex(m);
int8_t val = pthread_cond_wait(sem, m);
deleteMutex(m);
return val;

View File

@@ -19,21 +19,21 @@ Synchronized::Synchronized(MUTEX_ID semaphore)
{
m_mutex = semaphore;
m_semaphore = NULL;
takeMutex(m_mutex, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_mutex);
}
Synchronized::Synchronized(SEMAPHORE_ID semaphore)
{
m_mutex = NULL;
m_semaphore = semaphore;
takeSemaphore(m_semaphore, SEMAPHORE_WAIT_FOREVER);
takeSemaphore(m_semaphore);
}
Synchronized::Synchronized(ReentrantSemaphore& semaphore)
{
m_mutex = semaphore.m_semaphore;
m_semaphore = NULL;
takeMutex(m_mutex, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_mutex);
}
/**

View File

@@ -10,6 +10,7 @@
<groupId>edu.wpi.first.wpilib.templates.azalea</groupId>
<artifactId>static-library</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../maven-utilities/azalea/static-library</relativePath>
</parent>
<repositories>

View File

@@ -10,6 +10,7 @@
<groupId>edu.wpi.first.wpilib.templates</groupId>
<artifactId>include</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../maven-utilities/include</relativePath>
</parent>
<repositories>

View File

@@ -25,6 +25,223 @@
#ifndef HAL_H
#define HAL_H
#define HAL_IO_CONFIG_DATA_SIZE 32
#define HAL_SYS_STATUS_DATA_SIZE 44
#define HAL_USER_STATUS_DATA_SIZE (984 - HAL_IO_CONFIG_DATA_SIZE - HAL_SYS_STATUS_DATA_SIZE)
#define HAL_USER_DS_LCD_DATA_SIZE 128
#define HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input 17
#define HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output 18
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Header 19
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Extra1 20
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Vertices1 21
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Extra2 22
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Vertices2 23
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Joystick 24
#define HALFRC_NetworkCommunication_DynamicType_Kinect_Custom 25
namespace HALUsageReporting
{
typedef enum
{
kResourceType_Controller,
kResourceType_Module,
kResourceType_Language,
kResourceType_CANPlugin,
kResourceType_Accelerometer,
kResourceType_ADXL345,
kResourceType_AnalogChannel,
kResourceType_AnalogTrigger,
kResourceType_AnalogTriggerOutput,
kResourceType_CANJaguar,
kResourceType_Compressor,
kResourceType_Counter,
kResourceType_Dashboard,
kResourceType_DigitalInput,
kResourceType_DigitalOutput,
kResourceType_DriverStationCIO,
kResourceType_DriverStationEIO,
kResourceType_DriverStationLCD,
kResourceType_Encoder,
kResourceType_GearTooth,
kResourceType_Gyro,
kResourceType_I2C,
kResourceType_Framework,
kResourceType_Jaguar,
kResourceType_Joystick,
kResourceType_Kinect,
kResourceType_KinectStick,
kResourceType_PIDController,
kResourceType_Preferences,
kResourceType_PWM,
kResourceType_Relay,
kResourceType_RobotDrive,
kResourceType_SerialPort,
kResourceType_Servo,
kResourceType_Solenoid,
kResourceType_SPI,
kResourceType_Task,
kResourceType_Ultrasonic,
kResourceType_Victor,
kResourceType_Button,
kResourceType_Command,
kResourceType_AxisCamera,
kResourceType_PCVideoServer,
kResourceType_SmartDashboard,
kResourceType_Talon,
kResourceType_HiTechnicColorSensor,
kResourceType_HiTechnicAccel,
kResourceType_HiTechnicCompass,
kResourceType_SRF08,
} tResourceType;
typedef enum
{
kLanguage_LabVIEW = 1,
kLanguage_CPlusPlus = 2,
kLanguage_Java = 3,
kLanguage_Python = 4,
kCANPlugin_BlackJagBridge = 1,
kCANPlugin_2CAN = 2,
kFramework_Iterative = 1,
kFramework_Simple = 2,
kRobotDrive_ArcadeStandard = 1,
kRobotDrive_ArcadeButtonSpin = 2,
kRobotDrive_ArcadeRatioCurve = 3,
kRobotDrive_Tank = 4,
kRobotDrive_MecanumPolar = 5,
kRobotDrive_MecanumCartesian = 6,
kDriverStationCIO_Analog = 1,
kDriverStationCIO_DigitalIn = 2,
kDriverStationCIO_DigitalOut = 3,
kDriverStationEIO_Acceleration = 1,
kDriverStationEIO_AnalogIn = 2,
kDriverStationEIO_AnalogOut = 3,
kDriverStationEIO_Button = 4,
kDriverStationEIO_LED = 5,
kDriverStationEIO_DigitalIn = 6,
kDriverStationEIO_DigitalOut = 7,
kDriverStationEIO_FixedDigitalOut = 8,
kDriverStationEIO_PWM = 9,
kDriverStationEIO_Encoder = 10,
kDriverStationEIO_TouchSlider = 11,
kADXL345_SPI = 1,
kADXL345_I2C = 2,
kCommand_Scheduler = 1,
kSmartDashboard_Instance = 1,
} tInstances;
}
struct HALCommonControlData{
uint16_t packetIndex;
union {
uint8_t control;
#ifndef __vxworks
struct {
uint8_t checkVersions :1;
uint8_t test :1;
uint8_t resync : 1;
uint8_t fmsAttached:1;
uint8_t autonomous : 1;
uint8_t enabled : 1;
uint8_t notEStop : 1;
uint8_t reset : 1;
};
#else
struct {
uint8_t reset : 1;
uint8_t notEStop : 1;
uint8_t enabled : 1;
uint8_t autonomous : 1;
uint8_t fmsAttached:1;
uint8_t resync : 1;
uint8_t test :1;
uint8_t checkVersions :1;
};
#endif
};
uint8_t dsDigitalIn;
uint16_t teamID;
char dsID_Alliance;
char dsID_Position;
union {
int8_t stick0Axes[6];
struct {
int8_t stick0Axis1;
int8_t stick0Axis2;
int8_t stick0Axis3;
int8_t stick0Axis4;
int8_t stick0Axis5;
int8_t stick0Axis6;
};
};
uint16_t stick0Buttons; // Left-most 4 bits are unused
union {
int8_t stick1Axes[6];
struct {
int8_t stick1Axis1;
int8_t stick1Axis2;
int8_t stick1Axis3;
int8_t stick1Axis4;
int8_t stick1Axis5;
int8_t stick1Axis6;
};
};
uint16_t stick1Buttons; // Left-most 4 bits are unused
union {
int8_t stick2Axes[6];
struct {
int8_t stick2Axis1;
int8_t stick2Axis2;
int8_t stick2Axis3;
int8_t stick2Axis4;
int8_t stick2Axis5;
int8_t stick2Axis6;
};
};
uint16_t stick2Buttons; // Left-most 4 bits are unused
union {
int8_t stick3Axes[6];
struct {
int8_t stick3Axis1;
int8_t stick3Axis2;
int8_t stick3Axis3;
int8_t stick3Axis4;
int8_t stick3Axis5;
int8_t stick3Axis6;
};
};
uint16_t stick3Buttons; // Left-most 4 bits are unused
//Analog inputs are 10 bit right-justified
uint16_t analog1;
uint16_t analog2;
uint16_t analog3;
uint16_t analog4;
uint64_t cRIOChecksum;
uint32_t FPGAChecksum0;
uint32_t FPGAChecksum1;
uint32_t FPGAChecksum2;
uint32_t FPGAChecksum3;
char versionData[8];
};
inline float intToFloat(int value) {
return *(float*) &value;
@@ -50,11 +267,30 @@ extern "C" {
void setFPGALED(uint32_t state, int32_t *status);
int32_t getFPGALED(int32_t *status);
int HALSetErrorData(const char *errors, int errorsLength, int wait_ms);
int HALSetUserDsLcdData(const char *userDsLcdData, int userDsLcdDataLength, int wait_ms);
int HALOverrideIOConfig(const char *ioConfig, int wait_ms);
int HALGetDynamicControlData(uint8_t type, char *dynamicData, int32_t maxLength, int wait_ms);
int HALGetCommonControlData(HALCommonControlData *data, int wait_ms);
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);
void HALNetworkCommunicationReserve();
void HALNetworkCommunicationObserveUserProgramStarting(void);
void HALNetworkCommunicationObserveUserProgramDisabled(void);
void HALNetworkCommunicationObserveUserProgramAutonomous(void);
void HALNetworkCommunicationObserveUserProgramTeleop(void);
void HALNetworkCommunicationObserveUserProgramTest(void);
uint32_t HALReport(uint8_t resource, uint8_t instanceNumber, uint8_t context = 0, const char *feature = NULL);
}
// TODO: HACKS for now...
extern "C" {
void FRC_NetworkCommunication_Reserve();
//void FRC_NetworkCommunication_Reserve();
void NumericArrayResize();
void RTSetCleanupProc();

View File

@@ -32,14 +32,17 @@ extern "C" {
extern const uint32_t SEMAPHORE_EMPTY;
extern const uint32_t SEMAPHORE_FULL;
MUTEX_ID initializeMutex(uint32_t flags);
MUTEX_ID initializeMutexRecursive();
MUTEX_ID initializeMutexNormal();
void deleteMutex(MUTEX_ID sem);
int8_t takeMutex(MUTEX_ID sem, int32_t timeout);
int8_t takeMutex(MUTEX_ID sem);
int8_t tryTakeMutex(MUTEX_ID sem);
int8_t giveMutex(MUTEX_ID sem);
SEMAPHORE_ID initializeSemaphore(uint32_t flags, uint32_t initial_value);
SEMAPHORE_ID initializeSemaphore(uint32_t initial_value);
void deleteSemaphore(SEMAPHORE_ID sem);
int8_t takeSemaphore(SEMAPHORE_ID sem, int32_t timeout);
int8_t takeSemaphore(SEMAPHORE_ID sem);
int8_t tryTakeSemaphore(SEMAPHORE_ID sem);
int8_t giveSemaphore(SEMAPHORE_ID sem);
MULTIWAIT_ID initializeMultiWait();

View File

@@ -36,7 +36,7 @@ class ReentrantSemaphore
{
public:
explicit ReentrantSemaphore() {
m_semaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE);
m_semaphore = initializeMutexRecursive();
}
~ReentrantSemaphore() {
deleteMutex(m_semaphore);
@@ -47,7 +47,7 @@ public:
* @return 0 for success, -1 for error. If -1, the error will be in errno.
*/
int take() {
return takeMutex(m_semaphore, SEMAPHORE_WAIT_FOREVER);
return takeMutex(m_semaphore);
}
/**

View File

@@ -11,10 +11,6 @@
<module>include</module>
</modules>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
</properties>
<profiles>
<profile>
<id>jenkins</id>
@@ -32,9 +28,6 @@
</activation>
<modules>
<module>Athena</module>
<module>AthenaJava</module>
<module>AthenaXX</module>
<module>AthenaXXJava</module>
</modules>
</profile>
<profile>

View File

@@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<build>

View File

@@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<build>

View File

@@ -15,7 +15,7 @@
</modules>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<build>

View File

@@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<build>

View File

@@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<build>

View File

@@ -14,7 +14,7 @@
</modules>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -10,6 +10,7 @@
<groupId>edu.wpi.first.wpilib.templates.athena</groupId>
<artifactId>static-library</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../maven-utilities/athena/static-library</relativePath>
</parent>
<repositories>

View File

@@ -38,7 +38,7 @@
</build>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -12,7 +12,7 @@
</modules>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -10,6 +10,7 @@
<groupId>edu.wpi.first.wpilib.templates.athena</groupId>
<artifactId>library-jar</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../../maven-utilities/athena/library-jar</relativePath>
</parent>
<repositories>
@@ -56,6 +57,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>

View File

@@ -11,6 +11,7 @@
<groupId>edu.wpi.first.wpilib.templates.azalea</groupId>
<artifactId>library-jar</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>../../../maven-utilities/azalea/library-jar</relativePath>
</parent>
<repositories>
@@ -41,6 +42,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>

View File

@@ -158,7 +158,7 @@
</dependencies>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -8,7 +8,7 @@
<version>0.1.0-SNAPSHOT</version>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -13,7 +13,7 @@
</modules>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<build>

View File

@@ -21,7 +21,7 @@
</modules>
<properties>
<local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository>
<!-- local-repository>C:/Users/wpilibj-buildmaster/maven-repository</local-repository-->
</properties>
<profiles>
<profile>

View File

@@ -8,7 +8,7 @@
#define __DASHBOARD_H__
#include "DashboardBase.h"
#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/FRCComm.h"
#include <stack>
#include <vector>
#include "HAL/HAL.h"
@@ -50,7 +50,7 @@ public:
void GetStatusBuffer(char** userStatusData, int32_t* userStatusDataSize);
void Flush() {}
private:
static const int32_t kMaxDashboardDataSize = USER_STATUS_DATA_SIZE - sizeof(uint32_t) * 3 - sizeof(uint8_t); // 13 bytes needed for 3 size parameters and the sequence number
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);

View File

@@ -12,7 +12,7 @@
#include "SensorBase.h"
#include "Task.h"
struct FRCCommonControlData;
struct HALCommonControlData;
class AnalogChannel;
/**
@@ -109,7 +109,7 @@ private:
void Run();
struct FRCCommonControlData *m_controlData;
struct HALCommonControlData *m_controlData;
uint8_t m_digitalOut;
AnalogChannel *m_batteryChannel;
MUTEX_ID m_statusDataSemaphore;

View File

@@ -8,7 +8,7 @@
#define __DRIVER_STATION_ENHANCED_IO_H__
#include "ErrorBase.h"
#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/FRCComm.h"
#include <stack>
#include <vector>
#include "HAL/HAL.h"
@@ -91,8 +91,8 @@ class DriverStationEnhancedIO : public ErrorBase
enum tBlockID
{
kInputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input,
kOutputBlockID = kFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output,
kInputBlockID = HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Input,
kOutputBlockID = HALFRC_NetworkCommunication_DynamicType_DSEnhancedIO_Output,
};
enum tStatusFlags {kStatusValid = 0x01, kStatusConfigChanged = 0x02, kForceEnhancedMode = 0x04};

View File

@@ -33,7 +33,7 @@ class DriverStation;
#define START_ROBOT_CLASS(_ClassName_) \
int main() \
{ \
FRC_NetworkCommunication_Reserve(); \
HALNetworkCommunicationReserve(); \
RobotBase* robot = new _ClassName_(); \
robot->StartCompetition(); \
return 0; \

View File

@@ -7,7 +7,7 @@
#include "ADXL345_SPI.h"
#include "DigitalInput.h"
#include "DigitalOutput.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "SPI.h"
const uint8_t ADXL345_SPI::kPowerCtlRegister;
@@ -109,7 +109,7 @@ void ADXL345_SPI::Init(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *mi
m_spi->SetBitsPerWord(24);
m_spi->ApplyConfig();
nUsageReporting::report(nUsageReporting::kResourceType_ADXL345, nUsageReporting::kADXL345_SPI);
HALReport(HALUsageReporting::kResourceType_ADXL345, HALUsageReporting::kADXL345_SPI);
}
}

View File

@@ -6,7 +6,7 @@
#include "Accelerometer.h"
#include "AnalogModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -18,7 +18,7 @@ void Accelerometer::InitAccelerometer()
m_table = NULL;
m_voltsPerG = 1.0;
m_zeroGVoltage = 2.5;
nUsageReporting::report(nUsageReporting::kResourceType_Accelerometer, m_analogChannel->GetChannel(), m_analogChannel->GetModuleNumber() - 1);
HALReport(HALUsageReporting::kResourceType_Accelerometer, m_analogChannel->GetChannel(), m_analogChannel->GetModuleNumber() - 1);
LiveWindow::GetInstance()->AddSensor("Accelerometer", m_analogChannel->GetModuleNumber(), m_analogChannel->GetChannel(), this);
}

View File

@@ -6,7 +6,7 @@
#include "AnalogChannel.h"
#include "AnalogModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -53,7 +53,7 @@ void AnalogChannel::InitChannel(uint8_t moduleNumber, uint32_t channel)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
LiveWindow::GetInstance()->AddSensor("AnalogChannel",channel, GetModuleNumber(), this);
nUsageReporting::report(nUsageReporting::kResourceType_AnalogChannel, channel, GetModuleNumber() - 1);
HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel, GetModuleNumber() - 1);
}
/**

View File

@@ -8,7 +8,7 @@
#include "AnalogChannel.h"
#include "AnalogModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "WPIErrors.h"
@@ -25,7 +25,7 @@ void AnalogTrigger::InitTrigger(uint8_t moduleNumber, uint32_t channel)
wpi_setErrorWithContext(status, getHALErrorMessage(status));
m_index = index;
nUsageReporting::report(nUsageReporting::kResourceType_AnalogTrigger, channel, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_AnalogTrigger, channel, moduleNumber - 1);
}
/**

View File

@@ -6,7 +6,7 @@
#include "AnalogTriggerOutput.h"
#include "AnalogTrigger.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
/**
@@ -22,7 +22,7 @@ AnalogTriggerOutput::AnalogTriggerOutput(AnalogTrigger *trigger, AnalogTriggerTy
: m_trigger (trigger)
, m_outputType (outputType)
{
nUsageReporting::report(nUsageReporting::kResourceType_AnalogTriggerOutput, trigger->GetIndex(), outputType);
HALReport(HALUsageReporting::kResourceType_AnalogTriggerOutput, trigger->GetIndex(), outputType);
}
AnalogTriggerOutput::~AnalogTriggerOutput()

View File

@@ -6,9 +6,9 @@
#include "CANJaguar.h"
#define tNIRIO_i32 int
#include "CAN/JaguarCANDriver.h"
//#include "CAN/JaguarCANDriver.h"
#include "CAN/can_proto.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include <stdio.h>
#include "LiveWindow/LiveWindow.h"
@@ -31,7 +31,7 @@ constexpr double CANJaguar::kApproxBusVoltage;
void CANJaguar::InitCANJaguar()
{
m_table = NULL;
m_transactionSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_INVERSION_SAFE | SEMAPHORE_DELETE_SAFE);
m_transactionSemaphore = initializeMutexNormal();
if (m_deviceNumber < 1 || m_deviceNumber > 63)
{
char buf[256];
@@ -69,7 +69,7 @@ void CANJaguar::InitCANJaguar()
}
m_safetyHelper = new MotorSafetyHelper(this);
nUsageReporting::report(nUsageReporting::kResourceType_CANJaguar, m_deviceNumber, m_controlMode);
HALReport(HALUsageReporting::kResourceType_CANJaguar, m_deviceNumber, m_controlMode);
LiveWindow::GetInstance()->AddActuator("CANJaguar", m_deviceNumber, 0, this);
}
@@ -405,7 +405,7 @@ void CANJaguar::setTransaction(uint32_t messageID, const uint8_t *data, uint8_t
return;
// Make sure we don't have more than one transaction with the same Jaguar outstanding.
takeMutex(m_transactionSemaphore, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_transactionSemaphore);
// Throw away any stale acks.
receiveMessage(&ackMessageID, NULL, 0, 0.0f);
@@ -444,7 +444,7 @@ void CANJaguar::getTransaction(uint32_t messageID, uint8_t *data, uint8_t *dataS
}
// Make sure we don't have more than one transaction with the same Jaguar outstanding.
takeMutex(m_transactionSemaphore, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_transactionSemaphore);
// Throw away any stale responses.
receiveMessage(&targetedMessageID, NULL, 0, 0.0f);
@@ -778,7 +778,7 @@ void CANJaguar::ChangeControlMode(ControlMode controlMode)
// Update the local mode
m_controlMode = controlMode;
nUsageReporting::report(nUsageReporting::kResourceType_CANJaguar, m_deviceNumber, m_controlMode);
HALReport(HALUsageReporting::kResourceType_CANJaguar, m_deviceNumber, m_controlMode);
}
/**

View File

@@ -8,7 +8,7 @@
#include "Buttons/ButtonScheduler.h"
#include "Commands/Subsystem.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
#include <iostream>
@@ -19,23 +19,21 @@ Scheduler *Scheduler::_instance = NULL;
Scheduler::Scheduler() :
m_buttonsLock(NULL), m_additionsLock(NULL), m_adding(false) {
m_buttonsLock = initializeMutex(
SEMAPHORE_Q_PRIORITY | SEMAPHORE_INVERSION_SAFE | SEMAPHORE_DELETE_SAFE);
m_additionsLock = initializeMutex(
SEMAPHORE_Q_PRIORITY | SEMAPHORE_INVERSION_SAFE | SEMAPHORE_DELETE_SAFE);
m_buttonsLock = initializeMutexNormal();
m_additionsLock = initializeMutexNormal();
nUsageReporting::report(nUsageReporting::kResourceType_Command,
nUsageReporting::kCommand_Scheduler);
HALReport(HALUsageReporting::kResourceType_Command,
HALUsageReporting::kCommand_Scheduler);
m_table = NULL;
m_enabled = true;
}
Scheduler::~Scheduler() {
takeMutex(m_additionsLock, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_additionsLock);
deleteMutex(m_additionsLock);
takeMutex(m_buttonsLock, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_buttonsLock);
deleteMutex(m_buttonsLock);
}

View File

@@ -6,7 +6,7 @@
#include "Compressor.h"
#include "DigitalInput.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Timer.h"
#include "WPIErrors.h"
@@ -52,7 +52,7 @@ void Compressor::InitCompressor(uint8_t pressureSwitchModuleNumber,
m_pressureSwitch = new DigitalInput(pressureSwitchModuleNumber, pressureSwitchChannel);
m_relay = new Relay(compresssorRelayModuleNumber, compressorRelayChannel, Relay::kForwardOnly);
nUsageReporting::report(nUsageReporting::kResourceType_Compressor, 0);
HALReport(HALUsageReporting::kResourceType_Compressor, 0);
if (!m_task.Start((int32_t)this))
{

View File

@@ -7,7 +7,7 @@
#include "Counter.h"
#include "AnalogTrigger.h"
#include "DigitalInput.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "WPIErrors.h"
@@ -29,7 +29,7 @@ void Counter::InitCounter(Mode mode)
m_allocatedUpSource = false;
m_allocatedDownSource = false;
nUsageReporting::report(nUsageReporting::kResourceType_Counter, index, mode);
HALReport(HALUsageReporting::kResourceType_Counter, index, mode);
}
/**

View File

@@ -6,7 +6,7 @@
#include "Dashboard.h"
#include "DriverStation.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
#include <string.h>
@@ -33,7 +33,7 @@ Dashboard::Dashboard(MUTEX_ID statusDataSem)
m_localPrintBuffer = new char[kMaxDashboardDataSize * 2];
m_localPrintBuffer[0] = 0;
m_packPtr = m_localBuffer;
m_printSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
m_printSemaphore = initializeMutexNormal();
}
/**
@@ -307,7 +307,7 @@ int32_t Dashboard::Finalize()
static bool reported = false;
if (!reported)
{
nUsageReporting::report(nUsageReporting::kResourceType_Dashboard, 0);
HALReport(HALUsageReporting::kResourceType_Dashboard, 0);
reported = true;
}

View File

@@ -6,7 +6,7 @@
#include "DigitalInput.h"
#include "DigitalModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "WPIErrors.h"
@@ -39,7 +39,7 @@ void DigitalInput::InitDigitalInput(uint8_t moduleNumber, uint32_t channel)
m_module = DigitalModule::GetInstance(moduleNumber);
m_module->AllocateDIO(channel, true);
nUsageReporting::report(nUsageReporting::kResourceType_DigitalInput, channel, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_DigitalInput, channel, moduleNumber - 1);
}
/**

View File

@@ -6,7 +6,7 @@
#include "DigitalOutput.h"
#include "DigitalModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "WPIErrors.h"
@@ -38,7 +38,7 @@ void DigitalOutput::InitDigitalOutput(uint8_t moduleNumber, uint32_t channel)
m_module = DigitalModule::GetInstance(moduleNumber);
m_module->AllocateDIO(m_channel, false);
nUsageReporting::report(nUsageReporting::kResourceType_DigitalOutput, channel, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_DigitalOutput, channel, moduleNumber - 1);
}
/**

View File

@@ -5,7 +5,7 @@
/*----------------------------------------------------------------------------*/
#include "DoubleSolenoid.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include <string.h>
#include "LiveWindow/LiveWindow.h"
@@ -52,8 +52,8 @@ void DoubleSolenoid::InitSolenoid()
m_forwardMask = 1 << (m_forwardChannel - 1);
m_reverseMask = 1 << (m_reverseChannel - 1);
nUsageReporting::report(nUsageReporting::kResourceType_Solenoid, m_forwardChannel, m_moduleNumber - 1);
nUsageReporting::report(nUsageReporting::kResourceType_Solenoid, m_reverseChannel, m_moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_Solenoid, m_forwardChannel, m_moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_Solenoid, m_reverseChannel, m_moduleNumber - 1);
LiveWindow::GetInstance()->AddActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
}

View File

@@ -8,12 +8,20 @@
#include "AnalogChannel.h"
#include "HAL/cpp/Synchronized.h"
#include "Timer.h"
#include "NetworkCommunication/FRCComm.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "MotorSafetyHelper.h"
#include "Utility.h"
#include "WPIErrors.h"
#include <string.h>
#include "Log.h"
// set the logging level
TLogLevel dsLogLevel = logDEBUG;
#define DS_LOG(level) \
if (level > dsLogLevel) ; \
else Log().Get(level)
const uint32_t DriverStation::kBatteryModuleNumber;
const uint32_t DriverStation::kBatteryChannel;
@@ -32,7 +40,7 @@ DriverStation::DriverStation()
: m_controlData (NULL)
, m_digitalOut (0)
, m_batteryChannel (NULL)
, m_statusDataSemaphore (initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE))
, m_statusDataSemaphore (initializeMutexNormal())
, m_task ("DriverStation", (FUNCPTR)DriverStation::InitTask)
, m_dashboardHigh(m_statusDataSemaphore)
, m_dashboardLow(m_statusDataSemaphore)
@@ -49,16 +57,16 @@ DriverStation::DriverStation()
, m_userInTest(false)
{
// Create a new semaphore
m_packetDataAvailableSem = initializeMutex(SEMAPHORE_Q_PRIORITY);
m_newControlData = initializeSemaphore(SEMAPHORE_Q_FIFO, SEMAPHORE_EMPTY);
m_packetDataAvailableSem = initializeMutexNormal();
m_newControlData = initializeSemaphore(SEMAPHORE_EMPTY);
// Register that semaphore with the network communications task.
// It will signal when new packet data is available.
setNewDataSem(m_packetDataAvailableSem);
HALSetNewDataSem(m_packetDataAvailableSem);
m_waitForDataSem = initializeMultiWait();
m_controlData = new FRCCommonControlData;
m_controlData = new HALCommonControlData;
// initialize packet number and control words to zero;
m_controlData->packetIndex = 0;
@@ -104,7 +112,7 @@ DriverStation::~DriverStation()
m_instance = NULL;
deleteMultiWait(m_waitForDataSem);
// Unregister our semaphore.
setNewDataSem(0);
HALSetNewDataSem(0);
deleteMutex(m_packetDataAvailableSem);
}
@@ -118,7 +126,7 @@ void DriverStation::Run()
int period = 0;
while (true)
{
takeMutex(m_packetDataAvailableSem, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_packetDataAvailableSem);
SetData();
m_enhancedIO.UpdateData();
GetData();
@@ -129,13 +137,13 @@ void DriverStation::Run()
period = 0;
}
if (m_userInDisabled)
FRC_NetworkCommunication_observeUserProgramDisabled();
HALNetworkCommunicationObserveUserProgramDisabled();
if (m_userInAutonomous)
FRC_NetworkCommunication_observeUserProgramAutonomous();
HALNetworkCommunicationObserveUserProgramAutonomous();
if (m_userInTeleop)
FRC_NetworkCommunication_observeUserProgramTeleop();
HALNetworkCommunicationObserveUserProgramTeleop();
if (m_userInTest)
FRC_NetworkCommunication_observeUserProgramTest();
HALNetworkCommunicationObserveUserProgramTest();
}
}
@@ -159,7 +167,9 @@ DriverStation* DriverStation::GetInstance()
void DriverStation::GetData()
{
static bool lastEnabled = false;
getCommonControlData(m_controlData, HAL_WAIT_FOREVER);
HALGetCommonControlData(m_controlData, HAL_WAIT_FOREVER);
if (!lastEnabled && IsEnabled())
{
// If starting teleop, assume that autonomous just took up 15 seconds
@@ -190,7 +200,7 @@ void DriverStation::SetData()
m_dashboardInUseHigh->GetStatusBuffer(&userStatusDataHigh, &userStatusDataHighSize);
m_dashboardInUseLow->GetStatusBuffer(&userStatusDataLow, &userStatusDataLowSize);
setStatusData(GetBatteryVoltage(), m_digitalOut, m_updateNumber,
HALSetStatusData(GetBatteryVoltage(), m_digitalOut, m_updateNumber,
userStatusDataHigh, userStatusDataHighSize, userStatusDataLow, userStatusDataLowSize, HAL_WAIT_FOREVER);
m_dashboardInUseHigh->Flush();
@@ -311,7 +321,7 @@ float DriverStation::GetAnalogIn(uint32_t channel)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationCIO, channel, nUsageReporting::kDriverStationCIO_Analog);
HALReport(HALUsageReporting::kResourceType_DriverStationCIO, channel, HALUsageReporting::kDriverStationCIO_Analog);
reported_mask |= (1 >> channel);
}
@@ -343,7 +353,7 @@ bool DriverStation::GetDigitalIn(uint32_t channel)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationCIO, channel, nUsageReporting::kDriverStationCIO_DigitalIn);
HALReport(HALUsageReporting::kResourceType_DriverStationCIO, channel, HALUsageReporting::kDriverStationCIO_DigitalIn);
reported_mask |= (1 >> channel);
}
@@ -367,7 +377,7 @@ void DriverStation::SetDigitalOut(uint32_t channel, bool value)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationCIO, channel, nUsageReporting::kDriverStationCIO_DigitalOut);
HALReport(HALUsageReporting::kResourceType_DriverStationCIO, channel,HALUsageReporting::kDriverStationCIO_DigitalOut);
reported_mask |= (1 >> channel);
}
@@ -421,7 +431,7 @@ bool DriverStation::IsTest()
*/
bool DriverStation::IsNewControlData()
{
return takeSemaphore(m_newControlData, SEMAPHORE_NO_WAIT) == 0;
return tryTakeSemaphore(m_newControlData) == 0;
}
/**

View File

@@ -5,7 +5,7 @@
/*----------------------------------------------------------------------------*/
#include "DriverStationEnhancedIO.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
#include <string.h>
@@ -27,8 +27,8 @@ DriverStationEnhancedIO::DriverStationEnhancedIO()
m_outputData.id = kOutputBlockID;
// Expected to be active low, so initialize inactive.
m_outputData.data.fixed_digital_out = 0x3;
m_inputDataSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
m_outputDataSemaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
m_inputDataSemaphore = initializeMutexNormal();
m_outputDataSemaphore = initializeMutexNormal();
m_encoderOffsets[0] = 0;
m_encoderOffsets[1] = 0;
}
@@ -72,9 +72,9 @@ void DriverStationEnhancedIO::UpdateData()
}
m_outputData.flags |= kStatusConfigChanged;
}
overrideIOConfig((char*)&m_outputData, 5);
HALOverrideIOConfig((char*)&m_outputData, 5);
}
retVal = getDynamicControlData(kOutputBlockID, (char*)&tempOutputData, sizeof(status_block_t), 5);
retVal = HALGetDynamicControlData(kOutputBlockID, (char*)&tempOutputData, sizeof(status_block_t), 5);
if (retVal == 0)
{
if (m_outputValid)
@@ -114,7 +114,7 @@ void DriverStationEnhancedIO::UpdateData()
{
Synchronized sync(m_inputDataSemaphore);
control_block_t tempInputData;
retVal = getDynamicControlData(kInputBlockID, (char*)&tempInputData, sizeof(control_block_t), 5);
retVal = HALGetDynamicControlData(kInputBlockID, (char*)&tempInputData, sizeof(control_block_t), 5);
if (retVal == 0 && tempInputData.data.api_version == kSupportedAPIVersion)
{
m_inputData = tempInputData;
@@ -179,7 +179,7 @@ double DriverStationEnhancedIO::GetAcceleration(tAccelChannel channel)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_Acceleration);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_Acceleration);
reported_mask |= (1 >> channel);
}
@@ -221,7 +221,7 @@ double DriverStationEnhancedIO::GetAnalogInRatio(uint32_t channel)
static uint16_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_AnalogIn);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_AnalogIn);
reported_mask |= (1 >> channel);
}
@@ -286,7 +286,7 @@ void DriverStationEnhancedIO::SetAnalogOut(uint32_t channel, double value)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_AnalogOut);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_AnalogOut);
reported_mask |= (1 >> channel);
}
@@ -320,7 +320,7 @@ bool DriverStationEnhancedIO::GetButton(uint32_t channel)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_Button);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_Button);
reported_mask |= (1 >> channel);
}
@@ -339,7 +339,7 @@ uint8_t DriverStationEnhancedIO::GetButtons()
wpi_setWPIError(EnhancedIOMissing);
return 0;
}
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, 0, nUsageReporting::kDriverStationEIO_Button);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, 0, HALUsageReporting::kDriverStationEIO_Button);
Synchronized sync(m_inputDataSemaphore);
return m_inputData.data.buttons;
}
@@ -366,7 +366,7 @@ void DriverStationEnhancedIO::SetLED(uint32_t channel, bool value)
static uint16_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_LED);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_LED);
reported_mask |= (1 >> channel);
}
@@ -392,7 +392,8 @@ void DriverStationEnhancedIO::SetLEDs(uint8_t value)
wpi_setWPIError(EnhancedIOMissing);
return;
}
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, 0, nUsageReporting::kDriverStationEIO_LED);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, 0, HALUsageReporting::kDriverStationEIO_LED);
Synchronized sync(m_outputDataSemaphore);
m_outputData.data.leds = value;
}
@@ -414,7 +415,7 @@ bool DriverStationEnhancedIO::GetDigital(uint32_t channel)
static uint32_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_DigitalIn);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_DigitalIn);
reported_mask |= (1 >> channel);
}
@@ -433,7 +434,7 @@ uint16_t DriverStationEnhancedIO::GetDigitals()
wpi_setWPIError(EnhancedIOMissing);
return 0;
}
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, 0, nUsageReporting::kDriverStationEIO_DigitalIn);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, 0, HALUsageReporting::kDriverStationEIO_DigitalIn);
Synchronized sync(m_inputDataSemaphore);
return m_inputData.data.digital;
}
@@ -460,7 +461,7 @@ void DriverStationEnhancedIO::SetDigitalOutput(uint32_t channel, bool value)
static uint32_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_DigitalOut);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_DigitalOut);
reported_mask |= (1 >> channel);
}
@@ -762,7 +763,7 @@ void DriverStationEnhancedIO::SetFixedDigitalOutput(uint32_t channel, bool value
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_FixedDigitalOut);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_FixedDigitalOut);
reported_mask |= (1 >> channel);
}
@@ -806,7 +807,7 @@ int16_t DriverStationEnhancedIO::GetEncoder(uint32_t encoderNumber)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> encoderNumber)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, encoderNumber, nUsageReporting::kDriverStationEIO_Encoder);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, encoderNumber, HALUsageReporting::kDriverStationEIO_Encoder);
reported_mask |= (1 >> encoderNumber);
}
@@ -906,7 +907,7 @@ double DriverStationEnhancedIO::GetTouchSlider()
return 0.0;
}
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, 1, nUsageReporting::kDriverStationEIO_TouchSlider);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, 1, HALUsageReporting::kDriverStationEIO_TouchSlider);
Synchronized sync(m_inputDataSemaphore);
uint8_t value = m_inputData.data.capsense_slider;
@@ -961,7 +962,7 @@ void DriverStationEnhancedIO::SetPWMOutput(uint32_t channel, double value)
static uint8_t reported_mask = 0;
if (!(reported_mask & (1 >> channel)))
{
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationEIO, channel, nUsageReporting::kDriverStationEIO_PWM);
HALReport(HALUsageReporting::kResourceType_DriverStationEIO, channel, HALUsageReporting::kDriverStationEIO_PWM);
reported_mask |= (1 >> channel);
}

View File

@@ -8,8 +8,8 @@
//#include <algorithm>
#include <string.h>
#include "NetworkCommunication/FRCComm.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
#undef min
@@ -29,14 +29,14 @@ DriverStationLCD::DriverStationLCD()
: m_textBuffer (NULL)
, m_textBufferSemaphore (NULL)
{
m_textBuffer = new char[USER_DS_LCD_DATA_SIZE];
memset(m_textBuffer, ' ', USER_DS_LCD_DATA_SIZE);
m_textBuffer = new char[HAL_USER_DS_LCD_DATA_SIZE];
memset(m_textBuffer, ' ', HAL_USER_DS_LCD_DATA_SIZE);
*((uint16_t *)m_textBuffer) = kFullDisplayTextCommand;
m_textBufferSemaphore = initializeMutex(SEMAPHORE_DELETE_SAFE);
m_textBufferSemaphore = initializeMutexNormal();
nUsageReporting::report(nUsageReporting::kResourceType_DriverStationLCD, 0);
HALReport(HALUsageReporting::kResourceType_DriverStationLCD, 0);
AddToSingletonList();
}
@@ -66,7 +66,7 @@ DriverStationLCD* DriverStationLCD::GetInstance()
void DriverStationLCD::UpdateLCD()
{
Synchronized sync(m_textBufferSemaphore);
setUserDsLcdData(m_textBuffer, USER_DS_LCD_DATA_SIZE, kSyncTimeout_ms);
HALSetUserDsLcdData(m_textBuffer, HAL_USER_DS_LCD_DATA_SIZE, kSyncTimeout_ms);
}
/**

View File

@@ -6,7 +6,7 @@
#include "Encoder.h"
#include "DigitalInput.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -62,7 +62,7 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType)
m_distancePerPulse = 1.0;
m_pidSource = kDistance;
nUsageReporting::report(nUsageReporting::kResourceType_Encoder, index, encodingType);
HALReport(HALUsageReporting::kResourceType_Encoder, index, encodingType);
LiveWindow::GetInstance()->AddSensor("Encoder", m_aSource->GetModuleForRouting(), m_aSource->GetChannelForRouting(), this);
}

View File

@@ -10,7 +10,7 @@
#include <cstdio>
#include <cstring>
#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/FRCComm.h"
#include "Timer.h"
#include "Utility.h"
bool Error::m_stackTraceEnabled = false;
@@ -94,7 +94,7 @@ void Error::Report()
// TODO: Add logging to disk
// Send to the DriverStation
setErrorData(error_with_code, strlen(error_with_code), 100);
HALSetErrorData(error_with_code, strlen(error_with_code), 100);
delete [] error_with_code;

View File

@@ -14,7 +14,7 @@
#include <errno.h>
#include <cstdio>
MUTEX_ID ErrorBase::_globalErrorMutex = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
MUTEX_ID ErrorBase::_globalErrorMutex = initializeMutexNormal();
Error ErrorBase::_globalError;
/**
* @brief Initialize the instance status to 0 for now.

View File

@@ -7,7 +7,7 @@
#include "Gyro.h"
#include "AnalogChannel.h"
#include "AnalogModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Timer.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -66,7 +66,7 @@ void Gyro::InitGyro()
SetPIDSourceParameter(kAngle);
nUsageReporting::report(nUsageReporting::kResourceType_Gyro, m_analog->GetChannel(), m_analog->GetModuleNumber() - 1);
HALReport(HALUsageReporting::kResourceType_Gyro, m_analog->GetChannel(), m_analog->GetModuleNumber() - 1);
LiveWindow::GetInstance()->AddSensor("Gyro", m_analog->GetModuleNumber(), m_analog->GetChannel(), this);
}

View File

@@ -7,7 +7,7 @@
#include "HiTechnicColorSensor.h"
#include "DigitalModule.h"
#include "I2C.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "networktables2/type/NumberArray.h"
#include "WPIErrors.h"
@@ -54,7 +54,7 @@ HiTechnicColorSensor::HiTechnicColorSensor(uint8_t moduleNumber)
wpi_setWPIError(CompassTypeError);
}
nUsageReporting::report(nUsageReporting::kResourceType_HiTechnicColorSensor, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_HiTechnicColorSensor, moduleNumber - 1);
}
}

View File

@@ -7,7 +7,7 @@
#include "HiTechnicCompass.h"
#include "DigitalModule.h"
#include "I2C.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -45,7 +45,7 @@ HiTechnicCompass::HiTechnicCompass(uint8_t moduleNumber)
wpi_setWPIError(CompassTypeError);
}
nUsageReporting::report(nUsageReporting::kResourceType_HiTechnicCompass, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_HiTechnicCompass, moduleNumber - 1);
LiveWindow::GetInstance()->AddSensor("HiTechnicCompass", moduleNumber, 0, this);
}
}

View File

@@ -6,7 +6,7 @@
#include "I2C.h"
#include "DigitalModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
@@ -26,11 +26,11 @@ I2C::I2C(DigitalModule *module, uint8_t deviceAddress)
{
if (m_semaphore == NULL)
{
m_semaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
m_semaphore = initializeMutexNormal();
}
m_objCount++;
nUsageReporting::report(nUsageReporting::kResourceType_I2C, deviceAddress, module->GetNumber() - 1);
HALReport(HALUsageReporting::kResourceType_I2C, deviceAddress, module->GetNumber() - 1);
}
/**
@@ -163,7 +163,7 @@ void I2C::SetCompatibilityMode(bool enable)
const char *cm = NULL;
if (m_compatibilityMode) cm = "C";
nUsageReporting::report(nUsageReporting::kResourceType_I2C, m_deviceAddress, m_module->GetNumber() - 1, cm);
HALReport(HALUsageReporting::kResourceType_I2C, m_deviceAddress, m_module->GetNumber() - 1, cm);
}
/**

View File

@@ -7,7 +7,7 @@
#include "IterativeRobot.h"
#include "DriverStation.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/HAL.h"
#include "SmartDashboard/SmartDashboard.h"
#include "LiveWindow/LiveWindow.h"
@@ -92,7 +92,7 @@ double IterativeRobot::GetLoopsPerSec()
*/
void IterativeRobot::StartCompetition()
{
nUsageReporting::report(nUsageReporting::kResourceType_Framework, nUsageReporting::kFramework_Iterative);
HALReport(HALUsageReporting::kResourceType_Framework, HALUsageReporting::kFramework_Iterative);
LiveWindow *lw = LiveWindow::GetInstance();
// first and one-time initialization
@@ -121,7 +121,7 @@ void IterativeRobot::StartCompetition()
}
if (NextPeriodReady())
{
FRC_NetworkCommunication_observeUserProgramDisabled();
HALNetworkCommunicationObserveUserProgramDisabled();
DisabledPeriodic();
}
}
@@ -141,7 +141,7 @@ void IterativeRobot::StartCompetition()
}
if (NextPeriodReady())
{
FRC_NetworkCommunication_observeUserProgramAutonomous();
HALNetworkCommunicationObserveUserProgramAutonomous();
AutonomousPeriodic();
}
}
@@ -161,7 +161,7 @@ void IterativeRobot::StartCompetition()
}
if (NextPeriodReady())
{
FRC_NetworkCommunication_observeUserProgramTest();
HALNetworkCommunicationObserveUserProgramTest();
TestPeriodic();
}
}
@@ -182,7 +182,7 @@ void IterativeRobot::StartCompetition()
}
if (NextPeriodReady())
{
FRC_NetworkCommunication_observeUserProgramTeleop();
HALNetworkCommunicationObserveUserProgramTeleop();
TeleopPeriodic();
}
}

View File

@@ -6,7 +6,7 @@
#include "Jaguar.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "DigitalModule.h"
#include "LiveWindow/LiveWindow.h"
@@ -28,7 +28,7 @@ void Jaguar::InitJaguar()
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetRaw(m_centerPwm);
nUsageReporting::report(nUsageReporting::kResourceType_Jaguar, GetChannel(), GetModuleNumber() - 1);
HALReport(HALUsageReporting::kResourceType_Jaguar, GetChannel(), GetModuleNumber() - 1);
LiveWindow::GetInstance()->AddActuator("Jaguar", GetModuleNumber(), GetChannel(), this);
}

View File

@@ -6,7 +6,7 @@
#include "Joystick.h"
#include "DriverStation.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include <math.h>
@@ -43,7 +43,7 @@ Joystick::Joystick(uint32_t port)
m_buttons[kTriggerButton] = kDefaultTriggerButton;
m_buttons[kTopButton] = kDefaultTopButton;
nUsageReporting::report(nUsageReporting::kResourceType_Joystick, port);
HALReport(HALUsageReporting::kResourceType_Joystick, port);
}
/**

View File

@@ -7,16 +7,16 @@
#include "Kinect.h"
#include "DriverStation.h"
#include "NetworkCommunication/FRCComm.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Skeleton.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
#include <cstring>
#define kHeaderBundleID kFRC_NetworkCommunication_DynamicType_Kinect_Header
#define kSkeletonExtraBundleID kFRC_NetworkCommunication_DynamicType_Kinect_Extra1
#define kSkeletonBundleID kFRC_NetworkCommunication_DynamicType_Kinect_Vertices1
#define kHeaderBundleID HALFRC_NetworkCommunication_DynamicType_Kinect_Header
#define kSkeletonExtraBundleID HALFRC_NetworkCommunication_DynamicType_Kinect_Extra1
#define kSkeletonBundleID HALFRC_NetworkCommunication_DynamicType_Kinect_Vertices1
Kinect *Kinect::_instance = NULL;
@@ -25,14 +25,14 @@ Kinect::Kinect() :
m_numberOfPlayers(0)
{
AddToSingletonList();
m_dataLock = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_INVERSION_SAFE | SEMAPHORE_DELETE_SAFE);
m_dataLock = initializeMutexNormal();
nUsageReporting::report(nUsageReporting::kResourceType_Kinect, 0);
HALReport(HALUsageReporting::kResourceType_Kinect, 0);
}
Kinect::~Kinect()
{
takeMutex(m_dataLock, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_dataLock);
deleteMutex(m_dataLock);
}
@@ -156,7 +156,7 @@ void Kinect::UpdateData()
if (m_recentPacketNumber != packetNumber)
{
m_recentPacketNumber = packetNumber;
int retVal = getDynamicControlData(kHeaderBundleID, m_rawHeader, sizeof(m_rawHeader), 5);
int retVal = HALGetDynamicControlData(kHeaderBundleID, m_rawHeader, sizeof(m_rawHeader), 5);
if(retVal == 0)
{
m_numberOfPlayers = (int)m_rawHeader[13];
@@ -169,7 +169,7 @@ void Kinect::UpdateData()
memcpy(&m_gravityNormal.z, &m_rawHeader[42], 4);
}
retVal = getDynamicControlData(kSkeletonExtraBundleID, m_rawSkeletonExtra, sizeof(m_rawSkeletonExtra), 5);
retVal = HALGetDynamicControlData(kSkeletonExtraBundleID, m_rawSkeletonExtra, sizeof(m_rawSkeletonExtra), 5);
if(retVal == 0)
{
memcpy(&m_position[0].x, &m_rawSkeletonExtra[22], 4);
@@ -179,7 +179,7 @@ void Kinect::UpdateData()
memcpy(&m_trackingState[0], &m_rawSkeletonExtra[38], 4);
}
retVal = getDynamicControlData(kSkeletonBundleID, m_rawSkeleton, sizeof(m_rawSkeleton), 5);
retVal = HALGetDynamicControlData(kSkeletonBundleID, m_rawSkeleton, sizeof(m_rawSkeleton), 5);
if(retVal == 0)
{
for(int i=0; i < Skeleton::JointCount; i++)

View File

@@ -8,15 +8,15 @@
#include "DriverStation.h"
#include "Joystick.h"
#include "NetworkCommunication/FRCComm.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Utility.h"
#include "WPIErrors.h"
uint32_t KinectStick::_recentPacketNumber = 0;
KinectStick::KinectStickData KinectStick::_sticks;
#define kJoystickBundleID kFRC_NetworkCommunication_DynamicType_Kinect_Joystick
#define kJoystickBundleID HALFRC_NetworkCommunication_DynamicType_Kinect_Joystick
#define kTriggerMask 1
#define kTopMask 2
@@ -34,7 +34,7 @@ KinectStick::KinectStick(int id)
}
m_id = id;
nUsageReporting::report(nUsageReporting::kResourceType_KinectStick, id);
HALReport(HALUsageReporting::kResourceType_KinectStick, id);
}
/**
@@ -169,7 +169,7 @@ void KinectStick::GetData()
if (_recentPacketNumber != packetNumber)
{
_recentPacketNumber = packetNumber;
int retVal = getDynamicControlData(kJoystickBundleID, _sticks.data, sizeof(_sticks.data), 5);
int retVal = HALGetDynamicControlData(kJoystickBundleID, _sticks.data, sizeof(_sticks.data), 5);
if (retVal == 0)
{
wpi_assert(_sticks.formatted.size == sizeof(_sticks.data) - 1);

View File

@@ -30,7 +30,7 @@ Notifier::Notifier(TimerEventHandler handler, void *param)
m_period = 0;
m_nextEvent = NULL;
m_queued = false;
m_handlerSemaphore = initializeSemaphore(SEMAPHORE_Q_PRIORITY, SEMAPHORE_FULL);
m_handlerSemaphore = initializeSemaphore(SEMAPHORE_FULL);
{
Synchronized sync(queueSemaphore);
// do the first time intialization of static variables
@@ -66,7 +66,7 @@ Notifier::~Notifier()
// Acquire the semaphore; this makes certain that the handler is
// not being executed by the interrupt manager.
takeSemaphore(m_handlerSemaphore, SEMAPHORE_WAIT_FOREVER);
takeSemaphore(m_handlerSemaphore);
// Delete while holding the semaphore so there can be no race.
deleteSemaphore(m_handlerSemaphore);
}
@@ -122,7 +122,7 @@ void Notifier::ProcessQueue(uint32_t mask, void *params)
}
// Take handler semaphore while holding queue semaphore to make sure
// the handler will execute to completion in case we are being deleted.
takeSemaphore(current->m_handlerSemaphore, SEMAPHORE_WAIT_FOREVER);
takeSemaphore(current->m_handlerSemaphore);
}
current->m_handler(current->m_param); // call the event handler

View File

@@ -5,7 +5,7 @@
/*----------------------------------------------------------------------------*/
#include "PIDController.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Notifier.h"
#include "PIDSource.h"
#include "PIDOutput.h"
@@ -63,7 +63,7 @@ void PIDController::Initialize(float Kp, float Ki, float Kd, float Kf,
{
m_table = NULL;
m_semaphore = initializeMutex(SEMAPHORE_Q_PRIORITY);
m_semaphore = initializeMutexNormal();
m_controlLoop = new Notifier(PIDController::CallCalculate, this);
@@ -96,7 +96,7 @@ void PIDController::Initialize(float Kp, float Ki, float Kd, float Kf,
static int32_t instances = 0;
instances++;
nUsageReporting::report(nUsageReporting::kResourceType_PIDController, instances);
HALReport(HALUsageReporting::kResourceType_PIDController, instances);
m_toleranceType = kNoTolerance;
}
@@ -106,7 +106,7 @@ void PIDController::Initialize(float Kp, float Ki, float Kd, float Kf,
*/
PIDController::~PIDController()
{
takeMutex(m_semaphore, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_semaphore);
deleteMutex(m_semaphore);
delete m_controlLoop;
}

View File

@@ -7,7 +7,7 @@
#include "PWM.h"
#include "DigitalModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "Utility.h"
#include "WPIErrors.h"
@@ -54,7 +54,7 @@ void PWM::InitPWM(uint8_t moduleNumber, uint32_t channel)
m_module->SetPWM(m_channel, kPwmDisabled);
m_eliminateDeadband = false;
nUsageReporting::report(nUsageReporting::kResourceType_PWM, channel, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_PWM, channel, moduleNumber - 1);
}
/**

View File

@@ -6,7 +6,7 @@
#include "Preferences.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
@@ -36,22 +36,22 @@ Preferences::Preferences() :
m_readTask("PreferencesReadTask", (FUNCPTR)Preferences::InitReadTask),
m_writeTask("PreferencesWriteTask", (FUNCPTR)Preferences::InitWriteTask)
{
m_fileLock = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_INVERSION_SAFE | SEMAPHORE_DELETE_SAFE);
m_fileOpStarted = initializeSemaphore (SEMAPHORE_Q_PRIORITY, SEMAPHORE_EMPTY);
m_tableLock = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_INVERSION_SAFE | SEMAPHORE_DELETE_SAFE);
m_fileLock = initializeMutexNormal();
m_fileOpStarted = initializeSemaphore (SEMAPHORE_EMPTY);
m_tableLock = initializeMutexNormal();
Synchronized sync(m_fileLock);
m_readTask.Start((uint32_t)this);
takeSemaphore(m_fileOpStarted, SEMAPHORE_WAIT_FOREVER);
takeSemaphore(m_fileOpStarted);
nUsageReporting::report(nUsageReporting::kResourceType_Preferences, 0);
HALReport(HALUsageReporting::kResourceType_Preferences, 0);
}
Preferences::~Preferences()
{
takeMutex(m_tableLock, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_tableLock);
deleteMutex(m_tableLock);
takeMutex(m_fileLock, SEMAPHORE_WAIT_FOREVER);
takeMutex(m_fileLock);
deleteSemaphore(m_fileOpStarted);
deleteMutex(m_fileLock);
}
@@ -325,7 +325,7 @@ void Preferences::Save()
{
Synchronized sync(m_fileLock);
m_writeTask.Start((uint32_t)this);
takeSemaphore(m_fileOpStarted, SEMAPHORE_WAIT_FOREVER);
takeSemaphore(m_fileOpStarted);
}
/**

View File

@@ -7,7 +7,7 @@
#include "Relay.h"
#include "DigitalModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Resource.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -50,7 +50,7 @@ void Relay::InitRelay (uint8_t moduleNumber)
return;
}
nUsageReporting::report(nUsageReporting::kResourceType_Relay, m_channel, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_Relay, m_channel, moduleNumber - 1);
}
if (m_direction == kBothDirections || m_direction == kReverseOnly)
{
@@ -61,7 +61,7 @@ void Relay::InitRelay (uint8_t moduleNumber)
return;
}
nUsageReporting::report(nUsageReporting::kResourceType_Relay, m_channel + 128, moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_Relay, m_channel + 128, moduleNumber - 1);
}
m_module = DigitalModule::GetInstance(moduleNumber);
m_module->SetRelayForward(m_channel, false);

View File

@@ -7,9 +7,9 @@
#include "RobotBase.h"
#include "DriverStation.h"
#include "NetworkCommunication/FRCComm.h"
#include "NetworkCommunication/symModuleLink.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/symModuleLink.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Utility.h"
#include <cstring>
#include "HAL/HAL.h"
@@ -192,10 +192,10 @@ void RobotBase::startRobotTask(FUNCPTR factory)
#endif
// Let the framework know that we are starting a new user program so the Driver Station can disable.
FRC_NetworkCommunication_observeUserProgramStarting();
HALNetworkCommunicationObserveUserProgramStarting();
// Let the Usage Reporting framework know that there is a C++ program running
nUsageReporting::report(nUsageReporting::kResourceType_Language, nUsageReporting::kLanguage_CPlusPlus);
HALReport(HALUsageReporting::kResourceType_Language, HALUsageReporting::kLanguage_CPlusPlus);
// Start robot task
// This is done to ensure that the C++ robot task is spawned with the floating point

View File

@@ -10,7 +10,7 @@
#include "GenericHID.h"
#include "Joystick.h"
#include "Jaguar.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Utility.h"
#include "WPIErrors.h"
#include <math.h>
@@ -204,7 +204,7 @@ void RobotDrive::Drive(float outputMagnitude, float curve)
static bool reported = false;
if (!reported)
{
nUsageReporting::report(nUsageReporting::kResourceType_RobotDrive, GetNumMotors(), nUsageReporting::kRobotDrive_ArcadeRatioCurve);
HALReport(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(), HALUsageReporting::kRobotDrive_ArcadeRatioCurve);
reported = true;
}
@@ -292,7 +292,7 @@ void RobotDrive::TankDrive(float leftValue, float rightValue, bool squaredInputs
static bool reported = false;
if (!reported)
{
nUsageReporting::report(nUsageReporting::kResourceType_RobotDrive, GetNumMotors(), nUsageReporting::kRobotDrive_Tank);
HALReport(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(), HALUsageReporting::kRobotDrive_Tank);
reported = true;
}
@@ -405,7 +405,7 @@ void RobotDrive::ArcadeDrive(float moveValue, float rotateValue, bool squaredInp
static bool reported = false;
if (!reported)
{
nUsageReporting::report(nUsageReporting::kResourceType_RobotDrive, GetNumMotors(), nUsageReporting::kRobotDrive_ArcadeStandard);
HALReport(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(), HALUsageReporting::kRobotDrive_ArcadeStandard);
reported = true;
}
@@ -487,7 +487,7 @@ void RobotDrive::MecanumDrive_Cartesian(float x, float y, float rotation, float
static bool reported = false;
if (!reported)
{
nUsageReporting::report(nUsageReporting::kResourceType_RobotDrive, GetNumMotors(), nUsageReporting::kRobotDrive_MecanumCartesian);
HALReport(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(), HALUsageReporting::kRobotDrive_MecanumCartesian);
reported = true;
}
@@ -536,7 +536,7 @@ void RobotDrive::MecanumDrive_Polar(float magnitude, float direction, float rota
static bool reported = false;
if (!reported)
{
nUsageReporting::report(nUsageReporting::kResourceType_RobotDrive, GetNumMotors(), nUsageReporting::kRobotDrive_MecanumPolar);
HALReport(HALUsageReporting::kResourceType_RobotDrive, GetNumMotors(), HALUsageReporting::kRobotDrive_MecanumPolar);
reported = true;
}

View File

@@ -9,7 +9,7 @@
#include "DigitalModule.h"
#include "DigitalInput.h"
#include "DigitalOutput.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "HAL/cpp/Synchronized.h"
#include "WPIErrors.h"
@@ -122,7 +122,7 @@ void SPI::Init(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso)
static int32_t instances = 0;
instances++;
nUsageReporting::report(nUsageReporting::kResourceType_SPI, instances);
HALReport(HALUsageReporting::kResourceType_SPI, instances);
}
/**

View File

@@ -6,7 +6,7 @@
#include "SerialPort.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "visa/visa.h"
#include <stdarg.h>
@@ -57,7 +57,7 @@ SerialPort::SerialPort(uint32_t baudRate, uint8_t dataBits, SerialPort::Parity p
//viInstallHandler(m_portHandle, VI_EVENT_IO_COMPLETION, ioCompleteHandler, this);
//viEnableEvent(m_portHandle, VI_EVENT_IO_COMPLETION, VI_HNDLR, VI_NULL);
nUsageReporting::report(nUsageReporting::kResourceType_SerialPort, 0);
HALReport(HALUsageReporting::kResourceType_SerialPort, 0);
}
/**

View File

@@ -6,7 +6,7 @@
#include "Servo.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "LiveWindow/LiveWindow.h"
constexpr float Servo::kMaxServoAngle;
@@ -25,7 +25,7 @@ void Servo::InitServo()
SetPeriodMultiplier(kPeriodMultiplier_4X);
LiveWindow::GetInstance()->AddActuator("Servo", GetModuleNumber(), GetChannel(), this);
nUsageReporting::report(nUsageReporting::kResourceType_Servo, GetChannel(), GetModuleNumber() - 1);
HALReport(HALUsageReporting::kResourceType_Servo, GetChannel(), GetModuleNumber() - 1);
}
/**

View File

@@ -7,7 +7,7 @@
#include "SimpleRobot.h"
#include "DriverStation.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Timer.h"
#include "SmartDashboard/SmartDashboard.h"
#include "LiveWindow/LiveWindow.h"
@@ -100,7 +100,7 @@ void SimpleRobot::StartCompetition()
{
LiveWindow *lw = LiveWindow::GetInstance();
nUsageReporting::report(nUsageReporting::kResourceType_Framework, nUsageReporting::kFramework_Simple);
HALReport(HALUsageReporting::kResourceType_Framework, HALUsageReporting::kFramework_Simple);
SmartDashboard::init();
NetworkTable::GetTable("LiveWindow")->GetSubTable("~STATUS~")->PutBoolean("LW Enabled", false);

View File

@@ -6,7 +6,7 @@
#include "SmartDashboard/SmartDashboard.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "SmartDashboard/NamedSendable.h"
#include "WPIErrors.h"
#include "networktables/NetworkTable.h"

View File

@@ -5,7 +5,7 @@
/*----------------------------------------------------------------------------*/
#include "Solenoid.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
@@ -38,7 +38,7 @@ void Solenoid::InitSolenoid()
}
LiveWindow::GetInstance()->AddActuator("Solenoid", m_moduleNumber, m_channel, this);
nUsageReporting::report(nUsageReporting::kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
HALReport(HALUsageReporting::kResourceType_Solenoid, m_channel, m_moduleNumber - 1);
}
/**

View File

@@ -7,7 +7,7 @@
#include "Talon.h"
#include "DigitalModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "LiveWindow/LiveWindow.h"
/**
@@ -29,7 +29,7 @@ void Talon::InitTalon() {
SetPeriodMultiplier(kPeriodMultiplier_2X);
SetRaw(m_centerPwm);
nUsageReporting::report(nUsageReporting::kResourceType_Talon, GetChannel(), GetModuleNumber() - 1);
HALReport(HALUsageReporting::kResourceType_Talon, GetChannel(), GetModuleNumber() - 1);
LiveWindow::GetInstance()->AddActuator("Talon", GetModuleNumber(), GetChannel(), this);
}

View File

@@ -6,7 +6,7 @@
#include "Task.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "WPIErrors.h"
#include <errno.h>
#include <string.h>
@@ -33,7 +33,7 @@ Task::Task(const char* name, FUNCPTR function, int32_t priority, uint32_t stackS
static int32_t instances = 0;
instances++;
nUsageReporting::report(nUsageReporting::kResourceType_Task, instances, 0, m_taskName);
HALReport(HALUsageReporting::kResourceType_Task, instances, 0, m_taskName);
}
Task::~Task()

View File

@@ -65,7 +65,7 @@ Timer::Timer()
{
//Creates a semaphore to control access to critical regions.
//Initially 'open'
m_semaphore = initializeMutex(SEMAPHORE_Q_PRIORITY | SEMAPHORE_DELETE_SAFE | SEMAPHORE_INVERSION_SAFE);
m_semaphore = initializeMutexNormal();
Reset();
}

View File

@@ -9,7 +9,7 @@
#include "Counter.h"
#include "DigitalInput.h"
#include "DigitalOutput.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "Timer.h"
#include "Utility.h"
#include "WPIErrors.h"
@@ -58,9 +58,9 @@ void Ultrasonic::Initialize()
{
m_table = NULL;
bool originalMode = m_automaticEnabled;
if (m_semaphore == 0) m_semaphore = initializeSemaphore(SEMAPHORE_Q_PRIORITY, SEMAPHORE_FULL);
if (m_semaphore == 0) m_semaphore = initializeSemaphore(SEMAPHORE_FULL);
SetAutomaticMode(false); // kill task when adding a new sensor
takeSemaphore(m_semaphore, SEMAPHORE_WAIT_FOREVER); // link this instance on the list
takeSemaphore(m_semaphore); // link this instance on the list
{
m_nextSensor = m_firstSensor;
m_firstSensor = this;
@@ -77,7 +77,7 @@ void Ultrasonic::Initialize()
static int instances = 0;
instances++;
nUsageReporting::report(nUsageReporting::kResourceType_Ultrasonic, instances);
HALReport(HALUsageReporting::kResourceType_Ultrasonic, instances);
LiveWindow::GetInstance()->AddSensor("Ultrasonic", m_echoChannel->GetModuleForRouting(), m_echoChannel->GetChannel(), this);
}
@@ -176,7 +176,7 @@ Ultrasonic::~Ultrasonic()
}
wpi_assert(m_firstSensor != NULL);
takeSemaphore(m_semaphore, SEMAPHORE_WAIT_FOREVER);
takeSemaphore(m_semaphore);
{
if (this == m_firstSensor)
{

View File

@@ -6,7 +6,7 @@
#include "Utility.h"
#include "NetworkCommunication/FRCComm.h"
//#include "NetworkCommunication/FRCComm.h"
#include "HAL/HAL.h"
#include "HAL/cpp/StackTrace.h"
#include "Task.h"
@@ -75,7 +75,7 @@ bool wpi_assert_impl(bool conditionValue,
// Print to console and send to remote dashboard
printf("\n\n>>>>%s", error);
setErrorData(error, strlen(error), 100);
HALSetErrorData(error, strlen(error), 100);
wpi_handleTracing();
if (suspendOnAssertEnabled) suspendTask(0);
@@ -111,7 +111,7 @@ void wpi_assertEqual_common_impl(int valueA,
// Print to console and send to remote dashboard
printf("\n\n>>>>%s", error);
setErrorData(error, strlen(error), 100);
HALSetErrorData(error, strlen(error), 100);
wpi_handleTracing();
if (suspendOnAssertEnabled) suspendTask(0);

View File

@@ -7,7 +7,7 @@
#include "Victor.h"
#include "DigitalModule.h"
#include "NetworkCommunication/UsageReporting.h"
//#include "NetworkCommunication/UsageReporting.h"
#include "LiveWindow/LiveWindow.h"
/**
@@ -32,7 +32,7 @@ void Victor::InitVictor() {
SetRaw(m_centerPwm);
LiveWindow::GetInstance()->AddActuator("Victor", GetModuleNumber(), GetChannel(), this);
nUsageReporting::report(nUsageReporting::kResourceType_Victor, GetChannel(), GetModuleNumber() - 1);
HALReport(HALUsageReporting::kResourceType_Victor, GetChannel(), GetModuleNumber() - 1);
}
/**

View File

@@ -6,8 +6,8 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tInstances;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;

View File

@@ -7,7 +7,7 @@
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;

View File

@@ -6,14 +6,17 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.nio.ByteBuffer;
import com.sun.jna.Pointer;
//import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.AnalogJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
@@ -42,7 +45,7 @@ public class AnalogChannel extends SensorBase implements PIDSource,
private static final int kAccumulatorSlot = 1;
private static Resource channels = new Resource(kAnalogModules
* kAnalogChannels);
private Pointer m_port;
private ByteBuffer m_port;
private int m_moduleNumber, m_channel;
private static final int[] kAccumulatorChannels = { 1, 2 };
private long m_accumulatorOffset;
@@ -66,39 +69,38 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* The channel number to represent.
*/
public AnalogChannel(final int moduleNumber, final int channel) {
System.out.println("Module Number: " + moduleNumber + " Channel: "
+ channel);
System.out.println(Thread.currentThread().getStackTrace());
m_channel = channel;
m_moduleNumber = moduleNumber;
if (HALLibrary.checkAnalogModule((byte) moduleNumber) == 0) {
if (AnalogJNI.checkAnalogModule((byte)moduleNumber) == 0) {
throw new AllocationException("Analog channel " + m_channel
+ " on module " + m_moduleNumber
+ " cannot be allocated. Module is not present.");
}
if (HALLibrary.checkAnalogChannel(channel) == 0) {
if (AnalogJNI.checkAnalogChannel(channel) == 0) {
throw new AllocationException("Analog channel " + m_channel
+ " on module " + m_moduleNumber
+ " cannot be allocated. Channel is not present.");
}
try {
channels.allocate((moduleNumber - 1) * kAnalogChannels + m_channel
channels.allocate((moduleNumber - 1) * kAnalogChannels + channel
- 1);
} catch (CheckedAllocationException e) {
throw new AllocationException("Analog channel " + m_channel
+ " on module " + m_moduleNumber + " is already allocated");
}
Pointer port_pointer = HALLibrary.getPortWithModule(
ByteBuffer port_pointer = AnalogJNI.getPortWithModule(
(byte) moduleNumber, (byte) channel);
IntBuffer status = IntBuffer.allocate(1);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
// XXX: Uncomment when Analog has been fixed
m_port = HALLibrary.initializeAnalogPort(port_pointer, status);
HALUtil.checkStatus(status);
m_port = AnalogJNI.initializeAnalogPort(port_pointer, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
LiveWindow.addSensor("Analog", moduleNumber, channel, this);
UsageReporting.report(tResourceType.kResourceType_AnalogChannel,
channel, m_moduleNumber - 1);
channel, moduleNumber - 1);
}
/**
@@ -129,9 +131,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return A sample straight from this channel on the module.
*/
public int getValue() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogValue(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogValue(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -147,9 +151,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return A sample from the oversample and average engine for this channel.
*/
public int getAverageValue() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogAverageValue(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogAverageValue(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -161,9 +167,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return A scaled sample straight from this channel on the module.
*/
public double getVoltage() {
IntBuffer status = IntBuffer.allocate(1);
double value = Float.intBitsToFloat(HALLibrary.getAnalogVoltageIntHack(m_port, status));
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
double value = AnalogJNI.getAnalogVoltage(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -179,9 +187,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* engine for this channel.
*/
public double getAverageVoltage() {
IntBuffer status = IntBuffer.allocate(1);
double value = Float.intBitsToFloat(HALLibrary.getAnalogAverageVoltageIntHack(m_port, status));
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
double value = AnalogJNI.getAnalogAverageVoltage(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -195,9 +205,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return Least significant bit weight.
*/
public long getLSBWeight() {
IntBuffer status = IntBuffer.allocate(1);
long value = HALLibrary.getAnalogLSBWeight(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
long value = AnalogJNI.getAnalogLSBWeight(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -211,9 +223,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return Offset constant.
*/
public int getOffset() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogOffset(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogOffset(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -244,9 +258,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* The number of averaging bits.
*/
public void setAverageBits(final int bits) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogAverageBits(m_port, bits, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogAverageBits(m_port, bits, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -257,9 +273,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return The number of averaging bits.
*/
public int getAverageBits() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogAverageBits(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogAverageBits(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -272,9 +290,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* The number of oversample bits.
*/
public void setOversampleBits(final int bits) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogOversampleBits(m_port, bits, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogOversampleBits(m_port, bits, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -285,9 +305,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return The number of oversample bits.
*/
public int getOversampleBits() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogOversampleBits(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogOversampleBits(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -303,9 +325,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
+ kAccumulatorChannels[1]);
}
m_accumulatorOffset = 0;
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.initAccumulator(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.initAccumulator(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -324,9 +348,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* Resets the accumulator to the initial value.
*/
public void resetAccumulator() {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.resetAccumulator(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.resetAccumulator(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -342,18 +368,22 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* affect the size of the value for this field.
*/
public void setAccumulatorCenter(int center) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAccumulatorCenter(m_port, center, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAccumulatorCenter(m_port, center, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
* Set the accumulator's deadband.
*/
public void setAccumulatorDeadband(int deadband) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAccumulatorDeadband(m_port, deadband, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAccumulatorDeadband(m_port, deadband, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -365,9 +395,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return The 64-bit value accumulated since the last Reset().
*/
public long getAccumulatorValue() {
IntBuffer status = IntBuffer.allocate(1);
long value = HALLibrary.getAccumulatorValue(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
long value = AnalogJNI.getAccumulatorValue(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value + m_accumulatorOffset;
}
@@ -380,9 +412,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
* @return The number of times samples from the channel were accumulated.
*/
public long getAccumulatorCount() {
IntBuffer status = IntBuffer.allocate(1);
long value = HALLibrary.getAccumulatorCount(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
long value = AnalogJNI.getAccumulatorCount(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -405,13 +439,19 @@ public class AnalogChannel extends SensorBase implements PIDSource,
+ " on module " + m_moduleNumber
+ " is not an accumulator channel.");
}
LongBuffer value = LongBuffer.allocate(1);
IntBuffer count = IntBuffer.allocate(1);
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.getAccumulatorOutput(m_port, value, count, status);
result.value = value.get(0) + m_accumulatorOffset;
result.count = count.get(0);
HALUtil.checkStatus(status);
ByteBuffer value = ByteBuffer.allocateDirect(8);
// set the byte order
value.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer count = ByteBuffer.allocateDirect(4);
// set the byte order
count.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asIntBuffer(), status.asIntBuffer());
result.value = value.asLongBuffer().get(0) + m_accumulatorOffset;
result.count = count.asIntBuffer().get(0);
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -434,9 +474,11 @@ public class AnalogChannel extends SensorBase implements PIDSource,
public void setSampleRate(final double samplesPerSecond) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need float comparison with epsilon.
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogSampleRate((float) samplesPerSecond, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogSampleRate((float) samplesPerSecond, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**

View File

@@ -7,12 +7,11 @@
package edu.wpi.first.wpilibj;
import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.nio.ByteBuffer;
import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tModuleType;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tModuleType;
import edu.wpi.first.wpilibj.hal.AnalogJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
/**
@@ -40,7 +39,7 @@ public class AnalogModule extends Module {
* The default sample rate
*/
public static final double kDefaultSampleRate = 50000.0;
private Pointer[] m_ports;
private ByteBuffer[] m_ports;
/**
* Get an instance of an Analog Module.
@@ -70,13 +69,15 @@ public class AnalogModule extends Module {
protected AnalogModule(final int moduleNumber) {
super(tModuleType.kModuleType_Analog, moduleNumber);
m_ports = new Pointer[8];
m_ports = new ByteBuffer[8];
for (int i = 0; i < SensorBase.kAnalogChannels; i++) {
Pointer port_pointer = HALLibrary.getPortWithModule((byte) moduleNumber, (byte) (i+1));
IntBuffer status = IntBuffer.allocate(1);
ByteBuffer port_pointer = AnalogJNI.getPortWithModule((byte) moduleNumber, (byte) (i+1));
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
// XXX: Uncomment when analogchannel has been fixed
// m_ports[i] = HALLibrary.initializeAnalogPort(port_pointer, status);
HALUtil.checkStatus(status);
HALUtil.checkStatus(status.asIntBuffer());
}
}
@@ -91,9 +92,11 @@ public class AnalogModule extends Module {
public void setSampleRate(final double samplesPerSecond) {
// TODO: This will change when variable size scan lists are implemented.
// TODO: Need float comparison with epsilon.
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogSampleRateWithModule((byte) m_moduleNumber, (float) samplesPerSecond, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogSampleRateWithModule((byte) m_moduleNumber, (float) samplesPerSecond, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -105,9 +108,11 @@ public class AnalogModule extends Module {
* @return Sample rate.
*/
public double getSampleRate() {
IntBuffer status = IntBuffer.allocate(1);
double value = HALLibrary.getAnalogSampleRateWithModule((byte) m_moduleNumber, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
double value = AnalogJNI.getAnalogSampleRateWithModule((byte) m_moduleNumber, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -123,9 +128,11 @@ public class AnalogModule extends Module {
* Number of bits to average.
*/
public void setAverageBits(final int channel, final int bits) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogAverageBits(m_ports[channel], bits, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogAverageBits(m_ports[channel], bits, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -139,9 +146,11 @@ public class AnalogModule extends Module {
* @return Bits to average.
*/
public int getAverageBits(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogAverageBits(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogAverageBits(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -156,9 +165,11 @@ public class AnalogModule extends Module {
* @param bits Number of bits to oversample.
*/
public void setOversampleBits(final int channel, final int bits) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogOversampleBits(m_ports[channel], bits, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
AnalogJNI.setAnalogOversampleBits(m_ports[channel], bits, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -172,9 +183,11 @@ public class AnalogModule extends Module {
* @return Bits to oversample.
*/
public int getOversampleBits(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogOversampleBits(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogOversampleBits(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -187,9 +200,11 @@ public class AnalogModule extends Module {
* @return Raw value.
*/
public int getValue(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogValue(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogValue(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -200,9 +215,11 @@ public class AnalogModule extends Module {
* @return The averaged and oversampled raw value.
*/
public int getAverageValue(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogAverageValue(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogAverageValue(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -222,9 +239,11 @@ public class AnalogModule extends Module {
*/
public int voltsToValue(final int channel, final double voltage) {
// wpi_assert(voltage >= -10.0 && voltage <= 10.0);
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogVoltsToValue(m_ports[channel], (float) voltage, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocate(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogVoltsToValue(m_ports[channel], (float) voltage, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -237,9 +256,11 @@ public class AnalogModule extends Module {
* @return The scaled voltage from the channel.
*/
public double getVoltage(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
double value = HALLibrary.getAnalogVoltage(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
double value = AnalogJNI.getAnalogVoltage(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -252,9 +273,11 @@ public class AnalogModule extends Module {
* @return The scaled averaged and oversampled voltage from the channel.
*/
public double getAverageVoltage(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
double value = HALLibrary.getAnalogAverageVoltage(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
double value = AnalogJNI.getAnalogAverageVoltage(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -266,9 +289,11 @@ public class AnalogModule extends Module {
*/
public long getLSBWeight(final int channel) {
// TODO: add scaling to make this worth while.
IntBuffer status = IntBuffer.allocate(1);
long value = HALLibrary.getAnalogLSBWeight(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
long value = AnalogJNI.getAnalogLSBWeight(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -281,9 +306,11 @@ public class AnalogModule extends Module {
public int getOffset(final int channel) {
// TODO: add scaling to make this worth while.
// TODO: actually use this function.
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getAnalogOffset(m_ports[channel], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = AnalogJNI.getAnalogOffset(m_ports[channel], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
}

View File

@@ -8,12 +8,13 @@
package edu.wpi.first.wpilibj;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import com.sun.jna.Pointer;
//import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.AnalogJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.parsing.IInputOutput;
import edu.wpi.first.wpilibj.util.BoundaryException;
@@ -45,7 +46,7 @@ public class AnalogTrigger implements IInputOutput {
/**
* Where the analog trigger is attached
*/
protected Pointer m_port;
protected ByteBuffer m_port;
protected int m_index;
/**
@@ -59,7 +60,7 @@ public class AnalogTrigger implements IInputOutput {
* the port to use for the analog trigger
*/
protected void initTrigger(final int moduleNumber, final int channel) {
Pointer port_pointer = HALLibrary.getPortWithModule(
ByteBuffer port_pointer = AnalogJNI.getPortWithModule(
(byte) moduleNumber, (byte) channel);
IntBuffer status = IntBuffer.allocate(1);
IntBuffer index = IntBuffer.allocate(1);
@@ -114,7 +115,7 @@ public class AnalogTrigger implements IInputOutput {
*/
public void free() {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.cleanAnalogTrigger(m_port, status);
AnalogJNI.cleanAnalogTrigger(m_port, status);
HALUtil.checkStatus(status);
m_port = null;
}
@@ -134,7 +135,7 @@ public class AnalogTrigger implements IInputOutput {
throw new BoundaryException("Lower bound is greater than upper");
}
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogTriggerLimitsRaw(m_port, lower, upper, status);
AnalogJNI.setAnalogTriggerLimitsRaw(m_port, lower, upper, status);
HALUtil.checkStatus(status);
}
@@ -155,7 +156,7 @@ public class AnalogTrigger implements IInputOutput {
// TODO: This depends on the averaged setting. Only raw values will work
// as is.
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogTriggerLimitsVoltage(m_port, (float) lower,
AnalogJNI.setAnalogTriggerLimitsVoltage(m_port, (float) lower,
(float) upper, status);
HALUtil.checkStatus(status);
}
@@ -170,7 +171,7 @@ public class AnalogTrigger implements IInputOutput {
*/
public void setAveraged(boolean useAveragedValue) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogTriggerAveraged(m_port,
AnalogJNI.setAnalogTriggerAveraged(m_port,
(byte) (useAveragedValue ? 1 : 0), status);
HALUtil.checkStatus(status);
}
@@ -186,7 +187,7 @@ public class AnalogTrigger implements IInputOutput {
*/
public void setFiltered(boolean useFilteredValue) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setAnalogTriggerFiltered(m_port,
AnalogJNI.setAnalogTriggerFiltered(m_port,
(byte) (useFilteredValue ? 1 : 0), status);
HALUtil.checkStatus(status);
}
@@ -209,7 +210,7 @@ public class AnalogTrigger implements IInputOutput {
*/
public boolean getInWindow() {
IntBuffer status = IntBuffer.allocate(1);
byte value = HALLibrary.getAnalogTriggerInWindow(m_port, status);
byte value = AnalogJNI.getAnalogTriggerInWindow(m_port, status);
HALUtil.checkStatus(status);
return value != 0;
}
@@ -223,7 +224,7 @@ public class AnalogTrigger implements IInputOutput {
*/
public boolean getTriggerState() {
IntBuffer status = IntBuffer.allocate(1);
byte value = HALLibrary.getAnalogTriggerTriggerState(m_port, status);
byte value = AnalogJNI.getAnalogTriggerTriggerState(m_port, status);
HALUtil.checkStatus(status);
return value != 0;
}

View File

@@ -8,10 +8,11 @@
package edu.wpi.first.wpilibj;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.AnalogJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.parsing.IInputOutput;
@@ -99,7 +100,7 @@ public class AnalogTriggerOutput extends DigitalSource implements IInputOutput {
*/
public boolean get() {
IntBuffer status = IntBuffer.allocate(1);
byte value = HALLibrary.getAnalogTriggerOutput(m_trigger.m_port,
byte value = AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port,
m_outputType, status);
HALUtil.checkStatus(status);
return value != 0;

View File

@@ -8,12 +8,14 @@
package edu.wpi.first.wpilibj;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import edu.wpi.first.wpilibj.can.CANExceptionFactory;
import edu.wpi.first.wpilibj.can.CANJaguarVersionException;
import edu.wpi.first.wpilibj.can.CANLibrary;
import edu.wpi.first.wpilibj.can.CANJNI;
import edu.wpi.first.wpilibj.can.CANTimeoutException;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.HALUtil;
@@ -354,29 +356,29 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
switch (m_controlMode.value) {
case ControlMode.kPercentVbus_val:
messageID = CANLibrary.LM_API_VOLT_T_SET;
messageID = CANJNI.LM_API_VOLT_T_SET;
if (outputValue > 1.0) outputValue = 1.0;
if (outputValue < -1.0) outputValue = -1.0;
packPercentage(dataBuffer, outputValue);
dataSize = 2;
break;
case ControlMode.kSpeed_val: {
messageID = CANLibrary.LM_API_SPD_T_SET;
messageID = CANJNI.LM_API_SPD_T_SET;
dataSize = packFXP16_16(dataBuffer, outputValue);
}
break;
case ControlMode.kPosition_val: {
messageID = CANLibrary.LM_API_POS_T_SET;
messageID = CANJNI.LM_API_POS_T_SET;
dataSize = packFXP16_16(dataBuffer, outputValue);
}
break;
case ControlMode.kCurrent_val: {
messageID = CANLibrary.LM_API_ICTRL_T_SET;
messageID = CANJNI.LM_API_ICTRL_T_SET;
dataSize = packFXP8_8(dataBuffer, outputValue);
}
break;
case ControlMode.kVoltage_val: {
messageID = CANLibrary.LM_API_VCOMP_T_SET;
messageID = CANJNI.LM_API_VCOMP_T_SET;
dataSize = packFXP8_8(dataBuffer, outputValue);
}
break;
@@ -424,31 +426,31 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
switch (m_controlMode.value) {
case ControlMode.kPercentVbus_val:
dataSize = getTransaction(CANLibrary.LM_API_VOLT_SET, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_VOLT_SET, dataBuffer);
if (dataSize == 2) {
return unpackPercentage(dataBuffer);
}
break;
case ControlMode.kSpeed_val:
dataSize = getTransaction(CANLibrary.LM_API_SPD_SET, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_SPD_SET, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kPosition_val:
dataSize = getTransaction(CANLibrary.LM_API_POS_SET, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_POS_SET, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kCurrent_val:
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_SET, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_ICTRL_SET, dataBuffer);
if (dataSize == 2) {
return unpackFXP8_8(dataBuffer);
}
break;
case ControlMode.kVoltage_val:
dataSize = getTransaction(CANLibrary.LM_API_VCOMP_SET, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_VCOMP_SET, dataBuffer);
if (dataSize == 2) {
return unpackFXP8_8(dataBuffer);
}
@@ -548,7 +550,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
long unpackINT32(byte[] buffer) {
return unpack32(buffer,0);
}
private static final byte[] sendTrustedDataBuffer = new byte[kMaxMessageDataSize];
private static final ByteBuffer sendTrustedDataBuffer = ByteBuffer.allocateDirect(kMaxMessageDataSize);
/**
* Send a message on the CAN bus through the CAN driver in FRC_NetworkCommunication
@@ -562,33 +564,58 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
*/
protected static void sendMessage(int messageID, byte[] data, int dataSize) throws CANTimeoutException {
final int[] kTrustedMessages = {
CANLibrary.LM_API_VOLT_T_EN, CANLibrary.LM_API_VOLT_T_SET,
CANLibrary.LM_API_SPD_T_EN, CANLibrary.LM_API_SPD_T_SET,
CANLibrary.LM_API_VCOMP_T_EN, CANLibrary.LM_API_VCOMP_T_SET,
CANLibrary.LM_API_POS_T_EN, CANLibrary.LM_API_POS_T_SET,
CANLibrary.LM_API_ICTRL_T_EN, CANLibrary.LM_API_ICTRL_T_SET
CANJNI.LM_API_VOLT_T_EN, CANJNI.LM_API_VOLT_T_SET,
CANJNI.LM_API_SPD_T_EN, CANJNI.LM_API_SPD_T_SET,
CANJNI.LM_API_VCOMP_T_EN, CANJNI.LM_API_VCOMP_T_SET,
CANJNI.LM_API_POS_T_EN, CANJNI.LM_API_POS_T_SET,
CANJNI.LM_API_ICTRL_T_EN, CANJNI.LM_API_ICTRL_T_SET
};
byte i;
for (i = 0; i < kTrustedMessages.length; i++) {
if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) {
sendTrustedDataBuffer[0] = 0;
sendTrustedDataBuffer[1] = 0;
if ((kFullMessageIDMask & messageID) == kTrustedMessages[i])
{
// Make sure the data will still fit after adjusting for the token.
if (dataSize > kMaxMessageDataSize - 2) {
throw new RuntimeException("CAN message has too much data.");
}
ByteBuffer trustedBuffer = ByteBuffer.allocateDirect(dataSize+2);
trustedBuffer.put(0, (byte)0);
trustedBuffer.put(1, (byte)0);
byte j;
for (j = 0; j < dataSize; j++) {
sendTrustedDataBuffer[j + 2] = data[j];
trustedBuffer.put(j+2, data[j]);
}
CANLibrary.FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, sendTrustedDataBuffer, (byte) sendTrustedDataBuffer.length, IntBuffer.wrap(new int[]{dataSize + 2}));
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
status.asIntBuffer().put(0,dataSize+2);
CANJNI.FRCNetworkCommunicationJaguarCANDriverSendMessage(messageID, trustedBuffer, status.asIntBuffer());
return;
}
}
CANLibrary.FRC_NetworkCommunication_JaguarCANDriver_sendMessage(messageID, data, (byte) data.length, IntBuffer.wrap(new int[]{dataSize}));
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
status.asIntBuffer().put(0,dataSize);
ByteBuffer dataBuffer = null;
if( dataSize > 0)
{
dataBuffer = ByteBuffer.allocateDirect(dataSize);
dataBuffer.put(data);
}
CANJNI.FRCNetworkCommunicationJaguarCANDriverSendMessage(messageID, dataBuffer, status.asIntBuffer());
CANExceptionFactory.checkStatus(status.asIntBuffer().get(0), messageID);
}
/**
@@ -599,17 +626,36 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
* @param timeout Specify how long to wait for a message (in seconds)
*/
protected static byte receiveMessage(int messageID, byte[] data, double timeout) throws CANTimeoutException {
IntBuffer status = IntBuffer.allocate(1);
ByteBuffer dataSize = ByteBuffer.wrap(new byte[]{(byte) data.length});
CANLibrary.FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(
IntBuffer.wrap(new int[]{messageID}), ByteBuffer.wrap(data),
dataSize, (int) timeout, status);
HALUtil.checkStatus(status);
return dataSize.get();
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer messageIDBuffer = ByteBuffer.allocateDirect(4);
messageIDBuffer.order(ByteOrder.LITTLE_ENDIAN);
messageIDBuffer.asIntBuffer().put(0,messageID);
ByteBuffer dataBuffer = CANJNI.FRCNetworkCommunicationJaguarCANDriverReceiveMessage(
messageIDBuffer.asIntBuffer(), (int) (timeout*1000), status.asIntBuffer());
CANExceptionFactory.checkStatus(status.asIntBuffer().get(0), messageID);
byte returnValue = 0;
if( dataBuffer != null )
{
returnValue = (byte)dataBuffer.capacity();
for(int index = 0; index < returnValue; index++)
{
data[index] = dataBuffer.get(index);
}
}
return returnValue;
}
protected static byte receiveMessage(int messageID, byte[] data) throws CANTimeoutException {
return receiveMessage(messageID, data, 0.01);
//return receiveMessage(messageID, data, 0.01);
return receiveMessage(messageID, data, 0.1);
}
/**
@@ -623,7 +669,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
* @param dataSize Specify how much of the data in "data" to send
*/
protected byte setTransaction(int messageID, byte[] data, byte dataSize) throws CANTimeoutException {
int ackMessageID = CANLibrary.LM_API_ACK | m_deviceNumber;
int ackMessageID = CANJNI.LM_API_ACK | m_deviceNumber;
// Make sure we don't have more than one transaction with the same Jaguar outstanding.
synchronized (m_transactionMutex) {
@@ -674,7 +720,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
dataBuffer[0] = reference.value;
setTransaction(CANLibrary.LM_API_SPD_REF, dataBuffer, (byte) 1);
setTransaction(CANJNI.LM_API_SPD_REF, dataBuffer, (byte) 1);
}
/**
@@ -686,7 +732,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize = 0;
dataSize = getTransaction(CANLibrary.LM_API_SPD_REF, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_SPD_REF, dataBuffer);
if (dataSize == 1) {
switch (dataBuffer[0]) {
case SpeedReference.kEncoder_val:
@@ -714,7 +760,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
dataBuffer[0] = reference.value;
setTransaction(CANLibrary.LM_API_POS_REF, dataBuffer, (byte) 1);
setTransaction(CANJNI.LM_API_POS_REF, dataBuffer, (byte) 1);
}
/**
@@ -726,7 +772,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize = 0;
dataSize = getTransaction(CANLibrary.LM_API_POS_REF, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_POS_REF, dataBuffer);
if (dataSize == 1) {
switch (dataBuffer[0]) {
case PositionReference.kPotentiometer_val:
@@ -758,27 +804,27 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
break;
case ControlMode.kSpeed_val:
dataSize = packFXP16_16(dataBuffer, p);
setTransaction(CANLibrary.LM_API_SPD_PC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_SPD_PC, dataBuffer, dataSize);
dataSize = packFXP16_16(dataBuffer, i);
setTransaction(CANLibrary.LM_API_SPD_IC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_SPD_IC, dataBuffer, dataSize);
dataSize = packFXP16_16(dataBuffer, d);
setTransaction(CANLibrary.LM_API_SPD_DC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_SPD_DC, dataBuffer, dataSize);
break;
case ControlMode.kPosition_val:
dataSize = packFXP16_16(dataBuffer, p);
setTransaction(CANLibrary.LM_API_POS_PC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_POS_PC, dataBuffer, dataSize);
dataSize = packFXP16_16(dataBuffer, i);
setTransaction(CANLibrary.LM_API_POS_IC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_POS_IC, dataBuffer, dataSize);
dataSize = packFXP16_16(dataBuffer, d);
setTransaction(CANLibrary.LM_API_POS_DC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_POS_DC, dataBuffer, dataSize);
break;
case ControlMode.kCurrent_val:
dataSize = packFXP16_16(dataBuffer, p);
setTransaction(CANLibrary.LM_API_ICTRL_PC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_ICTRL_PC, dataBuffer, dataSize);
dataSize = packFXP16_16(dataBuffer, i);
setTransaction(CANLibrary.LM_API_ICTRL_IC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_ICTRL_IC, dataBuffer, dataSize);
dataSize = packFXP16_16(dataBuffer, d);
setTransaction(CANLibrary.LM_API_ICTRL_DC, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_ICTRL_DC, dataBuffer, dataSize);
break;
}
}
@@ -798,19 +844,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
// TODO: Error, Not Valid
break;
case ControlMode.kSpeed_val:
dataSize = getTransaction(CANLibrary.LM_API_SPD_PC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_SPD_PC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kPosition_val:
dataSize = getTransaction(CANLibrary.LM_API_POS_PC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_POS_PC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kCurrent_val:
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_PC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_ICTRL_PC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
@@ -834,19 +880,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
// TODO: Error, Not Valid
break;
case ControlMode.kSpeed_val:
dataSize = getTransaction(CANLibrary.LM_API_SPD_IC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_SPD_IC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kPosition_val:
dataSize = getTransaction(CANLibrary.LM_API_POS_IC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_POS_IC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kCurrent_val:
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_IC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_ICTRL_IC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
@@ -870,19 +916,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
// TODO: Error, Not Valid
break;
case ControlMode.kSpeed_val:
dataSize = getTransaction(CANLibrary.LM_API_SPD_DC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_SPD_DC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kPosition_val:
dataSize = getTransaction(CANLibrary.LM_API_POS_DC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_POS_DC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
break;
case ControlMode.kCurrent_val:
dataSize = getTransaction(CANLibrary.LM_API_ICTRL_DC, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_ICTRL_DC, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
@@ -915,20 +961,20 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
switch (m_controlMode.value) {
case ControlMode.kPercentVbus_val:
setTransaction(CANLibrary.LM_API_VOLT_T_EN, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_VOLT_T_EN, dataBuffer, dataSize);
break;
case ControlMode.kSpeed_val:
setTransaction(CANLibrary.LM_API_SPD_T_EN, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_SPD_T_EN, dataBuffer, dataSize);
break;
case ControlMode.kPosition_val:
dataSize = packFXP16_16(dataBuffer, encoderInitialPosition);
setTransaction(CANLibrary.LM_API_POS_T_EN, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_POS_T_EN, dataBuffer, dataSize);
break;
case ControlMode.kCurrent_val:
setTransaction(CANLibrary.LM_API_ICTRL_T_EN, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_ICTRL_T_EN, dataBuffer, dataSize);
break;
case ControlMode.kVoltage_val:
setTransaction(CANLibrary.LM_API_VCOMP_T_EN, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_VCOMP_T_EN, dataBuffer, dataSize);
break;
}
}
@@ -944,19 +990,19 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
switch (m_controlMode.value) {
case ControlMode.kPercentVbus_val:
setTransaction(CANLibrary.LM_API_VOLT_DIS, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_VOLT_DIS, dataBuffer, dataSize);
break;
case ControlMode.kSpeed_val:
setTransaction(CANLibrary.LM_API_SPD_DIS, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_SPD_DIS, dataBuffer, dataSize);
break;
case ControlMode.kPosition_val:
setTransaction(CANLibrary.LM_API_POS_DIS, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_POS_DIS, dataBuffer, dataSize);
break;
case ControlMode.kCurrent_val:
setTransaction(CANLibrary.LM_API_ICTRL_DIS, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_ICTRL_DIS, dataBuffer, dataSize);
break;
case ControlMode.kVoltage_val:
setTransaction(CANLibrary.LM_API_VCOMP_DIS, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_VCOMP_DIS, dataBuffer, dataSize);
break;
}
}
@@ -991,7 +1037,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize = 0;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_CMODE, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_CMODE, dataBuffer);
if (dataSize == 1) {
switch (dataBuffer[0]) {
case ControlMode.kPercentVbus_val:
@@ -1018,7 +1064,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize = 0;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_VOLTBUS, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_VOLTBUS, dataBuffer);
if (dataSize == 2) {
return unpackFXP8_8(dataBuffer);
}
@@ -1035,7 +1081,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte dataSize = 0;
// Read the volt out which is in Volts units.
dataSize = getTransaction(CANLibrary.LM_API_STATUS_VOUT, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_VOUT, dataBuffer);
if (dataSize == 2) {
return unpackFXP8_8(dataBuffer);
}
@@ -1051,7 +1097,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_CURRENT, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_CURRENT, dataBuffer);
if (dataSize == 2) {
return unpackFXP8_8(dataBuffer);
}
@@ -1068,7 +1114,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_TEMP, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_TEMP, dataBuffer);
if (dataSize == 2) {
return unpackFXP8_8(dataBuffer);
}
@@ -1084,7 +1130,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_POS, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_POS, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
@@ -1100,7 +1146,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_SPD, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_SPD, dataBuffer);
if (dataSize == 4) {
return unpackFXP16_16(dataBuffer);
}
@@ -1116,7 +1162,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_LIMIT, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_LIMIT, dataBuffer);
if (dataSize == 1) {
return (dataBuffer[0] & Limits.kForwardLimit_val) != 0;
}
@@ -1132,7 +1178,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_LIMIT, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_LIMIT, dataBuffer);
if (dataSize == 1) {
return (dataBuffer[0] & Limits.kReverseLimit_val) != 0;
}
@@ -1148,7 +1194,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_FAULT, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_FAULT, dataBuffer);
if (dataSize == 2) {
return (short)unpackINT16(dataBuffer);
}
@@ -1167,14 +1213,14 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_STATUS_POWER, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_STATUS_POWER, dataBuffer);
if (dataSize == 1) {
boolean powerCycled = dataBuffer[0] != 0;
// Clear the power cycled bit now that we've accessed it
if (powerCycled) {
dataBuffer[0] = 1;
setTransaction(CANLibrary.LM_API_STATUS_POWER, dataBuffer, (byte) 1);
setTransaction(CANJNI.LM_API_STATUS_POWER, dataBuffer, (byte) 1);
}
return powerCycled;
@@ -1197,11 +1243,11 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
switch (m_controlMode.value) {
case ControlMode.kPercentVbus_val:
dataSize = packPercentage(dataBuffer, rampRate / (m_maxOutputVoltage * kControllerRate));
setTransaction(CANLibrary.LM_API_VOLT_SET_RAMP, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_VOLT_SET_RAMP, dataBuffer, dataSize);
break;
case ControlMode.kVoltage_val:
dataSize = packFXP8_8(dataBuffer, rampRate / kControllerRate);
setTransaction(CANLibrary.LM_API_VCOMP_IN_RAMP, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_VCOMP_IN_RAMP, dataBuffer, dataSize);
break;
default:
return;
@@ -1218,7 +1264,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte dataSize;
// Set the MSB to tell the 2CAN that this is a remote message.
dataSize = getTransaction(0x80000000 | CANLibrary.CAN_MSGID_API_FIRMVER, dataBuffer);
dataSize = getTransaction(0x80000000 | CANJNI.CAN_MSGID_API_FIRMVER, dataBuffer);
if (dataSize == 4) {
return (int)unpackINT32(dataBuffer);
}
@@ -1234,14 +1280,14 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
byte dataSize;
dataSize = getTransaction(CANLibrary.LM_API_HWVER, dataBuffer);
dataSize = getTransaction(CANJNI.LM_API_HWVER, dataBuffer);
if (dataSize == 1 + 1) {
if (dataBuffer[0] == m_deviceNumber) {
return dataBuffer[1];
}
}
// Assume Gray Jag if there is no response
return CANLibrary.LM_HWVER_JAG_1_0;
return CANJNI.LM_HWVER_JAG_1_0;
}
/**
@@ -1255,7 +1301,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
dataBuffer[0] = mode.value;
setTransaction(CANLibrary.LM_API_CFG_BRAKE_COAST, dataBuffer, (byte) 1);
setTransaction(CANJNI.LM_API_CFG_BRAKE_COAST, dataBuffer, (byte) 1);
}
/**
@@ -1268,7 +1314,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte dataSize;
dataSize = packINT16(dataBuffer, (short)codesPerRev);
setTransaction(CANLibrary.LM_API_CFG_ENC_LINES, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_CFG_ENC_LINES, dataBuffer, dataSize);
}
/**
@@ -1284,7 +1330,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte dataSize;
dataSize = packINT16(dataBuffer, (short)turns);
setTransaction(CANLibrary.LM_API_CFG_POT_TURNS, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_CFG_POT_TURNS, dataBuffer, dataSize);
}
/**
@@ -1303,14 +1349,14 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
dataSize = packFXP16_16(dataBuffer, forwardLimitPosition);
dataBuffer[dataSize++] = (forwardLimitPosition > reverseLimitPosition) ? (byte) 1 : (byte) 0;
setTransaction(CANLibrary.LM_API_CFG_LIMIT_FWD, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_CFG_LIMIT_FWD, dataBuffer, dataSize);
dataSize = packFXP16_16(dataBuffer, reverseLimitPosition);
dataBuffer[dataSize++] = forwardLimitPosition <= reverseLimitPosition ? (byte) 1 : (byte) 0;
setTransaction(CANLibrary.LM_API_CFG_LIMIT_REV, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_CFG_LIMIT_REV, dataBuffer, dataSize);
dataBuffer[0] = LimitMode.kSoftPositionLimit_val;
setTransaction(CANLibrary.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
setTransaction(CANJNI.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
}
/**
@@ -1322,7 +1368,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
dataBuffer[0] = LimitMode.kSwitchInputsOnly_val;
setTransaction(CANLibrary.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
setTransaction(CANJNI.LM_API_CFG_LIMIT_MODE, dataBuffer, (byte) 1);
}
/**
@@ -1339,7 +1385,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
m_maxOutputVoltage = voltage;
dataSize = packFXP8_8(dataBuffer, voltage);
setTransaction(CANLibrary.LM_API_CFG_MAX_VOUT, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_CFG_MAX_VOUT, dataBuffer, dataSize);
}
/**
@@ -1356,7 +1402,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
// Message takes ms
dataSize = packINT16(dataBuffer, (short) (faultTime * 1000.0));
setTransaction(CANLibrary.LM_API_CFG_FAULT_TIME, dataBuffer, dataSize);
setTransaction(CANJNI.LM_API_CFG_FAULT_TIME, dataBuffer, dataSize);
}
/**
@@ -1368,7 +1414,7 @@ public class CANJaguar implements MotorSafety, PIDOutput, SpeedController, LiveW
byte[] dataBuffer = new byte[8];
dataBuffer[0] = syncGroup;
sendMessage(CANLibrary.CAN_MSGID_API_SYNC, dataBuffer, 1);
sendMessage(CANJNI.CAN_MSGID_API_SYNC, dataBuffer, 1);
}

View File

@@ -7,7 +7,7 @@
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.IDevice;

View File

@@ -7,13 +7,13 @@
package edu.wpi.first.wpilibj;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.AnalogJNI;
import edu.wpi.first.wpilibj.hal.CounterJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.tables.ITable;
@@ -68,16 +68,21 @@ public class Counter extends SensorBase implements CounterBase,
private DigitalSource m_downSource; // /< What makes the counter count down.
private boolean m_allocatedUpSource;
private boolean m_allocatedDownSource;
private Pointer m_counter; // /< The FPGA counter object.
private ByteBuffer m_counter; // /< The FPGA counter object.
private int m_index; // /< The index of this counter.
private PIDSourceParameter m_pidSource;
private double m_distancePerPulse; // distance of travel for each tick
private void initCounter(final Mode mode) {
IntBuffer status = IntBuffer.allocate(1), index = IntBuffer.allocate(1);
m_counter = HALLibrary.initializeCounter(mode.value, index, status);
HALUtil.checkStatus(status);
m_index = index.get();
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer index = ByteBuffer.allocateDirect(4);
// set the byte order
index.order(ByteOrder.LITTLE_ENDIAN);
m_counter = CounterJNI.initializeCounter(mode.value, index.asIntBuffer(), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_index = index.asIntBuffer().get(0);
m_allocatedUpSource = false;
m_allocatedDownSource = false;
@@ -189,7 +194,7 @@ public class Counter extends SensorBase implements CounterBase,
*/
public Counter(AnalogTrigger trigger) {
initCounter(Mode.kTwoPulse);
setUpSource(trigger.createOutput(HALLibrary.AnalogTriggerType.kState));
setUpSource(trigger.createOutput(AnalogJNI.AnalogTriggerType.kState));
}
public void free() {
@@ -198,9 +203,10 @@ public class Counter extends SensorBase implements CounterBase,
clearUpSource();
clearDownSource();
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.freeCounter(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.freeCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_upSource = null;
m_downSource = null;
@@ -245,12 +251,13 @@ public class Counter extends SensorBase implements CounterBase,
m_allocatedUpSource = false;
}
m_upSource = source;
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterUpSourceWithModule(m_counter,
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterUpSourceWithModule(m_counter,
(byte) source.getModuleForRouting(),
source.getChannelForRouting(),
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status);
HALUtil.checkStatus(status);
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -279,11 +286,12 @@ public class Counter extends SensorBase implements CounterBase,
if (m_upSource == null)
throw new RuntimeException(
"Up Source must be set before setting the edge!");
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterUpSourceEdge(m_counter,
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterUpSourceEdge(m_counter,
(byte) (risingEdge ? 1 : 0), (byte) (fallingEdge ? 1 : 0),
status);
HALUtil.checkStatus(status);
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -296,9 +304,10 @@ public class Counter extends SensorBase implements CounterBase,
}
m_upSource = null;
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.clearCounterUpSource(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.clearCounterUpSource(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -338,16 +347,17 @@ public class Counter extends SensorBase implements CounterBase,
m_downSource.free();
m_allocatedDownSource = false;
}
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterDownSourceWithModule(m_counter,
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterDownSourceWithModule(m_counter,
(byte) source.getModuleForRouting(),
source.getChannelForRouting(),
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status);
if (status.get() == HALLibrary.PARAMETER_OUT_OF_RANGE) {
(byte) (source.getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
if (status.asIntBuffer().get(0) == HALUtil.PARAMETER_OUT_OF_RANGE) {
throw new IllegalArgumentException(
"Counter only supports DownSource in TwoPulse and ExternalDirection modes.");
}
HALUtil.checkStatus(status);
HALUtil.checkStatus(status.asIntBuffer());
m_downSource = source;
}
@@ -377,10 +387,11 @@ public class Counter extends SensorBase implements CounterBase,
if (m_downSource == null)
throw new RuntimeException(
" Down Source must be set before setting the edge!");
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterDownSourceEdge(m_counter, (byte) (risingEdge ? 1
: 0), (byte) (fallingEdge ? 0 : 1), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterDownSourceEdge(m_counter, (byte) (risingEdge ? 1
: 0), (byte) (fallingEdge ? 0 : 1), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -393,9 +404,10 @@ public class Counter extends SensorBase implements CounterBase,
}
m_downSource = null;
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.clearCounterDownSource(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.clearCounterDownSource(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -403,9 +415,10 @@ public class Counter extends SensorBase implements CounterBase,
* are sourced independently from two inputs.
*/
public void setUpDownCounterMode() {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterUpDownMode(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterUpDownMode(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -413,9 +426,10 @@ public class Counter extends SensorBase implements CounterBase,
* counter input. The Down counter input represents the direction to count.
*/
public void setExternalDirectionMode() {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterExternalDirectionMode(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterExternalDirectionMode(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -426,10 +440,11 @@ public class Counter extends SensorBase implements CounterBase,
* true to count up on both rising and falling
*/
public void setSemiPeriodMode(boolean highSemiPeriod) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterSemiPeriodMode(m_counter,
(byte) (highSemiPeriod ? 1 : 0), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterSemiPeriodMode(m_counter,
(byte) (highSemiPeriod ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -442,10 +457,11 @@ public class Counter extends SensorBase implements CounterBase,
* direction. Units are seconds.
*/
public void setPulseLengthMode(double threshold) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterPulseLengthMode(m_counter, (float) threshold,
status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterPulseLengthMode(m_counter, threshold,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -454,9 +470,10 @@ public class Counter extends SensorBase implements CounterBase,
* is not reset on starting, and still has the previous value.
*/
public void start() {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.startCounter(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.startCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -465,9 +482,10 @@ public class Counter extends SensorBase implements CounterBase,
* it might have a different value.
*/
public int get() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getCounter(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
int value = CounterJNI.getCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -487,9 +505,10 @@ public class Counter extends SensorBase implements CounterBase,
* zero.
*/
public void reset() {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.resetCounter(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.resetCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -497,9 +516,10 @@ public class Counter extends SensorBase implements CounterBase,
* value.
*/
public void stop() {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.stopCounter(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.stopCounter(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -513,9 +533,10 @@ public class Counter extends SensorBase implements CounterBase,
* moving in seconds.
*/
public void setMaxPeriod(double maxPeriod) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterMaxPeriod(m_counter, maxPeriod, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterMaxPeriod(m_counter, maxPeriod, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -536,10 +557,11 @@ public class Counter extends SensorBase implements CounterBase,
* true to continue updating
*/
public void setUpdateWhenEmpty(boolean enabled) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterUpdateWhenEmpty(m_counter,
(byte) (enabled ? 1 : 0), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterUpdateWhenEmpty(m_counter,
(byte) (enabled ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -552,9 +574,10 @@ public class Counter extends SensorBase implements CounterBase,
* MaxPeriod value set by SetMaxPeriod.
*/
public boolean getStopped() {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.getCounterStopped(m_counter, status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = CounterJNI.getCounterStopped(m_counter, status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -564,9 +587,10 @@ public class Counter extends SensorBase implements CounterBase,
* @return The last direction the counter value changed.
*/
public boolean getDirection() {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.getCounterDirection(m_counter, status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = CounterJNI.getCounterDirection(m_counter, status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -579,10 +603,11 @@ public class Counter extends SensorBase implements CounterBase,
* true if the value counted should be negated.
*/
public void setReverseDirection(boolean reverseDirection) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterReverseDirection(m_counter,
(byte) (reverseDirection ? 1 : 0), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterReverseDirection(m_counter,
(byte) (reverseDirection ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -593,9 +618,10 @@ public class Counter extends SensorBase implements CounterBase,
* @returns The period of the last two pulses in units of seconds.
*/
public double getPeriod() {
IntBuffer status = IntBuffer.allocate(1);
double value = HALLibrary.getCounterPeriod(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
double value = CounterJNI.getCounterPeriod(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -620,14 +646,15 @@ public class Counter extends SensorBase implements CounterBase,
* The number of samples to average from 1 to 127.
*/
public void setSamplesToAverage(int samplesToAverage) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setCounterSamplesToAverage(m_counter, samplesToAverage,
status);
if (status.get() == HALLibrary.PARAMETER_OUT_OF_RANGE) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
CounterJNI.setCounterSamplesToAverage(m_counter, samplesToAverage,
status.asIntBuffer());
if (status.asIntBuffer().get(0) == HALUtil.PARAMETER_OUT_OF_RANGE) {
throw new BoundaryException(BoundaryException.getMessage(
samplesToAverage, 1, 127));
}
HALUtil.checkStatus(status);
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -640,9 +667,10 @@ public class Counter extends SensorBase implements CounterBase,
* 127)
*/
public int getSamplesToAverage() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getCounterSamplesToAverage(m_counter, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
status.order(ByteOrder.LITTLE_ENDIAN);
int value = CounterJNI.getCounterSamplesToAverage(m_counter, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}

View File

@@ -8,7 +8,7 @@ package edu.wpi.first.wpilibj;
import java.util.Stack;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.parsing.IInputOutput;

View File

@@ -7,12 +7,14 @@
package edu.wpi.first.wpilibj;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.HALLibrary.InterruptHandlerFunction;
import edu.wpi.first.wpilibj.hal.InterruptJNI;
import edu.wpi.first.wpilibj.hal.DIOJNI;
import edu.wpi.first.wpilibj.hal.InterruptJNI.InterruptHandlerFunction;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.IInputOutput;
@@ -64,9 +66,11 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
* @return the stats of the digital input
*/
public boolean get() {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.getDIO(m_port, status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = DIOJNI.getDIO(m_port, status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -106,13 +110,15 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
allocateInterrupts(false);
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
InterruptJNI.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
getChannelForRouting(),
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status);
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
setUpSourceEdge(true, false);
HALLibrary.attachInterruptHandler(m_interrupt, handler, null, status);
HALUtil.checkStatus(status);
InterruptJNI.attachInterruptHandler(m_interrupt, handler, null, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -131,11 +137,13 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
allocateInterrupts(true);
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
InterruptJNI.requestInterrupts(m_interrupt, (byte) getModuleForRouting(),
getChannelForRouting(),
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status);
HALUtil.checkStatus(status);
(byte) (getAnalogTriggerForRouting() ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
setUpSourceEdge(true, false);
}
@@ -150,11 +158,13 @@ public class DigitalInput extends DigitalSource implements IInputOutput,
*/
public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge) {
if (m_interrupt != null) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setInterruptUpSourceEdge(m_interrupt,
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
InterruptJNI.setInterruptUpSourceEdge(m_interrupt,
(byte) (risingEdge ? 1 : 0), (byte) (fallingEdge ? 1 : 0),
status);
HALUtil.checkStatus(status);
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
} else {
throw new IllegalArgumentException(
"You must call RequestInterrupts before setUpSourceEdge");

View File

@@ -6,12 +6,18 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
//import com.sun.jna.Pointer;
//import com.sun.jna.ptr.IntByReference;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tModuleType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tModuleType;
import edu.wpi.first.wpilibj.hal.DIOJNI;
import edu.wpi.first.wpilibj.hal.PWMJNI;
import edu.wpi.first.wpilibj.hal.RelayJNI;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.HALUtil;
@@ -27,9 +33,9 @@ public class DigitalModule extends Module {
*/
public static final int kExpectedLoopTiming = 260;
private int m_module;
private Pointer[] m_digital_ports;
private Pointer[] m_relay_ports;
private Pointer[] m_pwm_ports;
private ByteBuffer[] m_digital_ports;
private ByteBuffer[] m_relay_ports;
private ByteBuffer[] m_pwm_ports;
/**
* Get an instance of an Digital Module. Singleton digital module creation
@@ -46,32 +52,6 @@ public class DigitalModule extends Module {
moduleNumber);
}
/**
* @deprecated
* Convert a channel to its fpga reference
*
* @param channel
* the channel to convert
* @return the converted channel
*/
public static int remapDigitalChannel(final int channel) {
System.err.println("This is going away for compatability reasons. Don't use it.");
return SensorBase.kDigitalChannels - channel;
}
/**
* @deprecated
* Convert a channel from it's fpga reference
*
* @param channel
* the channel to convert
* @return the converted channel
*/
public static int unmapDigitalChannel(final int channel) {
System.err.println("This is going away for compatability reasons. Don't use it.");
return SensorBase.kDigitalChannels - channel;
}
/**
* Create a new digital module
*
@@ -82,33 +62,39 @@ public class DigitalModule extends Module {
super(tModuleType.kModuleType_Digital, moduleNumber);
m_module = moduleNumber;
m_digital_ports = new Pointer[SensorBase.kDigitalChannels];
m_digital_ports = new ByteBuffer[SensorBase.kDigitalChannels];
for (int i = 0; i < SensorBase.kDigitalChannels; i++) {
Pointer port_pointer = HALLibrary.getPortWithModule(
ByteBuffer port_pointer = DIOJNI.getPortWithModule(
(byte) moduleNumber, (byte) (i + 1));
IntBuffer status = IntBuffer.allocate(1);
m_digital_ports[i] = HALLibrary.initializeDigitalPort(port_pointer,
status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
m_digital_ports[i] = DIOJNI.initializeDigitalPort(port_pointer,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
m_relay_ports = new Pointer[SensorBase.kRelayChannels];
m_relay_ports = new ByteBuffer[SensorBase.kRelayChannels];
for (int i = 0; i < SensorBase.kRelayChannels; i++) {
Pointer port_pointer = HALLibrary.getPortWithModule(
ByteBuffer port_pointer = RelayJNI.getPortWithModule(
(byte) moduleNumber, (byte) (i + 1));
IntBuffer status = IntBuffer.allocate(1);
m_relay_ports[i] = HALLibrary.initializeDigitalPort(port_pointer,
status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
m_relay_ports[i] = RelayJNI.initializeDigitalPort(port_pointer,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
m_pwm_ports = new Pointer[SensorBase.kPwmChannels];
m_pwm_ports = new ByteBuffer[SensorBase.kPwmChannels];
for (int i = 0; i < SensorBase.kPwmChannels; i++) {
Pointer port_pointer = HALLibrary.getPortWithModule(
ByteBuffer port_pointer = PWMJNI.getPortWithModule(
(byte) moduleNumber, (byte) (i + 1));
IntBuffer status = IntBuffer.allocate(1);
m_pwm_ports[i] = HALLibrary.initializeDigitalPort(port_pointer,
status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
m_pwm_ports[i] = PWMJNI.initializeDigitalPort(port_pointer,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
}
@@ -123,9 +109,11 @@ public class DigitalModule extends Module {
* The PWM value to set.
*/
public void setPWM(final int channel, final int value) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setPWM(m_pwm_ports[channel - 1], (short) value, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWM(m_pwm_ports[channel - 1], (short) value, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -136,9 +124,11 @@ public class DigitalModule extends Module {
* @return The raw PWM value.
*/
public int getPWM(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
int value = (int) HALLibrary.getPWM(m_pwm_ports[channel - 1], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = (int) PWMJNI.getPWM(m_pwm_ports[channel - 1], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -151,10 +141,12 @@ public class DigitalModule extends Module {
* The 2-bit mask of outputs to squelch.
*/
public void setPWMPeriodScale(final int channel, final int squelchMask) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setPWMPeriodScale(m_pwm_ports[channel - 1], squelchMask,
status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMPeriodScale(m_pwm_ports[channel - 1], squelchMask,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -167,10 +159,12 @@ public class DigitalModule extends Module {
* Indicates whether to set the relay to the On state.
*/
public void setRelayForward(final int channel, final boolean on) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setRelayForward(m_relay_ports[channel - 1], (byte) (on ? 1
: 0), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
RelayJNI.setRelayForward(m_relay_ports[channel - 1], (byte) (on ? 1
: 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -183,10 +177,12 @@ public class DigitalModule extends Module {
* Indicates whether to set the relay to the On state.
*/
public void setRelayReverse(final int channel, final boolean on) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setRelayReverse(m_relay_ports[channel - 1], (byte) (on ? 1
: 0), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
RelayJNI.setRelayReverse(m_relay_ports[channel - 1], (byte) (on ? 1
: 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -197,10 +193,12 @@ public class DigitalModule extends Module {
* @return The current state of the relay.
*/
public boolean getRelayForward(int channel) {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.getRelayForward(m_relay_ports[channel - 1],
status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = RelayJNI.getRelayForward(m_relay_ports[channel - 1],
status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -212,11 +210,13 @@ public class DigitalModule extends Module {
*/
public byte getRelayForward() {
byte value = 0;
IntBuffer status = IntBuffer.allocate(1);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < SensorBase.kRelayChannels; i++) {
value |= HALLibrary.getRelayForward(m_relay_ports[i], status) << i;
value |= RelayJNI.getRelayForward(m_relay_ports[i], status.asIntBuffer()) << i;
}
HALUtil.checkStatus(status);
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -228,10 +228,12 @@ public class DigitalModule extends Module {
* @return The current statte of the relay
*/
public boolean getRelayReverse(int channel) {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.getRelayReverse(m_relay_ports[channel - 1],
status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = RelayJNI.getRelayReverse(m_relay_ports[channel - 1],
status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -243,11 +245,13 @@ public class DigitalModule extends Module {
*/
public byte getRelayReverse() {
byte value = 0;
IntBuffer status = IntBuffer.allocate(1);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < SensorBase.kRelayChannels; i++) {
value |= HALLibrary.getRelayReverse(m_relay_ports[i], status) << i;
value |= RelayJNI.getRelayReverse(m_relay_ports[i], status.asIntBuffer()) << i;
}
HALUtil.checkStatus(status);
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -264,10 +268,12 @@ public class DigitalModule extends Module {
* @return True if the I/O pin was allocated, false otherwise.
*/
public boolean allocateDIO(final int channel, final boolean input) {
IntBuffer status = IntBuffer.allocate(1);
boolean allocated = HALLibrary.allocateDIO(
m_digital_ports[channel - 1], (byte) (input ? 1 : 0), status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean allocated = DIOJNI.allocateDIO(
m_digital_ports[channel - 1], (byte) (input ? 1 : 0), status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return allocated;
}
@@ -278,9 +284,11 @@ public class DigitalModule extends Module {
* The channel whose resources should be freed.
*/
public void freeDIO(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.freeDIO(m_digital_ports[channel - 1], status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
DIOJNI.freeDIO(m_digital_ports[channel - 1], status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -293,10 +301,12 @@ public class DigitalModule extends Module {
* The value to set.
*/
public void setDIO(final int channel, final boolean value) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setDIO(m_digital_ports[channel - 1], (byte) (value ? 1 : 0),
status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
DIOJNI.setDIO(m_digital_ports[channel - 1], (byte) (value ? 1 : 0),
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -308,9 +318,11 @@ public class DigitalModule extends Module {
* @return The value of the selected channel
*/
public boolean getDIO(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.getDIO(m_digital_ports[channel - 1], status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = DIOJNI.getDIO(m_digital_ports[channel - 1], status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -321,12 +333,14 @@ public class DigitalModule extends Module {
* @return The state of all the Digital IO lines in hardware order
*/
public short getAllDIO() {
byte value = 0;
IntBuffer status = IntBuffer.allocate(1);
short value = 0;
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < SensorBase.kDigitalChannels; i++) {
value |= HALLibrary.getDIO(m_digital_ports[i], status) << i;
value |= DIOJNI.getDIO(m_digital_ports[i], status.asIntBuffer()) << i;
}
HALUtil.checkStatus(status);
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -339,10 +353,12 @@ public class DigitalModule extends Module {
* it is an input
*/
public boolean getDIODirection(int channel) {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.getDIODirection(
m_digital_ports[channel - 1], status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = DIOJNI.getDIODirection(
m_digital_ports[channel - 1], status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -355,11 +371,13 @@ public class DigitalModule extends Module {
*/
public short getDIODirection() {
byte value = 0;
IntBuffer status = IntBuffer.allocate(1);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < SensorBase.kDigitalChannels; i++) {
value |= HALLibrary.getDIODirection(m_digital_ports[i], status) << i;
value |= DIOJNI.getDIODirection(m_digital_ports[i], status.asIntBuffer()) << i;
}
HALUtil.checkStatus(status);
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -373,9 +391,11 @@ public class DigitalModule extends Module {
* The length of the pulse.
*/
public void pulse(final int channel, final float pulseLength) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.pulse(m_digital_ports[channel - 1], pulseLength, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
DIOJNI.pulse(m_digital_ports[channel - 1], pulseLength, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -389,13 +409,14 @@ public class DigitalModule extends Module {
* The length of the pulse.
*/
public void pulse(final int channel, final int pulseLength) {
IntBuffer status = IntBuffer.allocate(1);
float convertedPulse = (float) (pulseLength / 1.0e9 * (HALLibrary
.getLoopTiming(status) * 25));
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
float convertedPulse = (float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming(status.asIntBuffer()) * 25));
System.err
.println("You should use the float version of pulse for portability. This is deprecated");
HALLibrary.pulse(m_digital_ports[channel - 1], convertedPulse, status);
HALUtil.checkStatus(status);
DIOJNI.pulse(m_digital_ports[channel - 1], convertedPulse, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -406,10 +427,12 @@ public class DigitalModule extends Module {
* @return True if the channel is pulsing, false otherwise.
*/
public boolean isPulsing(final int channel) {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.isPulsing(m_digital_ports[channel - 1],
status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = DIOJNI.isPulsing(m_digital_ports[channel - 1],
status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -420,9 +443,11 @@ public class DigitalModule extends Module {
*/
public boolean isPulsing() {
boolean value;
IntBuffer status = IntBuffer.allocate(1);
value = HALLibrary.isAnyPulsingWithModule((byte) m_module, status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
value = DIOJNI.isAnyPulsingWithModule((byte) m_module, status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -430,22 +455,24 @@ public class DigitalModule extends Module {
* Allocate a DO PWM Generator. Allocate PWM generators so that they are not
* accidently reused.
*/
public int allocateDO_PWM() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.allocatePWMWithModule((byte) m_module, status)
.getInt(0); // XXX: Hacky, needs heavy testing
HALUtil.checkStatus(status);
public ByteBuffer allocateDO_PWM() {
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer value = PWMJNI.allocatePWMWithModule((byte) m_module, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
/**
* Free the resource associated with a DO PWM generator.
*/
public void freeDO_PWM(int pwmGenerator) {
IntBuffer status = IntBuffer.allocate(1);
Pointer pointer = new IntByReference(pwmGenerator).getPointer();
HALLibrary.freePWMWithModule((byte) m_module, pointer, status);
HALUtil.checkStatus(status);
public void freeDO_PWM(ByteBuffer pwmGenerator) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.freePWMWithModule((byte) m_module, pwmGenerator, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -459,9 +486,11 @@ public class DigitalModule extends Module {
* module.
*/
public void setDO_PWMRate(double rate) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setPWMRateWithModuleIntHack((byte) m_module, Float.floatToIntBits((float) rate), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMRateWithModule((byte) m_module, rate, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -472,12 +501,13 @@ public class DigitalModule extends Module {
* @param channel
* The Digital Output channel to output on
*/
public void setDO_PWMOutputChannel(int pwmGenerator, int channel) {
IntBuffer status = IntBuffer.allocate(1);
Pointer pointer = new IntByReference(pwmGenerator).getPointer();
HALLibrary.setPWMOutputChannelWithModule((byte) m_module, pointer,
channel, status);
HALUtil.checkStatus(status);
public void setDO_PWMOutputChannel(ByteBuffer pwmGenerator, int channel) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMOutputChannelWithModule((byte) m_module, pwmGenerator,
channel, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -488,12 +518,12 @@ public class DigitalModule extends Module {
* @param dutyCycle
* The percent duty cycle to output [0..1].
*/
public void setDO_PWMDutyCycle(int pwmGenerator, double dutyCycle) {
IntBuffer status = IntBuffer.allocate(1);
Pointer pointer = new IntByReference(pwmGenerator).getPointer();
HALLibrary.setPWMDutyCycleWithModuleIntHack((byte) m_module, pointer,
Float.floatToIntBits((float) dutyCycle), status);
HALUtil.checkStatus(status);
public void setDO_PWMDutyCycle(ByteBuffer pwmGenerator, double dutyCycle) {
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMDutyCycleWithModule((byte) m_module, pwmGenerator, dutyCycle, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -513,9 +543,11 @@ public class DigitalModule extends Module {
* @return The number of clock ticks per DIO loop
*/
public int getLoopTiming() {
IntBuffer status = IntBuffer.allocate(1);
int value = HALLibrary.getLoopTiming(status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
int value = DIOJNI.getLoopTiming(status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
}

View File

@@ -7,13 +7,17 @@
package edu.wpi.first.wpilibj;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import com.sun.jna.Pointer;
//import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.DIOJNI;
import edu.wpi.first.wpilibj.hal.PWMJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
import edu.wpi.first.wpilibj.parsing.IInputOutput;
@@ -28,7 +32,7 @@ import edu.wpi.first.wpilibj.tables.ITableListener;
public class DigitalOutput extends DigitalSource implements IInputOutput,
LiveWindowSendable {
private Pointer m_pwmGenerator;
private ByteBuffer m_pwmGenerator;
/**
* Create an instance of a digital output. Create an instance of a digital
@@ -75,9 +79,11 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
* true is on, off is false
*/
public void set(boolean value) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setDIO(m_port, (short) (value ? 1 : 0), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
DIOJNI.setDIO(m_port, (short) (value ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -97,9 +103,11 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
* The length of the pulse.
*/
public void pulse(final int channel, final float pulseLength) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.pulse(m_port, pulseLength, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
DIOJNI.pulse(m_port, pulseLength, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -113,13 +121,14 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
* The length of the pulse.
*/
public void pulse(final int channel, final int pulseLength) {
IntBuffer status = IntBuffer.allocate(1);
float convertedPulse = (float) (pulseLength / 1.0e9 * (HALLibrary
.getLoopTiming(status) * 25));
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
float convertedPulse = (float) (pulseLength / 1.0e9 * (DIOJNI.getLoopTiming(status.asIntBuffer()) * 25));
System.err
.println("You should use the float version of pulse for portability. This is deprecated");
HALLibrary.pulse(m_port, convertedPulse, status);
HALUtil.checkStatus(status);
DIOJNI.pulse(m_port, convertedPulse, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -129,9 +138,11 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
* @return true if pulsing
*/
public boolean isPulsing() {
IntBuffer status = IntBuffer.allocate(1);
boolean value = HALLibrary.isPulsing(m_port, status) != 0;
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
boolean value = DIOJNI.isPulsing(m_port, status.asIntBuffer()) != 0;
HALUtil.checkStatus(status.asIntBuffer());
return value;
}
@@ -148,10 +159,12 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
* module.
*/
public void setPWMRate(double rate) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setPWMRateWithModule((byte) m_moduleNumber, (float) rate,
status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMRateWithModule((byte) m_moduleNumber, rate,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/**
@@ -171,15 +184,17 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
public void enablePWM(double initialDutyCycle) {
if (m_pwmGenerator == null)
return;
IntBuffer status = IntBuffer.allocate(1);
m_pwmGenerator = HALLibrary.allocatePWMWithModule(
(byte) m_moduleNumber, status);
HALUtil.checkStatus(status);
HALLibrary.setPWMDutyCycle(m_pwmGenerator, (float) initialDutyCycle,
status);
HALUtil.checkStatus(status);
HALLibrary.setPWMOutputChannelWithModule((byte) m_moduleNumber,
m_pwmGenerator, m_channel, status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
m_pwmGenerator = PWMJNI.allocatePWMWithModule(
(byte) m_moduleNumber, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.setPWMDutyCycle(m_pwmGenerator, initialDutyCycle,
status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.setPWMOutputChannelWithModule((byte) m_moduleNumber,
m_pwmGenerator, m_channel, status.asIntBuffer());
}
/**
@@ -189,12 +204,13 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
*/
public void disablePWM() {
// Disable the output by routing to a dead bit.
IntBuffer status = IntBuffer.allocate(1);
HALLibrary
.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, status);
HALUtil.checkStatus(status);
HALLibrary.freePWMWithModule((byte) m_moduleNumber, m_pwmGenerator,
status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMOutputChannel(m_pwmGenerator, kDigitalChannels, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
PWMJNI.freePWMWithModule((byte) m_moduleNumber, m_pwmGenerator,
status.asIntBuffer());
m_pwmGenerator = null;
}
@@ -208,10 +224,12 @@ public class DigitalOutput extends DigitalSource implements IInputOutput,
* The duty-cycle to change to. [0..1]
*/
public void updateDutyCycle(double dutyCycle) {
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.setPWMDutyCycleWithModule((byte) m_moduleNumber,
m_pwmGenerator, (float) dutyCycle, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
PWMJNI.setPWMDutyCycleWithModule((byte) m_moduleNumber,
m_pwmGenerator, dutyCycle, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
/*

View File

@@ -7,11 +7,11 @@
package edu.wpi.first.wpilibj;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import com.sun.jna.Pointer;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.hal.DIOJNI;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.util.AllocationException;
import edu.wpi.first.wpilibj.util.CheckedAllocationException;
@@ -27,14 +27,14 @@ public abstract class DigitalSource extends InterruptableSensorBase {
protected static Resource channels = new Resource(kDigitalChannels
* kDigitalModules);
protected Pointer m_port;
protected ByteBuffer m_port;
protected int m_moduleNumber, m_channel;
protected void initDigitalPort(int moduleNumber, int channel, boolean input) {
m_channel = channel;
m_moduleNumber = moduleNumber;
if (HALLibrary.checkDigitalModule((byte) m_moduleNumber) != 1) {
if (DIOJNI.checkDigitalModule((byte) m_moduleNumber) != 1) {
throw new AllocationException("Digital input " + m_channel
+ " on module " + m_moduleNumber
+ " cannot be allocated. Module is not present.");
@@ -51,20 +51,24 @@ public abstract class DigitalSource extends InterruptableSensorBase {
+ " on module " + m_moduleNumber + " is already allocated");
}
Pointer port_pointer = HALLibrary.getPortWithModule(
ByteBuffer port_pointer = DIOJNI.getPortWithModule(
(byte) moduleNumber, (byte) channel);
IntBuffer status = IntBuffer.allocate(1);
m_port = HALLibrary.initializeDigitalPort(port_pointer, status);
HALUtil.checkStatus(status);
HALLibrary.allocateDIO(m_port, (byte) (input ? 1 : 0), status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
m_port = DIOJNI.initializeDigitalPort(port_pointer, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
DIOJNI.allocateDIO(m_port, (byte) (input ? 1 : 0), status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
}
public void free() {
channels.free(((m_moduleNumber - 1) * kDigitalChannels + m_channel - 1));
IntBuffer status = IntBuffer.allocate(1);
HALLibrary.freeDIO(m_port, status);
HALUtil.checkStatus(status);
ByteBuffer status = ByteBuffer.allocateDirect(4);
// set the byte order
status.order(ByteOrder.LITTLE_ENDIAN);
DIOJNI.freeDIO(m_port, status.asIntBuffer());
HALUtil.checkStatus(status.asIntBuffer());
m_channel = 0;
m_moduleNumber = 0;
}
@@ -75,10 +79,7 @@ public abstract class DigitalSource extends InterruptableSensorBase {
* @return channel routing number
*/
public int getChannelForRouting() {
IntBuffer status = IntBuffer.allocate(1);
int channel = HALLibrary.remapDigitalChannel(m_channel - 1, status);
HALUtil.checkStatus(status);
return channel;
return m_channel - 1;
}
/**

View File

@@ -6,7 +6,7 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import edu.wpi.first.wpilibj.communication.FRC_NetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
import edu.wpi.first.wpilibj.communication.UsageReporting;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
@@ -50,28 +50,28 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
* Common function to implement constructor behavior.
*/
private synchronized void initSolenoid() {
checkSolenoidModule(m_moduleNumber);
checkSolenoidChannel(m_forwardChannel);
checkSolenoidChannel(m_reverseChannel);
try {
m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
} catch (CheckedAllocationException e) {
throw new AllocationException(
"Solenoid channel " + m_forwardChannel + " on module " + m_moduleNumber + " is already allocated");
}
try {
m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
} catch (CheckedAllocationException e) {
throw new AllocationException(
"Solenoid channel " + m_reverseChannel + " on module " + m_moduleNumber + " is already allocated");
}
m_forwardMask = (byte) (1 << (m_forwardChannel - 1));
m_reverseMask = (byte) (1 << (m_reverseChannel - 1));
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_forwardChannel, m_moduleNumber-1);
UsageReporting.report(tResourceType.kResourceType_Solenoid, m_reverseChannel, m_moduleNumber-1);
LiveWindow.addActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
// checkSolenoidModule(m_moduleNumber);
// checkSolenoidChannel(m_forwardChannel);
// checkSolenoidChannel(m_reverseChannel);
//
// try {
// m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
// } catch (CheckedAllocationException e) {
// throw new AllocationException(
// "Solenoid channel " + m_forwardChannel + " on module " + m_moduleNumber + " is already allocated");
// }
// try {
// m_allocated.allocate((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
// } catch (CheckedAllocationException e) {
// throw new AllocationException(
// "Solenoid channel " + m_reverseChannel + " on module " + m_moduleNumber + " is already allocated");
// }
// m_forwardMask = (byte) (1 << (m_forwardChannel - 1));
// m_reverseMask = (byte) (1 << (m_reverseChannel - 1));
//
// UsageReporting.report(tResourceType.kResourceType_Solenoid, m_forwardChannel, m_moduleNumber-1);
// UsageReporting.report(tResourceType.kResourceType_Solenoid, m_reverseChannel, m_moduleNumber-1);
// LiveWindow.addActuator("DoubleSolenoid", m_moduleNumber, m_forwardChannel, this);
}
/**
@@ -105,8 +105,8 @@ public class DoubleSolenoid extends SolenoidBase implements LiveWindowSendable {
* Destructor.
*/
public synchronized void free() {
m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
// m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_forwardChannel - 1);
// m_allocated.free((m_moduleNumber - 1) * kSolenoidChannels + m_reverseChannel - 1);
}
/**

View File

@@ -6,10 +6,13 @@
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj;
import com.sun.jna.Pointer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import edu.wpi.first.wpilibj.communication.*;
import edu.wpi.first.wpilibj.hal.HALLibrary;
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
import edu.wpi.first.wpilibj.communication.FRCCommonControlData;
import edu.wpi.first.wpilibj.communication.FRCCommonControlMasks;
import edu.wpi.first.wpilibj.hal.HALUtil;
import edu.wpi.first.wpilibj.parsing.IInputOutput;
/**
@@ -20,7 +23,7 @@ public class DriverStation implements IInputOutput {
/**
* The size of the user status data
*/
public static final int USER_STATUS_DATA_SIZE = FRC_NetworkCommunicationsLibrary.USER_STATUS_DATA_SIZE;
public static final int USER_STATUS_DATA_SIZE = FRCNetworkCommunicationsLibrary.USER_STATUS_DATA_SIZE;
/**
* Slot for the analog module to read the battery
*/
@@ -100,7 +103,7 @@ public class DriverStation implements IInputOutput {
private boolean m_userInTeleop = false;
private boolean m_userInTest = false;
private boolean m_newControlData;
private final Pointer m_packetDataAvailableSem;
private final ByteBuffer m_packetDataAvailableSem;
// XXX: Add DriverStationEnhancedIO back
// private DriverStationEnhancedIO m_enhancedIO = new DriverStationEnhancedIO();
@@ -132,8 +135,12 @@ public class DriverStation implements IInputOutput {
// XXX: Uncomment when analogChannel is fixed
//m_batteryChannel = new AnalogChannel(kBatterySlot, kBatteryChannel);
m_packetDataAvailableSem = HALLibrary.initializeMutex(HALLibrary.SEMAPHORE_Q_PRIORITY.get());
FRC_NetworkCommunicationsLibrary.setNewDataSem(m_packetDataAvailableSem);
m_packetDataAvailableSem = HALUtil.initializeMutexNormal();
// set the byte order
m_packetDataAvailableSem.order(ByteOrder.LITTLE_ENDIAN);
FRCNetworkCommunicationsLibrary.setNewDataSem(m_packetDataAvailableSem);
m_thread = new Thread(new DriverStationTask(this), "FRCDriverStation");
m_thread.setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2);
@@ -154,7 +161,7 @@ public class DriverStation implements IInputOutput {
private void task() {
int safetyCounter = 0;
while (m_thread_keepalive) {
HALLibrary.takeMutex(m_packetDataAvailableSem, HALLibrary.SEMAPHORE_WAIT_FOREVER.get());
HALUtil.takeMutex(m_packetDataAvailableSem);
synchronized (this) {
getData();
// XXX: Add DriverStationEnhancedIO back
@@ -170,16 +177,16 @@ public class DriverStation implements IInputOutput {
safetyCounter = 0;
}
if (m_userInDisabled) {
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramDisabled();
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramDisabled();
}
if (m_userInAutonomous) {
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramAutonomous();
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramAutonomous();
}
if (m_userInTeleop) {
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramTeleop();
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTeleop();
}
if (m_userInTest) {
FRC_NetworkCommunicationsLibrary.FRC_NetworkCommunication_observeUserProgramTest();
FRCNetworkCommunicationsLibrary.FRCNetworkCommunicationObserveUserProgramTest();
}
}
}
@@ -213,7 +220,7 @@ public class DriverStation implements IInputOutput {
* the data will be copied from the DS polling loop.
*/
protected synchronized void getData() {
FRC_NetworkCommunicationsLibrary.getCommonControlData(m_controlData, HALLibrary.SEMAPHORE_WAIT_FOREVER.get());
FRCNetworkCommunicationsLibrary.getCommonControlData(m_controlData);
if (!lastEnabled && isEnabled()) {
// If starting teleop, assume that autonomous just took up 15 seconds
@@ -236,14 +243,13 @@ public class DriverStation implements IInputOutput {
*/
protected void setData() {
synchronized (m_semaphore) {
FRC_NetworkCommunicationsLibrary.setStatusData((float) getBatteryVoltage(),
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(),
HALLibrary.SEMAPHORE_WAIT_FOREVER.get());
m_dashboardInUseLow.getBytesLength());
m_dashboardInUseHigh.flush();
m_dashboardInUseLow.flush();
}
@@ -282,16 +288,16 @@ public class DriverStation implements IInputOutput {
int value;
switch (stick) {
case 1:
value = m_controlData.field2.stick0Axes[axis - 1];
value = m_controlData.stick0Axes[axis - 1];
break;
case 2:
value = m_controlData.field3.stick1Axes[axis - 1];
value = m_controlData.stick1Axes[axis - 1];
break;
case 3:
value = m_controlData.field4.stick2Axes[axis - 1];
value = m_controlData.stick2Axes[axis - 1];
break;
case 4:
value = m_controlData.field5.stick3Axes[axis - 1];
value = m_controlData.stick3Axes[axis - 1];
break;
default:
return 0.0;
@@ -400,7 +406,7 @@ public class DriverStation implements IInputOutput {
* @return True if the robot is enabled, false otherwise.
*/
public boolean isEnabled() {
return (m_controlData.field1.control & FRCCommonControlMasks.ENABLED) != 0;
return (m_controlData.control & FRCCommonControlMasks.ENABLED) != 0;
}
/**
@@ -420,7 +426,7 @@ public class DriverStation implements IInputOutput {
* @return True if autonomous mode should be enabled, false otherwise.
*/
public boolean isAutonomous() {
return (m_controlData.field1.control & FRCCommonControlMasks.AUTONOMOUS) != 0;
return (m_controlData.control & FRCCommonControlMasks.AUTONOMOUS) != 0;
}
/**
@@ -429,7 +435,7 @@ public class DriverStation implements IInputOutput {
* @return True if test mode should be enabled, false otherwise.
*/
public boolean isTest() {
return (m_controlData.field1.control & FRCCommonControlMasks.TEST) != 0;
return (m_controlData.control & FRCCommonControlMasks.TEST) != 0;
}
/**
@@ -588,7 +594,7 @@ public class DriverStation implements IInputOutput {
* @return True if the robot is competing on a field being controlled by a Field Management System
*/
public boolean isFMSAttached() {
return (m_controlData.field1.control & FRCCommonControlMasks.FMS_ATTATCHED) > 0;
return (m_controlData.control & FRCCommonControlMasks.FMS_ATTATCHED) > 0;
}
/**

Some files were not shown because too many files have changed in this diff Show More