Source code: com/synchrona/jred/irlap/IrLAPStateNDM.java
1 /*
2 **************************************************************************
3 ** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/irlap/IrLAPStateNDM.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.irlap;
19
20 import com.synchrona.util.Utilities;
21
22 /**
23 * Implement IrLAP's Normal Disconnected Mode.
24 */
25 class IrLAPStateNDM extends IrLAPState {
26 //--------------------------------------------------------------------
27 // Implement Singleton pattern
28 //--------------------------------------------------------------------
29
30 private static IrLAPState s_instance = new IrLAPStateNDM();
31
32 public static IrLAPState getInstance() {
33 return s_instance;
34 }
35
36 private IrLAPStateNDM() {
37 super();
38 }
39
40 //--------------------------------------------------------------------
41 // (Re)Implementation of IrLAPState
42 //--------------------------------------------------------------------
43
44 public void connectionRequest(IrLAPContext context, int nDestination) throws Exception {
45 if ( !context.isMediaBusy() ) {
46 context.nextState(IrLAPStateSetup.getInstance());
47 byte yConnection = context.generateConnectionAddress();
48 context.sendSNRM(nDestination, yConnection);
49 context.startFTimer();
50 context.zeroRetryCount();
51 }
52 }
53
54 /**
55 * Begin active discovery of other IrDA devices. Active discovery is
56 * not implemented in this version of J<font color="#ff0000">Red</font>.
57 */
58 public void discoveryRequest(IrLAPContext context) throws Exception {
59 logIfEnabled("discoveryRequest is not implemented yet.");
60 }
61
62 public void handleSNRM(IrLAPContext context, int nSource, int nDestination, byte yConnection, byte [] ayParameters) throws Exception {
63 logIfEnabled("handleSNRM: " + Utilities.bytesToString(ayParameters, 0, ayParameters.length));
64 context.nextState(IrLAPStateConnect.getInstance());
65 context.waitMinimumTurnaroundTime();
66 context.connectIndication(nSource, yConnection, ayParameters);
67 }
68
69 public void handleXID(IrLAPContext context, int nSource, int nDestination, byte ySlot, boolean bCommand, byte [] ayHints) throws Exception {
70 if ( bCommand ) {
71 context.generateResponseSlot((byte) 6, ySlot);
72 if ( context.getResponseSlot() == ySlot ) {
73 context.sendDiscoveryResponse(nSource);
74 context.setFrameSent(true);
75 context.startQueryTimer();
76 }
77 context.nextState(IrLAPStateReply.getInstance());
78 }
79 }
80
81 //--------------------------------------------------------------------
82 // End of implementation of IrLAPState
83 //--------------------------------------------------------------------
84 }