:tocdepth: 4

.. _configuration:

Configuration
-------------

Overview
++++++++
To configure the Impinj ItemEncode device for operation, the application must 
set the :ref:`DeviceConfig<device-config>`, 
:ref:`AntennasConfig<antennas-config>`, and either the 
:ref:`SerializationJob<serialization-job>` or 
:ref:`InventoryJob<inventory-job>`.

.. include:: ../../../Common/ApiGuide/DeviceConfiguration.rst

Operation Responsibility Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The :ref:`OperationResponsibility<operation-responsibility>` object controls 
which operations this specific ItemEncode device is responsible for. This is 
particularly important in a :ref:`Pipeline System<pipeline-encoding>`, where 
multiple ItemEncode devices could have the same encoding operations. 

Encoding Responsibilities
~~~~~~~~~~~~~~~~~~~~~~~~~
The :ref:`OperationResponsibility<operation-responsibility>` contains several
flags for the encoding responsibilities of this ItemEncode device. Most of these
are simply booleans to indicate whether they should perform the operation or 
not. These include the PC Word, Secure Password, Access Password, Kill Password,
Lock Config, and Tag Specific Feature Config. For the EPC and User Memory 
operations, a mask is used to control the responsibility, with each bit of the 
mask representing a 32 bit block of the operation. For example, if the EPC mask 
is set to 0xC000 with the EPC encoding operation being a 96 bit payload, this 
device will only encode the first 64 bits of that EPC.

.. code-block:: csharp

    DeviceConfig deviceConfig;
    OperationResponsibility operationResponsibility;

    // Write 96 bits of EPC if specified.
    operationResponsibility.EPC_memory_mask = [E000];    
    
    // Write Access Password if specified.
    operationResponsibility.access_password = true;

    deviceConfig.operation_responsibility = operationResponsibility;

Tags In View
~~~~~~~~~~~~
The :ref:`OperationResponsibility<operation-responsibility>` contains a field
for tags in view count. This represents the approximate number of tags in the 
field of view. This parameter is only valid in 
:ref:`Continuous Mode<continuous-mode>`. A report will be sent when a tag is 
removed from a list of this size. A larger number will delay reports, but allow
for retries if a tag remains in the field of view.

Pipelining Responsibilities
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The :ref:`OperationResponsibility<operation-responsibility>` also configures the
ItemEncode :ref:`Pipeline operations<pipeline-encoding>`. It configures which 
devices are downstream, how many tags are in the pipeline, and which device is 
the :ref:`Device Of Record<license-model>`. 

.. code-block:: csharp

    DeviceConfig deviceConfig;
    OperationResponsibility operationResponsibility;
    STPDevice encoderTwo("SpeedwayR-XX-XX-XX");
    STPDevice encoderThree("SpeedwayR-YY-YY-YY");
    STPDevice verifier("SpeedwayR-ZZ-ZZ-ZZ");

    // This is the approximate number of total tags in the ItemEncode pipeline.
    // It should be set to exceed the total number of tags between the first 
    // and last ItemEncode devices.
    operationResponsibility.tag_in_pipeline_view_count = 100;

    // Add the list of downstream ItemEncode devices
    operationResponsibility.downstream_pipeline_devices.add(encoderTwo);
    operationResponsibility.downstream_pipeline_devices.add(encoderThree);
    operationResponsibility.downstream_pipeline_devices.add(verifier);

    // Add the Device of Record. This tells the ItemEncode device where the 
    // encoding volume is maintained. If there is no Device of Record set,
    // the device will assume that it is the Device of Record.
    operationResponsibility.device_of_record(verifier);

    deviceConfig.operation_responsibility = operationResponsibility;


GPI/GPO Configuration
^^^^^^^^^^^^^^^^^^^^^
The :ref:`DeviceConfig<device-config>` object allows the application to 
configure the |project| GPI and GPO settings. The :ref:`GPIConfig<gpi-config>` 
object controls the polarity and the signaling mode for the GPI signals. The 
:ref:`GPOConfig<gpo-config>` controls the polarity, signaling mode, and pulse 
duration of the GPO signals. The :ref:`TriggerConfig<trigger-config>` must also
be set to enable the use of the GPIs as Start and Stop commands.

.. code-block:: csharp

    Device device;
    DeviceConfig deviceConfig;
    GPIConfig gpiConfig;
    GPOConfig gpoConfig;
    TriggerConfig triggerConfig;

    // Separate mode uses unique signals for Start/Stop. 
    // Combined mode uses the polarity of the GPI2 signal for Start/Stop.
    gpiConfig.signaling_mode = GPIO_SIGNAL_MODE_SEPARATE;
    
    gpiConfig.GPI2_polarity = GPIO_POLARITY_ACTIVE_HIGH;
    gpiConfig.GPI3_polarity = GPIO_POLARITY_ACTIVE_HIGH;

    gpoConfig.signaling_mode = GPIO_SIGNAL_MODE_SEPARATE;
    gpoConfig.GPO1_polarity = GPIO_POLARITY_ACTIVE_HIGH;
    gpoConfig.GPO2_polarity = GPIO_POLARITY_ACTIVE_LOW;
    gpoConfig.GPO3_polarity = GPIO_POLARITY_ACTIVE_LOW;

    // Pulse duration is in milliseconds.
    gpoConfig.GPO_pulse_duration = 1;

    // Enable Start and Stop triggers
    triggerConfig.start_trigger_config = StartTriggerConfig();
    triggerConfig.stop_trigger_config = StopTriggerConfig();

    deviceConfig.GPI_config = gpiConfig;
    deviceConfig.GPO_config = gpoConfig;
    deviceConfig.trigger_config = triggerConfig;

    device.SetDeviceConfig(deviceConfig);

