~ubuntu-branches/ubuntu/natty/mtkbabel/natty

« back to all changes in this revision

Viewing changes to mtkbabel

  • Committer: Bazaar Package Importer
  • Author(s): Uwe Hermann
  • Date: 2010-09-06 23:52:36 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20100906235236-cvgxel0ulr0klnl0
Tags: upstream-0.8.2
ImportĀ upstreamĀ versionĀ 0.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl
2
2
#
3
 
# Copyright (C) 2007 - 2009 Niccolo Rigacci
 
3
# Copyright (C) 2007 - 2010 Niccolo Rigacci
4
4
#
5
5
# This program is free software; you can redistribute it and/or
6
6
# modify it under the terms of the GNU General Public License
18
18
#
19
19
# Author:       Niccolo Rigacci <niccolo@rigacci.org>
20
20
#
21
 
# Version:      0.8     2009-01-19
 
21
# Version:      0.8.2   2010-04-02
22
22
#
23
23
# Control program for GPS units using the MediaTek (MTK) chipset.
24
24
# Tested to work with i-Blue 747 and Holux M-241 GPS data loggers.
29
29
use File::Basename;
30
30
# Use the getopts() function.
31
31
use Getopt::Std;
32
 
use vars qw($opt_a $opt_b $opt_c $opt_d $opt_E $opt_f $opt_h $opt_i $opt_l $opt_m $opt_o $opt_p $opt_R $opt_r $opt_s $opt_t $opt_v $opt_w);
 
32
use vars qw($opt_a $opt_b $opt_c $opt_d $opt_E $opt_f $opt_h $opt_i $opt_l $opt_m $opt_o $opt_p $opt_R $opt_r $opt_s $opt_t $opt_v $opt_w $opt_x);
33
33
# Install the libdevice-serialport-perl Debian package.
34
34
use Device::SerialPort;
35
35
# Install the libtimedate-perl Debian package.
218
218
#-------------------------------------------------------------------------
219
219
# Get options from command line.
220
220
#-------------------------------------------------------------------------
221
 
if (! getopts('ab:cd:Ef:hil:m:o:p:Rr:s:tvw') or $opt_h) {
 
221
if (! getopts('ab:cd:Ef:hil:m:o:p:Rr:s:tvwx') or $opt_h) {
222
222
    my $str1 = describe_log_format(0x00fff);
223
223
    my $str2 = describe_log_format(0xff000);
224
224
    print <<HELP;
225
225
Usage: $NAME [options]
226
226
Options:
227
227
    -a                       Read all the log memory (overlapped data)
228
 
    -b filename.bin          Do not read data from a GPS device, but rather read a
229
 
                             previously saved .bin file. Ignore -f option
230
 
    -c                       Create a gpx file with tracks and waypoints
 
228
    -b filename.bin          Don't read data from a GPS device, but rather read
 
229
                             a previously saved .bin file. Ignore -f option
 
230
    -c                       Create a GPX file with tracks and waypoints
231
231
    -d debug_level           Debug level: 0..7
232
232
    -E                       Erase data log memory
233
233
    -f filename              Base name for saved files (.bin and .gpx)
234
234
    -h                       Print this message and exit
235
 
    -i                       Ignore some error conditions and try to extract data
236
 
    -l {on|off}              Turn loggin ON/OFF
 
235
    -i                       Ignore some error conditions, try to extract data
 
236
    -l {on|off}              Turn logging ON/OFF
237
237
    -m {stop|overlap}        Set STOP/OVERLAP recording method on memory full
238
 
    -o log_format            Enable or disable log fields (FIELD1,-FIELD2,...), available fields:
 
238
    -o log_format            Enable or disable log fields (FIELD1,-FIELD2,...),
 
239
                             available fields:
239
240
                             $str1
240
241
                             $str2
241
242
    -p port                  Communication port, default: $port
242
 
    -R                       Recover from disabled log: erase data and reset recording criteria
 
243
    -R                       Recover from disabled log: erase data and reset
 
244
                             recording criteria
243
245
    -r time:distance:speed   Set logging criteria (zero to disable):
244
 
                             every 1-999 seconds, every 10-9999 meters, over 10-999 km/h
 
246
                             every 0.10-9999999.90 seconds, every 0.10-9999999.90
 
247
                             meters, over 0.10-9999999.90 km/h
245
248
    -s speed                 Serial port speed, default $baudrate baud
246
 
    -t                       Create a gpx file with tracks
 
249
    -t                       Create a GPX file with tracks
247
250
    -v                       Print MTKBabel version and exit
248
 
    -w                       Create a gpx file with waypoints
 
251
    -w                       Create a GPX file with waypoints
 
252
    -x                       Force reading Holux format
249
253
 
250
254
Example:
251
255
    Download traks and waypoints from GPS device, creating the
260
264
#-------------------------------------------------------------------------
261
265
# Check command line options.
262
266
#-------------------------------------------------------------------------
263
 
if ($opt_v) { print "\nMTKBabel Version 0.8\n\n"; exit }
 
267
if ($opt_v) { print "\nMTKBabel Version 0.8.2\n\n"; exit }
264
268
$debug    = $opt_d if (defined($opt_d) and ($opt_d >= $LOG_EMERG) and ($opt_d <= $LOG_DEBUG));
265
269
$port     = $opt_p if (defined($opt_p));
266
270
$baudrate = int($opt_s) if (defined($opt_s));
267
271
$opt_f    = substr($opt_f, 0, -4) if (substr($opt_f, -4) eq '.bin');
268
272
$opt_b    = substr($opt_b, 0, -4) if (substr($opt_b, -4) eq '.bin');
269
273
 
 
274
#-------------------------------------------------------------------------
 
275
# Force Holux format. Required to read a binary file because some
 
276
# Holux devices does not embed Holux identifier into the data.
 
277
#-------------------------------------------------------------------------
 
278
if ($opt_x) {
 
279
    $model_id = '0000';
 
280
    set_data_types($model_id);
 
281
}
270
282
 
271
283
#-------------------------------------------------------------------------
272
284
# Do not open the device, read instead an existing binary log file.
305
317
 
306
318
# Query firmware release (PMTK_Q_RELEASE). Examples:
307
319
#
 
320
# Holux M-1200E         PMTK705,AXN_1.30-B_1.3_C01,0000,01035-01A,1.0
308
321
# ???                   PMTK705,M-core_1.8,0001
309
322
# 747 ???               PMTK705,B-core_1.1,0002,TSI_747CD,1.0
 
323
# Qstarz BT-Q1000X      PMTK705,AXN_1.0-B_1.3_C01,0003,QST1000,1.0
310
324
# 747 ???               PMTK705,B-core_1.1,0004,TSI747CD,1.0
 
325
# Qstarz BT-Q1000P      PMTK705,B-core_1.1,0005,QST1000P,1.0
 
326
# 747 A+ Trip Recorder  PMTK705,AXN_1.0-B_1.3_C01,0006
311
327
# ???                   PMTK705,M-core_1.85,0008
312
328
# i-Blue 747            PMTK705,M-core_1.94,001B
313
329
# Holux M-241           PMTK705,B-core_1.1,0021,01017-00C,1.0
314
330
# Holux M-241           PMTK705,B-core_1.20,0023,01017-00D,1.0
 
331
# Holum M-241 fw 1.13   PMTK705,B-core_1.20,0043,01017-00F,1.0
 
332
# Qstarz BT-Q1300
 
333
# Qstarz BT-Q1000
315
334
#
316
335
packet_send('PMTK605');
317
336
$ret = packet_wait('PMTK705,');
321
340
}
322
341
 
323
342
printf "MTK Firmware: Version: $version, Release: $release, Model ID: $model_id\n";
324
 
set_data_types($model_id);
 
343
if (! $opt_x) {
 
344
    set_data_types($model_id);
 
345
}
325
346
 
326
347
#-------------------------------------------------------------------------
327
348
# Erase memory.
369
390
    undef($time)     if ($time     eq '');
370
391
    undef($distance) if ($distance eq '');
371
392
    undef($speed)    if ($speed    eq '');
372
 
    $time     = int($time    ) if (defined($time));
373
 
    $distance = int($distance) if (defined($distance));
374
 
    $speed    = int($speed   ) if (defined($speed));
375
 
    if (defined($time) and (($time >= 1 and $time <= 999) or ($time == 0))) {
376
 
        packet_send(sprintf('PMTK182,1,3,%u', $time * 10));
377
 
        packet_wait('PMTK001,182,1,3');
378
 
    }
379
 
    if (defined($distance) and (($distance >= 10 and $distance <= 9999) or ($distance == 0))) {
380
 
        packet_send(sprintf('PMTK182,1,4,%u', $distance * 10));
381
 
        packet_wait('PMTK001,182,1,3');
382
 
    }
383
 
    if (defined($speed) and (($speed >= 10 and $speed <= 999) or ($speed == 0))) {
384
 
        packet_send(sprintf('PMTK182,1,5,%u', $speed * 10));
 
393
    # Expect floating point values.
 
394
    $time     = eval(1.0 * $time    ) if (defined($time));
 
395
    $distance = eval(1.0 * $distance) if (defined($distance));
 
396
    $speed    = eval(1.0 * $speed   ) if (defined($speed));
 
397
    if (defined($time) and (($time >= 0.10 and $time <= 9999999.90) or ($time == 0))) {
 
398
        packet_send(sprintf('PMTK182,1,3,%u', int($time * 10)));
 
399
        packet_wait('PMTK001,182,1,3');
 
400
    }
 
401
    if (defined($distance) and (($distance >= 0.10 and $distance <= 9999999.90) or ($distance == 0))) {
 
402
        packet_send(sprintf('PMTK182,1,4,%u', int($distance * 10)));
 
403
        packet_wait('PMTK001,182,1,3');
 
404
    }
 
405
    if (defined($speed) and (($speed >= 0.10 and $speed <= 9999999.90) or ($speed == 0))) {
 
406
        packet_send(sprintf('PMTK182,1,5,%u', int($speed * 10)));
385
407
        packet_wait('PMTK001,182,1,3');
386
408
    }
387
409
}
814
836
 
815
837
        #------------------------------------------------------------------
816
838
        # Check for:
817
 
        # - record separator:        AAAAAAAAAAAAAAXXYYYYYYYYBBBBBBBB
818
 
        # - non written space:       FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
819
 
        # - Holux M-241 separators : HOLUXGR241LOGGER
820
 
        #                            HOLUXGR241WAYPNT
 
839
        # - record separator:          "AAAAAAAAAAAAAAXXYYYYYYYYBBBBBBBB"
 
840
        # - non written space:         "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
 
841
        # - Holux M-241 separators:    "HOLUXGR241LOGGER"
 
842
        #                              "HOLUXGR241WAYPNT"
 
843
        # - Holux M-241 fw 1.13 sep.:  "HOLUXGR241LOGGER    "
 
844
        #                              "HOLUXGR241WAYPNT    "
821
845
        #------------------------------------------------------------------
822
846
        if (($log_len - tell($fp)) >= $SIZEOF_SEPARATOR) {
823
847
 
847
871
                #----------------------------------------------------------
848
872
                printf("Separator: %s\n", $buffer) if ($debug >= $LOG_INFO);
849
873
                $model_id = '0021';
 
874
                if (($log_len - tell($fp)) >= 4) {
 
875
                    $buffer = my_read($fp, 4);
 
876
                    if ($buffer eq '    ') {
 
877
                        $model_id = '0043';
 
878
                    } else {
 
879
                        seek($fp, -4, 1);
 
880
                    }
 
881
                }
850
882
                set_data_types($model_id);
851
883
                next;
852
884
 
856
888
                #----------------------------------------------------------
857
889
                printf("Separator: %s\n", $buffer) if ($debug >= $LOG_INFO);
858
890
                $model_id = '0021';
 
891
                if (($log_len - tell($fp)) >= 4) {
 
892
                    $buffer = my_read($fp, 4);
 
893
                    if ($buffer eq '    ') {
 
894
                        $model_id = '0043';
 
895
                    } else {
 
896
                        seek($fp, -4, 1);
 
897
                    }
 
898
                }
859
899
                set_data_types($model_id);
860
900
                $next_data_force_waypoint = 1;
861
901
                next;
1661
1701
#-------------------------------------------------------------------------
1662
1702
sub flash_memory_size {
1663
1703
    my $model = shift;
1664
 
    return( 8 * 1024 * 1024 / 8) if ($model == 0x1388); # 757/ZI v1        8 Mbit = 1 Mb
1665
 
    return( 8 * 1024 * 1024 / 8) if ($model == 0x5202); # 757/ZI v2        8 Mbit = 1 Mb
1666
 
    return(32 * 1024 * 1024 / 8) if ($model == 0x8300); # Qstartz BT-1200 32 Mbit = 4 Mb
 
1704
    # 8 Mbit = 1 Mb
 
1705
    return( 8 * 1024 * 1024 / 8) if ($model == 0x1388); # 757/ZI v1
 
1706
    return( 8 * 1024 * 1024 / 8) if ($model == 0x5202); # 757/ZI v2
 
1707
    # 32 Mbit = 4 Mb
 
1708
    return(32 * 1024 * 1024 / 8) if ($model == 0x0000); # Holux M-1200E
 
1709
    return(32 * 1024 * 1024 / 8) if ($model == 0x0005); # Qstarz BT-Q1000P
 
1710
    return(32 * 1024 * 1024 / 8) if ($model == 0x0006); # 747 A+ GPS Trip Recorder
1667
1711
    return(32 * 1024 * 1024 / 8) if ($model == 0x0008); # Pentagram PathFinder P 3106
1668
 
    # 0x0051    i-Blue 737, Qstartz 810, Polaris iBT-GPS, Holux M1000
1669
 
    # 0x0002    Qstartz 815
 
1712
    return(32 * 1024 * 1024 / 8) if ($model == 0x8300); # Qstarz BT-1200
 
1713
    # 16Mbit -> 2Mb
 
1714
    # 0x0051    i-Blue 737, Qstarz 810, Polaris iBT-GPS, Holux M1000
 
1715
    # 0x0002    Qstarz 815
1670
1716
    # 0x001b    i-Blue 747
1671
1717
    # 0x001d    BT-Q1000 / BGL-32
1672
1718
    # 0x0131    EB-85A
1673
 
    return(16 * 1024 * 1024 / 8); # 16Mbit -> 2Mb
 
1719
    return(16 * 1024 * 1024 / 8);
1674
1720
}
1675
1721
 
1676
1722
#-------------------------------------------------------------------------
1681
1727
    my $port = shift;
1682
1728
    my $baudrate = shift;
1683
1729
    die("Cannot open $port. Did you switch ON the GPS device?\n") if (! -c $port);
1684
 
    $device = Device::SerialPort->new($port);
 
1730
    $device = Device::SerialPort->new($port)
 
1731
        || die "ERROR: Opening serial device $port: $!";
1685
1732
    $device->baudrate($baudrate) || die "fail setting baud rate";
1686
1733
    $device->parity('none')      || die "fail setting parity";
1687
1734
    $device->databits(8)         || die "fail setting databits";
1719
1766
 
1720
1767
    my $model_id = shift;
1721
1768
 
1722
 
    if ($model_id eq '0005' or
 
1769
    if ($model_id eq '0000' or
 
1770
        $model_id eq '0005' or
1723
1771
        $model_id eq '0021' or
1724
 
        $model_id eq '0023')
 
1772
        $model_id eq '0023' or
 
1773
        $model_id eq '0043')
1725
1774
    {
1726
 
        printf("Setting log format and data types for Holum M-241, model ID %s\n", $model_id) if ($debug >= $LOG_INFO);
 
1775
        printf("Setting log format and data types for Holux, model ID %s\n", $model_id) if ($debug >= $LOG_INFO);
1727
1776
        $LOG_HAS_CHECKSUM_SEPARATOR = 0;
1728
1777
        $SIZEOF_LOG_LATITUDE  = $SIZEOF_FLOAT;
1729
1778
        $SIZEOF_LOG_LONGITUDE = $SIZEOF_FLOAT;