/*
*/
/**
*
* @author Sebastien Riou
*/
package uk.co.nimp.scard;
import javax.smartcardio.CardNotPresentException;
import uk.co.nimp.scard.log.ScardPrintStreamLogHandler;
import com.atolsystems.atolutilities.AStringUtilities;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.smartcardio.CardException;
import uk.co.nimp.smartcard.Apdu;
import uk.co.nimp.smartcard.UnexpectedCardResponseException;
import static uk.co.nimp.scard.MP300TC2TerminalManager.*;
import static uk.co.nimp.scard.MP300Exception.*;
//don't use that, under construction...
@Deprecated
class MP300TC2Terminal extends MP65Terminal {
MP300TC2Terminal(int deviceId, int couplerId, String name, byte[] host) {
super(deviceId, couplerId, name, host);
}
public static void main(String[] args) throws ScardException, CardException {
//create a thread, as recommended by micropross support for stack overflow problems
Thread testThread = new Thread() {
@Override
public void run() {
{
try {
MP300TC2TerminalManager.initContext();
MP300TC2TerminalManager manager = new MP300TC2TerminalManager();
List<GenericTerminal> terminals = manager.list();
MP300TC2Terminal terminal = (MP300TC2Terminal) terminals.get(0);
terminal.addLogHandler(new ScardPrintStreamLogHandler(System.out));
System.out.println("Try to connect to " + terminal.getName());
terminal.coldConnect();
Apdu apdu = new Apdu(0x00, 0x8A, 0x00, 0x44, 0x02);
terminal.sendApdu(apdu);
//manager.batchInterfaceTest();
spyTest(terminal);
} catch (ScardException ex) {
Logger.getLogger(MP300TC2Terminal.class.getName()).log(Level.SEVERE, null, ex);
} catch (CardException ex) {
Logger.getLogger(MP300TC2Terminal.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
testThread.start();
}
static void spyTest(MP300TC2Terminal terminal) throws ScardException, UnexpectedCardResponseException, CardNotPresentException {
int status = 0;
status = win32Mp300ComDll.MPS_LogClockSelect(terminal.couplerId, INTERNAL_CLOCK_MODE);
if (RET_OK != status) {
throw new ScardException("MPS_LogClockSelect returned " + status);
}
status = win32Mp300ComDll.MPS_SetClkDiv(terminal.couplerId, CLOCK_DIV_8192);
if (RET_OK != status) {
throw new ScardException("MPS_SetClkDiv returned " + status);
}
String fileName = "C:\\tc3Spy.log";
status = win32Mp300ComDll.StartDownloadTo(terminal.couplerId, AStringUtilities.StringToBytes(fileName));
if (RET_OK != status) {
throw new ScardException("StartDownloadTo returned " + status);
}
status = win32Mp300ComDll.MPS_OpenLog(terminal.couplerId, EN_C1 | EN_C2 | EN_C3 | EN_C7 | EN_CHAR_ISO | EN_ETU, 0);
if (RET_OK != status) {
throw new ScardException("MPS_OpenLog returned " + status);
}
Apdu apdu = new Apdu(0x00, 0x8A, 0x00, 0x44, 0x02);
terminal.sendApdu(apdu);
status = win32Mp300ComDll.MPS_CloseLog(terminal.couplerId);
if (RET_OK != status) {
throw new ScardException("MPS_CloseLog returned " + status);
}
status = win32Mp300ComDll.MPS_EndDownload(terminal.couplerId);
if (RET_OK != status) {
throw new ScardException("MPS_EndDownload returned " + status);
}
}
}