瀏覽代碼

create the Quality of Service (QoS) Object and bind it

Ruben Nati 8 年之前
父節點
當前提交
b72fe78412
共有 4 個文件被更改,包括 189 次插入3 次删除
  1. 1 2
      source/src/cip/CMakeLists.txt
  2. 3 1
      source/src/cip/cipcommon.c
  3. 158 0
      source/src/cip/cipqos.c
  4. 27 0
      source/src/cip/cipqos.h

+ 1 - 2
source/src/cip/CMakeLists.txt

@@ -12,7 +12,6 @@ opener_common_includes()
 #######################################
 opener_platform_support("INCLUDES")
 
-set( CIP_SRC appcontype.c cipassembly.c cipclass3connection.c cipcommon.c cipconnectionmanager.c ciperror.h cipethernetlink.c cipidentity.c cipioconnection.c cipmessagerouter.c ciptcpipinterface.c ciptypes.h cipepath.h cipepath.c cipelectronickey.h cipelectronickey.c )
+set( CIP_SRC appcontype.c cipassembly.c cipclass3connection.c cipcommon.c cipconnectionmanager.c ciperror.h cipethernetlink.c cipidentity.c cipioconnection.c cipmessagerouter.c ciptcpipinterface.c ciptypes.h cipepath.h cipepath.c cipelectronickey.h cipelectronickey.c cipqos.c )
 
 add_library( CIP ${CIP_SRC} )
-

+ 3 - 1
source/src/cip/cipcommon.c

@@ -18,6 +18,7 @@
 #include "ciperror.h"
 #include "cipassembly.h"
 #include "cipmessagerouter.h"
+#include "cipqos.h"
 #include "cpf.h"
 #include "trace.h"
 #include "appcontype.h"
