-
Notifications
You must be signed in to change notification settings - Fork 207
Description
in example/example.cpp, the function NotifyCallback initialised a variable data using
DataType data{};
DataType is defined earlier as : using DataType = uint8_t;
What happens if the variable is not a uint8_t?
I tried to adapt the code that uses different "using DataType = float" if the variable returned by ADS is a float.
But the compiler fails to compile.
My thinking is to handle different datatypes, i would have to do this:
using boolDataType = bool;
using uint8DataType = uint8_t;
using uint16DataType = uint16_t;
using uint32DataType = uint32_t;
using uint64DataType = uint64_t;
using doubleDataType = double;
using floatDataType = float;
using int8DataType = int8_t;
using int16DataType = int16_t;
using int32DataType = int32_t;
using int64DataType = int64_t;
notificationByName(std::ostream& out, const AdsDevice& route, std::string variableName, int variableType)
{
switch (variableType)
case UA_TYPES_FLOAT :
attrib = {
sizeof(float),
ADSTRANS_SERVERCYCLE,
0,
{4000000}
};
break;
case UA_TYPES_DOUBLE:
attrib = {
sizeof(double),
ADSTRANS_SERVERCYCLE,
0,
{4000000}
};
break;
}
out << FUNCTION << "():\n";
AdsNotification notification { route, variableName, attrib, &NotifyCallback, 0xBEEFDEAD };
::Question: can i pass in variableType using notification? I tried to add to attrib{} but it failed to compile. I then tried to call as a parameter to notification.. also fail to compile.
}
Then in
NotifyCallback(const AmsAddr* pAddr, const AdsNotificationHeader* pNotification, uint32_t hUser)
{
// check the variableType passed in from notification
// if I can get the variableType i will do the following:
if (variableType == uint8_t)
{
uint8DataType booldata{};
std::memcpy(&boolData, pNotification + 1, std::min<size_t>(sizeof(boolData), pNotification->cbSampleSize));
}
else if (variableType == uint16_t)
{
uint16DataType booldata{};
std::memcpy(&boolData, pNotification + 1, std::min<size_t>(sizeof(boolData), pNotification->cbSampleSize));
}
... < and so on for the other datatype>