@@ -17,6 +17,7 @@ import android.content.Context
1717import android.net.Uri
1818import android.util.Log
1919import com.st.blue_sdk.board_catalog.BoardCatalogRepo
20+ import com.st.blue_sdk.board_catalog.models.BleCharacteristic
2021import com.st.blue_sdk.board_catalog.models.BoardDescription
2122import com.st.blue_sdk.board_catalog.models.BoardFirmware
2223import com.st.blue_sdk.board_catalog.models.DtmiModel
@@ -234,10 +235,21 @@ class BlueManagerImpl @Inject constructor(
234235 .filter { it.fota.bootloaderType == catalogInfo.fota.bootloaderType }
235236 .filter { ! it.fota.fwUrl.isNullOrEmpty() }.sortedBy { it.fwName }
236237
237- val fwUpdate = catalog.getFw(
238+ // List of fws update ordered by fw version
239+ val listOfFwUpdate = catalog.getFw(
238240 deviceId = catalogInfo.bleDevId, fwName = catalogInfo.fwName
239- ).filter { it.fota.fwUrl != null }.filter { it.fwVersion > catalogInfo.fwVersion }
240- .minByOrNull { it.fwVersion }
241+ ).filter { it.fota.fwUrl != null }.filter { it.fwVersion > catalogInfo.fwVersion }.sortedBy { it.fwVersion }
242+
243+ // Search if there is a mandatory update
244+ val fwMandatory = listOfFwUpdate.firstOrNull { it.fota.mandatory== true }
245+
246+ // the update will be the mandatory one, or the latest available
247+ val fwUpdate = fwMandatory ? : listOfFwUpdate.maxByOrNull { it.fwVersion }
248+
249+ // val fwUpdate = catalog.getFw(
250+ // deviceId = catalogInfo.bleDevId, fwName = catalogInfo.fwName
251+ // ).filter { it.fota.fwUrl != null }.filter { it.fwVersion > catalogInfo.fwVersion }
252+ // .minByOrNull { it.fwVersion }
241253
242254 node.copy(
243255 catalogInfo = catalogInfo, fwUpdate = fwUpdate, fwCompatibleList = fwCompatibleList
@@ -354,12 +366,13 @@ class BlueManagerImpl @Inject constructor(
354366 }
355367
356368 override suspend fun enableFeatures (
357- nodeId : String , features : List <Feature <* >>
369+ nodeId : String , features : List <Feature <* >>,
370+ onFeaturesEnabled : CoroutineScope .() -> Unit
358371 ): Boolean {
359372 val service = nodeServiceConsumer.getNodeService(nodeId)
360373 ? : throw IllegalStateException (" Unable to find NodeService for $nodeId " )
361374
362- return service.setFeaturesNotifications(features = features, true )
375+ return service.setFeaturesNotifications(features = features, true ,onFeaturesEnabled )
363376 }
364377
365378 override suspend fun disableFeatures (
@@ -489,6 +502,10 @@ class BlueManagerImpl @Inject constructor(
489502 return catalog.getSensorAdapter(uniqueId= uniqueId)
490503 }
491504
505+ override suspend fun getBleCharacteristics () : List <BleCharacteristic > {
506+ return catalog.getBleCharacteristics()
507+ }
508+
492509 override suspend fun upgradeFw (nodeId : String ): FwConsole ? {
493510 return otaService.updateFirmware(nodeId)
494511 }
0 commit comments