Class RfidService

java.lang.Object
com.tccc.kos.commons.util.ready.ReadyBean
com.tccc.kos.commons.core.service.AbstractService
com.tccc.kos.ext.freestyle.service.rfid.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

public class RfidService extends com.tccc.kos.commons.core.service.AbstractService
Service to manage rfid scanning. This service allows triggering a single or recurring scan of registered 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 Type
    Method
    Description
    void
    Stop the currently active recurring scan as quickly as possible.
    void
    Add a scan group to the service.
    void
    addScanner(RfidScanner<?> scanner)
    Add a RfidScanner to the default group.
    Return the default scan group.
    void
    performSingleScan(String scanType, Set<RfidTag> gather)
    Perform a single scan of the specified scanType .
    void
    Remove a scan group from the service.
    void
    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

      public RfidScanGroup getDefaultGroup()
      Return the default scan group. This group has a name of "default" and can be scanned using that name or by calling startRecurringDefaultGroup() . The default group only exists for convenience as most applications only use a single group for scanning.
    • addScanner

      public void addScanner(RfidScanner<?> scanner)
      Add a RfidScanner 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

      public void addGroup(RfidScanGroup group)
      Add a scan group to the service.
      Parameters:
      group - the group to add
    • removeGroup

      public void removeGroup(RfidScanGroup group)
      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 for startRecurring("default") .
    • startRecurring

      public void startRecurring(String scanType)
      Start a recurring scan of the specified type. This will continue scanning until stopRecurring() , or startRecurring(null) is called. The scanType 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

      public void performSingleScan(String scanType, Set<RfidTag> gather)
      Perform a single scan of the specified scanType . This will run concurrently with any active scanning. If gather is provided then any tags read during this scan will be added to the gather set.
      Parameters:
      scanType - the type of scan to run
      gather - optional to set hold any tags read