With the popularity of wearable devices, the collection of sports data has become more convenient, and more and more sports and health apps have come into people’s sight. Tracking and recording of daily exercise data has become the core function of various sports apps.

The southbound service provided by Huawei Sports and Health Service – device access service can help developers to write sports data. During the development process, the developer needs to parse the fields of the data sent back by the device in the App, restore the corresponding parameters, and display them in the App user interface.

So how do you parse the data returned by sports devices?

First of all, we need to understand that the device access service provided by Huawei Sports and Health is based on the standard FTMS protocol for data transmission. The so-called FTMS-Fitness equipment service is a separate definition made by the standard Bluetooth protocol for training data transmission in sports and fitness

What can we learn from the agreement document, standard FMTS agreement have defined the motions (warm-up, low strength, high strength, etc.), fitness equipment status (open, stagnation, etc.), and the types of fitness equipment support (treadmill, cross trainers, stair climbers, climb stairs, rowing, indoor cycling)

For support for different types of fitness equipment, refer to Chapter 3 of the FTMS protocol

Refer to Chapter 4 of the FTMS protocol for details of the parameters supported by specific fitness equipment

It should be noted that in FTMS protocol, we have made a convention on byte order. In FTMS protocol, little endian is adopted, that is, the high address bit stores the low byte bit data. For details, see section 3.2 of FTMS

FMTS agreement document links as follows: www.bluetooth.com/specificati…

All right, so with that in mind, let’s do an example

In the case of Rower Data, we receive a string of Data from a rowing machine. What does it mean

7e19002700d69c0000000061000000e4000d0000000024000000

Let’s take a look at the format of the data in the protocol. The data can be divided into two large segments, the first is Flags, the second is parameters

Parsing the Flags field

From the figure above, we can see that the data starts with the 2-byte (16-bit) Flags, that is, 7E19. This hexadecimal representation is converted to binary, which is 0111 1110 0001 1001

But remember that FTMS is small endian, meaning that the left 8 bits store the lower bits of data, so the actual read order should be

According to the document, we can find that this Flags indicates that the following fields are reported for this data (refer to the field meanings described in FTMS protocol).

At this point, let’s refer to the description of 4.8.1.1 Flags Field in the FTMS standard protocol. We can know the information contained in the following fields that this Flag indicates.

Note that the number of parameters identified by each bit is not the same. In some cases, one bit corresponds to multiple parameters. In this example, refer to the following table for details about the mapping between bits and parameters

In summary, we know that the data Flags segment tells us that the following parameter segment contains the following 13 parameters:

Stroke Rate

Stroke Count

Average Stroke Rate

Total Distance

Instantaneous Pace

Average Pace

Instantaneous Power

Average Power

Total Energy

Energy Per Hour

Energy Per Minute

Elapsed Time

Remaining Time

Now you can start parsing the specific parameters

Parameter Field parsing

According to the format definition of each parameter in the guide document, you can divide the data in the parameter segment according to the length defined in the format to match each parameter. In this example, data is divided as follows:

00-2700-d6-9c0000-0000-6100-0000-e400-0d00-0000-00-2400-0000

We can see what each parameter means by converting the above segmented parameter bytes to decimal. Once again, remember the byte order of FTMS. When converting the hexadecimal data of each field to decimal, remember the read order. The analysis results are as follows:

So far, such a movement data interpretation is completed, we can see that the user in the rowing machine movement, a total of 234 meters, consuming 15 kcal energy; In addition, we can also understand the specific number of paddles, pulp frequency, exercise time and other data.

Through the transmission and interpretation of such exercise data, we can record and track users’ exercise and daily exercise, which has helped users to achieve their own health and fitness management needs.

For details about how to add more devices, see

Developer.huawei.com/consumer/cn…

For more information about HMS Core, see: >> Huawei Developer Alliance official website

>> To get the development guide >> to participate in the developer discussion, visit the CSDN community or Reddit community >> To download the demo and sample code, visit Github or Gitee >> To resolve integration issues, visit Stack Overflow

The original link: developer.huawei.com/consumer/cn…

Original author: Pepper