The Nebula Device 3: Net::DebugPacket Class Reference

The Nebula Device 3

Net::DebugPacket Class Reference

#include <debugpacket.h>


Detailed Description

Encapsulates a data packet for debug communication. Currently this class is only used on the Wii to communicate on the host PC, with the Wii specific classes hidden away in the Wii port of N3. DebugPacket is "public" because it's also used in Win32 proxy tools.

Every packet consists of a 4-byte header, and 1020 bytes of playload data, so that each packet is exactly 1 KByte long.

A packet looks like this:

uint magic; // FourCC('DPKT') uint count; // message counter ushort port; // port number ushort payloadSize; // 0xFFFF if packet is full and more data follows, else size of data in packet ubyte payload[PacketSize - HeaderSize)

The payloadSize must be interpreted like this:

0xFFFF: full payload of data, current message is continued in next package else: payloadSize is number of bytes in packet, current message is complete

IMPORTANT NOTE:

The DebugPacket does not allocate any external memory, and thus can be safely used from Wii interrupt handlers.

(C) 2009 Radon Labs GmbH

Public Types

enum  Command
 packet commands

Public Member Functions

 DebugPacket ()
 constructor
virtual ~DebugPacket ()
 destructor
SizeT Write (ushort portNum, uint packetCounter, const ubyte *buf, SizeT numBytes)
 write data to packet, returns number of bytes written, all data must be written in a single call!
void WriteRaw (const void *buf, SizeT bufSize)
 write raw data to packet (must have valid packet header, size of src buffer must be PacketSize!
void SetDataValid (bool b)
 set the "has data" flag on the packet
bool HasData () const
 return true if the packet contains data
Util::FourCC GetMagic () const
 get magic code at start of header
uint GetCount () const
 get message counter
ushort GetPort () const
 get the port number of the packet
bool IsFinalPacket () const
 return true if this is the last packet of a message
SizeT GetPayloadSize () const
 get actual payload size
const ubyte * GetPayload () const
 get pointer to payload
const ubyte * GetRawBuffer () const
 get pointer to raw packet buffer (contains header + payload)

Static Public Member Functions

static Util::Array< DebugPacketEncodeStream (ushort portNum, uint firstPacketCounter, const Ptr< IO::Stream > &stream)
 encode stream into a series of packets
static void DecodePackets (const Util::Array< DebugPacket > &packets, const Ptr< IO::Stream > &stream, ushort &outPortNum)
 decode a series of packets into a stream

Static Public Attributes

static const SizeT PacketSize = 512
 packet size
static const SizeT HeaderSize = 12
 header size
static const SizeT MaxPayloadSize = PacketSize - HeaderSize
 max payload size

Member Function Documentation

SizeT Net::DebugPacket::Write ( ushort  portNum,
uint  packetCount,
const ubyte *  buf,
SizeT  numBytes 
)

write data to packet, returns number of bytes written, all data must be written in a single call!

Write data to the packet. Returns the number of data written. If all data could be written, the returned number is identical with the requested size, and the packet's payload size will be set to that size. This means the packet completes a message. If not all data could be written, the actually written size (MaxPayloadSize) will be returned, and the internal payloadSize will be set to 0xFFFF, meaning that the packet contains incomplete data which will be continued with the next packet.

void Net::DebugPacket::WriteRaw ( const void *  buf,
SizeT  bufSize 
)

write raw data to packet (must have valid packet header, size of src buffer must be PacketSize!

Write raw data to the packet. The source buffer must contain a valid packet header and the size of the source data must equal DebugPacket::PacketSize!

FourCC Net::DebugPacket::GetMagic (  )  const

get magic code at start of header

Get the magic code at the beginning of the message. Must be FourCC('DPKT').

uint Net::DebugPacket::GetCount (  )  const

get message counter

Get the packet counter of this packet.

ushort Net::DebugPacket::GetPort (  )  const

get the port number of the packet

Get the port number from the packet.

bool Net::DebugPacket::IsFinalPacket (  )  const

return true if this is the last packet of a message

Return true if this is the final packet in a multi-packet message.

SizeT Net::DebugPacket::GetPayloadSize (  )  const

get actual payload size

Returns the number of payload data bytes in the packet. This will always return a valid number, even if the payloadSize header member is set to the special 0xFFFF code.

const ubyte * Net::DebugPacket::GetPayload (  )  const

get pointer to payload

Get a pointer to the actual payload data.

const ubyte * Net::DebugPacket::GetRawBuffer (  )  const

get pointer to raw packet buffer (contains header + payload)

Get a pointer to the raw packet data.