148 lines
3.0 KiB
C++
148 lines
3.0 KiB
C++
#include "OutputConnector.h"
|
|
#include "GlobalDefine.h"
|
|
|
|
COutputConnector::COutputConnector()
|
|
{
|
|
}
|
|
|
|
|
|
int COutputConnector::SetOutputPins(QBitArray PinsStates)
|
|
{
|
|
if(mIOModuleRangeEnd >= IO_COUNT)
|
|
{
|
|
qDebug("Logic error in COutputConnector::SetOutputPins; mIOModuleRangeEnd greater than IO count");
|
|
return RET_ERROR;
|
|
}
|
|
if(IsConnectorDefined() == false)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
QBitArray OutputBuf(IO_COUNT);
|
|
|
|
int PinIndex = 0;
|
|
for(int IoPin = mIOModuleRangeBegin; IoPin <= mIOModuleRangeEnd; IoPin++)
|
|
{
|
|
OutputBuf[IoPin] = PinsStates[PinIndex++];
|
|
}
|
|
|
|
mIOInterfaceHandle->SetOutputs(OutputBuf);
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
|
|
QBitArray COutputConnector::GetOutputPinsStates()
|
|
{
|
|
if(IsConnectorDefined() == false)
|
|
{
|
|
return QBitArray();
|
|
}
|
|
|
|
QBitArray IOStates = mIOInterfaceHandle->GetOutputStates();
|
|
QBitArray PinsStates(mPinCount);
|
|
|
|
if(mIOModuleRangeEnd > IOStates.size()) //try not to crash!
|
|
{
|
|
qDebug("Logic error in CInputConnector::GetInputPinsStates(); mIOModuleRangeEnd greater than IO count");
|
|
return QBitArray();
|
|
}
|
|
|
|
int ConnectorPin = 0;
|
|
for(int IoPin = mIOModuleRangeBegin; IoPin <= mIOModuleRangeEnd; IoPin++)
|
|
{
|
|
PinsStates[ConnectorPin++] = IOStates[IoPin];
|
|
}
|
|
|
|
return PinsStates;
|
|
}
|
|
|
|
int COutputConnector::SetConnectorType(CConnectorDefs::eConnectorType type)
|
|
{
|
|
CConnector::SetConnectorType(type);
|
|
|
|
mOutputsPinsStateBuffer.clear();
|
|
mOutputsPinsStateBuffer = QBitArray(mPinCount);
|
|
|
|
ClearAllPins();
|
|
return RET_OK;
|
|
}
|
|
|
|
//! !!!! WARNING, PinIndex IS ZERO-BASED INDEX !!! //
|
|
int COutputConnector::SetSinglePin(unsigned int PinNumber)
|
|
{
|
|
if(IsConnectorDefined() == false)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
int ZeroBasedPinIndex = PinNumber-1;
|
|
|
|
if(ZeroBasedPinIndex >= (int)mPinCount || ZeroBasedPinIndex < 0)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
QBitArray PinsStates(mPinCount);
|
|
PinsStates.setBit(ZeroBasedPinIndex);
|
|
|
|
SetOutputPins(PinsStates);
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
//! !!!! WARNING, PinIndex IS ZERO-BASED INDEX !!! //
|
|
int COutputConnector::GetSinglePinState(unsigned int PinNumber)
|
|
{
|
|
if(IsConnectorDefined() == false)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
int ZeroBasedPinIndex = PinNumber-1;
|
|
|
|
if(ZeroBasedPinIndex > (int)mPinCount || ZeroBasedPinIndex < 0)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
QBitArray CurStates = GetOutputPinsStates();
|
|
|
|
return CurStates.at(ZeroBasedPinIndex);
|
|
}
|
|
|
|
int COutputConnector::TogglePin(unsigned int PinNumber)
|
|
{
|
|
if(IsConnectorDefined() == false)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
int ZeroBasedPinIndex = PinNumber-1;
|
|
|
|
if(ZeroBasedPinIndex > (int)mPinCount || ZeroBasedPinIndex < 0)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
QBitArray CurStates = GetOutputPinsStates();
|
|
|
|
CurStates.toggleBit(ZeroBasedPinIndex);
|
|
SetOutputPins(CurStates);
|
|
|
|
return RET_OK;
|
|
|
|
}
|
|
|
|
int COutputConnector::ClearAllPins()
|
|
{
|
|
if(IsConnectorDefined() == false)
|
|
{
|
|
return RET_ERROR;
|
|
}
|
|
|
|
mIOInterfaceHandle->ResetOutputs();
|
|
return RET_OK;
|
|
}
|