Activation of an output line when the device enters one of the geozones.
The list of geozones can exceed 1000 items.
Main:
Program File
Example Configuration for S-2651 Device
Additional:
Utility for Converting Geozone Lists to .INT File
Example KML File with Geozones for Conversion
Example TXT File with Geozones for Conversion (in archive)
Example XML File with Geozones for Conversion
The geozone list is represented as a file with an array of int32 values.
The file is placed in the root directory of the SD card (therefore, the program can only be used with devices that support working with an SD card).
The
.INTfile with the geozone list has a binary format. Therefore, a special programgeozone_to_int_converter.exeis provided for its creation, which allows converting geozone lists from formats convenient for human perception into a binary.INTfile.
The program ensures the device works with a list of geozones (geozone shape - circle). It checks whether the device's coordinates belong to at least one geozone from the list.
Geozone processing speed 300 items/sec.
Each time after checking the entire list, the position is recorded:
Also, the fact of position change is recorded:
In the test program, depending on the position, output control is performed:
| Inside | ➜ | Output 1 = ON |
| Outside | ➜ | Output 1 = OFF |
Convert the geozone list to an .INT file using the utility geozone_to_int_converter.exe
Remember the number of geozones that will be obtained as a result of the program's operation.
This value will need to be entered in the settingInt32 p1
Place the CExxxx.INT file in the root of the SD card.
If the file name differs from
CE0001.INT, then this must be specified in the settingInt32 p0

Configure Output 1 as "General Purpose"


An example of loading a program into a device is described in this article
Set the necessary settings for the program to work.

A detailed description of the program settings is provided below in the corresponding section

| Parameter in Configuration | int32_p0 |
| Associated Variable | GZ_INT_ARR_ID |
| Description | Identifier of the .INT array on the SD card |
| Default | 1 |
| Value Range | 1 .. 65535 (if 0 in configuration, the default value is used) |
The identifier determines the filename on the SD card with the geozone list.
The filename must be in the format CExxxx.INT, where xxxx is GZ_INT_ARR_ID in hexadecimal:
| GZ_INT_ARR_ID = 1 | ➜ | CE0001.INT |
| GZ_INT_ARR_ID = 300 | ➜ | CE012C.INT |
| Parameter in Configuration | int32_p1 |
| Associated Variable | GZ_MAX_COUNT |
| Description | Software limit for the geozone list |
| Default | 1000 |
| Value Range | 1 .. 2147483647 (if 0 in configuration, the default value is used) |
To ensure maximum processing speed, this value must match the actual number of geozones in the file.
The program checks this limit during work with the list. And if the number of the read geozone exceeds this setting, the program will prematurely interrupt the file search and start from the beginning.
If the limit is not reached, the program reads geozones until the end of the file.
| Parameter in Configuration | int32_p2 |
| Associated Variable | GZ_RADIUS_METERS |
| Description | Radius of each geozone in meters |
| Default | 3000 |
| Value Range | 1 .. 2147483647 (if 0 in configuration, the default value is used) |
The geozone list contains only the coordinates of the circle centers.
The program takes the geozone radius from this variable.
| Parameter in Configuration | bool_p0 |
| Associated Variable | OUTSIDE_STATE |
| Description | State of output line #1 if the object is OUTSIDE |
| Default | 0 |
| Value Range | 0 .. 1 |
This setting allows inverting the logic of output line activation depending on the device's position.
If OUTSIDE_STATE = 0, then the output is OFF OUTSIDE and ON INSIDE.
If OUTSIDE_STATE = 1, then the output is ON OUTSIDE and OFF INSIDE.
| Associated Variable | gz_id_active |
| Description | Identifier of the current active geozone. If 0, the device is OUTSIDE |
| Transmit as | 2 or 4 byte parameter |
| Variable Type | I32 |
| Associated Variable | gz_id_last |
| Description | Identifier of the last active geozone. If 0, the device has not visited any geozones |
| Transmit as | 2 or 4 byte parameter |
| Variable Type | I32 |
| Associated Variable | err_total |
| Description | Counter of SD card operation errors. If the value is greater than 0, there were errors reading data from the SD card since the last device power-on |
| Transmit as | 2 or 4 byte parameter |
| Variable Type | I32 |
none
none

At the very beginning of the program, in the "+" branch of the on startup condition, variables are restored from the configuration and telemetry. These conditions are executed once when the device is turned on.

The enable GZ scan condition opens the logic branch that performs reading of geozones on the SD card and subsequent control of the output line.
The condition is added to explicitly separate the program logic into a separate branch (this is clear and allows combining several programs into one).

This part of the program performs the basic logic of working with the SD card and checking whether the device is inside one of the geozones.
Separately, we note the error actions block. It counts errors when working with the SD card for convenient diagnostics of the program's operation.
If the error is one-time, it will simply be counted and saved in the variable err_total.
If several errors occur in a row, the program sets the flag had_err_series and tries to start reading the list from the very beginning. For convenience of diagnostics, this flag is reset only when the device is turned on.
The number of errors to set the flag had_err_series is set by the variable MAX_ERR_SERIES (by default, the variable value is 5 ).

In this part, under the on new cycle condition, service functions and user logic processing are performed. The on new cycle condition is executed after reading the entire geozone list (i.e., first the ENTIRE list is analyzed, and then the actions are performed).
In the SERVICE_2 block, variables are written to user parameters for saving in telemetry and transmission to the server.
Next, there are a series of "template" branches for implementing user logic.
Inside the "templates", you can insert several blocks or entire branches of user logic.
To avoid damaging the program structure, it is recommended to follow the rules:
➜ do not change existing variables
➜ any branches MUST NOT bypass the INIT block
The on ENTRY branch is executed upon entry into a geozone.
This is a short-term event that is activated at the moment of entry.
The on CHANGE branch is executed when two conditions are met simultaneously:
This is a short-term event that is activated at the moment of entry into a new geozone.
The on EXIT branch is executed upon exit from a geozone.
This is a short-term event that is activated at the moment of exit.
The OUTSIDE block is executed each time if the device is outside a geozone.
In the test program, the output value is set here:

The INSIDE block is executed each time if the device is inside a geozone.
In the test program, the output value is set here:

The program logic is built in such a way that all geozones are perceived as a single space.
Therefore, the ON_ENTER and ON_EXIT branches will not trigger if the device moves from one geozone to another.
For example, if geozones overlap each other.