To work with Deepsy smart card service it is necessary to use DeepsySmartCardManager located in com.gmv.its.deepsy.smartcard for getting the initial SmartCardManager object.
SmartCardManager smartCardManager = DeepsySmartCardManager.getInstance();
DeepsySmartCardManager.getInstance has an optional parameter indicating the ip address of remote service. For instance:
SmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.1.10");
SmartCardManager is an AutoCloseable interface. An object that may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur. To obtain a list of the Smartcard devices objects:
try (SmartCardManager smartCardManager = DeepsySmartCardManager.getInstance()){
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
If this object is not inside a try with resources block, it is recommended to call to smartCardManager.close() in order to finalize properly;
smartCardManager.close();
To detect service availability the DeepsySmartCardManager implements Manager interface which provides methods for getting availability and subscribing to availability events.
class MyManagerObserver implements ManagerObserver{
public void notify(ManagerConnectionEvent event) {
System.out.println(event.getManager().getName() +
" in "+
event.getManager().getIp() +
" "+
event.getAction().toString());
}
}
public class App {
public static void main(String[] args) {
ManagerObserver observer = new MyManagerObserver();
try (SmartCardManager smartCardManager = DeepsySmartCardManager.getInstance()){
smartCardManager.subscribe(observer);
} catch (CannotSubscribeException e1) {
e1.printStackTrace();
}
}
}
Getting available smart card devices, readers and cards
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.Arrays;
import java.util.List;
public class GetSmartCardsApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.238")) {
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
System.out.println(
" |- " + reader.getId());
List<SmartCard> cardList = reader.getSmartCards();
for (SmartCard card : cardList) {
System.out.println(
" |- " + card.getUid());
}
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
}
Remove, set and get MifareClassic keys
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.List;
public class ManageMifareClassicKeysApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.84")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
device.clearMifareClassicKeys();
List<MifareClassicKeyGroup> keyGroupList = new ArrayList<MifareClassicKeyGroup>();
List<MifareClassicKey> keyList = new ArrayList<MifareClassicKey>();
keyList.add(
new MifareClassicKey(
KeyType.KEY_A, 0,
"FFFFFFFFFFFF"));
keyList.add(
new MifareClassicKey(
KeyType.KEY_A, 1,
"FFFFFFFFFFFF"));
keyList.add(
new MifareClassicKey(
KeyType.KEY_A, 2,
"FFFFFFFFFFFF"));
keyList.add(
new MifareClassicKey(
KeyType.KEY_A, 3,
"FFFFFFFFFFFF"));
keyGroupList.add(new MifareClassicKeyGroup(keyList, 1));
device.addMifareClassicKeys(keyGroupList);
List<MifareClassicKeyGroup> keyGroupList2 = new ArrayList<MifareClassicKeyGroup>();
keyGroupList2 = device.getMifareClassicKeys();
for (MifareClassicKeyGroup keygroup : keyGroupList2) {
System.out.println(
"Key group with priority " + keygroup.getPriority());
for (MifareClassicKey key : keygroup.getKeys()) {
System.out.println(
"Index " + key.getIndex() +
" type " + key.getType().toString() +
" key " + key.getKey());
}
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
}
Subscribe to smart card events
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.List;
class SmartCardReaderObserverImpl implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent evt = (SmartCardReaderCardEvent) event;
System.out.println(evt.getAction().toString() +
" card with id " + evt.getSmartCard().getUid());
}
}
}
public class SmartCardEventsApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.109")) {
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new SmartCardReaderObserverImpl());
}
}
Thread.sleep(10000);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Detect and read smart card
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DetectAndReadSmartcardApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.84")) {
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new SmartCardReaderObserverImpl());
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static class SmartCardReaderObserverImpl implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent evt = (SmartCardReaderCardEvent) event;
System.out.println(evt.getAction().toString() +
" card with id " + evt.getSmartCard().getUid());
if (evt.getAction() == SmartCardAction.ADDED) {
List<SmartCardInformationBlock> blockList = new ArrayList<SmartCardInformationBlock>();
if (evt.getSmartCard() instanceof MifareClassicCard) {
MifareClassicCard sm = (MifareClassicCard) evt.getSmartCard();
try {
blockList = sm.readBlocks(Arrays.asList(1, 2, 3));
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
} else if (evt.getSmartCard() instanceof MifareUltralightCard) {
MifareUltralightCard sm = (MifareUltralightCard) evt.getSmartCard();
try {
blockList = sm.readPages(Arrays.asList(4, 5, 6));
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
System.out.println(
"Card content:");
for (SmartCardInformationBlock block : blockList) {
System.out.println(block.getContent());
}
System.out.println(
"-------------");
}
}
}
}
}
Detect and read smart card with specific keys in Mifare Classic (deprecated)
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
class mySmartCardReaderObserver implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent evt = (SmartCardReaderCardEvent) event;
System.out.println(evt.getAction().toString() +
" card with id " + evt.getSmartCard().getUid());
if (evt.getAction() == SmartCardAction.ADDED) {
List<SmartCardInformationBlock> blockList = new ArrayList<SmartCardInformationBlock>();
if (evt.getSmartCard() instanceof MifareClassicCard) {
MifareClassicCard sm = (MifareClassicCard) evt.getSmartCard();
try {
blockList = sm.readBlocksForceKey(Arrays.asList(
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
} else if (evt.getSmartCard() instanceof MifareUltralightCard) {
MifareUltralightCard sm = (MifareUltralightCard) evt.getSmartCard();
try {
blockList = sm.readPages(Arrays.asList(4, 5, 6));
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
System.out.println(
"Card content:");
for (SmartCardInformationBlock block : blockList) {
System.out.println(block.getContent());
}
System.out.println(
"-------------");
}
}
}
}
public class DetectAndReadMifareClassicWithKeysApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.84")){
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new mySmartCardReaderObserver());
}
}
Thread.sleep(120000);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Detect and read smart card with specific priority in Mifare Classic (optimization)
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
class mySmartCardReaderObserverPriority implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent evt = (SmartCardReaderCardEvent) event;
System.out.println(evt.getAction().toString() +
" card with id " + evt.getSmartCard().getUid());
if (evt.getAction() == SmartCardAction.ADDED) {
List<SmartCardInformationBlock> blockList = new ArrayList<SmartCardInformationBlock>();
if (evt.getSmartCard() instanceof MifareClassicCard) {
MifareClassicCard sm = (MifareClassicCard) evt.getSmartCard();
try {
blockList = sm.readBlocksForcePriority(Arrays.asList(
Map.entry(1,2),
Map.entry(2,2),
Map.entry(3,2)));
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
} else if (evt.getSmartCard() instanceof MifareUltralightCard) {
MifareUltralightCard sm = (MifareUltralightCard) evt.getSmartCard();
try {
blockList = sm.readPages(Arrays.asList(4, 5, 6));
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
System.out.println(
"Card content:");
for (SmartCardInformationBlock block : blockList) {
System.out.println(block.getContent());
}
System.out.println(
"-------------");
}
}
}
}
public class DetectAndReadMifareClassicWithPriorityApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.85")){
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new mySmartCardReaderObserverPriority());
}
}
Thread.sleep(120000);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Add a custom media profile and play the existing media profiles in the devices
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.Arrays;
import java.util.List;
public class ManageMediaProfileApp {
public static void main(String[] args) {
List<SmartCardDeviceSound> sounds = Arrays.asList(new SmartCardDeviceSound(2000, 200),
new SmartCardDeviceSound(0, 100), new SmartCardDeviceSound(2000, 200));
List<SmartCardDeviceLed> firstLedList = Arrays.asList(
new SmartCardDeviceLed(SmartCardDeviceLed.LedId.LED1, SmartCardDeviceLed.LedColor.WHITE),
new SmartCardDeviceLed(SmartCardDeviceLed.LedId.LED3, SmartCardDeviceLed.LedColor.WHITE),
new SmartCardDeviceLed(SmartCardDeviceLed.LedId.LED5, SmartCardDeviceLed.LedColor.WHITE));
List<SmartCardDeviceLed> secondLedList = Arrays.asList(
new SmartCardDeviceLed(SmartCardDeviceLed.LedId.LED1, SmartCardDeviceLed.LedColor.NA_COLOR),
new SmartCardDeviceLed(SmartCardDeviceLed.LedId.LED3, SmartCardDeviceLed.LedColor.NA_COLOR),
new SmartCardDeviceLed(SmartCardDeviceLed.LedId.LED5, SmartCardDeviceLed.LedColor.NA_COLOR));
SmartCardDeviceLedGroupState firstLedGroup = new SmartCardDeviceLedGroupState(firstLedList, 200);
SmartCardDeviceLedGroupState secondLedGroup = new SmartCardDeviceLedGroupState(secondLedList, 100);
SmartCardDeviceLedGroupState thirdLedGroup = new SmartCardDeviceLedGroupState(firstLedList, 200);
SmartCardDeviceMediaProfile customProfile = new SmartCardDeviceMediaProfile("Custom_media_profile", sounds,
Arrays.asList(firstLedGroup, secondLedGroup, thirdLedGroup));
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.146")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
device.addMediaProfiles(Arrays.asList(customProfile));
for (SmartCardDeviceMediaProfile mediaProfile : device.getMediaProfiles()) {
"Playing media profile " + mediaProfile.getId() + " for device " + device.getId());
device.playMediaProfile(mediaProfile.getId());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Retrieve PCI reboot time and set a new PCI reboot time while listening to reboot notifications
package com.gmv.its.dpyjavaexamples.smartcard;
import java.time.Instant;
import java.time.ZoneOffset;
class MySmartCardDeviceObserver extends SmartCardDeviceObserver {
@Override
public void notifyPciReboot(SmartCardDeviceRebootEvent event) {
System.out.println(
"Reboot notification: Device " + event.getDevice().getId() +
" is about to reboot at " + event.getPciRebootTime().toString());
}
@Override
public void newUpgradeStatus(SmartCardDeviceUpgradeStatusEvent event) {
}
}
public class ManagePciRebootTimeApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.146")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
device.subscribe(new MySmartCardDeviceObserver());
Instant currentRebootTime = device.getPciRebootTime();
"Current reboot time for device " + device.getId() + " is " + currentRebootTime.toString());
Instant newRebootTime = Instant.now();
newRebootTime = newRebootTime.atZone(ZoneOffset.UTC).withHour(3).withMinute(0).withSecond(0).withNano(0)
.toInstant();
System.out.println(
"Setting reboot time for device " + device.getId() +
" for 3:00 am UTC time" + newRebootTime.toString());
device.setPciRebootTime(newRebootTime);
Instant stablishedRebootTime = device.getPciRebootTime();
"New reboot time for device " + device.getId() + " is " + stablishedRebootTime.toString());
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Set and get Payment App Configuration
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SetGetPaymentConfApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.109")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
System.out.println(
" - " + device.getId());
managePaymentConf(device);
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void managePaymentConf(SmartCardDevice device) {
List<SmartCardPaymentAppConfiguration> configurations = new ArrayList<SmartCardPaymentAppConfiguration>();
try {
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.ACCESS_POINT_CODE, "3"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.ACCESS_POINT_TYPE, "ENT"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.TRANSPORT_OPERATOR_ID, "000201"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.PRICING_PLAN, "101"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.ONLINE_MODE, "0"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.OFFLINE_MODE, "1"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.OFFLINE_BACKUP, "0"));
configurations.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.PRICE,
"0000000001"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.TRANSACTION_MODE_CONF, "432"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.END_OF_DAY_TIME, "2359"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.BLACKLIST, "01"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.BLACK_LIST_UPDATE_TIMER, "30"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.BLACK_LIST_UPDATE_RETRIES, "02"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.BLACK_LIST_TIME_WITHOUT_UPDATES, "02"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.FINANCIAL_BLACK_LIST, "00"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.WHITE_LIST, "00"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.ODA_CARDS, "00"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.PASSBACK_TIMER, "02"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.PASSBACK_NUMBER, "006"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.LANGUAGE, "00"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.DESTINATION_MODE, "000A"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.ROUTE, "ROUTE1"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.TRANSPORT_ZONE, "ZONE1"));
configurations
.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.STOP, "STOP1"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.EMPLOYEE_ID, "EMPLOYEEID1"));
configurations.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.VEHICLE,
"VEHICLE1"));
configurations.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.EXTRA,
"Extra information"));
device.setPaymentAppConf(configurations);
System.out.println(
" setPaymentAppConf correct " + device.getId());
} catch (Exception e) {
System.out.println(
" setPaymentAppConf incorrect " + device.getId());
e.printStackTrace();
}
try {
List<SmartCardPaymentAppConfiguration> configurations_response = device.getPaymentAppConf(configurations);
for (SmartCardPaymentAppConfiguration configuration : configurations_response) {
System.out.println(
"configuration property: " + configuration.getProperty());
System.out.println(
"configuration property: " + configuration.getValue());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Set and Get device network configuration
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.Arrays;
import java.util.List;
public class SetGetDeviceNetworkConfApp {
public static void main(String[] args) {
SmartCardDeviceNetworkConfiguration network_configuration = new SmartCardDeviceNetworkConfiguration(
"192.168.0.236", "255.255.255.0", "192.168.0.1", "8.8.8.8", "0", "Ux410-1");
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.234")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
device.setNetworkConfiguration(network_configuration);
}
for (SmartCardDevice device : smartCardManager.getDevices()) {
SmartCardDeviceNetworkConfiguration network_configurration = device.getNetworkConfiguration();
System.out.println(
" " + network_configurration);
System.out.println(
"LocalIpAddress; " + network_configurration.getLocalIpAddress());
System.out.println(
"Netmask: " + network_configurration.getNetmask());
System.out.println(
"Gateway: " + network_configurration.getGateway());
System.out.println(
"DnsServer: " + network_configurration.getDnsServer());
System.out.println(
"Dhcp: " + network_configurration.getDhcp());
System.out.println(
"HostName: " + network_configurration.getHostName());
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Get device version
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.Arrays;
import java.util.List;
public class GetDeviceVersions {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.109")) {
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
SmartCardDeviceVersion deviceVersion = device.getVersion();
System.out.println(
" ADK Version - " + deviceVersion.getAdkVersion());
System.out.println(
" SDK Version - " + deviceVersion.getSdkVersion());
System.out.println(
" serial Number - " + deviceVersion.getSerialNumber());
System.out.println(
" OS Version - " + deviceVersion.getOsVersion());
System.out.println(
" APP Version - " + deviceVersion.getAppVersion());
System.out.println(
" Payment APP Version - " + deviceVersion.getPaymentAppVersion());
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
}
Get device date and time
APDU Exchange
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
class mySmartCardReaderAPDUExchangeObserver implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent evt = (SmartCardReaderCardEvent) event;
System.out.println(evt.getAction().toString() +
" card with id " + evt.getSmartCard().getUid());
if (evt.getAction() == SmartCardAction.ADDED) {
List<APDUResponse> responses = new ArrayList<APDUResponse>();
SmartCard card = evt.getSmartCard();
if (card instanceof MifareDesfireCard) {
MifareDesfireCard sm = (MifareDesfireCard) card;
try {
List<APDUCommand> commands = new ArrayList<APDUCommand>();
commands.add(new APDUCommand(0x90, 0x60, 0x00, 0x00, "", 0));
responses = sm.apduExchange(commands);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
if (card instanceof SamCard) {
SamCard sm = (SamCard) card;
try {
List<APDUCommand> commands = new ArrayList<APDUCommand>();
commands.add(new APDUCommand(0x90, 0x60, 0x00, 0x00, "", 0));
responses = sm.apduExchange(commands);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
for (APDUResponse response : responses) {
System.out.println(String.format(
"%02X", response.getSw1()) +
":" + String.format(
"%02X", response.getSw2()) +
" " + response.getResponseData());
}
System.out.println(
"-------------");
}
}
}
}
public class APDUExchange {
public static void main(String[] args) {
DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.109");
try {
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new mySmartCardReaderAPDUExchangeObserver());
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
smartCardManager.close();
}
}
Passthrough
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class mySmartCardReaderPassthroughObserver implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent evt = (SmartCardReaderCardEvent) event;
System.out.println(evt.getAction().toString() +
" card with id " + evt.getSmartCard().getUid());
if (evt.getAction() == SmartCardAction.ADDED) {
List<String> responses = new ArrayList<String>();
try {
responses = evt.getSmartCard().sendPasstroughCommands(Arrays.asList("A50101000000", "3901"));
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
for (String response : responses) {
}
System.out.println(
"-------------");
}
}
}
}
public class PassthroughApp {
public static void main(String[] args) {
DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.131");
try {
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new mySmartCardReaderPassthroughObserver());
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
smartCardManager.close();
}
}
Passthrough
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class mySmartCardReaderPassthroughObserver implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent evt = (SmartCardReaderCardEvent) event;
System.out.println(evt.getAction().toString() +
" card with id " + evt.getSmartCard().getUid());
if (evt.getAction() == SmartCardAction.ADDED) {
List<String> responses = new ArrayList<String>();
try {
responses = evt.getSmartCard().sendPasstroughCommands(Arrays.asList("A50101000000", "3901"));
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
for (String response : responses) {
}
System.out.println(
"-------------");
}
}
}
}
public class PassthroughApp {
public static void main(String[] args) {
DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.131");
try {
List<SmartCardDevice> devicesList = smartCardManager.getDevices();
for (SmartCardDevice device : devicesList) {
System.out.println(
" - " + device.getId());
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new mySmartCardReaderPassthroughObserver());
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
smartCardManager.close();
}
}
Emv Transaction
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
class mySmartCardReaderObserver2 implements SmartCardReaderObserver {
public void notify(SmartCardReaderEvent event) {
if (event instanceof SmartCardReaderCardEvent) {
SmartCardReaderCardEvent cardEvt = (SmartCardReaderCardEvent) event;
System.out.println(cardEvt.getAction().toString() +
" card with id " + cardEvt.getSmartCard().getUid());
if (cardEvt.getAction() == SmartCardAction.ADDED) {
if (cardEvt.getSmartCard() instanceof EmvCard) {
EmvCard emvCard = (EmvCard) cardEvt.getSmartCard();
try {
SmartCardCharge charge =
new SmartCardCharge(
"0000000001",
TicketMode.DISABLE_TICKET);
emvCard.requestCharge(charge);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
}
}else if(event instanceof SmartCardReaderEmvEvent) {
SmartCardReaderEmvEvent emvEvt = (SmartCardReaderEmvEvent) event;
SolutionCode code = emvEvt.getChargeResult().getSolutionCode();
try {
EmvCard emvCard = emvEvt.getEmvCard();
emvCard.confirmCharge(true);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
}
}
}
public class EmvTransactionApp {
public static void main(String[] args) {
DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.122");
try {
List<SmartCardDevice> devicesList = new ArrayList<SmartCardDevice>();
devicesList.addAll(smartCardManager.getDevices());
for (SmartCardDevice device : devicesList) {
enablePayment(device);
managePaymentConf(device);
List<SmartCardReader> readersList = device.getReaders();
for (SmartCardReader reader : readersList) {
reader.subscribe(new mySmartCardReaderObserver2());
}
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
smartCardManager.close();
}
public static void enablePayment(SmartCardDevice device) {
SmartCardPaymentAppStatus smartCardPaymentAppStatus =
new SmartCardPaymentAppStatus(SmartCardPaymentWorkMode.GW_DISABLE,
AppStatus.PA_ENABLE);
try {
device.setPaymentAppStatus(smartCardPaymentAppStatus);
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
try {
SmartCardPaymentAppInformation smartCardPaymentAppInformation = device.getPaymentAppInfo();
System.out.println(
"Payment application status:" );
System.out.println(
" - Workmode: " + smartCardPaymentAppInformation.getWorkmode());
System.out.println(
" - FunctionalityIndicator: " + smartCardPaymentAppInformation.getFunctionalityIndicator());
System.out.println(
" - ProtocolVersion: " + smartCardPaymentAppInformation.getProtocolVersion());
System.out.println(
" - Timestamp: " + smartCardPaymentAppInformation.getTimestamp());
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
}
public static void managePaymentConf(SmartCardDevice device) {
List<SmartCardPaymentAppConfiguration> configurations = new ArrayList<SmartCardPaymentAppConfiguration>();
try {
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.ACCESS_POINT_CODE, "3"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.ACCESS_POINT_TYPE, "ENT"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.TRANSPORT_OPERATOR_ID, "000201"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.PRICING_PLAN, "101"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.ONLINE_MODE, "0"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.OFFLINE_MODE, "1"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.OFFLINE_BACKUP, "0"));
configurations.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.PRICE,
"0000000001"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.TRANSACTION_MODE_CONF, "432"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.END_OF_DAY_TIME, "2359"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.BLACKLIST, "01"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.BLACK_LIST_UPDATE_TIMER, "30"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.BLACK_LIST_UPDATE_RETRIES, "02"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.BLACK_LIST_TIME_WITHOUT_UPDATES, "02"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.FINANCIAL_BLACK_LIST, "00"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.WHITE_LIST, "00"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.ODA_CARDS, "00"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.PASSBACK_TIMER, "02"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.PASSBACK_NUMBER, "006"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.LANGUAGE, "00"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.DESTINATION_MODE, "000A"));
configurations.add(
new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.ROUTE, "ROUTE1"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.TRANSPORT_ZONE, "ZONE1"));
configurations
.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.STOP, "STOP1"));
configurations.add(new SmartCardPaymentAppConfiguration(
SmartCardPaymentAppConfiguration.Property.EMPLOYEE_ID, "EMPLOYEEID1"));
configurations.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.VEHICLE,
"VEHICLE1"));
configurations.add(new SmartCardPaymentAppConfiguration(SmartCardPaymentAppConfiguration.Property.EXTRA,
"Extra information"));
device.setPaymentAppConf(configurations);
System.out.println(
" setPaymentAppConf correct " + device.getId());
} catch (Exception e) {
System.out.println(
" setPaymentAppConf incorrect " + device.getId());
e.printStackTrace();
}
try {
List<SmartCardPaymentAppConfiguration> configurations_response = device.getPaymentAppConf(configurations);
for (SmartCardPaymentAppConfiguration configuration : configurations_response) {
System.out.println(
"configuration property: " + configuration.getProperty());
System.out.println(
"configuration property: " + configuration.getValue());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Force upgrade process
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.List;
class SmartCardDeviceObserverImpl extends SmartCardDeviceObserver {
@Override
public void notifyPciReboot(SmartCardDeviceRebootEvent event) {
}
@Override
public void newUpgradeStatus(SmartCardDeviceUpgradeStatusEvent event) {
System.out.println(
"Device " + event.getDevice().getId() +
" upgrade status is " +
event.getStatus());
}
}
public class ForceUpgradeApp {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.125")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
device.subscribe(new SmartCardDeviceObserverImpl());
device.forceDeviceUpgrade();
System.out.println(
"Force Update for device "+ device.getId() +
" requested");
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
} catch (CannotSubscribeException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Test network connectivity
package com.gmv.its.dpyjavaexamples.smartcard;
public class TestNetworkConnectivity {
public static void main(String[] args) {
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.125")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
NetworkConnectivityStatus res = device.testNetworkConnectivity("www.google.es");
System.out.println(
"Test network connectivity OK for device: "+ device.getId());
System.out.println(
"ResolvedIP: "+ res.getResolvedIP());
System.out.println(
"PingTime_ms: "+ res.getPingTime_ms());
}
Thread.sleep(120000);
} catch (SmartCardNotAvailableException e) {
System.out.println(
"SmartCardNotAvailableException: " + e);
} catch (SmartCardLowLevelException e) {
System.out.println(
"SmartCardLowLevelException: " + e);
} catch (InterruptedException e) {
System.out.println(
"InterruptedException: " + e);
}
}
}
Set - Get Device Remote Logging Configuration
package com.gmv.its.dpyjavaexamples.smartcard;
import java.util.Arrays;
import java.util.List;
public class SetGetDeviceLoggingConf {
public static void main(String[] args) {
SmartCardDeviceLoggingConfiguration logging_configuration = new SmartCardDeviceLoggingConfiguration(
SmartCardDeviceLoggingConfiguration.Component.ALL,
SmartCardDeviceLoggingConfiguration.LogLevel.DEBUG,
"192.168.0.125",
7777,
1
);
System.out.println(
"Set Get Device Logging Configuration example " );
try (DeepsySmartCardManager smartCardManager = DeepsySmartCardManager.getInstance("192.168.0.125")) {
for (SmartCardDevice device : smartCardManager.getDevices()) {
System.out.println(
"Setting remote logging configuration for device " + device.getId());
device.setLoggingConfiguration(logging_configuration);
}
for (SmartCardDevice device : smartCardManager.getDevices()) {
System.out.println(
"Retrieving remote logging configuration for device " + device.getId() +
" :");
SmartCardDeviceLoggingConfiguration resultant_configuration = device.getLoggingConfiguration();
System.out.println(
"Component: " + resultant_configuration.getComponent().toString());
System.out.println(
"LogLevel: " + resultant_configuration.getLogLevel().toString());
System.out.println(
"Address " + resultant_configuration.getAddress());
System.out.println(
"Port: " + resultant_configuration.getPort());
System.out.println(
"Reboots until remote logging disabled: " + resultant_configuration.getRebootsUntilLoggingDisabled());
}
} catch (SmartCardNotAvailableException e) {
e.printStackTrace();
} catch (SmartCardLowLevelException e) {
e.printStackTrace();
}
try {
Thread.sleep(120000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}