Skip to content

Commit f741cc5

Browse files
Added Out of bound check to BK9XXX Driver
1 parent ad83d1a commit f741cc5

10 files changed

+118
-1
lines changed

Drivers/BK9xxx/ACT/LibMCDriver_BK9xxx.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ Custom implementation
265265
<param name="NameExists" type="bool" pass="return" description="Flag if value exists." />
266266
</method>
267267

268+
<method name="AnalogInputIsOutOfBounds" description="Returns if an analog input is out of bounds. The raw values itself will be clipped to the configured range.">
269+
<param name="Name" type="string" pass="in" description="Name of variable. Fails if Variable does not exist or is not an analog variable." />
270+
<param name="InputIsOutOfBounds" type="bool" pass="return" description="Flag if the raw value is out of bounds and has been clipped to the input window." />
271+
</method>
272+
268273
<method name="GetDigitalInput" description="Reads a value from an digital input variable. Fails if variable does not exist.">
269274
<param name="VariableName" type="string" pass="in" description="Name of variable." />
270275
<param name="Value" type="bool" pass="return" description="Result value." />

Drivers/BK9xxx/Headers/CppDynamic/libmcdriver_bk9xxx_dynamic.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ typedef LibMCDriver_BK9xxxResult (*PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogInputE
297297
*/
298298
typedef LibMCDriver_BK9xxxResult (*PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogOutputExistsPtr) (LibMCDriver_BK9xxx_Driver_BK9xxx pDriver_BK9xxx, const char * pName, bool * pNameExists);
299299

300+
/**
301+
* Returns if an analog input is out of bounds. The raw values itself will be clipped to the configured range.
302+
*
303+
* @param[in] pDriver_BK9xxx - Driver_BK9xxx instance.
304+
* @param[in] pName - Name of variable. Fails if Variable does not exist or is not an analog variable.
305+
* @param[out] pInputIsOutOfBounds - Flag if the raw value is out of bounds and has been clipped to the input window.
306+
* @return error code or 0 (success)
307+
*/
308+
typedef LibMCDriver_BK9xxxResult (*PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogInputIsOutOfBoundsPtr) (LibMCDriver_BK9xxx_Driver_BK9xxx pDriver_BK9xxx, const char * pName, bool * pInputIsOutOfBounds);
309+
300310
/**
301311
* Reads a value from an digital input variable. Fails if variable does not exist.
302312
*
@@ -491,6 +501,7 @@ typedef struct {
491501
PLibMCDriver_BK9xxxDriver_BK9xxx_DigitalOutputExistsPtr m_Driver_BK9xxx_DigitalOutputExists;
492502
PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogInputExistsPtr m_Driver_BK9xxx_AnalogInputExists;
493503
PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogOutputExistsPtr m_Driver_BK9xxx_AnalogOutputExists;
504+
PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogInputIsOutOfBoundsPtr m_Driver_BK9xxx_AnalogInputIsOutOfBounds;
494505
PLibMCDriver_BK9xxxDriver_BK9xxx_GetDigitalInputPtr m_Driver_BK9xxx_GetDigitalInput;
495506
PLibMCDriver_BK9xxxDriver_BK9xxx_GetDigitalOutputPtr m_Driver_BK9xxx_GetDigitalOutput;
496507
PLibMCDriver_BK9xxxDriver_BK9xxx_GetAnalogInputRawPtr m_Driver_BK9xxx_GetAnalogInputRaw;

Drivers/BK9xxx/Headers/CppDynamic/libmcdriver_bk9xxx_dynamic.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ class CDriver_BK9xxx : public CDriver {
537537
inline bool DigitalOutputExists(const std::string & sName);
538538
inline bool AnalogInputExists(const std::string & sName);
539539
inline bool AnalogOutputExists(const std::string & sName);
540+
inline bool AnalogInputIsOutOfBounds(const std::string & sName);
540541
inline bool GetDigitalInput(const std::string & sVariableName);
541542
inline bool GetDigitalOutput(const std::string & sVariableName);
542543
inline LibMCDriver_BK9xxx_uint32 GetAnalogInputRaw(const std::string & sVariableName);
@@ -695,6 +696,7 @@ class CDriver_BK9xxx : public CDriver {
695696
pWrapperTable->m_Driver_BK9xxx_DigitalOutputExists = nullptr;
696697
pWrapperTable->m_Driver_BK9xxx_AnalogInputExists = nullptr;
697698
pWrapperTable->m_Driver_BK9xxx_AnalogOutputExists = nullptr;
699+
pWrapperTable->m_Driver_BK9xxx_AnalogInputIsOutOfBounds = nullptr;
698700
pWrapperTable->m_Driver_BK9xxx_GetDigitalInput = nullptr;
699701
pWrapperTable->m_Driver_BK9xxx_GetDigitalOutput = nullptr;
700702
pWrapperTable->m_Driver_BK9xxx_GetAnalogInputRaw = nullptr;
@@ -986,6 +988,15 @@ class CDriver_BK9xxx : public CDriver {
986988
if (pWrapperTable->m_Driver_BK9xxx_AnalogOutputExists == nullptr)
987989
return LIBMCDRIVER_BK9XXX_ERROR_COULDNOTFINDLIBRARYEXPORT;
988990

991+
#ifdef _WIN32
992+
pWrapperTable->m_Driver_BK9xxx_AnalogInputIsOutOfBounds = (PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogInputIsOutOfBoundsPtr) GetProcAddress(hLibrary, "libmcdriver_bk9xxx_driver_bk9xxx_analoginputisoutofbounds");
993+
#else // _WIN32
994+
pWrapperTable->m_Driver_BK9xxx_AnalogInputIsOutOfBounds = (PLibMCDriver_BK9xxxDriver_BK9xxx_AnalogInputIsOutOfBoundsPtr) dlsym(hLibrary, "libmcdriver_bk9xxx_driver_bk9xxx_analoginputisoutofbounds");
995+
dlerror();
996+
#endif // _WIN32
997+
if (pWrapperTable->m_Driver_BK9xxx_AnalogInputIsOutOfBounds == nullptr)
998+
return LIBMCDRIVER_BK9XXX_ERROR_COULDNOTFINDLIBRARYEXPORT;
999+
9891000
#ifdef _WIN32
9901001
pWrapperTable->m_Driver_BK9xxx_GetDigitalInput = (PLibMCDriver_BK9xxxDriver_BK9xxx_GetDigitalInputPtr) GetProcAddress(hLibrary, "libmcdriver_bk9xxx_driver_bk9xxx_getdigitalinput");
9911002
#else // _WIN32
@@ -1246,6 +1257,10 @@ class CDriver_BK9xxx : public CDriver {
12461257
if ( (eLookupError != 0) || (pWrapperTable->m_Driver_BK9xxx_AnalogOutputExists == nullptr) )
12471258
return LIBMCDRIVER_BK9XXX_ERROR_COULDNOTFINDLIBRARYEXPORT;
12481259

1260+
eLookupError = (*pLookup)("libmcdriver_bk9xxx_driver_bk9xxx_analoginputisoutofbounds", (void**)&(pWrapperTable->m_Driver_BK9xxx_AnalogInputIsOutOfBounds));
1261+
if ( (eLookupError != 0) || (pWrapperTable->m_Driver_BK9xxx_AnalogInputIsOutOfBounds == nullptr) )
1262+
return LIBMCDRIVER_BK9XXX_ERROR_COULDNOTFINDLIBRARYEXPORT;
1263+
12491264
eLookupError = (*pLookup)("libmcdriver_bk9xxx_driver_bk9xxx_getdigitalinput", (void**)&(pWrapperTable->m_Driver_BK9xxx_GetDigitalInput));
12501265
if ( (eLookupError != 0) || (pWrapperTable->m_Driver_BK9xxx_GetDigitalInput == nullptr) )
12511266
return LIBMCDRIVER_BK9XXX_ERROR_COULDNOTFINDLIBRARYEXPORT;
@@ -1617,6 +1632,19 @@ class CDriver_BK9xxx : public CDriver {
16171632
return resultNameExists;
16181633
}
16191634

1635+
/**
1636+
* CDriver_BK9xxx::AnalogInputIsOutOfBounds - Returns if an analog input is out of bounds. The raw values itself will be clipped to the configured range.
1637+
* @param[in] sName - Name of variable. Fails if Variable does not exist or is not an analog variable.
1638+
* @return Flag if the raw value is out of bounds and has been clipped to the input window.
1639+
*/
1640+
bool CDriver_BK9xxx::AnalogInputIsOutOfBounds(const std::string & sName)
1641+
{
1642+
bool resultInputIsOutOfBounds = 0;
1643+
CheckError(m_pWrapper->m_WrapperTable.m_Driver_BK9xxx_AnalogInputIsOutOfBounds(m_pHandle, sName.c_str(), &resultInputIsOutOfBounds));
1644+
1645+
return resultInputIsOutOfBounds;
1646+
}
1647+
16201648
/**
16211649
* CDriver_BK9xxx::GetDigitalInput - Reads a value from an digital input variable. Fails if variable does not exist.
16221650
* @param[in] sVariableName - Name of variable.

Drivers/BK9xxx/Implementation/libmcdriver_bk9xxx_analogio.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ using namespace LibMCDriver_BK9xxx::Impl;
5252

5353

5454
CDriver_BK9xxx_AnalogIODefinition::CDriver_BK9xxx_AnalogIODefinition(pugi::xml_node& xmlNode)
55-
: m_nOffset(0), m_nActualRawValue(0), m_nTargetRawValue (0), m_nRawMin (0), m_nRawMax (65535), m_dScaledMin (0.0), m_dScaledMax (100.0)
55+
: m_nOffset(0), m_nActualRawValue(0), m_nTargetRawValue (0), m_nRawMin (0), m_nRawMax (65535), m_dScaledMin (0.0), m_dScaledMax (100.0), m_bActualValueIsOutOfBounds(false)
5656
{
5757

5858
auto offsetAttrib = xmlNode.attribute("offset");
@@ -152,17 +152,25 @@ uint32_t CDriver_BK9xxx_AnalogIODefinition::setActualRawValue(int64_t nRawValue)
152152
{
153153
if (nRawValue < (int64_t)m_nRawMin) {
154154
m_nActualRawValue = m_nRawMin;
155+
m_bActualValueIsOutOfBounds = true;
155156
}
156157
else if (nRawValue > (int64_t)m_nRawMax) {
157158
m_nActualRawValue = m_nRawMax;
159+
m_bActualValueIsOutOfBounds = true;
158160
}
159161
else {
160162
m_nActualRawValue = (uint32_t) nRawValue;
163+
m_bActualValueIsOutOfBounds = false;
161164
}
162165

163166
return m_nActualRawValue;
164167
}
165168

169+
bool CDriver_BK9xxx_AnalogIODefinition::getActualValueIsOutOfBounds() const
170+
{
171+
return m_bActualValueIsOutOfBounds;
172+
}
173+
166174
uint32_t CDriver_BK9xxx_AnalogIODefinition::setTargetRawValue(int64_t nRawValue)
167175
{
168176
if (nRawValue < (int64_t)m_nRawMin) {

Drivers/BK9xxx/Implementation/libmcdriver_bk9xxx_analogio.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ namespace Impl {
8585

8686
std::string m_sUnits;
8787

88+
bool m_bActualValueIsOutOfBounds;
89+
8890

8991
public:
9092

@@ -110,6 +112,8 @@ namespace Impl {
110112
// Returns value that has been set as target.
111113
uint32_t setTargetRawValue(int64_t nRawValue);
112114

115+
bool getActualValueIsOutOfBounds() const;
116+
113117
double rawValueToScaledValue(int64_t nRawValue) const;
114118

115119
uint32_t scaledValueToRawValue(double dScaledValue) const;

Drivers/BK9xxx/Implementation/libmcdriver_bk9xxx_driver_bk9xxx.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,17 @@ bool CDriver_BK9xxx::AnalogOutputExists(const std::string & sName)
726726
return iIter != m_AnalogOutputIOMap.end();
727727
}
728728

729+
bool CDriver_BK9xxx::AnalogInputIsOutOfBounds(const std::string& sName)
730+
{
731+
auto iIter = m_AnalogInputIOMap.find(sName);
732+
if (iIter == m_AnalogInputIOMap.end())
733+
throw ELibMCDriver_BK9xxxInterfaceException(LIBMCDRIVER_BK9XXX_ERROR_ANALOGIONOTFOUND, "analog IO not found: " + sName);
734+
735+
return iIter->second->getActualValueIsOutOfBounds ();
736+
737+
}
738+
739+
729740
bool CDriver_BK9xxx::GetDigitalInput(const std::string & sVariableName)
730741
{
731742
auto iIter = m_DigitalInputIOMap.find(sVariableName);

Drivers/BK9xxx/Implementation/libmcdriver_bk9xxx_driver_bk9xxx.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ namespace LibMCDriver_BK9xxx {
185185

186186
bool AnalogOutputExists(const std::string& sName) override;
187187

188+
bool AnalogInputIsOutOfBounds(const std::string& sName) override;
189+
188190
bool GetDigitalInput(const std::string& sVariableName) override;
189191

190192
bool GetDigitalOutput(const std::string& sVariableName) override;

Drivers/BK9xxx/Interfaces/libmcdriver_bk9xxx_abi.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ LIBMCDRIVER_BK9XXX_DECLSPEC LibMCDriver_BK9xxxResult libmcdriver_bk9xxx_driver_b
310310
*/
311311
LIBMCDRIVER_BK9XXX_DECLSPEC LibMCDriver_BK9xxxResult libmcdriver_bk9xxx_driver_bk9xxx_analogoutputexists(LibMCDriver_BK9xxx_Driver_BK9xxx pDriver_BK9xxx, const char * pName, bool * pNameExists);
312312

313+
/**
314+
* Returns if an analog input is out of bounds. The raw values itself will be clipped to the configured range.
315+
*
316+
* @param[in] pDriver_BK9xxx - Driver_BK9xxx instance.
317+
* @param[in] pName - Name of variable. Fails if Variable does not exist or is not an analog variable.
318+
* @param[out] pInputIsOutOfBounds - Flag if the raw value is out of bounds and has been clipped to the input window.
319+
* @return error code or 0 (success)
320+
*/
321+
LIBMCDRIVER_BK9XXX_DECLSPEC LibMCDriver_BK9xxxResult libmcdriver_bk9xxx_driver_bk9xxx_analoginputisoutofbounds(LibMCDriver_BK9xxx_Driver_BK9xxx pDriver_BK9xxx, const char * pName, bool * pInputIsOutOfBounds);
322+
313323
/**
314324
* Reads a value from an digital input variable. Fails if variable does not exist.
315325
*

Drivers/BK9xxx/Interfaces/libmcdriver_bk9xxx_interfaces.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,13 @@ class IDriver_BK9xxx : public virtual IDriver {
434434
*/
435435
virtual bool AnalogOutputExists(const std::string & sName) = 0;
436436

437+
/**
438+
* IDriver_BK9xxx::AnalogInputIsOutOfBounds - Returns if an analog input is out of bounds. The raw values itself will be clipped to the configured range.
439+
* @param[in] sName - Name of variable. Fails if Variable does not exist or is not an analog variable.
440+
* @return Flag if the raw value is out of bounds and has been clipped to the input window.
441+
*/
442+
virtual bool AnalogInputIsOutOfBounds(const std::string & sName) = 0;
443+
437444
/**
438445
* IDriver_BK9xxx::GetDigitalInput - Reads a value from an digital input variable. Fails if variable does not exist.
439446
* @param[in] sVariableName - Name of variable.

Drivers/BK9xxx/Interfaces/libmcdriver_bk9xxx_interfacewrapper.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,35 @@ LibMCDriver_BK9xxxResult libmcdriver_bk9xxx_driver_bk9xxx_analogoutputexists(Lib
842842
}
843843
}
844844

845+
LibMCDriver_BK9xxxResult libmcdriver_bk9xxx_driver_bk9xxx_analoginputisoutofbounds(LibMCDriver_BK9xxx_Driver_BK9xxx pDriver_BK9xxx, const char * pName, bool * pInputIsOutOfBounds)
846+
{
847+
IBase* pIBaseClass = (IBase *)pDriver_BK9xxx;
848+
849+
try {
850+
if (pName == nullptr)
851+
throw ELibMCDriver_BK9xxxInterfaceException (LIBMCDRIVER_BK9XXX_ERROR_INVALIDPARAM);
852+
if (pInputIsOutOfBounds == nullptr)
853+
throw ELibMCDriver_BK9xxxInterfaceException (LIBMCDRIVER_BK9XXX_ERROR_INVALIDPARAM);
854+
std::string sName(pName);
855+
IDriver_BK9xxx* pIDriver_BK9xxx = dynamic_cast<IDriver_BK9xxx*>(pIBaseClass);
856+
if (!pIDriver_BK9xxx)
857+
throw ELibMCDriver_BK9xxxInterfaceException(LIBMCDRIVER_BK9XXX_ERROR_INVALIDCAST);
858+
859+
*pInputIsOutOfBounds = pIDriver_BK9xxx->AnalogInputIsOutOfBounds(sName);
860+
861+
return LIBMCDRIVER_BK9XXX_SUCCESS;
862+
}
863+
catch (ELibMCDriver_BK9xxxInterfaceException & Exception) {
864+
return handleLibMCDriver_BK9xxxException(pIBaseClass, Exception);
865+
}
866+
catch (std::exception & StdException) {
867+
return handleStdException(pIBaseClass, StdException);
868+
}
869+
catch (...) {
870+
return handleUnhandledException(pIBaseClass);
871+
}
872+
}
873+
845874
LibMCDriver_BK9xxxResult libmcdriver_bk9xxx_driver_bk9xxx_getdigitalinput(LibMCDriver_BK9xxx_Driver_BK9xxx pDriver_BK9xxx, const char * pVariableName, bool * pValue)
846875
{
847876
IBase* pIBaseClass = (IBase *)pDriver_BK9xxx;
@@ -1162,6 +1191,8 @@ LibMCDriver_BK9xxxResult LibMCDriver_BK9xxx::Impl::LibMCDriver_BK9xxx_GetProcAdd
11621191
*ppProcAddress = (void*) &libmcdriver_bk9xxx_driver_bk9xxx_analoginputexists;
11631192
if (sProcName == "libmcdriver_bk9xxx_driver_bk9xxx_analogoutputexists")
11641193
*ppProcAddress = (void*) &libmcdriver_bk9xxx_driver_bk9xxx_analogoutputexists;
1194+
if (sProcName == "libmcdriver_bk9xxx_driver_bk9xxx_analoginputisoutofbounds")
1195+
*ppProcAddress = (void*) &libmcdriver_bk9xxx_driver_bk9xxx_analoginputisoutofbounds;
11651196
if (sProcName == "libmcdriver_bk9xxx_driver_bk9xxx_getdigitalinput")
11661197
*ppProcAddress = (void*) &libmcdriver_bk9xxx_driver_bk9xxx_getdigitalinput;
11671198
if (sProcName == "libmcdriver_bk9xxx_driver_bk9xxx_getdigitaloutput")

0 commit comments

Comments
 (0)