Browse Source

powerlink example

engel 5 years ago
parent
commit
b2204508d3

+ 36 - 0
examples/nodeset/CMakeLists.txt

@@ -75,3 +75,39 @@ if(UA_NAMESPACE_ZERO STREQUAL "FULL")
     
 
 endif()
+
+# PLCopen requires the full ns0 as basis
+if(UA_NAMESPACE_ZERO STREQUAL "FULL")
+
+    # Generate types and namespace for DI
+    #ua_generate_nodeset_and_datatypes(
+    #    NAME "di"
+    #    FILE_CSV "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/OpcUaDiModel.csv"
+    #    FILE_BSD "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.Types.bsd"
+    #    NAMESPACE_IDX 2
+    #    FILE_NS "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/DI/Opc.Ua.Di.NodeSet2.xml"
+    #    INTERNAL
+    #)
+
+    # generate powerlink namespace which is using DI
+    ua_generate_nodeset_and_datatypes(
+        NAME "powerlink"
+        # PLCopen does not define custom types. Only generate the nodeset
+        FILE_CSV "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/POWERLINK/Opc.Ua.POWERLINK.NodeIds.csv"
+        FILE_BSD "${PROJECT_SOURCE_DIR}/examples/nodeset/Opc.Ua.POWERLINK.NodeSet2.bsd"
+        NAMESPACE_IDX 3
+        FILE_NS "${PROJECT_SOURCE_DIR}/deps/ua-nodeset/POWERLINK/Opc.Ua.POWERLINK.NodeSet2.xml"
+        # PLCopen depends on the di nodeset, which must be generated before
+        DEPENDS "di"
+        INTERNAL
+    )
+
+    add_example(server_nodeset_powerlink server_nodeset_powerlink.c
+                ${PROJECT_BINARY_DIR}/src_generated/ua_types_di_generated.c
+                ${PROJECT_BINARY_DIR}/src_generated/ua_types_powerlink_generated.c
+                ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_di.c
+                ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_powerlink.c)
+    add_dependencies(server_nodeset_plcopen open62541-generator-ns-powerlink)
+    
+
+endif()

+ 58 - 0
examples/nodeset/Opc.Ua.POWERLINK.NodeSet2.bsd

