Module pyinsim :: Class Packet
[hide private]
[frames] | no frames]

Class Packet

source code

UserDict.UserDict --+
                    |
                   Packet

Class to handle an InSim packet. This is a generic Packet handling class which handles all packets, except for ISP_MCI and ISP_NLP, which are handled by _CarTrackPacket.

A Packet is a Python dictionary, and the packet attributes are set and accessed by using the dictionary keys.

Instance Methods [hide private]
 
__init__(self, packetType=None, data=None, insim=None, **values)
Init the packet.
source code
 
insim(self)
Get a refernece to the InSim object which created the packet.
source code
 
__createPacket(self, packetType, values)
Create new packet.
source code
 
__decodePacket(self, data, values)
Decode packet from binary formatted string.
source code
 
pack(self)
Pack the current packet values into a binary string, which can then be sent to InSim.
source code

Inherited from UserDict.UserDict: __cmp__, __contains__, __delitem__, __getitem__, __len__, __repr__, __setitem__, clear, copy, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Class Methods [hide private]

Inherited from UserDict.UserDict: fromkeys

Method Details [hide private]

__init__(self, packetType=None, data=None, insim=None, **values)
(Constructor)

source code 

Init the packet.

To create a new Packet to send to InSim, set the packetType. For packets being received from InSim, set the data.

Example (sending):
mst = pyinsim.Packet(pyinsim.ISP_MST, Msg='Hello, world!')
Example (receiving):
packet = pyinsim.Packet(data=receivedData)
Args:
packetType - The type of packet to create. data - A binary string containing packet data to unpack. values - Default data to initailise the packet with.
Overrides: UserDict.UserDict.__init__

insim(self)

source code 

Get a refernece to the InSim object which created the packet.

Returns:
The InSim object.

pack(self)

source code 

Pack the current packet values into a binary string, which can then be sent to InSim.

Returns:
A binary formatted string.