Meshtastic-Android/app/src/main/java/com/geeksville/mesh/database/MeshtasticDatabase.kt
Dayle Drinkwater 47b2ecc8aa
Hops Away implementation (#966)
* Initial Hops Away feature

* Generate our own hopsAway, comparing hopStart to hopLimit

* Remove import of hopsAway from device nodeInfo, as this only shows 0 when hopStart isn't included on packets (with this info, we can't differentiate between a node which is Hops Away but on old firmware, or nodes which are on new firmware but direct. Both are 0)

Check if hopStart is 0 but hopLimit is not 0, if true set hopsAway to -1.

Show nodes with hopsAway with -1 with a (!) appended to the RSSI details, to show this probably isn't true. (eg they are using old firmware)

Change the default of hopsAway to -1, until we know it is direct (0) or hops away (1+)

* tidy up: move from nested if else to when

* Revert Project_Default.xml

* Move hopsAway when block in to updateNodeInfo() block above it.

Move hopsAway var to end of NodeInfo Class.

Schema update due to change above.

* hopsAway now follows firmware implementation.
hopsAway now imported from radio (installNodeInfo)

* reformat

---------

Co-authored-by: andrekir <andrekir@pm.me>
2024-04-21 08:14:35 -03:00

54 lines
1.7 KiB
Kotlin

package com.geeksville.mesh.database
import android.content.Context
import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.geeksville.mesh.MyNodeInfo
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.database.dao.PacketDao
import com.geeksville.mesh.database.dao.MeshLogDao
import com.geeksville.mesh.database.dao.NodeInfoDao
import com.geeksville.mesh.database.dao.QuickChatActionDao
import com.geeksville.mesh.database.entity.MeshLog
import com.geeksville.mesh.database.entity.Packet
import com.geeksville.mesh.database.entity.QuickChatAction
@Database(
entities = [
MyNodeInfo::class,
NodeInfo::class,
Packet::class,
MeshLog::class,
QuickChatAction::class
],
autoMigrations = [
AutoMigration (from = 3, to = 4),
AutoMigration (from = 4, to = 5),
AutoMigration (from = 5, to = 6),
],
version = 6,
exportSchema = true,
)
@TypeConverters(Converters::class)
abstract class MeshtasticDatabase : RoomDatabase() {
abstract fun nodeInfoDao(): NodeInfoDao
abstract fun packetDao(): PacketDao
abstract fun meshLogDao(): MeshLogDao
abstract fun quickChatActionDao(): QuickChatActionDao
companion object {
fun getDatabase(context: Context): MeshtasticDatabase {
return Room.databaseBuilder(
context.applicationContext,
MeshtasticDatabase::class.java,
"meshtastic_database"
)
.fallbackToDestructiveMigration()
.build()
}
}
}