Răsfoiți Sursa

Fixes #109 PIT mismatch and PIT bug

Signed-off-by: CapXilinx <melik-merkumians@acin.tuwien.ac.at>
CapXilinx 8 ani în urmă
părinte
comite
92f5e0e148

+ 27 - 61
source/src/cip/cipconnectionmanager.c

@@ -51,8 +51,7 @@ typedef struct {
 
 /* Connection Object functions */
 ProductionTrigger GetProductionTrigger(
-  const ConnectionObject *const connection_object
-  ) {
+  const ConnectionObject *const connection_object) {
   const unsigned int ProductionTriggerMask = 0x70;
 
   switch (connection_object->transport_type_class_trigger
@@ -90,8 +89,7 @@ void SetProductionTrigger(
 }
 
 CipUint GetProductionInhibitTime(
-  const ConnectionObject *const connection_object
-  ) {
+  const ConnectionObject *const connection_object) {
   return connection_object->production_inhibit_time;
 }
 
@@ -103,15 +101,13 @@ void SetProductionInhibitTime(
 }
 
 CipUdint GetTargetToOriginatorRequestedPackedInterval(
-  const ConnectionObject *const RESTRICT connection_object
-  ) {
+  const ConnectionObject *const RESTRICT connection_object) {
   return connection_object->t_to_o_requested_packet_interval;
 }
 
 ConnectionObjectFixedVariable
 GetConnectionObjectTargetToOriginatorFixedOrVariableConnectionSize(
-  const ConnectionObject *const RESTRICT connection_object
-  ) {
+  const ConnectionObject *const RESTRICT connection_object) {
   const EipUint16 kFixedOrVariableMask = 1 << 9;
   if ( ( (connection_object->t_to_o_network_connection_parameter) &
          kFixedOrVariableMask ) == kFixedOrVariableMask ) {
@@ -218,11 +214,9 @@ EipUint8 ParseConnectionPath(
   CipMessageRouterRequest *message_router_request,
   EipUint16 *extended_error);
 
-ConnectionManagementHandling *GetConnectionManagementEntry(
-  EipUint32 class_id);
+ConnectionManagementHandling *GetConnectionManagementEntry(EipUint32 class_id);
 
-void InitializeConnectionManagerData(
-  void);
+void InitializeConnectionManagerData(void);
 
 void AddNullAddressItem(
   CipCommonPacketFormatData *common_data_packet_format_data);
@@ -232,9 +226,7 @@ void AddNullAddressItem(
  *
  * @return The padded logical path
  */
-unsigned int GetPaddedLogicalPath(
-  const EipUint8 **logical_path_segment
-  ) {
+unsigned int GetPaddedLogicalPath(const EipUint8 **logical_path_segment) {
   unsigned int padded_logical_path = *(*logical_path_segment)++;
 
   if ( (padded_logical_path & 3) == 0 ) {
@@ -256,17 +248,13 @@ unsigned int GetPaddedLogicalPath(
  * and the per-new-connection-incremented connection number/counter.
  * @return new connection id
  */
-EipUint32 GetConnectionId(
-  void
-  ) {
+EipUint32 GetConnectionId(void) {
   static EipUint32 connection_id = 18;
   connection_id++;
   return ( g_incarnation_id | (connection_id & 0x0000FFFF) );
 }
 
-void InitializeConnectionManager(
-  CipClass *class
-  ) {
+void InitializeConnectionManager(CipClass *class) {
 
   CipClass *meta_class = class->class_instance.cip_class;
 
@@ -290,9 +278,7 @@ void InitializeConnectionManager(
 
 }
 
-EipStatus ConnectionManagerInit(
-  EipUint16 unique_connection_id
-  ) {
+EipStatus ConnectionManagerInit(EipUint16 unique_connection_id) {
   InitializeConnectionManagerData();
 
   CipClass *connection_manager = CreateCipClass(
@@ -460,8 +446,7 @@ void ReadOutConnectionObjectFromMessage(
 }
 
 ForwardOpenConnectionType GetConnectionType(
-  EipUint16 network_connection_parameter
-  ) {
+  EipUint16 network_connection_parameter) {
   const EipUint16 kConnectionParameterMask = 0x6000;
 
   ForwardOpenConnectionType connection_type = network_connection_parameter
@@ -475,8 +460,7 @@ ForwardOpenConnectionType GetConnectionType(
 }
 
 ForwardOpenPriority GetConnectionObjectTToOPriority(
-  const ConnectionObject *const connection_object
-  ) {
+  const ConnectionObject *const connection_object) {
 
   const EipUint16 kConnectionParameterMask = 0xC00;
   CipUsint priority_value = 0x00;
@@ -738,9 +722,7 @@ EipStatus ForwardOpen(
                           message_router_request, message_router_response);
 }
 
-void GeneralConnectionConfiguration(
-  ConnectionObject *connection_object
-  ) {
+void GeneralConnectionConfiguration(ConnectionObject *connection_object) {
   if ( kForwardOpenConnectionTypePointToPointConnection
        == (connection_object->o_to_t_network_connection_parameter
            & kForwardOpenConnectionTypePointToPointConnection) ) {
@@ -784,8 +766,7 @@ void GeneralConnectionConfiguration(
                                                             / 1000 );
   }
 
-  connection_object->production_inhibit_timer = connection_object
-                                                ->production_inhibit_time = 0;
+  connection_object->production_inhibit_timer = 0;
 
   /*setup the preconsumption timer: max(ConnectionTimeoutMultiplier * ExpectedPacketRate, 10s) */
   connection_object->inactivity_watchdog_timer =
@@ -883,9 +864,7 @@ EipStatus GetConnectionOwner(
   return kEipStatusOk;
 }
 
-EipStatus ManageConnections(
-  MilliSeconds elapsed_time
-  ) {
+EipStatus ManageConnections(MilliSeconds elapsed_time) {
   //OPENER_TRACE_INFO("Entering ManageConnections\n");
   /*Inform application that it can execute */
   HandleApplication();
@@ -1073,8 +1052,7 @@ EipStatus AssembleForwardOpenResponse(
  * @param common_data_packet_format_data The CPF data packet where the Null Address Item shall be added
  */
 void AddNullAddressItem(
-  CipCommonPacketFormatData *common_data_packet_format_data
-  ) {
+  CipCommonPacketFormatData *common_data_packet_format_data) {
   /* Precondition: Null Address Item only valid in unconnected messages */
   assert(
     common_data_packet_format_data->data_item.type_id
@@ -1147,9 +1125,7 @@ EipStatus AssembleForwardCloseResponse(
   return kEipStatusOkSend;
 }
 
-ConnectionObject *GetConnectedObject(
-  EipUint32 connection_id
-  ) {
+ConnectionObject *GetConnectedObject(EipUint32 connection_id) {
   ConnectionObject *active_connection_object_list_item =
     g_active_connection_list;
   while (NULL != active_connection_object_list_item) {
@@ -1166,9 +1142,7 @@ ConnectionObject *GetConnectedObject(
   return NULL;
 }
 
-ConnectionObject *GetConnectedOutputAssembly(
-  EipUint32 output_assembly_id
-  ) {
+ConnectionObject *GetConnectedOutputAssembly(EipUint32 output_assembly_id) {
   ConnectionObject *active_connection_object_list_item =
     g_active_connection_list;
 
@@ -1189,8 +1163,7 @@ ConnectionObject *GetConnectedOutputAssembly(
 }
 
 ConnectionObject *CheckForExistingConnection(
-  ConnectionObject *connection_object
-  ) {
+  ConnectionObject *connection_object) {
   ConnectionObject *active_connection_object_list_item =
     g_active_connection_list;
 
@@ -1387,6 +1360,7 @@ EipUint8 ParseConnectionPath(
           GetPathNetworkSegmentSubtype(message);
         if (kNetworkSegmentSubtypeProductionInhibitTimeInMilliseconds
             == network_segment_subtype) {
+          OPENER_TRACE_INFO("PIT segment available - value: %u\n",message[1]);
           connection_object->production_inhibit_time = message[1];
           message += 2;
           remaining_path_size -= 1;
@@ -1582,14 +1556,14 @@ EipUint8 ParseConnectionPath(
     }
   }
 
+  OPENER_TRACE_INFO("Resulting PIT value: %u\n",
+                    connection_object->production_inhibit_time);
   /*save back the current position in the stream allowing followers to parse anything thats still there*/
   message_router_request->data = message;
   return kEipStatusOk;
 }
 
-void CloseConnection(
-  ConnectionObject *RESTRICT connection_object
-  ) {
+void CloseConnection(ConnectionObject *RESTRICT connection_object) {
   connection_object->state = kConnectionStateNonExistent;
   if ( 0x03 != (connection_object->transport_type_class_trigger & 0x03) ) {
     /* only close the UDP connection for not class 3 connections */
@@ -1612,9 +1586,7 @@ void CopyConnectionData(
   memcpy( destination, source, sizeof(ConnectionObject) );
 }
 
-void AddNewActiveConnection(
-  ConnectionObject *connection_object
-  ) {
+void AddNewActiveConnection(ConnectionObject *connection_object) {
   connection_object->first_connection_object = NULL;
   connection_object->next_connection_object = g_active_connection_list;
   if (NULL != g_active_connection_list) {
@@ -1624,9 +1596,7 @@ void AddNewActiveConnection(
   g_active_connection_list->state = kConnectionStateEstablished;
 }
 
-void RemoveFromActiveConnections(
-  ConnectionObject *connection_object
-  ) {
+void RemoveFromActiveConnections(ConnectionObject *connection_object) {
 
   if (NULL != connection_object->first_connection_object) {
     connection_object->first_connection_object->next_connection_object =
@@ -1644,9 +1614,7 @@ void RemoveFromActiveConnections(
   connection_object->state = kConnectionStateNonExistent;
 }
 
-EipBool8 IsConnectedOutputAssembly(
-  const EipUint32 instance_number
-  ) {
+EipBool8 IsConnectedOutputAssembly(const EipUint32 instance_number) {
   EipBool8 is_connected = false;
 
   ConnectionObject *iterator = g_active_connection_list;
@@ -1683,9 +1651,7 @@ EipStatus AddConnectableObject(
 }
 
 ConnectionManagementHandling *
-GetConnectionManagementEntry(
-  EipUint32 class_id
-  ) {
+GetConnectionManagementEntry(EipUint32 class_id) {
 
   ConnectionManagementHandling *connection_management_entry = NULL;
 

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

@@ -102,6 +102,8 @@ typedef enum {
   kConnectionManagerExtendedStatusCodeMismatchedTToONetworkConnectionPriority =
     0x0136,
   kConnectionManagerExtendedStatusCodeMismatchedTransportClass = 0x0137,
+  kConnectionManagerExtendedStatusCodeMismatchedTToOProductionInhibitTimeSegment
+    = 0x0139,
   kConnectionManagerExtendedStatusCodeConnectionTimedOut = 0x0203,
   kConnectionManagerExtendedStatusCodeUnconnectedRequestTimedOut = 0x0204,
   kConnectionManagerExtendedStatusCodeErrorParameterErrorInUnconnectedSendService

+ 17 - 19
source/src/cip/cipioconnection.c

@@ -95,11 +95,12 @@ unsigned int g_config_data_length = 0; /**< length of g_config_data_buffer. Init
 
 EipUint32 g_run_idle_state; /**< buffer for holding the run idle information. */
 
-EipUint16 ProcessProductionInhibitTime(ConnectionObject *io_connection_object
-                                       ) {
+EipUint16 ProcessProductionInhibitTime(ConnectionObject *io_connection_object)
+{
   if ( kProductionTriggerCyclic
        == GetProductionTrigger(io_connection_object) ) {
     if ( 256 == GetProductionInhibitTime(io_connection_object) ) {
+      OPENER_TRACE_INFO("No PIT segment available\n");
       /* there was no PIT segment in the connection path; set PIT to one fourth of RPI */
       SetProductionInhibitTime(
         GetTargetToOriginatorRequestedPackedInterval(io_connection_object)
@@ -119,9 +120,7 @@ EipUint16 ProcessProductionInhibitTime(ConnectionObject *io_connection_object
 }
 
 CipConnectionObjectTransportClassTriggerClass GetConnectionObjectTransportClass(
-  const ConnectionObject *const connection_object
-  )
-{
+  const ConnectionObject *const connection_object) {
   const unsigned int kTransportClassMask = 0x0F;
 
   switch(connection_object->transport_type_class_trigger &
@@ -137,8 +136,7 @@ CipConnectionObjectTransportClassTriggerClass GetConnectionObjectTransportClass(
   return kCipConnectionObjectTransportClassTriggerClassInvalid;
 }
 
-void SetIoConnectionCallbacks(ConnectionObject *const io_connection_object
-                              ) {
+void SetIoConnectionCallbacks(ConnectionObject *const io_connection_object) {
   io_connection_object->connection_close_function = CloseIoConnection;
   io_connection_object->connection_timeout_function = HandleIoConnectionTimeOut;
   io_connection_object->connection_send_data_function = SendConnectedData;
@@ -232,6 +230,12 @@ EipUint16 SetupIoConnectionTargetToOriginatorConnectionPoint(
         return kConnectionManagerExtendedStatusCodeMismatchedTransportClass;
       }
 
+      if( GetProductionInhibitTime(io_connection_object) !=
+          GetProductionInhibitTime(iterator) ) {
+        return
+          kConnectionManagerExtendedStatusCodeMismatchedTToOProductionInhibitTimeSegment;
+      }
+
     }
 
     iterator = iterator->next_connection_object;
@@ -640,8 +644,7 @@ EipStatus OpenMulticastConnection(
   return kEipStatusOk;
 }
 
-EipUint16 HandleConfigData(ConnectionObject *connection_object
-                           ) {
+EipUint16 HandleConfigData(ConnectionObject *connection_object) {
 
   CipClass *const assembly_class = GetCipClass(kCipAssemblyClassCode);
   EipUint16 connection_manager_status = 0;
@@ -688,8 +691,7 @@ EipUint16 HandleConfigData(ConnectionObject *connection_object
   return connection_manager_status;
 }
 
-void CloseIoConnection(ConnectionObject *connection_object
-                       ) {
+void CloseIoConnection(ConnectionObject *connection_object) {
 
   CheckIoConnectionEvent(connection_object->connection_path.connection_point[
                            kConnectionPointConsumer],
@@ -738,8 +740,7 @@ void CloseIoConnection(ConnectionObject *connection_object
     connection_object);
 }
 
-void HandleIoConnectionTimeOut(ConnectionObject *connection_object
-                               ) {
+void HandleIoConnectionTimeOut(ConnectionObject *connection_object) {
   CheckIoConnectionEvent(connection_object->connection_path.connection_point[0],
                          connection_object->connection_path.connection_point[1],
                          kIoConnectionEventTimedOut);
@@ -786,8 +787,7 @@ void HandleIoConnectionTimeOut(ConnectionObject *connection_object
   connection_object->connection_close_function(connection_object);
 }
 
-EipStatus SendConnectedData(ConnectionObject *connection_object
-                            ) {
+EipStatus SendConnectedData(ConnectionObject *connection_object) {
 
   /* TODO think of adding an own send buffer to each connection object in order to preset up the whole message on connection opening and just change the variable data items e.g., sequence number */
 
@@ -903,8 +903,7 @@ EipStatus HandleReceivedIoConnectionData(
   return kEipStatusOk;
 }
 
-EipStatus OpenCommunicationChannels(ConnectionObject *connection_object
-                                    ) {
+EipStatus OpenCommunicationChannels(ConnectionObject *connection_object) {
 
   EipStatus eip_status = kEipStatusOk;
   /*get pointer to the CPF data, currently we have just one global instance of the struct. This may change in the future*/
@@ -966,8 +965,7 @@ EipStatus OpenCommunicationChannels(ConnectionObject *connection_object
 }
 
 void CloseCommunicationChannelsAndRemoveFromActiveConnectionsList(
-  ConnectionObject *connection_object
-  ) {
+  ConnectionObject *connection_object) {
   IApp_CloseSocket_udp(
     connection_object->socket[kUdpCommuncationDirectionConsuming]);
 

+ 7 - 2
uncrustify.cfg

@@ -112,7 +112,6 @@ indent_with_tabs=0
 sp_arith=add
 sp_assign=add
 sp_assign_default=add
-sp_before_assign=ignore
 sp_enum_assign=add
 sp_pp_concat=add
 sp_pp_stringify=add
@@ -120,16 +119,22 @@ sp_before_ptr_star=add
 sp_between_ptr_star=remove
 sp_after_ptr_star=remove
 sp_after_ptr_star_func=remove
-sp_fparen_brace=add
+sp_func_def_paren=remove
+sp_fparen_brace=force
 nl_case_colon_brace=remove
 nl_class_brace=remove
 nl_func_decl_start_single=remove
 nl_func_def_start_single=remove
 nl_func_decl_args=add
 nl_func_def_args=add
+nl_func_decl_end_single=remove
+nl_func_def_end_single=remove
+nl_func_decl_empty=force
+nl_func_def_empty=remove
 nl_fdef_brace=remove
 mod_full_brace_do=add
 mod_full_brace_for=add
 mod_full_brace_function=add
 mod_full_brace_if=add
 mod_full_brace_while=add
+