Martin Melik Merkumians 9 лет назад
Родитель
Сommit
bc998eaa3d
3 измененных файлов с 44 добавлено и 32 удалено
  1. 4 3
      source/src/cip/cipioconnection.c
  2. 16 14
      source/src/enet_encap/encap.c
  3. 24 15
      source/src/ports/generic_networkhandler.c

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

@@ -433,9 +433,10 @@ EipStatus OpenProducingMulticastConnection(
              == 0) {
              == 0) {
     j = 1;
     j = 1;
   }
   }
-  
-  common_packet_format_data->address_info_item[j].type_id = kCipItemIdSocketAddressInfoTargetToOriginator;
-	
+
+  common_packet_format_data->address_info_item[j].type_id =
+    kCipItemIdSocketAddressInfoTargetToOriginator;
+
   if (NULL == existing_connection_object) { /* we are the first connection producing for the given Input Assembly */
   if (NULL == existing_connection_object) { /* we are the first connection producing for the given Input Assembly */
     return OpenMulticastConnection(kUdpCommuncationDirectionProducing,
     return OpenMulticastConnection(kUdpCommuncationDirectionProducing,
                                    connection_object,
                                    connection_object,

+ 16 - 14
source/src/enet_encap/encap.c

@@ -161,7 +161,7 @@ int HandleReceivedExplictTcpData(int socket,
                                  unsigned int length,
                                  unsigned int length,
                                  int *remaining_bytes,
                                  int *remaining_bytes,
                                  struct sockaddr *originator_address) {
                                  struct sockaddr *originator_address) {
-	OPENER_TRACE_INFO("Handles data for TCP socket: %d\n", socket);
+  OPENER_TRACE_INFO("Handles data for TCP socket: %d\n", socket);
   EipStatus return_value = kEipStatusOk;
   EipStatus return_value = kEipStatusOk;
   EncapsulationData encapsulation_data;
   EncapsulationData encapsulation_data;
   /* eat the encapsulation header*/
   /* eat the encapsulation header*/
@@ -180,45 +180,45 @@ int HandleReceivedExplictTcpData(int socket,
       /* most of these functions need a reply to be send */
       /* most of these functions need a reply to be send */
       switch (encapsulation_data.command_code) {
       switch (encapsulation_data.command_code) {
         case (kEncapsulationCommandNoOperation):
         case (kEncapsulationCommandNoOperation):
-        		OPENER_TRACE_INFO("NOP\n");
+          OPENER_TRACE_INFO("NOP\n");
           /* NOP needs no reply and does nothing */
           /* NOP needs no reply and does nothing */
           return_value = kEipStatusOk;
           return_value = kEipStatusOk;
           break;
           break;
 
 
         case (kEncapsulationCommandListServices):
         case (kEncapsulationCommandListServices):
-                		OPENER_TRACE_INFO("List services\n");
+          OPENER_TRACE_INFO("List services\n");
           HandleReceivedListServicesCommand(&encapsulation_data);
           HandleReceivedListServicesCommand(&encapsulation_data);
           break;
           break;
 
 
         case (kEncapsulationCommandListIdentity):
         case (kEncapsulationCommandListIdentity):
-                		OPENER_TRACE_INFO("List identity\n");
+          OPENER_TRACE_INFO("List identity\n");
           HandleReceivedListIdentityCommandTcp(&encapsulation_data);
           HandleReceivedListIdentityCommandTcp(&encapsulation_data);
           break;
           break;
 
 
         case (kEncapsulationCommandListInterfaces):
         case (kEncapsulationCommandListInterfaces):
-                		OPENER_TRACE_INFO("List interfaces\n");
+          OPENER_TRACE_INFO("List interfaces\n");
           HandleReceivedListInterfacesCommand(&encapsulation_data);
           HandleReceivedListInterfacesCommand(&encapsulation_data);
           break;
           break;
 
 
         case (kEncapsulationCommandRegisterSession):
         case (kEncapsulationCommandRegisterSession):
-                		OPENER_TRACE_INFO("Register session\n");
+          OPENER_TRACE_INFO("Register session\n");
           HandleReceivedRegisterSessionCommand(socket, &encapsulation_data);
           HandleReceivedRegisterSessionCommand(socket, &encapsulation_data);
           break;
           break;
 
 
         case (kEncapsulationCommandUnregisterSession):
         case (kEncapsulationCommandUnregisterSession):
-                		OPENER_TRACE_INFO("unregister session\n");
+          OPENER_TRACE_INFO("unregister session\n");
           return_value = HandleReceivedUnregisterSessionCommand(
           return_value = HandleReceivedUnregisterSessionCommand(
             &encapsulation_data);
             &encapsulation_data);
           break;
           break;
 
 
         case (kEncapsulationCommandSendRequestReplyData):
         case (kEncapsulationCommandSendRequestReplyData):
-                		OPENER_TRACE_INFO("Send Request/Reply Data\n");
+          OPENER_TRACE_INFO("Send Request/Reply Data\n");
           return_value = HandleReceivedSendRequestResponseDataCommand(
           return_value = HandleReceivedSendRequestResponseDataCommand(
             &encapsulation_data, originator_address);
             &encapsulation_data, originator_address);
           break;
           break;
 
 
         case (kEncapsulationCommandSendUnitData):
         case (kEncapsulationCommandSendUnitData):
-                		OPENER_TRACE_INFO("Send Unit Data\n");
+          OPENER_TRACE_INFO("Send Unit Data\n");
           return_value = HandleReceivedSendUnitDataCommand(&encapsulation_data,
           return_value = HandleReceivedSendUnitDataCommand(&encapsulation_data,
                                                            originator_address);
                                                            originator_address);
           break;
           break;
@@ -267,7 +267,7 @@ int HandleReceivedExplictUdpData(int socket,
           break;
           break;
 
 
         case (kEncapsulationCommandListIdentity):
         case (kEncapsulationCommandListIdentity):
-		 OPENER_TRACE_INFO("List Identity\n");
+          OPENER_TRACE_INFO("List Identity\n");
           if(unicast == true) {
           if(unicast == true) {
             HandleReceivedListIdentityCommandTcp(&encapsulation_data);
             HandleReceivedListIdentityCommandTcp(&encapsulation_data);
           }
           }
@@ -279,7 +279,7 @@ int HandleReceivedExplictUdpData(int socket,
           break;
           break;
 
 
         case (kEncapsulationCommandListInterfaces):
         case (kEncapsulationCommandListInterfaces):
-		  OPENER_TRACE_INFO("List Interfaces\n");
+          OPENER_TRACE_INFO("List Interfaces\n");
           HandleReceivedListInterfacesCommand(&encapsulation_data);
           HandleReceivedListInterfacesCommand(&encapsulation_data);
           break;
           break;
 
 
@@ -479,9 +479,11 @@ void HandleReceivedRegisterSessionCommand(int socket,
       {
       {
         receive_data->status = kEncapsulationProtocolInsufficientMemory;
         receive_data->status = kEncapsulationProtocolInsufficientMemory;
       } else { /* successful session registered */
       } else { /* successful session registered */
-    	  SocketTimer *socket_timer = SocketTimerArrayGetEmptySocketTimer(g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
-    	  SocketTimerSetSocket(socket_timer, socket);
-    	  SocketTimerSetLastUpdate(socket_timer, g_actual_time);
+        SocketTimer *socket_timer = SocketTimerArrayGetEmptySocketTimer(
+          g_timestamps,
+          OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
+        SocketTimerSetSocket(socket_timer, socket);
+        SocketTimerSetLastUpdate(socket_timer, g_actual_time);
         g_registered_sessions[session_index] = socket; /* store associated socket */
         g_registered_sessions[session_index] = socket; /* store associated socket */
         receive_data->session_handle = session_index + 1;
         receive_data->session_handle = session_index + 1;
         receive_data->status = kEncapsulationProtocolSuccess;
         receive_data->status = kEncapsulationProtocolSuccess;

+ 24 - 15
source/src/ports/generic_networkhandler.c

@@ -239,9 +239,13 @@ void IApp_CloseSocket_udp(int socket_handle) {
 
 
 void IApp_CloseSocket_tcp(int socket_handle) {
 void IApp_CloseSocket_tcp(int socket_handle) {
   SocketTimer *socket_timer = NULL;
   SocketTimer *socket_timer = NULL;
-  while(NULL != (socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps, OPENER_NUMBER_OF_SUPPORTED_SESSIONS, socket_handle)) )
+  while( NULL !=
+         ( socket_timer =
+             SocketTimerArrayGetSocketTimer(g_timestamps,
+                                            OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
+                                            socket_handle) ) )
   {
   {
-	SocketTimerClear(socket_timer);
+    SocketTimerClear(socket_timer);
   }
   }
   CloseSocket(socket_handle);
   CloseSocket(socket_handle);
 }
 }
@@ -275,15 +279,18 @@ void CheckAndHandleTcpListenerSocket(void) {
       FreeErrorMessage(error_message);
       FreeErrorMessage(error_message);
       return;
       return;
     }
     }
-    OPENER_TRACE_INFO(">>> network handler: accepting new TCP socket: %d \n", new_socket);
+    OPENER_TRACE_INFO(">>> network handler: accepting new TCP socket: %d \n",
+                      new_socket);
 
 
     SocketTimer *socket_timer = SocketTimerArrayGetEmptySocketTimer(
     SocketTimer *socket_timer = SocketTimerArrayGetEmptySocketTimer(
-          g_timestamps,
-		  OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
+      g_timestamps,
+      OPENER_NUMBER_OF_SUPPORTED_SESSIONS);
 
 
     OPENER_TRACE_INFO("Current time stamp: %ld\n", g_actual_time);
     OPENER_TRACE_INFO("Current time stamp: %ld\n", g_actual_time);
-    for(size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS;i++) {
-    	OPENER_TRACE_INFO("Socket: %d - Last Update: %ld\n", g_timestamps[i].socket, g_timestamps[i].last_update);
+    for(size_t i = 0; i < OPENER_NUMBER_OF_SUPPORTED_SESSIONS; i++) {
+      OPENER_TRACE_INFO("Socket: %d - Last Update: %ld\n",
+                        g_timestamps[i].socket,
+                        g_timestamps[i].last_update);
     }
     }
 
 
     OPENER_ASSERT(socket_timer != NULL);
     OPENER_ASSERT(socket_timer != NULL);
@@ -537,7 +544,7 @@ EipStatus HandleDataOnTcpSocket(int socket) {
                                    0); /*TODO we may have to set the socket to a non blocking socket */
                                    0); /*TODO we may have to set the socket to a non blocking socket */
 
 
   SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
   SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
-		  OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
+                                                             OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
                                                              socket);
                                                              socket);
   if (number_of_read_bytes == 0) {
   if (number_of_read_bytes == 0) {
     int error_code = GetSocketErrorNumber();
     int error_code = GetSocketErrorNumber();
@@ -653,7 +660,7 @@ EipStatus HandleDataOnTcpSocket(int socket) {
       socket, g_ethernet_communication_buffer, data_size, &remaining_bytes,
       socket, g_ethernet_communication_buffer, data_size, &remaining_bytes,
       &sender_address);
       &sender_address);
     SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
     SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
-    		OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
+                                                               OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
                                                                socket);
                                                                socket);
     if(NULL != socket_timer) {
     if(NULL != socket_timer) {
       SocketTimerSetLastUpdate(socket_timer, g_actual_time);
       SocketTimerSetLastUpdate(socket_timer, g_actual_time);
@@ -673,7 +680,7 @@ EipStatus HandleDataOnTcpSocket(int socket) {
       data_sent = send(socket, (char *) &g_ethernet_communication_buffer[0],
       data_sent = send(socket, (char *) &g_ethernet_communication_buffer[0],
                        number_of_read_bytes, 0);
                        number_of_read_bytes, 0);
       SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
       SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
-    		  OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
+                                                                 OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
                                                                  socket);
                                                                  socket);
       SocketTimerSetLastUpdate(socket_timer, g_actual_time);
       SocketTimerSetLastUpdate(socket_timer, g_actual_time);
       if (data_sent != number_of_read_bytes) {
       if (data_sent != number_of_read_bytes) {
@@ -785,7 +792,7 @@ int CreateUdpSocket(UdpCommuncationDirection communication_direction,
   /* add new socket to the master list                                             */
   /* add new socket to the master list                                             */
   FD_SET(new_socket, &master_socket);
   FD_SET(new_socket, &master_socket);
   if (new_socket > highest_socket_handle) {
   if (new_socket > highest_socket_handle) {
-	OPENER_TRACE_INFO("New highest socket: %d", new_socket);
+    OPENER_TRACE_INFO("New highest socket: %d", new_socket);
     highest_socket_handle = new_socket;
     highest_socket_handle = new_socket;
   }
   }
   return new_socket;
   return new_socket;
@@ -850,8 +857,8 @@ void CloseSocket(const int socket_handle) {
   OPENER_TRACE_INFO("networkhandler: closing socket %d\n", socket_handle);
   OPENER_TRACE_INFO("networkhandler: closing socket %d\n", socket_handle);
 
 
   if (kEipInvalidSocket != socket_handle) {
   if (kEipInvalidSocket != socket_handle) {
-      FD_CLR(socket_handle, &master_socket);
-      CloseSocketPlatform(socket_handle);
+    FD_CLR(socket_handle, &master_socket);
+    CloseSocketPlatform(socket_handle);
   }
   }
   OPENER_TRACE_INFO("networkhandler: closing socket done %d\n", socket_handle);
   OPENER_TRACE_INFO("networkhandler: closing socket done %d\n", socket_handle);
 }
 }
@@ -876,10 +883,12 @@ void CheckEncapsulationInactivity(int socket_handle) {
 
 
   if (0 < g_encapsulation_inactivity_timeout) {
   if (0 < g_encapsulation_inactivity_timeout) {
     SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
     SocketTimer *socket_timer = SocketTimerArrayGetSocketTimer(g_timestamps,
-    		OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
+                                                               OPENER_NUMBER_OF_SUPPORTED_SESSIONS,
                                                                socket_handle);
                                                                socket_handle);
 
 
-    OPENER_TRACE_INFO("Check socket %d - socket timer: %p\n", socket_handle, socket_timer);
+    OPENER_TRACE_INFO("Check socket %d - socket timer: %p\n",
+                      socket_handle,
+                      socket_timer);
     if(NULL != socket_timer) {
     if(NULL != socket_timer) {
       MilliSeconds diffms = g_actual_time - SocketTimerGetLastUpdate(
       MilliSeconds diffms = g_actual_time - SocketTimerGetLastUpdate(
         socket_timer);
         socket_timer);