DB Tracking

This page has been updated on the 26 May 2010.
Information validated on 2.4.0 framework.

Objective

The purpose of the dbTracking component is to get/set databases which will be automatically recorded in DataRecorder and sent by DataEmitter.
This will be done in several steps :

  • STEP 1 : The database
  • STEP 2 : The integrated tracking system
  • STEP 3 : Set a DB variable
  • STEP 4 : Manual record

Preliminary step

Create a non graphical component called dbTracking with the package name : com.training.dbTracking, and create an Initial class.

Step 1 : The database

The database is actually represented as a hash table with a Name and a Value, Name has a maximum size of 64 bytes and Value has a maximum size of 128 bytes. DB variables are used as state machines of the component, each component define databases in order to print their state. For more information about those MDI databases, take a look at the documentation section (DB Variables).

Two ways for database management exist:

  • DB components
  • JCPN file functionality

Databases can be used to check, retrieve or exchange data. But they are mainly used in Morpheus integrated tracking system.

Step 1 : The integrated tracking system

Our tracking system is composed of two components :

  • DataRecorder, recording the data according to a parameter table, and saving it in a PDM.
  • DattaEmitter, formating and sending the data to a server.

DataRecorder

DataRecorder’s job is to record data into a PDM using a parameter table:

  • fieldName : the name of the DB we want to record (e.g.: MDI_GPS_SPEED, MODEM_ROAMING, etc…)
  • fieldSize : the maximum size of the data to send.
  • fieldType : the type of data (-1 : UNKNOWN; 0 : BOOLEAN; 1 : INTEGER; 2 : DECIMAL; 3 : STRING; 4 : BASE64 binary)
  • fieldPeriod : the send period of the data (-1 to disable; 0 for each change; >0 for a period in seconds; <-1 for using a specific RecordingPolicy)

A recording policy already exists, but you can create your own. You will need to create a class which implements the RecorderPolicy interface. When a RecordPolicy implementation is set, the mustRecord() method is called every second and must return whether you want to record or not. Many operations can be done inside this method: check ignition, time, speed, weather, temperature, brightness and finally return the right value depending of the data you want.

DataRecorder simulator settings configuration:

  • dataRecorder.active=1
  • dataRecorder.fieldName[210]=TRAINING_DATA_1
  • dataRecorder.fieldSize[210]=50
  • dataRecorder.fieldType[210]=3
  • dataRecorder.fieldPeriod[210]=10

With these parameters, the DataRecorder will record every 10 seconds the DB variable TRAINING_DATA_1 which is a string of a maximum of 50 bytes.

By launching this configuration in the simulator and you will see this message every 10 second:

[…]
2010-XX-XX XX:XX:XX L[j$com/mdi/services/dataRecorder$0] DataRecorder_impl:recordRuleMultiple(RecordRule, int): record string/binary: 210 length is (21)
[…]

Note :

  • The DataRecorder.fieldPeriod[X] at 0 doesn’t work in the simulator, so you need to use it on a device.
  • The free table parameters range is from 208 to 250.

DataEmitter

DataRecorder’s job is formating the data from the PDM and send it via a managed connection.
It uses two sub-classes :

  • DataFormatter, managing the data format.
  • DataProtocol, managing the connection and the data sent.

By changing this DataFormatter and DataProtocol, you can manage different protocols:

  • MDI20 protocol (ASN.1) by choosing BinaryDataFormatter and BinaryDataProtocol
  • Header protocol (text) by choosing FrameDataFormatter and TcpDataProtocol
  • Custom protocol by implementing DataFormatter and DataProtocol

For more information and examples, please contact support@mobile-devices.fr.

DataEmitter simulator settings configuration:

  • dataEmitter.active=1
  • dataEmitter.period=0

With these parameters, the DataEmitter will send data when available.

If you use MDI20 protocol (ASN.1) you will also need to set the server url and port :

  • binaryGate.url[0]=XXX.XXX.XXX.XXX
  • binaryGate.port[0]=XXXX

Step 3 : Set a DB variable

To test the tracking system, we will set a DB variable (as we set the DataEmitter to send DB variables as soon as they change, see Step 2: The integrated tracking system).

  1. Open the JCPN file.
  2. Add required interfaces GPS and Modem.
  3. Click on DB Variables, then add.
  4. Click on “newDbEntry” and change the name to TRAINING_DATA_1 and type to String.
  5. Save your JCPN.

To change the DB variable, we will use Component methods.

  Component _cpn = null;
  Modem _mod = null;
  Gps _gps = null;

  public void start()
  {
    _cpn = Component.getInstance();
    _mod = _cpn.getModem();
    _gps = _cpn.getGps();

    new Thread(this).start();
  }
  
  public void run()
  {
    int count = 0;
    String tmp = "";
	while(true)
	{
      tmp=""count+"|"+_gps.getSatNumber()+"|"+_gps.isRTCsynchronized()+"|"+_mod.isRoaming()+"|"+_mod.isPPPConnected();
      _cpn.setDB_TRAINING_DATA_1(tmp);
      
      try {Thread.sleep(10000);} 
      catch (InterruptedException e) {e.printStackTrace();}
    }
  }

So every 10 second we change the DB value and the DataRecorder automatically catch the change. The DataEmitter will send it to the server according to the defined period. This example shows the easiest way to add custom information to the Morpheus tracking system: created and modifying DB variables.

Note :

  • A DB variable is not sent if the value didn’t change, to avoid sending unnecessary data.
  • Each DB variable is recorded with the current latitude, longitude and timestamp.

Step 4 : Manual record

Another solution to send data using the Morpheus tracking system is to record it manually using the record() method of the DataRecorder component.

You can modify the source code as follows :

  Component _cpn = null;
  DataRecorder _dr = null;
  Modem _mod = null;
  [...]
      tmp=""count+"|"+_gps.getSatNumber()+"|"+_gps.isRTCsynchronized()+"|"+_mod.isRoaming()+"|"+_mod.isPPPConnected();
      _dr.record(210, 3, tmp.length, tmp);
      
      try {Thread.sleep(10000);} 
  [...]

This will directly add “tmp” with fieldId 210 which is a String of tmp’s size.