import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
/**
* Technology class representing MIFARE Classic tags (also known as MIFARE Standard).
*/
public void increment(int blockIndex, int value) throws IOException {
validateBlock(blockIndex);
+ validateValueOperand(value);
checkConnected();
ByteBuffer cmd = ByteBuffer.allocate(6);
+ cmd.order(ByteOrder.LITTLE_ENDIAN);
cmd.put( (byte) 0xC1 );
cmd.put( (byte) blockIndex );
- cmd.putInt(value); // ByteBuffer does the correct big endian translation
+ cmd.putInt(value);
transceive(cmd.array(), false);
}
*/
public void decrement(int blockIndex, int value) throws IOException {
validateBlock(blockIndex);
+ validateValueOperand(value);
checkConnected();
ByteBuffer cmd = ByteBuffer.allocate(6);
+ cmd.order(ByteOrder.LITTLE_ENDIAN);
cmd.put( (byte) 0xC0 );
cmd.put( (byte) blockIndex );
- cmd.putInt(value); // ByteBuffer does the correct big endian translation
+ cmd.putInt(value);
transceive(cmd.array(), false);
}
+ private void validateValueOperand(int value) {
+ if (value < 0) {
+ throw new IllegalArgumentException("value operand negative");
+ }
+ }
+
/**
* Copy from temporary memory to value block.
* @param blockIndex