-
-
Save reactormonk/23b9edf0aa37e491430f692cb580328e to your computer and use it in GitHub Desktop.
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
enum class PICCPollInterval(val value: Byte) { | |
I250ms(0b00000000), | |
I500ms(0b00001000), | |
I1000ms(0b00010000), | |
I2500ms(0b00011000),; | |
companion object { | |
private val values = values() | |
fun bitMaskToEnum(bitMask: Byte) = | |
values.find { | |
it.value == bitMask and 0b00011000 | |
}!! | |
} | |
} | |
enum class AutomaticPPICPolling(override val position: Byte): Positional { | |
AutomaticPolling(0), | |
TurnOffFieldIfNoPICC(1), | |
TurnOffFieldIfPPICInactive(2), | |
EnforceISO14443AP4(7),; | |
companion object { | |
private val values = AutomaticPPICPolling.values() | |
fun bitMaskToSet(bitMask: Byte): EnumSet<AutomaticPPICPolling> = | |
values.filterTo(EnumSet.noneOf(AutomaticPPICPolling::class.java)) { | |
val toBitMask = it.toBitMask() | |
bitMask and toBitMask != 0.toByte() | |
} | |
} | |
} | |
interface Positional { | |
abstract val position: Byte | |
fun toBitMask(): Byte = (1 shl position.toInt()).toByte() | |
} | |
data class PollingSettings(val polling: EnumSet<AutomaticPPICPolling>, val interval: PICCPollInterval) { | |
fun toBitMask(): Byte = | |
polling.toBitMask() or interval.value | |
companion object { | |
fun bitMaskToEnum(byte: Byte): PollingSettings { | |
val interval = PICCPollInterval.bitMaskToEnum(byte) | |
val polling = AutomaticPPICPolling.bitMaskToSet(byte) | |
return PollingSettings(polling, interval) | |
} | |
} | |
class BluetoothSupportTest : DescribeSpec({ | |
describe("BluetoothSupport") { | |
forAll<PollingSettings> { setting -> | |
PollingSettings.bitMaskToEnum(setting.toBitMask()) == setting | |
} | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment