📄 irias.java
字号:
/*
**************************************************************************
** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/IrIAS.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 java.io.PrintWriter;
import com.synchrona.util.Log;
public class IrIAS implements iIrLMPService {
private static final byte IRIAS_CLIENT = (byte) 0x01;
private static final byte IRIAS_SERVER = (byte) 0x00;
private static final byte MASK_COMMAND_BIT = (byte) 0x80;
private static final int LM_GET_VALUE_BY_CLASS = 0x04;
private static IrIAS s_instance = new IrIAS();
private boolean m_bDoLogging;
private Log m_log;
public void connectRequest(IrLMP irlmp, byte yDestinationLSAP, byte ySourceLSAP, byte [] ayUserData) {
m_log.debug("IrIAS", "Connect-Request");
// connect only to IrIAS clients
if ( IRIAS_CLIENT == ySourceLSAP ) {
irlmp.connectConfirm(ySourceLSAP, yDestinationLSAP, null);
}
}
/**
* Per IrLMP specification there is one and only one instance
* of IAS per LMP instance.
*/
public static IrIAS getInstance() {
return s_instance;
}
public void serviceRequest(IrLMP irlmp, IrLMPConnection conn, byte [] ayRequest, int nOffset, int nLength) throws Exception {
boolean bLast = (0 != (0x80 & ayRequest[2]));
boolean bAck = (0 != (0x40 & ayRequest[2]));
int nOpcode = (0x3F & ayRequest[2]);
m_log.debug("IrIAS", "bLast: " + bLast);
m_log.debug("IrIAS", "bAck: " + bAck);
m_log.debug("IrIAS", "nOpcode: " + nOpcode);
switch ( nOpcode ) {
case LM_GET_VALUE_BY_CLASS:
int nClassNameLength = ayRequest[3];
int nAttributeNameLength = ayRequest[nClassNameLength + 4];
m_log.debug("IrIAS", nClassNameLength + " " + nAttributeNameLength);
String strClass = new String(ayRequest, 4, nClassNameLength);
String strAttribute = new String(ayRequest, nClassNameLength + 5, nAttributeNameLength);
getValueByClass(irlmp, strClass, strAttribute);
break;
default:
m_log.debug("IrIAS", "unknown value: " + nOpcode);
break;
}
/*
try {
irlmp.sendData((byte) 0x81, (byte) 0x00, ayConfirmMsg, 0, nConfirmLength);
} catch ( Exception e ) {
System.err.println(e);
e.printStackTrace(System.err);
}
*/
}
public void setLog(Log log) {
m_log = log;
}
public void setLog(PrintWriter log) {
}
public void setLogging(boolean bDoLogging) {
}
private IrIAS() {
m_bDoLogging = false;
m_log = null;
}
private void getValueByClass(IrLMP irlmp, String strClass, String strAttribute) {
m_log.debug("IrIAS", "strClass: " + strClass);
m_log.debug("IrIAS", "strAttribute: " + strAttribute);
if ( null == irlmp ) {
m_log.error("IrIAS", "IrLMP is null");
}
byte [] ayResult = new byte[255];
int nLength = 0;
ayResult[nLength++] = (byte) 0x84; // last frame | opcode 4
ayResult[nLength++] = (byte) 0x00; // success
ayResult[nLength++] = (byte) 0x00; // high byte of 16-bit sequence length
ayResult[nLength++] = (byte) 0x01; // high byte of 16-bit sequence length
ayResult[nLength++] = (byte) 0x34; // high byte of 16-bit object ID
ayResult[nLength++] = (byte) 0x56; // low byte of 16-bit object ID
ayResult[nLength++] = (byte) 0x01; // value type (1 = integer)
ayResult[nLength++] = (byte) 0x00; // MSB of value
ayResult[nLength++] = (byte) 0x00; //
ayResult[nLength++] = (byte) 0x00; //
ayResult[nLength++] = (byte) 0x05; // LSB -- TinyTP:LsapSel = 5 (fake for now)
try {
m_log.debug("IrIAS", "(sending) destination: " + IRIAS_CLIENT + " source: " + IRIAS_SERVER);
irlmp.sendData(IRIAS_CLIENT, IRIAS_SERVER, ayResult, 0, nLength);
} catch ( Exception e ) {
m_log.error("IrIAS", e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -