2121 NoCandidate ,
2222 NoVersionAvailable ,
2323)
24- from typedefs import FirmwareFormat , Platform , PlatformType , Vehicle
24+ from typedefs import FirmwareFormat , FlightController , Platform , PlatformType , Vehicle
2525
2626# TODO: This should be not necessary
2727# Disable SSL verification
@@ -125,21 +125,21 @@ def _find_version_item(self, **args: str) -> List[Dict[str, Any]]:
125125 # Make sure that the item matches all args value
126126 for item in self ._manifest ["firmware" ]:
127127 for key , value in args .items ():
128- real_key = key .replace ("_" , "-" )
129- if real_key not in item or item [real_key ] != value :
128+ real_key = key .replace ("_" , "-" ). lower ()
129+ if real_key not in item or item [real_key ]. lower () != value . lower () :
130130 break
131131 else :
132132 found_version_item .append (item )
133133
134134 return found_version_item
135135
136136 @temporary_cache (timeout_seconds = 3600 )
137- def get_available_versions (self , vehicle : Vehicle , platform : Platform ) -> List [str ]:
137+ def get_available_versions (self , vehicle : Vehicle , board : FlightController ) -> List [str ]:
138138 """Get available firmware versions for the specific plataform and vehicle
139139
140140 Args:
141141 vehicle (Vehicle): Desired vehicle.
142- platform (Platform ): Desired platform .
142+ board (FlightController ): Desired Flight Controller .
143143
144144 Returns:
145145 List[str]: List of available versions that match the specific desired configuration.
@@ -149,16 +149,18 @@ def get_available_versions(self, vehicle: Vehicle, platform: Platform) -> List[s
149149 if not self ._manifest_is_valid ():
150150 raise InvalidManifest ("Manifest file is invalid. Cannot use it to find available versions." )
151151
152- items = self ._find_version_item (vehicletype = vehicle .value , platform = platform .value )
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 )
153155
154156 for item in items :
155- if item ["format" ] == FirmwareDownloader ._supported_firmware_formats [platform . type ]:
157+ if item ["format" ] == FirmwareDownloader ._supported_firmware_formats [platform_type ]:
156158 available_versions .append (item ["mav-firmware-version-type" ])
157159
158160 return available_versions
159161
160162 @temporary_cache (timeout_seconds = 3600 )
161- def get_download_url (self , vehicle : Vehicle , platform : Platform , version : str = "" ) -> str :
163+ def get_download_url (self , vehicle : Vehicle , board : FlightController , version : str = "" ) -> str :
162164 """Find a specific firmware URL from manifest that matches the arguments.
163165
164166 Args:
@@ -170,16 +172,16 @@ def get_download_url(self, vehicle: Vehicle, platform: Platform, version: str =
170172 Returns:
171173 str: URL of valid firmware.
172174 """
173- versions = self .get_available_versions (vehicle , platform )
174- logger .debug (f"Got following versions for { vehicle } running { platform } : { versions } " )
175+ versions = self .get_available_versions (vehicle , board )
176+ logger .debug (f"Got following versions for { vehicle } running { board } : { versions } " )
175177
176178 if not versions :
177- raise NoVersionAvailable (f"Could not find available firmware versions for { platform } /{ vehicle } ." )
179+ raise NoVersionAvailable (f"Could not find available firmware versions for { board } /{ vehicle } ." )
178180
179181 if version and version not in versions :
180- raise NoVersionAvailable (f"Version { version } was not found for { platform } /{ vehicle } ." )
182+ raise NoVersionAvailable (f"Version { version } was not found for { board } /{ vehicle } ." )
181183
182- firmware_format = FirmwareDownloader ._supported_firmware_formats [platform .type ]
184+ firmware_format = FirmwareDownloader ._supported_firmware_formats [board . platform .type ]
183185
184186 # Autodetect the latest supported version.
185187 # For .apj firmwares (e.g. Pixhawk), we use the latest STABLE version while for the others (e.g. SITL and
@@ -194,21 +196,22 @@ def get_download_url(self, vehicle: Vehicle, platform: Platform, version: str =
194196 if not newest_version or Version (newest_version ) < Version (semver_version ):
195197 newest_version = semver_version
196198 if not newest_version :
197- raise NoVersionAvailable (f"No firmware versions found for { platform } /{ vehicle } ." )
199+ raise NoVersionAvailable (f"No firmware versions found for { board } /{ vehicle } ." )
198200 version = f"STABLE-{ newest_version } "
199201 else :
200202 version = "BETA"
201203
202204 items = self ._find_version_item (
203205 vehicletype = vehicle .value ,
204- platform = platform .value ,
206+ platform = board . platform .value if board . platform == Platform . SITL else board . name ,
205207 mav_firmware_version_type = version ,
206208 format = firmware_format ,
207209 )
208210
209211 if len (items ) == 0 :
212+ logger .error (f"Could not find any firmware for { vehicle = } , { board = } , { version = } , { firmware_format = } " )
210213 raise NoCandidate (
211- f"Found no candidate for configuration: { vehicle = } , { platform = } , { version = } , { firmware_format = } "
214+ f"Found no candidate for configuration: { vehicle = } , { board = } , { version = } , { firmware_format = } "
212215 )
213216
214217 if len (items ) != 1 :
@@ -218,7 +221,7 @@ def get_download_url(self, vehicle: Vehicle, platform: Platform, version: str =
218221 logger .debug (f"Downloading following firmware: { item } " )
219222 return str (item ["url" ])
220223
221- def download (self , vehicle : Vehicle , platform : Platform , version : str = "" ) -> pathlib .Path :
224+ def download (self , vehicle : Vehicle , board : FlightController , version : str = "" ) -> pathlib .Path :
222225 """Download a specific firmware that matches the arguments.
223226
224227 Args:
@@ -230,5 +233,5 @@ def download(self, vehicle: Vehicle, platform: Platform, version: str = "") -> p
230233 Returns:
231234 pathlib.Path: Temporary path for the firmware file.
232235 """
233- url = self .get_download_url (vehicle , platform , version )
236+ url = self .get_download_url (vehicle , board , version )
234237 return FirmwareDownloader ._download (url )
0 commit comments