Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more compact bundle protocol #999

Merged
merged 7 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ enum class ServerFeatureFlags {
/** Server can parse bundle packets: `PACKET_BUNDLE` = 100 (0x64). */
PROTOCOL_BUNDLE_SUPPORT,

/** Server can parse bundle packets with compact headers and packed IMU rotation/acceleration frames:
- `PACKET_BUNDLE_COMPACT` = 101 (0x65),
- `PACKET_ROTATION_AND_ACCELERATION` = 23 (0x17). */
PROTOCOL_BUNDLE_COMPACT_SUPPORT,

// Add new flags here

BITS_TOTAL, ;

companion object {
val flagsEnabled: Set<ServerFeatureFlags> = setOf(
PROTOCOL_BUNDLE_SUPPORT,
PROTOCOL_BUNDLE_COMPACT_SUPPORT,

// Add enabled flags here
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ class UDPProtocolParser {
buf.position(bundlePacketStart + bundlePacketLen)
}
return bundlePackets.toTypedArray()
} else if (packetId == PACKET_BUNDLE_COMPACT) {
bundlePackets.clear()
while (buf.hasRemaining()) {
val bundlePacketLen = Math.min(buf.get().toUByte().toInt(), buf.remaining()) // 1 byte
if (bundlePacketLen == 0) continue

val bundlePacketStart = buf.position()
val bundleBuf = buf.slice()
bundleBuf.limit(bundlePacketLen)
val bundlePacketId = bundleBuf.get().toUByte().toInt() // 1 byte
val newPacket = getNewPacket(bundlePacketId)
newPacket?.let {
newPacket.readData(bundleBuf)
bundlePackets.add(newPacket)
}

buf.position(bundlePacketStart + bundlePacketLen)
}
return bundlePackets.toTypedArray()
}

val newPacket = getNewPacket(packetId)
Expand Down Expand Up @@ -129,6 +148,7 @@ class UDPProtocolParser {
const val PACKET_FEATURE_FLAGS = 22
const val PACKET_ROTATION_AND_ACCELERATION = 23
const val PACKET_BUNDLE = 100
const val PACKET_BUNDLE_COMPACT = 101
const val PACKET_PROTOCOL_CHANGE = 200
private val HANDSHAKE_BUFFER = ByteArray(64)
private val bundlePackets = ArrayList<UDPPacket>(128)
Expand Down