Skip to content

Commit

Permalink
Merge pull request #32 from nimbuscontrols/issue-31
Browse files Browse the repository at this point in the history
fix issue with uninitialized variables in parameter object
  • Loading branch information
jadamroth authored Aug 14, 2020
2 parents 5e83aa7 + a7c3fd1 commit 09aea43
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
60 changes: 36 additions & 24 deletions src/ParameterObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,36 @@ namespace eipScanner {
: ParameterObject(id, fullAttributes, si, std::make_shared<MessageRouter>()) {
}

ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes, size_t typeSize)
: BaseObject(CLASS_ID, instanceId)
, _hasFullAttributes(fullAttributes)
, _value(typeSize)
, _maxValue(typeSize)
, _minValue(typeSize)
, _defaultValue(typeSize)
, _isScalable(false)
, _isReadOnly(false)
, _scalingMultiplier(1)
, _scalingDivisor(1)
, _scalingBase(1)
, _scalingOffset(0) {
}

ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes,
const SessionInfoIf::SPtr &si,
const MessageRouter::SPtr& messageRouter)
: BaseObject(CLASS_ID, instanceId)
, _name{""}
, _hasFullAttributes{fullAttributes}
, _isScalable{false}
, _messageRouter{messageRouter} {
ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes, size_t typeSize)
: BaseObject(CLASS_ID, instanceId)
, _hasFullAttributes(fullAttributes)
, _value(typeSize)
, _maxValue(typeSize)
, _minValue(typeSize)
, _defaultValue(typeSize)
, _isScalable(false)
, _isReadOnly(false)
, _scalingMultiplier(1)
, _scalingDivisor(1)
, _scalingBase(1)
, _scalingOffset(0)
, _precision(0) {
}

ParameterObject::ParameterObject(cip::CipUint instanceId, bool fullAttributes,
const SessionInfoIf::SPtr &si,
const MessageRouter::SPtr& messageRouter)
: BaseObject(CLASS_ID, instanceId)
, _name{""}
, _hasFullAttributes{fullAttributes}
, _isScalable{false}
, _isReadOnly(false)
, _scalingMultiplier(1)
, _scalingDivisor(1)
, _scalingBase(1)
, _scalingOffset(0)
, _precision(0)
, _messageRouter{messageRouter} {


Logger(LogLevel::DEBUG) << "Read data from parameter ID=" << instanceId;
Expand Down Expand Up @@ -103,7 +110,8 @@ namespace eipScanner {
CipWord descriptor;
buffer >> descriptor >> reinterpret_cast<CipUsint&>(_type);

_isScalable = descriptor & DescriptorAttributeBits::SUPPORTS_SCALING;
_parameter = instanceId;
_isScalable = descriptor & DescriptorAttributeBits::SUPPORTS_SCALING;
_isReadOnly = descriptor & DescriptorAttributeBits::READ_ONLY;
Logger(LogLevel::DEBUG) << "Parameter object ID=" << instanceId
<< " has descriptor=0x" << std::hex << descriptor
Expand Down Expand Up @@ -209,6 +217,10 @@ namespace eipScanner {
return _help;
}

const cip::CipUint &ParameterObject::getParameter() const {
return _parameter;
}

CipUint ParameterObject::getScalingMultiplier() const {
return _scalingMultiplier;
}
Expand Down
7 changes: 7 additions & 0 deletions src/ParameterObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ class ParameterObject : public BaseObject {
*/
const std::string &getHelp() const;

/**
* @brief Gets the number of parameter (instance ID)
* @return
*/
const cip::CipUint &getParameter() const;

/**
* @brief Sets the name [AttrID=7] of the parameter
* @param name
Expand Down Expand Up @@ -357,6 +363,7 @@ class ParameterObject : public BaseObject {
bool _isScalable;
bool _isReadOnly;

cip::CipUint _parameter;
std::vector<uint8_t> _value;
cip::CipDataTypes _type;
std::string _name;
Expand Down

0 comments on commit 09aea43

Please sign in to comment.