Add hopLimit to the DataPacket class, update MeshService to use hopLimit when building its MeshPackets

1.2-legacy
Paul Mandal 2021-02-27 22:28:59 -07:00
rodzic 1c7d1c7ea9
commit a6c80cc203
2 zmienionych plików z 14 dodań i 4 usunięć

Wyświetl plik

@ -26,7 +26,8 @@ data class DataPacket(
var from: String? = ID_LOCAL, // a nodeID string, or ID_LOCAL for localhost
var time: Long = System.currentTimeMillis(), // msecs since 1970
var id: Int = 0, // 0 means unassigned
var status: MessageStatus? = MessageStatus.UNKNOWN
var status: MessageStatus? = MessageStatus.UNKNOWN,
var hopLimit: Int = 0
) : Parcelable {
/**
@ -60,7 +61,8 @@ data class DataPacket(
parcel.readString(),
parcel.readLong(),
parcel.readInt(),
parcel.readParcelable(MessageStatus::class.java.classLoader)
parcel.readParcelable(MessageStatus::class.java.classLoader),
parcel.readInt()
) {
}
@ -77,6 +79,7 @@ data class DataPacket(
if (dataType != other.dataType) return false
if (!bytes!!.contentEquals(other.bytes!!)) return false
if (status != other.status) return false
if (hopLimit != other.hopLimit) return false
return true
}
@ -89,6 +92,7 @@ data class DataPacket(
result = 31 * result + dataType
result = 31 * result + bytes!!.contentHashCode()
result = 31 * result + status.hashCode()
result = 31 * result + hopLimit
return result
}
@ -100,6 +104,7 @@ data class DataPacket(
parcel.writeLong(time)
parcel.writeInt(id)
parcel.writeParcelable(status, flags)
parcel.writeInt(hopLimit)
}
override fun describeContents(): Int {
@ -115,6 +120,7 @@ data class DataPacket(
time = parcel.readLong()
id = parcel.readInt()
status = parcel.readParcelable(MessageStatus::class.java.classLoader)
hopLimit = parcel.readInt()
}
companion object CREATOR : Parcelable.Creator<DataPacket> {

Wyświetl plik

@ -540,10 +540,12 @@ class MeshService : Service(), Logging {
destId: String,
wantAck: Boolean = false,
id: Int = 0,
hopLimit: Int = 0,
initFn: MeshProtos.SubPacket.Builder.() -> Unit
): MeshPacket = newMeshPacketTo(destId).apply {
this.wantAck = wantAck
this.id = id
this.hopLimit = hopLimit
decoded = MeshProtos.SubPacket.newBuilder().also {
initFn(it)
}.build()
@ -564,6 +566,7 @@ class MeshService : Service(), Logging {
val bytes = data.payload.toByteArray()
val fromId = toNodeID(packet.from)
val toId = toNodeID(packet.to)
val hopLimit = packet.hopLimit
// If the rxTime was not set by the device (because device software was old), guess at a time
val rxTime = if (packet.rxTime == 0) packet.rxTime else currentSecond()
@ -584,7 +587,8 @@ class MeshService : Service(), Logging {
time = rxTime * 1000L,
id = packet.id,
dataType = data.portnumValue,
bytes = bytes
bytes = bytes,
hopLimit = hopLimit
)
}
}
@ -598,7 +602,7 @@ class MeshService : Service(), Logging {
}.build()
private fun toMeshPacket(p: DataPacket): MeshPacket {
return buildMeshPacket(p.to!!, id = p.id, wantAck = true) {
return buildMeshPacket(p.to!!, id = p.id, wantAck = true, hopLimit = p.hopLimit) {
data = makeData(p.dataType, ByteString.copyFrom(p.bytes))
}
}