@@ -0,0 +1,58 @@
+<opc:TypeDictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://opcfoundation.org/UA/POWERLINK/" DefaultByteOrder="LittleEndian" xmlns:opc="http://opcfoundation.org/BinarySchema/" xmlns:ua="http://opcfoundation.org/UA/" TargetNamespace="http://opcfoundation.org/UA/POWERLINK/">
+    <opc:Import Namespace="http://opcfoundation.org/UA/"/>
+    <opc:StructuredType BaseType="ua:ExtensionObject" Name="ErrorRegisterBits">
+        <opc:Documentation>Represents the values of the POWERLINK ErrorRegister </opc:Documentation>
+        <opc:Field TypeName="opc:ByteString" Name="Value"/>
+        <opc:Field TypeName="opc:ByteString" Name="ValidBits"/>
+    </opc:StructuredType>
+    <opc:StructuredType BaseType="ua:ExtensionObject" Name="PowerlinkAttribute">
+        <opc:Documentation>Represents the POWERLINK entry attributes</opc:Documentation>
+        <opc:Field TypeName="opc:ByteString" Name="Value"/>
+        <opc:Field TypeName="opc:ByteString" Name="ValidBits"/>
+    </opc:StructuredType>
+    <opc:StructuredType BaseType="ua:ExtensionObject" Name="PowerlinkErrorEntryDataType">
+        <opc:Documentation>Represents the entries of the POWERLINK Object ERR_History_ADOM (Object 1003h, SubIndex 1..254)</opc:Documentation>
+        <opc:Field TypeName="opc:UInt16" Name="entryType"/>
+        <opc:Field TypeName="opc:UInt16" Name="errorCode"/>
+        <opc:Field TypeName="opc:UInt64" Name="timeStamp"/>
+        <opc:Field TypeName="opc:UInt64" Name="additionalInformation"/>
+    </opc:StructuredType>
+    <opc:StructuredType BaseType="ua:ExtensionObject" Name="PowerlinkIpAddressDataType">
+        <opc:Documentation>Structure DataType PowerlinkIpAddressDataType to represent POWERLINK Objects of the POWERLINK data type IP_ADDRESS</opc:Documentation>
+        <opc:Field TypeName="opc:Byte" Name="b1"/>
+        <opc:Field TypeName="opc:Byte" Name="b2"/>
+        <opc:Field TypeName="opc:Byte" Name="b3"/>
+        <opc:Field TypeName="opc:Byte" Name="b4"/>
+    </opc:StructuredType>
+    <opc:StructuredType BaseType="ua:ExtensionObject" Name="PowerlinkPDOMappingEntryDataType">
+        <opc:Documentation>Structure DataType PowerlinkPDOMappingEntryDataType to represent the entries of POWERLINK Objects like PDO_RxCommParam_00h_REC</opc:Documentation>
+        <opc:Field TypeName="opc:UInt16" Name="length"/>
+        <opc:Field TypeName="opc:UInt16" Name="offset"/>
+        <opc:Field TypeName="opc:Byte" Name="reserved"/>
+        <opc:Field TypeName="opc:Byte" Name="subIndex"/>
+        <opc:Field TypeName="opc:UInt16" Name="index"/>
+    </opc:StructuredType>
+    <opc:EnumeratedType LengthInBits="32" Name="PowerlinkNMTResetCmdEnumeration">
+        <opc:Documentation>This DataType is an Enumeration that represents the NMT reset commands for POWERLINK</opc:Documentation>
+        <opc:EnumeratedValue Name="NMTResetNode" Value="40"/>
+        <opc:EnumeratedValue Name="NMTResetCommunication" Value="41"/>
+        <opc:EnumeratedValue Name="NMTResetConfiguration" Value="42"/>
+        <opc:EnumeratedValue Name="NMTSwReset" Value="43"/>
+        <opc:EnumeratedValue Name="NMTInvalidService" Value="255"/>
+    </opc:EnumeratedType>
+    <opc:EnumeratedType LengthInBits="32" Name="PowerlinkNMTStateEnumeration">
+        <opc:Documentation>This DataType is an enumeration that represents the NMT State</opc:Documentation>
+        <opc:EnumeratedValue Name="NMT_GS_OFF " Value="0"/>
+        <opc:EnumeratedValue Name="NMT_GS_INITIALISING" Value="25"/>
+        <opc:EnumeratedValue Name="NMT_GS_RESET_APPLICATION" Value="41"/>
+        <opc:EnumeratedValue Name="NMT_GS_RESET_COMMUNICATION" Value="57"/>
+        <opc:EnumeratedValue Name="NMT_GS_RESET_CONFIGURATION" Value="121"/>
+        <opc:EnumeratedValue Name="NMT_XS_NOT_ACTIVE" Value="28"/>
+        <opc:EnumeratedValue Name="NMT_XS_PRE_OPERATIONAL_1" Value="29"/>
+        <opc:EnumeratedValue Name="NMT_XS_PRE_OPERATIONAL_2" Value="93"/>
+        <opc:EnumeratedValue Name="NMT_XS_READY_TO_OPERATE" Value="109"/>
+        <opc:EnumeratedValue Name="NMT_XS_OPERATIONAL" Value="253"/>
+        <opc:EnumeratedValue Name="NMT_CS_STOPPED" Value="77"/>
+        <opc:EnumeratedValue Name="NMT_XS_BASIC_ETHERNET" Value="30"/>
+    </opc:EnumeratedType>
+</opc:TypeDictionary>

+ 53 - 0
examples/nodeset/server_nodeset_powerlink.c

@@ -0,0 +1,53 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
+
+#ifdef UA_ENABLE_AMALGAMATION
+#include "open62541.h"
+#else
+#include "ua_server.h"
+#include "ua_log_stdout.h"
+#include "ua_config_default.h"
+#endif
+
+#include <signal.h>
+
+/* Files example_namespace.h and example_namespace.c are created from server_nodeset.xml in the
+ * /src_generated directory by CMake */
+#include "ua_namespace_di.h"
+#include "ua_namespace_powerlink.h"
+
+UA_Boolean running = true;
+
+static void stopHandler(int sign) {
+    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
+    running = false;
+}
+
+int main(int argc, char** argv) {
+    signal(SIGINT, stopHandler);
+    signal(SIGTERM, stopHandler);
+
+    UA_ServerConfig *config = UA_ServerConfig_new_default();
+    UA_Server *server = UA_Server_new(config);
+
+    /* create nodes from nodeset */
+    UA_StatusCode retval = ua_namespace_di(server);
+    if(retval != UA_STATUSCODE_GOOD) {
+        UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the DI namespace failed. Please check previous error output.");
+        UA_Server_delete(server);
+        UA_ServerConfig_delete(config);
+        return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
+    }
+    retval |= ua_namespace_powerlink(server);
+    if(retval != UA_STATUSCODE_GOOD) {
+        UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the Powerlink namespace failed. Please check previous error output.");
+        UA_Server_delete(server);
+        UA_ServerConfig_delete(config);
+        return (int)UA_STATUSCODE_BADUNEXPECTEDERROR;
+    }
+
+    retval = UA_Server_run(server, &running);
+    UA_Server_delete(server);
+    UA_ServerConfig_delete(config);
+    return (int)retval;
+}