Explorar o código

Updates extended status for run/idle connections, as required by the PlugFest tests

Signed-off-by: Martin Melik-Merkumians <melik-merkumians@acin.tuwien.ac.at>
Martin Melik-Merkumians %!s(int64=7) %!d(string=hai) anos
pai
achega
f15414b6f3

+ 3 - 1
source/src/cip/cipidentity.c

@@ -34,6 +34,7 @@
 #include "ciperror.h"
 #include "endianconv.h"
 #include "opener_api.h"
+#include "trace.h"
 
 /* attributes in CIP Identity Object */
 
@@ -182,6 +183,7 @@ EipStatus CipIdentityInit() {
 }
 
 CipIdentitySetExtendedDeviceStatus(CipIdentityExtendedStatus extended_status) {
+  OPENER_TRACE_INFO("Setting extended status: %x", extended_status);
   status_ &= ~(0x70);
-  status_ &= extended_status;
+  status_ |= extended_status;
 }

+ 1 - 1
source/src/cip/cipidentity.h

@@ -37,7 +37,7 @@ typedef enum {
   kNoIoConnectionsEstablished = 0x0030,
   kNonVolatileConfigurationBad = 0x0040,
   kMajorFault = 0x0050,
-  kAtLeastOneIoConnectionInRuneMode = 0x0060,
+  kAtLeastOneIoConnectionInRunMode = 0x0060,
   kAtLeastOneIoConnectionEstablishedAllInIdleMode = 0x0070
 } CipIdentityExtendedStatus;
 

+ 15 - 1
source/src/cip/cipioconnection.c

@@ -12,6 +12,7 @@
 #include "generic_networkhandler.h"
 #include "cipconnectionmanager.h"
 #include "cipassembly.h"
+#include "cipidentity.h"
 #include "ciptcpipinterface.h"
 #include "cipcommon.h"
 #include "appcontype.h"
@@ -869,6 +870,8 @@ EipStatus HandleReceivedIoConnectionData(
   EipUint16 data_length
   ) {
 
+  OPENER_TRACE_INFO("Starting data length: %d\n", data_length);
+  bool no_new_data = false;
   /* check class 1 sequence number*/
   if (kConnectionObjectTransportClassTriggerTransportClass1 ==
       ConnectionObjectGetTransportClassTriggerTransportClass(connection_object) )
@@ -876,22 +879,33 @@ EipStatus HandleReceivedIoConnectionData(
     EipUint16 sequence_buffer = GetIntFromMessage( &(data) );
     if ( SEQ_LEQ16(sequence_buffer,
                    connection_object->sequence_count_consuming) ) {
-      return kEipStatusOk; /* no new data for the assembly */
+      no_new_data = true;
     }
     connection_object->sequence_count_consuming = sequence_buffer;
     data_length -= 2;
   }
 
+  OPENER_TRACE_INFO("data length after sequence count: %d\n", data_length);
   if (data_length > 0) {
     /* we have no heartbeat connection */
 #ifdef OPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER
     EipUint32 nRunIdleBuf = GetDintFromMessage( &(data) );
+    OPENER_TRACE_INFO("Run/Idle handler: 0x%x", nRunIdleBuf);
+    const uint32_t kRunBitMask = 0x0001;
+    if((kRunBitMask & nRunIdleBuf) == 1) {
+      CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionInRunMode);
+    } else {
+      CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionEstablishedAllInIdleMode);
+    }
     if (g_run_idle_state != nRunIdleBuf) {
       RunIdleChanged(nRunIdleBuf);
     }
     g_run_idle_state = nRunIdleBuf;
     data_length -= 4;
 #endif /* OPENER_CONSUMED_DATA_HAS_RUN_IDLE_HEADER */
+    if(no_new_data) {
+      return kEipStatusOk;
+    }
 
     if (NotifyAssemblyConnectedDataReceived(
           connection_object->consuming_instance, (EipUint8 *const)data,

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

@@ -154,7 +154,7 @@ void CipFree(void *data) {
 void RunIdleChanged(EipUint32 run_idle_value) {
   OPENER_TRACE_INFO("Run/Idle handler triggered\n");
   if((0x0001 & run_idle_value) == 1) {
-    CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionInRuneMode);
+    CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionInRunMode);
   } else {
     CipIdentitySetExtendedDeviceStatus(kAtLeastOneIoConnectionEstablishedAllInIdleMode);
   }