[Huawei Developers] muraliameakula:
The popularization of wearable devices enables ever more convenient workout data collection, as well as the come into being of more sports and health apps that provide users with diverse daily workout tracking and data recording features.

HUAWEI Health Kit can be integrated to fitness devices through southbound APIs to help developers write workout data to apps, after which the developers will be able to parse the fields in the app, restore them to the corresponding parameters, and then display these parameters on the app UI.

So, how to parse the data returned by a fitness device?

The device integration service provided by HUAWEI Health Kit is based on the standard Fitness Machine Service (FTMS) protocol for data transmission. The FTMS provides a new definition of the standard Bluetooth protocol for training data transmission.

According to the protocol documentation, the standard FTMS protocol defines the workout status (warm-up, low-intensity, and high-intensity), fitness equipment status (on and standby), and supported fitness equipment types (treadmill, cross trainer, stair climber, rower, and indoor bike).

For details about the support of different types of fitness devices, see Chapter 3 of the FTMS protocol.

For specific parameters supported by a specific fitness device, see Chapter 4 of the FTMS protocol.

It should be noted that in the FTMS protocol, the byte order has been specified. In the FTMS protocol, little endian is used. That is, a higher address stores the data of the lower order byte data. For details, see Chapter 3.2 of the FTMS protocol.

Link to the FTMS protocol document:

https://www.bluetooth.com/specifications/specs/fitness-machine-service-1-0/

Take Rower Data as an example. The rowing machine returns the following data. What does it mean?

7e19002700d69c0000000061000000e4000d0000000024000000

Let's first look at the data format in the protocol. The data can be divided into two segments: Flags and Parameters.

Flags field parsing

According to the preceding figure, the data starts with a 2-byte (16-bit) flag, that is, 7E19. The hexadecimal representation is converted into binary, that is, 0111 1110 0001 1001.

But don't forget that FTMS uses little endian, that is, the first 8 digits (from left to right) store the lower bits of data, so the actual read order should be the following.

According to the document, we can find that the flag indicates that the data contains the following fields: (For details, see the field description in the FTMS protocol.)

According to the document, we can find that the flag indicates that the data contains the following fields: (For details, see the field description in the FTMS protocol.)

At this moment, we can refer to the description of 4.8.1.1 Flags Field in the FTMS protocol to obtain the information contained in the subsequent fields indicated by this flag.

It should be noted that a quantity of parameters identified by each bit is different, and one bit corresponds to a plurality of parameters. For a specific correspondence between a bit and a parameter in this example, refer to the following table.

Then we will be able to obtain the 13 parameters contained in the subsequent fields indicated by this flag:

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

We can then start parsing the parameters.

Parameter field parsing

By referring to the format definition of each parameter in the guide, we can divide the data of the parameter segment based on the format definition to match each parameter. In this example, the data is divided as follows:

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

Convert the segmented parameter byte into decimal to know the meaning of each parameter. Keep in mind the byte order of the FTMS. When converting the hexadecimal data of each field to the decimal, pay attention to the reading order. The parsing result is as follows.

At this point, the workout data is interpreted. We can see that the user completed 234 meters and consumed 15 kcal of energy in this rowing machine workout. In addition, we can learn about the number and frequency of paddle strokes and the workout time.

By transmitting and interpreting workout data from time to time, we can record and track users' daily workout, helping them manage their health and fitness.

For more about device integration, visit the following website:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/rd-0000001050725868-V5

To learn more, please visit:

HUAWEI Developers official website

Development Guide

Reddit to join developer discussions

GitHub or Gitee to download the demo and sample code

Stack Overflow to solve integration problems

Original Source