Skip to content

Instantly share code, notes, and snippets.

@Komarev
Created June 2, 2016 09:54
Show Gist options
  • Save Komarev/04a3219ffaf87137698a2219c69e2c82 to your computer and use it in GitHub Desktop.
Save Komarev/04a3219ffaf87137698a2219c69e2c82 to your computer and use it in GitHub Desktop.
public static Observable<String> resetClock(NfcA nfca, long timestamp) {
return Observable.fromCallable(() -> {
prepareToIO(nfca);
writeOperationCommand(nfca,
NfcOperationFactory.getCommandForTimeSetup(timestamp));
//checkForOperationSuccess(nfca); //////////////////
try {
selectSector(nfca, SECTOR_3);
} catch (Exception e) {
throw new NfcOperationException("select sector 3" + e.getMessage());
}
byte[] record = new byte[4];
byte[] command = new byte[] {COMMAND_READ_RECORD, (byte) (249)};
DateTime startTime = DateTime.now().plusSeconds(1);
while (true) {
try {
record = nfca.transceive(command);
} catch (Exception e) {
}
if (startTime.isBeforeNow()) {
throw new NfcOperationException("timed out");
}
if ((record[2] & 8) == 8) {
break;
}
}
////////////////////////////////////////////
return readOperationAnswer(nfca);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment