52
52
raise RuntimeError ("ArduPilot manager needs to run with root privilege." )
53
53
54
54
55
- def target_board (board_name : Optional [str ]) -> FlightController :
55
+ async def target_board (board_name : Optional [str ]) -> FlightController :
56
56
"""Returns the board that should be used to perform operations on.
57
57
58
58
Most of the API routes that have operations related to board management will give the option to perform those
@@ -64,7 +64,7 @@ def target_board(board_name: Optional[str]) -> FlightController:
64
64
"""
65
65
if board_name is not None :
66
66
try :
67
- return next (board for board in autopilot .available_boards (True ) if board .name == board_name )
67
+ return next (board for board in await autopilot .available_boards (True ) if board .name == board_name )
68
68
except StopIteration as error :
69
69
raise ValueError ("Chosen board not available." ) from error
70
70
if autopilot .current_board is None :
@@ -153,8 +153,8 @@ async def get_firmware_vehicle_type() -> Any:
153
153
summary = "Retrieve dictionary of available firmwares versions with their respective URL." ,
154
154
)
155
155
@version (1 , 0 )
156
- def get_available_firmwares (vehicle : Vehicle , board_name : Optional [str ] = None ) -> Any :
157
- return autopilot .get_available_firmwares (vehicle , target_board (board_name ).platform )
156
+ async def get_available_firmwares (vehicle : Vehicle , board_name : Optional [str ] = None ) -> Any :
157
+ return autopilot .get_available_firmwares (vehicle , ( await target_board (board_name ) ).platform )
158
158
159
159
160
160
@app .post ("/install_firmware_from_url" , summary = "Install firmware for given URL." )
@@ -168,7 +168,7 @@ async def install_firmware_from_url(
168
168
) -> Any :
169
169
try :
170
170
await autopilot .kill_ardupilot ()
171
- autopilot .install_firmware_from_url (url , target_board (board_name ), make_default , parameters )
171
+ autopilot .install_firmware_from_url (url , await target_board (board_name ), make_default , parameters )
172
172
finally :
173
173
await autopilot .start_ardupilot ()
174
174
@@ -188,7 +188,7 @@ async def install_firmware_from_file(
188
188
logger .debug ("Going to kill ardupilot" )
189
189
await autopilot .kill_ardupilot ()
190
190
logger .debug ("Installing firmware from file" )
191
- autopilot .install_firmware_from_file (custom_firmware , target_board (board_name ), parameters )
191
+ autopilot .install_firmware_from_file (custom_firmware , await target_board (board_name ), parameters )
192
192
os .remove (custom_firmware )
193
193
except InvalidFirmwareFile as error :
194
194
raise StackedHTTPException (status_code = status .HTTP_415_UNSUPPORTED_MEDIA_TYPE , error = error ) from error
@@ -260,15 +260,15 @@ async def stop() -> Any:
260
260
async def restore_default_firmware (board_name : Optional [str ] = None ) -> Any :
261
261
try :
262
262
await autopilot .kill_ardupilot ()
263
- autopilot .restore_default_firmware (target_board (board_name ))
263
+ autopilot .restore_default_firmware (await target_board (board_name ))
264
264
finally :
265
265
await autopilot .start_ardupilot ()
266
266
267
267
268
268
@app .get ("/available_boards" , response_model = List [FlightController ], summary = "Retrieve list of connected boards." )
269
269
@version (1 , 0 )
270
- def available_boards () -> Any :
271
- return autopilot .available_boards (True )
270
+ async def available_boards () -> Any :
271
+ return await autopilot .available_boards (True )
272
272
273
273
274
274
app = VersionedFastAPI (app , version = "1.0.0" , prefix_format = "/v{major}.{minor}" , enable_latest = True )
0 commit comments