Index: applications/editors/josm/plugins/FIT/LICENSE.txt
===================================================================
--- applications/editors/josm/plugins/FIT/LICENSE.txt	(revision 36153)
+++ applications/editors/josm/plugins/FIT/LICENSE.txt	(revision 36153)
@@ -0,0 +1,339 @@
+                    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.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    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.
+
+  <signature of Ty Coon>, 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.
Index: applications/editors/josm/plugins/FIT/README.md
===================================================================
--- applications/editors/josm/plugins/FIT/README.md	(revision 36153)
+++ applications/editors/josm/plugins/FIT/README.md	(revision 36153)
@@ -0,0 +1,19 @@
+README 
+======
+
+The FIT plugin is written for Garmin FIT files.
+
+The `org.openstreetmap.josm.plugins.fit.lib` package does not have any
+dependency on JOSM; you should be able to import that into your code with
+no issues.
+
+## License
+This plugin is licensed under the GPLv2 or later.
+
+## Usage
+The main entry point for the library is `FitReader.read(InputStream inputStream)`.
+You _should not_ use any of the `public` constructors; they may change at any time.
+You also _should not_ use any of the `static <return> parse` methods.
+
+## Authors
+Taylor Smock <taylor.smock@kaart.com>
Index: applications/editors/josm/plugins/FIT/build.xml
===================================================================
--- applications/editors/josm/plugins/FIT/build.xml	(revision 36153)
+++ applications/editors/josm/plugins/FIT/build.xml	(revision 36153)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project name="FIT" default="dist" basedir=".">
+    <property name="plugin.src.dir" value="src/main/java"/>
+    <property name="plugin.test.dir" location="src/test"/>
+    <property name="plugin.resources.dir" value="src/main/resources"/>
+    <!-- enter the SVN commit message -->
+    <property name="commit.message" value="Commit message"/>
+    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
+    <property name="plugin.main.version" value="10580"/>
+
+    <property name="plugin.author" value="Taylor Smock"/>
+    <property name="plugin.class" value="org.openstreetmap.josm.plugins.fit.FitPlugin"/>
+    <property name="plugin.description" value="Garmin FIT files in JOSM"/>
+    <!--<property name="plugin.icon" value="..."/>-->
+    <!--<property name="plugin.link" value="..."/>-->
+    <property name="plugin.minimum.java.version" value="21"/>
+    <property name="java.lang.version" value="21"/>
+    <property name="plugin.canloadatruntime" value="true"/>
+
+    <!-- ** include targets that all plugins have in common ** -->
+    <import file="../build-common.xml"/>
+</project>
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/FitPlugin.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/FitPlugin.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/FitPlugin.java	(revision 36153)
@@ -0,0 +1,85 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Map;
+
+import org.openstreetmap.josm.actions.ExtensionFileFilter;
+import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.gpx.GpxData;
+import org.openstreetmap.josm.data.gpx.GpxTrack;
+import org.openstreetmap.josm.data.gpx.WayPoint;
+import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.io.importexport.FileImporter;
+import org.openstreetmap.josm.gui.layer.GpxLayer;
+import org.openstreetmap.josm.gui.progress.ProgressMonitor;
+import org.openstreetmap.josm.plugins.Plugin;
+import org.openstreetmap.josm.plugins.PluginInformation;
+import org.openstreetmap.josm.plugins.fit.lib.FitReader;
+import org.openstreetmap.josm.plugins.fit.lib.FitReaderOptions;
+import org.openstreetmap.josm.plugins.fit.lib.global.HeartRateCadenceDistanceSpeed;
+
+/**
+ * The POJO entry point for JOSM
+ */
+public class FitPlugin extends Plugin {
+    /**
+     * Creates the plugin
+     *
+     * @param info the plugin information describing the plugin.
+     */
+    public FitPlugin(PluginInformation info) {
+        super(info);
+        ExtensionFileFilter.addImporter(new FitImporter());
+    }
+
+    private static final class FitImporter extends FileImporter {
+
+        /**
+         * Constructs a new {@code FitImporter} with the given extension file filter.
+         */
+        public FitImporter() {
+            super(new ExtensionFileFilter("fit", "fit", tr("FIT Files (*.fit)")));
+        }
+
+        @Override
+        public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
+            try (InputStream inputStream = Files.newInputStream(file.toPath())) {
+                final var records = FitReader.read(inputStream, FitReaderOptions.TRY_TO_FINISH);
+                final var gpxData = new GpxData(true);
+                progressMonitor.beginTask(tr("Processing FIT records"), records.length);
+                final var waypoints = new ArrayList<WayPoint>(records.length % 1000);
+                for (int i = 0; i < records.length; i++) {
+                    var r = records[i];
+                    if (i % 1000 == 0) {
+                        progressMonitor.worked(1);
+                    }
+                    if (r instanceof HeartRateCadenceDistanceSpeed(
+                            Instant timestamp, double lat, double lon, double ele, short heartRate, short cadence,
+                            int distance, int speed, long[][] unknown,
+                            org.openstreetmap.josm.plugins.fit.lib.global.FitDevDataRecord devData
+                    )) {
+                        final var waypoint = new WayPoint(new LatLon(lat, lon));
+                        waypoint.setInstant(timestamp);
+                        waypoint.attr.putAll(Map.of("ele", ele, "heart_rate", heartRate,
+                                "cadence", cadence, "distance", distance, "speed", speed,
+                                "unknown", unknown, "devData", devData));
+                        waypoints.add(waypoint);
+                    }
+                }
+                waypoints.trimToSize();
+                gpxData.addTrack(new GpxTrack(Collections.singleton(waypoints), Collections.emptyMap()));
+                gpxData.endUpdate();
+                MainApplication.getLayerManager().addLayer(new GpxLayer(gpxData, file.getName(), true));
+            }
+        }
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitBaseType.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitBaseType.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitBaseType.java	(revision 36153)
@@ -0,0 +1,90 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib;
+
+/**
+ * The base fit types in order
+ */
+public enum FitBaseType {
+    // enum types
+    enum_(false, 0x00, 1, 0xFF),
+    // signed int (8 bit)
+    sint8(false, 0x01, 1, 0x7F),
+    // unsigned int (8 bit)
+    uint8(false, 0x02, 1, 0xFF),
+    // signed int (16 bit)
+    sint16(true, 0x83, 2, 0x7FFF),
+    // unsigned int (16 bit)
+    uint16(true, 0x84, 2, 0xFFFF),
+    // signed int (32 bit)
+    sint32(true, 0x85, 4, 0x7FFFFFFF),
+    // unsigned int (32 bit)
+    uint32(true, 0x86, 4, 0xFFFFFFFFL),
+    // string (delimited by nul byte)
+    string(false, 0x07, 1, 0x00),
+    // float
+    float32(true, 0x88, 4, 0xFFFFFFFFL),
+    // double
+    float64(true, 0x89, 8, 0xF_FFF_FFF_FFF_FFF_FFFL),
+    // unsigned int (8 bit)
+    uint8z(false, 0x0A, 1, 0x00),
+    // unsigned int (16 bit)
+    uint16z(true, 0x8B, 2, 0x0000),
+    // unsigned int (32 bit)
+    uint32z(true, 0x8C, 4, 0x00000000),
+    // byte array -- I believe the size is the number of bytes in the array
+    byte_(false, 0x0D, 1, 0xFF),
+    // signed int (64 bit)
+    sint64(true, 0x8E, 8, 0x7_FFF_FFF_FFF_FFF_FFFL),
+    // unsigned int (64 bit)
+    uint64(true, 0x8F, 8, 0xF_FFF_FFF_FFF_FFF_FFFL),
+    // unsigned int (64 bit)
+    uint64z(true, 0x90, 8, 0x0_000_000_000_000_000),
+    // Unknown type
+    UNKNOWN(false, 0xFF, 0, 0);
+
+    private static final FitBaseType[] values = values();
+    private final boolean endianAbility;
+    private final short baseTypeField;
+    private final byte size;
+    private final long invalidValue;
+
+    FitBaseType(boolean endianAbility, int baseTypeField, int size, long invalidValue) {
+        this.size = (byte) size;
+        this.invalidValue = invalidValue;
+        this.endianAbility = endianAbility;
+        this.baseTypeField = (short) baseTypeField;
+    }
+
+    /**
+     * A cached copy of {@link #values()} for memory allocation reasons. Do not modify!
+     *
+     * @return The cached {@link #values()}.
+     */
+    public static FitBaseType fromBaseTypeField(int baseTypeField) {
+        for (FitBaseType type : values) {
+            if (type.baseTypeField == baseTypeField) {
+                return type;
+            }
+        }
+        return UNKNOWN;
+    }
+
+    /**
+     * The expected size of the type. Some, notable {@link #string} and {@link #byte_} may not follow this. Specifically,
+     * {@link #string} is terminated by a null byte.
+     *
+     * @return The expected size of the type
+     */
+    byte size() {
+        return this.size;
+    }
+
+    /**
+     * The invalid value for the type
+     *
+     * @return The invalid value
+     */
+    public long invalidValue() {
+        return invalidValue;
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitException.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitException.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitException.java	(revision 36153)
@@ -0,0 +1,45 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib;
+
+import java.io.IOException;
+
+/**
+ * An exception caused during parsing a fit file
+ */
+public class FitException extends IOException {
+    /**
+     * Constructs an {@code FitException} with {@code null}
+     * as its error detail message.
+     */
+    FitException() {
+        super();
+    }
+
+    /**
+     * Create a new {@link FitException} with a specified message
+     *
+     * @param message The message to use for the exception
+     */
+    FitException(String message) {
+        super(message);
+    }
+
+    /**
+     * Create a new {@link FitException} with a specified message and cause
+     *
+     * @param message The message to use for the exception
+     * @param cause   The cause of the exception
+     */
+    FitException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    /**
+     * Create a new {@link FitException} with specified cause
+     *
+     * @param cause The cause of the exception
+     */
+    FitException(Throwable cause) {
+        super(cause);
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitReader.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitReader.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitReader.java	(revision 36153)
@@ -0,0 +1,262 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.openstreetmap.josm.plugins.fit.lib.global.FitData;
+import org.openstreetmap.josm.plugins.fit.lib.global.Global;
+import org.openstreetmap.josm.plugins.fit.lib.global.IFitTimestamp;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDefinitionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperFieldDescriptionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitHeader;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitRecordCompressedTimestampHeader;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitRecordHeader;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitRecordNormalHeader;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.IField;
+import org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils;
+
+/**
+ * Read a fit file
+ */
+public final class FitReader {
+    private static final FitData[] EMPTY_FIT_DATA_ARRAY = new FitData[0];
+
+    private FitReader() {
+        // Hide constructor
+    }
+
+    /**
+     * Read a fit file from an {@link InputStream}
+     *
+     * @param inputStream The stream to read
+     * @param options options for reading the file
+     * @throws FitException if there was an error reading the fit file <i>or</i> there was an {@link InputStream} read
+     *                      exception.
+     */
+    public static FitData[] read(InputStream inputStream, FitReaderOptions... options) throws FitException {
+        final var bufferedInputStream = inputStream.markSupported() ? inputStream
+                : new BufferedInputStream(inputStream);
+        final var optionsSet = options.length == 0 ? EnumSet.noneOf(FitReaderOptions.class)
+                : EnumSet.of(options[0], options);
+        final var fitData = new ArrayList<FitData>();
+        try {
+            final var header = readFitHeader(bufferedInputStream);
+            bufferedInputStream.mark(1);
+            var localMessageHeaders = new FitDefinitionMessage[1];
+            var developerData = new FitDeveloperFieldDescriptionMessage[0];
+            long lastTimeStamp = Long.MIN_VALUE;
+            var offsetAddition = 0;
+            byte lastOffset = 0;
+            while (bufferedInputStream.read() != -1) {
+                bufferedInputStream.reset();
+                final var nextRecordHeader = readNextRecordHeader(bufferedInputStream);
+                if (nextRecordHeader instanceof FitRecordNormalHeader normalHeader) {
+                    if (normalHeader.isDefinitionMessage()) {
+                        final var fitDefinitionMessage = readNextDefinition(normalHeader, bufferedInputStream);
+                        if (localMessageHeaders.length <= normalHeader.localMessageType()) {
+                            localMessageHeaders = Arrays.copyOf(localMessageHeaders,
+                                    normalHeader.localMessageType() + 1);
+                        }
+                        localMessageHeaders[normalHeader.localMessageType()] = fitDefinitionMessage;
+                    } else {
+                        final Object obj = readNextRecord(localMessageHeaders[normalHeader.localMessageType()],
+                                developerData, bufferedInputStream);
+                        if (obj instanceof IFitTimestamp<?> timestamp) {
+                            lastTimeStamp = timestamp.timestamp().getEpochSecond() & 0xFF_FFF_FE0L;
+                            offsetAddition = 0;
+                            lastOffset = 0;
+                        }
+                        if (obj instanceof FitData fd) {
+                            fitData.add(fd);
+                        } else if (obj instanceof FitDeveloperFieldDescriptionMessage developerFieldDescriptionMessage) {
+                            if (developerData.length <= developerFieldDescriptionMessage.developerDataIndex()) {
+                                developerData = Arrays.copyOf(developerData,
+                                        developerFieldDescriptionMessage.developerDataIndex() + 1);
+                            }
+                            developerData[developerFieldDescriptionMessage
+                                    .developerDataIndex()] = developerFieldDescriptionMessage;
+                        } else {
+                            handleException(optionsSet, new IllegalStateException("Unknown record type"));
+                        }
+                    }
+                } else if (nextRecordHeader instanceof FitRecordCompressedTimestampHeader compressedHeader) {
+                    if (lastTimeStamp == Long.MIN_VALUE) {
+                        handleException(optionsSet,
+                                new FitException("No full timestamp found before compressed timestamp header"));
+                        break;
+                    }
+                    if (compressedHeader.timeOffset() < lastOffset) {
+                        offsetAddition++;
+                    }
+                    final Object obj = readNextRecord(localMessageHeaders[compressedHeader.localMessageType()],
+                            developerData, bufferedInputStream);
+                    if (obj instanceof FitData fd) {
+                        // Note: this could be wrong
+                        long actualTimestamp = lastTimeStamp + compressedHeader.timeOffset() + (offsetAddition * 0x20L);
+                        if (fd instanceof IFitTimestamp<?> timestamp) {
+                            fitData.add((FitData) timestamp.withTimestamp(Instant.ofEpochSecond(actualTimestamp)));
+                        } else {
+                            fitData.add(fd);
+                        }
+                    } else {
+                        handleException(optionsSet, new IllegalStateException(
+                                "Cannot handle non-data types with compressed timestamp headers"));
+                    }
+                    lastOffset = compressedHeader.timeOffset();
+                } else {
+                    handleException(optionsSet,
+                            new UnsupportedOperationException("Unknown record type: " + nextRecordHeader.getClass()));
+                }
+                bufferedInputStream.mark(1);
+            }
+        } catch (FitException fitException) {
+            handleException(optionsSet, fitException);
+        } catch (IOException ioException) {
+            handleException(optionsSet, new FitException(ioException));
+        }
+        return fitData.toArray(EMPTY_FIT_DATA_ARRAY);
+    }
+
+    private static <T extends Throwable> void handleException(EnumSet<FitReaderOptions> options, T throwable) throws T {
+        if (!options.contains(FitReaderOptions.TRY_TO_FINISH)) {
+            throw throwable;
+        }
+        Logger.getLogger(FitReader.class.getCanonicalName()).log(Level.WARNING, throwable.getMessage(), throwable);
+    }
+
+    /**
+     * Read the FIT file header; this should only ever be called once.
+     *
+     * @param inputStream The stream to read
+     * @return The header
+     * @throws IOException If something happened while reading the fit file (see {@link InputStream#read()} for some causes)
+     */
+    static FitHeader readFitHeader(InputStream inputStream) throws IOException {
+        final int size = inputStream.read();
+        if (size < 12) {
+            throw new FitException("FIT header is not the expected size.");
+        }
+        final int protocolVersion = inputStream.read();
+        final int profileVersion = inputStream.read() + (inputStream.read() << 8);
+        final long dataSize = inputStream.read() + (inputStream.read() << 8) + (inputStream.read() << 16)
+                + ((long) inputStream.read() << 24);
+        final var fit = new byte[4];
+        int read = inputStream.read(fit);
+        if (read != fit.length || fit[0] != '.' || fit[1] != 'F' || fit[2] != 'I' || fit[3] != 'T') {
+            throw new FitException("FIT header has the wrong data type: " + new String(fit, StandardCharsets.US_ASCII));
+        }
+        final int crc;
+        if (size >= 14) {
+            crc = inputStream.read() + (inputStream.read() << 8);
+        } else {
+            crc = 0;
+        }
+        return new FitHeader((short) protocolVersion, profileVersion, dataSize, crc);
+    }
+
+    /**
+     * Read the header for the next record
+     *
+     * @param inputStream The stream to parse
+     * @return The header for the next record
+     * @throws IOException See {@link InputStream#read()}
+     */
+    static FitRecordHeader readNextRecordHeader(InputStream inputStream) throws IOException {
+        final int header = inputStream.read();
+        if ((header & 0x80) == 0) {
+            return new FitRecordNormalHeader((header & 0x40) != 0, (header & 0x20) != 0, (header & 0x10) != 0,
+                    (byte) (header & 0xF));
+        }
+        return new FitRecordCompressedTimestampHeader((byte) ((header & 0x60) >> 6), (byte) (header & 0x1F));
+    }
+
+    /**
+     * Read the next definition message
+     *
+     * @param normalHeader The header for the message
+     * @param inputStream  The stream to read
+     * @return The definition message
+     * @throws IOException see {@link InputStream#read()}
+     */
+    static FitDefinitionMessage readNextDefinition(FitRecordNormalHeader normalHeader, InputStream inputStream)
+            throws IOException {
+        // first byte is reserved; skip it.
+        final int reserved = inputStream.read();
+        final boolean littleEndian = inputStream.read() == 0; // 0 = little endian, 1 == big endian
+        final var globalMessageNumber = NumberUtils.decodeInt(2, littleEndian, inputStream);
+        final int numberOfFields = inputStream.read();
+        final var fitFields = new ArrayList<FitField>(numberOfFields);
+        for (var i = 0; i < numberOfFields; i++) {
+            fitFields.add(readNextField(inputStream));
+        }
+        // Read developer fields
+        final List<FitDeveloperField> fitDeveloperFields;
+        if (normalHeader.messageTypeSpecific()) {
+            final int numberOfDeveloperFields = inputStream.read();
+            fitDeveloperFields = new ArrayList<>(numberOfDeveloperFields);
+            for (var i = 0; i < numberOfDeveloperFields; i++) {
+                fitDeveloperFields.add(readNextDeveloperField(inputStream));
+            }
+        } else {
+            fitDeveloperFields = Collections.emptyList();
+        }
+        return new FitDefinitionMessage((short) reserved, littleEndian, globalMessageNumber,
+                Collections.unmodifiableList(fitFields), Collections.unmodifiableList(fitDeveloperFields));
+    }
+
+    /**
+     * Read the next field definition
+     *
+     * @param inputStream The stream to read
+     * @return The next field
+     * @throws IOException see {@link InputStream#read()} for most reasons; may also occur if the fit file is corrupted.
+     */
+    static FitField readNextField(InputStream inputStream) throws IOException {
+        return readNextField(FitField.class, inputStream);
+    }
+
+    /**
+     * Read the next developer field definition
+     *
+     * @param inputStream The stream to read
+     * @return The next developer field
+     * @throws IOException see {@link InputStream#read()} for most reasons; may also occur if the fit file is corrupted.
+     */
+    static FitDeveloperField readNextDeveloperField(InputStream inputStream) throws IOException {
+        return readNextField(FitDeveloperField.class, inputStream);
+    }
+
+    private static <T extends IField> T readNextField(Class<T> clazz, InputStream inputStream) throws IOException {
+        final int fieldNumber = inputStream.read();
+        final int size = inputStream.read();
+        final int baseType = inputStream.read();
+        if (fieldNumber == -1 || size == -1 || baseType == -1) {
+            throw new FitException("Reached end of FIT file unexpectedly");
+        }
+        if (clazz == FitDeveloperField.class) {
+            return clazz.cast(new FitDeveloperField((short) fieldNumber, (short) size, (short) baseType));
+        } else if (clazz == FitField.class) {
+            return clazz.cast(new FitField(fieldNumber, size, baseType));
+        } else {
+            throw new IllegalArgumentException("Unknown type: " + clazz);
+        }
+    }
+
+    static Object readNextRecord(FitDefinitionMessage definitionMessage,
+            FitDeveloperFieldDescriptionMessage[] developerFields, InputStream inputStream) throws IOException {
+        return Global.parseData(definitionMessage, developerFields, inputStream);
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitReaderOptions.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitReaderOptions.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/FitReaderOptions.java	(revision 36153)
@@ -0,0 +1,10 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib;
+
+/**
+ * Options for the reader
+ */
+public enum FitReaderOptions {
+    /** Return data even if there was a problem parsing the file */
+    TRY_TO_FINISH
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitData.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitData.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitData.java	(revision 36153)
@@ -0,0 +1,13 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+/**
+ * A generic data interface, mostly to make it easier for users to exhaustively use switch statements.
+ */
+public sealed
+interface FitData
+permits FitDeveloperDataIdMessage, FitDevice, FitUnknownRecord, HeartRateCadenceDistanceSpeed
+{
+
+    FitDevDataRecord devData();
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDevDataRecord.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDevDataRecord.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDevDataRecord.java	(revision 36153)
@@ -0,0 +1,26 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+import org.openstreetmap.josm.plugins.fit.lib.records.IFitDevData;
+
+public record FitDevDataRecord(IFitDevData<?>... fitDevData) {
+    @Override
+    public boolean equals(Object obj) {
+        return obj instanceof FitDevDataRecord r && Arrays.equals(this.fitDevData, r.fitDevData);
+    }
+
+    @Override
+    public int hashCode() {
+        return Arrays.hashCode(fitDevData);
+    }
+
+    @Override
+    public String toString() {
+        return this.getClass().getSimpleName() + '[' +
+                Arrays.stream(this.fitDevData).map(Object::toString).collect(Collectors.joining(", "))
+                + ']';
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDeveloperDataIdMessage.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDeveloperDataIdMessage.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDeveloperDataIdMessage.java	(revision 36153)
@@ -0,0 +1,42 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.util.List;
+
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperFieldDescriptionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitField;
+import org.openstreetmap.josm.plugins.fit.lib.utils.DevDataUtils;
+import org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils;
+
+/**
+ * Used to uniquely identify developer data field sources; there can be at most 255 in a FIT file.
+ *
+ * @param applicationId      The 16-byte identifier for the developer
+ * @param developerDataIndex The developer data index for this message
+ * @param devData            Additional dev data fields (unlikely for this class)
+ */
+public record FitDeveloperDataIdMessage(BigInteger applicationId, short developerDataIndex,
+                                        FitDevDataRecord devData) implements FitData {
+
+    public static FitDeveloperDataIdMessage parse(boolean littleEndian, List<FitField> fieldList,
+                                                  List<FitDeveloperField> developerFieldList, FitDeveloperFieldDescriptionMessage[] devFields,
+                                                  InputStream inputStream)
+            throws IOException {
+        BigInteger applicationId = null;
+        short developerDataIndex = 0xFF;
+        for (FitField fitField : fieldList) {
+            final var size = fitField.size();
+            switch (fitField.fieldDefinitionNumber()) {
+                case 1 -> applicationId = new BigInteger(inputStream.readNBytes(size));
+                case 3 -> developerDataIndex = NumberUtils.decodeShort(size, littleEndian, inputStream);
+                default -> inputStream.readNBytes(size);
+            }
+        }
+        return new FitDeveloperDataIdMessage(applicationId, developerDataIndex,
+                DevDataUtils.parseDevFields(littleEndian, developerFieldList, devFields, inputStream));
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDevice.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDevice.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitDevice.java	(revision 36153)
@@ -0,0 +1,38 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperFieldDescriptionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitField;
+import org.openstreetmap.josm.plugins.fit.lib.utils.DevDataUtils;
+import org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils;
+
+public record FitDevice(short type, int manufacturer, int product, long serialNumber, long timeCreated,
+                        FitDevDataRecord devData) implements FitData {
+
+    public static FitDevice parse(boolean littleEndian, List<FitField> fieldList, List<FitDeveloperField> developerFieldList,
+                                  FitDeveloperFieldDescriptionMessage[] developerFields, InputStream inputStream) throws IOException {
+        short type = 0xFF;
+        var manufacturer = 0xFFFF;
+        var product = 0xFFFF;
+        long serialNumber = 0x00000000;
+        var timeCreated = 0xFFFFFFFFL;
+        for (FitField fitField : fieldList) {
+            final var size = fitField.size();
+            switch (fitField.fieldDefinitionNumber()) {
+                case 0 -> type = NumberUtils.decodeByte(size, littleEndian, inputStream);
+                case 1 -> manufacturer = NumberUtils.decodeInt(size, littleEndian, inputStream);
+                case 2 -> product = NumberUtils.decodeInt(size, littleEndian, inputStream);
+                case 3 -> serialNumber = NumberUtils.decodeLong(size, littleEndian, inputStream);
+                case 4 -> timeCreated = NumberUtils.decodeLong(size, littleEndian, inputStream);
+                default -> inputStream.readNBytes(size);
+            }
+        }
+        return new FitDevice(type, manufacturer, product, serialNumber, timeCreated,
+                DevDataUtils.parseDevFields(littleEndian, developerFieldList, developerFields, inputStream));
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitUnknownRecord.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitUnknownRecord.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/FitUnknownRecord.java	(revision 36153)
@@ -0,0 +1,9 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.IField;
+
+public record FitUnknownRecord(FieldData[] data, FitDevDataRecord devData) implements FitData {
+
+    public record FieldData(IField field, byte[] data) {}
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/Global.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/Global.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/Global.java	(revision 36153)
@@ -0,0 +1,73 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDefinitionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperFieldDescriptionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitField;
+import org.openstreetmap.josm.plugins.fit.lib.utils.DevDataUtils;
+
+/**
+ * Global message ids
+ */
+public interface Global {
+    byte MESSAGE_NUMBER_FILE_ID = 0;
+    short MESSAGE_NUMBER_APP_ID = 207;
+    short MESSAGE_NUMBER_DEV_FIELD_DESCRIPTION = 206;
+
+    /**
+     * Get the constructor for the specified message number
+     *
+     * @param globalMessageNumber The message number for the field definition (the "meaning")
+     * @param fieldList           The list of fields to populate
+     * @param inputStream         The stream to read
+     * @param littleEndian        The endianness of the data
+     * @param developerFieldList  The list of developer fields
+     * @param developerFields The global developer field definitions
+     * @return The fit data or null if we couldn't parse it
+     * @throws IOException see {@link InputStream#read()}
+     */
+    static Object parseData(int globalMessageNumber, boolean littleEndian, List<FitField> fieldList,
+                            List<FitDeveloperField> developerFieldList, FitDeveloperFieldDescriptionMessage[] developerFields,
+                            InputStream inputStream) throws IOException {
+        return switch (globalMessageNumber) {
+            case MESSAGE_NUMBER_FILE_ID ->
+                    FitDevice.parse(littleEndian, fieldList, developerFieldList, developerFields, inputStream);
+            // No clue what to call this. For all I know, it is a typo and will never appear in the wild.
+            case 20 ->
+                    HeartRateCadenceDistanceSpeed.parse(littleEndian, fieldList, developerFieldList, developerFields, inputStream);
+            case MESSAGE_NUMBER_DEV_FIELD_DESCRIPTION -> FitDeveloperFieldDescriptionMessage
+                    .parse(littleEndian, fieldList, developerFieldList, developerFields, inputStream);
+            case MESSAGE_NUMBER_APP_ID ->
+                    FitDeveloperDataIdMessage.parse(littleEndian, fieldList, developerFieldList, developerFields, inputStream);
+            default -> {
+                final var fieldData = new FitUnknownRecord.FieldData[fieldList.size()];
+                var index = 0;
+                for (FitField field : fieldList) {
+                    fieldData[index++] = new FitUnknownRecord.FieldData(field, inputStream.readNBytes(field.size()));
+                }
+                yield new FitUnknownRecord(fieldData,
+                        DevDataUtils.parseDevFields(littleEndian, developerFieldList, developerFields, inputStream));
+            }
+        };
+    }
+
+    /**
+     * Get the constructor for the specified message number
+     *
+     * @param definitionMessage The data definitions
+     * @param inputStream       The stream to read
+     * @return The fit data or null if we couldn't parse it
+     * @throws IOException see {@link InputStream#read()}
+     */
+    static Object parseData(FitDefinitionMessage definitionMessage,
+            FitDeveloperFieldDescriptionMessage[] developerFields, InputStream inputStream) throws IOException {
+        return parseData(definitionMessage.globalMessageNumber(), definitionMessage.littleEndian(),
+                definitionMessage.fitFields(), definitionMessage.fitDeveloperFields(), developerFields, inputStream);
+    }
+
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/HeartRateCadenceDistanceSpeed.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/HeartRateCadenceDistanceSpeed.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/HeartRateCadenceDistanceSpeed.java	(revision 36153)
@@ -0,0 +1,103 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+import static org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils.checkShort;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.List;
+
+import org.openstreetmap.josm.plugins.fit.lib.FitBaseType;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperFieldDescriptionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitField;
+import org.openstreetmap.josm.plugins.fit.lib.utils.DevDataUtils;
+import org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils;
+
+public record HeartRateCadenceDistanceSpeed(Instant timestamp, double lat, double lon, double ele, short heartRate, short cadence,
+                                            int distance, int speed, long[][] unknown,
+                                            FitDevDataRecord devData) implements FitData, IFitTimestamp<HeartRateCadenceDistanceSpeed> {
+    private static final long[][] NO_UNKNOWNS = new long[0][];
+
+    // Using the 2023-09-09-12-0016.fit.gpx file provided by richlv:
+    // 1063184416, 1063184419, 1063184488 -> 2023-09-09 + (T09:00:16Z, T09:00:19Z, T09:01:28Z)
+    // If we just call ofEpochSecond, these will all be in 2003-09-10. Therefore, the epoch start
+    // must be different in fit files. We can get this using the following code:
+    // Instant.ofEpochSecond(Instant.parse("2023-09-09T09:00:16Z").getEpochSecond() - 1063184416).toString()
+    private static final long EPOCH_DIFFERENCE = Instant.parse("1989-12-31T00:00:00Z").getEpochSecond();
+
+    public HeartRateCadenceDistanceSpeed(int heartRate, int cadence, int distance, int speed, FitDevDataRecord devData) {
+        this(Instant.EPOCH, Double.NaN, Double.NaN, Double.NaN, checkShort(heartRate), checkShort(cadence),
+                distance, speed, NO_UNKNOWNS, devData);
+    }
+
+    @Override
+    public HeartRateCadenceDistanceSpeed withTimestamp(Instant timestamp) {
+        return new HeartRateCadenceDistanceSpeed(timestamp, this.lat, this.lon, this.ele, this.heartRate, this.cadence,
+                this.distance, this.speed, this.unknown, this.devData);
+    }
+
+    public static HeartRateCadenceDistanceSpeed parse(boolean littleEndian, List<FitField> fieldList,
+                                                      List<FitDeveloperField> developerFieldList,
+                                                      FitDeveloperFieldDescriptionMessage[] developerFields, InputStream inputStream)
+            throws IOException {
+        long heartRate = FitBaseType.uint8.invalidValue();
+        short cadence = 0xFF;
+        var lat = Double.NaN;
+        var lon = Double.NaN;
+        var ele = Double.NaN;
+        var distance = FitBaseType.uint32.invalidValue();
+        var speed = FitBaseType.uint16.invalidValue();
+        var timestamp = Instant.EPOCH;
+        var unknowns = NO_UNKNOWNS;
+        for (FitField fitField : fieldList) {
+            final var size = fitField.size();
+            switch (fitField.fieldDefinitionNumber()) {
+                // Fields 0/1 were the only two fields with sufficient "bits" for lat/lon
+                // Field 0 was "closer" to the lat, and Field 1 was "closer" to the lon.
+                case 0 -> lat = decodeDegrees(NumberUtils.decodeLong(size, littleEndian, inputStream));
+                case 1 -> lon = decodeDegrees(NumberUtils.decodeLong(size, littleEndian, inputStream));
+                case 2 -> ele = decodeElevation(NumberUtils.decodeLong(size, littleEndian, inputStream));
+                case 3 -> heartRate = NumberUtils.decodeShort(size, littleEndian, inputStream);
+                case 4 -> cadence = NumberUtils.decodeShort(size, littleEndian, inputStream);
+                case 5 -> distance = NumberUtils.decodeInt(size, littleEndian, inputStream);
+                case 6 -> speed = NumberUtils.decodeInt(size, littleEndian, inputStream);
+                case 253 -> timestamp = Instant.ofEpochSecond(EPOCH_DIFFERENCE + NumberUtils.decodeLong(size, littleEndian, inputStream));
+                default -> {
+                    unknowns = Arrays.copyOf(unknowns, unknowns.length + 1);
+                    unknowns[unknowns.length - 1] = new long[]{fitField.fieldDefinitionNumber(),
+                            NumberUtils.decodeLong(size, littleEndian, inputStream)};
+                }
+            }
+        }
+        return new HeartRateCadenceDistanceSpeed(timestamp, lat, lon, ele, (short) heartRate, cadence, (int) distance, (int) speed, unknowns,
+                DevDataUtils.parseDevFields(littleEndian, developerFieldList, developerFields, inputStream));
+    }
+
+    private static double decodeDegrees(long original) {
+        // signed ints, no need to look into zigzag decoding
+        // 0 -> 0 (assumed)
+        // 676960569 -> 56.7421794
+        // 676960086 -> 56.7421389
+        // 291082210 -> 24.3982289
+        // 291082461 -> 24.3982500
+        // min/max lat probably -+90
+        // min/max lon probably -+180
+        // Equation probably has 180 in it (max(180, 90))
+        // Assume that the equation doesn't have fractions and no additions (0, 0)
+        // 56.7421794 = 676960569 / 180 * x => x = 56.7421794 * 180 / 676960569 = 1.5087e-5 (inverse -> 66280.359)
+        // 56.7421794 = 676960569 * 180 * x => x = 56.7421794 / (180 * 676960569) = 3.56e-8 (inverse -> 2.1474836E9, or Integer.MAX_VALUE)
+        return original * 180d / Integer.MAX_VALUE;
+    }
+
+    private static double decodeElevation(long original) {
+        // 2212 -> -57.6
+        // 2655 -> 31.0
+        // 2656 -> 31.2
+        // 2657 -> 31.4
+        // Each integer == 0.2 (probably m?)
+        return original / 5d - 500;
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/IFitTimestamp.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/IFitTimestamp.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/global/IFitTimestamp.java	(revision 36153)
@@ -0,0 +1,15 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.global;
+
+import java.time.Instant;
+
+public sealed
+
+interface IFitTimestamp<T>
+permits HeartRateCadenceDistanceSpeed
+{
+
+    Instant timestamp();
+
+    T withTimestamp(Instant timestamp);
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevDoubleData.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevDoubleData.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevDoubleData.java	(revision 36153)
@@ -0,0 +1,5 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records;
+
+public record FitDevDoubleData(String fieldName, String unit, Double value) implements IFitDevData<Double> {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevFloatData.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevFloatData.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevFloatData.java	(revision 36153)
@@ -0,0 +1,5 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records;
+
+public record FitDevFloatData(String fieldName, String unit, Float value) implements IFitDevData<Float> {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevIntData.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevIntData.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevIntData.java	(revision 36153)
@@ -0,0 +1,5 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records;
+
+public record FitDevIntData(String fieldName, String unit, Integer value) implements IFitDevData<Integer> {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevLongData.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevLongData.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevLongData.java	(revision 36153)
@@ -0,0 +1,5 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records;
+
+public record FitDevLongData(String fieldName, String unit, Long value) implements IFitDevData<Long> {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevStringData.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevStringData.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevStringData.java	(revision 36153)
@@ -0,0 +1,6 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records;
+
+
+public record FitDevStringData(String fieldName, String unit, String value) implements IFitDevData<String> {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevUnknown.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevUnknown.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/FitDevUnknown.java	(revision 36153)
@@ -0,0 +1,5 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records;
+
+public record FitDevUnknown(String fieldName, String unit, byte[] value) implements IFitDevData<byte[]> {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/IFitDevData.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/IFitDevData.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/IFitDevData.java	(revision 36153)
@@ -0,0 +1,17 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records;
+
+/**
+ * An interface for custom data types.
+ */
+public sealed
+interface IFitDevData<V>
+permits FitDevDoubleData, FitDevFloatData, FitDevIntData, FitDevLongData, FitDevStringData, FitDevUnknown
+{
+
+    String fieldName();
+
+    String unit();
+
+    V value();
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDefinitionMessage.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDefinitionMessage.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDefinitionMessage.java	(revision 36153)
@@ -0,0 +1,8 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+import java.util.List;
+
+public record FitDefinitionMessage(short reserved, boolean littleEndian, int globalMessageNumber,
+                                   List<FitField> fitFields, List<FitDeveloperField> fitDeveloperFields) {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDeveloperField.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDeveloperField.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDeveloperField.java	(revision 36153)
@@ -0,0 +1,12 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+/**
+ * Define the meaning of data (e.g. field name, units, and base type)
+ *
+ * @param fieldNumber        Maps to {@code field_definition_number} of a {@code field_description} message
+ * @param size               The size (in bytes) of the FIT message field
+ * @param developerDataIndex Maps to the {@code developer_data_index} of a {@code developer_data_id} message.
+ */
+public record FitDeveloperField(short fieldNumber, short size, short developerDataIndex) implements IField {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDeveloperFieldDescriptionMessage.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDeveloperFieldDescriptionMessage.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitDeveloperFieldDescriptionMessage.java	(revision 36153)
@@ -0,0 +1,44 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.openstreetmap.josm.plugins.fit.lib.global.FitDevDataRecord;
+import org.openstreetmap.josm.plugins.fit.lib.utils.DevDataUtils;
+import org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils;
+import org.openstreetmap.josm.plugins.fit.lib.utils.StringUtils;
+
+public record FitDeveloperFieldDescriptionMessage(short developerDataIndex, short fieldDefinitionNumber,
+                                                  short fitBaseTypeId, String fieldName, String units,
+                                                  short nativeFieldNumber,
+                                                  FitDevDataRecord devData) {
+
+
+    public static FitDeveloperFieldDescriptionMessage parse(boolean littleEndian, List<FitField> fieldList,
+                                                            List<FitDeveloperField> developerFieldList,
+                                                            FitDeveloperFieldDescriptionMessage[] developerFields, InputStream inputStream)
+            throws IOException {
+        short developerDataIndex = 0xFF;
+        short fieldDefinitionNumber = 0xFF;
+        short fitBaseTypeId = 0xFF;
+        var fieldName = "";
+        var units = "";
+        short nativeFieldNumber = Short.MAX_VALUE;
+        for (FitField fitField : fieldList) {
+            final var size = fitField.size();
+            switch (fitField.fieldDefinitionNumber()) {
+                case 0 -> developerDataIndex = NumberUtils.decodeShort(size, littleEndian, inputStream);
+                case 1 -> fieldDefinitionNumber = NumberUtils.decodeShort(size, littleEndian, inputStream);
+                case 2 -> fitBaseTypeId = NumberUtils.decodeShort(size, littleEndian, inputStream);
+                case 3 -> fieldName = StringUtils.decodeString(inputStream);
+                case 8 -> units = StringUtils.decodeString(inputStream);
+                default -> inputStream.readNBytes(size);
+            }
+        }
+
+        return new FitDeveloperFieldDescriptionMessage(developerDataIndex, fieldDefinitionNumber, fitBaseTypeId,
+                fieldName, units, nativeFieldNumber, DevDataUtils.parseDevFields(littleEndian, developerFieldList, developerFields, inputStream));
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitField.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitField.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitField.java	(revision 36153)
@@ -0,0 +1,21 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+import static org.openstreetmap.josm.plugins.fit.lib.utils.NumberUtils.checkShort;
+
+import org.openstreetmap.josm.plugins.fit.lib.FitBaseType;
+
+/**
+ * A FIT field
+ *
+ * @param fieldDefinitionNumber The field definition number
+ * @param size                  The size (in bytes) of the fit message field
+ * @param baseType              The base type of the FIT message. See {@link FitBaseType} and {@link #fitBaseType()}.
+ * @param fitBaseType           The parsed base type of the FIT message.
+ */
+public record FitField(short fieldDefinitionNumber, short size, short baseType, FitBaseType fitBaseType) implements IField {
+    public FitField(int fieldDefinitionNumber, int size, int baseType) {
+        this(checkShort(fieldDefinitionNumber), checkShort(size), checkShort(baseType), FitBaseType.fromBaseTypeField(baseType));
+    }
+
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitFieldDescriptionMessage.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitFieldDescriptionMessage.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitFieldDescriptionMessage.java	(revision 36153)
@@ -0,0 +1,17 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+/**
+ * Define the meaning of data in a dev field
+ *
+ * @param developerDataIndex    The index of the developer for this message
+ * @param fieldDefinitionNumber The field number for this message
+ * @param baseTypeId            The base type of this field
+ * @param fieldName             The name of the field
+ * @param units                 The units of the field
+ * @param nativeFieldNumber     The equivalent native field number
+ */
+record FitFieldDescriptionMessage(short developerDataIndex, short fieldDefinitionNumber, short baseTypeId,
+                                  String fieldName,
+                                  String units, short nativeFieldNumber) {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitHeader.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitHeader.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitHeader.java	(revision 36153)
@@ -0,0 +1,13 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+/**
+ * The header for a fit file
+ *
+ * @param protocolVersion The protocol version number
+ * @param profileVersion  The profile version number
+ * @param dataSize        The size of the data in bytes (does not include header or CRC)
+ * @param crc             The CRC of the data
+ */
+public record FitHeader(short protocolVersion, int profileVersion, long dataSize, int crc) {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordCompressedTimestampHeader.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordCompressedTimestampHeader.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordCompressedTimestampHeader.java	(revision 36153)
@@ -0,0 +1,11 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+/**
+ * Compressed timestamp header
+ *
+ * @param localMessageType The local message type
+ * @param timeOffset       The time offset in seconds
+ */
+public record FitRecordCompressedTimestampHeader(byte localMessageType, byte timeOffset) implements FitRecordHeader {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordHeader.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordHeader.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordHeader.java	(revision 36153)
@@ -0,0 +1,18 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+/**
+ * The headers for data in a FIT file
+ */
+sealed
+public interface FitRecordHeader
+permits FitRecordCompressedTimestampHeader, FitRecordNormalHeader
+{
+
+    /**
+     * Get the local message type
+     *
+     * @return The local message type
+     */
+    byte localMessageType();
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordNormalHeader.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordNormalHeader.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/FitRecordNormalHeader.java	(revision 36153)
@@ -0,0 +1,16 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+/**
+ * A header for the next data record
+ *
+ * @param isDefinitionMessage {@code true} if it is a <i>definition message</i>, {@code false} if it is a <i>data message</i>
+ * @param messageTypeSpecific This is specific to <i>definition</i> and <i>data</i> message types. For <i>definition</i>,
+ *                            it indicates that the message contains extended definitions for developer data. For <i>data</i>,
+ *                            it is reserved and should be 0.
+ * @param reserved            Reserved (not used)
+ * @param localMessageType
+ */
+public record FitRecordNormalHeader(boolean isDefinitionMessage, boolean messageTypeSpecific,
+                                    boolean reserved, byte localMessageType) implements FitRecordHeader {
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/IField.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/IField.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/records/internal/IField.java	(revision 36153)
@@ -0,0 +1,8 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.records.internal;
+
+public sealed
+interface IField
+permits FitDeveloperField, FitField
+{
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/DevDataUtils.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/DevDataUtils.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/DevDataUtils.java	(revision 36153)
@@ -0,0 +1,55 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+
+import org.openstreetmap.josm.plugins.fit.lib.FitBaseType;
+import org.openstreetmap.josm.plugins.fit.lib.global.FitDevDataRecord;
+import org.openstreetmap.josm.plugins.fit.lib.records.FitDevDoubleData;
+import org.openstreetmap.josm.plugins.fit.lib.records.FitDevFloatData;
+import org.openstreetmap.josm.plugins.fit.lib.records.FitDevIntData;
+import org.openstreetmap.josm.plugins.fit.lib.records.FitDevLongData;
+import org.openstreetmap.josm.plugins.fit.lib.records.FitDevStringData;
+import org.openstreetmap.josm.plugins.fit.lib.records.FitDevUnknown;
+import org.openstreetmap.josm.plugins.fit.lib.records.IFitDevData;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperFieldDescriptionMessage;
+
+public final class DevDataUtils {
+    private static final FitDevDataRecord EMPTY_IFITDEVDATA = new FitDevDataRecord();
+
+    private DevDataUtils() {
+        // Hide constructor
+    }
+
+    public static FitDevDataRecord parseDevFields(boolean littleEndian,
+            Collection<FitDeveloperField> developerFieldList, FitDeveloperFieldDescriptionMessage[] devFields,
+            InputStream inputStream) throws IOException {
+        if (developerFieldList.isEmpty()) {
+            return EMPTY_IFITDEVDATA;
+        }
+        final var arrayData = new IFitDevData<?>[developerFieldList.size()];
+        int index = 0;
+        for (FitDeveloperField fitField : developerFieldList) {
+            final var devField = devFields[fitField.developerDataIndex()];
+            final String fieldName = devField.fieldName();
+            final String units = devField.units();
+            final short fieldSize = fitField.size();
+            arrayData[index++] = switch (FitBaseType.fromBaseTypeField(devField.fitBaseTypeId())) {
+            case float64 -> new FitDevDoubleData(fieldName, units,
+                    NumberUtils.decodeDouble(fieldSize, littleEndian, inputStream));
+            case float32 -> new FitDevFloatData(fieldName, units,
+                    NumberUtils.decodeFloat(fieldSize, littleEndian, inputStream));
+            case enum_, sint8, uint8, uint8z, sint16, uint16, uint16z, sint32 -> new FitDevIntData(fieldName, units,
+                    NumberUtils.decodeInt(fieldSize, littleEndian, inputStream));
+            case uint32, uint32z, sint64, uint64, uint64z -> new FitDevLongData(fieldName, units,
+                    NumberUtils.decodeLong(fieldSize, littleEndian, inputStream));
+            case string -> new FitDevStringData(fieldName, units, StringUtils.decodeString(inputStream));
+            case byte_, UNKNOWN -> new FitDevUnknown(fieldName, units, inputStream.readNBytes(fieldSize));
+            };
+        }
+        return new FitDevDataRecord(arrayData);
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/NumberUtils.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/NumberUtils.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/NumberUtils.java	(revision 36153)
@@ -0,0 +1,58 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public final class NumberUtils {
+    private NumberUtils() {
+        // Hide constructor
+    }
+
+    public static long decodeLong(int byteSize, boolean littleEndian, InputStream inputStream) throws IOException {
+        long value = 0;
+        int increment = littleEndian ? 8 : -8;
+        int shift = littleEndian ? 0 : (byteSize - 1) * 8;
+        for (var i = 0; i < byteSize; i++) {
+            value += ((long) inputStream.read() << shift);
+            shift += increment;
+        }
+        return value;
+    }
+
+    public static double decodeDouble(int byteSize, boolean littleEndian, InputStream inputStream) throws IOException {
+        return Double.longBitsToDouble(decodeLong(byteSize, littleEndian, inputStream));
+    }
+
+    public static int decodeInt(int byteSize, boolean littleEndian, InputStream inputStream) throws IOException {
+        return (int) decodeLong(byteSize, littleEndian, inputStream);
+    }
+
+    public static float decodeFloat(int byteSize, boolean littleEndian, InputStream inputStream) throws IOException {
+        return Float.intBitsToFloat(decodeInt(byteSize, littleEndian, inputStream));
+    }
+
+    public static short decodeShort(int byteSize, boolean littleEndian, InputStream inputStream) throws IOException {
+        return (short) decodeLong(byteSize, littleEndian, inputStream);
+    }
+
+    public static byte decodeByte(int byteSize, boolean littleEndian, InputStream inputStream) throws IOException {
+        return (byte) decodeLong(byteSize, littleEndian, inputStream);
+    }
+
+    public static char decodeChar(int byteSize, boolean littleEndian, InputStream inputStream) throws IOException {
+        return (char) decodeLong(byteSize, littleEndian, inputStream);
+    }
+
+    public static boolean decodeBoolean(int byteSize, boolean littleEndian, InputStream inputStream)
+            throws IOException {
+        return decodeLong(byteSize, littleEndian, inputStream) == 1;
+    }
+
+    public static short checkShort(int number) {
+        if (number > Short.MAX_VALUE || number < Short.MIN_VALUE) {
+            throw new IllegalArgumentException(number + " is larger than a short");
+        }
+        return (short) number;
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/StringUtils.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/StringUtils.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/main/java/org/openstreetmap/josm/plugins/fit/lib/utils/StringUtils.java	(revision 36153)
@@ -0,0 +1,30 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.plugins.fit.lib.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Utils for strings
+ */
+public final class StringUtils {
+    private StringUtils() {
+        // Hide constructor
+    }
+
+    /**
+     * Decode the next string from a stream
+     *
+     * @param inputStream The stream to read
+     * @return The decoded string
+     * @throws IOException See {@link InputStream#read()}
+     */
+    public static String decodeString(InputStream inputStream) throws IOException {
+        final var stringBuilder = new StringBuilder();
+        int next;
+        while ((next = inputStream.read()) != 0) {
+            stringBuilder.append((char) next);
+        }
+        return stringBuilder.toString();
+    }
+}
Index: applications/editors/josm/plugins/FIT/src/test/unit/org/openstreetmap/josm/plugins/fit/lib/FitReaderTest.java
===================================================================
--- applications/editors/josm/plugins/FIT/src/test/unit/org/openstreetmap/josm/plugins/fit/lib/FitReaderTest.java	(revision 36153)
+++ applications/editors/josm/plugins/FIT/src/test/unit/org/openstreetmap/josm/plugins/fit/lib/FitReaderTest.java	(revision 36153)
@@ -0,0 +1,173 @@
+package org.openstreetmap.josm.plugins.fit.lib;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Collections;
+
+import org.junit.jupiter.api.Test;
+import org.openstreetmap.josm.plugins.fit.lib.global.FitDevDataRecord;
+import org.openstreetmap.josm.plugins.fit.lib.global.Global;
+import org.openstreetmap.josm.plugins.fit.lib.global.FitDeveloperDataIdMessage;
+import org.openstreetmap.josm.plugins.fit.lib.global.FitDevice;
+import org.openstreetmap.josm.plugins.fit.lib.global.HeartRateCadenceDistanceSpeed;
+import org.openstreetmap.josm.plugins.fit.lib.records.FitDevIntData;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitDeveloperFieldDescriptionMessage;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitField;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitHeader;
+import org.openstreetmap.josm.plugins.fit.lib.records.internal.FitRecordNormalHeader;
+import org.openstreetmap.josm.plugins.fit.lib.utils.DevDataUtils;
+
+class FitReaderTest {
+    private static final FitDeveloperFieldDescriptionMessage[] NO_DEV_FIELDS = new FitDeveloperFieldDescriptionMessage[0];
+    private static final FitDevDataRecord NO_DEV_DATA = assertDoesNotThrow(() -> DevDataUtils.parseDevFields(false, Collections.emptyList(), NO_DEV_FIELDS, null));
+    private static final byte[][] SAMPLE_FIGURE_14 = {
+            // File header (14 byte)
+            {0x0E, 0x10, (byte) 0x98, 0x08, (byte) 0xA9, 0x00, 0x00, 0x00, 0x2E, 0x46, 0x49, 0x54, /* wrong crc (fix) */ 0x00, 0x00 /* wrong crc */},
+            // Record 1 (1,2)
+            {0x40}, {0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x02, (byte) 0x84, 0x02, 0x02, (byte) 0x84, 0x03, 0x04, (byte) 0x8C, 0x04, 0x04, (byte) 0x86},
+            // Record 2 (3,4)
+            {0x00}, {0x04, 0x0F, 0x00, 0x16, 0x00, (byte) 0xD2, 0x04, 0x00, 0x00, 0x28, (byte) 0xC6, 0x0A, 0x25},
+            // Record 3 (5,6)
+            {0x40}, {0x00, 0x00, (byte) 0xCF, 0x00, 0x02, 0x01, 0x10, 0x0D, 0x03, 0x01, 0x02},
+            // Record 4 (7,8)
+            {0x00}, {0x2C, 0x01, 0x02, 0x02, 0x03, 0x01, 0x0F, 0x01, 0x02, 0x0C, 0x1F, 0x29, 0x01, 0x02, 0x01, 0x58, 0x00},
+            // Record 5 (9,10)
+            {0x40}, {0x00, 0x00, (byte) 0xCE, 0X00, 0x05, 0x00, 0x01, 0x02, 0x01, 0x01, 0x02, 0x02, 0x01, 0x02, 0x03, 0x40, 0x07, 0x08, 0x10, 0x07},
+            // Record 6 (11,12)
+            {0x00}, {0x00, 0x00, 0x01, 0x64, 0x6F, 0x75, 0x67, 0x68, 0x6E, 0x75, 0x74, 0x73, 0x5F, 0x65, 0x61, 0x72, 0x6E, 0x65, 0x64, 0x00, 0x64, 0x6F, 0x75, 0x67, 0x68, 0x6E, 0x75, 0x74, 0x73, 0x00},
+            // Record 7 (13,14)
+            {0x60}, {0x00, 0x00, 0x14, 0x00, 0x04, 0x03, 0x01, 0x02, 0x04, 0x01, 0x02, 0x05, 0x04, (byte) 0x86, 0x06, 0x02, (byte) 0x84, 0x01, 0x00, 0x01, 0x00},
+            // Record 8 (15,16)
+            {0x00}, {(byte) 0x8C, 0x58, (byte) 0xFE, 0x01, 0x00, 0x00, (byte) 0xF0, 0x0A, 0x01},
+            // Record 9 (17,18)
+            {0x00}, {(byte) 0x8F, 0x5A, 0x20, 0x08, 0x00, 0x00, 0x68, 0x0B, 0x01},
+            // Record 10 (19, 20)
+            {0x00}, {(byte) 0x90, 0x5C, 0x7E, 0x0E, 0x00, 0x00, (byte) 0xEA, 0x0B, 0x01},
+            // CRC (2 byte) (fix this, see also header)
+            {}
+    };
+
+    private static byte[] convert2dByteArray(byte[][] array) {
+        var size = 0;
+        for (byte[] bytes : array) {
+            size += bytes.length;
+        }
+        final byte[] returnArray = new byte[size];
+        var index = 0;
+        for (byte[] bytes : array) {
+            System.arraycopy(bytes, 0, returnArray, index, bytes.length);
+            index += bytes.length;
+        }
+        return returnArray;
+    }
+
+    @Test
+    void testFitHeader() throws IOException {
+        final var header = FitReader.readFitHeader(new ByteArrayInputStream(
+                new byte[] {0x0e, 0x10, (byte) 0x98, 0x08, (byte) 0xda, (byte) 0xd4, 0x00, 0x00, 0x2e, 0x46, 0x49, 0x54, (byte) 0x9a, (byte) 0xfc}));
+        assertEquals(new FitHeader((short) 16, 2200, 54490L, 64666), header);
+    }
+
+    @Test
+    void testReadRecordDefinitionHeader() throws IOException {
+        final var recordHeader = FitReader.readNextRecordHeader(new ByteArrayInputStream(SAMPLE_FIGURE_14[1]));
+        final var normalHeader = assertInstanceOf(FitRecordNormalHeader.class, recordHeader);
+        assertAll(() -> assertTrue(normalHeader.isDefinitionMessage()),
+                () -> assertFalse(normalHeader.messageTypeSpecific()),
+                () -> assertFalse(normalHeader.reserved()),
+                () -> assertEquals(0, normalHeader.localMessageType()));
+    }
+
+    @Test
+    void testReadRecordDataHeader() throws IOException {
+        final var recordHeader = FitReader.readNextRecordHeader(new ByteArrayInputStream(new byte[] {0x00}));
+        final var normalHeader = assertInstanceOf(FitRecordNormalHeader.class, recordHeader);
+        assertAll(() -> assertFalse(normalHeader.isDefinitionMessage()),
+                () -> assertFalse(normalHeader.messageTypeSpecific()),
+                () -> assertFalse(normalHeader.reserved()),
+                () -> assertEquals(0, normalHeader.localMessageType()));
+    }
+
+    @Test
+    void testRecordDefinitionMessage() throws IOException {
+        final var recordHeader = assertInstanceOf(FitRecordNormalHeader.class,
+                FitReader.readNextRecordHeader(new ByteArrayInputStream(SAMPLE_FIGURE_14[1])));
+        final var definitionMessage = FitReader.readNextDefinition(recordHeader, new ByteArrayInputStream(SAMPLE_FIGURE_14[2]));
+        assertAll(() -> assertEquals(5, definitionMessage.fitFields().size()),
+                () -> assertEquals(0, definitionMessage.fitDeveloperFields().size()),
+                () -> assertEquals(0, definitionMessage.globalMessageNumber()),
+                () -> assertTrue(definitionMessage.littleEndian()),
+                () -> assertEquals(0, definitionMessage.reserved()));
+        assertAll(() -> assertEquals(new FitField(0, 1, 0), definitionMessage.fitFields().getFirst()),
+                () -> assertEquals(new FitField(1, 2, 132), definitionMessage.fitFields().get(1)),
+                () -> assertEquals(new FitField(2, 2, 132), definitionMessage.fitFields().get(2)),
+                () -> assertEquals(new FitField(3, 4, 140), definitionMessage.fitFields().get(3)),
+                () -> assertEquals(new FitField(4, 4, 134), definitionMessage.fitFields().getLast()));
+    }
+
+    @Test
+    void testDeviceFit() throws IOException {
+        final var definitionMessage = FitReader.readNextDefinition(
+                assertInstanceOf(FitRecordNormalHeader.class, FitReader.readNextRecordHeader(new ByteArrayInputStream(SAMPLE_FIGURE_14[1]))),
+                new ByteArrayInputStream(SAMPLE_FIGURE_14[2]));
+        final var device = assertInstanceOf(FitDevice.class, Global.parseData(definitionMessage, NO_DEV_FIELDS, new ByteArrayInputStream(SAMPLE_FIGURE_14[4])));
+        assertAll(() -> assertEquals(4, device.type()),
+                () -> assertEquals(15, device.manufacturer()),
+                () -> assertEquals(22, device.product()),
+                () -> assertEquals(1234, device.serialNumber()),
+                () -> assertEquals(621463080, device.timeCreated()));
+    }
+
+    @Test
+    void testDeveloperDataIdMessage() throws IOException {
+        final var definitionHeader = assertInstanceOf(FitRecordNormalHeader.class,
+                FitReader.readNextRecordHeader(new ByteArrayInputStream(SAMPLE_FIGURE_14[5])));
+        final var definitionMessage = FitReader.readNextDefinition(definitionHeader, new ByteArrayInputStream(SAMPLE_FIGURE_14[6]));
+        assertInstanceOf(FitRecordNormalHeader.class,
+                FitReader.readNextRecordHeader(new ByteArrayInputStream(SAMPLE_FIGURE_14[7])));
+        assertInstanceOf(FitDeveloperDataIdMessage.class, Global.parseData(definitionMessage, NO_DEV_FIELDS, new ByteArrayInputStream(SAMPLE_FIGURE_14[8])));
+    }
+
+    @Test
+    void testRecordDefinitionMessageDevFields() throws IOException {
+        final var recordHeader = assertInstanceOf(FitRecordNormalHeader.class,
+                FitReader.readNextRecordHeader(new ByteArrayInputStream(SAMPLE_FIGURE_14[9])));
+        // definition message for the dev data
+        final var definitionMessage = FitReader.readNextDefinition(recordHeader, new ByteArrayInputStream(SAMPLE_FIGURE_14[10]));
+        assertAll(() -> assertEquals(5, definitionMessage.fitFields().size()),
+                () -> assertEquals(0, definitionMessage.fitDeveloperFields().size()),
+                () -> assertTrue(definitionMessage.littleEndian()),
+                () -> assertEquals(0, definitionMessage.reserved()),
+                () -> assertEquals(206, definitionMessage.globalMessageNumber()));
+        final var devDefinitionMessage = assertInstanceOf(FitDeveloperFieldDescriptionMessage.class,
+                Global.parseData(definitionMessage, NO_DEV_FIELDS, new ByteArrayInputStream(SAMPLE_FIGURE_14[12])));
+
+        assertAll(() -> assertEquals(0, devDefinitionMessage.developerDataIndex()),
+                () -> assertEquals(0, devDefinitionMessage.fieldDefinitionNumber()),
+                () -> assertEquals(1, devDefinitionMessage.fitBaseTypeId()),
+                () -> assertEquals("doughnuts_earned", devDefinitionMessage.fieldName()),
+                () -> assertEquals("doughnuts", devDefinitionMessage.units()));
+    }
+
+    @Test
+    void testReadSampleFigure14() throws FitException {
+        final var fitData = FitReader.read(new ByteArrayInputStream(convert2dByteArray(SAMPLE_FIGURE_14)));
+        final var doughnuts = new FitDevDataRecord(new FitDevIntData("doughnuts_earned", "doughnuts", 1));
+        assertEquals(5, fitData.length);
+        assertAll(() -> assertEquals(new FitDevice((short) 4, 15, 22, 1234, 621463080,
+                                NO_DEV_DATA), fitData[0]),
+                () -> assertEquals(new FitDeveloperDataIdMessage(
+                        new BigInteger("58491264835600100376640728332759073112"), (short) 0, NO_DEV_DATA), fitData[1]),
+                () -> assertEquals(new HeartRateCadenceDistanceSpeed(140, 88, 510, 2800, doughnuts), fitData[2]),
+                () -> assertEquals(new HeartRateCadenceDistanceSpeed(143, 90, 2080, 2920, doughnuts), fitData[3]),
+                () -> assertEquals(new HeartRateCadenceDistanceSpeed(144, 92, 3710, 3050, doughnuts), fitData[4]));
+    }
+}
Index: applications/editors/josm/plugins/build.xml
===================================================================
--- applications/editors/josm/plugins/build.xml	(revision 36152)
+++ applications/editors/josm/plugins/build.xml	(revision 36153)
@@ -12,5 +12,5 @@
     <condition property="isJava11"><matches string="${ant.java.version}" pattern="1[1-9]|[2-9][0-9]" /></condition>
     <!-- Specific plugins -->
-    <property name="java21_plugins" value="fit/build.xml" />
+    <property name="java21_plugins" value="FIT/build.xml" />
     <property name="java17_plugins" value="maproulette/build.xml
                                             imageio/build.xml
