⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluetoothstack.java

📁 蓝牙协议栈可是要钱的喔
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param condition 0x01	Do NOT Auto accept the connection. (Auto accept is off)
     * 0x02	Do Auto accept the connection with role switch disabled. (Auto accept is on).
     * 0x03	Do Auto accept the connection with role switch enabled. (Auto accept is on). Note: When auto accepting an incoming
     * SCO connection, no	role switch will be performed. The value 0x03 of the Auto_Accept_Flag will then get the same
     * effect as if the value had been 0x02. For details see Page 623 of the Bluetooth Core Specification Version 1.1
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Write_Event_Filter_Connection_Setup(int classOfDevice, int mask,
        byte condition) throws HCIException {
            byte[] data = {
                CMD_PKT, 0x05, 0x0c, 0x09, 0x02, 0x01, (byte)((classOfDevice) & 0xff), (byte)((classOfDevice >> 8) & 0xff),
                    (byte)((classOfDevice >> 16) & 0xff), (byte)((mask) & 0xff), (byte)((mask >> 8) & 0xff), (byte)((mask >> 16) & 0xff), condition
            };
            byte[] resultData = send_HCI_Command_Packet(data);
            return resultData[6];
    }

    /**
     * Adds Inquiry Result Filter for all new Devices responding to the Inquiry Process. For details see Page 623 of the
     * Bluetooth Core Specification Version 1.1
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Write_Event_Filter_Inquiry_Result() throws HCIException {
        byte[] data = { CMD_PKT, 0x05, 0x0c, 0x02, 0x01, 0x00 };
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[6];
    }

    /**
     * Adds Inquiry Result Filter for devices with a specific Bluetooth Address. For details see Page 623 of the Bluetooth
     * Core Specification Version 1.1
     * @param bd_addr Bluetooth Address of the Device for which Inquiry Filters are being set.
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Write_Event_Filter_Inquiry_Result(long bd_addr) throws HCIException {
        byte[] data = {
            CMD_PKT, 0x05, 0x0c, 0x08, 0x01, 0x02, (byte)((bd_addr) & 0xff), (byte)((bd_addr >> 8) & 0xff), (byte)((bd_addr >> 16) & 0xff),
                (byte)((bd_addr >> 24) & 0xff), (byte)((bd_addr >> 32) & 0xff), (byte)((bd_addr >> 40) & 0xff)
        };
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[6];
    }

    /**
     * Adds Inquiry Result Filter for devices with a specific Class Of Device. For details see Page 623 of the Bluetooth Core
     * Specification Version 1.1
     * @param classOfDevice specifies the Class Of Device of the devices to be filtered.
     * @param mask Bit Mask used to determine which bits of the Class of Device parameter
     * are `don't care'. Zero-value bits in the mask indicate the `don't care' bits of the Class of Device.
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Write_Event_Filter_Inquiry_Result(int classOfDevice, int mask) throws HCIException {
        byte[] data = {
            CMD_PKT, 0x05, 0x0c, 0x09, 0x01, 0x01, (byte)((classOfDevice) & 0xff), (byte)((classOfDevice >> 8) & 0xff),
                (byte)((classOfDevice >> 16) & 0xff), (byte)((mask) & 0xff), (byte)((mask >> 8) & 0xff),
                (byte)((mask >> 16) & 0xff)
        };
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[6];
    }

    /**
     * The Change_Local_Name command provides the ability to modify
     * the user-friendly name for the Bluetooth device. A Bluetooth device
     * may send a request to get the user-friendly name of another Bluetooth
     * device. The user-friendly name provides the user with the ability to distinguish one Bluetooth device from another.
     * For details see Page 640 of the Bluetooth Core Specification Version 1.1
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Change_Local_Name(String localName) throws HCIException {
        byte[] data = new byte[252];
        data[0] = CMD_PKT;
        data[1] = (byte)0x13;
        data[2] = (byte)0x0c;
        data[3] = (byte)0xf8;
        int byteCount = 0;
        for ( ; (byteCount < localName.length()) && (byteCount < 247); byteCount++)
            data[byteCount + 4] = (byte)localName.charAt(byteCount);
        for ( ; byteCount < 248; byteCount++) data[byteCount + 4] = (byte)0x00;
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[6];
    }

    /**
     * Retrieves the name of the local device.  The Bluetooth specification calls this name the "Bluetooth device name" or the
     * "user-friendly name". For details see Page 641 of the Bluetooth Specification Version 1.1
     * @return the name of the local device; <code>null</code> if the name could not be retrieved
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public String send_HCI_HC_Read_Local_Name() throws HCIException {
        byte[] data = { CMD_PKT, 0x14, 0x0c, 0x00 };
        byte[] resultData = send_HCI_Command_Packet(data);
        if (resultData[6] == 0x00) {
            int i = 0;
            while (i < 248 && resultData[i + 7] != 0x00) { i++; }
            return new String(resultData, 7, i);
        }
        else return null;
    }

    /**
     * This command will read the value for the Scan_Enable parameter. The
     * Scan_Enable parameter controls whether or not the Bluetoothdevice will periodically scan for page attempts and/or
     * inquiry requests from other Bluetooth devices. If Page_Scan is enabled, then the device will enter page
     * scan mode based on the value of the Page_Scan_Interval and Page_Scan_Window parameters. If Inquiry_Scan is enabled,
     * then the device will enter Inquiry Scan mode based on the value of the Inquiry_Scan_Interval and Inquiry_Scan_Window
     * parameters. For details see Page 646 of the Bluetooth Core Specification Version 1.1
     * @return 0x00 = No Scans enabled. 0x01 = Inquiry Scan enabled. Page Scan disabled.
     * 0x02 = Inquiry Scan disabled. Page Scan enabled. 0x03 = Inquiry Scan enabled.  Page Scan enabled.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Read_Scan_Enable() throws HCIException {
        byte[] data = { CMD_PKT, 0x19, 0x0C, 0x00 };
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[7];
    }

    /**
     *	This command will write the value for the Scan_Enable parameter. The Scan_Enable parameter controls whether or not the
     * Bluetooth device will periodically scan for page attempts and/or inquiry requests
     * from other Bluetooth devices. If Page_Scan is enabled, then the device
     * will enter page scan mode based on the value of the Page_Scan_Interval
     * and Page_Scan_Window parameters. If Inquiry_Scan is enabled, then the device will enter Inquiry Scan mode based on the
     * value of the Inquiry_Scan_Interval and Inquiry_Scan_Window parameters.
     * For details see Page 647 of the Bluetooth Core Specification Version 1.1
     * @param scanType 0x00 = No Scans enabled. Default. 0x01 = Inquiry Scan enabled. Page Scan disabled.
     * 0x02 = Inquiry Scan disabled. Page Scan enabled. 0x03 = Inquiry Scan enabled.  Page Scan enabled.
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Write_Scan_Enable(byte scanType) throws HCIException {
        byte[] data = { CMD_PKT, 0x1a, 0x0C, 0x01, scanType };
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[6];
    }

    /**
     * This command will read the value for the Class_of_Device parameter. The Class_of_Device parameter is used to indicate
     * the capabilities of the local device to other devices.
     * For details see Page 661 of the Bluetooth Core Specification Version 1.1
     * @return The Class of Device of the local Bluetooth Host Controller.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public int send_HCI_HC_Read_Class_Of_Device() throws HCIException {
        byte[] data = { CMD_PKT, 0x23, 0x0c, 0x00 };
        byte[] resultData = send_HCI_Command_Packet(data);
        //TODO is this right? byte order?
        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]); }
    }

    /**
     * This command will write the value for the Class_of_Device parameter.
     * The Class_of_Device parameter is used to indicate the capabilities of the local device to other devices.
     * For details see Page 662 of the Bluetooth Core Specification Version 1.1
     * @param classOfDevice the Class of Device for the device.
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public byte send_HCI_HC_Write_Class_Of_Device(int classOfDevice) throws HCIException {
        byte[] data = {
            CMD_PKT, 0x24, 0x0c, 0x03, (byte)((classOfDevice) & 0xff), (byte)((classOfDevice >> 8) & 0xff),
                (byte)((classOfDevice >> 16) & 0xff)
        };
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[6];
    }

    /**
     * This command reads the LAP used to create the Inquiry Access Codes (IAC) that the local Bluetooth device is
     * simultaneously scanning for during Inquiry Scans. For details see Page 691 of the Bluetooth Core
     * Specification Version 1.1
     * @return
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public int send_HCI_HC_Read_Current_IAC_LAP() throws HCIException {
        byte[] data = { CMD_PKT, 0x39, 0x0c, 0x00 };
        byte[] resultData = send_HCI_Command_Packet(data);
        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.");
    }

    /**
     * This command writes the LAP(s) used to create the Inquiry Access Code
     * (IAC) that the local Bluetooth device is scanning for during Inquiry Scans.
     * All Bluetooth devices are required to support at least one IAC, the General Inquiry Access Code (the GIAC). Some
     * Bluetooth devices support additional IACs. For details see Page 692 of the Bluetooth Core Specification Version 1.1
     * @param iacLap
     * @return 0x00 if the command succeeded. 0x01-0xFF if the command failed. See Table 6.1 on page 766
     * for list of Error Codes.
     */
    public byte send_HCI_HC_Write_Current_IAC_LAP(int iacLap) throws HCIException {
        byte[] data = {
            CMD_PKT, 0x3a, 0x0c, 0x04, 0x01, (byte)((iacLap) & 0xff), (byte)((iacLap >> 8) & 0xff),
                (byte)((iacLap >> 16) & 0xff)
        };
        byte[] resultData = send_HCI_Command_Packet(data);
        return resultData[6];
    }

    /**
     * This command will read the value for the BD_ADDR parameter.
     * The BD_ADDR is a 48-bit unique identifier for a Bluetooth device.
     * For details see Page 706 of the Bluetooth Core Specification Version 1.1
     * @return Bluetooth Device Address
     * @throws org.javabluetooth.stack.bluetooth.hci.HCIException
     */
    public long send_HCI_IP_Read_BD_ADDR() throws HCIException {
        byte[] data = { CMD_PKT, 0x09, 0x10, 0x00 };
        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]);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -