Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions Drivers/CifX/Implementation/libmcdriver_cifx_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Abstract: This is a stub class definition of CChannelInformation
#define CIFX_DEFAULT_HOSTSTATETIMEOUT 5000
#define CIFX_DEFAULT_BUSSTATETIMEOUT 2000
#define CIFX_DEFAULT_SYNCDELAY 10
#define CIFX_DEFAULT_READTIMEOUT 1000
#define CIFX_DEFAULT_WRITETIMEOUT 1000

using namespace LibMCDriver_CifX::Impl;

Expand Down Expand Up @@ -325,7 +327,7 @@ std::vector<uint8_t>& CDriver_CifXChannelBuffer::getBuffer()


CDriver_CifXChannelThreadState::CDriver_CifXChannelThreadState(PCifXSDK pCifXSDK, uint32_t nInputSize, uint32_t nOutputSize, cifxHandle hChannel)
: m_pCifXSDK(pCifXSDK), m_hChannel(hChannel), m_bDebugMode(true), m_InputBuffer(nInputSize), m_OutputBuffer(nOutputSize), m_bThreadIsRunning (false)
: m_pCifXSDK(pCifXSDK), m_hChannel(hChannel), m_bCancelFlag(false), m_bThreadIsRunning(false), m_bDebugMode(true), m_InputBuffer(nInputSize), m_OutputBuffer(nOutputSize)
{
if (pCifXSDK.get() == nullptr)
throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM);
Expand Down Expand Up @@ -576,7 +578,8 @@ void CDriver_CifXChannelThreadState::writeOutputParameter(CDriver_CifXParameter*


CDriver_CifXChannel::CDriver_CifXChannel(pugi::xml_node& channelNode)
: m_nChannelIndex(0), m_nInputSize(0), m_nOutputSize(0), m_nHostStateTimeOut(CIFX_DEFAULT_HOSTSTATETIMEOUT), m_nBusStateTimeOut(CIFX_DEFAULT_BUSSTATETIMEOUT), m_SyncDelay (CIFX_DEFAULT_SYNCDELAY)
: m_nChannelIndex(0), m_nInputSize(0), m_nOutputSize(0), m_nHostStateTimeOut(CIFX_DEFAULT_HOSTSTATETIMEOUT), m_nBusStateTimeOut(CIFX_DEFAULT_BUSSTATETIMEOUT), m_SyncDelay(CIFX_DEFAULT_SYNCDELAY),
m_nReadTimeout(CIFX_DEFAULT_READTIMEOUT), m_nWriteTimeout(CIFX_DEFAULT_WRITETIMEOUT)

{
auto boardAttrib = channelNode.attribute("board");
Expand Down Expand Up @@ -626,6 +629,30 @@ CDriver_CifXChannel::CDriver_CifXChannel(pugi::xml_node& channelNode)
m_nBusStateTimeOut = nBusStateTimeout;
}

auto syncDelayAttrib = channelNode.attribute("syncdelay");
if (!syncDelayAttrib.empty()) {
int nSyncDelay = syncDelayAttrib.as_int(0);
if (nSyncDelay <= 0)
throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM, "invalid syncdelay attribute");
m_SyncDelay = nSyncDelay;
}

auto readTimeoutAttrib = channelNode.attribute("readtimeout");
if (!readTimeoutAttrib.empty()) {
int nReadTimeout = readTimeoutAttrib.as_int(0);
if (nReadTimeout <= 0)
throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM, "invalid readtimeout attribute");
m_nReadTimeout = nReadTimeout;
}

auto writeTimeoutAttrib = channelNode.attribute("writetimeout");
if (!writeTimeoutAttrib.empty()) {
int nWriteTimeout = writeTimeoutAttrib.as_int(0);
if (nWriteTimeout <= 0)
throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM, "invalid writetimeout attribute");
m_nWriteTimeout = nWriteTimeout;
}

auto inputIONode = channelNode.child("input_io");
if (!inputIONode.empty()) {

Expand Down Expand Up @@ -804,8 +831,8 @@ void CDriver_CifXChannel::startSyncThread(PCifXSDK pCifXSDK, cifxHandle hDriverH
uint32_t nBusState = 0;
pCifXSDK->checkError(pCifXSDK->xChannelBusState(hChannel, CIFX_BUS_STATE_ON, &nBusState, m_nBusStateTimeOut));

uint32_t nReadTimeout = 1000;
uint32_t nWriteTimeout = 1000;
uint32_t nReadTimeout = m_nReadTimeout;
uint32_t nWriteTimeout = m_nWriteTimeout;
uint32_t nSyncDelay = m_SyncDelay;

auto pInputs = m_Inputs;
Expand Down
3 changes: 2 additions & 1 deletion Drivers/CifX/Implementation/libmcdriver_cifx_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ namespace Impl {
uint32_t m_nHostStateTimeOut;
uint32_t m_nBusStateTimeOut;
uint32_t m_SyncDelay;
uint32_t m_nReadTimeout;
uint32_t m_nWriteTimeout;

std::shared_ptr<CDriver_CifXChannelThreadState> m_pThreadState;

Expand Down Expand Up @@ -183,4 +185,3 @@ namespace Impl {

#endif // __LIBMCDRIVER_CIFX_CHANNEL


9 changes: 8 additions & 1 deletion Drivers/CifX/Implementation/libmcdriver_cifx_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,25 @@ CDriver_CifXParameter_Integer::~CDriver_CifXParameter_Integer()

int64_t CDriver_CifXParameter_Integer::GetActualIntegerValue()
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
return m_nActualValue;
}

void CDriver_CifXParameter_Integer::SetActualIntegerValue(int64_t nValue)
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
m_nActualValue = nValue;
}

int64_t CDriver_CifXParameter_Integer::GetTargetIntegerValue()
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
return m_nTargetValue;
}

void CDriver_CifXParameter_Integer::SetTargetIntegerValue(int64_t nValue)
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
m_nTargetValue = nValue;
}

Expand All @@ -277,21 +281,25 @@ CDriver_CifXParameter_Double::~CDriver_CifXParameter_Double()

double CDriver_CifXParameter_Double::GetActualDoubleValue()
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
return m_dActualValue;
}

void CDriver_CifXParameter_Double::SetActualDoubleValue(double dValue)
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
m_dActualValue = dValue;
}

double CDriver_CifXParameter_Double::GetTargetDoubleValue()
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
return m_dTargetValue;
}

void CDriver_CifXParameter_Double::SetTargetDoubleValue(double dValue)
{
std::lock_guard<std::mutex> lockGuard(m_ValueMutex);
m_dTargetValue = dValue;
}

Expand All @@ -311,4 +319,3 @@ uint32_t CDriver_CifXParameter_Bool::getBit()
{
return m_nBit;
}

2 changes: 2 additions & 0 deletions Drivers/CifX/Implementation/libmcdriver_cifx_parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ namespace Impl {

class CDriver_CifXParameter_Integer : public CDriver_CifXParameter {
private:
mutable std::mutex m_ValueMutex;
int64_t m_nActualValue;
int64_t m_nTargetValue;

Expand All @@ -129,6 +130,7 @@ namespace Impl {

class CDriver_CifXParameter_Double : public CDriver_CifXParameter {
private:
mutable std::mutex m_ValueMutex;
double m_dActualValue;
double m_dTargetValue;

Expand Down
Loading