From 3d4be477a2737b433018026844cad702e62e8c61 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 5 Jun 2020 21:12:15 -0700 Subject: [PATCH] remove old BLE api --- TODO.md | 5 ++ .../mesh/IRadioInterfaceService.aidl | 15 ----- .../mesh/service/BluetoothInterfaceService.kt | 10 ---- .../mesh/service/InterfaceService.kt | 40 ------------- .../geeksville/mesh/service/MeshService.kt | 56 ++----------------- 5 files changed, 10 insertions(+), 116 deletions(-) diff --git a/TODO.md b/TODO.md index a83f6c0d0..2748510db 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,11 @@ # High priority Work items for soon alpha builds +USBserial todo: + +* remove old api +* refactor ble and serial into Interface subclasses, used by RadioInterfaceService. Instanciate either a BLE or a serial interface as needed + Document the following in application behavior *change ls_secs is 1 hr normally, which is fine because if there are other nodes in the mesh and they send us a packet we will wake any time during ls_secs and update app state * use states for meshservice: disconnected -> connected-> devsleep -> disconnected (3 states) diff --git a/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl b/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl index 5db144027..a10975157 100644 --- a/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl +++ b/app/src/main/aidl/com/geeksville/mesh/IRadioInterfaceService.aidl @@ -7,21 +7,6 @@ interface IRadioInterfaceService { void sendToRadio(in byte [] a); - /// mynode - read/write this to access a MyNodeInfo protobuf - byte []readMyNode(); - - /// nodeinfo - read this to get a series of node infos (ending with a null empty record), write to this to restart the read statemachine that returns all the node infos - byte []readNodeInfo(); - void restartNodeInfo(); - - /// radio - read/write this to access a RadioConfig protobuf - byte []readRadioConfig(); - void writeRadioConfig(in byte [] config); - - /// owner - read/write this to access a User protobuf - byte []readOwner(); - void writeOwner(in byte [] owner); - /// If a macaddress we will try to talk to our device, if null we will be idle. /// Any current connection will be dropped (even if the device address is the same) before reconnecting. /// Users should not call this directly, called only by MeshService diff --git a/app/src/main/java/com/geeksville/mesh/service/BluetoothInterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/BluetoothInterfaceService.kt index 4b36478dd..fa7b382cc 100644 --- a/app/src/main/java/com/geeksville/mesh/service/BluetoothInterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/BluetoothInterfaceService.kt @@ -101,11 +101,6 @@ class BluetoothInterfaceService : InterfaceService() { /// If our service is currently running, this pointer can be used to reach it (in case setBondedDeviceAddress is called) private var runningService: BluetoothInterfaceService? = null - /** - * Temp hack (until old API deprecated), try using just the new API now - */ - var isOldApi: Boolean? = false - /// Get our bluetooth adapter (should always succeed except on emulator private fun getBluetoothAdapter(context: Context): BluetoothAdapter? { val bluetoothManager = @@ -344,11 +339,6 @@ class BluetoothInterfaceService : InterfaceService() { debug("Discovered services!") delay(1000) // android BLE is buggy and needs a 500ms sleep before calling getChracteristic, or you might get back null - // service could be null, test this by throwing BLEException and testing it on my machine - if (isOldApi == null) - isOldApi = service.getCharacteristic(BTM_RADIO_CHARACTER) != null - warn("Use oldAPI = $isOldApi") - /* if (isFirstTime) { isFirstTime = false throw BLEException("Faking a BLE failure") diff --git a/app/src/main/java/com/geeksville/mesh/service/InterfaceService.kt b/app/src/main/java/com/geeksville/mesh/service/InterfaceService.kt index b0ea3ff8c..8f34d31eb 100644 --- a/app/src/main/java/com/geeksville/mesh/service/InterfaceService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/InterfaceService.kt @@ -4,7 +4,6 @@ import android.app.Service import android.content.Context import android.content.Intent import android.os.IBinder -import android.os.RemoteException import com.geeksville.android.BinaryLogFile import com.geeksville.android.Logging import com.geeksville.concurrent.DeferredExecution @@ -53,22 +52,6 @@ abstract class InterfaceService : Service(), Logging { val BTM_FROMNUM_CHARACTER = UUID.fromString("ed9da18c-a800-4f66-a670-aa7547e34453") - /// mynode - read/write this to access a MyNodeInfo protobuf - val BTM_MYNODE_CHARACTER = - UUID.fromString("ea9f3f82-8dc4-4733-9452-1f6da28892a2") - - /// nodeinfo - read this to get a series of node infos (ending with a null empty record), write to this to restart the read statemachine that returns all the node infos - val BTM_NODEINFO_CHARACTER = - UUID.fromString("d31e02e0-c8ab-4d3f-9cc9-0b8466bdabe8") - - /// radio - read/write this to access a RadioConfig protobuf - val BTM_RADIO_CHARACTER = - UUID.fromString("b56786c8-839a-44a1-b98e-a1724c4a0262") - - /// owner - read/write this to access a User protobuf - val BTM_OWNER_CHARACTER = - UUID.fromString("6ff1d8b6-e2de-41e3-8c0b-8fa384f64eb6") - /// This is public only so that SimRadio can bootstrap our message flow fun broadcastReceivedFromRadio(context: Context, payload: ByteArray) { val intent = Intent(RECEIVE_FROMRADIO_ACTION) @@ -202,28 +185,5 @@ abstract class InterfaceService : Service(), Logging { // Do this in the IO thread because it might take a while (and we don't care about the result code) serviceScope.handledLaunch { handleSendToRadio(a) } } - - // - // NOTE: the following methods are all deprecated and will be removed soon - // - - // A write of any size to nodeinfo means restart reading - override fun restartNodeInfo() = doWrite(BTM_NODEINFO_CHARACTER, ByteArray(0)) - - override fun readMyNode() = - doRead(BTM_MYNODE_CHARACTER) - ?: throw RemoteException("Device returned empty MyNodeInfo") - - override fun readRadioConfig() = - doRead(BTM_RADIO_CHARACTER) - ?: throw RemoteException("Device returned empty RadioConfig") - - override fun readOwner() = - doRead(BTM_OWNER_CHARACTER) ?: throw RemoteException("Device returned empty Owner") - - override fun writeOwner(owner: ByteArray) = doWrite(BTM_OWNER_CHARACTER, owner) - override fun writeRadioConfig(config: ByteArray) = doWrite(BTM_RADIO_CHARACTER, config) - - override fun readNodeInfo() = doRead(BTM_NODEINFO_CHARACTER) } } diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index fa21e2a05..3a93c6529 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -920,43 +920,6 @@ class MeshService : Service(), Logging { private fun currentSecond() = (System.currentTimeMillis() / 1000).toInt() - /** - * Note: this is the deprecated REV1 API way of getting the nodedb - * We are reconnecting to a radio, redownload the full state. This operation might take hundreds of milliseconds - * */ - private fun reinitFromRadioREV1() { - // Read the MyNodeInfo object - val myInfo = MeshProtos.MyNodeInfo.parseFrom( - connectedRadio.readMyNode() - ) - - handleMyInfo(myInfo) - myNodeInfo = newMyNodeInfo // Apply the changes from handleMyInfo right now - - radioConfig = MeshProtos.RadioConfig.parseFrom(connectedRadio.readRadioConfig()) - - // Ask for the current node DB - connectedRadio.restartNodeInfo() - - // read all the infos until we get back null - var infoBytes = connectedRadio.readNodeInfo() - while (infoBytes != null) { - val info = MeshProtos.NodeInfo.parseFrom(infoBytes) - installNodeInfo(info) - - // advance to next - infoBytes = connectedRadio.readNodeInfo() - } - - haveNodeDB = true // we've done our initial node db initialization - processEarlyPackets() // handle any packets that showed up while we were booting - - // broadcast an intent with our new connection state - broadcastConnection() - reportConnection() // this is just analytics - onNodeDBChanged() - } - /// If we just changed our nodedb, we might want to do somethings private fun onNodeDBChanged() { updateNotification() @@ -1060,10 +1023,7 @@ class MeshService : Service(), Logging { // Do our startup init try { connectTimeMsec = System.currentTimeMillis() - if (BluetoothInterfaceService.isOldApi!!) - reinitFromRadioREV1() - else - startConfig() + startConfig() } catch (ex: InvalidProtocolBufferException) { errormsg( @@ -1348,12 +1308,9 @@ class MeshService : Service(), Logging { val parsed = MeshProtos.RadioConfig.parseFrom(payload) // Update our device - if (BluetoothInterfaceService.isOldApi!!) - connectedRadio.writeRadioConfig(payload) - else - sendToRadio(ToRadio.newBuilder().apply { - this.setRadio = parsed - }) + sendToRadio(ToRadio.newBuilder().apply { + this.setRadio = parsed + }) // Update our cached copy this@MeshService.radioConfig = parsed @@ -1378,12 +1335,9 @@ class MeshService : Service(), Logging { } // set my owner info - if (BluetoothInterfaceService.isOldApi!!) - connectedRadio.writeOwner(user.toByteArray()) - else sendToRadio(ToRadio.newBuilder().apply { + sendToRadio(ToRadio.newBuilder().apply { this.setOwner = user }) - } /// Do not use directly, instead call generatePacketId()