fun handleDevEvent(data: ByteArray) {
val cmd = data[0].toInt()
if (fullForward) {
listener.handleDevEvent(data)
return
}
if (cmd == Rpc.Cmd.RPC_CMDID_EVT_PCD_SET_FIELD.id) {
setField(data[1])
} else {
listener.handleDevEvent(data)
}
}
@Throws(IOException::class)
fun handleDevRequest(data: ByteArray): ByteArray? {
val cmd = data[0].toInt()
if (fullForward) return listener.handleDevRequest(data)
/* Handles NFC requests locally. Pass the rest onto the higher level app */
return when (cmd) {
Rpc.Cmd.RPC_CMDID_REQ_PCD_DETECT.id -> {
val resp = ByteArray(1)
val timeout = data[1].toInt()
resp[0] = detectCard(timeout).toByte()
resp
}
Rpc.Cmd.RPC_CMDID_REQ_PCD_REMOVE.id -> {
removeCard()
ByteArray(1)
}
Rpc.Cmd.RPC_CMDID_REQ_PCD_XCHNG.id -> {
val apdu = data.copyOfRange(1, 1 + data.size - 1)
sendApdu(apdu)
}
else -> {
listener.handleDevRequest(data)null
}
}
} |