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/07/29 16:11:49 UTC
[plc4x] branch develop updated: fix(cbus): fixed power up notification
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 42137e444 fix(cbus): fixed power up notification
42137e444 is described below
commit 42137e444d8cb69f5734c0bca154869feb7947e9
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Jul 29 18:11:42 2022 +0200
fix(cbus): fixed power up notification
---
plc4go/go.mod | 2 +-
plc4go/protocols/cbus/readwrite/model/PowerUp.go | 87 ++++++++--------------
plc4go/tools/plc4xbrowser/main.go | 14 +++-
.../apache/plc4x/java/cbus/RandomPackagesTest.java | 13 ++++
.../src/main/resources/protocols/cbus/c-bus.mspec | 6 +-
5 files changed, 59 insertions(+), 63 deletions(-)
diff --git a/plc4go/go.mod b/plc4go/go.mod
index e9399fef8..acc8c15ad 100644
--- a/plc4go/go.mod
+++ b/plc4go/go.mod
@@ -25,6 +25,7 @@ require (
github.com/IBM/netaddr v1.5.0
github.com/ajankovic/xdiff v0.0.1
github.com/fatih/color v1.13.0
+ github.com/gdamore/tcell/v2 v2.5.1
github.com/google/gopacket v1.1.19
github.com/icza/bitio v1.1.0
github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4
@@ -47,7 +48,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
- github.com/gdamore/tcell/v2 v2.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
diff --git a/plc4go/protocols/cbus/readwrite/model/PowerUp.go b/plc4go/protocols/cbus/readwrite/model/PowerUp.go
index aa7651414..13c6509dd 100644
--- a/plc4go/protocols/cbus/readwrite/model/PowerUp.go
+++ b/plc4go/protocols/cbus/readwrite/model/PowerUp.go
@@ -28,14 +28,13 @@ import (
// Code generated by code-generation. DO NOT EDIT.
// Constant values.
-const PowerUp_POWERUPINDICATOR byte = 0x2B
+const PowerUp_POWERUPINDICATOR1 byte = 0x2B
+const PowerUp_POWERUPINDICATOR2 byte = 0x2B
// PowerUp is the corresponding interface of PowerUp
type PowerUp interface {
utils.LengthAware
utils.Serializable
- // GetReqTermination returns ReqTermination (property field)
- GetReqTermination() RequestTermination
}
// PowerUpExactly can be used when we want exactly this type and not a type which fulfills PowerUp.
@@ -47,29 +46,19 @@ type PowerUpExactly interface {
// _PowerUp is the data-structure of this message
type _PowerUp struct {
- ReqTermination RequestTermination
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
-/////////////////////// Accessors for property fields.
+/////////////////////// Accessors for const fields.
///////////////////////
-func (m *_PowerUp) GetReqTermination() RequestTermination {
- return m.ReqTermination
+func (m *_PowerUp) GetPowerUpIndicator1() byte {
+ return PowerUp_POWERUPINDICATOR1
}
-///////////////////////
-///////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////
-/////////////////////// Accessors for const fields.
-///////////////////////
-
-func (m *_PowerUp) GetPowerUpIndicator() byte {
- return PowerUp_POWERUPINDICATOR
+func (m *_PowerUp) GetPowerUpIndicator2() byte {
+ return PowerUp_POWERUPINDICATOR2
}
///////////////////////
@@ -78,8 +67,8 @@ func (m *_PowerUp) GetPowerUpIndicator() byte {
///////////////////////////////////////////////////////////
// NewPowerUp factory function for _PowerUp
-func NewPowerUp(reqTermination RequestTermination) *_PowerUp {
- return &_PowerUp{ReqTermination: reqTermination}
+func NewPowerUp() *_PowerUp {
+ return &_PowerUp{}
}
// Deprecated: use the interface for direct cast
@@ -104,11 +93,11 @@ func (m *_PowerUp) GetLengthInBits() uint16 {
func (m *_PowerUp) GetLengthInBitsConditional(lastItem bool) uint16 {
lengthInBits := uint16(0)
- // Const Field (powerUpIndicator)
+ // Const Field (powerUpIndicator1)
lengthInBits += 8
- // Simple field (reqTermination)
- lengthInBits += m.ReqTermination.GetLengthInBits()
+ // Const Field (powerUpIndicator2)
+ lengthInBits += 8
return lengthInBits
}
@@ -126,26 +115,22 @@ func PowerUpParse(readBuffer utils.ReadBuffer) (PowerUp, error) {
currentPos := positionAware.GetPos()
_ = currentPos
- // Const Field (powerUpIndicator)
- powerUpIndicator, _powerUpIndicatorErr := readBuffer.ReadByte("powerUpIndicator")
- if _powerUpIndicatorErr != nil {
- return nil, errors.Wrap(_powerUpIndicatorErr, "Error parsing 'powerUpIndicator' field of PowerUp")
+ // Const Field (powerUpIndicator1)
+ powerUpIndicator1, _powerUpIndicator1Err := readBuffer.ReadByte("powerUpIndicator1")
+ if _powerUpIndicator1Err != nil {
+ return nil, errors.Wrap(_powerUpIndicator1Err, "Error parsing 'powerUpIndicator1' field of PowerUp")
}
- if powerUpIndicator != PowerUp_POWERUPINDICATOR {
- return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", PowerUp_POWERUPINDICATOR) + " but got " + fmt.Sprintf("%d", powerUpIndicator))
+ if powerUpIndicator1 != PowerUp_POWERUPINDICATOR1 {
+ return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", PowerUp_POWERUPINDICATOR1) + " but got " + fmt.Sprintf("%d", powerUpIndicator1))
}
- // Simple Field (reqTermination)
- if pullErr := readBuffer.PullContext("reqTermination"); pullErr != nil {
- return nil, errors.Wrap(pullErr, "Error pulling for reqTermination")
+ // Const Field (powerUpIndicator2)
+ powerUpIndicator2, _powerUpIndicator2Err := readBuffer.ReadByte("powerUpIndicator2")
+ if _powerUpIndicator2Err != nil {
+ return nil, errors.Wrap(_powerUpIndicator2Err, "Error parsing 'powerUpIndicator2' field of PowerUp")
}
- _reqTermination, _reqTerminationErr := RequestTerminationParse(readBuffer)
- if _reqTerminationErr != nil {
- return nil, errors.Wrap(_reqTerminationErr, "Error parsing 'reqTermination' field of PowerUp")
- }
- reqTermination := _reqTermination.(RequestTermination)
- if closeErr := readBuffer.CloseContext("reqTermination"); closeErr != nil {
- return nil, errors.Wrap(closeErr, "Error closing for reqTermination")
+ if powerUpIndicator2 != PowerUp_POWERUPINDICATOR2 {
+ return nil, errors.New("Expected constant value " + fmt.Sprintf("%d", PowerUp_POWERUPINDICATOR2) + " but got " + fmt.Sprintf("%d", powerUpIndicator2))
}
if closeErr := readBuffer.CloseContext("PowerUp"); closeErr != nil {
@@ -153,7 +138,7 @@ func PowerUpParse(readBuffer utils.ReadBuffer) (PowerUp, error) {
}
// Create the instance
- return NewPowerUp(reqTermination), nil
+ return NewPowerUp(), nil
}
func (m *_PowerUp) Serialize(writeBuffer utils.WriteBuffer) error {
@@ -163,22 +148,16 @@ func (m *_PowerUp) Serialize(writeBuffer utils.WriteBuffer) error {
return errors.Wrap(pushErr, "Error pushing for PowerUp")
}
- // Const Field (powerUpIndicator)
- _powerUpIndicatorErr := writeBuffer.WriteByte("powerUpIndicator", 0x2B)
- if _powerUpIndicatorErr != nil {
- return errors.Wrap(_powerUpIndicatorErr, "Error serializing 'powerUpIndicator' field")
+ // Const Field (powerUpIndicator1)
+ _powerUpIndicator1Err := writeBuffer.WriteByte("powerUpIndicator1", 0x2B)
+ if _powerUpIndicator1Err != nil {
+ return errors.Wrap(_powerUpIndicator1Err, "Error serializing 'powerUpIndicator1' field")
}
- // Simple Field (reqTermination)
- if pushErr := writeBuffer.PushContext("reqTermination"); pushErr != nil {
- return errors.Wrap(pushErr, "Error pushing for reqTermination")
- }
- _reqTerminationErr := writeBuffer.WriteSerializable(m.GetReqTermination())
- if popErr := writeBuffer.PopContext("reqTermination"); popErr != nil {
- return errors.Wrap(popErr, "Error popping for reqTermination")
- }
- if _reqTerminationErr != nil {
- return errors.Wrap(_reqTerminationErr, "Error serializing 'reqTermination' field")
+ // Const Field (powerUpIndicator2)
+ _powerUpIndicator2Err := writeBuffer.WriteByte("powerUpIndicator2", 0x2B)
+ if _powerUpIndicator2Err != nil {
+ return errors.Wrap(_powerUpIndicator2Err, "Error serializing 'powerUpIndicator2' field")
}
if popErr := writeBuffer.PopContext("PowerUp"); popErr != nil {
diff --git a/plc4go/tools/plc4xbrowser/main.go b/plc4go/tools/plc4xbrowser/main.go
index d138cf2ec..5afbebb43 100644
--- a/plc4go/tools/plc4xbrowser/main.go
+++ b/plc4go/tools/plc4xbrowser/main.go
@@ -39,7 +39,7 @@ import (
)
// TODO: replace with real commands
-const plc4xCommands = "connect,disconnect,read,write,register,subscribe"
+const plc4xCommands = "connect,disconnect,read,write,register,subscribe,quit"
var connections map[string]plc4go.PlcConnection
var connectionsChanged func()
@@ -137,6 +137,11 @@ func buildCommandArea(newPrimitive func(text string) tview.Primitive, applicatio
commandInputField.
SetDoneFunc(func(key tcell.Key) {
commandText := commandInputField.GetText()
+ if commandText == "quit" {
+ // TODO: maybe add a modal here
+ application.Stop()
+ return
+ }
commandsExecuted++
_, _ = fmt.Fprintf(enteredCommands, "%s [\"%d\"]%s[\"\"]\n", time.Now().Format("04:05"), commandsExecuted, commandText)
go func() {
@@ -159,14 +164,15 @@ func buildCommandArea(newPrimitive func(text string) tview.Primitive, applicatio
}
}
switch {
+ case strings.HasPrefix(currentText, "disconnect"):
+ for connectionsString, _ := range connections {
+ entries = append(entries, "disconnect "+connectionsString)
+ }
case strings.HasPrefix(currentText, "subscribe"):
for connectionsString, _ := range connections {
entries = append(entries, "subscribe "+connectionsString)
}
}
- if len(entries) <= 1 {
- entries = nil
- }
return
})
commandArea.AddItem(commandInputField, 2, 0, 1, 1, 0, 0, true)
diff --git a/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java b/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java
index a16d0d962..b5e49b83d 100644
--- a/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java
+++ b/plc4j/drivers/c-bus/src/test/java/org/apache/plc4x/java/cbus/RandomPackagesTest.java
@@ -417,4 +417,17 @@ public class RandomPackagesTest {
assertMessageMatches(bytes, msg);
}
+
+ @Test
+ void powerUpNotification() throws Exception {
+ byte[] bytes = "++\r\n".getBytes(StandardCharsets.UTF_8);
+ ReadBufferByteBased readBufferByteBased = new ReadBufferByteBased(bytes);
+ CBusMessage msg = CBusMessage.staticParse(readBufferByteBased, true, requestContext, cBusOptions);
+ assertThat(msg).isNotNull();
+ System.out.println(msg);
+
+ assertMessageMatches(bytes, msg);
+ }
+
+
}
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 a5eee0a22..899999a4b 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
@@ -1478,10 +1478,8 @@
]
[type PowerUp
- [const byte powerUpIndicator 0x2B ] // "+"
- // TODO: do we really need a static helper to peek for terminated?=
- //[array uint 8 garbage terminated '0x0D' ] // read all following +
- [simple RequestTermination reqTermination ] // TODO: maybe should be externalized
+ [const byte powerUpIndicator1 0x2B ] // "+"
+ [const byte powerUpIndicator2 0x2B ] // "+"
]
[type ParameterChange