org.jSyncManager.API.Protocol

Class CMP_DLP


public class CMP_DLP
extends java.lang.Object

CMP_DLP class. This class provides the black-box for handling CMP and DLP packets.

Field Summary

protected boolean
connected
The connection state.
protected CMPDLPTransferInterface
padpHandler
The underlying CMPDLPTransferInterface object to use for packet I/O.
protected int
speed
The speed to use for serial synchronization.

Constructor Summary

CMP_DLP()
Construct an instance of the CMP_DLP class with no parameters.
CMP_DLP(CMPDLPTransferInterface padp)
Construct an instance of the CMP_DLP class using the specified underlying CMPDLPTransferInterface protocol handler.

Method Summary

void
connect()
Attempt to listen for a connection to the remote CMP/DLP enabled device.
protected boolean
determinePacketType(GenericPacket genericpacket)
A method to determine the type of incoming packet.
void
disconnect()
A method to cause the protocol stack issue a disconnect request.
void
disconnect(char c)
A method to cause the protocol stack issue a disconnect request with the specified disconnect reason code.
DLP_Packet
getDLPPacket(DLP_Packet dlp_packet)
Retreives a DLP packet from the underlying protocol in the stack.
int
getSpeed()
Retreives the speed of the connection.
boolean
isConnected()
Returns the connection status of this protocol layer.
byte[]
readRawPacket()
Retreives a raw packet from the underlying protocol in the stack.
protected void
rxHandshake()
USB Receive Handshake.
void
setSpeed(int newValue)
Sets the speed that this protocol should attempt to use for serial synchronization sessions.
void
suspend()
Suspends the synchronization.
void
writeRawPacket(byte[] data, byte srcSocket, byte destSocket)
Write a raw packet to the underlying protocol in the stack.

Field Details

connected

protected boolean connected
The connection state. Set to true if the protocol stack is connected to the remote end, otherwise set to false.

padpHandler

protected CMPDLPTransferInterface padpHandler
The underlying CMPDLPTransferInterface object to use for packet I/O.

speed

protected int speed
The speed to use for serial synchronization. This field is ignored for non-serial synchronizations. The default is 9600bps.

Constructor Details

CMP_DLP

protected CMP_DLP()
Construct an instance of the CMP_DLP class with no parameters. This method is protected for use by subclasses.

CMP_DLP

public CMP_DLP(CMPDLPTransferInterface padp)
Construct an instance of the CMP_DLP class using the specified underlying CMPDLPTransferInterface protocol handler.
Parameters:
padp - the underlying CMPDLPTransferInterface protocol handler to use for I/O.

Method Details

connect

public void connect()
            throws NotConnectedException
Attempt to listen for a connection to the remote CMP/DLP enabled device. This method will block until a connection is initiated, so it's safe to call and wait until a connection occurs. Interactive applications should call this method in a seperate thread to allow the user to continue interacting with the application.
Throws:
NotConnectedException - thrown if the connection is lost during connection initialization.

determinePacketType

protected boolean determinePacketType(GenericPacket genericpacket)
A method to determine the type of incoming packet.
Returns:
true if this packet is a PADP packet, false otherwise.

disconnect

public void disconnect()
A method to cause the protocol stack issue a disconnect request. This method simply calls disconnect(char) with a disconnect reason code of 0.

disconnect

public void disconnect(char c)
A method to cause the protocol stack issue a disconnect request with the specified disconnect reason code.
Parameters:
c - the reason code for the disconnect.

getDLPPacket

public DLP_Packet getDLPPacket(DLP_Packet dlp_packet)
            throws NotConnectedException,
                   DLPError
Retreives a DLP packet from the underlying protocol in the stack. This method uses a request/response format, so in order to get a packet of data, you have to request the packet via a DLP Request packet.
Parameters:
dlp_packet - the packet containing the DLP request.
Returns:
the DLP_Packet containing the response from the remote end.
Throws:
NotConnectedException - thrown if the connection is lost during request/responce processing, or if this method was called prior to a connection being initialized via connect().
DLPError - if the request resulted in an error on the remote end, a DLPError is thrown.

getSpeed

public int getSpeed()
Retreives the speed of the connection. This value is only valid for serial based connections. Other connections will return the default speed value of 9600bps, and should be ignored.
Returns:
the speed of the serial connection.

isConnected

public boolean isConnected()
Returns the connection status of this protocol layer.
Returns:
true if we're connected to the remote device still, false otherwise.

readRawPacket

public byte[] readRawPacket()
            throws NotConnectedException
Retreives a raw packet from the underlying protocol in the stack.
Returns:
the GenericPacket containing the data from the remote end.
Throws:
NotConnectedException - thrown if the connection is lost during request/responce processing, or if this method was called prior to a connection being initialized via connect().

rxHandshake

protected void rxHandshake()
            throws PADP_PacketTooBigException,
                   NotConnectedException
USB Receive Handshake.

setSpeed

public void setSpeed(int newValue)
Sets the speed that this protocol should attempt to use for serial synchronization sessions. This method has no effect for non-serial synchronization.
Parameters:
newValue - the speed that the synchronization should be attempted at.

suspend

public void suspend()
            throws NotConnectedException
Suspends the synchronization. Calling this method closes down the current synchronization session, while leaving the protocol stack in tact so it can begin another synchronization session as soon as this method returns. This method will alsa attempt to suspend the protocol layer beneath it.
Throws:
NotConnectedException - thrown if the connection to the remote end is lost.

writeRawPacket

public void writeRawPacket(byte[] data,
                           byte srcSocket,
                           byte destSocket)
            throws NotConnectedException
Write a raw packet to the underlying protocol in the stack.
Parameters:
data - the byte array to be written to the handheld.
srcSocket - the source socket (usually 3).
destSocket - the destination socket (usually 3).
Throws:
NotConnectedException - thrown if the connection is lost during request/responce processing, or if this method was called prior to a connection being initialized via connect().