mtkbabel-0.8.4/0000755000175000017500000000000013550357647013161 5ustar niccoloniccolomtkbabel-0.8.4/README0000644000175000017500000000374613550354140014034 0ustar niccoloniccolo--------------------------------------------------------------------------- README file for the MTKBabel program --------------------------------------------------------------------------- Copyright 2007 - 2019 Niccolo Rigacci Get latest version and other info at: http://sourceforge.net/projects/mtkbabel http://www.rigacci.org/wiki/doku.php/doc/appunti/hardware/gps_logger_i_blue_747 MTKBabel is a Perl program to operate the i-Blue 747 GPS data logger. It should work also with other GPS devices based on the MediaTek MTK chipset. It is free software released under the GPL license. The main capabilities are: * Command line interface * Save data log in GPX and raw binary format * If required retrieve all the data, also the old one being overlapped * Change logging criteria: time, distance, speed * Change log format * START/STOP logging * Set OVERLAP or STOP method on memory full * Erase the internal memory The progam is written in Perl, and it was tested on Linux via USB connection. One goal is easy portability to C and small RAM footprint. Run mtkbabel -h for a brief help screen. In order to run the mtkbabel program you should have installed a standard Perl distribution, plus the following libraries: * Device::SerialPort * Date::Format Check if your operating system provides a package for them, or refer to the cpan(1) manual page. --------------------------------------------------------------------------- KNOWN BUGS --------------------------------------------------------------------------- * Floating point numbers and non-i386 architectures Convesion of floating point numbers (64 bit doubles and 32 bit floats) from MTK binary format to GPX text is done with the Perl unpack() function. This seems to work properly on the GNU/Linux i386 architecture, (I think both uses IEEE 754 encoding). It fails - at least - on my Arm box, with an XScale processor. The function mtk2number() should be rewritten using some math library or in pure Perl. mtkbabel-0.8.4/copyright0000644000175000017500000004310313550354140015076 0ustar niccoloniccolo GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. mtkbabel-0.8.4/mtkbabel0000755000175000017500000023325013550354140014656 0ustar niccoloniccolo#!/usr/bin/perl # # Copyright (C) 2007 - 2019 Niccolo Rigacci # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # Author: Niccolo Rigacci # # Version: 0.8.4 2019-10-11 # # Control program for GPS units using the MediaTek (MTK) chipset. # Tested to work with i-Blue 747 and Holux M-241 GPS data loggers. # use strict; # Use the basename() function. use File::Basename; # Use the getopts() function. use Getopt::Std; use vars qw($opt_a $opt_b $opt_c $opt_d $opt_E $opt_f $opt_h $opt_i $opt_I $opt_l $opt_m $opt_o $opt_p $opt_R $opt_r $opt_s $opt_t $opt_v $opt_W $opt_w $opt_x); # Install the libdevice-serialport-perl Debian package. use Device::SerialPort; # Install the libtimedate-perl Debian package. use Date::Format; my $NAME = basename($0); # Debug levels. my $LOG_EMERG = 0; my $LOG_ALERT = 1; my $LOG_CRIT = 2; my $LOG_ERR = 3; my $LOG_WARNING = 4; my $LOG_NOTICE = 5; my $LOG_INFO = 6; my $LOG_DEBUG = 7; # Size in bytes of data types. my $SIZEOF_BYTE = 1; my $SIZEOF_WORD = 2; my $SIZEOF_LONG = 4; my $SIZEOF_FLOAT3 = 3; my $SIZEOF_FLOAT = 4; my $SIZEOF_DOUBLE = 8; # Log format is stored as a bitmask field. my $LOG_FORMAT_UTC = 0x00000001; my $LOG_FORMAT_VALID = 0x00000002; my $LOG_FORMAT_LATITUDE = 0x00000004; my $LOG_FORMAT_LONGITUDE = 0x00000008; my $LOG_FORMAT_HEIGHT = 0x00000010; my $LOG_FORMAT_SPEED = 0x00000020; my $LOG_FORMAT_HEADING = 0x00000040; my $LOG_FORMAT_DSTA = 0x00000080; my $LOG_FORMAT_DAGE = 0x00000100; my $LOG_FORMAT_PDOP = 0x00000200; my $LOG_FORMAT_HDOP = 0x00000400; my $LOG_FORMAT_VDOP = 0x00000800; my $LOG_FORMAT_NSAT = 0x00001000; my $LOG_FORMAT_SID = 0x00002000; my $LOG_FORMAT_ELEVATION = 0x00004000; my $LOG_FORMAT_AZIMUTH = 0x00008000; my $LOG_FORMAT_SNR = 0x00010000; my $LOG_FORMAT_RCR = 0x00020000; my $LOG_FORMAT_MILLISECOND = 0x00040000; my $LOG_FORMAT_DISTANCE = 0x00080000; # Log status is stored as a bitmask field; my $LOG_STATUS_AUTOLOG = 0x0002; # AUTO_LOG mode (by criteria) ON/OFF my $LOG_STATUS_STOP_WHEN_FULL = 0x0004; # STOP/OVERLAP method when memory full my $LOG_STATUS_ENABLE = 0x0100; # Device is in ENABLE_LOG (normal) state my $LOG_STATUS_DISABLE = 0x0200; # Device entered DISABLE_LOG state (fail sectors >= 16) my $LOG_STATUS_NEED_FORMAT = 0x0400; # Flash memory need format my $LOG_STATUS_FULL = 0x0800; # Flash memory is full # Default data types. my $SIZEOF_LOG_UTC = $SIZEOF_LONG; my $SIZEOF_LOG_VALID = $SIZEOF_WORD; my $SIZEOF_LOG_LATITUDE = $SIZEOF_DOUBLE; my $SIZEOF_LOG_LONGITUDE = $SIZEOF_DOUBLE; my $SIZEOF_LOG_HEIGHT = $SIZEOF_FLOAT; my $SIZEOF_LOG_SPEED = $SIZEOF_FLOAT; my $SIZEOF_LOG_HEADING = $SIZEOF_FLOAT; my $SIZEOF_LOG_DSTA = $SIZEOF_WORD; my $SIZEOF_LOG_DAGE = $SIZEOF_LONG; my $SIZEOF_LOG_PDOP = $SIZEOF_WORD; my $SIZEOF_LOG_HDOP = $SIZEOF_WORD; my $SIZEOF_LOG_VDOP = $SIZEOF_WORD; my $SIZEOF_LOG_NSAT = $SIZEOF_BYTE * 2; my $SIZEOF_LOG_SID = $SIZEOF_BYTE; my $SIZEOF_LOG_SIDINUSE = $SIZEOF_BYTE; my $SIZEOF_LOG_SATSINVIEW = $SIZEOF_WORD; my $SIZEOF_LOG_ELEVATION = $SIZEOF_WORD; my $SIZEOF_LOG_AZIMUTH = $SIZEOF_WORD; my $SIZEOF_LOG_SNR = $SIZEOF_WORD; my $SIZEOF_LOG_RCR = $SIZEOF_WORD; my $SIZEOF_LOG_MILLISECOND = $SIZEOF_WORD; my $SIZEOF_LOG_DISTANCE = $SIZEOF_DOUBLE; # A record separator has one of the following types. my $SEP_TYPE_CHANGE_LOG_BITMASK = 0x02; my $SEP_TYPE_CHANGE_LOG_PERIOD = 0x03; my $SEP_TYPE_CHANGE_LOG_DISTANCE = 0x04; my $SEP_TYPE_CHANGE_LOG_SPEED = 0x05; my $SEP_TYPE_CHANGE_OVERLAP_STOP = 0x06; my $SEP_TYPE_CHANGE_START_STOP_LOG = 0x07; # Values for the VALID field. my $VALID_NOFIX = 0x0001; my $VALID_SPS = 0x0002; my $VALID_DGPS = 0x0004; my $VALID_PPS = 0x0008; my $VALID_RTK = 0x0010; my $VALID_FRTK = 0x0020; my $VALID_ESTIMATED = 0x0040; my $VALID_MANUAL = 0x0080; my $VALID_SIMULATOR = 0x0100; # Values for the RCR field. my $RCR_TIME = 0x01; my $RCR_SPEED = 0x02; my $RCR_DISTANCE = 0x04; my $RCR_BUTTON = 0x08; # Recording method: OVERLAP or STOP. my $RCD_METHOD_OVP = 1; my $RCD_METHOD_STP = 2; # Log data is retrieved in chunks of this size. my $SIZEOF_CHUNK = 0x800; my $SIZEOF_SECTOR = 0x10000; my $SIZEOF_SECTOR_HEADER = 0x200; my $SIZEOF_SEPARATOR = 0x10; # End Of Line for generated GPX files. my $GPX_EOL = "\n"; # Default timeout for packet wait (sec). my $TIMEOUT = 5; # Timeout waiting for char "$" which is MTK packet start (sec). my $TIMEOUT_PKT_PREAMBLE = 20; # Timeout for activity on device port (msec). my $TIMEOUT_IDLE_PORT = 5000; # Is there a char "*" separator between data and checksum? my $LOG_HAS_CHECKSUM_SEPARATOR = 1; # Used to fix the Weeks Rollover Bug. my $SECONDS_IN_WEEK = 3600 * 24 * 7; my $WEEKS_ROLLOVER = 1024; #------------------------------------------------------------------------- # Global variables. #------------------------------------------------------------------------- my $debug = $LOG_WARNING; # Default loggin level. my $port = '/dev/ttyUSB0'; # Default communication port. my $baudrate = 115200; # Default port speed. my $ro_weeks = 0; # Weeks offset to fix Weeks Rollover Bug # GPX global values. my $gpx_trk_minlat = 90.0; my $gpx_trk_minlon = 180.0; my $gpx_trk_maxlat = -90.0; my $gpx_trk_maxlon = -180.0; my $gpx_wpt_minlat = 90.0; my $gpx_wpt_minlon = 180.0; my $gpx_wpt_maxlat = -90.0; my $gpx_wpt_maxlon = -180.0; my $gpx_trk_number = 0; my $gpx_wpt_number = 0; my $device; my $version; my $release; my $model_id; my $ret; my $log_format; my $next_write_address; my $expected_records_total; my $log_status; my $rec_method; my $fail_sectors; my $sectors; my $bytes_to_read; my $fp_log; my $offset; my $non_written_sector_found; # Record values. my $record_utc; my $record_valid; my $record_latitude; my $record_longitude; my $record_height; my $record_speed; my $record_heading; my $record_dsta; my $record_dage; my $record_pdop; my $record_hdop; my $record_vdop; my $record_nsat_in_use; my $record_nsat_in_view; my $record_satdata; my $record_rcr; my $record_millisecond; my $record_distance; #------------------------------------------------------------------------- # Get options from command line. #------------------------------------------------------------------------- if (! getopts('ab:cd:Ef:hiIl:m:o:p:Rr:s:tvW:wx') or $opt_h) { my $str1 = describe_log_format(0x00fff); my $str2 = describe_log_format(0xff000); print <= $LOG_EMERG) and ($opt_d <= $LOG_DEBUG)); $port = $opt_p if (defined($opt_p)); $baudrate = int($opt_s) if (defined($opt_s)); $opt_f = substr($opt_f, 0, -4) if (substr($opt_f, -4) eq '.bin'); $opt_b = substr($opt_b, 0, -4) if (substr($opt_b, -4) eq '.bin'); $ro_weeks = int($opt_W) if (defined($opt_W)); #------------------------------------------------------------------------- # Force Holux format. Required to read a binary file because some # Holux devices does not embed Holux identifier into the data. #------------------------------------------------------------------------- if ($opt_x) { $model_id = '0000'; set_data_types($model_id); } #------------------------------------------------------------------------- # Do not open the device, read instead an existing binary log file. #------------------------------------------------------------------------- if ($opt_b) { if ($opt_t or $opt_w or $opt_c) { # Parse binary data and save GPX files. $opt_f = $opt_b; # Total number of records is unknown: we will exit on End Of File. $expected_records_total = 0xffffffff; parse_log_data(); } exit; } #------------------------------------------------------------------------- # Initialize the device port. #------------------------------------------------------------------------- serial_port_open($port, $baudrate); # Do not write the log file yet. undef($fp_log); # Send test packet (PMTK_TEST). packet_send('PMTK000'); $ret = packet_wait('PMTK001,0,'); die("MTK Test command FAILED\n") if (!($ret =~ m/PMTK001,0,/)); print "MTK Test OK\n"; # Query firmware version (PMTK_Q_VERSION). packet_send('PMTK604'); $ret = packet_wait('PMTK001,604,'); if ($ret =~ m/PMTK001,604,([0-9A-Za-z]+)\*/) { $version = $1; } # Query firmware release (PMTK_Q_RELEASE). Examples: # # Holux M-1200E PMTK705,AXN_1.30-B_1.3_C01,0000,01035-01A,1.0 # Holux GPSport 245 PMTK705,M-core_2.12,0000,GR-245,1.0 # ??? PMTK705,M-core_1.8,0001 # 747 ??? PMTK705,B-core_1.1,0002,TSI_747CD,1.0 # Qstarz BT-Q1000X PMTK705,AXN_1.0-B_1.3_C01,0003,QST1000,1.0 # 747 ??? PMTK705,B-core_1.1,0004,TSI747CD,1.0 # Qstarz BT-Q1000P PMTK705,B-core_1.1,0005,QST1000P,1.0 # 747 A+ Trip Recorder PMTK705,AXN_1.0-B_1.3_C01,0006 # iBlue 747A+ PMTK705,AXN_1.30-B_1.3_C01,000F,TSI_747A+,1.0 # ??? PMTK705,M-core_1.85,0008 # i-Blue 747 PMTK705,M-core_1.94,001B # Holux M-241 PMTK705,B-core_1.1,0021,01017-00C,1.0 # Holux M-241 PMTK705,B-core_1.20,0023,01017-00D,1.0 # Holux M-241 fw 1.13 PMTK705,B-core_1.20,0043,01017-00F,1.0 # Holux M-1000C PMTK705,AXN_1.30-B_1.3_C01,005C # Qstarz BT-Q1300 # Qstarz BT-Q1000 # packet_send('PMTK605'); $ret = packet_wait('PMTK705,'); if ($ret =~ m/PMTK705,([\.0-9A-Za-z_-]+),([0-9A-Za-z]+)[,\*]/) { $release = $1; $model_id = $2; } printf "MTK Firmware: Version: $version, Release: $release, Model ID: $model_id\n"; if (! $opt_x) { set_data_types($model_id); } #------------------------------------------------------------------------- # Erase memory. #------------------------------------------------------------------------- if ($opt_E) { printf(">> Erasing log memory...\n"); packet_send('PMTK182,6,1'); packet_wait('PMTK001,182,6,3', 120); } #------------------------------------------------------------------------- # Recover from disable log: ENABLE LOG and FORMAT LOG ALL. # Also reset recording criteria. #------------------------------------------------------------------------- if ($opt_R) { printf(">> Recover from disable log: ENABLE LOG and FORMAT LOG ALL...\n"); packet_send('PMTK182,10'); packet_wait('PMTK001,182,16,3', 120); packet_send('PMTK182,6,1'); packet_wait('PMTK001,182,6,3', 120); } #------------------------------------------------------------------------- # Turn ON or OFF data logging. #------------------------------------------------------------------------- if ($opt_l eq 'on') { printf(">> Switch recording to ON\n"); # Send PMTK_LOG_ON. packet_send('PMTK182,4'); packet_wait('PMTK001,182,4,3'); } if ($opt_l eq 'off') { printf(">> Switch recording to OFF\n"); # Send PMTK_LOG_OFF. packet_send('PMTK182,5'); packet_wait('PMTK001,182,5,3'); } #------------------------------------------------------------------------- # Set recording criteria: TIME, DISTANCE, SPEED. #------------------------------------------------------------------------- if ($opt_r) { printf(">> Setting recording criteria: time, distance, speed\n"); my ($time, $distance, $speed) = split(/:/, $opt_r); undef($time) if ($time eq ''); undef($distance) if ($distance eq ''); undef($speed) if ($speed eq ''); # Expect floating point values. $time = eval(1.0 * $time ) if (defined($time)); $distance = eval(1.0 * $distance) if (defined($distance)); $speed = eval(1.0 * $speed ) if (defined($speed)); if (defined($time) and (($time >= 0.10 and $time <= 9999999.90) or ($time == 0))) { packet_send(sprintf('PMTK182,1,3,%u', int($time * 10))); packet_wait('PMTK001,182,1,3'); } if (defined($distance) and (($distance >= 0.10 and $distance <= 9999999.90) or ($distance == 0))) { packet_send(sprintf('PMTK182,1,4,%u', int($distance * 10))); packet_wait('PMTK001,182,1,3'); } if (defined($speed) and (($speed >= 0.10 and $speed <= 9999999.90) or ($speed == 0))) { packet_send(sprintf('PMTK182,1,5,%u', int($speed * 10))); packet_wait('PMTK001,182,1,3'); } } #------------------------------------------------------------------------- # Set recording method: OVERLAP or STOP (PMTK_LOG_REC_METHOD). #------------------------------------------------------------------------- if ((lc($opt_m) eq 'overlap') or (lc($opt_m) eq 'stop')) { if (lc($opt_m) eq 'overlap') { printf(">> Setting method OVERLAP on memory full\n"); packet_send('PMTK182,1,6,1'); } else { printf(">> Setting method STOP on memory full\n"); packet_send('PMTK182,1,6,2'); } $ret = packet_wait('PMTK001,182,1,'); if ($ret =~ m/PMTK001,182,1,(\d)/) { if ($1 ne '3') { printf(">> ERROR: Cannot set recording method\n"); } } } #------------------------------------------------------------------------- # Set log format (PMTK_LOG_SETFORMAT). #------------------------------------------------------------------------- if ($opt_o) { printf(">> Setting log format\n"); # Get current log format. packet_send('PMTK182,2,2'); $ret = packet_wait('PMTK182,3,2,'); packet_wait('PMTK001,182,2,3'); if ($ret =~ m/PMTK182,3,2,([0-9A-Za-z]+)\*/) { $log_format = hex($1); $log_format = encode_log_format($log_format, $opt_o); packet_send(sprintf('PMTK182,1,2,%08X', $log_format)); $ret = packet_wait('PMTK001,182,1,3'); } } # Query log format (PMTK_LOG_QUERY). packet_send('PMTK182,2,2'); $ret = packet_wait('PMTK182,3,2,'); packet_wait('PMTK001,182,2,3'); if ($ret =~ m/PMTK182,3,2,([0-9A-Za-z]+)\*/) { $log_format = hex($1); my ($size_wpt, $size_sat) = sizeof_log_format($log_format); printf("Log format: (%s) %s\n", $1, describe_log_format($log_format)); printf("Size in bytes of each log record: %u + (%u * sats_in_view)\n", $size_wpt + 2, $size_sat); } # Query recording criteria: time, distance, speed (PMTK_LOG_QUERY). packet_send('PMTK182,2,3'); $ret = packet_wait('PMTK182,3,3,'); if ($ret =~ m/PMTK182,3,3,([0-9]+)\*/) { printf("Logging TIME interval: %6.2f s\n", $1 / 10); } packet_send('PMTK182,2,4'); $ret = packet_wait('PMTK182,3,4,'); if ($ret =~ m/PMTK182,3,4,([0-9]+)\*/) { printf("Logging DISTANCE interval: %6.2f m\n", $1 / 10); } packet_send('PMTK182,2,5'); $ret = packet_wait('PMTK182,3,5,'); if ($ret =~ m/PMTK182,3,5,([0-9]+)\*/) { printf("Logging SPEED limit: %6.2f km/h\n", $1 / 10); } # Query recording method when full (OVERLAP/STOP). packet_send('PMTK182,2,6'); packet_wait('PMTK001,182,2,3'); $ret = packet_wait('PMTK182,3,6,'); if ($ret =~ m/PMTK182,3,6,([0-9]+)\*/) { $rec_method = $1; printf("Recording method on memory full: (%u) %s\n", $rec_method, describe_recording_method($rec_method)); } # Query LOG_STATUS (recording ON/OFF, ...). packet_send('PMTK182,2,7'); packet_wait('PMTK001,182,2,3'); $ret = packet_wait('PMTK182,3,7,'); if ($ret =~ m/PMTK182,3,7,([0-9A-Za-z]+)\*/) { $log_status = $1; printf("Log status: (%012b) %s\n", $log_status, describe_log_status($log_status)); if ($log_status & $LOG_STATUS_NEED_FORMAT) { printf("WARNING! Log status NEED_FORMAT, log data is not valid!\n"); } if ($log_status & $LOG_STATUS_DISABLE) { printf("WARNING! Log status DISABLE_LOG, may too many failed sectors!\n"); } } # Query the RCD_ADDR (data log Next Write Address). # If device is in STOP mode, this is also the total memory used. # If it is in OVERLAP mode, there is old data beyond the NWA. packet_send('PMTK182,2,8'); $ret = packet_wait('PMTK182,3,8,'); packet_wait('PMTK001,182,2,3'); if ($ret =~ m/PMTK182,3,8,([0-9A-Za-z]+)\*/) { $next_write_address = hex($1); printf("Next write address: %u (0x%08X)\n", $next_write_address, $next_write_address); } # Query number of records stored in the log. packet_send('PMTK182,2,10'); $ret = packet_wait('PMTK182,3,10,'); packet_wait('PMTK001,182,2,3'); if ($ret =~ m/PMTK182,3,10,([0-9A-Za-z]+)\*/) { $expected_records_total = hex($1); printf("Number of records: %u\n", $expected_records_total); } # Query failed sectors (PMTK_RCD_FSECTOR). packet_send('PMTK182,2,11'); $ret = packet_wait('PMTK182,3,11,'); packet_wait('PMTK001,182,2,3'); if ($ret =~ m/PMTK182,3,11,([0-9A-Za-z]+)\*/) { $fail_sectors = $1; printf("Memory health status (failed sectors mask): %s\n", $fail_sectors); } #------------------------------------------------------------------------- # Get binary data from the device and save to a file. #------------------------------------------------------------------------- if ($opt_f and ($opt_t or $opt_w or $opt_c)) { # Compute the memory used by data log, round-up to the entire sector. if (($rec_method == $RCD_METHOD_OVP) or $opt_a) { # In OVERLAP mode we don't know where data ends; read the entire memory. $bytes_to_read = flash_memory_size($model_id); } else { # In STOP mode read from zero to Next Write Address. $sectors = int($next_write_address / $SIZEOF_SECTOR); $sectors += 1 if (($next_write_address % $SIZEOF_SECTOR) != 0); $bytes_to_read = $sectors * $SIZEOF_SECTOR; } printf(">> Retrieving %u (0x%08X) bytes of log data from device...\n", $bytes_to_read, $bytes_to_read); open($fp_log, ">${opt_f}.bin") or die("Cannot open file ${opt_f}.bin: $!"); binmode($fp_log); # Avoid reading the entire memory if we find a non-written sector. $non_written_sector_found = 0; # NOTE: On a slow machine there was some problem getting the entire log data # via USB port with a single PMTK_LOG_REQ_DATA request. # The GPS device eventually begins to send packets longer than $SIZEOF_CHUNK, # apparently with corrupted data (failed checksum). # To be safe we iterate requesting $SIZEOF_CHUNK bytes at time. for ($offset = 0; $offset < $bytes_to_read; $offset += $SIZEOF_CHUNK) { # Request log data (PMTK_LOG_REQ_DATA) from $offset to $bytes_to_read. packet_send(sprintf('PMTK182,7,%08X,%08X', $offset, $SIZEOF_CHUNK)); # Start writing binary data to file and wait the final PMTK_ACK packet. packet_wait('PMTK001,182,7,3', 10); last if ($non_written_sector_found); } close($fp_log); undef($fp_log); # Parse binary data and save GPX files. parse_log_data(); } serial_port_close(); exit; #------------------------------------------------------------------------- # Some devices suffer from Weeks Rollover Bug: they cannot handle more # than $WEEKS_ROLLOVER (1024) weeks in timestamps. # If timestamp is more than $WEEKS_ROLLOVER weeks in the past, we can # try to guess a fix. #------------------------------------------------------------------------- sub fix_timestamp_rollover { my $timestamp = shift; if ($ro_weeks >= 0) { # Apply the requested Weeks Rollovers. return($timestamp + $ro_weeks * $SECONDS_IN_WEEK); } else { # Guess how many Weeks Rollovers need to apply. my $time_now = time(); if ($timestamp < $time_now) { my $guess = int(($time_now - $timestamp) / $SECONDS_IN_WEEK / $WEEKS_ROLLOVER); printf("%s Guessed count of Weeks Rollover: %d\n", log_time(), $guess) if ($debug >= $LOG_WARNING); # If timestamp is a 32bit integer, a 1024 weeks rollover may occurr max 6 times. if ($guess <= 6) { $ro_weeks = $guess * $WEEKS_ROLLOVER; return($timestamp + $ro_weeks * $SECONDS_IN_WEEK); } } $ro_weeks = 0; printf("%s Cannot guess Weeks Rollover count\n", log_time()) if ($debug >= $LOG_WARNING); } return($timestamp); } #------------------------------------------------------------------------- # Calculate the packet checksum: bitwise XOR of string's bytes. #------------------------------------------------------------------------- sub packet_checksum { my $pkt = shift; my $len = length($pkt); my $check = 0; my $i; for ($i = 0; $i < $len; $i++) { $check ^= ord(substr($pkt, $i, 1)); } #printf("0x%02X\n", $check); return($check); } #------------------------------------------------------------------------- # Send NMEA packet to the device. #------------------------------------------------------------------------- sub packet_send { my $pkt = shift; my $n; # Add the checksum to the packet. $pkt = $pkt . '*' . sprintf('%02X', packet_checksum($pkt)); printf("%s TX packet => %s\n", log_time(), $pkt) if ($debug >= $LOG_NOTICE); # Add the preamble and . $pkt = '$' . $pkt . "\r\n"; $n = serial_port_write($pkt); printf("Writing %u bytes to device; actually written %u bytes\n", length($pkt), $n) if ($debug >= $LOG_DEBUG); die("ERROR: Writing to device: $!") if ($n != length($pkt)); } #------------------------------------------------------------------------- # Read a packet from the device. # Return the packet with PktType, DataField, "*" and Checksum. # # Example: PMTK182,3,8,0004E69C*13 # # The packet received has a leading Preample and a trailing , # example: $PMTK182,3,8,0004E69C*13 #------------------------------------------------------------------------- sub packet_read { my $timeout = shift; my $c; my $n; my $t; my $pkt; my $previous_c; my $payload; my $checksum; # Timeout (in milliseconds) for activity on the port. $timeout = $TIMEOUT_IDLE_PORT if (!defined($timeout)); serial_port_set_read_timeout($timeout); # Wait packet preamble. $c = ''; $t = time(); while ($c ne '$' and (time() - $t) < $TIMEOUT_PKT_PREAMBLE) { ($n, $c) = serial_port_getch(); die("ERROR: Reading from device (may be switched OFF): $!") if ($n != 1); } die("ERROR: Packet preamble not found (wrong serial speed or output from device not flushed)\n") if ($c ne '$'); # Read until End Of Packet. $pkt = ''; $previous_c = ''; while (1) { ($n, $c) = serial_port_getch(); die("ERROR: Reading from device (may be switched OFF): $!") if ($n != 1); if ($c eq '$') { $pkt = ''; } else { $pkt .= $c; } if (($c eq "\n") and ($previous_c eq "\r")) { last; } $previous_c = $c; } # Remove trailing . $pkt = substr($pkt, 0, -2); printf("%s RX packet <= %s\n", log_time(), $pkt) if ($debug >= $LOG_NOTICE); # Extract packet payload and checksum. $payload = substr($pkt, 0, -3); $checksum = hex(substr($pkt, -2, 2)); # Verify packet checksum. if ($checksum ne packet_checksum($payload)) { printf("Packet checksum error: expected 0x%02X, computed 0x%02X\n", $checksum, packet_checksum($payload)) if ($debug >= $LOG_ERR); return(''); } else { return($pkt); } } #------------------------------------------------------------------------- # Read packets from the device, untill we get the one we want. #------------------------------------------------------------------------- sub packet_wait { my $pkt_type = shift; my $timeout = shift; my $max_time; my $pkt; my $len; $len = length($pkt_type); # Timeout (in seconds) for packet wait. $timeout = $TIMEOUT if (!defined($timeout)); $max_time = time() + $timeout; while(1) { $pkt = packet_read($timeout * 1000); return($pkt) if (substr($pkt, 0, $len) eq $pkt_type); write_log_packet($pkt) if (defined($fp_log)); last if (time() > $max_time); } printf("%s ERROR: packet_wait() failed for packet %s\n", log_time(), $pkt_type) if ($debug >= $LOG_ERR); return(undef); } #------------------------------------------------------------------------- # Append received packets of log data to a file. # # Packet format is PMTK182,8,SSSSSSSS,PacketData*CC where: # SSSSSSSS = Offset of first byte (hex value, 8 chars) # PacketData = Packet data (hex values, 4096 chars) # * = Separator (1 char) # CC = Checksum of data (hex value, 2 chars) #------------------------------------------------------------------------- sub write_log_packet { my $pkt = shift; my $pkt_len; my $pkt_offset; my $log_offset; my $percent; my $i; # Save only datalog packets (PMTK_LOG_RESP_DATA). return if (substr($pkt, 0, 10) ne 'PMTK182,8,'); # Check if packet length is OK and if chunk is in sequence order. $log_offset = tell($fp_log); $pkt_offset = hex(substr($pkt, 10, 8)); $pkt_len = ($SIZEOF_CHUNK * 2) + 22; # Check sector headers for non-written pattern, set a flag to avoid reading unused memory. if (($log_offset % $SIZEOF_SECTOR) == 0) { if (uc(substr($pkt, 19, $SIZEOF_SEPARATOR * 2)) eq ('FF' x $SIZEOF_SEPARATOR)) { printf("WARNING: Sector header at offset 0x%08X is non-written data\n", $log_offset); $non_written_sector_found = 1; } } # We request $pkt_len at time, check how much we got. if (length($pkt) != $pkt_len) { printf("WARNING: Packet size error: expected %04X, got %04X\n", $pkt_len, length($pkt)) if ($debug >= $LOG_WARNING); } if ($pkt_offset != $log_offset) { printf("ERROR: Chunk out of sequence: expected %08X, got %08X\n", $log_offset, $pkt_offset) if ($debug >= $LOG_ERR); # To avoid "out-of-order" for every next packet, re-request the one we're still waiting for. $offset = $log_offset - $SIZEOF_CHUNK; } else { printf("Saving log data, offset: 0x%08X\n", $log_offset) if ($debug >= $LOG_INFO); # Convert the string of hex values into binary data. for ($i = 19; $i < ($pkt_len - 3); $i += 2) { printf $fp_log chr(hex(substr($pkt, $i, 2))); } $percent = ($log_offset / $bytes_to_read) * 100; printf("Saved log data: %6.2f%%\n", $percent); } } #------------------------------------------------------------------------- # Parse raw binary log data and write GPX files. #------------------------------------------------------------------------- sub parse_log_data { my $fp; my $fp_gpx; my $fp_gpx_trk; my $fp_gpx_wpt; my $buffer; my $log_len; my $new_offset; my $log_format; my $checksum; my $trailing_spaces; my $sep_model; my $expected_records_sector = 0; my $record_count_sector = 0; my $record_count_total = 0; my $gpx_in_trk = 0; my $next_data_force_waypoint = 0; my $gpx_fname = "${opt_f}.gpx"; my $gpx_trk_fname = "${opt_f}_trk.gpx"; my $gpx_wpt_fname = "${opt_f}_wpt.gpx"; my $gpx_trk_tmp_fname = "${opt_f}_trk.gpx.$$.tmp"; my $gpx_wpt_tmp_fname = "${opt_f}_wpt.gpx.$$.tmp"; my $timestamp; my $max_timestamp = 0; # Open the binary log file for reading. open($fp, "${opt_f}.bin") or die("ERROR reading ${opt_f}.bin: $!"); binmode($fp); seek($fp, 0, 2) or die; $log_len = tell($fp); seek($fp, 0, 0) or die; # Open GPX temporary files for writing tracks and waypoints. open($fp_gpx_trk, ">$gpx_trk_tmp_fname") or die("ERROR writing $gpx_trk_tmp_fname: $!") if ($opt_t or $opt_c); open($fp_gpx_wpt, ">$gpx_wpt_tmp_fname") or die("ERROR writing $gpx_wpt_tmp_fname: $!") if ($opt_w or $opt_c); while (1) { # Print current file position. printf("Reading offset %08X\n", tell($fp)) if ($debug >= $LOG_INFO); #----------------------------------------- # Process the begin of a sector (header). #----------------------------------------- if ((tell($fp) % $SIZEOF_SECTOR) == 0) { # Reached the begin of a log sector (every 0x10000 bytes). Get the header (0x200 bytes). $buffer = my_read($fp, $SIZEOF_SECTOR_HEADER); # What we will find in this log sector: ($expected_records_sector, $log_format) = parse_sector_header($buffer); last if (!defined($expected_records_sector) or !defined($log_format)); $record_count_sector = 0; } #----------------------------------------- # Check if all the records has been read. #----------------------------------------- if ($record_count_total >= $expected_records_total) { printf("Total record count: %u\n", $record_count_total); last; } if ($record_count_sector >= $expected_records_sector) { $new_offset = $SIZEOF_SECTOR * (int(tell($fp) / $SIZEOF_SECTOR) + 1); if ($new_offset < $log_len) { # Log file contains more data (that is old data, being overwritten). seek($fp, $new_offset, 0); next; } else { # End Of File. if (!defined($opt_b)) { printf("ERROR: End of log file! Total record count: %u, expected %u\n", $record_count_total, $expected_records_total); } else { printf("Total record count: %u\n", $record_count_total); } last; } } #------------------------------------------------------------------ # Check for: # - record separator: "AAAAAAAAAAAAAAXXYYYYYYYYBBBBBBBB" # - non written space: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" # - Holux M-241 separators: "HOLUXGR241LOGGER" # "HOLUXGR241WAYPNT" # - Holux M-241 fw 1.13 sep.: "HOLUXGR241LOGGER " # "HOLUXGR241WAYPNT " # - Holux Holux M-1200E sep.: "HOLUXM1200WAYPNT " # # - Holux GPSport GR-245 sep.: "HOLUXGR245LOGGER " # "HOLUXGR245WAYPNT " #------------------------------------------------------------------ if (($log_len - tell($fp)) >= $SIZEOF_SEPARATOR) { $buffer = my_read($fp, $SIZEOF_SEPARATOR); if ((substr($buffer, 0, 7) eq (chr(0xaa) x 7)) and (substr($buffer, -4) eq (chr(0xbb) x 4))) { #---------------------------------------------------------- # Found a record separator. #---------------------------------------------------------- # Close the current in GPX. if ($gpx_in_trk) { gpx_print_trk_end($fp_gpx_trk) if ($opt_t or $opt_c); $gpx_in_trk = 0; } my $separator_type = ord(substr($buffer, 7, $SIZEOF_BYTE)); my $separator_arg = mtk2long(substr($buffer, 8, $SIZEOF_LONG)); printf("Separator: %s, type: %s\n", uc(unpack('H*', $buffer)), describe_separator_type($separator_type)) if ($debug >= $LOG_INFO); if ($separator_type == $SEP_TYPE_CHANGE_LOG_BITMASK) { $log_format = $separator_arg; printf("New log bitmask: %s (0x%08X = %s)\n", $separator_arg, $log_format, describe_log_format($log_format)) if ($debug >= $LOG_INFO); } next; # Search for the next record or record separator. } elsif (substr($buffer, 0, 5) eq 'HOLUX') { #---------------------------------------------------------- # Found Holux separator. #---------------------------------------------------------- printf("Separator: %s\n", $buffer) if ($debug >= $LOG_INFO); # Search for trailing four spaces after the separator. $trailing_spaces = 0; if (($log_len - tell($fp)) >= 4) { if (my_read($fp, 4) eq ' ') { $trailing_spaces = 1; } else { seek($fp, -4, 1); } } # Define $model_id upon separator string. $sep_model = substr($buffer, 5, 5); if ($sep_model eq 'GR241' and $trailing_spaces) { $model_id = '0043'; # M-241 fw 1.13 } elsif ($sep_model eq 'GR241') { $model_id = '0021'; # M-241 } elsif ($sep_model eq 'GR245' or $sep_model eq 'M1200') { $model_id = '0000'; # M-1200E or GPSport 245 } else { $model_id = '0021'; # Unknown Holux model, assume M-241 } set_data_types($model_id); # Check if the following data is a waypoint. if (substr($buffer, 10, 6) eq 'WAYPNT') { $next_data_force_waypoint = 1; } next; } elsif ($buffer eq (chr(0xff) x $SIZEOF_SEPARATOR)) { #---------------------------------------------------------- # Found non-written space. #---------------------------------------------------------- # Close the current in GPX. if ($gpx_in_trk) { gpx_print_trk_end($fp_gpx_trk) if ($opt_t or $opt_c); $gpx_in_trk = 0; } if ($expected_records_sector == 0xffff) { # Sector record count = 0xffff means this is the currently writing sector. # We found empty space, so we skip to sector end. $new_offset = $SIZEOF_SECTOR * (int(tell($fp) / $SIZEOF_SECTOR) + 1); if ($new_offset < $log_len) { # Log file contains more data (that is old data, being overwritten). seek($fp, $new_offset, 0); next; # Search for the next record or record separator. } else { # End Of File. if (!defined($opt_b)) { printf("ERROR: End of log file! Total record count: %u, expected %u\n", $record_count_total, $expected_records_total); } else { printf("Total record count: %u\n", $record_count_total); } last; } } else { # ERROR! Non written space, but this is not the writing sector. printf("ERROR: Non written space! Read %u records, expected %u\n", $record_count_sector, $expected_records_sector); next if ($opt_i); last; } } else { # None of above, should be record data: rewind the file pointer so we can read it. seek($fp, -$SIZEOF_SEPARATOR, 1); } } #----------------------------------------- # Read a log record. #----------------------------------------- $record_count_sector++; $record_count_total++; $checksum = 0; printf("Reading log sector: record %u (%u/%u total)\n", $record_count_sector, $record_count_total, $expected_records_total) if ($debug >= $LOG_INFO); # Read each record field. undef($record_utc); if ($log_format & $LOG_FORMAT_UTC) { $buffer = my_read($fp, $SIZEOF_LOG_UTC); $checksum ^= packet_checksum($buffer); $timestamp = fix_timestamp_rollover(mtk2long($buffer)); if ($timestamp > $max_timestamp) { $max_timestamp = $timestamp; } $record_utc = utc_time($timestamp); printf("Record UTC: %s %s\n", uc(unpack('H*', $buffer)), $record_utc) if ($debug >= $LOG_DEBUG); } undef($record_valid); if ($log_format & $LOG_FORMAT_VALID) { $buffer = my_read($fp, $SIZEOF_LOG_VALID); $checksum ^= packet_checksum($buffer); $record_valid = mtk2unsignedword($buffer); printf("Record VALID: %s (0x%04X = %s)\n", uc(unpack('H*', $buffer)), $record_valid, describe_valid_mtk($record_valid)) if ($debug >= $LOG_DEBUG); } undef($record_latitude); if ($log_format & $LOG_FORMAT_LATITUDE) { $buffer = my_read($fp, $SIZEOF_LOG_LATITUDE); $checksum ^= packet_checksum($buffer); $record_latitude = mtk2number($buffer, $SIZEOF_LOG_LATITUDE); printf("Record LATITUDE: %s (%.9f)\n", uc(unpack('H*', $buffer)), $record_latitude) if ($debug >= $LOG_DEBUG); } undef($record_longitude); if ($log_format & $LOG_FORMAT_LONGITUDE) { $buffer = my_read($fp, $SIZEOF_LOG_LONGITUDE); $checksum ^= packet_checksum($buffer); $record_longitude = mtk2number($buffer, $SIZEOF_LOG_LONGITUDE); printf("Record LONGITUDE: %s (%.9f)\n", uc(unpack('H*', $buffer)), $record_longitude) if ($debug >= $LOG_DEBUG); } undef($record_height); if ($log_format & $LOG_FORMAT_HEIGHT) { $buffer = my_read($fp, $SIZEOF_LOG_HEIGHT); $checksum ^= packet_checksum($buffer); $record_height = mtk2number($buffer, $SIZEOF_LOG_HEIGHT); printf("Record HEIGHT: %s (%.6f)\n", uc(unpack('H*', $buffer)), $record_height) if ($debug >= $LOG_DEBUG); } undef($record_speed); if ($log_format & $LOG_FORMAT_SPEED) { $buffer = my_read($fp, $SIZEOF_LOG_SPEED); $checksum ^= packet_checksum($buffer); $record_speed = mtk2number($buffer, $SIZEOF_LOG_SPEED); printf("Record SPEED: %s (%.6f)\n", uc(unpack('H*', $buffer)), $record_speed) if ($debug >= $LOG_DEBUG); } undef($record_heading); if ($log_format & $LOG_FORMAT_HEADING) { $buffer = my_read($fp, $SIZEOF_LOG_HEADING); $checksum ^= packet_checksum($buffer); $record_heading = mtk2number($buffer, $SIZEOF_LOG_HEADING); printf("Record HEADING: %s (%.6f)\n", uc(unpack('H*', $buffer)), $record_heading) if ($debug >= $LOG_DEBUG); } undef($record_dsta); if ($log_format & $LOG_FORMAT_DSTA) { $buffer = my_read($fp, $SIZEOF_LOG_DSTA); $checksum ^= packet_checksum($buffer); $record_dsta = mtk2unsignedword($buffer); printf("Record DSTA: %s (%u)\n", uc(unpack('H*', $buffer)), $record_dsta) if ($debug >= $LOG_DEBUG); } undef($record_dage); if ($log_format & $LOG_FORMAT_DAGE) { $buffer = my_read($fp, $SIZEOF_LOG_DAGE); $checksum ^= packet_checksum($buffer); $record_dage = mtk2long($buffer); printf("Record DAGE: %s (%u)\n", uc(unpack('H*', $buffer)), $record_dage) if ($debug >= $LOG_DEBUG); } undef($record_pdop); if ($log_format & $LOG_FORMAT_PDOP) { $buffer = my_read($fp, $SIZEOF_LOG_PDOP); $checksum ^= packet_checksum($buffer); $record_pdop = mtk2unsignedword($buffer) / 100; printf("Record PDOP: %s (%.2f)\n", uc(unpack('H*', $buffer)), $record_pdop) if ($debug >= $LOG_DEBUG); } undef($record_hdop); if ($log_format & $LOG_FORMAT_HDOP) { $buffer = my_read($fp, $SIZEOF_LOG_HDOP); $checksum ^= packet_checksum($buffer); $record_hdop = mtk2unsignedword($buffer) / 100; printf("Record HDOP: %s (%.2f)\n", uc(unpack('H*', $buffer)), $record_hdop) if ($debug >= $LOG_DEBUG); } undef($record_vdop); if ($log_format & $LOG_FORMAT_VDOP) { $buffer = my_read($fp, $SIZEOF_LOG_VDOP); $checksum ^= packet_checksum($buffer); $record_vdop = mtk2unsignedword($buffer) / 100; printf("Record VDOP: %s (%.2f)\n", uc(unpack('H*', $buffer)), $record_vdop) if ($debug >= $LOG_DEBUG); } undef($record_nsat_in_use); undef($record_nsat_in_view); if ($log_format & $LOG_FORMAT_NSAT) { $buffer = my_read($fp, $SIZEOF_BYTE); $checksum ^= packet_checksum($buffer); $record_nsat_in_view = mtk2byte($buffer); $buffer = my_read($fp, $SIZEOF_BYTE); $checksum ^= packet_checksum($buffer); $record_nsat_in_use = mtk2byte($buffer); printf("Record NSAT: in view %u, in use %u\n", $record_nsat_in_view, $record_nsat_in_use) if ($debug >= $LOG_DEBUG); } undef($record_satdata); if ($log_format & $LOG_FORMAT_SID) { my $satdata_count = 0; my $satdata_sid; my $satdata_inuse; my $satdata_inview; my $satdata_elevation; my $satdata_azimuth; my $satdata_snr; while (1) { # Even with zero satellites in view, we have at least one bunch of data. $buffer = my_read($fp, $SIZEOF_LOG_SID); $checksum ^= packet_checksum($buffer); $satdata_sid = mtk2byte($buffer); $buffer = my_read($fp, $SIZEOF_LOG_SIDINUSE); $checksum ^= packet_checksum($buffer); $satdata_inuse = mtk2byte($buffer); $buffer = my_read($fp, $SIZEOF_LOG_SATSINVIEW); $checksum ^= packet_checksum($buffer); $satdata_inview = mtk2unsignedword($buffer); if ($satdata_inview == 0) { printf("No satellites in view\n") if ($debug >= $LOG_DEBUG); } else { # Read data for this satellite. printf("Sats in view: %u, SatID %u in use: %u\n", $satdata_inview, $satdata_sid, $satdata_inuse) if ($debug >= $LOG_DEBUG); undef($satdata_elevation); if ($log_format & $LOG_FORMAT_ELEVATION) { $buffer = my_read($fp, $SIZEOF_LOG_ELEVATION); $checksum ^= packet_checksum($buffer); $satdata_elevation = mtk2signedword($buffer); printf("Satellite ELEVATION: %s (%d)\n", uc(unpack('H*', $buffer)), $satdata_elevation) if ($debug >= $LOG_DEBUG); } undef($satdata_azimuth); if ($log_format & $LOG_FORMAT_AZIMUTH) { $buffer = my_read($fp, $SIZEOF_LOG_AZIMUTH); $checksum ^= packet_checksum($buffer); $satdata_azimuth = mtk2unsignedword($buffer); printf("Satellite AZIMUTH: %s (%u)\n", uc(unpack('H*', $buffer)), $satdata_azimuth) if ($debug >= $LOG_DEBUG); } undef($satdata_snr); if ($log_format & $LOG_FORMAT_SNR) { $buffer = my_read($fp, $SIZEOF_LOG_SNR); $checksum ^= packet_checksum($buffer); $satdata_snr = mtk2unsignedword($buffer); printf("Satellite SNR: %s (%u)\n", uc(unpack('H*', $buffer)), $satdata_snr) if ($debug >= $LOG_DEBUG); } $record_satdata .= "\n" if ($record_satdata ne ''); $record_satdata .= $satdata_sid . "\t"; $record_satdata .= $satdata_inuse . "\t"; $record_satdata .= $satdata_elevation . "\t"; $record_satdata .= $satdata_azimuth . "\t"; $record_satdata .= $satdata_snr; $satdata_count++; } last if ($satdata_count >= $satdata_inview); } } undef($record_rcr); if ($log_format & $LOG_FORMAT_RCR) { $buffer = my_read($fp, $SIZEOF_LOG_RCR); $checksum ^= packet_checksum($buffer); $record_rcr = mtk2unsignedword($buffer); printf("Record RCR: %s (%s)\n", uc(unpack('H*', $buffer)), describe_rcr_mtk($record_rcr)) if ($debug >= $LOG_DEBUG); } undef($record_millisecond); if ($log_format & $LOG_FORMAT_MILLISECOND) { $buffer = my_read($fp, $SIZEOF_LOG_MILLISECOND); $checksum ^= packet_checksum($buffer); $record_millisecond = mtk2unsignedword($buffer); printf("Record MILLISECOND: %s (%u)\n", uc(unpack('H*', $buffer)), $record_millisecond) if ($debug >= $LOG_DEBUG); } undef($record_distance); if ($log_format & $LOG_FORMAT_DISTANCE) { $buffer = my_read($fp, $SIZEOF_LOG_DISTANCE); $checksum ^= packet_checksum($buffer); $record_distance = mtk2number($buffer, $SIZEOF_LOG_DISTANCE); printf("Record DISTANCE: %s (%.9f)\n", uc(unpack('H*', $buffer)), $record_distance) if ($debug >= $LOG_DEBUG); } if ($LOG_HAS_CHECKSUM_SEPARATOR) { # Read separator between data and checksum. $buffer = my_read($fp, $SIZEOF_BYTE); if ($buffer ne '*') { printf("ERROR: Checksum separator error: expected char 0x%02X, found 0x%02X\n", ord('*'), ord($buffer)); last if (! $opt_i); next if (! $opt_I); } } # Read and verify checksum. $buffer = my_read($fp, $SIZEOF_BYTE); if ($checksum != ord($buffer)) { printf("ERROR: Record checksum error: expected 0x%02X, computed 0x%02X\n", ord($buffer), $checksum); last if (! $opt_i); next if (! $opt_I); } # Start a new GPX on satellite lost. if (($record_valid == $VALID_NOFIX) and $gpx_in_trk) { gpx_print_trk_end($fp_gpx_trk) if ($opt_t or $opt_c); $gpx_in_trk = 0; } if (defined($record_latitude) and defined($record_longitude)) { if ($next_data_force_waypoint) { # Write data in GPX file. gpx_print_wpt($fp_gpx_wpt) if ($opt_w or $opt_c); $next_data_force_waypoint = 0; } else { # Write data in GPX file. if (($record_valid != $VALID_NOFIX) and !($record_rcr & $RCR_BUTTON)) { if (! $gpx_in_trk) { gpx_print_trk_begin($fp_gpx_trk) if ($opt_t or $opt_c); $gpx_in_trk = 1; } gpx_print_trkpt($fp_gpx_trk) if ($opt_t or $opt_c); } # Write data in GPX file. if (($record_rcr & $RCR_BUTTON) and ($record_valid != $VALID_NOFIX)) { gpx_print_wpt($fp_gpx_wpt) if ($opt_w or $opt_c); } } } } close($fp); # Eventually close the GPX tags. if ($gpx_in_trk) { gpx_print_trk_end($fp_gpx_trk) if ($opt_t or $opt_c); $gpx_in_trk = 0; } # Close temporary files. close($fp_gpx_trk) if ($opt_t or $opt_c); close($fp_gpx_wpt) if ($opt_w or $opt_c); # Warn about Weeks Rollover Bug. if ($max_timestamp > 0) { if (((time() - $max_timestamp) / $SECONDS_IN_WEEK) > $WEEKS_ROLLOVER) { printf("%s Very old timestamps: probable Weeks Rollover Bug. Try using option -W -1\n", log_time()) if ($debug >= $LOG_WARNING); } } # Write GPX combined tracks and waypoint file. if ($opt_c) { my $gpx_minlat = $gpx_trk_minlat < $gpx_wpt_minlat ? $gpx_trk_minlat : $gpx_wpt_minlat; my $gpx_maxlat = $gpx_trk_maxlat > $gpx_wpt_maxlat ? $gpx_trk_maxlat : $gpx_wpt_maxlat; my $gpx_minlon = $gpx_trk_minlon < $gpx_wpt_minlon ? $gpx_trk_minlon : $gpx_wpt_minlon; my $gpx_maxlon = $gpx_trk_maxlon > $gpx_wpt_maxlon ? $gpx_trk_maxlon : $gpx_wpt_maxlon; open($fp_gpx, ">$gpx_fname") or die("ERROR writing $gpx_fname: $!"); gpx_print_gpx_begin($fp_gpx, time(), $gpx_minlat, $gpx_minlon, $gpx_maxlat, $gpx_maxlon); open($fp_gpx_trk, "$gpx_trk_tmp_fname") or die; while (<$fp_gpx_trk>) { print $fp_gpx $_; } close($fp_gpx_trk); open($fp_gpx_wpt, "$gpx_wpt_tmp_fname") or die; while (<$fp_gpx_wpt>) { print $fp_gpx $_; } close($fp_gpx_wpt); gpx_print_gpx_end($fp_gpx); close($fp_gpx); } # Write GPX tracks file. if ($opt_t) { open($fp_gpx, ">$gpx_trk_fname") or die("ERROR writing $gpx_trk_fname: $!"); gpx_print_gpx_begin($fp_gpx, time(), $gpx_trk_minlat, $gpx_trk_minlon, $gpx_trk_maxlat, $gpx_trk_maxlon); open($fp_gpx_trk, "$gpx_trk_tmp_fname") or die; while (<$fp_gpx_trk>) { print $fp_gpx $_; } close($fp_gpx_trk); gpx_print_gpx_end($fp_gpx); close($fp_gpx); } # Write GPX waypoints file. if ($opt_w) { open($fp_gpx, ">$gpx_wpt_fname") or die("ERROR writing $gpx_wpt_fname: $!"); gpx_print_gpx_begin($fp_gpx, time(), $gpx_wpt_minlat, $gpx_wpt_minlon, $gpx_wpt_maxlat, $gpx_wpt_maxlon); open($fp_gpx_wpt, "$gpx_wpt_tmp_fname") or die; while (<$fp_gpx_wpt>) { print $fp_gpx $_; } close($fp_gpx_wpt); gpx_print_gpx_end($fp_gpx); close($fp_gpx); } # Remove temporary files. unlink($gpx_trk_tmp_fname) if ($opt_t or $opt_c); unlink($gpx_wpt_tmp_fname) if ($opt_w or $opt_c); } #------------------------------------------------------------------------- # Read some bytes from the device and return them. #------------------------------------------------------------------------- sub my_read { my $handle = shift; my $length = shift; my $variable; my $n = read($handle, $variable, $length); printf("ERROR: Reading file: read %u bytes, expected %u\n", $n, $length) if ($n != $length); return($variable); } #------------------------------------------------------------------------- # Parse the header (0x200 bytes) of a datalog sector (every 0x10000 bytes). # Return the number of records in the sector and the log format. #------------------------------------------------------------------------- sub parse_sector_header { my $sector_header = shift; if ($debug >= $LOG_NOTICE) { printf("\n"); printf("Sector header: %s\n", uc(unpack('H*', $sector_header))) if ($debug >= $LOG_DEBUG); } # Check validity of sector header. my $separator = substr($sector_header, -6, 1); # Should be '*' my $checksum = ord(substr($sector_header, -5, $SIZEOF_BYTE)); # WARNING: It's not the XOR checksum!!! my $header_tail = substr($sector_header, -4, 4); # Should be 0xBBBBBBBB if (($separator ne '*') or ($header_tail ne (chr(0xBB) x 4))) { printf("ERROR: Invalid datalog sector header\n"); return(undef, undef); } # Settings of this log sector (hex values, LSB first). my $log_count = substr($sector_header, 0, $SIZEOF_WORD); # Record count in this sector. 0xFFFF if the sector is not filled. my $log_format = substr($sector_header, 2, $SIZEOF_LONG); # Log format bitmask my $log_status = substr($sector_header, 6, $SIZEOF_WORD); # Log mode bitmask my $log_period = substr($sector_header, 8, $SIZEOF_LONG); # Log period in 10ths of s my $log_distance = substr($sector_header, 12, $SIZEOF_LONG); # Log distance in 10ths of m my $log_speed = substr($sector_header, 16, $SIZEOF_LONG); # Log speed in 10ths ok km/h my $log_failsect = substr($sector_header, 20, $SIZEOF_BYTE * 32); # Failed sectors bitmask my $count = unpack('S', $log_count); my $format = unpack('L', $log_format); my $status = unpack('S', $log_status); my $period = unpack('L', $log_period); my $distance = unpack('L', $log_distance); my $speed = unpack('L', $log_speed); if ($debug >= $LOG_NOTICE) { printf("Record count: %s %s %u records\n", uc(unpack('H*', $log_count)), ' 'x6, $count); printf("Log format mask: %s %s %032bb (%s)\n", uc(unpack('H*', $log_format)), ' 'x2, $format, describe_log_format($format)); printf("Log mode mask: %s %s %016bb (%s)\n", uc(unpack('H*', $log_status)), ' 'x6, $status, describe_log_status($status)); printf("Log period: %s %s %6.2f s\n", uc(unpack('H*', $log_period)), ' 'x2, $period / 10); printf("Log distance: %s %s %6.2f m\n", uc(unpack('H*', $log_distance)), ' 'x2, $distance / 10); printf("Log speed: %s %s %6.2f km/h\n", uc(unpack('H*', $log_speed)), ' 'x2, $speed / 10); printf("Failed sectors mask: %s\n", uc(unpack('H*', $log_failsect))); printf("\n"); } return($count, $format); } #------------------------------------------------------------------------- # Given a log format value (bitmask), return a description string. #------------------------------------------------------------------------- sub describe_log_format { my $log_format = shift; my $str = ''; $str .= ',UTC' if ($log_format & $LOG_FORMAT_UTC); $str .= ',VALID' if ($log_format & $LOG_FORMAT_VALID); $str .= ',LATITUDE' if ($log_format & $LOG_FORMAT_LATITUDE); $str .= ',LONGITUDE' if ($log_format & $LOG_FORMAT_LONGITUDE); $str .= ',HEIGHT' if ($log_format & $LOG_FORMAT_HEIGHT); $str .= ',SPEED' if ($log_format & $LOG_FORMAT_SPEED); $str .= ',HEADING' if ($log_format & $LOG_FORMAT_HEADING); $str .= ',DSTA' if ($log_format & $LOG_FORMAT_DSTA); $str .= ',DAGE' if ($log_format & $LOG_FORMAT_DAGE); $str .= ',PDOP' if ($log_format & $LOG_FORMAT_PDOP); $str .= ',HDOP' if ($log_format & $LOG_FORMAT_HDOP); $str .= ',VDOP' if ($log_format & $LOG_FORMAT_VDOP); $str .= ',NSAT' if ($log_format & $LOG_FORMAT_NSAT); $str .= ',SID' if ($log_format & $LOG_FORMAT_SID); $str .= ',ELEVATION' if ($log_format & $LOG_FORMAT_ELEVATION); $str .= ',AZIMUTH' if ($log_format & $LOG_FORMAT_AZIMUTH); $str .= ',SNR' if ($log_format & $LOG_FORMAT_SNR); $str .= ',RCR' if ($log_format & $LOG_FORMAT_RCR); $str .= ',MILLISECOND' if ($log_format & $LOG_FORMAT_MILLISECOND); $str .= ',DISTANCE' if ($log_format & $LOG_FORMAT_DISTANCE); return(substr($str, 1)); } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- sub encode_log_format { my $log_format = shift; my $changes = shift; $log_format |= $LOG_FORMAT_UTC if ($changes =~ m/\bUTC\b/); $log_format |= $LOG_FORMAT_VALID if ($changes =~ m/\bVALID\b/); $log_format |= $LOG_FORMAT_LATITUDE if ($changes =~ m/\bLATITUDE\b/); $log_format |= $LOG_FORMAT_LONGITUDE if ($changes =~ m/\bLONGITUDE\b/); $log_format |= $LOG_FORMAT_HEIGHT if ($changes =~ m/\bHEIGHT\b/); $log_format |= $LOG_FORMAT_SPEED if ($changes =~ m/\bSPEED\b/); $log_format |= $LOG_FORMAT_HEADING if ($changes =~ m/\bHEADING\b/); $log_format |= $LOG_FORMAT_DSTA if ($changes =~ m/\bDSTA\b/); $log_format |= $LOG_FORMAT_DAGE if ($changes =~ m/\bDAGE\b/); $log_format |= $LOG_FORMAT_PDOP if ($changes =~ m/\bPDOP\b/); $log_format |= $LOG_FORMAT_HDOP if ($changes =~ m/\bHDOP\b/); $log_format |= $LOG_FORMAT_VDOP if ($changes =~ m/\bVDOP\b/); $log_format |= $LOG_FORMAT_NSAT if ($changes =~ m/\bNSAT\b/); $log_format |= $LOG_FORMAT_SID if ($changes =~ m/\bSID\b/); $log_format |= $LOG_FORMAT_ELEVATION if ($changes =~ m/\bELEVATION\b/); $log_format |= $LOG_FORMAT_AZIMUTH if ($changes =~ m/\bAZIMUTH\b/); $log_format |= $LOG_FORMAT_SNR if ($changes =~ m/\bSNR\b/); $log_format |= $LOG_FORMAT_RCR if ($changes =~ m/\bRCR\b/); $log_format |= $LOG_FORMAT_MILLISECOND if ($changes =~ m/\bMILLISECOND\b/); $log_format |= $LOG_FORMAT_DISTANCE if ($changes =~ m/\bDISTANCE\b/); $log_format &= ~$LOG_FORMAT_UTC if ($changes =~ m/-UTC\b/); $log_format &= ~$LOG_FORMAT_VALID if ($changes =~ m/-VALID\b/); $log_format &= ~$LOG_FORMAT_LATITUDE if ($changes =~ m/-LATITUDE\b/); $log_format &= ~$LOG_FORMAT_LONGITUDE if ($changes =~ m/-LONGITUDE\b/); $log_format &= ~$LOG_FORMAT_HEIGHT if ($changes =~ m/-HEIGHT\b/); $log_format &= ~$LOG_FORMAT_SPEED if ($changes =~ m/-SPEED\b/); $log_format &= ~$LOG_FORMAT_HEADING if ($changes =~ m/-HEADING\b/); $log_format &= ~$LOG_FORMAT_DSTA if ($changes =~ m/-DSTA\b/); $log_format &= ~$LOG_FORMAT_DAGE if ($changes =~ m/-DAGE\b/); $log_format &= ~$LOG_FORMAT_PDOP if ($changes =~ m/-PDOP\b/); $log_format &= ~$LOG_FORMAT_HDOP if ($changes =~ m/-HDOP\b/); $log_format &= ~$LOG_FORMAT_VDOP if ($changes =~ m/-VDOP\b/); $log_format &= ~$LOG_FORMAT_NSAT if ($changes =~ m/-NSAT\b/); $log_format &= ~$LOG_FORMAT_SID if ($changes =~ m/-SID\b/); $log_format &= ~$LOG_FORMAT_ELEVATION if ($changes =~ m/-ELEVATION\b/); $log_format &= ~$LOG_FORMAT_AZIMUTH if ($changes =~ m/-AZIMUTH\b/); $log_format &= ~$LOG_FORMAT_SNR if ($changes =~ m/-SNR\b/); $log_format &= ~$LOG_FORMAT_RCR if ($changes =~ m/-RCR\b/); $log_format &= ~$LOG_FORMAT_MILLISECOND if ($changes =~ m/-MILLISECOND\b/); $log_format &= ~$LOG_FORMAT_DISTANCE if ($changes =~ m/-DISTANCE\b/); return($log_format); } #------------------------------------------------------------------------- # Given a log format value (bitmask), return the record size in bytes. #------------------------------------------------------------------------- sub sizeof_log_format { my $log_format = shift; my $size_wpt = 0; my $size_sat = 0; $size_wpt += $SIZEOF_LOG_UTC if ($log_format & $LOG_FORMAT_UTC); $size_wpt += $SIZEOF_LOG_VALID if ($log_format & $LOG_FORMAT_VALID); $size_wpt += $SIZEOF_LOG_LATITUDE if ($log_format & $LOG_FORMAT_LATITUDE); $size_wpt += $SIZEOF_LOG_LONGITUDE if ($log_format & $LOG_FORMAT_LONGITUDE); $size_wpt += $SIZEOF_LOG_HEIGHT if ($log_format & $LOG_FORMAT_HEIGHT); $size_wpt += $SIZEOF_LOG_SPEED if ($log_format & $LOG_FORMAT_SPEED); $size_wpt += $SIZEOF_LOG_HEADING if ($log_format & $LOG_FORMAT_HEADING); $size_wpt += $SIZEOF_LOG_DSTA if ($log_format & $LOG_FORMAT_DSTA); $size_wpt += $SIZEOF_LOG_DAGE if ($log_format & $LOG_FORMAT_DAGE); $size_wpt += $SIZEOF_LOG_PDOP if ($log_format & $LOG_FORMAT_PDOP); $size_wpt += $SIZEOF_LOG_HDOP if ($log_format & $LOG_FORMAT_HDOP); $size_wpt += $SIZEOF_LOG_VDOP if ($log_format & $LOG_FORMAT_VDOP); $size_wpt += $SIZEOF_LOG_NSAT if ($log_format & $LOG_FORMAT_NSAT); # Variable part, for each satellite: if ($log_format & $LOG_FORMAT_SID) { $size_sat += $SIZEOF_LOG_SID; $size_sat += $SIZEOF_LOG_SIDINUSE; $size_sat += $SIZEOF_LOG_SATSINVIEW; $size_sat += $SIZEOF_LOG_ELEVATION if ($log_format & $LOG_FORMAT_ELEVATION); $size_sat += $SIZEOF_LOG_AZIMUTH if ($log_format & $LOG_FORMAT_AZIMUTH); $size_sat += $SIZEOF_LOG_SNR if ($log_format & $LOG_FORMAT_SNR); } $size_wpt += $SIZEOF_LOG_RCR if ($log_format & $LOG_FORMAT_RCR); $size_wpt += $SIZEOF_LOG_MILLISECOND if ($log_format & $LOG_FORMAT_MILLISECOND); $size_wpt += $SIZEOF_LOG_DISTANCE if ($log_format & $LOG_FORMAT_DISTANCE); return($size_wpt, $size_sat); } #------------------------------------------------------------------------- # Return a string describing the log record separator type. #------------------------------------------------------------------------- sub describe_separator_type { my $sep_type = shift; return('CHANGE_LOG_BITMASK') if ($sep_type == $SEP_TYPE_CHANGE_LOG_BITMASK); return('CHANGE_LOG_PERIOD') if ($sep_type == $SEP_TYPE_CHANGE_LOG_PERIOD); return('CHANGE_LOG_DISTANCE') if ($sep_type == $SEP_TYPE_CHANGE_LOG_DISTANCE); return('CHANGE_LOG_SPEED') if ($sep_type == $SEP_TYPE_CHANGE_LOG_SPEED); return('CHANGE_OVERLAP_STOP') if ($sep_type == $SEP_TYPE_CHANGE_OVERLAP_STOP); return('CHANGE_START_STOP_LOG') if ($sep_type == $SEP_TYPE_CHANGE_START_STOP_LOG); return('Unknown'); } #------------------------------------------------------------------------- # Return a string describing some field. #------------------------------------------------------------------------- sub describe_valid_mtk { my $valid = shift; return('nofix') if ($valid == $VALID_NOFIX); return('sps') if ($valid == $VALID_SPS); return('dgps') if ($valid == $VALID_DGPS); return('pps') if ($valid == $VALID_PPS); return('rtk') if ($valid == $VALID_RTK); return('frtk') if ($valid == $VALID_FRTK); return('estimated') if ($valid == $VALID_ESTIMATED); return('manual') if ($valid == $VALID_MANUAL); return('simulator') if ($valid == $VALID_SIMULATOR); return('Unknown'); } # Description suitable for GPX element. sub describe_valid_gpx { my $valid = shift; return('none') if ($valid == $VALID_NOFIX); return('3d') if ($valid == $VALID_SPS); return('dgps') if ($valid == $VALID_DGPS); return('pps') if ($valid == $VALID_PPS); return(undef); } sub describe_rcr_mtk { my $rcr = shift; my $str = ''; $str .= ',TIME' if ($rcr & $RCR_TIME); $str .= ',SPEED' if ($rcr & $RCR_SPEED); $str .= ',DISTANCE' if ($rcr & $RCR_DISTANCE); $str .= ',BUTTON' if ($rcr & $RCR_BUTTON); return('Unknown') if ($str eq ''); return(substr($str, 1)); } # Description suitable for GPX element. sub describe_rcr_gpx { my $rcr = shift; my $str = ''; $str .= ',TIME' if ($rcr & $RCR_TIME); $str .= ',SPEED' if ($rcr & $RCR_SPEED); $str .= ',DISTANCE' if ($rcr & $RCR_DISTANCE); $str .= ',BUTTON' if ($rcr & $RCR_BUTTON); return(undef) if ($str eq ''); return(substr($str, 1)); } sub describe_log_status { my $log_status = shift; my $str = ''; if ($log_status & $LOG_STATUS_AUTOLOG) { $str .= ',AUTOLOG_ON'; } else { $str .= ',AUTOLOG_OFF'; } if ($log_status & $LOG_STATUS_STOP_WHEN_FULL) { $str .= ',STOP_WHEN_FULL'; } else { $str .= ',OVERLAP_WHEN_FULL'; } if ($log_status & $LOG_STATUS_ENABLE) { $str .= ',ENABLE_LOG'; } if ($log_status & $LOG_STATUS_DISABLE) { $str .= ',DISABLE_LOG'; } if ($log_status & $LOG_STATUS_NEED_FORMAT) { $str .= ',NEED_FORMAT'; } if ($log_status & $LOG_STATUS_FULL) { $str .= ',FULL'; } return(substr($str, 1)); } sub describe_recording_method { my $val = shift; return('OVERLAP') if ($val == $RCD_METHOD_OVP); return('STOP') if ($val == $RCD_METHOD_STP); return('Unknown'); } #------------------------------------------------------------------------- # Silly function: return a byte! #------------------------------------------------------------------------- sub mtk2byte { ord(shift); } #------------------------------------------------------------------------- # Convert a 16 bit binary data into an integer. #------------------------------------------------------------------------- sub mtk2unsignedword { unpack('S', shift); } sub mtk2signedword{ unpack('s', shift); } #------------------------------------------------------------------------- # Convert a 32 bit binary data into a long integer number. #------------------------------------------------------------------------- sub mtk2long { unpack('L', shift); } #------------------------------------------------------------------------- # Convert 24, 32 or 64 bit binary data into a number. #------------------------------------------------------------------------- sub mtk2number { my $buffer = shift; my $size = shift; if ($size == $SIZEOF_FLOAT3) { return unpack('f', chr(0) . $buffer); } elsif ($size == $SIZEOF_FLOAT) { return unpack('f', $buffer); } elsif ($size == $SIZEOF_DOUBLE) { return unpack('d', $buffer); } } #------------------------------------------------------------------------- # Convert seconds from epoch (long int) to UTC timestamp. #------------------------------------------------------------------------- sub utc_time { time2str('%Y-%m-%dT%H:%M:%SZ', shift, 'GMT'); } #------------------------------------------------------------------------- # Print the header of a GPX file. #------------------------------------------------------------------------- sub gpx_print_gpx_begin { my $fp = shift; my $time = shift; my $minlat = shift; my $minlon = shift; my $maxlat = shift; my $maxlon = shift; print $fp sprintf('%s', $GPX_EOL); print $fp '' . $GPX_EOL; print $fp sprintf('%s', $GPX_EOL); print $fp sprintf(' %s', utc_time($time), $GPX_EOL); print $fp sprintf(' %s', $minlat, $minlon, $maxlat, $maxlon, $GPX_EOL); print $fp sprintf('%s', $GPX_EOL); } sub gpx_print_gpx_end { my $fp = shift; print $fp sprintf('%s', $GPX_EOL); } #------------------------------------------------------------------------- # Open and close the GPX tag. #------------------------------------------------------------------------- sub gpx_print_trk_begin { my $fp = shift; print $fp sprintf('%s', $GPX_EOL); print $fp sprintf(' %s%s', $record_utc, $GPX_EOL); print $fp sprintf(' %u%s', $gpx_trk_number, $GPX_EOL) if ($gpx_trk_number > 0);; print $fp sprintf('%s', $GPX_EOL); $gpx_trk_number++; } sub gpx_print_trk_end { my $fp = shift; print $fp sprintf('%s', $GPX_EOL); print $fp sprintf('%s', $GPX_EOL); } #------------------------------------------------------------------------- # Print a GPX . #------------------------------------------------------------------------- sub gpx_print_trkpt { my $fp = shift; print $fp sprintf('%s', $record_latitude, $record_longitude, $GPX_EOL); print $fp sprintf(' %.6f%s', $record_height, $GPX_EOL) if (defined($record_height)); print $fp sprintf(' %s', $record_utc, $GPX_EOL) if (defined($record_utc)); gpx_print_pt_attributes($fp); print $fp sprintf('%s', $GPX_EOL); $gpx_trk_minlat = $record_latitude if ($record_latitude < $gpx_trk_minlat); $gpx_trk_maxlat = $record_latitude if ($record_latitude > $gpx_trk_maxlat); $gpx_trk_minlon = $record_longitude if ($record_longitude < $gpx_trk_minlon); $gpx_trk_maxlon = $record_longitude if ($record_longitude > $gpx_trk_maxlon); } #------------------------------------------------------------------------- # Print a GPX . #------------------------------------------------------------------------- sub gpx_print_wpt { my $fp = shift; $gpx_wpt_number++; print $fp sprintf('%s', $record_latitude, $record_longitude, $GPX_EOL); print $fp sprintf(' %.6f%s', $record_height, $GPX_EOL) if (defined($record_height)); print $fp sprintf(' %s', $record_utc, $GPX_EOL) if (defined($record_utc)); print $fp sprintf(' %03d%s', $gpx_wpt_number, $GPX_EOL); print $fp sprintf(' %03d%s', $gpx_wpt_number, $GPX_EOL); print $fp sprintf(' %s%s', $record_utc, $GPX_EOL) if (defined($record_utc)); print $fp sprintf(' Flag%s', $GPX_EOL); gpx_print_pt_attributes($fp); print $fp sprintf('%s', $GPX_EOL); $gpx_wpt_minlat = $record_latitude if ($record_latitude < $gpx_wpt_minlat); $gpx_wpt_maxlat = $record_latitude if ($record_latitude > $gpx_wpt_maxlat); $gpx_wpt_minlon = $record_longitude if ($record_longitude < $gpx_wpt_minlon); $gpx_wpt_maxlon = $record_longitude if ($record_longitude > $gpx_wpt_maxlon); } #------------------------------------------------------------------------- # Print and common attributes. #------------------------------------------------------------------------- sub gpx_print_pt_attributes { my $fp = shift; print $fp sprintf(' %s%s', describe_rcr_gpx($record_rcr), $GPX_EOL) if (describe_rcr_gpx($record_rcr)); print $fp sprintf(' %s%s', describe_valid_gpx($record_valid), $GPX_EOL) if (describe_valid_gpx($record_valid)); print $fp sprintf(' %u%s', $record_nsat_in_use, $GPX_EOL) if (defined($record_nsat_in_use)); print $fp sprintf(' %.2f%s', $record_hdop, $GPX_EOL) if (defined($record_hdop)); print $fp sprintf(' %.2f%s', $record_vdop, $GPX_EOL) if (defined($record_vdop)); print $fp sprintf(' %.2f%s', $record_pdop, $GPX_EOL) if (defined($record_pdop)); print $fp sprintf(' %u%s', $record_dage, $GPX_EOL) if (defined($record_dage)); print $fp sprintf(' %u%s', $record_dsta, $GPX_EOL) if (defined($record_dsta)); if (defined($record_speed) or defined($record_heading) or defined($record_nsat_in_view) or defined($record_millisecond) or defined($record_distance) or defined($record_satdata)) { print $fp sprintf(' %s', $GPX_EOL); print $fp sprintf(' %s', $GPX_EOL); print $fp sprintf(' %s%s', describe_valid_mtk($record_valid), $GPX_EOL) if (defined($record_valid)); print $fp sprintf(' %.6f%s', $record_speed, $GPX_EOL) if (defined($record_speed)); print $fp sprintf(' %.6f%s', $record_heading, $GPX_EOL) if (defined($record_heading)); print $fp sprintf(' %u%s', $record_nsat_in_view, $GPX_EOL) if (defined($record_nsat_in_view)); if (defined($record_satdata)) { my $sat; foreach $sat (split(/\n/, $record_satdata)) { my ($sid, $inuse, $elevation, $azimuth, $snr) = split(/\t/, $sat); print $fp sprintf(' %s', $sid, $inuse, $GPX_EOL); print $fp sprintf(' %d%s', $elevation, $GPX_EOL) if ($elevation ne ''); print $fp sprintf(' %u%s', $azimuth, $GPX_EOL) if ($azimuth ne ''); print $fp sprintf(' %u%s', $snr, $GPX_EOL) if ($snr ne ''); print $fp sprintf(' %s', $GPX_EOL); } } print $fp sprintf(' %u%s', $record_millisecond, $GPX_EOL) if (defined($record_millisecond)); print $fp sprintf(' %.9f%s', $record_distance, $GPX_EOL) if (defined($record_distance)); print $fp sprintf(' %s', $GPX_EOL); print $fp sprintf(' %s', $GPX_EOL); } } #------------------------------------------------------------------------- # Log time. #------------------------------------------------------------------------- sub log_time { time2str('%H:%M:%S', time()); } #------------------------------------------------------------------------- # Return the flash memory size upon model ID. #------------------------------------------------------------------------- sub flash_memory_size { my $string = shift; my $model = hex('0x' . $string); # 8 Mbit = 1 Mb return( 8 * 1024 * 1024 / 8) if ($model == 0x1388); # 757/ZI v1 return( 8 * 1024 * 1024 / 8) if ($model == 0x5202); # 757/ZI v2 # 32 Mbit = 4 Mb return(32 * 1024 * 1024 / 8) if ($model == 0x0000); # Holux M-1200E return(32 * 1024 * 1024 / 8) if ($model == 0x0005); # Qstarz BT-Q1000P return(32 * 1024 * 1024 / 8) if ($model == 0x0006); # 747 A+ GPS Trip Recorder return(32 * 1024 * 1024 / 8) if ($model == 0x0008); # Pentagram PathFinder P 3106 return(32 * 1024 * 1024 / 8) if ($model == 0x000F); # iBlue 747A+ return(32 * 1024 * 1024 / 8) if ($model == 0x005C); # Holux M-1000C return(32 * 1024 * 1024 / 8) if ($model == 0x8300); # Qstarz BT-1200 # 16Mbit -> 2Mb # 0x0051 i-Blue 737, Qstarz 810, Polaris iBT-GPS, Holux M1000 # 0x0002 Qstarz 815 # 0x001b i-Blue 747 # 0x001d Qstarz BT-Q1000 / BGL-32 # 0x0131 EB-85A return(16 * 1024 * 1024 / 8); } #------------------------------------------------------------------------- # Functions for serial communication. Use the global variable $device. #------------------------------------------------------------------------- # Open the serial port. sub serial_port_open { my $port = shift; my $baudrate = shift; die("Cannot open $port. Did you switch ON the GPS device?\n") if (! -c $port); $device = Device::SerialPort->new($port) || die "ERROR: Opening serial device $port: $!"; $device->baudrate($baudrate) || die "fail setting baud rate"; $device->parity('none') || die "fail setting parity"; $device->databits(8) || die "fail setting databits"; $device->stopbits(1) || die "fail setting stopbits"; $device->handshake('none') || die "fail setting handshake"; $device->write_settings || die "no settings"; } # Close the port. sub serial_port_close { $device->close || warn "close failed"; } # Write the received string to the port. # Return the bytes actually written. sub serial_port_write { return($device->write(shift)); } # Set read timeout (in milliseconds) on the port. sub serial_port_set_read_timeout { $device->read_const_time(shift); } # Get a character from the port. # Return the number of characters read (1 if success) and the character itself. sub serial_port_getch { return($device->read(1)); } #------------------------------------------------------------------------- # Set data type according to GPS model ID. #------------------------------------------------------------------------- sub set_data_types { my $model_id = shift; if ($model_id eq '0000' or $model_id eq '0021' or $model_id eq '0023' or $model_id eq '0043' or $model_id eq '005C') { printf("Setting log format and data types for Holux, model ID %s\n", $model_id) if ($debug >= $LOG_INFO); $LOG_HAS_CHECKSUM_SEPARATOR = 0; $SIZEOF_LOG_LATITUDE = $SIZEOF_FLOAT; $SIZEOF_LOG_LONGITUDE = $SIZEOF_FLOAT; $SIZEOF_LOG_HEIGHT = $SIZEOF_FLOAT3; } } mtkbabel-0.8.4/changelog0000644000175000017500000001042013550354140015011 0ustar niccoloniccolomtkbabel (0.8.4) * Added option -W, workaround for Weeks Rollover Bug. * Merged patch from Andrew Shadura . * Minor code cleaning. -- Niccolo Rigacci Sat, 12 Oct 2019 12:23:29 +0200 mtkbabel (0.8.3.1) * Fixed model detection for Qstarz BT-Q1000P: not Holux format. * Added detection of Holux GPSport 245 and Holux M-1000C. * Refactored handling of Holux separators: HOLUXxxxxxLOGGER and HOLUXxxxxxWAYPNT. * Changed behaviour with-i switch: do not save bad data into the GPX. Added the -I switch to download also bad data. -- Niccolo Rigacci Sat, 30 Jul 2011 18:05:44 +0200 mtkbabel (0.8.3) * Fixed a bug in identifying model (and flash memory size). * Added iBlue 747A+ to the known models, thanks to Bastiaan Naber. * Added binmode() call when opening binary files. -- Niccolo Rigacci Sat, 21 May 2011 15:16:39 +0200 mtkbabel (0.8.2) * Added flash memory size for 747 A+ GPS Trip Recorder, thanks to Thomas Siedlich. * Added support for the Holux M-1200E, which does not embed the Holux string into the binary data. A new -x switch is required to read back such data. Thanks to Paulius Zaleckas. -- Niccolo Rigacci Sat, 03 Apr 2010 01:38:34 +0200 mtkbabel (0.8.1) * Added some GPS models to known flash memory size. * Changed range of loggin criteria, allowing floating point values from 0.10 to 9999999.90, thanks to Stanislav Brabec. * Added support for Holux M-241 firmware 1.13, thanks to Stefan Schöfegger and Luca Niccoli. * Error message for device open errors. -- Niccolo Rigacci Thu, 18 Mar 2010 19:05:05 +0100 mtkbabel (0.8) * Allow more time for the -E and -R commands to execute. * Exit if MTK Test command fails. * Added hints in error messages for device turned OFF. * Added timeout and error message for wrong communication speed. * Added -c option, to get a GPX file with both tracks and waypoints, thanks to Filippo Giunchedi. * Added -i option, to ignore some error conditions and try to extract as much data as possible from the GPS. Thanks to Markus Brückner and Stefan Höhne. -- Niccolo Rigacci Mon, 19 Jan 2009 18:36:13 +0100 mtkbabel (0.7) * Added support for the Holux M-241 data logger. * Added option -R to recover from a disabled log status. -- Niccolo Rigacci Tue, 17 Jun 2008 16:16:25 +0200 mtkbabel (0.6) * Added a man page, thanks to Uwe Hermann. * Some cosmetic changes. -- Niccolo Rigacci Thu, 07 Feb 2008 22:22:20 +0100 mtkbabel (0.5) * Read all the contents of the flash memory when in OVERLAP mode or when forced with the -a option. * Added flash_memory_size($model_id) function. * Fixed memory used computation. * Improved error handling in log file parsing. * Description of record type (time, distance, speed, button) can now accomodate multiple criteria. * Clean-up of the code. -- Niccolo Rigacci Mon, 10 Dec 2007 16:39:55 +0100 mtkbabel (0.4) * Used the File::Basename library instead of basename(1) Unix command. * Added display of failed sectors, need format and disable status. * Chaged wording: use sector instead of block, to conform with Mediatek documentation. * Fixed a bug occurring when SID is logged, but NSAT is not. * Better output of waypoints, now conform with GPX schema. * Grouped all the serial port related functions, to ease porting. -- Niccolo Rigacci Wed, 28 Nov 2007 22:38:07 +0100 mtkbabel (0.3) * Fixed a bug in encode_log_format() function: disabling a log field now works as expected. * Changed type of $satdata_elevation from unsigned to signed. * Now produces GPX 1.1 files with mtk extensions, as defined in the proposed MtkExtensionsv1.xsd schema. -- Niccolo Rigacci Sun, 25 Nov 2007 21:31:21 +0100 mtkbabel (0.2) * Fixed an error in utm_time() function. * Improved timeout handling in packet_wait(). * Correction in changelog (!). -- Niccolo Rigacci Tue, 20 Nov 2007 14:06:53 +0100 mtkbabel (0.1) * First public release. -- Niccolo Rigacci Wed, 17 Oct 2007 12:37:37 +0200 mtkbabel-0.8.4/mtkbabel.10000644000175000017500000001203013550354140015001 0ustar niccoloniccolo.TH MTKBABEL 1 "October 11, 2019" .SH NAME mtkbabel \- Tool for managing GPS data loggers based on the MTK chip .SH SYNOPSIS .B mtkbabel \fR[\fB\-abcdEfhiIlmopRrstvwx\fR] .SH DESCRIPTION .B mtkbabel is a command line program to operate GPS data loggers based on the MediaTek MTK chip. It was tested on the i-Blue 747, Qstarz BT-Q1000 and on the Holux M-241, it should work also with other GPS devices based on the same chip. .sp The main features are: - Command line interface - Save data log in GPX and raw binary format - If required retrieve all the data, also the old one being overlapped - Change logging criteria: time, distance, speed - Change log format - START/STOP logging - Set OVERLAP or STOP method on memory full - Erase the internal memory .SH USAGE In order to use mtkbabel, please follow these instructions: .sp 1. Attach the GPS data logger device to your computer .BR "via USB" . .sp 2. Now you have to switch the GPS device (at least the i-Blue 747) into .BR "LOG or NAV mode" , otherwise the device will not be powered on, and no connection will be possible. Beware that in NAV mode the device goes into sleep mode if not connected to any Bluetooth device. .sp 3. In order to use mtkbabel you have to either be root (not recommended) and/or you must have read/write permissions for the USB device file, usually .BR /dev/ttyUSB0 . This device usually has permissions .BR "'crw-rw---- 1 root dialout'" , so you can either add your user to the .B dialout group (in this example) by doing .sp .B " $ adduser USERNAME dialout" .sp or (not recommended) make the device world-readable/-writable by doing: .sp .B " $ chmod 666 /dev/ttyUSB0" .sp Another option is to write a udev rules file to change the owner and permissions of /dev/ttyUSB0 according to your requirements. .sp 4. You can now run mtkbabel. For example, if you want to download the track log and the list of waypoints you captured on the device, run: .sp .B " $ mtkbabel -s 115200 -l off -f foo -w -t" .sp The default speed of .B 115200 baud should work in most cases and you can omit it, for the Holux M-241 you must use .B 38400 instead. This will turn off the autolog function, which is always turned on when you switch on the device. The track log will be in the file .BR foo_trk.gpx , the waypoints in the file .B foo_wpt.gpx (both in GPX format). The file .B foo.bin will contain the binary log file. Downloading the data from the GPS device can take several minutes, depending on how much data has to be transferred. .sp In order to delete all data from the GPS device, run: .sp .B " $ mtkbabel -s 115200 -E" .SH OPTIONS .TP .B "\-a" Read all the log memory (overlapped data). .TP .BR "\-b" " filename.bin" Do not read data from a GPS device, but rather read a previously saved .bin file. Ignore \-f option. .TP .B "\-c" Create a GPX file with both tracks and waypoints. .TP .BR "\-d" " debug_level" Debug level: 0..7. .TP .B "\-E" Erase data log memory. .TP .B "\-f" Base name for saved files (.bin and .gpx). If you, for example, use .BR "-f gpslog" , mtkbabel will create files which are called .BR gpslog.gpx , .BR gpslog_trk.gpx , .BR gpslog_wpt.gpx " and" .BR gpslog.bin . .TP .B "\-h" Show a help text and exit. .TP .B "\-i" Ignore some error conditions and try to extract as much data as possible from GPS. .TP .B "\-I" Same as -i, but also write bad records into the GPX file. .TP .BR "\-l" " {on|off}" Turn logging ON/OFF. .TP .BR "\-m" " {stop|overlap}" Set STOP/OVERLAP recording method on memory full. .TP .BR "\-o" " log_format" Enable or disable log fields (FIELD1,\-FIELD2,...), available fields: UTC, VALID, LATITUDE, LONGITUDE, HEIGHT, SPEED, HEADING, DSTA, DAGE, PDOP, HDOP, VDOP, NSAT, SID, ELEVATION, AZIMUTH, SNR, RCR, MILLISECOND, DISTANCE. .TP .BR "\-p" " port" Communication port, default: .BR /dev/ttyUSB0 "." .TP .B "\-R" Recover from disabled log: erase data and reset recording criteria. .TP .BR "\-r" " time:distance:speed" Set logging criteria (zero to disable): every 0.10-9999999.90 seconds, every 0.10-9999999.90 meters, over 0.10-9999999.90 km/h. Not all the devices support such wide ranges, more reasonable values are 1-999 seconds, 10-9999 meters and 10-999 km/h. .TP .BR "\-s" " speed" Serial port speed, default .BR 115200 " baud." .TP .B "\-t" Create a GPX file with tracks. .TP .B "\-v" Show version information and exit. .TP .B "\-w" Create a GPX file with waypoints. .TP .B "\-W" " weeks" Add the specified weeks count to timestamps, to fix the Weeks Rollover Bug. Try -W 1024 or multiples, or use -W -1 to guess the rollover count from current time. .TP .B "\-x" Force reading Holux format. This is required to read-back the binary data produced by some Holux devices, which do not embed into the data itself the Holux identifier string. .SH BUGS Please report any bugs to Niccolo Rigacci . .SH LICENCE .B mtkbabel is covered by the GNU General Public License (GPL), version 2 or later. .SH AUTHORS Niccolo Rigacci .PP This manual page was written by Uwe Hermann . It is licensed under the terms of the GNU GPL (version 2 or later). mtkbabel-0.8.4/MtkExtensionsv1.xsd0000644000175000017500000001045513550354140016751 0ustar niccoloniccolo This schema defines an extension to be used with the GPX 1.1 schema; it accomodates extra fields logged by GPS devices based un the MediaTek (MTK) chip. The root elements defined by this schema are intended to be used as child elements of the "extensions" elements in the GPX 1.1 schema. The GPX 1.1 schema is available at http://www.topografix.com/GPX/1/1/gpx.xsd. This type contains data fields available in MTK waypoints that cannot be represented in waypoints instances of GPX 1.1 schema. Type of GPS fix. nofix = the GPS device had no fix. sps = Standard Positioning Service; before May 2000 it was affected by Selective Availability degradation. dgps = Differential GPS; fix aided by ground-based station corrections. pps = Precise Positioning Service; accuracy not affected by Selective Availability, provided encrypted. rtk = Real Time Kinematic with fixed integers. frtk = Real Time Kinematic with floating integers. estimated = Estimated mode (dead reckoning). manual = fix was entered manually. simulator = the GPS device is operating in simulation mode, it had no real GPS fix. Satellite information. If satellite information is logged, "sid" (Station ID) and "inuse" (if the station was used to compute the fix) are always logged. elevation = elevation above the horizon of the satellite, in degrees. azimuth = the angle between true north and the satellite, in degrees. snr = signal to noise ratio.