GPS tracker: Configuring the parser for the GPS tracker with text-formatted data packets
We need to process data packets from a vehicle tracker (GPS tracker). The tracker uses the plain ASCII format and does not require data receipt confirmation from the server. Sample information packet:
The tracker sends data in one line without carriage returns. The documentation from the manufacturer contains information about the format of an information packet:
- GPS Tracker Data Logger Professional or the trial version;
- ASCII data parser and query plugin for Data Logger;
- DDE server plugin for the logger (optional, for testing purposes).
It is assumed that:
You have configured the device connection parameters, for example, activated the TCP/IP server mode.
You can see in the picture above that the data is in plain text format. Each record has a fixed set of comma-separated values. The data contains no non-printing characters at the beginning and the end of the line, but it contains characters always added at the beginning of each data packet. You can see that each data packet (one in a line) is started with "&REPORT". It is necessary to determine the characters that end a data packet (if there are any) by which the program will be able to single out a data packet from the general flow. Please enable displaying non-printing characters with the code below 0x20h. To do it, select the options from the picture below.
Fig.1. Data view settings
Then click the "OK" button and wait till you receive data from the GPS tracker. Received data will look like in the picture below.
Fig.2. GPS tracker. Received data.
It is another view of received data. All non-printing characters have been replaced with their code in the form of #0D. You can see that the data packet (in the green rectangle) ends with #0D#0A (underlined in red).
Now we are ready to configure plugins. First, please select the "ASCII data parser and query" plugin (fig.3a, pos.1) from the drop-down list. After that, select the "Analyze and export received data" checkbox (fig. 3a, pos. 2). The "DDE server" plugin (fig.3b, pos.3) will help you make sure that the parser parses the data packet correctly. After you finish configuring the program, you can disable it to save resources. Also, you can activate any data export plugin, for example, for writing data from the tracker to the database.
Fig.3a. GPS tracker. Parser activation.
Fig.3b. GPS tracker. Selecting the data export plugin.
Now open the dialog box where you can configure the "ASCII parser and query" plugin. To do it, click the "Configure" button next to the drop-down list (fig.3a, pos.1). The configuration dialog box will appear on the screen (fig.4).
Fig.4. GPS tracker. Parser configuration dialog box.
You should specify the characters that start and end a data packet in this dialog box. You must enter the data in the same form they appear in the program's main window in fields 1 and 2. Field 1 sets the beginning of a data packet (you should enter "&REPORT,") while field 2 sets its ending (#0D#0A). Use the "Timeout" field (fig.4 pos.3) to specify the necessary timeout the parser will wait for the ending of a packet. It is necessary to prevent the parser from freezing in those cases when it receives the beginning of a packet and does not receive the ending of a packet.
The next tab is a very important part of the configuration (fig.5). We know the format of the data packet. Now, we need to specify for the parser how to parse the data packet into separate values (variables). Afterward, these variables will be used in the filter and export plugins.
Fig.5. GPS tracker. Parser variables.
You should add all necessary variables by clicking the "Add" button (fig.5). The program will ask you to enter a description for the variable before it adds it. You can enter any description that will help you remember what this variable means. We have added all variables with the corresponding descriptions in fig.5.
Each variable in the parser has several properties:
- Variable name - this name will be displayed in the column in the data export plugin. This name must consist of only Latin letters and digits;
- Data processing type - the program will use this method to single out variables from data packets. When a comma separates all values in the data packet (like in this case), you can use the "Separated" method.
- Data type - variable data type. Our example will use the following data types: FLOAT, DATE, TIME, INTEGER, and STRING. The plugin allows you to determine some options that will be used for conversion (see the "Data Format" tab);
- Default value - this value will be used when data cannot be extracted from the specified position and converted into the specified data type;
- Field separator - this character separates values in the data packet. It is a comma in this tutorial;
- Number - this number is the position of the value in the data packet. Since the "&REPORT," part of the packet is used as the data packet identifier and the "Parse packets completely" option is disabled in fig. 4, this part is dropped and does not take part in further processing. That is why the numbering starts with 1 in this example.
You can specify the main options of value format and conversion on the next tab (fig.6). Since we set the "String" data type for some variables, the first two options allow us to delete spaces at the beginning and the end of a value. This tutorial has a variable with the "DATE" and "TIME" types. So the second option allows us to specify the mask that will be used to convert the string data or time value into a variable of the corresponding data type. Please see the help file for a more detailed description of characters that can be used in the mask.
Fig.6. GPS tracker. Formatting the variables.
Please click the "OK" button in the parser configuration dialog box and the "OK" button in the configuration window for the program to enable all the configured plugins.
Now the parser is configured, and it is time to test it. Wait till the GPS tracker sends an information packet. If the parser works correctly, the program will display variables and their values in the DDE server plugin window (fig.7).
Fig.7. GPS tracker. DDE server window.
Now all parser variables are ready for export. To do it, you can use any data export plugin.