Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/synchrona/jred/IrIAS.java


1   /*
2   **************************************************************************
3   ** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/IrIAS.java,v 1.1.1.1 2000/07/05 04:41:52 mpatters Exp $
4   **
5   ** Copyright (C) 2000 Synchrona, Inc. All rights reserved.
6   **
7   ** This file is part of JRed, a 100% Java implementation of the IrDA
8   ** infrared communications protocols.
9   **
10  ** This file may be distributed under the terms of the Synchrona Public
11  ** License as defined by Synchrona, Inc. and appearing in the file
12  ** LICENSE included in the packaging of this file. The Synchrona Public
13  ** License is based on the Q Public License as defined by Troll Tech AS
14  ** of Norway; it differs only in its use of the courts of Florida, USA
15  ** rather than those of Oslo, Norway.
16  **************************************************************************
17  */
18  package com.synchrona.jred;
19  
20  import java.io.PrintWriter;
21  
22  import com.synchrona.util.Log;
23  
24  public class IrIAS implements iIrLMPService {
25    private static final byte IRIAS_CLIENT          = (byte) 0x01;
26    private static final byte IRIAS_SERVER          = (byte) 0x00;
27    private static final byte MASK_COMMAND_BIT      = (byte) 0x80;
28    private static final int  LM_GET_VALUE_BY_CLASS = 0x04;
29  
30    private static IrIAS s_instance = new IrIAS();
31  
32    private boolean m_bDoLogging;
33    private Log     m_log;
34  
35    public void connectRequest(Test irlmp, byte yDestinationLSAP, byte ySourceLSAP, byte [] ayUserData) {
36      m_log.debug("IrIAS", "Connect-Request");
37  
38      // connect only to IrIAS clients
39      if ( IRIAS_CLIENT == ySourceLSAP ) {
40        irlmp.connectConfirm(ySourceLSAP, yDestinationLSAP, null);  
41      }
42    }
43  
44    /**
45     * Per IrLMP specification there is one and only one instance
46     * of IAS per LMP instance.
47     */
48    public static IrIAS getInstance() {
49      return s_instance;
50    }
51  
52    public void serviceRequest(Test irlmp, IrLMPConnection conn, byte [] ayRequest, int nOffset, int nLength) throws Exception {
53      boolean bLast   = (0 != (0x80 & ayRequest[2]));
54      boolean bAck    = (0 != (0x40 & ayRequest[2]));
55      int     nOpcode = (0x3F & ayRequest[2]);
56  
57      m_log.debug("IrIAS", "bLast:   " + bLast);
58      m_log.debug("IrIAS", "bAck:    " + bAck);
59      m_log.debug("IrIAS", "nOpcode: " + nOpcode);
60  
61      switch ( nOpcode ) {
62        case LM_GET_VALUE_BY_CLASS:
63  
64          int    nClassNameLength     = ayRequest[3];
65          int    nAttributeNameLength = ayRequest[nClassNameLength + 4];
66          m_log.debug("IrIAS", nClassNameLength + " " + nAttributeNameLength);
67          String strClass             = new String(ayRequest, 4, nClassNameLength);
68          String strAttribute         = new String(ayRequest, nClassNameLength + 5, nAttributeNameLength);
69          getValueByClass(irlmp, strClass, strAttribute);
70  
71        break;
72        default:
73          m_log.debug("IrIAS", "unknown value: " + nOpcode);
74        break;
75      }
76  
77  /*
78      try {
79        irlmp.sendData((byte) 0x81, (byte) 0x00, ayConfirmMsg, 0, nConfirmLength);
80      } catch ( Exception e ) {
81        System.err.println(e);
82        e.printStackTrace(System.err);
83      }
84  */
85    }
86  
87    public void setLog(Log log) {
88      m_log = log;
89    }
90  
91    public void setLog(PrintWriter log) {
92    }
93  
94    public void setLogging(boolean bDoLogging) {
95    }
96  
97    private IrIAS() {
98      m_bDoLogging = false;
99      m_log        = null;
100   }
101 
102   private void getValueByClass(Test irlmp, String strClass, String strAttribute) {
103     m_log.debug("IrIAS", "strClass:     " + strClass);
104     m_log.debug("IrIAS", "strAttribute: " + strAttribute);
105 
106     byte [] ayResult = new byte[255];
107     int     nLength  = 0;
108 
109     ayResult[nLength++] = (byte) 0x84; // last frame | opcode 4
110     ayResult[nLength++] = (byte) 0x00; // success
111 
112     ayResult[nLength++] = (byte) 0x00; // high byte of 16-bit sequence length
113     ayResult[nLength++] = (byte) 0x01; // high byte of 16-bit sequence length
114 
115     ayResult[nLength++] = (byte) 0x34; // high byte of 16-bit object ID
116     ayResult[nLength++] = (byte) 0x56; // low byte of 16-bit object ID
117 
118     ayResult[nLength++] = (byte) 0x01; // value type (1 = integer)
119     ayResult[nLength++] = (byte) 0x00; // MSB of value
120     ayResult[nLength++] = (byte) 0x00; // 
121     ayResult[nLength++] = (byte) 0x00; // 
122     ayResult[nLength++] = (byte) 0x05; // LSB -- TinyTP:LsapSel = 5 (fake for now)
123 
124     irlmp.sendData((byte) 0x01, (byte) 0x00, ayResult, 0, nLength);
125   }
126 }