TCPInterface (for accessing the native-simulator) kinda works

pull/276/head^2
Kevin Hester 2021-03-29 21:09:27 +08:00
rodzic 9e42634402
commit 04f4a2a342
3 zmienionych plików z 19 dodań i 15 usunięć

Wyświetl plik

@ -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<InterfaceFactory>(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)

Wyświetl plik

@ -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()
}
}

Wyświetl plik

@ -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.