remove old BLE api

1.2-legacy
geeksville 2020-06-05 21:12:15 -07:00
rodzic d1a3d98de4
commit 3d4be477a2
5 zmienionych plików z 10 dodań i 116 usunięć

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -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")

Wyświetl plik

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

Wyświetl plik

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