Skip to content

Commit

Permalink
fix(cbus): fixed power up notification
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jul 29, 2022
1 parent 027ef30 commit 42137e4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 63 deletions.
2 changes: 1 addition & 1 deletion plc4go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
87 changes: 33 additions & 54 deletions plc4go/protocols/cbus/readwrite/model/PowerUp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions plc4go/tools/plc4xbrowser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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() {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,17 @@ void ownSal() throws Exception {

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);
}


}
6 changes: 2 additions & 4 deletions protocols/c-bus/src/main/resources/protocols/cbus/c-bus.mspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 42137e4

Please sign in to comment.