Skip to content

Commit 7b22974

Browse files
committed
Align with BlueST-SDK V1.1.3
Signed-off-by: Luca Pezzoni <luca.pezzoni@st.com>
1 parent e163d75 commit 7b22974

File tree

183 files changed

+1096
-357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+1096
-357
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Module for creating the BlueST-SDK library
44

55
## For using it
66

7-
Code compiled using gradle 8.2.1 and JDK jbr-17
7+
Code compiled using gradle 8.2.1 and JDK 17.0.7
88

99
set on Gradle properties the Github Login name and SSO authentication
1010
Example:

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ android {
2020
defaultConfig {
2121
applicationId "com.st.demo"
2222
minSdk rootProject.minSdk
23-
targetSdkVersion targetSdk
24-
versionCode 2
25-
versionName "5.0.0"
23+
targetSdkVersion rootProject.targetSdk
24+
versionCode 3
25+
versionName "5.2.1"
2626

2727
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2828
vectorDrawables {

app/src/main/java/com/st/demo/device_list/BleDeviceList.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import androidx.compose.runtime.*
3131
import androidx.compose.runtime.saveable.rememberSaveable
3232
import androidx.compose.ui.Alignment
3333
import androidx.compose.ui.Modifier
34-
import androidx.compose.ui.platform.LocalContext
3534
import androidx.compose.ui.res.stringResource
3635
import androidx.compose.ui.unit.dp
3736
import androidx.navigation.NavHostController
@@ -50,8 +49,6 @@ fun BleDeviceList(
5049
viewModel: BleDeviceListViewModel, navController: NavHostController
5150
) {
5251

53-
val context = LocalContext.current
54-
5552
var doNotShowRationale by rememberSaveable {
5653
mutableStateOf(false)
5754
}

build.gradle

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ buildscript {
1616

1717
compose_bom_date = '2023.10.01'
1818

19-
accompanist_version = '0.30.1'
20-
activity_compose_version = '1.8.0'
19+
accompanist_version = '0.32.0'
20+
activity_compose_version = '1.8.2'
2121
appcompat_version = '1.6.1'
2222
compose_compiler_version = '1.5.3'
2323
core_ktx_version = '1.12.0'
2424
espresso_core_version = '3.5.1'
25-
google_material_version = '1.10.0'
26-
gradle_version = '8.1.2'
27-
hilt_version = '2.48.1'
28-
hilt_compose_version = '1.0.0'
29-
hilt_navigation_fragment_version = '1.0.0'
25+
google_material_version = '1.11.0'
26+
gradle_version = '8.2.2'
27+
hilt_version = '2.50'
28+
hilt_compose_version = '1.1.0'
29+
hilt_navigation_fragment_version = '1.1.0'
3030
junit_version = '4.13.2'
3131
junit_ui_version = '1.1.5'
3232
kotlin_version = '1.9.10'
33-
kotlinx_serialization_version = '1.6.0'
33+
kotlinx_serialization_version = '1.6.2'
3434
kotlinx_retrofit_version = '1.0.0'
3535
ktlint_version = '11.3.1'
36-
lifecycle_version = '2.6.2'
37-
logging_version = '5.0.0-alpha.11'
36+
lifecycle_version = '2.7.0'
37+
logging_version = '5.0.0-alpha.12'
3838
nav_version = '2.6.0'
39-
navigation_compose_version = '2.7.4'
39+
navigation_compose_version = '2.7.6'
4040
retrofit_version = '2.9.0'
41-
room_version = '2.6.0'
41+
room_version = '2.6.1'
4242
}
4343

4444
repositories {

st_blue_sdk/publish.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ apply plugin: 'maven-publish'
1010

1111
def LIB_GROUP_ID = 'com.st.blue.sdk'
1212
def LIB_ARTIFACT_ID = 'st-blue-sdk'
13-
def LIB_VERSION = '1.1.0'
13+
def LIB_VERSION = '1.1.3'
1414

1515
afterEvaluate {
1616
publishing {

st_blue_sdk/src/main/java/com/st/blue_sdk/BlueManager.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package com.st.blue_sdk
99

1010
import android.content.ContentResolver
1111
import android.net.Uri
12+
import com.st.blue_sdk.board_catalog.models.BleCharacteristic
1213
import com.st.blue_sdk.board_catalog.models.BoardDescription
1314
import com.st.blue_sdk.board_catalog.models.BoardFirmware
1415
import com.st.blue_sdk.board_catalog.models.DtmiModel
@@ -50,7 +51,11 @@ interface BlueManager {
5051

5152
fun getRssi(nodeId: String)
5253

53-
fun connectToNode(nodeId: String, maxPayloadSize: Int = 248, enableServer: Boolean = true): Flow<Node>
54+
fun connectToNode(
55+
nodeId: String,
56+
maxPayloadSize: Int = 248,
57+
enableServer: Boolean = true
58+
): Flow<Node>
5459

5560
fun getNode(nodeId: String): Node?
5661

@@ -66,7 +71,10 @@ interface BlueManager {
6671

6772
suspend fun getNodeWithFirmwareInfo(nodeId: String): Node
6873

69-
suspend fun enableFeatures(nodeId: String, features: List<Feature<*>>): Boolean
74+
suspend fun enableFeatures(
75+
nodeId: String, features: List<Feature<*>>,
76+
onFeaturesEnabled: CoroutineScope.() -> Unit = { /** NOOP **/ }
77+
): Boolean
7078

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

@@ -103,9 +111,9 @@ interface BlueManager {
103111

104112
suspend fun getBoardsDescription(): List<BoardDescription>
105113

106-
suspend fun reset(url: String?=null)
114+
suspend fun reset(url: String? = null)
107115

108-
suspend fun getDtmiModel(nodeId: String,isBeta: Boolean): DtmiModel?
116+
suspend fun getDtmiModel(nodeId: String, isBeta: Boolean): DtmiModel?
109117

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

@@ -119,6 +127,8 @@ interface BlueManager {
119127

120128
suspend fun getSensorAdapter(uniqueId: Int): Sensor?
121129

130+
suspend fun getBleCharacteristics(): List<BleCharacteristic>
131+
122132
suspend fun upgradeFw(nodeId: String): FwConsole?
123133

124134
fun getFwUpdateStrategy(nodeId: String): UpgradeStrategy

st_blue_sdk/src/main/java/com/st/blue_sdk/BlueManagerImpl.kt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import android.content.Context
1717
import android.net.Uri
1818
import android.util.Log
1919
import com.st.blue_sdk.board_catalog.BoardCatalogRepo
20+
import com.st.blue_sdk.board_catalog.models.BleCharacteristic
2021
import com.st.blue_sdk.board_catalog.models.BoardDescription
2122
import com.st.blue_sdk.board_catalog.models.BoardFirmware
2223
import 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
}

st_blue_sdk/src/main/java/com/st/blue_sdk/LoggableUnit.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ class LoggableUnit : Loggable {
1818

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

21+
override val logDoubleValues: List<Double> = listOf()
2122
}

st_blue_sdk/src/main/java/com/st/blue_sdk/NodeService.kt

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class NodeService(
123123

124124
suspend fun setFeaturesNotifications(
125125
features: List<Feature<*>>,
126-
enabled: Boolean
126+
enabled: Boolean,
127+
onFeaturesEnabled: CoroutineScope.() -> Unit = { /** NOOP **/ }
127128
): Boolean {
128129

129130
var result = true
@@ -135,17 +136,39 @@ class NodeService(
135136
}.toSet()
136137

137138
characteristicsWithFeatures.forEach {
138-
val operationResult = bleHal.setCharacteristicNotification(
139-
serviceUid = it.characteristic.service.uuid.toString(),
140-
characteristicUid = it.characteristic.uuid.toString(),
141-
enabled = enabled
142-
)
143-
144-
if (operationResult) {
145-
it.hasEnabledNotifications = enabled
139+
if(enabled) {
140+
it.numberEnables++
141+
} else {
142+
it.numberEnables--
146143
}
144+
//For Avoiding to do this operation when it's not necessary
145+
if(it.hasEnabledNotifications!=enabled) {
146+
//For avoiding to remove the notification on Aggregate Features
147+
if((!enabled && (it.numberEnables==0)) || enabled) {
148+
val operationResult = bleHal.setCharacteristicNotification(
149+
serviceUid = it.characteristic.service.uuid.toString(),
150+
characteristicUid = it.characteristic.uuid.toString(),
151+
enabled = enabled
152+
)
153+
154+
if (operationResult) {
155+
it.hasEnabledNotifications = enabled
156+
if(enabled) {
157+
coroutineScope.launch {
158+
onFeaturesEnabled.invoke(this)
159+
}
160+
}
161+
}
147162

148-
result = result && operationResult
163+
result = result && operationResult
164+
}
165+
} else {
166+
if(enabled) {
167+
coroutineScope.launch {
168+
onFeaturesEnabled.invoke(this)
169+
}
170+
}
171+
}
149172
}
150173

151174
return result
@@ -455,5 +478,6 @@ class NodeService(
455478
data class CharacteristicWithFeatures(
456479
val characteristic: BluetoothGattCharacteristic,
457480
var hasEnabledNotifications: Boolean = false,
481+
var numberEnables: Int = 0,
458482
val features: List<Feature<*>> = emptyList()
459483
)

st_blue_sdk/src/main/java/com/st/blue_sdk/board_catalog/BoardCatalogRepo.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package com.st.blue_sdk.board_catalog
99

1010
import android.content.ContentResolver
1111
import android.net.Uri
12+
import com.st.blue_sdk.board_catalog.models.BleCharacteristic
1213
import com.st.blue_sdk.board_catalog.models.BoardDescription
1314
import com.st.blue_sdk.board_catalog.models.BoardFirmware
1415
import com.st.blue_sdk.board_catalog.models.DtmiModel
@@ -23,6 +24,8 @@ interface BoardCatalogRepo {
2324

2425
suspend fun getSensorAdapters(): List<Sensor>
2526

27+
suspend fun getBleCharacteristics(): List<BleCharacteristic>
28+
2629
suspend fun getSensorAdapter(uniqueId: Int): Sensor?
2730

2831
suspend fun getFwDetailsNode(deviceId: String, bleFwId: String): BoardFirmware?

0 commit comments

Comments
 (0)