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/07 12:26:32 UTC

[plc4x] branch develop updated: feat(cbus): report levels as percentage (virtual)

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


The following commit(s) were added to refs/heads/develop by this push:
     new ef888b9a5 feat(cbus): report levels as percentage (virtual)
ef888b9a5 is described below

commit ef888b9a5a71259e7841e17ce445e4828c0914f3
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Sep 7 14:26:24 2022 +0200

    feat(cbus): report levels as percentage (virtual)
---
 .../cbus/readwrite/model/LevelInformationNormal.go      | 17 +++++++++++++++++
 .../c-bus/src/main/resources/protocols/cbus/c-bus.mspec |  3 ++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/plc4go/protocols/cbus/readwrite/model/LevelInformationNormal.go b/plc4go/protocols/cbus/readwrite/model/LevelInformationNormal.go
index c2766050a..ae7b95864 100644
--- a/plc4go/protocols/cbus/readwrite/model/LevelInformationNormal.go
+++ b/plc4go/protocols/cbus/readwrite/model/LevelInformationNormal.go
@@ -37,6 +37,8 @@ type LevelInformationNormal interface {
 	GetPair2() LevelInformationNibblePair
 	// GetActualLevel returns ActualLevel (virtual field)
 	GetActualLevel() uint8
+	// GetActualLevelInPercent returns ActualLevelInPercent (virtual field)
+	GetActualLevelInPercent() float32
 }
 
 // LevelInformationNormalExactly can be used when we want exactly this type and not a type which fulfills LevelInformationNormal.
@@ -97,6 +99,10 @@ func (m *_LevelInformationNormal) GetActualLevel() uint8 {
 	return uint8(m.GetPair2().NibbleValue()<<uint8(4) | m.GetPair1().NibbleValue())
 }
 
+func (m *_LevelInformationNormal) GetActualLevelInPercent() float32 {
+	return float32(float32(float32(float32(100))*float32((float32(m.GetActualLevel())+float32(float32(2))))) / float32(float32(255)))
+}
+
 ///////////////////////
 ///////////////////////
 ///////////////////////////////////////////////////////////
@@ -143,6 +149,8 @@ func (m *_LevelInformationNormal) GetLengthInBitsConditional(lastItem bool) uint
 
 	// A virtual field doesn't have any in- or output.
 
+	// A virtual field doesn't have any in- or output.
+
 	return lengthInBits
 }
 
@@ -190,6 +198,11 @@ func LevelInformationNormalParse(readBuffer utils.ReadBuffer) (LevelInformationN
 	actualLevel := uint8(_actualLevel)
 	_ = actualLevel
 
+	// Virtual field
+	_actualLevelInPercent := float32(float32(float32(100))*float32((float32(actualLevel)+float32(float32(2))))) / float32(float32(255))
+	actualLevelInPercent := float32(_actualLevelInPercent)
+	_ = actualLevelInPercent
+
 	if closeErr := readBuffer.CloseContext("LevelInformationNormal"); closeErr != nil {
 		return nil, errors.Wrap(closeErr, "Error closing for LevelInformationNormal")
 	}
@@ -239,6 +252,10 @@ func (m *_LevelInformationNormal) Serialize(writeBuffer utils.WriteBuffer) error
 		if _actualLevelErr := writeBuffer.WriteVirtual("actualLevel", m.GetActualLevel()); _actualLevelErr != nil {
 			return errors.Wrap(_actualLevelErr, "Error serializing 'actualLevel' field")
 		}
+		// Virtual field
+		if _actualLevelInPercentErr := writeBuffer.WriteVirtual("actualLevelInPercent", m.GetActualLevelInPercent()); _actualLevelInPercentErr != nil {
+			return errors.Wrap(_actualLevelInPercentErr, "Error serializing 'actualLevelInPercent' field")
+		}
 
 		if popErr := writeBuffer.PopContext("LevelInformationNormal"); popErr != nil {
 			return errors.Wrap(popErr, "Error popping for LevelInformationNormal")
diff --git a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
index 703b200bf..c3418448a 100644
--- a/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
+++ b/protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
@@ -1619,7 +1619,8 @@
         [*          *Normal
             [simple  LevelInformationNibblePair  pair1                      ]
             [simple  LevelInformationNibblePair  pair2                      ]
-            [virtual uint 8  actualLevel 'pair2.nibbleValue << 4 | pair1.nibbleValue']
+            [virtual uint   8  actualLevel 'pair2.nibbleValue << 4 | pair1.nibbleValue']
+            [virtual float 32  actualLevelInPercent '100 * (actualLevel + 2) / 255 )'  ]
         ]
     ]
 ]