Просмотр исходного кода

Adds getter and setter + tests for connection object

Signed-off-by: CapXilinx <melik-merkumians@acin.tuwien.ac.at>
CapXilinx 8 лет назад
Родитель
Сommit
c45ebef6d0

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

@@ -592,7 +592,7 @@ EipStatus HandleNonNullNonMatchingForwardOpenRequest(
 
   /*parsing is now finished all data is available and check now establish the connection */
   ConnectionManagementHandling *connection_management_entry =
-    GetConnectionManagementEntry(
+    GetConnectionManagementEntry( /* Gets correct open connection function for the targeted object */
       g_dummy_connection_object.connection_path.class_id);
   if (NULL != connection_management_entry) {
     temp = connection_management_entry->open_connection_function(

+ 128 - 0
source/src/cip/cipconnectionobject.c

@@ -6,6 +6,8 @@
 
 #include "cipconnectionobject.h"
 
+#include "opener_user_conf.h"
+
 #define CIP_CONNECTION_OBJECT_STATE_NON_EXISTENT 0U
 #define CIP_CONNECTION_OBJECT_STATE_CONFIGURING 1U
 #define CIP_CONNECTION_OBJECT_STATE_WAITING_FOR_CONNECTION_ID 2U
@@ -32,6 +34,29 @@
 #define CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_2 2
 #define CIP_CONNECTION_OBJECT_TRANSPORT_CLASS_TRIGGER_TRANSPORT_CLASS_3 3
 
+#define CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_TRANSITION_TO_TIMED_OUT 0
+#define CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_DELETE 1
+#define CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_RESET 2
+#define CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_DEFERRED_DELETE 3
+
+static CipConnectionObject explicit_connection_object_pool[
+  OPENER_CIP_NUM_EXPLICIT_CONNS];
+static CipConnectionObject input_only_connection_object_pool[
+  OPENER_CIP_NUM_INPUT_ONLY_CONNS];
+static CipConnectionObject exclusive_owner_connection_object_pool[
+  OPENER_CIP_NUM_EXLUSIVE_OWNER_CONNS];
+static CipConnectionObject listen_only_connection_object_pool[
+  OPENER_CIP_NUM_LISTEN_ONLY_CONNS];
+
+void ConnectionObjectInitializeEmpty(
+  CipConnectionObject *const connection_object) {
+  memset( connection_object, 0, sizeof(*connection_object) );
+}
+
+CipConnectionObject *CipConnectionObjectCreate(const CipOctet *message) {
+
+}
+
 ConnectionObjectState ConnectionObjectGetState(
   const CipConnectionObject *const connection_object) {
   switch(connection_object->state) {
@@ -53,6 +78,27 @@ ConnectionObjectState ConnectionObjectGetState(
   }
 }
 
+void ConnectionObjectSetState(CipConnectionObject *const connection_object,
+                              const ConnectionObjectState state) {
+  switch(state) {
+    case kConnectionObjectStateNonExistent: connection_object->state =
+      CIP_CONNECTION_OBJECT_STATE_NON_EXISTENT; break;
+    case kConnectionObjectStateConfiguring: connection_object->state =
+      CIP_CONNECTION_OBJECT_STATE_CONFIGURING; break;
+    case kConnectionObjectStateWaitingForConnectionID: connection_object->state
+        = CIP_CONNECTION_OBJECT_STATE_WAITING_FOR_CONNECTION_ID; break;
+    case kConnectionObjectStateEstablished: connection_object->state =
+      CIP_CONNECTION_OBJECT_STATE_ESTABLISHED; break;
+    case kConnectionObjectStateTimedOut: connection_object->state =
+      CIP_CONNECTION_OBJECT_STATE_TIMEOUT; break;
+    case kConnectionObjectStateDeferredDelete: connection_object->state =
+      CIP_CONNECTION_OBJECT_STATE_DEFERRED_DELETE; break;
+    case kConnectionObjectStateClosing: connection_object->state =
+      CIP_CONNECTION_OBJECT_STATE_CLOSING; break;
+    default: OPENER_ASSERT(false);     /* Never get here */
+  }
+}
+
 ConnectionObjectInstanceType ConnectionObjectGetInstanceType(
   const CipConnectionObject *const connection_object) {
   switch(connection_object->instance_type) {
@@ -144,6 +190,24 @@ void ConnectionObjectSetConsumedConnectionSize(
   connection_object->consumed_connection_size = consumed_connection_size;
 }
 
+CipUint ConnectionObjectGetExpectedPacketRate(
+  const CipConnectionObject *const connection_object) {
+  return connection_object->expected_packet_rate;
+}
+
+void ConnectionObjectSetExpectedPacketRate(
+  CipConnectionObject *const connection_object,
+  CipUint expected_packet_rate) {
+  if( (expected_packet_rate % kOpenerTimerTickInMilliSeconds) == 0 ) {
+    connection_object->expected_packet_rate = expected_packet_rate;
+  } else {
+    connection_object->expected_packet_rate = expected_packet_rate +
+                                              (kOpenerTimerTickInMilliSeconds -
+                                               expected_packet_rate %
+                                               kOpenerTimerTickInMilliSeconds);
+  }
+}
+
 CipUdint ConnectionObjectGetCipProducedConnectionID(
   const CipConnectionObject *const connection_object) {
   return connection_object->cip_produced_connection_id;
@@ -167,3 +231,67 @@ void ConnectionObjectSetCipConsumedConnectionID(
   cip_consumed_connection_id) {
   connection_object->cip_consumed_connection_id = cip_consumed_connection_id;
 }
+
+ConnectionObjectWatchdogTimeoutAction ConnectionObjectGetWatchdogTimeoutAction(
+  const CipConnectionObject *const connection_object) {
+  switch(connection_object->watchdog_timeout_action) {
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_TRANSITION_TO_TIMED_OUT:
+      return kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut; break;
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_DELETE: return
+        kConnectionObjectWatchdogTimeoutActionAutoDelete; break;
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_RESET: return
+        kConnectionObjectWatchdogTimeoutActionAutoReset; break;
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_DEFERRED_DELETE: return
+        kConnectionObjectWatchdogTimeoutActionDeferredDelete; break;
+    default: return kConnectionObjectWatchdogTimeoutActionInvalid; break;
+  }
+}
+
+void ConnectionObjectSetWatchdofTimeoutAction(
+  CipConnectionObject *const connection_object,
+  const CipUsint
+  watchdog_timeout_action) {
+  switch(watchdog_timeout_action) {
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_TRANSITION_TO_TIMED_OUT:
+      connection_object->watchdog_timeout_action =
+        kConnectionObjectWatchdogTimeoutActionTransitionToTimedOut; break;
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_DELETE:
+      connection_object->watchdog_timeout_action =
+        kConnectionObjectWatchdogTimeoutActionAutoDelete; break;
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_AUTO_RESET:
+      connection_object->watchdog_timeout_action =
+        kConnectionObjectWatchdogTimeoutActionAutoReset; break;
+    case CIP_CONNECTION_OBJECT_WATCHDOG_TIMEOUT_ACTION_DEFERRED_DELETE:
+      connection_object->watchdog_timeout_action =
+        kConnectionObjectWatchdogTimeoutActionDeferredDelete; break;
+    default: connection_object->watchdog_timeout_action =
+      kConnectionObjectWatchdogTimeoutActionInvalid; break;
+  }
+}
+
+CipUint ConnectionObjectGetProducedConnectionPathLength(
+  const CipConnectionObject *const connection_object) {
+  return connection_object->produced_connection_path_length;
+}
+
+void ConnectionObjectSetProducedConnectionPathLength(
+  CipConnectionObject *const connection_object,
+  const CipUint
+  produced_connection_path_length) {
+  connection_object->produced_connection_path_length =
+    produced_connection_path_length;
+}
+
+CipUint ConnectionObjectGetConsumedConnectionPathLength(
+  const CipConnectionObject *const connection_object) {
+  return connection_object->consumed_connection_path_length;
+}
+
+void ConnectionObjectSetConsumedConnectionPathLength(
+  CipConnectionObject *const connection_object,
+  const CipUint
+  consumed_connection_path_length) {
+  connection_object->consumed_connection_path_length =
+    consumed_connection_path_length;
+}
+

+ 64 - 0
source/src/cip/cipconnectionobject.h

@@ -85,9 +85,30 @@ typedef struct cip_connection_object {
 
 } CipConnectionObject;
 
+/** @brief Array allocator
+ *
+ */
+CipConnectionObject *CipConnectionObjectCreate(const CipOctet *message);
+
+/** @brief Array deallocator
+ *
+ */
+void CipConnectionObjectDelete(CipConnectionObject **connection_object);
+
+void ConnectionObjectInitializeEmpty(
+  CipConnectionObject *const connection_object);
+
+void ConnectionObjectInitializeFromMessage(
+  const CipOctet *message,
+  CipConnectionObject *const
+  connection_object);
+
 ConnectionObjectState ConnectionObjectGetState(
   const CipConnectionObject *const connection_object);
 
+void ConnectionObjectSetState(CipConnectionObject *const connection_object,
+                              const ConnectionObjectState state);
+
 ConnectionObjectInstanceType ConnectionObjectGetInstanceType(
   const CipConnectionObject *const connection_object);
 
@@ -119,6 +140,9 @@ void ConnectionObjectSetConsumedConnectionSize(
   const CipUint
   consumed_connection_size);
 
+CipUint ConnectionObjectGetExpectedPacketRate(
+  const CipConnectionObject *const connection_object);
+
 /**
  * @brief Sets the expected packet rate according to the rules of the CIP specification
  *
@@ -145,5 +169,45 @@ void ConnectionObjectSetCipConsumedConnectionID(
   const CipUdint
   cip_consumed_connection_id);
 
+ConnectionObjectWatchdogTimeoutAction ConnectionObjectGetWatchdogTimeoutAction(
+  const CipConnectionObject *const connection_object);
+
+void ConnectionObjectSetWatchdofTimeoutAction(
+  CipConnectionObject *const connection_object,
+  const CipUsint
+  watchdog_timeout_action);
+
+CipUint ConnectionObjectGetProducedConnectionPathLength(
+  const CipConnectionObject *const connection_object);
+
+void ConnectionObjectSetProducedConnectionPathLength(
+  CipConnectionObject *const connection_object,
+  const CipUint
+  produced_connection_path_length);
+
+CipUint ConnectionObjectGetConsumedConnectionPathLength(
+  const CipConnectionObject *const connection_object);
+
+void ConnectionObjectSetConsumedConnectionPathLength(
+  CipConnectionObject *const connection_object,
+  const CipUint
+  consumed_connection_path_length);
+
+CipUint ConnectionObjectGetProductionInhibitTime(
+  const CipConnectionObject *const connection_object);
+
+void ConnectionObjectSetProductionInhibitTime(
+  CipConnectionObject *const connection_object,
+  const CipUint
+  production_inhibit_time);
+
+CipUsint ConnectionObjectGetConnectionTimeoutMultiplier(
+  const CipConnectionObject *const connection_object);
+
+void ConnectionObjectSetConnectionTimeoutMultiplier(
+  CipConnectionObject *const connection_object,
+  const CipUsint
+  connection_timeout_multiplier);
+
 
 #endif /* SRC_CIP_CIPCONNECTIONOBJECT_H_ */

+ 24 - 0
source/tests/cip/cipconnectionobjecttest.cpp

@@ -210,3 +210,27 @@ TEST(CipConnectionObject, TransportClassTriggerClass3) {
   CHECK_EQUAL(kConnectionObjectTransportClassTriggerTransportClass3,
               transport_class);
 }
+
+TEST(CipConnectionObject, ExpectedPacketRate) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetExpectedPacketRate(&connection_object, 11);
+  CipUint expected_packet_rate = ConnectionObjectGetExpectedPacketRate(
+    &connection_object);
+  CHECK_EQUAL(20, expected_packet_rate);
+}
+
+TEST(CipConnectionObject, ExpectedPacketRateBelowTimerResolution) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetExpectedPacketRate(&connection_object, 9);
+  CipUint expected_packet_rate = ConnectionObjectGetExpectedPacketRate(
+    &connection_object);
+  CHECK_EQUAL(10, expected_packet_rate);
+}
+
+TEST(CipConnectionObject, ExpectedPacketRateZero) {
+  CipConnectionObject connection_object = { 0 };
+  ConnectionObjectSetExpectedPacketRate(&connection_object, 0);
+  CipUint expected_packet_rate = ConnectionObjectGetExpectedPacketRate(
+    &connection_object);
+  CHECK_EQUAL(0, expected_packet_rate);
+}