Fitsed - Stream editor for Garmin .FIT files
fitsed -show_version=1 fitsed [-parser_dump_indent=<number>] -parser_dump=1 <expression> fitsed <expression> [<input_file1> [<input_file2> ...] [<output file>]]
Fitsed reads the contents of Garmin .FIT files, assigns specified values to specified fields of specified data messages, and outputs them with appropriate .FIT header and trailing CRC-16.
The latest version is obtained viafitsed-0.09.tar.gz (8KB, 2017-06-18 14:36:07).
It uses a Perl class
Garmin::FIT
of version 0.27 or later.
Each time when a data message is read, <expression> is evaluated. <expression> is <single expression> or <compound expression>. All syntactical keywords and operators in explanations below are case-insensitive.
A single expression must be one of the following forms.
+
-
<place spec> must be one of the following forms.
.
<field spec>_n
.
<name>_s
.
<name>_n.
<name> and _s.
<name> represent global variables named <name>.
The value of _n.
<name> is treated as a number,
and the value of _s.
<name> is treated as a string.
<message spec>.
, _n.
, or _s.
can be omitted.
In that case,
the last refered one is assumed.
<assignment or comparison> must be one of =
, :lt:
, :le:
, :eq:
, :ge:
, :gt:
, or ::
.
=
An array value is expressed as a comma separated list of members enclosed with open and closing braces.
:lt:
:le:
:eq:
:ge:
:gt:
::
The evaluation engine has two data stack. One is for numeric values, and the other is for string values.
+
pushs the value of <place spec> to one of the stacks.
-
pops a value from one of the stacks,
and assigns the value to <place spec>.
Which of stacks is selected is determined by data type of <place spec>.
Both operations are evaluated to a true value.
<a Perl expression> is evaluated to a true value if and only if it is a true value as a Perl expression.
A compound expression must be one of the following form.
!
<expression>not
<expression>(
<sequence of expressions> )
[
<sequence of expressions> ]
<
<sequence of expressions> >
{
<sequence of expressions> }
b
<sequence of expressions> e
beg
<sequence of expressions> end
begin
<sequence of expressions> end
beginning
<sequence of expressions> end
start
<sequence of expressions> end
do
<sequence of expressions> done
<and sequence> is simply a sequence of any number of <expression>'s. They are evaluated in order. Evaluation stops when an <expression> evaluates to a false value, and the false value becomes the value of the whole sequence.
If all <expression>'s evaluate to true values, this <and sequence> evaluates to a true value.
or
<sequence of expressions>.
First the left <and sequence> is evaluated. If the evaluation generates a true value, the value becomes the value of this <or sequence>. In this case the right <sequence of expression> is not evaluated.
If the evaluation generates a false value, the right <sequence of expression> is evaluated, and the result becomes the value of this <or sequence>.
The following variables have special meaning.
_n._stop
_n._skip
_n._global_message_type
_s._global_message_type
_n._local_message_type
All other global variables with names starting with _
(underscore) are reserved for special purpose.
If you want to modify a .FIT file (say originalfile.fit), you can first look at the contents of the file with
fitdump
of version 0.3 or later. It shows messages with message numbers and fields with field indices defined in a global .FIT profile.
fitsed
likefitsed
<M>.
<I>=<new value> originalfile.fit newfile.fit
where modified contens are saved to newfile.fit.
Assuming Edge 500 is mounted on the folder /mnt/Edge500, it has a file Settings.fit in the folder /mnt/Edge500/Garmin/Settings.
friendly_name
of the message user_profile
in Settings.fit to suto
,
and to save the result to /tmp/new_settings.fit:fitsed
user_profile.friendly_name=suto
/mnt/Edge500/Garmin/Settings/Settings.fit /tmp/new_settings.fit
weight
of the same message to 54kg simultaneously:fitsed
B
user_profile.friendly_name=suto
weight=54kg
E
/mnt/Edge500/Garmin/Settings/Settings.fit /tmp/new_settings.fit
The file Settings.fit has 3 messages with message number 6. They seem to be bike profiles. The field with index 254 in a global .FIT profile of a message of this type, seems to be an identification number of the message in the file, and the field with index 10 seems to be a bike weight.
fitsed
B
6.254:eq:0
6.10=7.5kg
OR
user_profile.friendly_name=suto
weight=54kg
E
/mnt/Edge500/Garmin/Settings/Settings.fit /tmp/new_settings.fit
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.
force_proto_ver1
When developer data or 64bit numbers are not used but major part of protocol version is 2, protocol version is set to 1.00 if this option is set to true.
Thanks to analysis by Stefan Heinen.
cat_cb()
drop_developer_data
Description about notation of an array literal is added to this document. Thanks to report from Leandro Lind.
cat_cb()
$self
which should be $obj
.
Thanks to report and fix of this issue by Marcus.
cat_cb()
pack_data_message
of Garmin::FIT
.
with_endian
cat()
cat_header()
.
cat_cb()