-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create common ancestor class for odid scanners
DT-2604
- Loading branch information
1 parent
40df49e
commit ada49b6
Showing
5 changed files
with
172 additions
and
175 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
android/src/main/kotlin/cz/dronetag/flutter_opendroneid/OdidPayloadHandler.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
android/src/main/kotlin/cz/dronetag/flutter_opendroneid/scanner/ODIDScanner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cz.dronetag.flutter_opendroneid | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
|
||
/// Contains common functinality for ODID scanners | ||
/// Creates [ODIDPayload] instances implementin Pigeon PayloadAPI | ||
abstract class ODIDScanner( | ||
val odidPayloadStreamHandler: StreamHandler | ||
) : Pigeon.PayloadApi { | ||
|
||
companion object { | ||
const val MAX_MESSAGE_SIZE = 25 | ||
} | ||
|
||
var isScanning = false | ||
get() = field | ||
set(value) { | ||
field = value | ||
} | ||
|
||
val adapterStateReceiver: BroadcastReceiver = object : BroadcastReceiver() { | ||
override fun onReceive(context: Context?, intent: Intent?) { | ||
onAdapterStateReceived() | ||
} | ||
} | ||
|
||
override fun getPayload(rawData: ByteArray, source: Pigeon.MessageSource, macAddress: String, rssi: Long, receivedTimestamp: Long): Pigeon.ODIDPayload { | ||
val builder = Pigeon.ODIDPayload.Builder() | ||
|
||
builder.setRawData(rawData) | ||
builder.setReceivedTimestamp(receivedTimestamp) | ||
builder.setMacAddress(macAddress) | ||
builder.setSource(source) | ||
builder.setRssi(rssi) | ||
|
||
return builder.build() | ||
} | ||
|
||
abstract fun scan() | ||
|
||
abstract fun cancel() | ||
|
||
abstract fun onAdapterStateReceived() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.