Skip to content

Commit

Permalink
Improve controlbox cmd
Browse files Browse the repository at this point in the history
Add handling for reacting to the write limit response
  • Loading branch information
DerAndereAndi committed May 29, 2024
1 parent 7544961 commit 82ae1e0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmd/controlbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features/client"
"github.com/enbility/eebus-go/service"
ucapi "github.com/enbility/eebus-go/usecases/api"
"github.com/enbility/eebus-go/usecases/eg/lpc"
Expand Down Expand Up @@ -129,6 +130,26 @@ func (h *controlbox) RemoteSKIConnected(service api.ServiceInterface, ski string
continue
}

// add a callback to the result
if lc, err := client.NewLoadControl(h.uclpc.LocalEntity, entity); err == nil {
err := lc.AddResponseCallback(*msgCounter, func(msg spineapi.ResponseMessage) {
// the response has to be of model.ResultDataType
response, ok := msg.Data.(*model.ResultDataType)
if !ok || response.ErrorNumber == nil {
return
}

if *response.ErrorNumber == model.ErrorNumberTypeNoError {
fmt.Println("Limit accepted.")
} else {
fmt.Println("Limit rejected. Code", response.ErrorNumber, "Description", response.Description)
}
})
if err != nil {
fmt.Println("Failed to add callback", err)
}
}

fmt.Println("Sent limit to", ski, "with msgCounter", msgCounter)
}
})
Expand Down

0 comments on commit 82ae1e0

Please sign in to comment.