Ejemplo n.º 1
0
    // Fill out an ExpandedNodeId
    // =============================================================================================
    Status NamespaceArray::fillExpandedNodeId(
            const OpcUa_ExpandedNodeId& opcUaExpandedNodeId,
            ExpandedNodeId&             expandedNodeId) const
    {
        Status ret;

        string namespaceUri;

        // according to the OPC UA specs, if the opcUaExpandedNodeId contains a namespaceUri,
        // then the namespaceIndex should be ignored.

        // So, if a non-empty namespace URI is already given, then we use that one.
        // Else, we try to find the namespace URI that corresponds to the given namespace index.
        if (!UaString(&opcUaExpandedNodeId.NamespaceUri).isEmpty())
        {
            // bugfix: added the following line: also in this situation the attributes from the SDK need to be copied!
            expandedNodeId.fromSdk(opcUaExpandedNodeId);

            NodeId nodeId = expandedNodeId.nodeId();
            nodeId.setNameSpaceUri(string(UaString(&opcUaExpandedNodeId.NamespaceUri).toUtf8()));
            expandedNodeId.setNodeId(nodeId);
            ret.isGood();
        }
        else if (findNamespaceUri(opcUaExpandedNodeId.NodeId.NamespaceIndex, namespaceUri))
        {
            ret = expandedNodeId.fromSdk(opcUaExpandedNodeId, namespaceUri);
        }
        else
        {
            ret = EmptyServerUriAndUnknownNamespaceIndexError(
                    opcUaExpandedNodeId.NodeId.NamespaceIndex);
        }

        return ret;
    }
Ejemplo n.º 2
0
UaString UaNodeId::identifierString() const
{
    if (m_impl.identifierType != UA_NODEIDTYPE_STRING)
        throw std::runtime_error("asking for identifierString from a non-string identifier!");
    return UaString( &m_impl.identifier.string );

}
Ejemplo n.º 3
0
 // Static function to get the time from a string representation.
 // =============================================================================================
 DateTime DateTime::fromString(const string& s)
 {
     UaDateTime uaDateTime = UaDateTime::fromString(UaString(s.c_str()));
     DateTime ret;
     ret.fromSdk(uaDateTime);
     return ret;
 }
Ejemplo n.º 4
0
 // Set the variant to a string array.
 // =============================================================================================
 void Variant::setStringArray(const std::vector<std::string>& vec)
 {
     clear();
     UaStringArray arr;
     arr.create(vec.size());
     for (std::size_t i = 0; i < vec.size(); i++) { UaString(vec[i].c_str()).copyTo(&arr[i]); }
     uaVariant_.setStringArray(arr);
 }
Ejemplo n.º 5
0
 // Convert the variant to a string array.
 // =============================================================================================
 Status Variant::toStringArray(std::vector<std::string>& vec) const
 {
     UaStringArray arr;
     Status ret = evaluate(uaVariant_.toStringArray(arr), uaVariant_.type(), OpcUaType_String);
     vec.resize(arr.length());
     for (std::size_t i = 0; i < arr.length(); i++)
         vec[i] = string(UaString(&arr[i]).toUtf8());
     return ret;
 }
Ejemplo n.º 6
0
UaString UaNodeId::toFullString() const
{
    if (identifierType() == IdentifierType::OpcUa_IdentifierType_String)
    {
        std::string s = "(ns="+boost::lexical_cast<std::string>(namespaceIndex())+","+UaString(identifierString()).toUtf8()+")";
        return UaString(s.c_str());
    }
    else
        return toString();
}
Ejemplo n.º 7
0
UaString UaNodeId::toString() const
{
    if (identifierType() == IdentifierType::OpcUa_IdentifierType_String)
    {
        return identifierString();
    }
    else if (identifierType() == IdentifierType::OpcUa_IdentifierType_Numeric)
    {
        std::string s = "(ns="+boost::lexical_cast<std::string>(namespaceIndex())+","+boost::lexical_cast<std::string>(identifierNumeric())+")";
        return UaString(s.c_str());
    }
    return "identifier-type-unsupported";
}
Ejemplo n.º 8
0
/*ctr*/
ASServer::ASServer (
    UaNodeId parentNodeId,
    const UaNodeId& typeNodeId,
    ASNodeManager *nm,
    const Configuration::Server & config):
    OpcUa::BaseObjectType (
        /*nodeId*/nm->makeChildNodeId(parentNodeId,"Server"), "Server", nm->getNameSpaceIndex(), nm),
    m_typeNodeId (typeNodeId)


    ,
    m_connectedClientCount (new

                            OpcUa::BaseDataVariableType


                            (nm->makeChildNodeId(this->nodeId(),UaString("connectedClientCount")), UaString("connectedClientCount"), nm->getNameSpaceIndex(), UaVariant(

                                 OpcUa_UInt32( 0 )

                             ),

                             OpcUa_AccessLevels_CurrentRead
                             , nm))



    ,
    m_deviceLink (0)


