You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/09/05 09:11:42 UTC

[plc4x] 03/03: fix(plc4go/cbus): fix wrongfully reporting of sal to mmi subscribers

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit ff4c27c34749f31484b3f22a2dc54458fb39dc09
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Sep 5 11:07:48 2022 +0200

    fix(plc4go/cbus): fix wrongfully reporting of sal to mmi subscribers
---
 plc4go/internal/cbus/Subscriber.go                 |  2 +-
 .../tests/drivers/tests/manual_cbus_driver_test.go | 53 ++++++++++++++++------
 2 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/plc4go/internal/cbus/Subscriber.go b/plc4go/internal/cbus/Subscriber.go
index d5fd37e90..712ead1bc 100644
--- a/plc4go/internal/cbus/Subscriber.go
+++ b/plc4go/internal/cbus/Subscriber.go
@@ -229,7 +229,7 @@ func (m *Subscriber) handleMonitoredSal(sal readWriteModel.MonitoredSAL) bool {
 	for registration, consumer := range m.consumers {
 		for _, subscriptionHandle := range registration.GetSubscriptionHandles() {
 			subscriptionHandle := subscriptionHandle.(*SubscriptionHandle)
-			field, ok := subscriptionHandle.field.(SALMonitorField)
+			field, ok := subscriptionHandle.field.(*salMonitorField)
 			if !ok {
 				log.Debug().Msgf("Unusable field for mmi subscription %s", field)
 				continue
diff --git a/plc4go/tests/drivers/tests/manual_cbus_driver_test.go b/plc4go/tests/drivers/tests/manual_cbus_driver_test.go
index d7e37ad2d..d0036ab89 100644
--- a/plc4go/tests/drivers/tests/manual_cbus_driver_test.go
+++ b/plc4go/tests/drivers/tests/manual_cbus_driver_test.go
@@ -37,11 +37,11 @@ import (
 	"time"
 )
 
-func TestManualCBusDriver(t *testing.T) {
+func TestManualCBusDriverMixed(t *testing.T) {
 	log.Logger = log.
 		With().Caller().Logger().
 		Output(zerolog.ConsoleWriter{Out: os.Stderr}).
-		Level(zerolog.TraceLevel)
+		Level(zerolog.InfoLevel)
 	config.TraceTransactionManagerWorkers = true
 	config.TraceTransactionManagerTransactions = true
 	config.TraceDefaultMessageCodecWorker = true
@@ -53,21 +53,34 @@ func TestManualCBusDriver(t *testing.T) {
 	transports.RegisterTcpTransport(driverManager)
 	test := testutils.NewManualTestSuite(connectionString, driverManager, t)
 
-	test.AddTestCase("status/binary/0x04", "DOES_NOT_EXIST, OFF, ERROR, ON")
-	test.AddTestCase("status/level=0x40/0x04", 255)
+	// TODO: fix those test cases
+	//test.AddTestCase("status/binary/0x04", "PlcStruct{\n  application: \"LIGHTING_38\"\n  blockStart: \"false, false, false, false, false, false, false, false\"\n  values: \"DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, DOES_NOT_EXIST, OFF, ERROR, ON, [...]
+	//test.AddTestCase("status/level=0x40/0x04", 255)
 	//test.AddTestCase("cal/0/recall=[INTERFACE_OPTIONS_1, 1]", true)
 	//test.AddTestCase("cal/0/identify=[FirmwareVersion]", true)
 	//test.AddTestCase("cal/0/gestatus=[0xFF, 1]", true)
 
 	plcConnection := test.Run()
 	t.Run("Subscription test", func(t *testing.T) {
-		gotMonitor := make(chan bool)
+		gotMMI := make(chan bool)
+		gotSAL := make(chan bool)
 		subscriptionRequest, err := plcConnection.SubscriptionRequestBuilder().
-			AddEventQuery("something", "monitor/*/*").
-			AddPreRegisteredConsumer("something", func(event model.PlcSubscriptionEvent) {
-				fmt.Printf("\n%s", event)
+			AddEventQuery("mmi", "mmimonitor/*/*").
+			AddEventQuery("sal", "salmonitor/*/*").
+			AddPreRegisteredConsumer("mmi", func(event model.PlcSubscriptionEvent) {
+				fmt.Printf("mmi:\n%s", event)
+				if _, ok := event.GetValue("mmi").GetStruct()["SALData"]; ok {
+					panic("got sal in mmi")
+				}
+				select {
+				case gotMMI <- true:
+				default:
+				}
+			}).
+			AddPreRegisteredConsumer("sal", func(event model.PlcSubscriptionEvent) {
+				fmt.Printf("sal:\n%s", event)
 				select {
-				case gotMonitor <- true:
+				case gotSAL <- true:
 				default:
 				}
 			}).
@@ -77,22 +90,32 @@ func TestManualCBusDriver(t *testing.T) {
 		timeout := time.NewTimer(30 * time.Second)
 		defer utils.CleanupTimer(timeout)
 		// We expect couple monitors
-		monitorCount := 0
+		mmiCount := 0
+		salCount := 0
+		gotEnough := func() bool {
+			return mmiCount > 3 && salCount > 3
+		}
 	waitingForMonitors:
 		for {
 			select {
 			case at := <-timeout.C:
 				t.Errorf("timeout at %s", at)
 				break waitingForMonitors
-			case <-gotMonitor:
-				monitorCount++
-				println(monitorCount)
-				if monitorCount > 3 {
+			case <-gotMMI:
+				mmiCount++
+				fmt.Printf("mmi count: %d\n", mmiCount)
+				if gotEnough() {
+					break waitingForMonitors
+				}
+			case <-gotSAL:
+				salCount++
+				fmt.Printf("sal count: %d\n", salCount)
+				if gotEnough() {
 					break waitingForMonitors
 				}
 			}
 		}
-		t.Logf("Got %d monitors", monitorCount)
+		t.Logf("Got %d mmis and %d sal monitors", mmiCount, salCount)
 	})
 }