java.lang.Object
com.pi4j.crowpi.components.internal.rfid.RfidCard
- Direct Known Subclasses:
Mifare1K
Abstract base class to be implemented by all supported RFID cards.
Provides various helper methods to abstract away internal details of various PICC types.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRfidCard
(RfidCardUid uid) Creates a new RFID card instance for the given PICC UID. -
Method Summary
Modifier and TypeMethodDescriptionabstract int
Returns the maximum capacity in bytes this card can store.Returns the human-readable serial of this card, based on the UID.protected RfidCardUid
getUid()
Returns the UID of this card.protected abstract byte[]
Reads all available blocks from the card and returns a byte array.Reads a single Java object from the card without casting the result into a more-specific type.<T> T
readObject
(Class<T> type) Reads a single Java object from the card by deserializing a GZIP-compressed byte stream previously written onto the card.protected abstract void
writeBytes
(byte[] data) Writes the given data to the card, using as many blocks as needed.void
writeObject
(Object data) Stores a single Java object onto the card by serializing the passed object and writing a GZIP-compressed byte stream.
-
Field Details
-
logger
Logger instance
-
-
Constructor Details
-
RfidCard
Creates a new RFID card instance for the given PICC UID.- Parameters:
uid
- UID of PICC
-
-
Method Details
-
getSerial
Returns the human-readable serial of this card, based on the UID.- Returns:
- Human-readable card serial
-
writeObject
Stores a single Java object onto the card by serializing the passed object and writing a GZIP-compressed byte stream. While this method may be called multiple times, only a single object can be stored at once on the card. Please note that the capacity of RFID cards is limited, so this command might fail if the given object is too large.- Parameters:
data
- Serializable object to be stored on card- Throws:
RfidException
- Object serialization or write process failed
-
readObject
Reads a single Java object from the card without casting the result into a more-specific type.- Throws:
RfidException
- See Also:
-
readObject
Reads a single Java object from the card by deserializing a GZIP-compressed byte stream previously written onto the card. This method can only read a single object from the card, so calling it multiple times results in the same value every time. The deserialized object is automatically casted into the giventype
to simplify usage.- Type Parameters:
T
- Target type for deserialized object, determined bytype
parameter.- Parameters:
type
- Class instance of target type for deserialized object- Returns:
- Deserialized object read from card
- Throws:
RfidException
- Object deserialization or read process failed
-
getUid
Returns the UID of this card.- Returns:
- Card/PICC UID
-
getCapacity
public abstract int getCapacity()Returns the maximum capacity in bytes this card can store. This method should already subtract all unavailable blocks / sectors, e.g. trailer blocks.- Returns:
- Maximum capacity in bytes
-
readBytes
Reads all available blocks from the card and returns a byte array. This method targets the same blocks aswriteBytes(byte[])
does.- Returns:
- Byte array of available data on card
- Throws:
RfidException
- Reading data from card failed
-
writeBytes
Writes the given data to the card, using as many blocks as needed. This method will only write to safe blocks and does not overwrite any internal blocks.- Parameters:
data
- Data to write to the card- Throws:
RfidException
- Writing data to card failedIllegalArgumentException
- Given data exceeds card capacity
-