Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/board/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ type Board interface {
// SetPowerMode sets the board to the given power mode. If
// provided, the board will exit the given power mode after
// the specified duration.
SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration) error
SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration, extra map[string]interface{}) error

// StreamTicks starts a stream of digital interrupt ticks.
StreamTicks(ctx context.Context, interrupts []DigitalInterrupt, ch chan Tick,
Expand Down
8 changes: 6 additions & 2 deletions components/board/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ func (c *client) GPIOPinByName(name string) (GPIOPin, error) {
}, nil
}

func (c *client) SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration) error {
func (c *client) SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration, extra map[string]interface{}) error {
ext, err := protoutils.StructToStructPb(extra)
if err != nil {
return err
}
var dur *durationpb.Duration
if duration != nil {
dur = durationpb.New(*duration)
}
_, err := c.client.SetPowerMode(ctx, &pb.SetPowerModeRequest{Name: c.boardName, PowerMode: mode, Duration: dur})
_, err = c.client.SetPowerMode(ctx, &pb.SetPowerModeRequest{Name: c.boardName, PowerMode: mode, Duration: dur, Extra: ext})
return err
}

Expand Down
8 changes: 6 additions & 2 deletions components/board/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,15 @@ func TestWorkingClient(t *testing.T) {
test.That(t, name, test.ShouldEqual, "digital1")

// SetPowerMode (currently unimplemented in RDK)
injectBoard.SetPowerModeFunc = func(ctx context.Context, mode boardpb.PowerMode, duration *time.Duration) error {
injectBoard.SetPowerModeFunc = func(ctx context.Context, mode boardpb.PowerMode, duration *time.Duration,
extra map[string]interface{},
) error {
actualExtra = extra
return viamgrpc.UnimplementedError
}
err = client.SetPowerMode(context.Background(), boardpb.PowerMode_POWER_MODE_OFFLINE_DEEP, nil)
err = client.SetPowerMode(context.Background(), boardpb.PowerMode_POWER_MODE_OFFLINE_DEEP, nil, expectedExtra)
test.That(t, err, test.ShouldNotBeNil)
test.That(t, actualExtra, test.ShouldResemble, expectedExtra)
test.That(t, err, test.ShouldHaveSameTypeAs, viamgrpc.UnimplementedError)

test.That(t, client.Close(context.Background()), test.ShouldBeNil)
Expand Down
2 changes: 1 addition & 1 deletion components/board/fake/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (b *Board) GPIOPinByName(name string) (board.GPIOPin, error) {
// SetPowerMode sets the board to the given power mode. If provided,
// the board will exit the given power mode after the specified
// duration.
func (b *Board) SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration) error {
func (b *Board) SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration, extra map[string]interface{}) error {
return grpc.UnimplementedError
}

Expand Down
1 change: 1 addition & 0 deletions components/board/genericlinux/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func (b *Board) SetPowerMode(
ctx context.Context,
mode pb.PowerMode,
duration *time.Duration,
extra map[string]interface{},
) error {
return grpc.UnimplementedError
}
Expand Down
4 changes: 2 additions & 2 deletions components/board/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ func (s *serviceServer) SetPowerMode(ctx context.Context,
}

if req.Duration == nil {
err = b.SetPowerMode(ctx, req.PowerMode, nil)
err = b.SetPowerMode(ctx, req.PowerMode, nil, req.Extra.AsMap())
} else {
if err := req.Duration.CheckValid(); err != nil {
return nil, err
}
duration := req.Duration.AsDuration()
err = b.SetPowerMode(ctx, req.PowerMode, &duration)
err = b.SetPowerMode(ctx, req.PowerMode, &duration, req.Extra.AsMap())
}

if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions testutils/inject/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Board struct {
GPIOPinByNameFunc func(name string) (board.GPIOPin, error)
gpioPinByNameCap []interface{}
CloseFunc func(ctx context.Context) error
SetPowerModeFunc func(ctx context.Context, mode boardpb.PowerMode, duration *time.Duration) error
SetPowerModeFunc func(ctx context.Context, mode boardpb.PowerMode, duration *time.Duration, extra map[string]interface{}) error
StreamTicksFunc func(ctx context.Context,
interrupts []board.DigitalInterrupt, ch chan board.Tick, extra map[string]interface{}) error
}
Expand Down Expand Up @@ -113,11 +113,11 @@ func (b *Board) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[
// SetPowerMode sets the board to the given power mode. If
// provided, the board will exit the given power mode after
// the specified duration.
func (b *Board) SetPowerMode(ctx context.Context, mode boardpb.PowerMode, duration *time.Duration) error {
func (b *Board) SetPowerMode(ctx context.Context, mode boardpb.PowerMode, duration *time.Duration, extra map[string]interface{}) error {
if b.SetPowerModeFunc == nil {
return b.Board.SetPowerMode(ctx, mode, duration)
return b.Board.SetPowerMode(ctx, mode, duration, extra)
}
return b.SetPowerModeFunc(ctx, mode, duration)
return b.SetPowerModeFunc(ctx, mode, duration, extra)
}

// StreamTicks calls the injected StreamTicks or the real version.
Expand Down
Loading