📄 tinytp.java
字号:
/*
**************************************************************************
** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/TinyTP.java,v 1.2 2000/07/29 20:29:29 mpatters Exp $
**
** Copyright (C) 2000 Synchrona, Inc. All rights reserved.
**
** This file is part of JRed, a 100% Java implementation of the IrDA
** infrared communications protocols.
**
** This file may be distributed under the terms of the Synchrona Public
** License as defined by Synchrona, Inc. and appearing in the file
** LICENSE included in the packaging of this file. The Synchrona Public
** License is based on the Q Public License as defined by Troll Tech AS
** of Norway; it differs only in its use of the courts of Florida, USA
** rather than those of Oslo, Norway.
**************************************************************************
*/
package com.synchrona.jred;
import com.synchrona.util.Log;
import com.synchrona.util.Utilities;
import java.io.PrintWriter;
/**
***
**/
public class TinyTP implements iIrLMPService {
public final static int PDU_HAS_PARAMETERS = 0x00000080;
public final static int PDU_HAS_NO_PARAMETERS = 0x00000000;
public final static int PDU_INITIAL_CREDIT = 0x0000007F;
private IrLMP m_irlmp;
private Log m_log;
private IrOBEX m_obex;
private byte m_yDestination;
private byte m_ySource;
public TinyTP(Log log, IrLMP irlmp, IrOBEX obex) {
m_irlmp = irlmp;
m_log = log;
m_obex = obex;
}
public IrLMP getIrLMP() {
return m_irlmp;
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Implement IrLMPService
//-------------------------------------------------------------------
public void clientConfirmsConnection(Client client) {
m_log.debug("TinyTP", "clientConfirmsConnection: " + client);
}
public void clientConfirmsDisconnect(Client client) {
m_log.debug("TinyTP", "clientConfirmsDisconnect: " + client);
}
public void clientDiscovered(Client client) {
m_log.debug("TinyTP", "clientDiscovered: " + client);
}
public void confirmConnectionRequest(Client client) {
boolean okayToConnect = false;
byte [] myServiceData = new byte[1];
m_log.debug("TinyTP", "respondToConnectionRequest: " + client);
byte [] serviceData = client.getServiceData();
if ( null == serviceData ) {
m_log.debug("TinyTP", "User data was null, TinyTP expects to see at least one byte.");
} else {
int hasParameters = (serviceData[0] & PDU_HAS_PARAMETERS);
if ( hasParameters != 0 ) {
m_log.error("TinyTP", "Parameter-Carrying Connect TTP-PDU's are not implemented yet.");
} else {
// It's our responsibility to give away Tx credits -- give away
// 127, the maximum. Also this user data means no support for
// SAR.
myServiceData[0]= (byte) (PDU_HAS_NO_PARAMETERS | PDU_INITIAL_CREDIT);
okayToConnect = true;
}
}
if ( okayToConnect ) {
client.confirmConnectionRequest(myServiceData);
} else {
client.denyConnectionRequest();
}
}
public void clientRequestsDisconnect(Client client) {
client.confirmDisconnectRequest();
}
public void clientSendsData(Client client, byte [] data, int offset, int length) {
}
//-------------------------------------------------------------------
// Implement iIrLMPService
//-------------------------------------------------------------------
public void connectRequest(IrLMP irlmp, byte yDestinationLSAP, byte ySourceLSAP, byte [] ayUserData) {
m_log.debug("TinyTP", "(connectRequest) " + Utilities.bytesToString(ayUserData));
if ( null == ayUserData ) {
m_log.debug("TinyTP", "User data was null, TinyTP expects to see at least one byte.");
} else {
// Mask off the high bit of the user data to see if this client
// expects to set TinyTP parameters. We don't support them.
int nP = (ayUserData[0] & 0x80);
if ( nP != 0 ) {
m_log.debug("TinyTP", "Parameter-Carrying Connect TTP-PDU's are not implemented yet.");
}
// Mask off the lower 7 bits to get our initial transmit credits.
int nInitialCredit = (ayUserData[0] & 0x7F);
m_log.debug("TinyTP", "nInitialCredit: " + nInitialCredit);
// It's our responsibility to give away Tx credits -- give away
// 127, the maximum. Also this user data means no support for
// SAR.
byte [] ayMyUserData = new byte[1];
ayMyUserData[0] = (byte) 0x7F;
irlmp.connectConfirm(ySourceLSAP, yDestinationLSAP, ayMyUserData);
}
}
public void dataRequest(byte [] ayData, int nOffset, int nLength) {
m_log.debug("TinyTP", "(dataRequest)");
byte [] ayRequest = new byte[nLength + 1];
ayRequest[0] = 0x7F;
for (int i = 0; i < nLength; i++) {
ayRequest[i + 1] = ayData[nOffset + i];
}
try {
m_irlmp.sendData(m_ySource, m_yDestination, ayRequest, 0, ayRequest.length);
} catch ( Exception e ) {
m_log.error("TinyTP", e.toString());
}
}
public void serviceRequest(IrLMP irlmp, IrLMPConnection conn, byte [] ayRequest, int nOffset, int nLength) throws Exception {
m_log.debug("TinyTP", "(serviceRequest) " + Utilities.bytesToString(ayRequest, nOffset, nLength));
m_irlmp = irlmp;
m_yDestination = (byte) (ayRequest[nOffset] & 0x7F);
m_ySource = (byte) (ayRequest[nOffset + 1] & 0x7F);
m_obex.serviceRequest(this, conn, ayRequest, nOffset + 3, nLength - 3);
}
public void setLog(PrintWriter log) {
}
public void setLogging(boolean bDoLogging) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -