Package org.javabluetooth.stack.hci

Examples of org.javabluetooth.stack.hci.HCIException


        hciTransport = HCIDriver.getHCIDriver();
        try {
            serverSocket = new ServerSocket(port);
            this.start();
        }
        catch (IOException e) { throw new HCIException("HCIManagerRemoteServer: IOException: " + e); }
    }
View Full Code Here


            isConnected = true;
            Thread thisThread = new Thread(this);
            thisThread.start();
        }
        catch (UnknownHostException e) {
            throw new HCIException("HCIManagerRemoteClient: Unknown Host " + remoteAddress + ":" + remotePort + ". " + e);
        }
        catch (IOException e) { throw new HCIException("HCIManagerRemoteClient: IOException: " + e); }
    }
View Full Code Here

            socketOut.write(cmdPacket);
            socketOut.flush();
        }
        catch (IOException e) {
            cleanExit();
            throw new HCIException("IOException: " + e);
        }
        int timer = 0;
        while (commandResponse == null) {
            try {
                Thread.sleep(500);
                timer++;
                if (timer == 100) { throw new HCIException("Command Packet Response Timed Out. "); }
            }
            catch (InterruptedException e) { }
        }
        byte[] result = commandResponse;
        commandResponseOpCode = 0;
View Full Code Here

    /**
     * @see org.javabluetooth.stack.BluetoothStack#connectL2CAPChannel(org.javabluetooth.stack.l2cap.L2CAPChannel,
     * javax.bluetooth.RemoteDevice, short)
     */
    public void connectL2CAPChannel(L2CAPChannel channel, RemoteDevice remoteDevice, short psm) throws HCIException {
        if (!isConnected) throw new HCIException("BluetoothTCPClient is not connected.");
        short channelHandle = -1;
        for (int i = 0; i < channels.length; i++) {
            if (channels[i] == null) {
                channels[i] = channel;
                channel.l2capSender = this;
                channel.remoteAddress = remoteDevice.bdAddrLong;
                channelHandle = (short)i;
                break;
            }
        }
        if (channelHandle == -1) throw new HCIException("Connect L2CAPChannel failed. No Open Channel Slots.");
        byte[] createL2CAPChannelRequest = {
            L2CAP_CREATE_CONNECTION_REQUEST, 0x0e, 0x00, //fixed length 14
            (byte)((channelHandle) & 0xff), (byte)((channelHandle >> 8) & 0xff), (byte)((psm) & 0xff), (byte)((psm >> 8) & 0xff),
                (byte)((remoteDevice.bdAddrLong) & 0xff), (byte)((remoteDevice.bdAddrLong >> 8) & 0xff),
                (byte)((remoteDevice.bdAddrLong >> 16) & 0xff), (byte)((remoteDevice.bdAddrLong >> 24) & 0xff),
                (byte)((remoteDevice.bdAddrLong >> 32) & 0xff), (byte)((remoteDevice.bdAddrLong >> 40) & 0xff),
                remoteDevice.pageScanRepMode, remoteDevice.pageScanMode, (byte)((remoteDevice.clockOffset) & 0xff),
                (byte)((remoteDevice.clockOffset >> 8) & 0xff)
        };
        try {
            Debug.println(6, "BluetoothTCPClient: Sending L2CAP Create Connection Request:", createL2CAPChannelRequest);
            socketOut.write(createL2CAPChannelRequest);
            socketOut.flush();
        }
        catch (IOException e) {
            cleanExit();
            throw new HCIException("IOException: " + e);
        }
        int timeout = 0;
        while (channel.channelState == L2CAPChannel.CLOSED) {
            try {
                Thread.sleep(1000);
                timeout++;
            }
            catch (InterruptedException e) { }
            if (timeout == 100) throw new HCIException("Connect L2CAPChannel timed out.");
        }
        if (channel.channelState == L2CAPChannel.FAILED) throw new HCIException("Connect L2CAPChannel failed.");
    }
