From 04f4a2a342f8c582efe6c165c12a7f3d287e55b5 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 29 Mar 2021 21:09:27 +0800 Subject: [PATCH] TCPInterface (for accessing the native-simulator) kinda works --- .../mesh/service/RadioInterfaceService.kt | 3 ++ .../geeksville/mesh/service/TCPInterface.kt | 28 +++++++++---------- .../geeksville/mesh/ui/SettingsFragment.kt | 3 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt index d3edeb5b..9467187b 100644 --- a/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/RadioInterfaceService.kt @@ -51,6 +51,9 @@ class RadioInterfaceService : Service(), Logging { const val DEVADDR_KEY = "devAddr2" // the new name for devaddr + /// We keep this var alive so that the following factory objects get created and not stripped during the android build + private val factories = arrayOf(BluetoothInterface, SerialInterface, TCPInterface, MockInterface, NopInterface) + /// This is public only so that SimRadio can bootstrap our message flow fun broadcastReceivedFromRadio(context: Context, payload: ByteArray) { val intent = Intent(RECEIVE_FROMRADIO_ACTION) diff --git a/app/src/main/java/com/geeksville/mesh/service/TCPInterface.kt b/app/src/main/java/com/geeksville/mesh/service/TCPInterface.kt index 0ee12a2d..aec64343 100644 --- a/app/src/main/java/com/geeksville/mesh/service/TCPInterface.kt +++ b/app/src/main/java/com/geeksville/mesh/service/TCPInterface.kt @@ -54,23 +54,24 @@ class TCPInterface(service: RadioInterfaceService, private val address: String) override fun connect() { //here you must put your computer's IP address. //here you must put your computer's IP address. - val addr = InetAddress.getByName(address) - - debug("TCP connecting to $address") - - //create a socket to make the connection with the server - - //create a socket to make the connection with the server - val port = 4403 - val s = Socket(addr, port) - s.tcpNoDelay = true - socket = s - outStream = BufferedOutputStream(s.getOutputStream()) - inStream = BufferedInputStream(s.getInputStream()) // No need to keep a reference to this thread - it will exit when we close inStream thread(start = true, isDaemon = true, name = "TCP reader") { try { + val a = InetAddress.getByName(address) + debug("TCP connecting to $address") + + //create a socket to make the connection with the server + val port = 4403 + val s = Socket(a, port) + s.tcpNoDelay = true + socket = s + outStream = BufferedOutputStream(s.getOutputStream()) + inStream = s.getInputStream() + + // Note: we call the super method FROM OUR NEW THREAD + super.connect() + while (true) { val c = inStream.read() if (c == -1) @@ -84,6 +85,5 @@ class TCPInterface(service: RadioInterfaceService, private val address: String) } debug("Exiting TCP reader") } - super.connect() } } \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index a5dbcb95..e1e6dfa3 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -276,7 +276,8 @@ class BTScanModel(app: Application) : AndroidViewModel(app), Logging { warn("No bluetooth adapter. Running under emulation?") val testnodes = listOf( - DeviceListEntry("Simulated interface", "m", true), + DeviceListEntry("Included simulator", "m", true), + DeviceListEntry("Complete simulator", "t10.0.2.2", true), DeviceListEntry(context.getString(R.string.none), "n", true) /* Don't populate fake bluetooth devices, because we don't want testlab inside of google to try and use them.