2121 NoCandidate ,
2222 NoVersionAvailable ,
2323)
24- from typedefs import FirmwareFormat , FlightController , Platform , PlatformType , Vehicle
24+ from typedefs import Firmware , FirmwareFormat , FlightController , Platform , PlatformType , Vehicle
2525
2626# TODO: This should be not necessary
2727# Disable SSL verification
@@ -105,7 +105,7 @@ def download_manifest(self) -> bool:
105105
106106 return True
107107
108- def _find_version_item (self , ** args : str ) -> List [Dict [ str , Any ] ]:
108+ def _find_version_item (self , ** args : str ) -> List [Firmware ]:
109109 """Find version objects in the manifest that match the specific case of **args
110110
111111 The arguments should follow the same name described in the dictionary inside the manifest
@@ -117,6 +117,7 @@ def _find_version_item(self, **args: str) -> List[Dict[str, Any]]:
117117 Returns:
118118 List[Dict[str, Any]]: A list of firmware items that match the arguments.
119119 """
120+ logger .info (f"Searching for version item with args: { args } " )
120121 if not self ._manifest and not self .download_manifest ():
121122 raise ManifestUnavailable ("Manifest file is not available. Cannot use it to find firmware candidates." )
122123
@@ -125,39 +126,45 @@ def _find_version_item(self, **args: str) -> List[Dict[str, Any]]:
125126 # Make sure that the item matches all args value
126127 for item in self ._manifest ["firmware" ]:
127128 for key , value in args .items ():
128- real_key = key .replace ("_" , "-" ).lower ()
129- if real_key not in item or item [real_key ].lower () != value .lower ():
129+ real_key = key .replace ("_" , "-" ).lower () if key != "board_id" else "board_id"
130+ if real_key not in item or str ( item [real_key ]) .lower () != str ( value ) .lower ():
130131 break
131132 else :
132133 found_version_item .append (item )
133134
134- return found_version_item
135+ return [
136+ Firmware (
137+ board_id = item ["board_id" ] if "board_id" in item else None ,
138+ platform = item ["platform" ],
139+ name = item ["mav-firmware-version-type" ],
140+ url = item ["url" ],
141+ )
142+ for item in found_version_item
143+ ]
135144
136145 @temporary_cache (timeout_seconds = 3600 )
137- def get_available_versions (self , vehicle : Vehicle , board : FlightController ) -> List [str ]:
146+ def get_available_versions (
147+ self , vehicle : Vehicle , board : FlightController , firmware_name : Optional [str ] = "Ardupilot"
148+ ) -> List [Firmware ]:
138149 """Get available firmware versions for the specific plataform and vehicle
139150
140151 Args:
141152 vehicle (Vehicle): Desired vehicle.
142153 board (FlightController): Desired Flight Controller.
154+ firmware (Optional[str]): Desired firmware ("Ardupilot" or "PX4").
143155
144156 Returns:
145157 List[str]: List of available versions that match the specific desired configuration.
146158 """
147- available_versions : List [ str ] = []
148-
159+ logger . info ( f"Getting available versions for { vehicle = } , { board = } , { firmware_name = } " )
160+ logger . error ( "implement px4 stuff!" , firmware_name )
149161 if not self ._manifest_is_valid ():
150162 raise InvalidManifest ("Manifest file is invalid. Cannot use it to find available versions." )
151-
152- platform = board .platform .value if board .platform != Platform .GenericSerial else board .name
153- platform_type = board .platform .type if board .platform != Platform .GenericSerial else PlatformType .Serial
154- items = self ._find_version_item (vehicletype = vehicle .value , platform = platform )
155-
156- for item in items :
157- if item ["format" ] == FirmwareDownloader ._supported_firmware_formats [platform_type ]:
158- available_versions .append (item ["mav-firmware-version-type" ])
159-
160- return available_versions
163+ if board .ardupilot_board_id is None :
164+ if board .platform != Platform .GenericSerial :
165+ return self ._find_version_item (vehicletype = vehicle .value , platform = board .platform .value )
166+ return self ._find_version_item (vehicletype = vehicle .value , platform = board .name )
167+ return self ._find_version_item (vehicletype = vehicle .value , board_id = str (board .ardupilot_board_id ))
161168
162169 @temporary_cache (timeout_seconds = 3600 )
163170 def get_download_url (self , vehicle : Vehicle , board : FlightController , version : str = "" ) -> str :
@@ -178,21 +185,21 @@ def get_download_url(self, vehicle: Vehicle, board: FlightController, version: s
178185 if not versions :
179186 raise NoVersionAvailable (f"Could not find available firmware versions for { board } /{ vehicle } ." )
180187
181- if version and version not in versions :
188+ if version and not any ( version == found_version . name for found_version in versions ) :
182189 raise NoVersionAvailable (f"Version { version } was not found for { board } /{ vehicle } ." )
183190
184- firmware_format = FirmwareDownloader ._supported_firmware_formats [board .platform .type ]
191+ firmware_format = FirmwareDownloader ._supported_firmware_formats [board .platform .type ]. value
185192
186193 # Autodetect the latest supported version.
187194 # For .apj firmwares (e.g. Pixhawk), we use the latest STABLE version while for the others (e.g. SITL and
188195 # Navigator) we use latest BETA. Specially on this development phase of the BlueOS/navigator, using
189196 # the BETA release allow us to track and fix introduced bugs faster.
190197 if not version :
191198 if firmware_format == FirmwareFormat .APJ :
192- supported_versions = [version for version in versions if "STABLE" in version ]
199+ supported_versions = [version for version in versions if "STABLE" in version . name ]
193200 newest_version : Optional [str ] = None
194201 for supported_version in supported_versions :
195- semver_version = supported_version .split ("-" )[1 ]
202+ semver_version = supported_version .name . split ("-" )[1 ]
196203 if not newest_version or Version (newest_version ) < Version (semver_version ):
197204 newest_version = semver_version
198205 if not newest_version :
@@ -219,7 +226,7 @@ def get_download_url(self, vehicle: Vehicle, board: FlightController, version: s
219226
220227 item = items [0 ]
221228 logger .debug (f"Downloading following firmware: { item } " )
222- return str ( item [ " url" ])
229+ return item . url
223230
224231 def download (self , vehicle : Vehicle , board : FlightController , version : str = "" ) -> pathlib .Path :
225232 """Download a specific firmware that matches the arguments.
0 commit comments