feat: get queued packets from database

master
andrekir 2023-01-12 17:47:59 -03:00
rodzic 5a07998b73
commit d23584c283
3 zmienionych plików z 18 dodań i 12 usunięć

Wyświetl plik

@ -18,6 +18,10 @@ class PacketRepository @Inject constructor(private val packetDaoLazy: dagger.Laz
packetDao.getAllPackets()
}
suspend fun getQueuedPackets(): List<DataPacket>? = withContext(Dispatchers.IO) {
packetDao.getQueuedPackets()
}
suspend fun insert(packet: Packet) = withContext(Dispatchers.IO) {
packetDao.insert(packet)
}

Wyświetl plik

@ -48,11 +48,15 @@ interface PacketDao {
findDataPacket(data)?.let { update(it.copy(data = new)) }
}
@Query("Select data from packet")
@Query("Select data from packet order by received_time asc")
fun getDataPackets(): List<DataPacket>
@Transaction
fun getDataPacketById(requestId: Int): DataPacket? {
return getDataPackets().firstOrNull { it.id == requestId }
}
@Transaction
fun getQueuedPackets(): List<DataPacket>? =
getDataPackets().filter { it.status in setOf(MessageStatus.ENROUTE, MessageStatus.QUEUED) }
}

Wyświetl plik

@ -765,12 +765,6 @@ class MeshService : Service(), Logging {
}
}
/// If packets arrive before we have our node DB, we delay parsing them until the DB is ready
// private val earlyReceivedPackets = mutableListOf<MeshPacket>()
/// If apps try to send packets when our radio is sleeping, we queue them here instead
private val offlineSentPackets = mutableListOf<DataPacket>()
/// Update our model and resend as needed for a MeshPacket we just received from the radio
private fun handleReceivedMeshPacket(packet: MeshPacket) {
if (haveNodeDB) {
@ -792,12 +786,16 @@ class MeshService : Service(), Logging {
}
private fun processQueuedPackets() {
offlineSentPackets.forEach { p ->
// encapsulate our payload in the proper protobufs and fire it off
serviceScope.handledLaunch {
packetRepository.get().getQueuedPackets()?.forEach { p ->
try {
sendNow(p)
changeStatus(p, MessageStatus.ENROUTE)
} catch (ex: Exception) {
errormsg("Error sending queued message:", ex)
}
}
}
offlineSentPackets.clear()
}
/**