artf3622: Each Solenoid creates handles for all other Solenoids as well

Fixed so that one static handle is called for all Solenoids.

Change-Id: Ib5f3bbaa160d253e0533259bfe0e9e2a6f11733f
This commit is contained in:
jmanning
2015-06-17 14:42:09 -04:00
committed by Kevin O'Connor
parent 39130721d0
commit ead60eaab8
4 changed files with 38 additions and 37 deletions

View File

@@ -9,6 +9,7 @@
#include "SensorBase.h"
#include "HAL/HAL.hpp"
#include "HAL/cpp/Synchronized.hpp"
#include "Port.h"
/**
* SolenoidBase class is the common base class for the Solenoid and
@@ -18,20 +19,19 @@ class SolenoidBase : public SensorBase
{
public:
virtual ~SolenoidBase();
uint8_t GetAll();
uint8_t GetPCMSolenoidBlackList();
bool GetPCMSolenoidVoltageStickyFault();
bool GetPCMSolenoidVoltageFault();
void ClearAllPCMStickyFaults();
uint8_t GetAll(int module = 0);
uint8_t GetPCMSolenoidBlackList(int module);
bool GetPCMSolenoidVoltageStickyFault(int module);
bool GetPCMSolenoidVoltageFault(int module);
void ClearAllPCMStickyFaults(int module);
protected:
explicit SolenoidBase(uint8_t pcmID);
void Set(uint8_t value, uint8_t mask);
void Set(uint8_t value, uint8_t mask, int module);
virtual void InitSolenoid() = 0;
const static int m_maxModules = 63;
const static int m_maxPorts = 8;
static void* m_ports[m_maxModules][m_maxPorts];
uint32_t m_moduleNumber; ///< Slot number where the module is plugged into the chassis.
static Resource *m_allocated;
private:
void* m_ports[kSolenoidChannels];
};

View File

@@ -121,7 +121,7 @@ void DoubleSolenoid::Set(Value value)
break;
}
SolenoidBase::Set(rawValue, m_forwardMask | m_reverseMask);
SolenoidBase::Set(rawValue, m_forwardMask | m_reverseMask, m_moduleNumber);
}
/**
@@ -132,7 +132,7 @@ void DoubleSolenoid::Set(Value value)
DoubleSolenoid::Value DoubleSolenoid::Get()
{
if (StatusIsFatal()) return kOff;
uint8_t value = GetAll();
uint8_t value = GetAll(m_moduleNumber);
if (value & m_forwardMask) return kForward;
if (value & m_reverseMask) return kReverse;
@@ -148,7 +148,7 @@ DoubleSolenoid::Value DoubleSolenoid::Get()
*/
bool DoubleSolenoid::IsFwdSolenoidBlackListed()
{
int blackList = GetPCMSolenoidBlackList();
int blackList = GetPCMSolenoidBlackList(m_moduleNumber);
return (blackList & m_forwardMask) ? 1 : 0;
}
/**
@@ -161,7 +161,7 @@ bool DoubleSolenoid::IsFwdSolenoidBlackListed()
*/
bool DoubleSolenoid::IsRevSolenoidBlackListed()
{
int blackList = GetPCMSolenoidBlackList();
int blackList = GetPCMSolenoidBlackList(m_moduleNumber);
return (blackList & m_reverseMask) ? 1 : 0;
}

View File

@@ -88,7 +88,7 @@ void Solenoid::Set(bool on)
uint8_t value = on ? 0xFF : 0x00;
uint8_t mask = 1 << m_channel;
SolenoidBase::Set(value, mask);
SolenoidBase::Set(value, mask, m_moduleNumber);
}
/**
@@ -99,7 +99,7 @@ void Solenoid::Set(bool on)
bool Solenoid::Get()
{
if (StatusIsFatal()) return false;
uint8_t value = GetAll() & ( 1 << m_channel);
uint8_t value = GetAll(m_moduleNumber) & ( 1 << m_channel);
return (value != 0);
}
/**
@@ -112,7 +112,7 @@ bool Solenoid::Get()
*/
bool Solenoid::IsBlackListed()
{
int value = GetPCMSolenoidBlackList() & ( 1 << m_channel);
int value = GetPCMSolenoidBlackList(m_moduleNumber) & ( 1 << m_channel);
return (value != 0);
}