@@ -45,6 +46,8 @@ void CipStackInit(const EipUint16 unique_connection_id) {
   OPENER_ASSERT(kEipStatusOk == eip_status);
   eip_status = CipAssemblyInitialize();
   OPENER_ASSERT(kEipStatusOk == eip_status);
+  eip_status = CipQoSInit();
+  OPENER_ASSERT(kEipStatusOk == eip_status);
   /* the application has to be initialized at last */
   eip_status = ApplicationInitialization();
   OPENER_ASSERT(kEipStatusOk == eip_status);
@@ -865,4 +868,3 @@ size_t CalculateIndex(EipUint16 attribute_number) {
   size_t index = attribute_number / 8;
   return index;
 }
-

+ 158 - 0
source/src/cip/cipqos.c

@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2009/, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#include "cipqos.h"
+
+#include "opener_user_conf.h"
+#include "cipcommon.h"
+#include "cipmessagerouter.h"
+#include "ciperror.h"
+#include "endianconv.h"
+#include "cipethernetlink.h"
+#include "opener_api.h"
+#include "trace.h"
+
+CipUsint QFramesEnable = 0; /* Enables or disable sending 802.1Q frames on CIP and IEEE 1588 messages */
+CipUsint DscpEvent = 59; /* DSCP value for event messages*/
+CipUsint DscpGeneral = 47; /* DSCP value for general messages*/
+CipUsint kDscpUrgent = 55; /* DSCP value for CIP transport class 0/1 Urgent priority messages */
+CipUsint kDscpScheduled = 47; /* DSCP value for CIP transport class 0/1 Scheduled priority messages*/
+CipUsint kDscpHigh = 43; /* DSCP value for CIP transport class 0/1 High priority messages */
+CipUsint kDscpLow = 31; /* DSCP value for CIP transport class 0/1 low priority messages */
+CipUsint kDscpExplicit = 27; /* DSCP value for CIP explicit messages (transport class 2/3 and UCMM)
+                              and all other EtherNet/IP encapsulation messages */
+
+/************** Functions ****************************************/
+EipStatus GetAttributeSingleQoS(
+  CipInstance *const RESTRICT instance,
+  CipMessageRouterRequest *RESTRICT const message_router_request,
+  CipMessageRouterResponse *RESTRICT const message_router_response,
+  struct sockaddr *originator_address) {
+
+    return GetAttributeSingle(instance, message_router_request,
+      message_router_response, originator_address);
+}
+
+EipStatus SetAttributeSingleQoS(
+  CipInstance *instance,
+  CipMessageRouterRequest *message_router_request,
+  CipMessageRouterResponse *message_router_response,
+  struct sockaddr *originator_address) {
+
+    CipAttributeStruct *attribute = GetCipAttribute(
+      instance, message_router_request->request_path.attribute_number);
+    (void) instance; /*Suppress compiler warning */
+    EipUint16 attribute_number = message_router_request->request_path.attribute_number;
+    uint8_t set_bit_mask = (instance->cip_class->set_bit_mask[CalculateIndex(
+      attribute_number)]);
+
+    if(NULL != attribute && (set_bit_mask & (1 << ((attribute_number - 1) % 8)))) {
+      CipUint attribute_value_recieved = GetDintFromMessage(
+        &(message_router_request->data));
+
+      if(!((attribute_value_recieved <= 0) || (attribute_value_recieved >= 63)) {
+        OPENER_TRACE_INFO(" setAttribute %d\n", attribute_number);
+
+        if(NULL != attribute->data) {
+          CipUsint *data = (CipUsint *) attribute->data;
+          *(data) = attribute_value_recieved;
+
+          message_router_response->general_status = kCipErrorSuccess;
+        } else {
+          message_router_response->general_status = kCipErrorNotEnoughData;
+        }
+      } else {
+        message_router_response->general_status = kCipErrorInvalidAttributeValue;
+      }
+    } else {
+      /* we don't have this attribute */
+      message_router_response->general_status = kCipErrorAttributeNotSupported;
+    }
+
+    message_router_response->size_of_additional_status = 0;
+    message_router_response->data_length = 0;
+    message_router_response->reply_service = (0x80
+      | message_router_request->service);
+
+    return kEipStatusOkSend;
+}
+
+CipUsint GetPriorityForSocket(ForwardOpenPriority priority) {
+  switch (priority) {
+    case kForwardOpenPriorityLow: {
+      return kDscpLow;
+      break;
+    }
+    case kForwardOpenPriorityHigh: {
+      return kDscpHigh;
+      break;
+    }
+    case kForwardOpenPriorityScheduled: {
+      return kDscpScheduled;
+      break;
+    }
+    case kForwardOpenPriorityUrgent: {
+      return kDscpUrgent;
+      break;
+    }
+    default: {
+      return kDscpExplicit;
+      break;
+    }
+  }
+}
+
+void InitializeCipQos(CipClass *class) {
+
+  CipClass *meta_class = class->class_instance.cip_class;
+}
+
+EipStatus CipQoSInit() {
+
+  CipClass *qos_class = NULL;
+
+  if((qos_class = CreateCipClass(kCipQoSClassCode,
+                                  0, /* # class attributes*/
+                                  7, /* # highest class attribute number*/
+                                  0, /* # class services*/
+                                  8, /* # instance attributes*/
+                                  8, /* # highest instance attribute number*/
+                                  2, /* # instance services*/
+                                  1, /* # instances*/
+                                  "Quality of Service",
+                                  1, /* # class revision*/
+                                  &InitializeCipQos /* # function pointer for initialization*/
+                                  )) == 0) {
+
+    return kEipStatusError;
+  }
+
+  CipInstance *instance = GetCipInstance(qos_class, 1); /* bind attributes to the instance #1 that was created above*/
+
+  InsertAttribute(instance, 1, kCipUsint, (void *) &QFramesEnable,
+                  kNotSetOrGetable);
+  InsertAttribute(instance, 2, kCipUsint, (void *) &DscpEvent,
+                  kNotSetOrGetable);
+  InsertAttribute(instance, 3, kCipUsint, (void *) &DscpGeneral,
+                  kNotSetOrGetable);
+  InsertAttribute(instance, 4, kCipUsint, (void *) &kDscpUrgent,
+                  kGetableSingle | kSetable);
+  InsertAttribute(instance, 5, kCipUsint, (void *) &kDscpScheduled,
+                  kGetableSingle | kSetable);
+  InsertAttribute(instance, 6, kCipUsint, (void *) &kDscpHigh,
+                  kGetableSingle | kSetable);
+  InsertAttribute(instance, 7, kCipUsint, (void *) &kDscpLow,
+                  kGetableSingle | kSetable);
+  InsertAttribute(instance, 8, kCipUsint, (void *) &kDscpExplicit,
+                  kGetableSingle | kSetable);
+
+  InsertService(qos_class, kGetAttributeSingle, &GetAttributeSingleQoS,
+                  "GetAttributeSingleQoS");
+  InsertService(qos_class, kSetAttributeSingle, &SetAttributeSingleQoS,
+                  "SetAttributeSingleQoS");
+
+  return kEipStatusOk;
+}

+ 27 - 0
source/src/cip/cipqos.h

@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#ifndef OPENER_CIPQOS_H_
+#define OPENER_CIPQOS_H_
+
+/** @file cipqos.h
+ *  @brief Public interface of the QoS Object
+ *
+ */
+
+#include "typedefs.h"
+#include "ciptypes.h"
+#include "cipconnectionmanager.h"
+
+static const EipUint16 kCipQoSClassCode = 0x48; /**< QoS Object class code */
+
+/* public functions */
+/** @brief Initializing the data structures of the TCP/IP interface object
+ */
+CipUsint GetPriorityForSocket(ForwardOpenPriority priority);
+EipStatus CipQoSInit(void);
+
+#endif  /* OPENER_CIPQOS_H_*/