Skip to content

Commit

Permalink
Updated to BlueST-SDK V1.0.10
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Pezzoni <[email protected]>
  • Loading branch information
PezzoniL committed Oct 23, 2023
1 parent dfd85a7 commit bd33e48
Show file tree
Hide file tree
Showing 49 changed files with 1,313 additions and 333 deletions.
4 changes: 2 additions & 2 deletions 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.1.1 and JDK 11
Code compiled using gradle 8.2.1 and JDK jbr-17

set on Gradle properties the Github Login name and SSO authentication
Example:
Expand Down Expand Up @@ -34,4 +34,4 @@ So:
st_blue_sdk/publishing/publishToMavenLocal

st_opus/build/assemble
st_opus/publishing/publishToMavenLocal
st_opus/publishing/publishToMavenLocal
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
defaultConfig {
applicationId "com.st.demo"
minSdk rootProject.minSdk
targetSdk rootProject.targetSdk
targetSdkVersion targetSdk
versionCode 1
versionName "4.17"

Expand Down Expand Up @@ -109,8 +109,8 @@ dependencies {
kapt "com.google.dagger:hilt-compiler:$hilt_version"

// Kotlinx serialization
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0"
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinx_serialization_version"
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:$kotlinx_retrofit_version"

// Accompanist
implementation "com.google.accompanist:accompanist-permissions:$accompanist_version"
Expand Down
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@
buildscript {
ext {
// Sdk and Tools
minSdk = 21
minSdk = 26
targetSdk = 33
compileSdk = 33

compose_bom_date = '2023.05.01'
compose_bom_date = '2023.06.01'

accompanist_version = '0.30.1'
activity_compose_version = '1.7.1'
activity_compose_version = '1.7.2'
appcompat_version = '1.6.1'
compose_compiler_version = '1.4.7'
core_ktx_version = '1.10.1'
espresso_core_version = '3.5.1'
google_material_version = '1.9.0'
gradle_version = '8.0.2'
hilt_version = '2.46.1'
gradle_version = '8.1.0'
hilt_version = '2.47'
hilt_compose_version = '1.0.0'
hilt_navigation_fragment_version = '1.0.0'
junit_version = '4.13.2'
junit_ui_version = '1.1.5'
kotlin_version = '1.8.21'
kotlinx_serialization_version = '1.5.0'
kotlinx_serialization_version = '1.5.1'
kotlinx_retrofit_version = '1.0.0'
ktlint_version = '11.3.1'
lifecycle_version = '2.6.1'
logging_version = '5.0.0-alpha.11'
nav_version = '2.5.3'
navigation_compose_version = '2.5.3'
nav_version = '2.6.0'
navigation_compose_version = '2.6.0'
retrofit_version = '2.9.0'
room_version = '2.6.0-alpha01'
}
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.0.0'
def LIB_VERSION = '1.0.10'

afterEvaluate {
publishing {
Expand Down
10 changes: 8 additions & 2 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 @@ -12,12 +12,14 @@ import android.net.Uri
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
import com.st.blue_sdk.board_catalog.models.Sensor
import com.st.blue_sdk.common.Resource
import com.st.blue_sdk.features.Feature
import com.st.blue_sdk.features.FeatureCommand
import com.st.blue_sdk.features.FeatureResponse
import com.st.blue_sdk.features.FeatureUpdate
import com.st.blue_sdk.logger.Logger
import com.st.blue_sdk.models.ChunkProgress
import com.st.blue_sdk.models.Node
import com.st.blue_sdk.services.debug.DebugMessage
import com.st.blue_sdk.services.fw_version.FwVersionBoard
Expand Down Expand Up @@ -48,7 +50,7 @@ interface BlueManager {

fun getRssi(nodeId: String)

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

fun getNode(nodeId: String): Node?

Expand Down Expand Up @@ -87,6 +89,8 @@ interface BlueManager {

fun getDebugMessages(nodeId: String): Flow<DebugMessage>?

fun getChunkProgressUpdates(nodeId: String): Flow<ChunkProgress>?

suspend fun writeFeatureCommand(
nodeId: String,
featureCommand: FeatureCommand,
Expand All @@ -101,7 +105,7 @@ interface BlueManager {

suspend fun reset(url: String?=null)

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

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

Expand All @@ -113,6 +117,8 @@ interface BlueManager {

suspend fun getBoardFirmware(nodeId: String): BoardFirmware?

suspend fun getSensorAdapter(uniqueId: Int): Sensor?

suspend fun upgradeFw(nodeId: String): FwConsole?

fun getFwUpdateStrategy(nodeId: String): UpgradeStrategy
Expand Down
40 changes: 32 additions & 8 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 @@ -20,6 +20,7 @@ import com.st.blue_sdk.board_catalog.BoardCatalogRepo
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
import com.st.blue_sdk.board_catalog.models.Sensor
import com.st.blue_sdk.bt.advertise.AdvertiseFilter
import com.st.blue_sdk.bt.advertise.BlueNRGAdvertiseFilter
import com.st.blue_sdk.bt.advertise.BlueSTSDKAdvertiseFilter
Expand All @@ -34,6 +35,7 @@ import com.st.blue_sdk.features.exported.ExportedAudioOpusMusicFeature
import com.st.blue_sdk.features.exported.ExportedAudioOpusVoiceFeature
import com.st.blue_sdk.features.exported.ExportedFeature
import com.st.blue_sdk.logger.Logger
import com.st.blue_sdk.models.ChunkProgress
import com.st.blue_sdk.models.Node
import com.st.blue_sdk.services.NodeServerConsumer
import com.st.blue_sdk.services.NodeServerProducer
Expand Down Expand Up @@ -69,6 +71,8 @@ class BlueManagerImpl @Inject constructor(
private val otaService: OtaService
) : BlueManager {

private var serverWasEnable=true

companion object {
private val TAG = BlueManager::class.java.simpleName
private const val EXPORTED_SERVICE = "00000000-0001-11e1-9ab4-0002a5d5c51b"
Expand Down Expand Up @@ -228,7 +232,7 @@ class BlueManagerImpl @Inject constructor(
val fwCompatibleList = catalog.getFwCompatible(deviceId = catalogInfo.bleDevId)
.filter { (it.fwName != catalogInfo.fwName) || (it.fwVersion != catalogInfo.fwVersion) }
.filter { it.fota.bootloaderType == catalogInfo.fota.bootloaderType }
.filter { it.fota.fwUrl != null }.sortedBy { it.fwName }
.filter { !it.fota.fwUrl.isNullOrEmpty() }.sortedBy { it.fwName }

val fwUpdate = catalog.getFw(
deviceId = catalogInfo.bleDevId, fwName = catalogInfo.fwName
Expand Down Expand Up @@ -296,12 +300,14 @@ class BlueManagerImpl @Inject constructor(
nodeServiceConsumer.getNodeService(deviceAddress) != null

@SuppressLint("MissingPermission")
override fun connectToNode(nodeId: String, maxPayloadSize: Int): Flow<Node> {
override fun connectToNode(nodeId: String, maxPayloadSize: Int, enableServer: Boolean): Flow<Node> {
val nodeService = nodeServiceConsumer.getNodeService(nodeId) ?: throw IllegalStateException(
"Unable to find NodeService for $nodeId"
)

stopScan()

serverWasEnable = enableServer
connectFromNode(node = nodeService.bleHal.getDevice())

return nodeService.connectToNode(autoConnect = false, maxPayloadSize = maxPayloadSize)
Expand Down Expand Up @@ -406,12 +412,18 @@ class BlueManagerImpl @Inject constructor(
return service.getConfigControlUpdates()
}

override fun getDebugMessages(nodeId: String): Flow<DebugMessage>? {
override fun getDebugMessages(nodeId: String): Flow<DebugMessage> {
val service = nodeServiceConsumer.getNodeService(nodeId)
?: throw IllegalStateException("Unable to find NodeService for $nodeId")
return service.getDebugMessages()
}

override fun getChunkProgressUpdates(nodeId: String): Flow<ChunkProgress> {
val service = nodeServiceConsumer.getNodeService(nodeId)
?: throw IllegalStateException("Unable to find NodeService for $nodeId")
return service.getChunkProgressUpdates()
}

override suspend fun writeFeatureCommand(
nodeId: String,
featureCommand: FeatureCommand,
Expand All @@ -430,11 +442,11 @@ class BlueManagerImpl @Inject constructor(
)
}

override suspend fun getDtmiModel(nodeId: String): DtmiModel? {
override suspend fun getDtmiModel(nodeId: String,isBeta: Boolean): DtmiModel? {
val nodeService = nodeServiceConsumer.getNodeService(nodeId) ?: return null
val advInfo = nodeService.getNode().advertiseInfo ?: return null
return advInfo.getFwInfo()?.let {
catalog.getDtmiModel(it.deviceId, it.fwId)
catalog.getDtmiModel(it.deviceId, it.fwId,isBeta)
}
}

Expand Down Expand Up @@ -473,6 +485,10 @@ class BlueManagerImpl @Inject constructor(
return getBoardFirmware(nodeService = nodeService)
}

override suspend fun getSensorAdapter(uniqueId: Int): Sensor? {
return catalog.getSensorAdapter(uniqueId=uniqueId)
}

override suspend fun upgradeFw(nodeId: String): FwConsole? {
return otaService.updateFirmware(nodeId)
}
Expand All @@ -489,21 +505,29 @@ class BlueManagerImpl @Inject constructor(
private fun connectFromNode(node: Node): Boolean {
val server = nodeServerConsumer.getNodeServer(node.device.address)
?: nodeServerProducer.createServer(node, EXPORTED_MAP)
return server.connectToPeripheral()
return if(serverWasEnable) {
server.connectToPeripheral()
} else {
false
}
}

private fun disconnectFromNode(nodeId: String? = null): Boolean {
if (nodeId == null) {
nodeServerConsumer.getNodeServers().forEach {
it.disconnectFromPeripheral()
if(serverWasEnable) {
it.disconnectFromPeripheral()
}
}

nodeServerProducer.clear()

return true
} else {
nodeServerConsumer.getNodeServer(nodeId)?.let { server ->
server.disconnectFromPeripheral()
if(serverWasEnable) {
server.disconnectFromPeripheral()
}

nodeServerProducer.removeServer(nodeId = nodeId)

Expand Down
13 changes: 9 additions & 4 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 @@ -8,7 +8,6 @@
package com.st.blue_sdk

import android.annotation.SuppressLint
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGattCharacteristic
import android.util.Log
import com.st.blue_sdk.bt.advertise.BleAdvertiseInfo
Expand Down Expand Up @@ -103,6 +102,8 @@ class NodeService(

fun getDeviceStatus() = bleHal.getDeviceStatus()

fun getChunkProgressUpdates() = bleHal.getChunkProgressUpdates()

fun getRssi() = bleHal.getRssi()

fun isConnected(): Boolean = bleHal.isConnected()
Expand Down Expand Up @@ -192,8 +193,11 @@ class NodeService(
val protocolVersion = advertiseInfo.getProtocolVersion()

characteristicWithFeatures.clear()
val boardModel: Boards.Model =
Boards.getModelFromIdentifier(advertiseInfo.getDeviceId().toInt())
val deviceId = advertiseInfo.getDeviceId().toInt()
val sdkVersion = advertiseInfo.getProtocolVersion().toInt()
val boardModel: Boards.Model = advertiseInfo.getBoardType()

val containsRemoteFeatures = Boards.containsRemoteFeatures(deviceId,sdkVersion)

bleHal.getDiscoveredServices().map { service ->
service.characteristics.forEach { characteristic ->
Expand Down Expand Up @@ -227,7 +231,8 @@ class NodeService(
features = characteristic.buildFeatures(
advertiseMask = featureMap,
protocolVersion = protocolVersion,
boardModel = boardModel
boardModel = boardModel,
containsRemoteFeatures = containsRemoteFeatures
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.net.Uri
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
import com.st.blue_sdk.board_catalog.models.Sensor

interface BoardCatalogRepo {
suspend fun reset(url: String?=null)
Expand All @@ -20,13 +21,17 @@ interface BoardCatalogRepo {

suspend fun getBoardsDescription(): List<BoardDescription>

suspend fun getSensorAdapters(): List<Sensor>

suspend fun getSensorAdapter(uniqueId: Int): Sensor?

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

suspend fun getFwCompatible(deviceId: String): List<BoardFirmware>

suspend fun getFw(deviceId: String, fwName: String): List<BoardFirmware>

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

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

Expand Down
Loading

0 comments on commit bd33e48

Please sign in to comment.