GPS tracker: Configuring the parser for the GPS tracker using the text-formatted data
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 plug-in for Data Logger;
- DDE server plug-in 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 the plain format. Each record has a fixed set of comma-separated values. The data contains no non-printing characters at the beginning and at the end of the line, but it contains characters that are 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. Now you can see that the data packet (in the green rectangle) ends with #0D#0A (underlined in red).
Now we are ready to configure plug-ins. First, please select the "ASCII data parser and query" plug-in (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" plug-in (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 plug-in, 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 plug-in.
Now open the dialog box where you can configure the "ASCII parser and query" plug-in. 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 main window of the program 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.
It is necessary to enable the option in fig. 5 because most GPS trackers run as clients, i.e. they connect to the server, send data and disconnect. Several trackers can be connected to the server simultaneously. Make sure you configure the options specified in the tooltip that appears after you enable this option.
Fig.5. GPS tracker. Parser configuration dialog box.
The next tab is a very important part of the configuration (fig.6). 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). Afterwards these variables will be used in the filter and export plug-ins.
Fig.6. GPS tracker. Parser variables.
You should add all necessary variables by clicking the "Add" button (fig.6, pos.7). 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.6.
Each variable in the parser has several properties:
- Variable name - this name will be displayed in the column in the data export plug-in. 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 plug-in 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.7). Since we set the "String" data type for some variables, the first two options allow us to delete spaces at the beginning and at the end of a value. This tutorial has a variable with the "DATE" and "TIME" type. 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.7. 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 plug-ins.
Now the parser is configured and it is time to test it. Wait till the GPS tracker sends an information packet. If the parser is configured correctly, the variables and their values will be displayed in the DDE server window (fig.8).
Fig.8. GPS tracker. DDE server window.
Now all parser variables are ready for export. To do it, you can use any data export plug-in.