Package lejos.remote.rcx
Class PacketHandler
- java.lang.Object
-
- lejos.remote.rcx.PacketHandler
-
- Direct Known Subclasses:
LLCHandler,LLCReliableHandler
public abstract class PacketHandler extends java.lang.ObjectAbstract packet handler. Implementations must include sendPacket, receivePacket and isPacketAvailable(). The other methods are optional.
-
-
Field Summary
Fields Modifier and Type Field Description protected PacketHandlerlowerHandler
-
Constructor Summary
Constructors Constructor Description PacketHandler()PacketHandler(PacketHandler handler)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Close this packet handler and all lower layers.intgetError()Get the last error.booleanisAckAvailable()Check if an ack is availableabstract booleanisPacketAvailable()Check if a packet is availablevoidopen(byte source, byte destination)Set the source and destination for this connection.intreceiveAck(byte[] buffer)abstract intreceivePacket(byte[] buffer)Receive a packet.voidreset()Reset sequence numbers for this handlerabstract booleansendPacket(byte[] packet, int len)Send a packet.voidsetListen(boolean listen)Set or unset the listen flag to keep a PC serial tower alive
-
-
-
Field Detail
-
lowerHandler
protected PacketHandler lowerHandler
-
-
Constructor Detail
-
PacketHandler
public PacketHandler()
-
PacketHandler
public PacketHandler(PacketHandler handler)
-
-
Method Detail
-
open
public void open(byte source, byte destination)Set the source and destination for this connection.
-
reset
public void reset()
Reset sequence numbers for this handler
-
setListen
public void setListen(boolean listen)
Set or unset the listen flag to keep a PC serial tower alive- Parameters:
listen- true to set listen mode, else false
-
sendPacket
public abstract boolean sendPacket(byte[] packet, int len)Send a packet.- Parameters:
packet- the bytes to sendlen- the number of bytes to send- Returns:
- true if the send was successful, else false
-
receivePacket
public abstract int receivePacket(byte[] buffer)
Receive a packet.- Parameters:
buffer- the buffer to receive the packet into- Returns:
- the number of bytes received
-
receiveAck
public int receiveAck(byte[] buffer)
-
isPacketAvailable
public abstract boolean isPacketAvailable()
Check if a packet is available- Returns:
- true if a Packet is available, else false
-
isAckAvailable
public boolean isAckAvailable()
Check if an ack is available- Returns:
- true if a ack is available, else false
-
close
public void close()
Close this packet handler and all lower layers.
-
getError
public int getError()
Get the last error.- Returns:
- the error number, or zero for success
-
-