Skip to content

Commit

Permalink
Feat: Added read env and usage for hoplink example
Browse files Browse the repository at this point in the history
  • Loading branch information
ocfmem committed Feb 10, 2020
1 parent c7acdff commit a52c712
Showing 1 changed file with 102 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import org.eclipse.keyple.calypso.command.po.parser.ReadRecordsRespPars
import org.eclipse.keyple.calypso.transaction.PoSelectionRequest
import org.eclipse.keyple.calypso.transaction.PoSelector
import org.eclipse.keyple.core.selection.SeSelection
import org.eclipse.keyple.core.seproxy.ChannelControl
import org.eclipse.keyple.core.seproxy.MultiSeRequestProcessing
import org.eclipse.keyple.core.seproxy.SeSelector
import org.eclipse.keyple.core.seproxy.protocol.SeCommonProtocols
import org.eclipse.keyple.core.util.ByteArrayUtil
import org.eclipse.keyple.example.calypso.android.omapi.R
import org.eclipse.keyple.example.calypso.android.omapi.utils.AidEnum


class CalypsoExamplesActivity : ExamplesActivity() {

override fun initContentView() {
Expand All @@ -27,7 +30,7 @@ class CalypsoExamplesActivity : ExamplesActivity() {

private fun explicitSectionAid(){
val poAid = AidEnum.NAVIGO2013.aid //navigo (without version number 01)
addHeaderEvent("Starting explicitAidSelection with: %s".format(poAid))
addHeaderEvent("Starting explicitAidSelection with: $poAid")

/*
* Get a reader
Expand Down Expand Up @@ -60,10 +63,10 @@ class CalypsoExamplesActivity : ExamplesActivity() {
if(selectionsResult.hasActiveSelection()){
val matchedSe = selectionsResult.activeSelection.matchingSe
addResultEvent("The selection of the SE has succeeded.")
addResultEvent("Application FCI = %s".format(ByteArrayUtil.toHex(matchedSe.selectionStatus.fci.bytes)))
addResultEvent("Application FCI = ${ByteArrayUtil.toHex(matchedSe.selectionStatus.fci.bytes)}")
}else{
addResultEvent("The selection of the PO Failed")
showAlertDialog(NoSuchElementException("Could not select: %s".format(poAid)))
showAlertDialog(NoSuchElementException("Could not select: $poAid"))
}

eventRecyclerView.smoothScrollToPosition(events.size-1)
Expand All @@ -84,7 +87,7 @@ class CalypsoExamplesActivity : ExamplesActivity() {
val sfiNavigoEFEnvironment = 0x07.toByte()
val sfiNavigoEFTransportEvent = 0x08.toByte()

addHeaderEvent("Starting readEnvironmentAndUsage with: %s".format(poAid))
addHeaderEvent("Starting readEnvironmentAndUsage with: $poAid")

/*
* Prepare a Calypso PO selection
Expand Down Expand Up @@ -123,14 +126,14 @@ class CalypsoExamplesActivity : ExamplesActivity() {
* Actual PO communication: operate through a single request the Calypso PO
* selection and the file read
*/
addActionEvent("Process explicit selection for %s and reading Environment and transport event".format(poAid))
addActionEvent("Process explicit selection for $poAid and reading Environment and transport event")
val selectionsResult = seSelection.processExplicitSelection(reader)

if (selectionsResult.hasActiveSelection()) {
val matchingSelection = selectionsResult.activeSelection

//val calypsoPo = matchingSelection.matchingSe as CalypsoPo
addResultEvent("Selection succeeded for P0 with aid %s".format(poAid))
addResultEvent("Selection succeeded for P0 with aid $poAid")

val readEnvironmentParser = matchingSelection
.getResponseParser(readEnvironmentParserIndex) as ReadRecordsRespPars
Expand All @@ -140,7 +143,7 @@ class CalypsoExamplesActivity : ExamplesActivity() {
* process (Environment)
*/
val environmentAndHolder = readEnvironmentParser.records[1]
addResultEvent("Environment file data: %s".format(ByteArrayUtil.toHex(environmentAndHolder)))
addResultEvent("Environment file data: ${ByteArrayUtil.toHex(environmentAndHolder)}")


val readTransportEventParser = matchingSelection
Expand All @@ -151,11 +154,102 @@ class CalypsoExamplesActivity : ExamplesActivity() {
* process (Usage)
*/
val transportEvents = readTransportEventParser.records[1]
addResultEvent("Transport Event file data: %s".format(ByteArrayUtil.toHex(transportEvents)))
addResultEvent("Transport Event file data: ${ByteArrayUtil.toHex(transportEvents)}")

}
}else if(aidEnum== AidEnum.HOPLINK){
val poAid = AidEnum.NAVIGO2013.aid
val sfiHoplinkEFEnvironment = 0x14.toByte()
val sfiHoplinkEFUsage = 0x1A.toByte()

addHeaderEvent("Starting readEnvironmentAndUsage with: $poAid")


val t2UsageRecord1_dataFill = ("0102030405060708090A0B0C0D0E0F10" + "1112131415161718191A1B1C1D1E1F20"
+ "2122232425262728292A2B2C2D2E2F30")

/*
* Prepare a Calypso PO selection
*/
val seSelection = SeSelection(MultiSeRequestProcessing.FIRST_MATCH,
ChannelControl.KEEP_OPEN)

/*
* Setting of an AID based selection of a Calypso REV3 PO
*
* Select the first application matching the selection AID whatever the SE
* communication protocol keep the logical channel open after the selection
*/

/*
* Calypso selection: configures a PoSelectionRequest with all the desired
* attributes to make the selection and read additional information afterwards
*/
val poSelectionRequest = PoSelectionRequest(
PoSelector(SeCommonProtocols.PROTOCOL_ISO7816_3, null,
PoSelector.PoAidSelector(
SeSelector.AidSelector.IsoAid(poAid),
PoSelector.InvalidatedPo.REJECT),
"AID: $poAid"))

/*
* Prepare the reading order and keep the associated parser for later use once
* the selection has been made.
*/
val readEnvironmentParserIndex = poSelectionRequest.prepareReadRecordsCmd(
sfiHoplinkEFEnvironment, ReadDataStructure.SINGLE_RECORD_DATA,
1.toByte(), 32, String.format("Hoplink EF T2Environment (SFI=%02X)",
sfiHoplinkEFEnvironment))

val readUsageParserIndex = poSelectionRequest.prepareReadRecordsCmd(
sfiHoplinkEFUsage, ReadDataStructure.SINGLE_RECORD_DATA,
1.toByte(), 48, String.format("Hoplink EF T2Usage (SFI=%02X)",
sfiHoplinkEFUsage))


/*
* Add the selection case to the current selection (we could have added other
* cases here)
*
* Ignore the returned index since we have only one selection here.
*/
seSelection.prepareSelection(poSelectionRequest)

/*
* Actual PO communication: operate through a single request the Calypso PO
* selection and the file read
*/

val selectionsResult = seSelection.processExplicitSelection(reader)

if (selectionsResult.hasActiveSelection()) {
val matchingSelection = selectionsResult.activeSelection

//val calypsoPo = matchingSelection.matchingSe as CalypsoPo
addResultEvent("Selection succeeded for P0 with aid $poAid")

val readEnvironmentParser = matchingSelection
.getResponseParser(readEnvironmentParserIndex) as ReadRecordsRespPars

/*
* Retrieve the data read from the parser updated during the selection
* process (Environment)
*/
val environmentAndHolder = readEnvironmentParser.records[1]
addResultEvent("Environment file data: ${ByteArrayUtil.toHex(environmentAndHolder)}")


val readUsageParser = matchingSelection
.getResponseParser(readUsageParserIndex) as ReadRecordsRespPars

/*
* Retrieve the data read from the parser updated during the selection
* process (Usage)
*/
val transportEvents = readUsageParser.records[1]
addResultEvent("Transport Event file data: ${ByteArrayUtil.toHex(transportEvents)}")

}
}
}

Expand Down

0 comments on commit a52c712

Please sign in to comment.