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
@@ -123,21 +123,21 @@ def _find_version_item(self, **args: str) -> List[Dict[str, Any]]:
123123 # Make sure that the item matches all args value
124124 for item in self ._manifest ["firmware" ]:
125125 for key , value in args .items ():
126- real_key = key .replace ("_" , "-" )
127- if real_key not in item or item [real_key ] != value :
126+ real_key = key .replace ("_" , "-" ). lower ()
127+ if real_key not in item or item [real_key ]. lower () != value . lower () :
128128 break
129129 else :
130130 found_version_item .append (item )
131131
132132 return found_version_item
133133
134134 @temporary_cache (timeout_seconds = 3600 )
135- def get_available_versions (self , vehicle : Vehicle , platform : Platform ) -> List [str ]:
135+ def get_available_versions (self , vehicle : Vehicle , board : FlightController ) -> List [str ]:
136136 """Get available firmware versions for the specific plataform and vehicle
137137
138138 Args:
139139 vehicle (Vehicle): Desired vehicle.
140- platform (Platform ): Desired platform .
140+ board (FlightController ): Desired Flight Controller .
141141
142142 Returns:
143143 List[str]: List of available versions that match the specific desired configuration.
@@ -147,16 +147,18 @@ def get_available_versions(self, vehicle: Vehicle, platform: Platform) -> List[s
147147 if not self ._manifest_is_valid ():
148148 raise InvalidManifest ("Manifest file is invalid. Cannot use it to find available versions." )
149149
150- items = self ._find_version_item (vehicletype = vehicle .value , platform = platform .value )
150+ platform = board .platform .value if board .platform != Platform .GenericSerial else board .name
151+ platform_type = board .platform .type if board .platform != Platform .GenericSerial else PlatformType .Serial
152+ items = self ._find_version_item (vehicletype = vehicle .value , platform = platform )
151153
152154 for item in items :
153- if item ["format" ] == FirmwareDownloader ._supported_firmware_formats [platform . type ]:
155+ if item ["format" ] == FirmwareDownloader ._supported_firmware_formats [platform_type ]:
154156 available_versions .append (item ["mav-firmware-version-type" ])
155157
156158 return available_versions
157159
158160 @temporary_cache (timeout_seconds = 3600 )
159- def get_download_url (self , vehicle : Vehicle , platform : Platform , version : str = "" ) -> str :
161+ def get_download_url (self , vehicle : Vehicle , board : FlightController , version : str = "" ) -> str :
160162 """Find a specific firmware URL from manifest that matches the arguments.
161163
162164 Args:
@@ -168,16 +170,16 @@ def get_download_url(self, vehicle: Vehicle, platform: Platform, version: str =
168170 Returns:
169171 str: URL of valid firmware.
170172 """
171- versions = self .get_available_versions (vehicle , platform )
172- logger .debug (f"Got following versions for { vehicle } running { platform } : { versions } " )
173+ versions = self .get_available_versions (vehicle , board )
174+ logger .debug (f"Got following versions for { vehicle } running { board } : { versions } " )
173175
174176 if not versions :
175- raise NoVersionAvailable (f"Could not find available firmware versions for { platform } /{ vehicle } ." )
177+ raise NoVersionAvailable (f"Could not find available firmware versions for { board } /{ vehicle } ." )
176178
177179 if version and version not in versions :
178- raise NoVersionAvailable (f"Version { version } was not found for { platform } /{ vehicle } ." )
180+ raise NoVersionAvailable (f"Version { version } was not found for { board } /{ vehicle } ." )
179181
180- firmware_format = FirmwareDownloader ._supported_firmware_formats [platform .type ]
182+ firmware_format = FirmwareDownloader ._supported_firmware_formats [board . platform .type ]
181183
182184 # Autodetect the latest supported version.
183185 # For .apj firmwares (e.g. Pixhawk), we use the latest STABLE version while for the others (e.g. SITL and
@@ -192,21 +194,22 @@ def get_download_url(self, vehicle: Vehicle, platform: Platform, version: str =
192194 if not newest_version or Version (newest_version ) < Version (semver_version ):
193195 newest_version = semver_version
194196 if not newest_version :
195- raise NoVersionAvailable (f"No firmware versions found for { platform } /{ vehicle } ." )
197+ raise NoVersionAvailable (f"No firmware versions found for { board } /{ vehicle } ." )
196198 version = f"STABLE-{ newest_version } "
197199 else :
198200 version = "BETA"
199201
200202 items = self ._find_version_item (
201203 vehicletype = vehicle .value ,
202- platform = platform .value ,
204+ platform = board . platform .value if board . platform == Platform . SITL else board . name ,
203205 mav_firmware_version_type = version ,
204206 format = firmware_format ,
205207 )
206208
207209 if len (items ) == 0 :
210+ logger .error (f"Could not find any firmware for { vehicle = } , { board = } , { version = } , { firmware_format = } " )
208211 raise NoCandidate (
209- f"Found no candidate for configuration: { vehicle = } , { platform = } , { version = } , { firmware_format = } "
212+ f"Found no candidate for configuration: { vehicle = } , { board = } , { version = } , { firmware_format = } "
210213 )
211214
212215 if len (items ) != 1 :
@@ -216,7 +219,7 @@ def get_download_url(self, vehicle: Vehicle, platform: Platform, version: str =
216219 logger .debug (f"Downloading following firmware: { item } " )
217220 return str (item ["url" ])
218221
219- def download (self , vehicle : Vehicle , platform : Platform , version : str = "" ) -> pathlib .Path :
222+ def download (self , vehicle : Vehicle , board : FlightController , version : str = "" ) -> pathlib .Path :
220223 """Download a specific firmware that matches the arguments.
221224
222225 Args:
@@ -228,5 +231,5 @@ def download(self, vehicle: Vehicle, platform: Platform, version: str = "") -> p
228231 Returns:
229232 pathlib.Path: Temporary path for the firmware file.
230233 """
231- url = self .get_download_url (vehicle , platform , version )
234+ url = self .get_download_url (vehicle , board , version )
232235 return FirmwareDownloader ._download (url )
0 commit comments