2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "SensorBase.h"
|
|
|
|
|
|
2016-05-26 20:20:58 -07:00
|
|
|
#include "FRC_NetworkCommunication/LoadOut.h"
|
2016-05-22 21:41:22 -07:00
|
|
|
#include "HAL/HAL.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "WPIErrors.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
const uint32_t SensorBase::kDigitalChannels;
|
2014-06-12 18:07:45 -04:00
|
|
|
const uint32_t SensorBase::kAnalogInputs;
|
2013-12-15 18:30:16 -05:00
|
|
|
const uint32_t SensorBase::kSolenoidChannels;
|
|
|
|
|
const uint32_t SensorBase::kSolenoidModules;
|
|
|
|
|
const uint32_t SensorBase::kPwmChannels;
|
|
|
|
|
const uint32_t SensorBase::kRelayChannels;
|
2014-05-30 14:04:05 -04:00
|
|
|
const uint32_t SensorBase::kPDPChannels;
|
2013-12-15 18:30:16 -05:00
|
|
|
const uint32_t SensorBase::kChassisSlots;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that the solenoid module number is valid.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Solenoid module is valid and present
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckSolenoidModule(uint8_t moduleNumber) {
|
|
|
|
|
if (moduleNumber < 64) return true;
|
|
|
|
|
return false;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that the digital channel number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the channel number is one of the legal channel numbers. Channel
|
2016-05-20 17:30:37 -07:00
|
|
|
* numbers are 1-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Digital channel is valid
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckDigitalChannel(uint32_t channel) {
|
|
|
|
|
if (channel < kDigitalChannels) return true;
|
|
|
|
|
return false;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-06-29 18:58:14 -07:00
|
|
|
* Check that the relay channel number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the channel number is one of the legal channel numbers. Channel
|
2016-06-29 18:58:14 -07:00
|
|
|
* numbers are 0-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Relay channel is valid
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckRelayChannel(uint32_t channel) {
|
2016-07-09 00:24:26 -07:00
|
|
|
return HAL_CheckRelayChannel((uint8_t)channel);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that the digital channel number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the channel number is one of the legal channel numbers. Channel
|
2016-05-20 17:30:37 -07:00
|
|
|
* numbers are 1-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return PWM channel is valid
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckPWMChannel(uint32_t channel) {
|
|
|
|
|
if (channel < kPwmChannels) return true;
|
|
|
|
|
return false;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-12 18:07:45 -04:00
|
|
|
* Check that the analog input number is value.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the analog input number is one of the legal channel numbers.
|
2016-05-20 17:30:37 -07:00
|
|
|
* Channel numbers are 0-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Analog channel is valid
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckAnalogInput(uint32_t channel) {
|
|
|
|
|
if (channel < kAnalogInputs) return true;
|
|
|
|
|
return false;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-06-12 18:07:45 -04:00
|
|
|
/**
|
2014-06-24 10:37:02 -07:00
|
|
|
* Check that the analog output number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the analog output number is one of the legal channel numbers.
|
2016-05-20 17:30:37 -07:00
|
|
|
* Channel numbers are 0-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
|
|
|
|
* @return Analog channel is valid
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckAnalogOutput(uint32_t channel) {
|
|
|
|
|
if (channel < kAnalogOutputs) return true;
|
|
|
|
|
return false;
|
2014-06-12 18:07:45 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Verify that the solenoid channel number is within limits.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Solenoid channel is valid
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckSolenoidChannel(uint32_t channel) {
|
|
|
|
|
if (channel < kSolenoidChannels) return true;
|
|
|
|
|
return false;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-05-30 14:04:05 -04:00
|
|
|
/**
|
|
|
|
|
* Verify that the power distribution channel number is within limits.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2014-06-24 10:37:02 -07:00
|
|
|
* @return PDP channel is valid
|
2014-05-30 14:04:05 -04:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool SensorBase::CheckPDPChannel(uint32_t channel) {
|
|
|
|
|
if (channel < kPDPChannels) return true;
|
|
|
|
|
return false;
|
2014-05-30 14:04:05 -04:00
|
|
|
}
|