Explorar o código

timeout checker functions handling added (#399)

* .gitignore update

* cipcommon max_instance BUGFIX

* uncrustify update

* cleanup

* timeout checker functions handling added
micsat %!s(int64=3) %!d(string=hai) anos
pai
achega
cb4f7e9020
Modificáronse 3 ficheiros con 41 adicións e 10 borrados
  1. 1 10
      source/src/cip/cipcommon.c
  2. 14 0
      source/src/opener_api.h
  3. 26 0
      source/src/ports/generic_networkhandler.c

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

@@ -1417,16 +1417,7 @@ EipStatus CipDeleteService(CipInstance *RESTRICT const instance,
     class->number_of_instances--; /* update the total number of instances
                                             recorded by the class - Attr. 3 */
 
-    // update largest instance number (class Attribute 2)
-    instances = class->instances;
-    EipUint16 max_instance = 0;
-    while (NULL != instances->next) {
-      if(instances->instance_number > max_instance) {
-        max_instance = instances->instance_number;
-      }
-      instances = instances->next;
-    }
-    class->max_instance = max_instance;
+    class->max_instance = GetMaxInstanceNumber(class); /* update largest instance number (class Attribute 2) */
 
     message_router_response->general_status = kCipErrorSuccess;
   }

+ 14 - 0
source/src/opener_api.h

@@ -617,6 +617,13 @@ typedef CipError (*ConnectionReceiveDataFunction)(CipConnectionObject *
                                                   const EipUint8 *data,
                                                   const EipUint16 data_length);
 
+ /** @ingroup CIP_API
+ * @brief Function pointer for timeout checker functions 
+ *
+ * @param elapsed_time elapsed time since last check
+ */
+typedef void (*TimeoutCheckerFunction)(const MilliSeconds elapsed_time);
+
 /** @ingroup CIP_API
  * @brief register open functions for an specific object.
  *
@@ -941,6 +948,13 @@ EipStatus SendUdpData(const struct sockaddr_in *const socket_data,
  */
 void CloseSocket(const int socket_handle);
 
+/** @ingroup CIP_CALLBACK_API
+ * @brief Register function pointer in timeout_checker_array
+ *
+ * @param timeout_checker_function pointer to object specific timeout checker function
+ */
+void RegisterTimeoutChecker(TimeoutCheckerFunction timeout_checker_function);
+
 /** @mainpage OpENer - Open Source EtherNet/IP(TM) Communication Stack
  * Documentation
  *

+ 26 - 0
source/src/ports/generic_networkhandler.c

@@ -74,6 +74,14 @@ MilliSeconds g_last_time;
 
 NetworkStatus g_network_status;
 
+/** @brief Size of the timeout checker function pointer array
+ */
+#define OPENER_TIMEOUT_CHECKER_ARRAY_SIZE 10 
+
+/** @brief function pointer array for timer checker functions
+ */
+TimeoutCheckerFunction timeout_checker_array[OPENER_TIMEOUT_CHECKER_ARRAY_SIZE];
+
 /** @brief handle any connection request coming in the TCP server socket.
  *
  */
@@ -499,6 +507,14 @@ EipStatus NetworkHandlerProcessCyclic(void) {
   if(g_network_status.elapsed_time >= kOpenerTimerTickInMilliSeconds) {
     /* call manage_connections() in connection manager every kOpenerTimerTickInMilliSeconds ms */
     ManageConnections(g_network_status.elapsed_time);
+
+    /* Call timeout checker functions registered in timeout_checker_array */
+    for (size_t i = 0; i < OPENER_TIMEOUT_CHECKER_ARRAY_SIZE; i++) {
+      if (NULL != timeout_checker_array[i]) {
+        (timeout_checker_array[i])(g_network_status.elapsed_time);
+      }
+    }
+
     g_network_status.elapsed_time = 0;
   }
   return kEipStatusOk;
@@ -1129,3 +1145,13 @@ void CheckEncapsulationInactivity(int socket_handle) {
     }
   }
 }
+
+void RegisterTimeoutChecker(TimeoutCheckerFunction timeout_checker_function)
+{
+  for (size_t i = 0; i < OPENER_TIMEOUT_CHECKER_ARRAY_SIZE; i++) {
+    if (NULL == timeout_checker_array[i]) { // find empty array element
+      timeout_checker_array[i] = timeout_checker_function; // add function pointer to array
+      break;
+    }
+  }
+}