1
+ # -*- coding: utf-8 -*-
2
+ # DO NOT EDIT! This file is auto-generated from
3
+ # https://github.com/mavlink/MAVSDK-Python/tree/main/other/templates/py
4
+ from ._base import AsyncBase
5
+ from . import arm_authorizer_server_pb2 , arm_authorizer_server_pb2_grpc
6
+ from enum import Enum
7
+
8
+
9
+ class RejectionReason (Enum ):
10
+ """
11
+
12
+
13
+ Values
14
+ ------
15
+ GENERIC
16
+ Not a specific reason
17
+
18
+ NONE
19
+ Authorizer will send the error as string to GCS
20
+
21
+ INVALID_WAYPOINT
22
+ At least one waypoint have a invalid value
23
+
24
+ TIMEOUT
25
+ Timeout in the authorizer process(in case it depends on network)
26
+
27
+ AIRSPACE_IN_USE
28
+ Airspace of the mission in use by another vehicle, second result parameter can have the waypoint id that caused it to be denied.
29
+
30
+ BAD_WEATHER
31
+ Weather is not good to fly
32
+
33
+ """
34
+
35
+
36
+ GENERIC = 0
37
+ NONE = 1
38
+ INVALID_WAYPOINT = 2
39
+ TIMEOUT = 3
40
+ AIRSPACE_IN_USE = 4
41
+ BAD_WEATHER = 5
42
+
43
+ def translate_to_rpc (self ):
44
+ if self == RejectionReason .GENERIC :
45
+ return arm_authorizer_server_pb2 .REJECTION_REASON_GENERIC
46
+ if self == RejectionReason .NONE :
47
+ return arm_authorizer_server_pb2 .REJECTION_REASON_NONE
48
+ if self == RejectionReason .INVALID_WAYPOINT :
49
+ return arm_authorizer_server_pb2 .REJECTION_REASON_INVALID_WAYPOINT
50
+ if self == RejectionReason .TIMEOUT :
51
+ return arm_authorizer_server_pb2 .REJECTION_REASON_TIMEOUT
52
+ if self == RejectionReason .AIRSPACE_IN_USE :
53
+ return arm_authorizer_server_pb2 .REJECTION_REASON_AIRSPACE_IN_USE
54
+ if self == RejectionReason .BAD_WEATHER :
55
+ return arm_authorizer_server_pb2 .REJECTION_REASON_BAD_WEATHER
56
+
57
+ @staticmethod
58
+ def translate_from_rpc (rpc_enum_value ):
59
+ """ Parses a gRPC response """
60
+ if rpc_enum_value == arm_authorizer_server_pb2 .REJECTION_REASON_GENERIC :
61
+ return RejectionReason .GENERIC
62
+ if rpc_enum_value == arm_authorizer_server_pb2 .REJECTION_REASON_NONE :
63
+ return RejectionReason .NONE
64
+ if rpc_enum_value == arm_authorizer_server_pb2 .REJECTION_REASON_INVALID_WAYPOINT :
65
+ return RejectionReason .INVALID_WAYPOINT
66
+ if rpc_enum_value == arm_authorizer_server_pb2 .REJECTION_REASON_TIMEOUT :
67
+ return RejectionReason .TIMEOUT
68
+ if rpc_enum_value == arm_authorizer_server_pb2 .REJECTION_REASON_AIRSPACE_IN_USE :
69
+ return RejectionReason .AIRSPACE_IN_USE
70
+ if rpc_enum_value == arm_authorizer_server_pb2 .REJECTION_REASON_BAD_WEATHER :
71
+ return RejectionReason .BAD_WEATHER
72
+
73
+ def __str__ (self ):
74
+ return self .name
75
+
76
+
77
+ class ArmAuthorizerServerResult :
78
+ """
79
+
80
+
81
+ Parameters
82
+ ----------
83
+ result : Result
84
+ Result enum value
85
+
86
+ result_str : std::string
87
+ Human-readable English string describing the result
88
+
89
+ """
90
+
91
+
92
+
93
+ class Result (Enum ):
94
+ """
95
+
96
+
97
+ Values
98
+ ------
99
+ UNKNOWN
100
+ Unknown result
101
+
102
+ SUCCESS
103
+ Command accepted
104
+
105
+ FAILED
106
+ Command failed
107
+
108
+ """
109
+
110
+
111
+ UNKNOWN = 0
112
+ SUCCESS = 1
113
+ FAILED = 2
114
+
115
+ def translate_to_rpc (self ):
116
+ if self == ArmAuthorizerServerResult .Result .UNKNOWN :
117
+ return arm_authorizer_server_pb2 .ArmAuthorizerServerResult .RESULT_UNKNOWN
118
+ if self == ArmAuthorizerServerResult .Result .SUCCESS :
119
+ return arm_authorizer_server_pb2 .ArmAuthorizerServerResult .RESULT_SUCCESS
120
+ if self == ArmAuthorizerServerResult .Result .FAILED :
121
+ return arm_authorizer_server_pb2 .ArmAuthorizerServerResult .RESULT_FAILED
122
+
123
+ @staticmethod
124
+ def translate_from_rpc (rpc_enum_value ):
125
+ """ Parses a gRPC response """
126
+ if rpc_enum_value == arm_authorizer_server_pb2 .ArmAuthorizerServerResult .RESULT_UNKNOWN :
127
+ return ArmAuthorizerServerResult .Result .UNKNOWN
128
+ if rpc_enum_value == arm_authorizer_server_pb2 .ArmAuthorizerServerResult .RESULT_SUCCESS :
129
+ return ArmAuthorizerServerResult .Result .SUCCESS
130
+ if rpc_enum_value == arm_authorizer_server_pb2 .ArmAuthorizerServerResult .RESULT_FAILED :
131
+ return ArmAuthorizerServerResult .Result .FAILED
132
+
133
+ def __str__ (self ):
134
+ return self .name
135
+
136
+
137
+ def __init__ (
138
+ self ,
139
+ result ,
140
+ result_str ):
141
+ """ Initializes the ArmAuthorizerServerResult object """
142
+ self .result = result
143
+ self .result_str = result_str
144
+
145
+ def __eq__ (self , to_compare ):
146
+ """ Checks if two ArmAuthorizerServerResult are the same """
147
+ try :
148
+ # Try to compare - this likely fails when it is compared to a non
149
+ # ArmAuthorizerServerResult object
150
+ return \
151
+ (self .result == to_compare .result ) and \
152
+ (self .result_str == to_compare .result_str )
153
+
154
+ except AttributeError :
155
+ return False
156
+
157
+ def __str__ (self ):
158
+ """ ArmAuthorizerServerResult in string representation """
159
+ struct_repr = ", " .join ([
160
+ "result: " + str (self .result ),
161
+ "result_str: " + str (self .result_str )
162
+ ])
163
+
164
+ return f"ArmAuthorizerServerResult: [{ struct_repr } ]"
165
+
166
+ @staticmethod
167
+ def translate_from_rpc (rpcArmAuthorizerServerResult ):
168
+ """ Translates a gRPC struct to the SDK equivalent """
169
+ return ArmAuthorizerServerResult (
170
+
171
+ ArmAuthorizerServerResult .Result .translate_from_rpc (rpcArmAuthorizerServerResult .result ),
172
+
173
+
174
+ rpcArmAuthorizerServerResult .result_str
175
+ )
176
+
177
+ def translate_to_rpc (self , rpcArmAuthorizerServerResult ):
178
+ """ Translates this SDK object into its gRPC equivalent """
179
+
180
+
181
+
182
+
183
+ rpcArmAuthorizerServerResult .result = self .result .translate_to_rpc ()
184
+
185
+
186
+
187
+
188
+
189
+ rpcArmAuthorizerServerResult .result_str = self .result_str
190
+
191
+
192
+
193
+
194
+
195
+
196
+ class ArmAuthorizerServerError (Exception ):
197
+ """ Raised when a ArmAuthorizerServerResult is a fail code """
198
+
199
+ def __init__ (self , result , origin , * params ):
200
+ self ._result = result
201
+ self ._origin = origin
202
+ self ._params = params
203
+
204
+ def __str__ (self ):
205
+ return f"{ self ._result .result } : '{ self ._result .result_str } '; origin: { self ._origin } ; params: { self ._params } "
206
+
207
+
208
+ class ArmAuthorizerServer (AsyncBase ):
209
+ """
210
+
211
+
212
+ Generated by dcsdkgen - MAVSDK ArmAuthorizerServer API
213
+ """
214
+
215
+ # Plugin name
216
+ name = "ArmAuthorizerServer"
217
+
218
+ def _setup_stub (self , channel ):
219
+ """ Setups the api stub """
220
+ self ._stub = arm_authorizer_server_pb2_grpc .ArmAuthorizerServerServiceStub (channel )
221
+
222
+
223
+ def _extract_result (self , response ):
224
+ """ Returns the response status and description """
225
+ return ArmAuthorizerServerResult .translate_from_rpc (response .arm_authorizer_server_result )
226
+
227
+
228
+ async def arm_authorization (self ):
229
+ """
230
+ Subscribe to arm authorization request messages. Each request received should respond to using RespondArmAuthorization
231
+
232
+ Yields
233
+ -------
234
+ system_id : uint32_t
235
+ vehicle system id
236
+
237
+
238
+ """
239
+
240
+ request = arm_authorizer_server_pb2 .SubscribeArmAuthorizationRequest ()
241
+ arm_authorization_stream = self ._stub .SubscribeArmAuthorization (request )
242
+
243
+ try :
244
+ async for response in arm_authorization_stream :
245
+
246
+
247
+
248
+ yield response .system_id
249
+ finally :
250
+ arm_authorization_stream .cancel ()
251
+
252
+ async def accept_arm_authorization (self , valid_time_s ):
253
+ """
254
+ Authorize arm for the specific time
255
+
256
+ Parameters
257
+ ----------
258
+ valid_time_s : int32_t
259
+ Time in seconds for which this authorization is valid
260
+
261
+ Raises
262
+ ------
263
+ ArmAuthorizerServerError
264
+ If the request fails. The error contains the reason for the failure.
265
+ """
266
+
267
+ request = arm_authorizer_server_pb2 .AcceptArmAuthorizationRequest ()
268
+ request .valid_time_s = valid_time_s
269
+ response = await self ._stub .AcceptArmAuthorization (request )
270
+
271
+
272
+ result = self ._extract_result (response )
273
+
274
+ if result .result != ArmAuthorizerServerResult .Result .SUCCESS :
275
+ raise ArmAuthorizerServerError (result , "accept_arm_authorization()" , valid_time_s )
276
+
277
+
278
+ async def reject_arm_authorization (self , temporarily , reason , extra_info ):
279
+ """
280
+ Reject arm authorization request
281
+
282
+ Parameters
283
+ ----------
284
+ temporarily : bool
285
+ True if the answer should be TEMPORARILY_REJECTED, false for DENIED
286
+
287
+ reason : RejectionReason
288
+ Reason for the arm to be rejected
289
+
290
+ extra_info : int32_t
291
+ Extra information specific to the rejection reason (see https://mavlink.io/en/services/arm_authorization.html)
292
+
293
+ Raises
294
+ ------
295
+ ArmAuthorizerServerError
296
+ If the request fails. The error contains the reason for the failure.
297
+ """
298
+
299
+ request = arm_authorizer_server_pb2 .RejectArmAuthorizationRequest ()
300
+ request .temporarily = temporarily
301
+
302
+ request .reason = reason .translate_to_rpc ()
303
+
304
+
305
+ request .extra_info = extra_info
306
+ response = await self ._stub .RejectArmAuthorization (request )
307
+
308
+
309
+ result = self ._extract_result (response )
310
+
311
+ if result .result != ArmAuthorizerServerResult .Result .SUCCESS :
312
+ raise ArmAuthorizerServerError (result , "reject_arm_authorization()" , temporarily , reason , extra_info )
313
+
0 commit comments