1 package com.github.google.bumble.remotehci 2 3 import java.io.IOException 4 5 class CommandLineInterface { 6 companion object { printUsagenull7 fun printUsage() { 8 System.out.println("usage: <launch-command> [-h|--help] [<tcp-port>]") 9 } 10 mainnull11 @JvmStatic fun main(args: Array<String>) { 12 System.out.println("Starting proxy") 13 14 var tcpPort = DEFAULT_TCP_PORT 15 if (args.isNotEmpty()) { 16 if (args[0] == "-h" || args[0] == "--help") { 17 printUsage() 18 return 19 } 20 try { 21 tcpPort = args[0].toInt() 22 } catch (error: NumberFormatException) { 23 System.out.println("ERROR: invalid TCP port argument") 24 printUsage() 25 return 26 } 27 } 28 29 try { 30 val hciProxy = HciProxy(tcpPort, object : HciProxy.Listener { 31 override fun onHostConnectionState(connected: Boolean) { 32 } 33 34 override fun onHciPacketCountChange( 35 commandPacketsReceived: Int, 36 aclPacketsReceived: Int, 37 scoPacketsReceived: Int, 38 eventPacketsSent: Int, 39 aclPacketsSent: Int, 40 scoPacketsSent: Int 41 ) { 42 } 43 44 override fun onMessage(message: String?) { 45 System.out.println(message) 46 } 47 48 }) 49 hciProxy.run() 50 } catch (error: IOException) { 51 System.err.println("Exception while running HCI Server: $error") 52 } catch (error: HciProxy.HalException) { 53 System.err.println("HAL exception: ${error.message}") 54 } 55 } 56 } 57 }