Skip to content

Commit

Permalink
refactor(plc4go): added a IsAPlcMessage() bool method to plc_message
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 5, 2022
1 parent 34d70f7 commit 65adaaa
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
15 changes: 8 additions & 7 deletions plc4go/internal/spi/model/DefaultBrowseRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ func (m *DefaultPlcBrowseRequestBuilder) Build() (model.PlcBrowseRequest, error)
}

type DefaultPlcBrowseRequest struct {
DefaultRequest
queries map[string]string
browser spi.PlcBrowser
}

func NewDefaultPlcBrowseResponse(request model.PlcBrowseRequest, results map[string][]model.PlcBrowseQueryResult) DefaultPlcBrowseResponse {
return DefaultPlcBrowseResponse{
request: request,
results: results,
}
}

func (d DefaultPlcBrowseRequest) GetQueryNames() []string {
var queryNames []string
for queryName := range d.queries {
Expand All @@ -79,13 +87,6 @@ type DefaultPlcBrowseResponse struct {
results map[string][]model.PlcBrowseQueryResult
}

func NewDefaultPlcBrowseResponse(request model.PlcBrowseRequest, results map[string][]model.PlcBrowseQueryResult) DefaultPlcBrowseResponse {
return DefaultPlcBrowseResponse{
request: request,
results: results,
}
}

func (d DefaultPlcBrowseResponse) GetRequest() model.PlcBrowseRequest {
return d.request
}
Expand Down
4 changes: 4 additions & 0 deletions plc4go/internal/spi/model/DefaultRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type DefaultRequest struct {
fieldNames []string
}

func (m DefaultRequest) IsAPlcMessage() bool {
return true
}

func NewDefaultRequest(Fields map[string]model.PlcField, FieldNames []string) DefaultRequest {
return DefaultRequest{Fields, FieldNames}
}
Expand Down
4 changes: 4 additions & 0 deletions plc4go/internal/spi/model/DefaultResponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ type DefaultResponse struct {
responseCodes map[string]model.PlcResponseCode
}

func (m DefaultResponse) IsAPlcMessage() bool {
return true
}

func (m DefaultResponse) GetResponseCode(name string) model.PlcResponseCode {
return m.responseCodes[name]
}
Expand Down
1 change: 1 addition & 0 deletions plc4go/pkg/api/model/plc_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
package model

type PlcMessage interface {
IsAPlcMessage() bool
}
3 changes: 3 additions & 0 deletions plc4go/tools/plc4xbrowser/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/rs/zerolog/log"
"net/url"
"strings"
"time"
)

const rootCommandIndicator = "rootCommand"
Expand Down Expand Up @@ -156,7 +157,9 @@ var rootCommand = Command{
AddEventQuery("subscriptionField", split[1]).
AddItemHandler(func(event model.PlcSubscriptionEvent) {
messagesReceived++
start := time.Now()
_, _ = fmt.Fprintf(messageOutput, "[\"%d\"]\n%s[\"\"]", messagesReceived, event)
plc4xBrowserLog.Debug().Msgf("write took %f seconds", time.Now().Sub(start).Seconds())
}).
Build()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions plc4go/tools/plc4xbrowser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type Config struct {
AutoRegisterDrivers []string `yaml:"auto_register_driver"`
LastUpdated time.Time `yaml:"last_updated"`
LogLevel string `yaml:"log_level"`
MaxConsoleLines int `yaml:"max_console_lines"`
MaxOutputLines int `yaml:"max_output_lines"`
}

func init() {
Expand Down
1 change: 1 addition & 0 deletions plc4go/tools/plc4xbrowser/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func buildOutputArea(newPrimitive func(text string) tview.Primitive, application
{
consoleView := tview.NewTextView().
SetDynamicColors(true).
SetMaxLines(config.MaxConsoleLines).
SetChangedFunc(func() {
application.Draw()
})
Expand Down

0 comments on commit 65adaaa

Please sign in to comment.