TransitTerminalpublic class TransitTerminal extends Terminal This class implements a transit terminal.
It sends transit system entry and exit events to the on-card applet for
processing. |
Constructors Summary |
---|
TransitTerminal(String hostName, int hostPort, byte[] staticKeyData)Creates a transit terminal.
super(hostName, hostPort, staticKeyData);
|
Methods Summary |
---|
public static void | main(java.lang.String[] args)Parses and runs the CLI command.
int i = parseCommonArgs(args);
if (i <= 0) {
usage();
System.exit(3);
}
TransitTerminal terminal = new TransitTerminal(hostName, port,
staticKeyData);
terminal.powerUp();
terminal.selectApplet();
terminal.initializeSession();
for (; i < args.length; i++) {
if (args[i].equals("PROCESS_ENTRY")) {
if (++i < args.length) {
short entryStationId = new Short(args[i]).shortValue();
terminal.processEntry(entryStationId);
} else {
usage();
System.exit(3);
}
} else if (args[i].equals("PROCESS_EXIT")) {
if (++i < args.length) {
byte transitFee = new Byte(args[i]).byteValue();
terminal.processExit(transitFee);
} else {
usage();
System.exit(3);
}
} else {
usage();
System.exit(3);
}
}
terminal.powerDown();
System.exit(0);
| private void | processEntry(short entryStationId)Sends a transit system entry event to the on-card applet for processing.
// Request Message: [2-bytes Entry Station ID]
byte[] requestMessage = new byte[2];
copyShort(entryStationId, requestMessage, 0);
// Response Message: [[8-bytes UID], [2-bytes Correlation ID]]
byte[] responseMessage = processRequest(PROCESS_ENTRY, requestMessage);
if (responseMessage != null) {
// Retrieve the UID
byte[] uid = new byte[UID_LENGTH];
System.arraycopy(responseMessage, 0, uid, 0, UID_LENGTH);
// Retrieve the correlation Id
short correlationId = getShort(responseMessage, 2);
System.out.println("processEntry: [" + entryStationId + "] => "
+ "[ " + new String(uid) + ", " + correlationId + "]");
} else {
System.out.println("processEntry: [" + entryStationId + "] => "
+ "error");
}
| private void | processExit(byte transitFee)Sends a transit system exit event to the on-card applet for processing.
// Request Message: [1-byte Transit Fee]
byte[] requestMessage = new byte[1];
requestMessage[0] = transitFee;
// Response Message: [[8-bytes UID], [2-bytes Correlation ID]]
byte[] responseMessage = processRequest(PROCESS_EXIT, requestMessage);
if (responseMessage != null) {
// Retrieve the UID
byte[] uid = new byte[UID_LENGTH];
System.arraycopy(responseMessage, 0, uid, 0, UID_LENGTH);
// Retrieve the correlation Id
short correlationId = getShort(responseMessage, 2);
System.out.println("processEntry: [" + transitFee + "] => " + "[ "
+ new String(uid) + ", " + correlationId + "]");
} else {
System.out.println("processEntry: [" + transitFee + "] => "
+ "error");
}
| private static void | usage()Prints the usage.
commonUsage();
System.out
.println("<command list>: ([PROCESS_ENTRY <entry station id>]|[PROCESS_EXIT <transit fee>])*");
|
|