Class RfidService
- All Implemented Interfaces:
com.tccc.kos.commons.core.context.CtxEventListener
,com.tccc.kos.commons.core.service.handle.ContextHandleAware
,com.tccc.kos.commons.core.service.handle.HandleAware
,com.tccc.kos.commons.util.ready.Ready
,com.tccc.kos.commons.util.ready.ReadyListener
RfidScanner
objects based on a specified scan type. As scanType
is
an arbitrary string that identifies the purpose of the scan.
The scanType
will be provided to callbacks so they can
perform conditional logic based on the type.
RfidScanner
objects are collected into groups and
groups can be tagged with scan types. When performing a scan
with a scanType
, all groups that are tagged with the
scanType
will be run. This will cause all scanners
in the group to be run in the order in which they were added
to the group.
Groups and scan types allow complex scanning policy to be
constructed without having to write custom code. For example,
consider a dispenser with three cartridge shelves, each with
a multi-position antenna. When the door of the dispenser is
open the goal is to scan all shelves sequentially for cartridges.
By added a RfidScanner
for each shelf and adding to a
group, scanning the group will automatically scan all the shelves
in sequence.
Now consider the same dispenser has an antenna on the door which can be used while the door is open to scan product information. This scanner can be added to the group and it will be scanned at after all three shelves are scanned. If lower latency is desired, the same scanner can be added after each shelf scanner, resulting in the door being check three times per group scan, once at the end of each shelf scan.
Now consider that while the door is closed, the door antenna
should be scanned for a product or technician tag. A second
group can be added that only has the door scanner. By tagging
the first group with a scan type of "doorClosed" and the second
group with a scan type of "doorOpen", simply calling
startRecurring()
with the correct scan type will result
in the desired scanning policy.
This service supports both single and recurring scanning. It is
possible to run a single scan while a recurring scan is running.
Scanning callbacks are based on changes in tags. That is, if a
new tag is discovered, or an existing tag is no longer visible,
events are generated and passed to the registered listeners.
When performing a single scan, an optional Set
can be
provided and that will contain all the visible tags during that
scan, even if they've been previously scanned.
Many simple applications may only require a simple scan policy.
To simplify this use case, the service contains a default group
and scanners can be added directly to this group. This group
has a scan type of "default" and can be scanned using this
type or startRecurringDefaultGroup()
can be used.
- Version:
- 2023-10-14
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Stop the currently active recurring scan as quickly as possible.void
addGroup
(RfidScanGroup group) Add a scan group to the service.void
addScanner
(RfidScanner<?> scanner) Add aRfidScanner
to the default group.Return the default scan group.void
performSingleScan
(String scanType, Set<RfidTag> gather) Perform a single scan of the specifiedscanType
.void
removeGroup
(RfidScanGroup group) Remove a scan group from the service.void
startRecurring
(String scanType) Start a recurring scan of the specified type.void
Start a recurring scan of the default group.void
Stop the currently active recurring scan at the end of the current scan.Methods inherited from class com.tccc.kos.commons.core.service.AbstractService
getHandle, getHandlePrefix
Methods inherited from class com.tccc.kos.commons.util.ready.ReadyBean
getReady, onBeanReady, onDependenciesReady
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.context.CtxEventListener
onCtxAutowiringCompleted, onCtxDestroyed, onCtxPhaseCompleted
Methods inherited from interface com.tccc.kos.commons.core.service.handle.HandleAware
addHandleChild, getName, getPath
Methods inherited from interface com.tccc.kos.commons.util.ready.Ready
isReady, setReady
Methods inherited from interface com.tccc.kos.commons.util.ready.ReadyListener
onDependenciesGroupReady
-
Method Details
-
getDefaultGroup
Return the default scan group. This group has a name of "default" and can be scanned using that name or by callingstartRecurringDefaultGroup()
. The default group only exists for convenience as most applications only use a single group for scanning. -
addScanner
Add aRfidScanner
to the default group. Scanners will be run in the order in which they're added, and scanners can be added to the group multiple times. This allows a group to provide fine grained control over scanning order.- Parameters:
scanner
- the scanner to add to the default group
-
addGroup
Add a scan group to the service.- Parameters:
group
- the group to add
-
removeGroup
Remove a scan group from the service.- Parameters:
group
- the group to remove
-
startRecurringDefaultGroup
public void startRecurringDefaultGroup()Start a recurring scan of the default group. This is simply a convenience method forstartRecurring("default")
. -
startRecurring
Start a recurring scan of the specified type. This will continue scanning untilstopRecurring()
, orstartRecurring(null)
is called. ThescanType
can be changed while a recurring scan is in progress. The existing scan will complete and then the next recurring scan will use the new type if applicable.- Parameters:
scanType
- the type of scan to run
-
stopRecurring
public void stopRecurring()Stop the currently active recurring scan at the end of the current scan. -
abortRecurring
public void abortRecurring()Stop the currently active recurring scan as quickly as possible. -
performSingleScan
Perform a single scan of the specifiedscanType
. This will run concurrently with any active scanning. Ifgather
is provided then any tags read during this scan will be added to thegather
set.- Parameters:
scanType
- the type of scan to rungather
- optional to set hold any tags read
-