-
Notifications
You must be signed in to change notification settings - Fork 110
/
client.go
72 lines (64 loc) · 1.74 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package posetracker
import (
"context"
pb "go.viam.com/api/component/posetracker/v1"
"go.viam.com/utils/protoutils"
"go.viam.com/utils/rpc"
"go.viam.com/rdk/logging"
rprotoutils "go.viam.com/rdk/protoutils"
"go.viam.com/rdk/referenceframe"
"go.viam.com/rdk/resource"
)
// client implements PoseTrackerServiceClient.
type client struct {
resource.Named
resource.TriviallyReconfigurable
resource.TriviallyCloseable
name string
client pb.PoseTrackerServiceClient
logger logging.Logger
}
// NewClientFromConn constructs a new Client from connection passed in.
func NewClientFromConn(
ctx context.Context,
conn rpc.ClientConn,
remoteName string,
name resource.Name,
logger logging.Logger,
) (PoseTracker, error) {
c := pb.NewPoseTrackerServiceClient(conn)
return &client{
Named: name.PrependRemote(remoteName).AsNamed(),
name: name.ShortName(),
client: c,
logger: logger,
}, nil
}
func (c *client) Poses(
ctx context.Context, bodyNames []string, extra map[string]interface{},
) (BodyToPoseInFrame, error) {
ext, err := protoutils.StructToStructPb(extra)
if err != nil {
return nil, err
}
req := &pb.GetPosesRequest{
Name: c.name,
BodyNames: bodyNames,
Extra: ext,
}
resp, err := c.client.GetPoses(ctx, req)
if err != nil {
return nil, err
}
result := BodyToPoseInFrame{}
for key, pf := range resp.GetBodyPoses() {
result[key] = referenceframe.ProtobufToPoseInFrame(pf)
}
return result, nil
}
func (c *client) Readings(ctx context.Context, extra map[string]interface{}) (map[string]interface{}, error) {
return Readings(ctx, c)
}
func (c *client) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
return rprotoutils.DoFromResourceClient(ctx, c.client, c.name, cmd)
}