aboutsummaryrefslogtreecommitdiff
path: root/extras/android/RemoteHCI/app/src/main/java/com/github/google/bumble/remotehci/CommandLineInterface.kt
blob: 2f1b59e7472e586708a14471352faf146348b4d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.github.google.bumble.remotehci

import java.io.IOException

class CommandLineInterface {
    companion object {
        fun printUsage() {
            System.out.println("usage: <launch-command> [-h|--help] [<tcp-port>]")
        }

        @JvmStatic fun main(args: Array<String>) {
            System.out.println("Starting proxy")

            var tcpPort = DEFAULT_TCP_PORT
            if (args.isNotEmpty()) {
                if (args[0] == "-h" || args[0] == "--help") {
                    printUsage()
                    return
                }
                try {
                    tcpPort = args[0].toInt()
                } catch (error: NumberFormatException) {
                    System.out.println("ERROR: invalid TCP port argument")
                    printUsage()
                    return
                }
            }

            try {
                val hciProxy = HciProxy(tcpPort, object : HciProxy.Listener {
                    override fun onHostConnectionState(connected: Boolean) {
                    }

                    override fun onHciPacketCountChange(
                        commandPacketsReceived: Int,
                        aclPacketsReceived: Int,
                        scoPacketsReceived: Int,
                        eventPacketsSent: Int,
                        aclPacketsSent: Int,
                        scoPacketsSent: Int
                    ) {
                    }

                    override fun onMessage(message: String?) {
                        System.out.println(message)
                    }

                })
                hciProxy.run()
            } catch (error: IOException) {
                System.err.println("Exception while running HCI Server: $error")
            } catch (error: HciProxy.HalException) {
                System.err.println("HAL exception: ${error.message}")
            }
        }
    }
}