View File

@@ -9,6 +9,7 @@
// Needs to be global since the protected resource spans all Solenoid objects.
Resource *SolenoidBase::m_allocated = NULL;
void* SolenoidBase::m_ports[m_maxModules][m_maxPorts];
/**
* Constructor
*
@@ -17,12 +18,12 @@ Resource *SolenoidBase::m_allocated = NULL;
SolenoidBase::SolenoidBase(uint8_t moduleNumber)
: m_moduleNumber (moduleNumber)
{
for (uint32_t i = 0; i < kSolenoidChannels; i++)
for (uint32_t i = 0; i < kSolenoidChannels; i++)
{
void* port = getPortWithModule(moduleNumber, i);
int32_t status = 0;
m_ports[i] = initializeSolenoidPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
void* port = getPortWithModule(moduleNumber, i);
int32_t status = 0;
SolenoidBase::m_ports[moduleNumber][i] = initializeSolenoidPort(port, &status);
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
}
@@ -39,13 +40,13 @@ SolenoidBase::~SolenoidBase()
* @param value The value you want to set on the module.
* @param mask The channels you want to be affected.
*/
void SolenoidBase::Set(uint8_t value, uint8_t mask)
void SolenoidBase::Set(uint8_t value, uint8_t mask, int module)
{
int32_t status = 0;
for (int i = 0; i < 8; i++) { // XXX: Unhardcode
for (int i = 0; i < m_maxPorts; i++) {
uint8_t local_mask = 1 << i;
if (mask & local_mask)
setSolenoid(m_ports[i], value & local_mask, &status);
setSolenoid(m_ports[module][i], value & local_mask, &status);
}
wpi_setErrorWithContext(status, getHALErrorMessage(status));
}
@@ -55,12 +56,12 @@ void SolenoidBase::Set(uint8_t value, uint8_t mask)
*
* @return The current value of all 8 solenoids on the module.
*/
uint8_t SolenoidBase::GetAll()
uint8_t SolenoidBase::GetAll(int module)
{
uint8_t value = 0;
int32_t status = 0;
for (int i = 0; i < 8; i++) { // XXX: Unhardcode
value |= getSolenoid(m_ports[i], &status) << i;
for (int i = 0; i < m_maxPorts; i++) {
value |= getSolenoid(m_ports[module][i], &status) << i;
}
return value;
}
@@ -73,30 +74,30 @@ uint8_t SolenoidBase::GetAll()
*
* @return The solenoid blacklist of all 8 solenoids on the module.
*/
uint8_t SolenoidBase::GetPCMSolenoidBlackList()
uint8_t SolenoidBase::GetPCMSolenoidBlackList(int module)
{
int32_t status = 0;
return getPCMSolenoidBlackList(m_ports[0], &status);
return getPCMSolenoidBlackList(m_ports[module][0], &status);
}
/**
* @return true if PCM sticky fault is set : The common
* highside solenoid voltage rail is too low,
* most likely a solenoid channel is shorted.
*/
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault()
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module)
{
int32_t status = 0;
return getPCMSolenoidVoltageStickyFault(m_ports[0], &status);
return getPCMSolenoidVoltageStickyFault(m_ports[module][0], &status);
}
/**
* @return true if PCM is in fault state : The common
* highside solenoid voltage rail is too low,
* most likely a solenoid channel is shorted.
*/
bool SolenoidBase::GetPCMSolenoidVoltageFault()
bool SolenoidBase::GetPCMSolenoidVoltageFault(int module)
{
int32_t status = 0;
return getPCMSolenoidVoltageFault(m_ports[0], &status);
return getPCMSolenoidVoltageFault(m_ports[module][0], &status);
}
/**
* Clear ALL sticky faults inside PCM that Compressor is wired to.
@@ -108,8 +109,8 @@ bool SolenoidBase::GetPCMSolenoidVoltageFault()
*
* If no sticky faults are set then this call will have no effect.
*/
void SolenoidBase::ClearAllPCMStickyFaults()
void SolenoidBase::ClearAllPCMStickyFaults(int module)
{
int32_t status = 0;
return clearAllPCMStickyFaults_sol(m_ports[0], &status);
return clearAllPCMStickyFaults_sol(m_ports[module][0], &status);
}