public CEPASPurse getPurse(int purseId) throws IOException { try { byte[] purseBuff = sendRequest((byte) 0x32, (byte) (purseId), (byte) 0, (byte) 0, new byte[] {(byte) 0}); if (purseBuff != null) { return new CEPASPurse(purseId, purseBuff); } else { return new CEPASPurse(purseId, "No purse found"); } } catch (CEPASException ex) { Log.w(TAG, "Error reading purse " + purseId, ex); return new CEPASPurse(purseId, ex.getMessage()); } }
public CEPASHistory getHistory(int purseId, int recordCount) throws IOException { try { byte[] fullHistoryBuff = null; byte[] historyBuff = sendRequest( (byte) 0x32, (byte) (purseId), (byte) 0, (byte) 1, new byte[] {(byte) 0, (byte) (recordCount <= 15 ? recordCount * 16 : 15 * 16)}); if (historyBuff != null) { if (recordCount > 15) { byte[] historyBuff2 = null; try { historyBuff2 = sendRequest( (byte) 0x32, (byte) (purseId), (byte) 0, (byte) 1, new byte[] {(byte) 0x0F, (byte) ((recordCount - 15) * 16)}); } catch (CEPASException ex) { Log.w(TAG, "Error reading 2nd purse history " + purseId, ex); } fullHistoryBuff = new byte[historyBuff.length + (historyBuff2 != null ? historyBuff2.length : 0)]; System.arraycopy(historyBuff, 0, fullHistoryBuff, 0, historyBuff.length); if (historyBuff2 != null) System.arraycopy( historyBuff2, 0, fullHistoryBuff, historyBuff.length, historyBuff2.length); } else { fullHistoryBuff = historyBuff; } } if (fullHistoryBuff != null) { return new CEPASHistory(purseId, fullHistoryBuff); } else { return new CEPASHistory(purseId, "No history found"); } } catch (CEPASException ex) { Log.w(TAG, "Error reading purse history " + purseId, ex); return new CEPASHistory(purseId, ex.getMessage()); } }