Skip to content

Commit

Permalink
Align with BlueST-SDK V1.1.0
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Pezzoni <[email protected]>
  • Loading branch information
PezzoniL committed Dec 15, 2023
1 parent bd33e48 commit e163d75
Show file tree
Hide file tree
Showing 29 changed files with 603 additions and 54 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
applicationId "com.st.demo"
minSdk rootProject.minSdk
targetSdkVersion targetSdk
versionCode 1
versionName "4.17"
versionCode 2
versionName "5.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
30 changes: 15 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ buildscript {
ext {
// Sdk and Tools
minSdk = 26
targetSdk = 33
compileSdk = 33
targetSdk = 34
compileSdk = 34

compose_bom_date = '2023.06.01'
compose_bom_date = '2023.10.01'

accompanist_version = '0.30.1'
activity_compose_version = '1.7.2'
activity_compose_version = '1.8.0'
appcompat_version = '1.6.1'
compose_compiler_version = '1.4.7'
core_ktx_version = '1.10.1'
compose_compiler_version = '1.5.3'
core_ktx_version = '1.12.0'
espresso_core_version = '3.5.1'
google_material_version = '1.9.0'
gradle_version = '8.1.0'
hilt_version = '2.47'
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'
junit_version = '4.13.2'
junit_ui_version = '1.1.5'
kotlin_version = '1.8.21'
kotlinx_serialization_version = '1.5.1'
kotlin_version = '1.9.10'
kotlinx_serialization_version = '1.6.0'
kotlinx_retrofit_version = '1.0.0'
ktlint_version = '11.3.1'
lifecycle_version = '2.6.1'
lifecycle_version = '2.6.2'
logging_version = '5.0.0-alpha.11'
nav_version = '2.6.0'
navigation_compose_version = '2.6.0'
navigation_compose_version = '2.7.4'
retrofit_version = '2.9.0'
room_version = '2.6.0-alpha01'
room_version = '2.6.0'
}

repositories {
Expand All @@ -57,5 +57,5 @@ plugins {
id "com.android.library" version "$gradle_version" apply false
id "org.jetbrains.kotlin.android" version "$kotlin_version" apply false
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" apply false
id 'com.google.devtools.ksp' version '1.8.21-1.0.11' apply false
id 'com.google.devtools.ksp' version '1.9.10-1.0.13' apply false
}
3 changes: 2 additions & 1 deletion st_blue_sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
schemas
7 changes: 4 additions & 3 deletions st_blue_sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlinx-serialization'
id 'com.google.devtools.ksp'
id 'com.google.devtools.ksp' version '1.9.10-1.0.13'
}

apply from: file('publish.gradle')
Expand Down Expand Up @@ -52,9 +52,9 @@ android {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
arg("room.generateKotlin","true")
}

namespace 'com.st.blue_sdk'
Expand Down Expand Up @@ -87,8 +87,9 @@ dependencies {

// Room
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
ksp "androidx.room:room-compiler:$room_version"
annotationProcessor("androidx.room:room-compiler:$room_version")
implementation("androidx.room:room-ktx:$room_version")

// Tests
testImplementation "junit:junit:$junit_version"
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.10'
def LIB_VERSION = '1.1.0'

afterEvaluate {
publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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.DtmiContent
import com.st.blue_sdk.board_catalog.models.DtmiModel
import com.st.blue_sdk.board_catalog.models.FirmwareMaturity
import com.st.blue_sdk.board_catalog.models.Sensor
import com.st.blue_sdk.board_catalog.models.toDtmiContent
import dagger.hilt.android.qualifiers.ApplicationContext
Expand Down Expand Up @@ -187,7 +188,8 @@ class BoardCatalogRepoImpl @Inject constructor(

val savedBoardsModelString = pref.getString(CUSTOM_BOARDS_MODEL, null)
savedBoardsModelString?.let {
val result = json.decodeFromString<BoardCatalog>(savedBoardsModelString)?.let { boardCatalog ->
val result = json.decodeFromString<BoardCatalog>(savedBoardsModelString)
?.let { boardCatalog ->
boardCatalog.bleListBoardFirmwareV1?.let {
db.add(it)
cache.addAll(it)
Expand Down Expand Up @@ -321,7 +323,11 @@ class BoardCatalogRepoImpl @Inject constructor(
return cache.find { it.bleFwId == bleFwId && deviceId == it.bleDevId }
}

override suspend fun getDtmiModel(deviceId: String, bleFwId: String, isBeta: Boolean): DtmiModel? {
override suspend fun getDtmiModel(
deviceId: String,
bleFwId: String,
isBeta: Boolean
): DtmiModel? {
if (needSync()) {
sync()
}
Expand Down Expand Up @@ -434,13 +440,19 @@ class BoardCatalogRepoImpl @Inject constructor(
if (inStream != null) {
val text = inStream.bufferedReader(StandardCharsets.ISO_8859_1).readText()
inStream.close()
val result = json.decodeFromString<BoardCatalog>(text)?.let { boardCatalog ->
val result = json.decodeFromString<BoardCatalog>(text).let { boardCatalog ->
cache.clear()
boardCatalog.bleListBoardFirmwareV1?.let {
it.forEach { it2 ->
if (it2.bleFwId == "0xFF") it2.maturity = FirmwareMaturity.CUSTOM
}
db.add(it)
//it.forEach { it2 -> cache.add(it2) }
}
boardCatalog.bleListBoardFirmwareV2?.let {
it.forEach { it2 ->
if (it2.bleFwId == "0xFF") it2.maturity = FirmwareMaturity.CUSTOM
}
db.add(it)
//it.forEach { it2 -> cache.add(it2) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ package com.st.blue_sdk.board_catalog.api.serializers

import com.st.blue_sdk.board_catalog.models.BoardFotaType
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializer(forClass = BoardFotaType::class)
class BoardFotaTypeSerializer : KSerializer<BoardFotaType> {

override val descriptor: SerialDescriptor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package com.st.blue_sdk.board_catalog.api.serializers

import com.st.blue_sdk.board_catalog.models.BoardStatus
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializer(forClass = BoardStatus::class)
class BoardStatusTypeSerializer : KSerializer<BoardStatus> {

override val descriptor: SerialDescriptor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package com.st.blue_sdk.board_catalog.api.serializers

import com.st.blue_sdk.board_catalog.models.BootLoaderType
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializer(forClass = BootLoaderType::class)
class BootLoaderTypeSerializer : KSerializer<BootLoaderType> {

override val descriptor: SerialDescriptor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package com.st.blue_sdk.board_catalog.api.serializers

import android.util.Log
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
Expand All @@ -18,7 +17,6 @@ import kotlinx.serialization.encoding.Encoder
import java.text.SimpleDateFormat
import java.util.*

@Serializer(forClass = Date::class)
class DateSerializer : KSerializer<Date> {

private var formatStrings = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.st.blue_sdk.board_catalog.api.serializers

import com.st.blue_sdk.board_catalog.models.FirmwareMaturity
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

class FirmwareMaturityTypeSerializer : KSerializer<FirmwareMaturity> {

override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("FirmwareMaturityType", PrimitiveKind.STRING)

override fun deserialize(decoder: Decoder): FirmwareMaturity =
FirmwareMaturity.valueOf(decoder.decodeString().uppercase())

override fun serialize(encoder: Encoder, value: FirmwareMaturity) {
val encoded = value.name.lowercase()
encoder.encodeString(encoded)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.st.blue_sdk.board_catalog.db.converters.Board_compatibilityDataConver
import com.st.blue_sdk.board_catalog.db.converters.CloudAppDataConverter
import com.st.blue_sdk.board_catalog.db.converters.CompatibleSensorAdapterDataConverter
import com.st.blue_sdk.board_catalog.db.converters.ComponentsDataConverter
import com.st.blue_sdk.board_catalog.db.converters.DemoDecoratorDataConverter
import com.st.blue_sdk.board_catalog.db.converters.FotaDetailsConverter
import com.st.blue_sdk.board_catalog.db.converters.OptionByteDataConverter
import com.st.blue_sdk.board_catalog.db.converters.PowerModeDataConverter
Expand All @@ -24,7 +25,7 @@ import com.st.blue_sdk.board_catalog.models.BoardFirmware
import com.st.blue_sdk.board_catalog.models.Sensor

@Database(
version = 10,
version = 15,
exportSchema = true,
entities = [
BoardFirmware::class,
Expand All @@ -41,7 +42,8 @@ import com.st.blue_sdk.board_catalog.models.Sensor
CompatibleSensorAdapterDataConverter::class,
PowerModeDataConverter::class,
Board_compatibilityDataConverter::class,
SensorConfigurationConverter::class
SensorConfigurationConverter::class,
DemoDecoratorDataConverter::class
)
abstract class BoardCatalogDB : RoomDatabase() {
abstract fun boardCatalogDao(): BoardCatalogDao
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.st.blue_sdk.board_catalog.db.converters

import androidx.room.TypeConverter
import com.st.blue_sdk.board_catalog.models.DemoDecorator
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

class DemoDecoratorDataConverter {
@TypeConverter
fun fromDemoDecorator(value: DemoDecorator): String {
return Json.encodeToString(value)
}

@TypeConverter
fun toDemoDecorator(value: String): DemoDecorator {
return Json.decodeFromString(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ data class BoardDescription(
@ColumnInfo(name = "brd_variant")
@SerialName(value = "brd_variant")
val boardVariant: String?=null,
@ColumnInfo(name = "components")
@SerialName(value = "components")
val components: List<String>?=null,
@ColumnInfo(name = "friendly_name")
@SerialName(value = "friendly_name")
val friendlyName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
* the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*/
@file:UseSerializers(FirmwareMaturityTypeSerializer::class)

package com.st.blue_sdk.board_catalog.models

import com.st.blue_sdk.board_catalog.api.serializers.FirmwareMaturityTypeSerializer
import kotlinx.serialization.UseSerializers

import androidx.room.ColumnInfo
import androidx.room.Entity
import com.st.blue_sdk.models.Boards
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable


@Entity(
primaryKeys = ["ble_dev_id", "ble_fw_id"],
tableName = "board_firmware"
Expand All @@ -38,9 +43,6 @@ data class BoardFirmware(
@ColumnInfo(name = "dtmi")
@SerialName("dtmi")
val dtmi: String? = null,
@ColumnInfo(name = "flow_enable")
@SerialName("flow_enable")
val flowEnable: Int? = null,
@ColumnInfo(name = "cloud_apps")
@SerialName(value = "cloud_apps")
val cloudApps: List<CloudApp>,
Expand All @@ -61,7 +63,11 @@ data class BoardFirmware(
var fota: FotaDetails,
@ColumnInfo(name = "compatible_sensor_adapters")
@SerialName("compatible_sensor_adapters")
var compatibleSensorAdapters: List<Int>?=null
var compatibleSensorAdapters: List<Int>?=null,
@SerialName("demo_decorator")
var demoDecorator: DemoDecorator?=null,
@SerialName("maturity")
var maturity: FirmwareMaturity?=null
) {

fun friendlyName(): String =
Expand All @@ -82,7 +88,8 @@ data class BoardFirmware(
characteristics = emptyList(),
optionBytes = emptyList(),
fwDesc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tempor posuere enim, et imperdiet quam mattis at.",
fota = FotaDetails()
fota = FotaDetails(),
maturity = FirmwareMaturity.RELEASE
)
}

Expand All @@ -96,4 +103,22 @@ data class BoardFirmware(
return true
}

override fun hashCode(): Int {
var result = bleDevId.hashCode()
result = 31 * result + bleFwId.hashCode()
result = 31 * result + brdName.hashCode()
result = 31 * result + fwVersion.hashCode()
result = 31 * result + fwName.hashCode()
result = 31 * result + (dtmi?.hashCode() ?: 0)
result = 31 * result + cloudApps.hashCode()
result = 31 * result + characteristics.hashCode()
result = 31 * result + optionBytes.hashCode()
result = 31 * result + fwDesc.hashCode()
result = 31 * result + (changelog?.hashCode() ?: 0)
result = 31 * result + fota.hashCode()
result = 31 * result + (compatibleSensorAdapters?.hashCode() ?: 0)
result = 31 * result + (demoDecorator?.hashCode() ?: 0)
result = 31 * result + (maturity?.hashCode() ?: 0)
return result
}
}
Loading

0 comments on commit e163d75

Please sign in to comment.