wip
This commit is contained in:
@ -41,6 +41,7 @@ func OnMessage[T any](ctx context.Context, client *Client, mType string) (chan T
|
||||
type Broadcast struct {
|
||||
Name string `mapstructure:"name" json:"name"`
|
||||
Payload any `mapstructure:"payload" json:"payload"`
|
||||
State string `mapstructure:"state" json:"state"`
|
||||
}
|
||||
|
||||
// OnBroadcast listens for ReachView "broadcast" messages
|
||||
@ -52,3 +53,13 @@ func OnBroadcast(ctx context.Context, client *Client) (chan Broadcast, error) {
|
||||
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
// OnMessageType listens for ReachView type of messages
|
||||
func OnMessageType(ctx context.Context, client *Client, messageType string) (chan Broadcast, error) {
|
||||
ch, err := OnMessage[Broadcast](ctx, client, messageType)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return ch, nil
|
||||
}
|
||||
|
@ -152,4 +152,18 @@ func (c *Client) Reboot(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AveragePosition implements protocol.Operations.
|
||||
func (c *Client) AveragePosition(ctx context.Context) error {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := ops.AveragePosition(ctx); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Client{}
|
||||
|
@ -41,4 +41,6 @@ type Operations interface {
|
||||
|
||||
// Reboot restarts the module
|
||||
Reboot(ctx context.Context) error
|
||||
|
||||
AveragePosition(ctx context.Context) error
|
||||
}
|
||||
|
@ -363,4 +363,19 @@ func (o *Operations) Version(ctx context.Context) (string, bool, error) {
|
||||
return strings.TrimSpace(res.Version), res.Stable, nil
|
||||
}
|
||||
|
||||
func (o *Operations) AveragePosition(ctx context.Context) error {
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
err = ctx.Err()
|
||||
}()
|
||||
|
||||
if err = o.client.Emit("task", map[string]string{"name": "average_base_coordinates"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Operations{}
|
||||
|
@ -264,4 +264,19 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (o *Operations) AveragePosition(ctx context.Context) error {
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
err = ctx.Err()
|
||||
}()
|
||||
|
||||
if err = o.client.Emit("task", &model.Action{Name: "average_base_coordinates"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Operations{}
|
||||
|
Reference in New Issue
Block a user