We now detect and use the newapi if the device doesn't offer the old one

This commit is contained in:
geeksville
2020-04-23 11:54:47 -07:00
parent 17edf75b95
commit a3db3eca06
2 changed files with 11 additions and 5 deletions

View File

@@ -916,8 +916,6 @@ class MeshService : Service(), Logging {
/// msecs since 1970 we started this connection
private var connectTimeMsec = 0L
private val useOldApi = false
/// Called when we gain/lose connection to our radio
private fun onConnectionChanged(c: ConnectionState) {
debug("onConnectionChanged=$c")
@@ -969,7 +967,7 @@ class MeshService : Service(), Logging {
// Do our startup init
try {
connectTimeMsec = System.currentTimeMillis()
if (useOldApi)
if (RadioInterfaceService.isOldApi!!)
reinitFromRadioREV1()
else
startConfig()
@@ -1231,7 +1229,7 @@ class MeshService : Service(), Logging {
val parsed = MeshProtos.RadioConfig.parseFrom(payload)
// Update our device
if (useOldApi)
if (RadioInterfaceService.isOldApi!!)
connectedRadio.writeRadioConfig(payload)
else
sendToRadio(ToRadio.newBuilder().apply {
@@ -1261,7 +1259,7 @@ class MeshService : Service(), Logging {
}
// set my owner info
if (useOldApi)
if (RadioInterfaceService.isOldApi!!)
connectedRadio.writeOwner(user.toByteArray())
else sendToRadio(ToRadio.newBuilder().apply {
this.setOwner = user

View File

@@ -141,6 +141,11 @@ class RadioInterfaceService : Service(), Logging {
/// If our service is currently running, this pointer can be used to reach it (in case setBondedDeviceAddress is called)
private var runningService: RadioInterfaceService? = null
/**
* Temp hack (until old API deprecated), we probe for old API at connected
*/
var isOldApi: Boolean? = null
/// This is public only so that SimRadio can bootstrap our message flow
fun broadcastReceivedFromRadio(context: Context, payload: ByteArray) {
val intent = Intent(RECEIVE_FROMRADIO_ACTION)
@@ -399,6 +404,9 @@ class RadioInterfaceService : Service(), Logging {
debug("Discovered services!")
delay(500) // android BLE is buggy and needs a 500ms sleep before calling getChracteristic, or you might get back null
isOldApi = service.getCharacteristic(BTM_RADIO_CHARACTER) != null
warn("Use oldAPI = $isOldApi")
fromNum = service.getCharacteristic(BTM_FROMNUM_CHARACTER)!!
// We must set this to true before broadcasting connectionChanged