message status updates are coded but not yet tested.

This commit is contained in:
geeksville 2020-05-30 19:58:36 -07:00
parent b2d8b30d5b
commit 7506d712ff
9 changed files with 157 additions and 130 deletions

View file

@ -24,11 +24,33 @@ data class DataPacket(
val bytes: ByteArray?,
val dataType: Int, // A value such as MeshProtos.Data.Type.OPAQUE_VALUE
var from: String? = ID_LOCAL, // a nodeID string, or ID_LOCAL for localhost
var rxTime: Long = System.currentTimeMillis(), // msecs since 1970
var time: Long = System.currentTimeMillis(), // msecs since 1970
var id: Int = 0, // 0 means unassigned
var status: MessageStatus? = MessageStatus.UNKNOWN
) : Parcelable {
/**
* If there was an error with this message, this string describes what was wrong.
*/
var errorMessage: String? = null
/**
* Syntactic sugar to make it easy to create text messages
*/
constructor(to: String? = ID_BROADCAST, text: String) : this(
to, text.toByteArray(utf8),
MeshProtos.Data.Type.CLEAR_TEXT_VALUE
)
/**
* If this is a text message, return the string, otherwise null
*/
val text: String?
get() = if (dataType == MeshProtos.Data.Type.CLEAR_TEXT_VALUE)
bytes?.toString(utf8)
else
null
// Autogenerated comparision, because we have a byte array
constructor(parcel: Parcel) : this(
@ -50,7 +72,7 @@ data class DataPacket(
if (from != other.from) return false
if (to != other.to) return false
if (rxTime != other.rxTime) return false
if (time != other.time) return false
if (id != other.id) return false
if (dataType != other.dataType) return false
if (!bytes!!.contentEquals(other.bytes!!)) return false
@ -62,7 +84,7 @@ data class DataPacket(
override fun hashCode(): Int {
var result = from.hashCode()
result = 31 * result + to.hashCode()
result = 31 * result + rxTime.hashCode()
result = 31 * result + time.hashCode()
result = 31 * result + id
result = 31 * result + dataType
result = 31 * result + bytes!!.contentHashCode()
@ -75,7 +97,7 @@ data class DataPacket(
parcel.writeByteArray(bytes)
parcel.writeInt(dataType)
parcel.writeString(from)
parcel.writeLong(rxTime)
parcel.writeLong(time)
parcel.writeInt(id)
parcel.writeParcelable(status, flags)
}
@ -90,7 +112,7 @@ data class DataPacket(
parcel.createByteArray()
parcel.readInt()
from = parcel.readString()
rxTime = parcel.readLong()
time = parcel.readLong()
id = parcel.readInt()
status = parcel.readParcelable(MessageStatus::class.java.classLoader)
}