Преглед на файлове

Cleanup: Object's class ids get same type and naming convention

The object's class id declaration in the headers have a now a common
"k<ObjectName>ClassId" naming style.

The class id type is now EipUint16 that can hold all possible class id
values, extends with no sign conversion to the EipUint32 parameters of
functions getting a class_id parameter and avoids signed / unsigned
comparison warnings when compared with the class_id of a class instance.

Signed-off-by: Stefan Mätje <stefan.maetje@esd.eu>
Stefan Mätje преди 6 години
родител
ревизия
2cdf3582cf

+ 3 - 3
source/src/cip/cipassembly.c

@@ -31,7 +31,7 @@ EipStatus SetAssemblyAttributeSingle(CipInstance *const instance,
  */
  */
 CipClass *CreateAssemblyClass(void) {
 CipClass *CreateAssemblyClass(void) {
   /* create the CIP Assembly object with zero instances */
   /* create the CIP Assembly object with zero instances */
-  CipClass *assembly_class = CreateCipClass(kCipAssemblyClassCode, 0, /* # class attributes*/
+  CipClass *assembly_class = CreateCipClass(kCipAssemblyClassId, 0, /* # class attributes*/
                                             7, /* # highest class attribute number*/
                                             7, /* # highest class attribute number*/
                                             1, /* # class services*/
                                             1, /* # class services*/
                                             2, /* # instance attributes*/
                                             2, /* # instance attributes*/
@@ -63,7 +63,7 @@ EipStatus CipAssemblyInitialize(void) {
 }
 }
 
 
 void ShutdownAssemblies(void) {
 void ShutdownAssemblies(void) {
-  CipClass *assembly_class = GetCipClass(kCipAssemblyClassCode);
+  CipClass *assembly_class = GetCipClass(kCipAssemblyClassId);
 
 
   if(NULL != assembly_class) {
   if(NULL != assembly_class) {
     CipInstance *instance = assembly_class->instances;
     CipInstance *instance = assembly_class->instances;
@@ -80,7 +80,7 @@ void ShutdownAssemblies(void) {
 CipInstance *CreateAssemblyObject(const EipUint32 instance_id,
 CipInstance *CreateAssemblyObject(const EipUint32 instance_id,
                                   EipByte *const data,
                                   EipByte *const data,
                                   const EipUint16 data_length) {
                                   const EipUint16 data_length) {
-  CipClass *assembly_class = GetCipClass(kCipAssemblyClassCode);
+  CipClass *assembly_class = GetCipClass(kCipAssemblyClassId);
   if(NULL == assembly_class) {
   if(NULL == assembly_class) {
     assembly_class = CreateAssemblyClass();
     assembly_class = CreateAssemblyClass();
   }
   }

+ 2 - 2
source/src/cip/cipassembly.h

@@ -9,8 +9,8 @@
 #include "typedefs.h"
 #include "typedefs.h"
 #include "ciptypes.h"
 #include "ciptypes.h"
 
 
-/** @brief Assembly Class Code */
-static const int kCipAssemblyClassCode = 0x04;
+/** @brief Assembly class id */
+static const EipUint16 kCipAssemblyClassId = 0x04u;
 
 
 /* public functions */
 /* public functions */
 
 

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

@@ -443,7 +443,7 @@ EipStatus GetAttributeSingle(CipInstance *RESTRICT const instance,
        */
        */
 
 
       if (attribute->type == kCipByteArray
       if (attribute->type == kCipByteArray
-          && instance->cip_class->class_id == kCipAssemblyClassCode) {
+          && instance->cip_class->class_id == kCipAssemblyClassId) {
         /* we are getting a byte array of a assembly object, kick out to the app callback */
         /* we are getting a byte array of a assembly object, kick out to the app callback */
         OPENER_TRACE_INFO(" -> getAttributeSingle CIP_BYTE_ARRAY\r\n");
         OPENER_TRACE_INFO(" -> getAttributeSingle CIP_BYTE_ARRAY\r\n");
         BeforeAssemblyDataSend(instance);
         BeforeAssemblyDataSend(instance);

+ 4 - 4
source/src/cip/cipconnectionmanager.c

@@ -207,7 +207,7 @@ EipStatus ConnectionManagerInit(EipUint16 unique_connection_id) {
   InitializeConnectionManagerData();
   InitializeConnectionManagerData();
 
 
   CipClass *connection_manager = CreateCipClass(
   CipClass *connection_manager = CreateCipClass(
-    g_kCipConnectionManagerClassCode,   /* class ID */
+    kCipConnectionManagerClassId,   /* class ID */
     0,   /* # of class attributes */
     0,   /* # of class attributes */
     7,   /* # highest class attribute number*/
     7,   /* # highest class attribute number*/
     2,   /* # of class services */
     2,   /* # of class services */
@@ -233,8 +233,8 @@ EipStatus ConnectionManagerInit(EipUint16 unique_connection_id) {
 
 
   g_incarnation_id = ( (EipUint32) unique_connection_id ) << 16;
   g_incarnation_id = ( (EipUint32) unique_connection_id ) << 16;
 
 
-  AddConnectableObject(kCipMessageRouterClassCode, EstablishClass3Connection);
-  AddConnectableObject(kCipAssemblyClassCode, EstablishIoConnection);
+  AddConnectableObject(kCipMessageRouterClassId, EstablishClass3Connection);
+  AddConnectableObject(kCipAssemblyClassId, EstablishIoConnection);
 
 
   return kEipStatusOk;
   return kEipStatusOk;
 }
 }
@@ -1213,7 +1213,7 @@ EipUint8 ParseConnectionPath(
       }
       }
 
 
       /* connection end point has to be the message router instance 1 */
       /* connection end point has to be the message router instance 1 */
-      if ( (class_id != kCipMessageRouterClassCode)
+      if ( (class_id != kCipMessageRouterClassId)
            || (1 != instance_id) ) {
            || (1 != instance_id) ) {
         *extended_error =
         *extended_error =
           kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;
           kConnectionManagerExtendedStatusCodeInconsistentApplicationPathCombo;

+ 2 - 2
source/src/cip/cipconnectionmanager.h

@@ -159,8 +159,8 @@ typedef enum {
 #define SEQ_LEQ16(a, b) ( (short)( (a) - (b) ) <= 0 )
 #define SEQ_LEQ16(a, b) ( (short)( (a) - (b) ) <= 0 )
 #define SEQ_GEQ16(a, b) ( (short)( (a) - (b) ) >= 0 )
 #define SEQ_GEQ16(a, b) ( (short)( (a) - (b) ) >= 0 )
 
 
-/** @brief Connection Manager class code */
-static const int g_kCipConnectionManagerClassCode = 0x06;
+/** @brief Connection Manager class id */
+static const EipUint16 kCipConnectionManagerClassId = 0x06u;
 
 
 /* public functions */
 /* public functions */
 
 

+ 1 - 1
source/src/cip/cipethernetlink.c

@@ -66,7 +66,7 @@ CipEthernetLinkInterfaceCapability interface_capability = {
 };
 };
 
 
 EipStatus CipEthernetLinkInit() {
 EipStatus CipEthernetLinkInit() {
-  CipClass *ethernet_link_class = CreateCipClass(CIP_ETHERNETLINK_CLASS_CODE,
+  CipClass *ethernet_link_class = CreateCipClass(kCipEthernetLinkClassId,
                                                  0, /* # class attributes*/
                                                  0, /* # class attributes*/
                                                  7, /* # highest class attribute number*/
                                                  7, /* # highest class attribute number*/
                                                  2, /* # class services*/
                                                  2, /* # class services*/

+ 5 - 1
source/src/cip/cipethernetlink.h

@@ -9,7 +9,11 @@
 #include "typedefs.h"
 #include "typedefs.h"
 #include "ciptypes.h"
 #include "ciptypes.h"
 
 
-#define CIP_ETHERNETLINK_CLASS_CODE 0xF6
+/** @brief This Ethernet Link class id as #define is still needed for a static
+ *  initialization. */
+#define CIP_ETHERNETLINK_CLASS_ID   0xF6u
+/** @brief Ethernet Link class id */
+static const EipUint16 kCipEthernetLinkClassId = CIP_ETHERNETLINK_CLASS_ID;
 
 
 /* public functions */
 /* public functions */
 /** @brief Initialize the Ethernet Link Objects data
 /** @brief Initialize the Ethernet Link Objects data

+ 1 - 1
source/src/cip/cipidentity.c

@@ -147,7 +147,7 @@ void InitializeCipIdentiy(CipClass *class) {
 
 
 EipStatus CipIdentityInit() {
 EipStatus CipIdentityInit() {
 
 
-  CipClass *class = CreateCipClass(kIdentityClassCode,
+  CipClass *class = CreateCipClass(kIdentityClassId,
                                    0, /* # of non-default class attributes */
                                    0, /* # of non-default class attributes */
                                    7, /* # highest class attribute number*/
                                    7, /* # highest class attribute number*/
                                    2, /* # of class services*/
                                    2, /* # of class services*/

+ 2 - 1
source/src/cip/cipidentity.h

@@ -9,7 +9,8 @@
 #include "typedefs.h"
 #include "typedefs.h"
 #include "ciptypes.h"
 #include "ciptypes.h"
 
 
-static const int kIdentityClassCode = 0x01;
+/** @brief Identity class id */
+static const EipUint16 kIdentityClassId = 0x01u;
 
 
 /** @brief Status of the CIP Identity object */
 /** @brief Status of the CIP Identity object */
 typedef enum {
 typedef enum {

+ 3 - 3
source/src/cip/cipioconnection.c

@@ -111,7 +111,7 @@ EipUint16 SetupIoConnectionOriginatorToTargetConnectionPoint(
   CipConnectionObject *const io_connection_object,
   CipConnectionObject *const io_connection_object,
   CipConnectionObject *const RESTRICT connection_object
   CipConnectionObject *const RESTRICT connection_object
   ) {
   ) {
-  CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
+  CipClass *const assembly_class = GetCipClass(kCipAssemblyClassId);
   CipInstance *instance = NULL;
   CipInstance *instance = NULL;
   if ( NULL
   if ( NULL
        != ( instance =
        != ( instance =
@@ -218,7 +218,7 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
   }
   }
 
 
   /*setup producer side*/
   /*setup producer side*/
-  CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
+  CipClass *const assembly_class = GetCipClass(kCipAssemblyClassId);
   CipInstance *instance = NULL;
   CipInstance *instance = NULL;
   if ( NULL
   if ( NULL
        != ( instance =
        != ( instance =
@@ -621,7 +621,7 @@ EipStatus OpenMulticastConnection(
 
 
 EipUint16 HandleConfigData(CipConnectionObject *connection_object) {
 EipUint16 HandleConfigData(CipConnectionObject *connection_object) {
 
 
-  CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
+  CipClass *const assembly_class = GetCipClass(kCipAssemblyClassId);
   EipUint16 connection_manager_status = 0;
   EipUint16 connection_manager_status = 0;
   CipInstance *config_instance = GetCipInstance(
   CipInstance *config_instance = GetCipInstance(
     assembly_class, connection_object->configuration_path.instance_id);
     assembly_class, connection_object->configuration_path.instance_id);

+ 1 - 1
source/src/cip/cipmessagerouter.c

@@ -77,7 +77,7 @@ void InitializeCipMessageRouterClass(CipClass *cip_class) {
 
 
 EipStatus CipMessageRouterInit() {
 EipStatus CipMessageRouterInit() {
 
 
-  CipClass *message_router = CreateCipClass(kCipMessageRouterClassCode, /* class ID*/
+  CipClass *message_router = CreateCipClass(kCipMessageRouterClassId, /* class ID*/
                                             0, /* # of class attributes */
                                             0, /* # of class attributes */
                                             7, /* # highest class attribute number*/
                                             7, /* # highest class attribute number*/
                                             2, /* # of class services*/
                                             2, /* # of class services*/

+ 3 - 2
source/src/cip/cipmessagerouter.h

@@ -9,12 +9,13 @@
 #include "typedefs.h"
 #include "typedefs.h"
 #include "ciptypes.h"
 #include "ciptypes.h"
 
 
-static const int kCipMessageRouterClassCode = 0x02;
+/** @brief Message Router class id */
+static const EipUint16 kCipMessageRouterClassId = 0x02u;
 
 
 /** @brief Structure for storing the Response generated by an explict message.
 /** @brief Structure for storing the Response generated by an explict message.
  *
  *
  *  This buffer will be used for storing the result. The response message will be generated
  *  This buffer will be used for storing the result. The response message will be generated
- *  by assembleLinearMsg.
+ *  by AssembleLinearMessage().
  */
  */
 extern CipMessageRouterResponse g_message_router_response;
 extern CipMessageRouterResponse g_message_router_response;
 
 

+ 1 - 1
source/src/cip/cipqos.c

@@ -119,7 +119,7 @@ EipStatus CipQoSInit() {
 
 
   CipClass *qos_class = NULL;
   CipClass *qos_class = NULL;
 
 
-  if( ( qos_class = CreateCipClass(kCipQoSClassCode,
+  if( ( qos_class = CreateCipClass(kCipQoSClassId,
                                    0, /* # class attributes*/
                                    0, /* # class attributes*/
                                    7, /* # highest class attribute number*/
                                    7, /* # highest class attribute number*/
                                    0, /* # class services*/
                                    0, /* # class services*/

+ 2 - 1
source/src/cip/cipqos.h

@@ -16,7 +16,8 @@
 #include "ciptypes.h"
 #include "ciptypes.h"
 #include "cipconnectionmanager.h"
 #include "cipconnectionmanager.h"
 
 
-static const EipUint16 kCipQoSClassCode = 0x48; /**< QoS Object class code */
+/** @brief QoS Object class id */
+static const EipUint16 kCipQoSClassId = 0x48u;
 
 
 /* public functions */
 /* public functions */
 /** @brief Initializing the data structures of the TCP/IP interface object
 /** @brief Initializing the data structures of the TCP/IP interface object

+ 3 - 2
source/src/cip/ciptcpipinterface.c

@@ -22,7 +22,7 @@ CipDword configuration_capability_ = 0x04; /**< #2  This is a default value mean
 CipDword configuration_control_ = 0x02; /**< #3  This is a TCP/IP object attribute. 0x02 means that the device shall obtain its interface configuration values via DHCP. */
 CipDword configuration_control_ = 0x02; /**< #3  This is a TCP/IP object attribute. 0x02 means that the device shall obtain its interface configuration values via DHCP. */
 CipEpath physical_link_object_ = /**< #4 */
 CipEpath physical_link_object_ = /**< #4 */
 { 2, /**< EIP_UINT16 (UINT) PathSize in 16 Bit chunks*/
 { 2, /**< EIP_UINT16 (UINT) PathSize in 16 Bit chunks*/
-  CIP_ETHERNETLINK_CLASS_CODE, /**< EIP_UINT16 ClassID*/
+  CIP_ETHERNETLINK_CLASS_ID, /**< EIP_UINT16 ClassID*/
   1, /**< EIP_UINT16 InstanceNr*/
   1, /**< EIP_UINT16 InstanceNr*/
   0 /**< EIP_UINT16 AttributNr (not used as this is the EPATH the EthernetLink object)*/
   0 /**< EIP_UINT16 AttributNr (not used as this is the EPATH the EthernetLink object)*/
 };
 };
@@ -165,7 +165,8 @@ EipStatus SetAttributeSingleTcp(
 EipStatus CipTcpIpInterfaceInit() {
 EipStatus CipTcpIpInterfaceInit() {
   CipClass *tcp_ip_class = NULL;
   CipClass *tcp_ip_class = NULL;
 
 
-  if ( ( tcp_ip_class = CreateCipClass(kCipTcpIpInterfaceClassCode, 0, /* # class attributes*/
+  if ( ( tcp_ip_class = CreateCipClass(kCipTcpIpInterfaceClassId, /* class ID*/
+                                       0, /* # class attributes*/
                                        7, /* # highest class attribute number*/
                                        7, /* # highest class attribute number*/
                                        2, /* # class services*/
                                        2, /* # class services*/
                                        9, /* # instance attributes*/
                                        9, /* # instance attributes*/

+ 2 - 1
source/src/cip/ciptcpipinterface.h

@@ -18,7 +18,8 @@ extern CipString hostname_;
 
 
 extern CipTcpIpNetworkInterfaceConfiguration interface_configuration_;
 extern CipTcpIpNetworkInterfaceConfiguration interface_configuration_;
 
 
-static const EipUint16 kCipTcpIpInterfaceClassCode = 0xF5; /**< TCP/IP Interface Object class code */
+/** @brief TCP/IP Interface class id */
+static const EipUint16 kCipTcpIpInterfaceClassId = 0xF5u;
 
 
 /** @brief Multicast Configuration struct, called Mcast config
 /** @brief Multicast Configuration struct, called Mcast config
  *
  *