NAME

UAV::Pilot::Wumpus::Packet

DESCRIPTION

Role for Wumpus packets. This is a custom protocol, documented below.

Do not create Packets directly. Instead, use UAV::Pilot::Wumpus::PacketFactory.

Does the UAV::Pilot::Logger role.

METHODS

write

write( $fh )

Writes the packet to the given filehandle.

make_checksum_clean

Recalculates the checksum based on current field values.

make_byte_vector

Returns the packet fields in a single scalar full of bytes.

get_ordered_payload_vales

Returns the packet field values in the order they appear in payload_fields().

get_ordered_payload_value_bytes

Returns a byte array of all the packet fields in the order they appear in payload_fields().

make_packet_queue_map_key

Creates a unique key for this packet.

ATTRIBUTES

preamble

Fixed bytes that start every packet

version

Protocol version

packet_count

The count of this packet in the stream.

checksum

Checksum value

REQUIRED METHODS/ATTRIBUTES

message_id

ID for this type of message

payload_fields

Arrayref. A list of field names in the order they appear in the packet.

payload_length

Hashref. Keys match to an entry in payload_fields. Values are the length in bytes of that field.

PROTOCOL

Each data packet starts with a 16-bit magic number (0xBF24), which is followed by:

  • 1 byte - Version (this document is version 0x01)

  • 4 bytes - Packet count

  • 1 byte - Message ID

  • 4 bytes - Length of payload

  • 2 bytes - Checksum of payload

  • n bytes - Payload

The Message IDs are documented below. The checksum field is calculated by taking the bytes of the fields for version, message ID, length, and payload, and running Fletcher16 on them.

A session starts by the client sending a StartupRequest to the server. On getting a Startup response, the client should then send a RadioMinMax, followed by RadioOutput messages. During this time, the server can be sending Status and VideoStream messages. Either side may also send a AckRequest at any time, with the receiving end replying with Ack in a timely fashion.

The Packet Count is incremented for each packet sent by the given side. Packets with a count lower than the highest count seen during this session should be discarded.

Message IDs

0x00 Ack

Length 2. The response to an AckRequest. Contains:

2 bytes - The checksum of the AckRequest being responded to.

0x01 AckRequest

Length 4. Requests that the reciever send an Ack in response. Contains:

4 bytes - Random data. This just gives something for the checksum to use.

0x02 RadioMinMax

Length 64. Sends the min/max values that will be sent by each channel. Contains:

  • 2 bytes - ch1 min

  • 2 bytes - ch2 min

...

  • 2 bytes - ch16 min

  • 2 bytes - ch1 max

...

  • 2 bytes - ch16 max

0x03 RadioOutputs

Length 32. Sends the current outputs for each channel. Contains:

  • 2 bytes - ch1 out

  • 2 bytes - ch2 out

...

  • 2 bytes - ch16 out

0x04 Startup

Length 1. A response to a StartupRequest of the startup going well or not. Contains:

1 byte - 0 = BAD, 1 = OK

0x05 StartupRequest

Length 0. Requests the server startup.

0x06 VideoStream

Length 9 + n. A frame of video data. Contains:

  • 1 byte - Codec ID. 0 = NULL, 1 = h.264, 2 = JPEG, other values reserved

  • 2 bytes - Width

  • 2 bytes - Height

  • 4 bytes - Adler32 checksum of video data

  • n bytes - Video data

0x07 Status

Length 4. Gives the current status. Contains:

  • 1 byte - Flags (see below)

  • 1 byte - Battery level

  • 2 bytes - Shield level

Each bit of the flags field is:

0 Took a hit since last Status
1 (Reserved)
2 (Reserved)
3 (Reserved)
4 (Reserved)
5 (Reserved)
6 (Reserved)
7 (Reserved)