forked from viamrobotics/viam-flutter-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.dart
66 lines (55 loc) · 1.8 KB
/
client.dart
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
import 'package:grpc/grpc_connection_interface.dart';
import '../../gen/common/v1/common.pb.dart';
import '../../gen/component/servo/v1/servo.pbgrpc.dart';
import '../../gen/google/protobuf/struct.pb.dart';
import '../../resource/base.dart';
import '../../utils.dart';
import 'servo.dart';
/// {@category Viam SDK}
/// gRPC client for the [Servo] component.
class ServoClient extends Servo implements ResourceRPCClient {
@override
final String name;
@override
ClientChannelBase channel;
@override
ServoServiceClient get client => ServoServiceClient(channel);
ServoClient(this.name, this.channel);
@override
Future<void> move(int angle, {Map<String, dynamic>? extra}) async {
final request = MoveRequest()
..name = name
..angleDeg = angle
..extra = extra?.toStruct() ?? Struct();
await client.move(request);
}
@override
Future<int> position({Map<String, dynamic>? extra}) async {
final request = GetPositionRequest()
..name = name
..extra = extra?.toStruct() ?? Struct();
final response = await client.getPosition(request);
return response.positionDeg;
}
@override
Future<void> stop({Map<String, dynamic>? extra}) async {
final request = StopRequest()
..name = name
..extra = extra?.toStruct() ?? Struct();
await client.stop(request);
}
@override
Future<bool> isMoving({Map<String, dynamic>? extra}) async {
final request = IsMovingRequest()..name = name;
final response = await client.isMoving(request);
return response.isMoving;
}
@override
Future<Map<String, dynamic>> doCommand(Map<String, dynamic> command) async {
final request = DoCommandRequest()
..name = name
..command = command.toStruct();
final response = await client.doCommand(request);
return response.result.toMap();
}
}