Garmin::FIT - A Perl class to decode Garmin .FIT files
use Garmin::FIT; Garmin::FIT->version_string; $fit = new Garmin::FIT; $fit->unit_table(<unit> => <unit conversion table>); $fit->semicircles_to_degree(<boolean>); $fit->mps_to_kph(<boolean>); $fit->use_gmtime(<boolean>); $fit->file(<file name>) $fit->open; $fit->fetch_header; $fit->fetch; $fit->protocol_version_string; $fit->protocol_version_string(<version number>); $fit->profile_version_string; $fit->profile_version_string(<version number>); $fit->data_message_callback_by_name(<message name>, <callback function>[, <callback data>, ...]); $fit->data_message_callback_by_num(<message number>, <callback function>[, <callback data>, ...]); $fit->switched(<data message descriptor>, <array of values>, <data type table>); $fit->string_value(<array of values>, <offset in the array>, <counts>); $fit->value_cooked(<type name>, <field attributes table>, <invalid data>, <value>); $fit->error; $fit->crc_expected; $fit->crc; $fit->trailing_garbages; $fit->close; ...
Garmin::FIT is a Perl class to provide interfaces to decode Garmin .FIT files.
The latest version is obtained viaGarminFIT-0.28.tar.gz (41KB, 2017-08-22 19:08:19).
There are three applications
fitdump,
fitsed,
and
fit2tcx
using this class.
Following constants are automatically exported.
unit_table() method.
date_time type value conversion.
1 on success, or undef on failure or EOF.
When fetch method meets a definition message,
it creates a hash which includes various information about the corresponding data message.
We call the hash a data message descriptor.
It includes the following key value pairs.
local_message_type => <local message type>message_number => <message number>message_name => <message name>callback => <reference to an array>callback is registered.
endian => <endian>template => <template for unpack>i_<field name> => <offset in data array>value(s) of the field named <field name>.
o_<field_name> => <offset in binary data>value(s) of the field named <field name>.
c_<field_name> => <the number of values>s_<field_name> => <size in octets>a_<field name> => <reference to a hash>t_<field name> => <type name>T_<field name> => <a number>N_<field name> => <a number>I_<field name> => <a number>endian_converter => <reference to an array>message_length => <length of binary data>array_length => <length of data array>
fetch method meets a data message,
it calls a <callback function> registered with data_message_callback_by_name or data_message_callback_by_num,
in the formThe return value of the function becomes the return value of fetch.
It is expected to be 1 on success, or undef on failure status.
Fields in devloper data are given names of the form <developer data index>_<field definition number>_<converted field name>,
and related informations are included <data message descriptors> in the same way as the fields defined in the global .FIT profile.
Each <converted field name> is made from the value of field_name field in the corresponding field description message,
after the following conversion rules:
_._ + 2 column hex representation of ord() of the character + _.
If your perl lacks 64bit integer support,
you need the module Math::BigInt.
Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
This program is distributed with ABSOLUTELY NO WARRANTY.
Anyone can use, modify, and re-distibute this program without any restriction if version <= 0.20.
The version 0.21 and newers are based on
Matjaz Rihtar's git repository
version. So, regardless of the above disclaimer, uses, modifications, and re-distributions of this version are restricted by the contents of the file LICENSE_LGPL_v2.1.txt in the git repository.
The author is very grateful to Garmin for supplying us free software programers with .FIT SDK which includes detailed documetation about its proprietary file format.
syscallback_devdata_id()application_id field is not mandatory.
Thanks to the analysis by Matjaz Rihtar.
syscallback_devdata_field_desc()field_name field is not mandatory.
Thanks to the analysis by Matjaz Rihtar.
cat_definition_message()pack_data_message()drop_developer_data().
drop_developer_data()initialize()drop_developer_data.
$typename --> $typenam and $typdesc --> $typedesc).
fetch_definition_message()There is a developer who assigns the same field name to different fields. Such fields could not be distinguished with the old naming way.
reset()maybe_chained()end_of_chunk()fetch()maybe_chained() and end_of_chunk() to support chained FIT files.
fixes of the issues:
Problems with big endian.
$defmsg_min_templateendian_converterendian_convert()
support for developer data and 64bit integers introduced in FIT 2.0.
64bit integers support is not tested at all.
This version is based on
Matjaz Rihtar's git repository
version. So, regardless of the above disclaimer, uses, modifications, and re-distributions of this version are restricted by the contents of the file LICENSE_LGPL_v2.1.txt in the git repository.
fetch_header()fetch()
protocol_versionprotocol_version_header_crc_startedcat_definition_message()
profile_version%named_type%msgtype_by_namefetch_data_message()
safe_isa()isa method from UNIVERSAL class.
Thanks to Blaine Schmidt who kindly informed that such importation is deprecated.
xxx45_ftp
profile_version%named_type%msgtype_by_name
profile_version%named_type%msgtype_by_name
profile_versionprofile_version_from_string()profile_version_scale instead of profile_version_major_shift.
fetch_header()cat_header()msgtype_by_name->{session}->{35}scale attribute was missing.
msgtype_by_name->{session}->{36}
protocol_versionprofile_versionfetch_header()%named_type%msgtype_by_name%msgtype_by_num
profile_versionerror()fetch_header()
initialize()buffer of an object must be initialzied with a reference to a scalar,
not the scalar itself.
Thanks to report from Nils Knieling.
$version$version_major_scale@version$my_endian$protocol_version_major_shift$protocol_version_minor_mask$protocol_version@protocol_version$profile_version_major_shift$profile_version_minor_mask$profile_version@profile_version@crc_table$header_template$header_length$FIT_signature_string$FIT_signature$rechd_offset_compressed_timestamp_header$rechd_mask_compressed_timestamp_header$rechd_offset_cth_local_message_type$rechd_length_cth_local_message_type$rechd_mask_cth_local_message_type$rechd_length_cth_timestamp$rechd_mask_cth_timestamp$rechd_offset_definition_message$rechd_mask_definition_message$rechd_length_local_message_type$rechd_mask_local_message_type$cthd_offset_local_message_type$cthd_length_local_message_type$cthd_mask_local_message_type$cthd_length_time_offset$cthd_mask_time_offset$defmsg_min_template$defmsg_min_length$deffld_template$deffld_length$deffld_mask_endian_p$deffld_mask_type@invalid@size@template%named_type$use_gmtime%msgtype_by_name$mesg_name_vs_num%msgtype_by_num$msgnum_anon$msgname_anon@type_namefetch_header()
use_gmtime()msgtype_by_name->{file_id}->{2}type_name with value garmin_product.
msgtype_by_name->{device_info}->{4}msgtype_by_name->{schedule}->{1}msgtype_by_name->{event}->{data16}->{2}->{switch}->{course_point}when --> name.
msgtype_by_name->{event}->{data}->{2}->{switch}->{course_point}data_message_callback_by_num()@_.
data_message_callback_by_name()open()$FH binary mode.
Thanks to reports and tests on Windows platform by Nils Knieling.
@EXPORTFIT_FLOAT16 --> FIT_FLOAT64).
my_endian()crc_initialize()error()crc_of_string()crc_calc()crc_of_string().
fill_buffer()cat_header()named_type->{mesg_num}undocumented_message_6 and undocumented_message_22 are removed.
date_string()named_type_value()support reverse-conversion of 'date_time' type.
msgtype_by_nameundocumented_message_6 and undocumented_message_22 are removed.
msgtype_by_nummessage_name()message_number()field_name()field_number()undocumented_field_name()fetch_definition_message()offset() method was wrong.
use undocumented_field_name().
new key-value pairs of the form $index => $name in %desc.
new key-value pair array_length => $i_array in %desc.
cat_definition_message()endian_convert()$buffer and $i).
last_timestampfetch_data_message()switched()value_processed()value_unprocessed()value_cooked()value_uncooked()fetch()type_nameprint_all_fields()change output format.
use single method value_cooked() instead of methods named_type_value() and value_processed().
EOFfill_buffer()clear_buffer method and EOF method.
FIT_HEADER_LENGTH()numeric_date_time()named_type_value()calls numeric_date_time method.
message_type_by_name->{lap}totoal_distnace --> total_distance).
message_type_by_name->{session}data_message_callback_by_name()$msgtype (num --> _number).
unit_table()without_unit()value_processed()$attr is a hash.
calls without_unit method.
initialize()member crc should not be initialized.
print_all_fields()semicircles_to_degree()mps_to_kph()close