GPI
~~~
The GPI signals can be used to trigger a Start or a Stop without sending a 
command over the network. 

.. list-table::
    :header-rows: 1

    * - Signal
      - Separate Signal Mode 
      - Combined Signal Mode
    * - GPI1
      - None
      - None
    * - GPI2
      - Start
      - Active Start | Inactive Stop
    * - GPI3
      - Stop
      - None
    * - GPI4
      - None
      - None

GPO
~~~
The GPO signals provide a notification as to the current state of operations on
the ItemEncode device.

.. list-table::
    :header-rows: 1

    * - Signal
      - Active Meaning
      - Inactive Meaning
    * - GPO1
      - :ref:`Operating State<operating-state>`
      - :ref:`Engaged State<engaged-state>`
    * - GPO2
      - Operation Pass
      - Operation Fail (if COMBINED)
    * - GPO3
      - Operation Fail
      - N/A
    * - GPO4
      - :ref:`Engaged State<engaged-state>`
      - :ref:`Configuration State<configuration-state>`


.. include:: ../../../Common/ApiGuide/AntennaConfiguration.rst

.. _serialization-job-configuration:

Serialization Job Configuration
+++++++++++++++++++++++++++++++
The :ref:`SerializationJob<serialization-job>` configures what the tag should be
encoded with. It is used in :ref:`Encode<encode-mode>`, 
:ref:`Verify Tag Chip Basic<verify-tag-chip-basic-mode>`, and 
:ref:`Verify Tag Chip Data<verify-tag-chip-data-mode>` modes. It can be set 
using the :ref:`AddSerializationJobCommand<add-serialization-job-command>`. 

.. code-block:: csharp

    Device device;
    SerializationJob job;

    job.job_id = 1;
    job.job_type = SERIALIZATION_JOB_TYPE_STATIC;
    job.EPC_memory = EPCMemory();
    
    device.AddSerializationJob(job);

Static Encoding Options
^^^^^^^^^^^^^^^^^^^^^^^
The :ref:`SerializationJob<serialization-job>` is used to set the 
:ref:`Static<static-mode>` encoding operations. 

.. code-block:: csharp

    Device device;
    SerializationJob job;

    // EPC encoding operations
    job.EPC_Memory = EPCMemory();

    // Data to write to user memory data bank
    job.user_memory = UserMemory();

    // If tag has it's access password already set, set it here to open the tag
    job.secure_password = Password();

    // Data to write to the access password field
    job.access_password = Password();

    // Data to write to the kill password field
    job.kill_password = Password();

    // Payload for the Lock command
    job.lock_config = LockConfig();

    device.AddSerializationJob(job);

TID Table/Ordered List Options
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The :ref:`SerializationJob<serialization-job>` can also be used to set an 
initial :ref:`TID Table<tid-table-mode>` or 
:ref:`Ordered List<ordered-list-mode>`.

.. code-block:: csharp

    Device device;
    SerializationJob job;

    job.job_type = SERIALIZATION_JOB_TYPE_TID_TABLE;

    // Set the max TID table size
    job.TID_table_size = 100;

    // Add a couple TID table entries.
    job.tid_table_entries.add(TIDTableEntry());
    job.tid_table_entries.add(TIDTableEntry());

    job.AddSerializationJob(job);

.. code-block:: csharp

    Device device;
    SerializationJob job;

    job.job_type = SERIALIZATION_JOB_TYPE_ORDERED_LIST;

    // Add a couple Ordered List Entries
    job.ordered_list_entries.add(OrderedListEntry());
    job.ordered_list_entries.add(OrderedListEntry());

    job.AddSerializationJob(job);

.. _serialization-filters:

Serialization Filters
^^^^^^^^^^^^^^^^^^^^^
If there is a need to limit encoding operation to a specific TID or EPC pattern,
a :ref:`Filter<filter>` can be used to ensure that ItemEncode is only operating 
on tags that match that pattern. This can be accomplished by setting the 
:ref:`SerializationJobFilters<serialization-job-filters>`. If any filter is set,
then a tag must match at least one filter for encoding operations to proceed.
Else, a :ref:`TagOperationResult<tag-operation-result>` of 
TAG_OPERATION_RESULT_FAIL_FILTER_NO_MATCH will be reported.

.. code-block:: csharp
    
    Device device;
    SerializationJob job;
    Filter tidFilter;
    Filter epcFilter;
   
    // Match the second word to 1160
    tidFilter.data = [E2801160];
    tidFilter.mask = [0000FFFF];
    tidFilter.word_offset = 0;

    // Match the third word (zero-based) to BEEF
    epcFilter.data = [BEEF];
    epcFilter.mask = [FFFF];
    epcFilter.word_offset = 2;

    // Add the filters to the SerializationJob
    job.filters.tid_filters.add(tidFilter);
    job.filters.epc_filters.add(epcFilter);
    
    job.AddSerializationJob(job);


