Back to contents pageHow to change tag update rates using the API

How to change tag update rates using the API

Summary

This article shows you how to change tag update rates using the API.



Prerequisites

None. You can use this article on its own.



Example material

Save this link to get a zip file of the example material


Guide

Before you start, remember:



This guide shows you how to change tag update rates programmatically. Tags are normally configured to update at a slower rate when they are not moving, and a faster rate when they are moving. This behaviour is easily set up in Location Engine Configuration. This article is intended for applications that require tag update rates to be calculated on the fly as your application is running.


1) Create the schema clients

There are 2 schemas that are relevant: Ubisense.ULocationEngine.TagConfigurationUpdate and Ubisense.ULocationEngine.TagConfiguration . The tag configuration update schema contains remote operations that you can use to update the relations in the tag configuration schema.


    // Create an event client for the
    // ULocationEngine.TagConfigurationUpdate schema
    Ubisense.ULocationEngine.TagConfigurationUpdate.Schema
        tag_config_update_schema = new
        Ubisense.ULocationEngine.TagConfigurationUpdate.Schema(true);

    // Create a caching client for the
    // ULocationEngine.TagConfiguration schema
    Ubisense.ULocationEngine.TagConfiguration.Schema
        tag_config_schema = new
        Ubisense.ULocationEngine.TagConfiguration.Schema(false);

    // Connect as a client to the schemas
    tag_config_update_schema.ConnectAsClient();
    tag_config_schema.ConnectAsClient();



2) Read the TagHasParameters relation

The TagHasParameters relation in the tag configuration schema contains fields for both the filter used and the update rate parameters. In this example, we do not want to change the filter that is used. We do want to change the update rates, which are stored in the "QoS" field.

Therefore, the first task is to find the filter that is used by reading the local cache:


    using (Ubisense.ULocationEngine.TagConfiguration.ReadTransaction xact =
        tag_config_schema.ReadTransaction())
    {
        string filter = "Default no filtering";

        foreach (Ubisense.ULocationEngine.TagConfiguration.TagHasParameters.RowType row in
            Ubisense.ULocationEngine.TagConfiguration.TagHasParameters.tag_(xact, _tag))
        {
            filter = row.filter_;
        }



3) Update the TagHasParameters relation

Now use the tag configuration update schema to update the TagHasParameters relation with a new row for the tag. This example shows the use of insert_tag_parameters. You can also insert parameters for a range of tags using insert_tag_range_parameters. In the attached example, _tag, _lower, _upper and _speed_threshold are inputs provided by the caller of the method.


        // The list of errors, for example setting the lower rate to be
        // higher than the upper rate, choosing a rate that is not implemented,
        // or specifying a filter name that does not exist.
        List<string> errors;

        // Create the new QoS field.
        // _speed_threshold is the threshold (m/s) at which we switch between the rates
        // _lower and _upper are the rate specifiers for the lower and upper rates
        // respectively. The following rate specifiers are allowed:

        /*  Rate specifier             QoS
         *
         *        2         one update every 4 time slots
         *        3         one update every 8 time slots
         *        4         one update every 16 time slots
         *        5         one update every 32 time slots
         *        6         one update every 64 time slots
         *        7         one update every 128 time slots
         *        8         one update every 256 time slots
         *        9         one update every 512 time slots
         *       10         one update every 1024 time slots
         *       11         one update every 2048 time slots
         *       12         one update every 4096 time slots
         *       13         one update every 8192 time slots
         */

        Ubisense.ULocationEngine.QoS qos = new
            Ubisense.ULocationEngine.QoS(_lower, _upper, _speed_threshold);

        // Use the tag_config_update_schema to update the tag parameters.
        // In this example, the filter is kept the same and the QoS is changed.
        tag_config_update_schema.insert_tag_parameters(_tag, filter, qos, out errors);

        foreach (string error in errors)
        {
            Console.WriteLine(error);
        }
    }





Back to top