Nebula
Loading...
Searching...
No Matches
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.

Public Types

enum  Command { PC2WiiCmd , Wii2PCCmd , PC2WiiAck , Wii2PCAck }
 packet commands More...
 

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 ubyteGetPayload () const
 get pointer to payload
 
const ubyteGetRawBuffer () 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
 

Private Attributes

ubyte buffer [PacketSize]
 
bool hasData
 

Member Enumeration Documentation

◆ Command

packet commands

Enumerator
PC2WiiCmd 
Wii2PCCmd 
PC2WiiAck 
Wii2PCAck 

Constructor & Destructor Documentation

◆ DebugPacket()

Net::DebugPacket::DebugPacket ( )

constructor

◆ ~DebugPacket()

Net::DebugPacket::~DebugPacket ( )
virtual

destructor

Member Function Documentation

◆ DecodePackets()

void Net::DebugPacket::DecodePackets ( const Util::Array< DebugPacket > & packets,
const Ptr< IO::Stream > & stream,
ushort & outPortNum )
static

decode a series of packets into a stream

◆ EncodeStream()

Array< DebugPacket > Net::DebugPacket::EncodeStream ( ushort portNum,
uint firstPacketCounter,
const Ptr< IO::Stream > & stream )
static

encode stream into a series of packets

◆ GetCount()

uint Net::DebugPacket::GetCount ( ) const

get message counter

Get the packet counter of this packet.

◆ GetMagic()

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').

◆ GetPayload()

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

get pointer to payload

Get a pointer to the actual payload data.

◆ GetPayloadSize()

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.

◆ GetPort()

ushort Net::DebugPacket::GetPort ( ) const

get the port number of the packet

Get the port number from the packet.

◆ GetRawBuffer()

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

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

Get a pointer to the raw packet data.

◆ HasData()

bool Net::DebugPacket::HasData ( ) const
inline

return true if the packet contains data

◆ IsFinalPacket()

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.

◆ SetDataValid()

void Net::DebugPacket::SetDataValid ( bool b)
inline

set the "has data" flag on the packet

◆ Write()

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.

◆ WriteRaw()

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!

Member Data Documentation

◆ buffer

ubyte Net::DebugPacket::buffer[PacketSize]
private

◆ hasData

bool Net::DebugPacket::hasData
private

◆ HeaderSize

const SizeT Net::DebugPacket::HeaderSize = 12
static

header size

◆ MaxPayloadSize

const SizeT Net::DebugPacket::MaxPayloadSize = PacketSize - HeaderSize
static

max payload size

◆ PacketSize

const SizeT Net::DebugPacket::PacketSize = 512
static

packet size


The documentation for this class was generated from the following files: