Skip to content

Commit

Permalink
Align with BlueST-SDK V1.1.3
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Pezzoni <[email protected]>
  • Loading branch information
PezzoniL committed Feb 29, 2024
1 parent e163d75 commit 7b22974
Show file tree
Hide file tree
Showing 183 changed files with 1,096 additions and 357 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Module for creating the BlueST-SDK library

## For using it

Code compiled using gradle 8.2.1 and JDK jbr-17
Code compiled using gradle 8.2.1 and JDK 17.0.7

set on Gradle properties the Github Login name and SSO authentication
Example:
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ android {
defaultConfig {
applicationId "com.st.demo"
minSdk rootProject.minSdk
targetSdkVersion targetSdk
versionCode 2
versionName "5.0.0"
targetSdkVersion rootProject.targetSdk
versionCode 3
versionName "5.2.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/com/st/demo/device_list/BleDeviceList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
Expand All @@ -50,8 +49,6 @@ fun BleDeviceList(
viewModel: BleDeviceListViewModel, navController: NavHostController
) {

val context = LocalContext.current

var doNotShowRationale by rememberSaveable {
mutableStateOf(false)
}
Expand Down
24 changes: 12 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ buildscript {

compose_bom_date = '2023.10.01'

accompanist_version = '0.30.1'
activity_compose_version = '1.8.0'
accompanist_version = '0.32.0'
activity_compose_version = '1.8.2'
appcompat_version = '1.6.1'
compose_compiler_version = '1.5.3'
core_ktx_version = '1.12.0'
espresso_core_version = '3.5.1'
google_material_version = '1.10.0'
gradle_version = '8.1.2'
hilt_version = '2.48.1'
hilt_compose_version = '1.0.0'
hilt_navigation_fragment_version = '1.0.0'
google_material_version = '1.11.0'
gradle_version = '8.2.2'
hilt_version = '2.50'
hilt_compose_version = '1.1.0'
hilt_navigation_fragment_version = '1.1.0'
junit_version = '4.13.2'
junit_ui_version = '1.1.5'
kotlin_version = '1.9.10'
kotlinx_serialization_version = '1.6.0'
kotlinx_serialization_version = '1.6.2'
kotlinx_retrofit_version = '1.0.0'
ktlint_version = '11.3.1'
lifecycle_version = '2.6.2'
logging_version = '5.0.0-alpha.11'
lifecycle_version = '2.7.0'
logging_version = '5.0.0-alpha.12'
nav_version = '2.6.0'
navigation_compose_version = '2.7.4'
navigation_compose_version = '2.7.6'
retrofit_version = '2.9.0'
room_version = '2.6.0'
room_version = '2.6.1'
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion st_blue_sdk/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: 'maven-publish'

def LIB_GROUP_ID = 'com.st.blue.sdk'
def LIB_ARTIFACT_ID = 'st-blue-sdk'
def LIB_VERSION = '1.1.0'
def LIB_VERSION = '1.1.3'

afterEvaluate {
publishing {
Expand Down
18 changes: 14 additions & 4 deletions st_blue_sdk/src/main/java/com/st/blue_sdk/BlueManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.st.blue_sdk

import android.content.ContentResolver
import android.net.Uri
import com.st.blue_sdk.board_catalog.models.BleCharacteristic
import com.st.blue_sdk.board_catalog.models.BoardDescription
import com.st.blue_sdk.board_catalog.models.BoardFirmware
import com.st.blue_sdk.board_catalog.models.DtmiModel
Expand Down Expand Up @@ -50,7 +51,11 @@ interface BlueManager {

fun getRssi(nodeId: String)

fun connectToNode(nodeId: String, maxPayloadSize: Int = 248, enableServer: Boolean = true): Flow<Node>
fun connectToNode(
nodeId: String,
maxPayloadSize: Int = 248,
enableServer: Boolean = true
): Flow<Node>

fun getNode(nodeId: String): Node?

Expand All @@ -66,7 +71,10 @@ interface BlueManager {

suspend fun getNodeWithFirmwareInfo(nodeId: String): Node

suspend fun enableFeatures(nodeId: String, features: List<Feature<*>>): Boolean
suspend fun enableFeatures(
nodeId: String, features: List<Feature<*>>,
onFeaturesEnabled: CoroutineScope.() -> Unit = { /** NOOP **/ }
): Boolean

suspend fun disableFeatures(nodeId: String, features: List<Feature<*>>): Boolean

Expand Down Expand Up @@ -103,9 +111,9 @@ interface BlueManager {

suspend fun getBoardsDescription(): List<BoardDescription>

suspend fun reset(url: String?=null)
suspend fun reset(url: String? = null)

suspend fun getDtmiModel(nodeId: String,isBeta: Boolean): DtmiModel?
suspend fun getDtmiModel(nodeId: String, isBeta: Boolean): DtmiModel?

suspend fun setBoardCatalog(fileUri: Uri, contentResolver: ContentResolver): List<BoardFirmware>

Expand All @@ -119,6 +127,8 @@ interface BlueManager {

suspend fun getSensorAdapter(uniqueId: Int): Sensor?

suspend fun getBleCharacteristics(): List<BleCharacteristic>

suspend fun upgradeFw(nodeId: String): FwConsole?

fun getFwUpdateStrategy(nodeId: String): UpgradeStrategy
Expand Down
27 changes: 22 additions & 5 deletions st_blue_sdk/src/main/java/com/st/blue_sdk/BlueManagerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import android.content.Context
import android.net.Uri
import android.util.Log
import com.st.blue_sdk.board_catalog.BoardCatalogRepo
import com.st.blue_sdk.board_catalog.models.BleCharacteristic
import com.st.blue_sdk.board_catalog.models.BoardDescription
import com.st.blue_sdk.board_catalog.models.BoardFirmware
import com.st.blue_sdk.board_catalog.models.DtmiModel
Expand Down Expand Up @@ -234,10 +235,21 @@ class BlueManagerImpl @Inject constructor(
.filter { it.fota.bootloaderType == catalogInfo.fota.bootloaderType }
.filter { !it.fota.fwUrl.isNullOrEmpty() }.sortedBy { it.fwName }

val fwUpdate = catalog.getFw(
//List of fws update ordered by fw version
val listOfFwUpdate = catalog.getFw(
deviceId = catalogInfo.bleDevId, fwName = catalogInfo.fwName
).filter { it.fota.fwUrl != null }.filter { it.fwVersion > catalogInfo.fwVersion }
.minByOrNull { it.fwVersion }
).filter { it.fota.fwUrl != null }.filter { it.fwVersion > catalogInfo.fwVersion }.sortedBy { it.fwVersion }

//Search if there is a mandatory update
val fwMandatory = listOfFwUpdate.firstOrNull { it.fota.mandatory==true }

//the update will be the mandatory one, or the latest available
val fwUpdate = fwMandatory ?: listOfFwUpdate.maxByOrNull { it.fwVersion }

// val fwUpdate = catalog.getFw(
// deviceId = catalogInfo.bleDevId, fwName = catalogInfo.fwName
// ).filter { it.fota.fwUrl != null }.filter { it.fwVersion > catalogInfo.fwVersion }
// .minByOrNull { it.fwVersion }

node.copy(
catalogInfo = catalogInfo, fwUpdate = fwUpdate, fwCompatibleList = fwCompatibleList
Expand Down Expand Up @@ -354,12 +366,13 @@ class BlueManagerImpl @Inject constructor(
}

override suspend fun enableFeatures(
nodeId: String, features: List<Feature<*>>
nodeId: String, features: List<Feature<*>>,
onFeaturesEnabled: CoroutineScope.() -> Unit
): Boolean {
val service = nodeServiceConsumer.getNodeService(nodeId)
?: throw IllegalStateException("Unable to find NodeService for $nodeId")

return service.setFeaturesNotifications(features = features, true)
return service.setFeaturesNotifications(features = features, true,onFeaturesEnabled)
}

override suspend fun disableFeatures(
Expand Down Expand Up @@ -489,6 +502,10 @@ class BlueManagerImpl @Inject constructor(
return catalog.getSensorAdapter(uniqueId=uniqueId)
}

override suspend fun getBleCharacteristics() : List<BleCharacteristic> {
return catalog.getBleCharacteristics()
}

override suspend fun upgradeFw(nodeId: String): FwConsole? {
return otaService.updateFirmware(nodeId)
}
Expand Down
1 change: 1 addition & 0 deletions st_blue_sdk/src/main/java/com/st/blue_sdk/LoggableUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ class LoggableUnit : Loggable {

override fun toString(): String = "No Data"

override val logDoubleValues: List<Double> = listOf()
}
44 changes: 34 additions & 10 deletions st_blue_sdk/src/main/java/com/st/blue_sdk/NodeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class NodeService(

suspend fun setFeaturesNotifications(
features: List<Feature<*>>,
enabled: Boolean
enabled: Boolean,
onFeaturesEnabled: CoroutineScope.() -> Unit = { /** NOOP **/ }
): Boolean {

var result = true
Expand All @@ -135,17 +136,39 @@ class NodeService(
}.toSet()

characteristicsWithFeatures.forEach {
val operationResult = bleHal.setCharacteristicNotification(
serviceUid = it.characteristic.service.uuid.toString(),
characteristicUid = it.characteristic.uuid.toString(),
enabled = enabled
)

if (operationResult) {
it.hasEnabledNotifications = enabled
if(enabled) {
it.numberEnables++
} else {
it.numberEnables--
}
//For Avoiding to do this operation when it's not necessary
if(it.hasEnabledNotifications!=enabled) {
//For avoiding to remove the notification on Aggregate Features
if((!enabled && (it.numberEnables==0)) || enabled) {
val operationResult = bleHal.setCharacteristicNotification(
serviceUid = it.characteristic.service.uuid.toString(),
characteristicUid = it.characteristic.uuid.toString(),
enabled = enabled
)

if (operationResult) {
it.hasEnabledNotifications = enabled
if(enabled) {
coroutineScope.launch {
onFeaturesEnabled.invoke(this)
}
}
}

result = result && operationResult
result = result && operationResult
}
} else {
if(enabled) {
coroutineScope.launch {
onFeaturesEnabled.invoke(this)
}
}
}
}

return result
Expand Down Expand Up @@ -455,5 +478,6 @@ class NodeService(
data class CharacteristicWithFeatures(
val characteristic: BluetoothGattCharacteristic,
var hasEnabledNotifications: Boolean = false,
var numberEnables: Int = 0,
val features: List<Feature<*>> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package com.st.blue_sdk.board_catalog

import android.content.ContentResolver
import android.net.Uri
import com.st.blue_sdk.board_catalog.models.BleCharacteristic
import com.st.blue_sdk.board_catalog.models.BoardDescription
import com.st.blue_sdk.board_catalog.models.BoardFirmware
import com.st.blue_sdk.board_catalog.models.DtmiModel
Expand All @@ -23,6 +24,8 @@ interface BoardCatalogRepo {

suspend fun getSensorAdapters(): List<Sensor>

suspend fun getBleCharacteristics(): List<BleCharacteristic>

suspend fun getSensorAdapter(uniqueId: Int): Sensor?

suspend fun getFwDetailsNode(deviceId: String, bleFwId: String): BoardFirmware?
Expand Down
Loading

0 comments on commit 7b22974

Please sign in to comment.