Parcourir la source

Code and documentation cleanup

CapXilinx il y a 9 ans
Parent
commit
daebe7be37

+ 18 - 20
source/src/cip/cipconnectionmanager.c

@@ -80,6 +80,7 @@ void SetProductionTrigger(const enum ProductionTrigger production_trigger,
       connection_object->transport_type_class_trigger = 0x20;
       connection_object->transport_type_class_trigger = 0x20;
       break;
       break;
     default:
     default:
+    	//TODO: Replace with assert?
       connection_object->transport_type_class_trigger = 0x30;
       connection_object->transport_type_class_trigger = 0x30;
       break;           /**< Invalid value */
       break;           /**< Invalid value */
   }
   }
@@ -394,10 +395,10 @@ void ReadOutConnectionObjectFromMessage(
 
 
 ForwardOpenConnectionType GetConnectionType(
 ForwardOpenConnectionType GetConnectionType(
   EipUint16 network_connection_parameter) {
   EipUint16 network_connection_parameter) {
-  const uint16_t connection_parameter_mask = 0x6000;
+  const EipUint16 kConnectionParameterMask = 0x6000;
 
 
   ForwardOpenConnectionType connection_type = network_connection_parameter
   ForwardOpenConnectionType connection_type = network_connection_parameter
-                                              & connection_parameter_mask;
+                                              & kConnectionParameterMask;
 
 
   OPENER_TRACE_INFO(
   OPENER_TRACE_INFO(
     "Connection type: %x / network connection parameter: %x\n",
     "Connection type: %x / network connection parameter: %x\n",
@@ -409,7 +410,8 @@ ForwardOpenConnectionType GetConnectionType(
  *
  *
  */
  */
 typedef EipStatus (*HandleForwardOpenRequestFunction)(
 typedef EipStatus (*HandleForwardOpenRequestFunction)(
-  ConnectionObject *connection_object, CipInstance *instance,
+  ConnectionObject *connection_object,
+  CipInstance *instance,
   CipMessageRouterRequest *message_router_request,
   CipMessageRouterRequest *message_router_request,
   CipMessageRouterResponse *message_router_response);
   CipMessageRouterResponse *message_router_response);
 
 
@@ -788,13 +790,12 @@ EipStatus GetConnectionOwner(CipInstance *instance,
 }
 }
 
 
 EipStatus ManageConnections(MilliSeconds elapsed_time) {
 EipStatus ManageConnections(MilliSeconds elapsed_time) {
-  ConnectionObject *connection_object;
 
 
   /*Inform application that it can execute */
   /*Inform application that it can execute */
   HandleApplication();
   HandleApplication();
   ManageEncapsulationMessages(elapsed_time);
   ManageEncapsulationMessages(elapsed_time);
 
 
-  connection_object = g_active_connection_list;
+  ConnectionObject *connection_object = g_active_connection_list;
   while (NULL != connection_object) {
   while (NULL != connection_object) {
     if (connection_object->state == kConnectionStateEstablished) {
     if (connection_object->state == kConnectionStateEstablished) {
       if ( (0 != connection_object->consuming_instance) ||                  /* we have a consuming connection check inactivity watchdog timer */
       if ( (0 != connection_object->consuming_instance) ||                  /* we have a consuming connection check inactivity watchdog timer */
@@ -858,19 +859,16 @@ EipStatus ManageConnections(MilliSeconds elapsed_time) {
   return kEipStatusOk;
   return kEipStatusOk;
 }
 }
 
 
-/* TODO: Update Documentation  INT8 assembleFWDOpenResponse(S_CIP_ConnectionObject *pa_pstConnObj, S_CIP_MR_Response * pa_MRResponse, EIP_UINT8 pa_nGeneralStatus, EIP_UINT16 pa_nExtendedStatus,
-   void * deleteMeSomeday, EIP_UINT8 * pa_msg)
- *   create FWDOpen response dependent on status.
- *      pa_pstConnObj pointer to connection Object
- *      pa_MRResponse	pointer to message router response
- *      pa_nGeneralStatus the general status of the response
- *      pa_nExtendedStatus extended status in the case of an error otherwise 0
- *      pa_CPF_data	pointer to CPF Data Item
- *      pa_msg		pointer to memory where reply has to be stored
- *  return status
- *                      0 .. no reply need to be sent back
- *                      1 .. need to send reply
- *                -1 .. error
+/** @brief Assembles the Forward Open Response
+ *
+ * @param connection_object pointer to connection Object
+ * @param message_router_response pointer to message router response
+ * @param general_status the general status of the response
+ * @param extended_status extended status in the case of an error otherwise 0
+ * @return status
+ *   kEipStatusOk .. no reply need to be sent back
+ *   kEipStatusOkSend .. need to send reply
+ *   kEipStatusError .. error
  */
  */
 EipStatus AssembleForwardOpenResponse(
 EipStatus AssembleForwardOpenResponse(
   ConnectionObject *connection_object,
   ConnectionObject *connection_object,
@@ -912,7 +910,7 @@ EipStatus AssembleForwardOpenResponse(
                      &message);
                      &message);
   } else {
   } else {
     /* we have an connection creation error */
     /* we have an connection creation error */
-    OPENER_TRACE_INFO("assembleFWDOpenResponse: sending error response\n");
+    OPENER_TRACE_INFO("AssembleForwardOpenResponse: sending error response\n");
     connection_object->state = kConnectionStateNonExistent;
     connection_object->state = kConnectionStateNonExistent;
     message_router_response->data_length = 10;
     message_router_response->data_length = 10;
 
 
@@ -1484,7 +1482,7 @@ EipUint8 ParseConnectionPath(ConnectionObject *connection_object,
               "No data segment identifier found for the configuration data\n");
               "No data segment identifier found for the configuration data\n");
             *extended_error = connection_object->connection_path_size
             *extended_error = connection_object->connection_path_size
                               - remaining_path_size;                           /*offset in 16Bit words where within the connection path the error happend*/
                               - remaining_path_size;                           /*offset in 16Bit words where within the connection path the error happend*/
-            return 0x04;                             /*status code for invalid segment type*/
+            return 0x04; /* kConnectionManagerGeneralStatusPathSegmentErrorInUnconnectedSend */
             break;
             break;
         }
         }
       }
       }

+ 3 - 3
source/src/opener_api.h

@@ -342,7 +342,7 @@ typedef EipStatus (*ConnectionReceiveDataFunction)(
  * With this function any object can be enabled to be a target for forward
  * With this function any object can be enabled to be a target for forward
  * open/close request.
  * open/close request.
  * @param class_id The class ID
  * @param class_id The class ID
- * @param open_connection_function   pointer to the function handling the open
+ * @param open_connection_function Pointer to the function handling the open
  * process
  * process
  * @return EIP_OK on success
  * @return EIP_OK on success
  */
  */
@@ -615,13 +615,13 @@ ResetDeviceToInitialConfiguration(void);
  * @param size_of_element size in bytes of one element
  * @param size_of_element size in bytes of one element
  * @return pointer to the allocated memory, 0 on error
  * @return pointer to the allocated memory, 0 on error
  */
  */
-void *CipCalloc(unsigned int number_of_elements, unsigned int size_of_element);
+void *CipCalloc(size_t number_of_elements, size_t size_of_element);
 
 
 /** @ingroup CIP_CALLBACK_API
 /** @ingroup CIP_CALLBACK_API
  * @brief Free memory allocated by the OpENer
  * @brief Free memory allocated by the OpENer
  *
  *
  * emulate the common c-library function free
  * emulate the common c-library function free
- * @param pa_poData pointer to the allocated memory
+ * @param data pointer to the allocated memory
  */
  */
 void CipFree(void *data);
 void CipFree(void *data);
 
 

+ 8 - 0
source/src/ports/POSIX/networkhandler.h

@@ -11,8 +11,16 @@
 
 
 #include "typedefs.h"
 #include "typedefs.h"
 
 
+/** @brief Executes platform dependent network handler initialization code
+ *
+ * 	@return EipStatusOk if initialization was successful, otherwise EipStatusError
+ */
 EipStatus NetworkHandlerInitializePlatform(void);
 EipStatus NetworkHandlerInitializePlatform(void);
 
 
+/** @brief Platform dependent code to close a socket
+ *
+ *  @param socket_handle The socket handle to be closed
+ */
 void CloseSocketPlatform(int socket_handle);
 void CloseSocketPlatform(int socket_handle);
 
 
 /** @brief This function shall return the current time in microseconds relative to epoch, and shall be implemented in a port specific networkhandler
 /** @brief This function shall return the current time in microseconds relative to epoch, and shall be implemented in a port specific networkhandler

+ 3 - 3
source/src/ports/POSIX/opener_error.c

@@ -17,15 +17,15 @@
 
 
 #include "opener_error.h"
 #include "opener_error.h"
 
 
-const int error_message_buffer_size = 255;
+const int kErrorMessageBufferSize = 255;
 
 
 int GetSocketErrorNumber() {
 int GetSocketErrorNumber() {
   return errno;
   return errno;
 }
 }
 
 
 char *GetErrorMessage(int error_number) {
 char *GetErrorMessage(int error_number) {
-  char *error_message = malloc(error_message_buffer_size);
-  strerror_r(error_number, error_message, error_message_buffer_size);
+  char *error_message = malloc(kErrorMessageBufferSize);
+  strerror_r(error_number, error_message, kErrorMessageBufferSize);
   return error_message;
   return error_message;
 }
 }
 
 

+ 1 - 1
source/src/ports/POSIX/sample_application/sampleapplication.c

@@ -132,7 +132,7 @@ EipStatus ResetDeviceToInitialConfiguration(void) {
 }
 }
 
 
 void *
 void *
-CipCalloc(unsigned int number_of_elements, unsigned size_of_element) {
+CipCalloc(size_t number_of_elements, size_t size_of_element) {
   return calloc(number_of_elements, size_of_element);
   return calloc(number_of_elements, size_of_element);
 }
 }
 
 

+ 2 - 2
source/src/ports/generic_networkhandler.c

@@ -243,7 +243,7 @@ EipBool8 CheckSocketSet(int socket) {
 }
 }
 
 
 void CheckAndHandleTcpListenerSocket(void) {
 void CheckAndHandleTcpListenerSocket(void) {
-  int new_socket;
+  int new_socket = kEipInvalidSocket;
   /* see if this is a connection request to the TCP listener*/
   /* see if this is a connection request to the TCP listener*/
   if ( true == CheckSocketSet(g_network_status.tcp_listener) ) {
   if ( true == CheckSocketSet(g_network_status.tcp_listener) ) {
     OPENER_TRACE_INFO("networkhandler: new TCP connection\n");
     OPENER_TRACE_INFO("networkhandler: new TCP connection\n");
@@ -324,7 +324,7 @@ EipStatus NetworkHandlerProcessOnce(void) {
    * This should compensate the jitter of the windows timer
    * This should compensate the jitter of the windows timer
    */
    */
   if (g_network_status.elapsed_time >= kOpenerTimerTickInMilliSeconds) {
   if (g_network_status.elapsed_time >= kOpenerTimerTickInMilliSeconds) {
-    /* call manage_connections() in connection manager every OPENER_TIMER_TICK ms */
+    /* call manage_connections() in connection manager every kOpenerTimerTickInMilliSeconds ms */
     ManageConnections(g_network_status.elapsed_time);
     ManageConnections(g_network_status.elapsed_time);
     g_network_status.elapsed_time = 0;
     g_network_status.elapsed_time = 0;
   }
   }