View Full Code Here

     * @see org.javabluetooth.stack.BluetoothStack#openL2CAPService(org.javabluetooth.stack.l2cap.L2CAPChannel, short,
     * short, byte[])
     */
    public void registerL2CAPService(L2CAPChannel channel, short serviceUUID, short browseUUID,
        byte[] serviceRecord) throws HCIException {
            if (!isConnected) throw new HCIException("BluetoothTCPClient is not connected.");
            short channelHandle = -1;
            for (int i = 0; i < channels.length; i++) {
                if (channels[i] == null) {
                    channels[i] = channel;
                    channel.l2capSender = this;
                    channelHandle = (short)i;
                    break;
                }
            }
            if (channelHandle == -1) throw new HCIException("Register SDP Service failed. No Open Channel Slots.");
            short length = (short)(6 + serviceRecord.length);
            byte[] registerL2CAPServiceRequest = new byte[3 + length];
            registerL2CAPServiceRequest[0] = SDP_REGISTER_SERVICE_REQUEST;
            registerL2CAPServiceRequest[1] = (byte)((length) & 0xff);
            registerL2CAPServiceRequest[2] = (byte)((length >> 8) & 0xff);
            registerL2CAPServiceRequest[3] = (byte)((channelHandle) & 0xff);
            registerL2CAPServiceRequest[4] = (byte)((channelHandle >> 8) & 0xff);
            registerL2CAPServiceRequest[5] = (byte)((serviceUUID) & 0xff);
            registerL2CAPServiceRequest[6] = (byte)((serviceUUID >> 8) & 0xff);
            registerL2CAPServiceRequest[7] = (byte)((browseUUID) & 0xff);
            registerL2CAPServiceRequest[8] = (byte)((browseUUID >> 8) & 0xff);
            System.arraycopy(serviceRecord, 0, registerL2CAPServiceRequest, 9, serviceRecord.length);
            try {
                Debug.println(6, "BluetoothTCPClient: Sending SDP Register Service Request:", registerL2CAPServiceRequest);
                socketOut.write(registerL2CAPServiceRequest);
                socketOut.flush();
            }
            catch (IOException e) {
                cleanExit();
                throw new HCIException("IOException: " + e);
            }
    }
View Full Code Here

     * to determine which implementation of <code>BluetoothStack</code> to use.
     * @return BluetoothStack instance set by BluetoothStack.init(BluetoothStack)
     * @throws HCIException if no BluetoothStack was initialized via BluetoothStack.init(BluetoothStack)
     */
    public static BluetoothStack getBluetoothStack() throws HCIException {
        if (bluetoothStack == null) throw new HCIException("BluetoothStack not initalized. ");
        return bluetoothStack;
    }
View Full Code Here

        if (resultData[6] == 0x00) {
            int resultOut = ((int)(resultData[7] & 0xff)) | ((int)(resultData[8] & 0xff) << 8) |
                ((int)(resultData[9] & 0xff) << 16);
            return resultOut;
        }
        else { throw new HCIException("Read_Class_Of_Device Failed: status=" + resultData[6]); }
    }
View Full Code Here

        if (resultData[6] == 0x00) {
            int resultOut = ((int)((resultData[8] & 0xff))) | ((int)((resultData[9] & 0xff) << 8)) |
                ((int)((resultData[10] & 0xff) << 16));
            return resultOut;
        }
        else throw new HCIException("HCI_HC_Read_Current_IAC_LAP returned invalid result.");
    }
View Full Code Here

        byte[] resultData = send_HCI_Command_Packet(data);
        if (resultData[6] == 0x00) {
            return (((long)data[7]) & 0xff) | (((long)data[8]) & 0xff) << 8 | (((long)data[9]) & 0xff) << 16 |
                (((long)data[10]) & 0xff) << 24 | (((long)data[11]) & 0xff) << 32 | (((long)data[12]) & 0xff) << 40;
        }
        else throw new HCIException("Read_DB_ADDR Failed: Status=" + resultData[6]);
    }
View Full Code Here

                channel.localChannelID = (short)(i + 2);
                break;
            }
        }
        if (channel.localChannelID == -1)
            throw new HCIException("L2CAP Connection Request failed. No Local Channels available.");
        byte[] connectionRequest = {
            0x02, identifierCount++, 0x04, //fixed length
            0x00, //fixed length
            (byte)((psm) & 0xff), (byte)((psm >> 8) & 0xff), (byte)((channel.localChannelID) & 0xff),
                (byte)((channel.localChannelID >> 8) & 0xff)
View Full Code Here

TOP

Related Classes of org.javabluetooth.stack.hci.HCIException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.