{
    UaStatus s;
    UaVariant v;

    v.setUInt32
    ( 0 );

    m_connectedClientCount->setValue(/*pSession*/0, UaDataValue(UaVariant( v ),
            OpcUa_Good, UaDateTime::now(), UaDateTime::now() ), /*check access level*/OpcUa_False);

    s = nm->addNodeAndReference(this, m_connectedClientCount, OpcUaId_HasComponent);
    if (!s.isGood())
    {
        std::cout << "While addNodeAndReference from " << this->nodeId().toString().toUtf8() << " to " << m_connectedClientCount->nodeId().toString().toUtf8() << " : " << std::endl;
        ASSERT_GOOD(s);
    }



}
Ejemplo n.º 9
0
 // Set the variant to a string.
 // =============================================================================================
 void Variant::setString(const std::string& val)
 {
     clear();
     uaVariant_.setString(UaString(val.c_str()));
 }
Ejemplo n.º 10
0
    // Convert a uaf::NodeId to a OpcUa_NodeId
    // =============================================================================================
    Status NamespaceArray::fillOpcUaNodeId(
            const NodeId& nodeId,
            OpcUa_NodeId& opcUaNodeId) const
    {
        Status ret;

        // we need to get a valid namespace index
        NameSpaceIndex nameSpaceIndex;

        // check if the browse name has a namespace URI for which we can find an index
        if (nodeId.hasNameSpaceUri())
        {

            if (findNamespaceIndex(nodeId.nameSpaceUri(), nameSpaceIndex))
                ret = statuscodes::Good;
            else
                ret = UnknownNamespaceUriError(
                        nodeId.nameSpaceUri(),
                        nameSpaceMap_,
                        toString(nameSpaceMap_));
        }
        else if (nodeId.hasNameSpaceIndex())
        {
            // OK we don't have a namespace URI but we do have a namespace index
            nameSpaceIndex = nodeId.nameSpaceIndex();
            ret = statuscodes::Good;
        }
        else
        {
            // we have no possible means to get the namespace index
            ret = NoNamespaceIndexOrUriGivenError();
        }


        // if the namespace index was found, update the OpcUa_NodeId
        if (ret.isGood())
        {
            UaNodeId uaNodeId;
            // update the NodeId identifier
            if (nodeId.identifier().type == nodeididentifiertypes::Identifier_Numeric)
            {
                uaNodeId.setNodeId(nodeId.identifier().idNumeric, nameSpaceIndex);
                uaNodeId.copyTo(&opcUaNodeId);
            }
            else if (nodeId.identifier().type == nodeididentifiertypes::Identifier_String)
            {
                uaNodeId.setNodeId(UaString(nodeId.identifier().idString.c_str()), nameSpaceIndex);
                uaNodeId.copyTo(&opcUaNodeId);
            }
            else if (nodeId.identifier().type == nodeididentifiertypes::Identifier_Guid)
            {
                UaGuid uaGuid;
                nodeId.identifier().idGuid.toSdk(uaGuid);
                uaNodeId.setNodeId(uaGuid, nameSpaceIndex);
                uaNodeId.copyTo(&opcUaNodeId);
            }
            else if (nodeId.identifier().type == nodeididentifiertypes::Identifier_Opaque)
            {
                UaByteString uaByteString;
                nodeId.identifier().idOpaque.toSdk(uaByteString);
                uaNodeId.setNodeId(uaByteString, nameSpaceIndex);
                uaNodeId.copyTo(&opcUaNodeId);
            }
            else
            {
                ret = UnsupportedNodeIdIdentifierTypeError();
            }
        }

        return ret;
    }