Skip to content

05.Sync Data

Kilnn edited this page Jul 18, 2023 · 12 revisions

sample project: Refer to SyncFragment.kt

The function of sync data refers to obtaining the data of each functional module from the device. This is also the main capability of the device.

Use FcDataFeature.syncData to sync data from device, like this:

val dataFeature = fcSDK.connector.dataFeature()
dataFeature.syncData().observeOn(Schedulers.io(), true).subscribe({
    when (it.type) {
        FcSyncDataType.STEP -> {
            val data = it.toStep()//the step data
        }
        FcSyncDataType.OXYGEN -> {
            val data = it.toOxygen()
        }
        FcSyncDataType.OXYGEN_MEASURE -> {
            val data = it.toOxygenMeasure()
        }
        ...
    }
}, {
    //error
})

After successful synchronization of each type of data, except for FcTodayTotalData, the data on the device will be deleted. If a certain type fails to synchronize data, the subsequent synchronization process will be interrupted.

For monitoring data, devices typically store data for 7 days. Such as step, sleep, heart rate and blood pressure, etc.

For measurement data, it depends on the size of the storage space of the device itself. Such as ECG, Sport, heart rate real-time data, etc.

Types

Base

Devices may contain multiple types of data, but not all devices support them. Use FcDeviceInfo.Feature to determine whether the device supports these types of data, as shown below:

Name Flag Type Class
Step All supported FcSyncDataType.STEP FcStepData
Sleep All supported FcSyncDataType.SLEEP FcSleepData
Heart Rate Feature.HEART_RATE FcSyncDataType.HEART_RATE FcHeartRateData
Oxygen Feature.OXYGEN FcSyncDataType.OXYGEN FcOxygenData
Blood Pressure Feature.BLOOD_PRESSURE FcSyncDataType.BLOOD_PRESSURE FcBloodPressureData
Temperature Feature.TEMPERATURE FcSyncDataType.TEMPERATURE FcTemperatureData
Pressure Feature.PRESSURE FcSyncDataType.PRESSURE FcPressureData
Sport Feature.SPORT FcSyncDataType.SPORT FcSportData
ECG Feature.ECG FcSyncDataType.ECG FcEcgData
Game Feature.GAME FcSyncDataType.GAME FcGameData
GPS Feature.GPS FcSyncDataType.GPS FcGpsData

Measure

Heart Rate, Oxygen, Blood Pressure, Temperature and Pressure are collectively referred to as Health data. These types of data are affected by FcHealthMonitorConfig, We call it monitor data.

APP can use FcDataFeature.openHealthRealTimeData to measure real-time data. Similarly, real-time data measurement can also be performed on the device. The data generated by some devices can also be synchronized, We call it measure data, and their types are as follows:

Name Flag Type Class
Heart Rate measure / FcSyncDataType.HEART_RATE_MEASURE FcHeartRateData
Oxygen measure / FcSyncDataType.OXYGEN_MEASURE FcOxygenData
Blood Pressure measure / FcSyncDataType.BLOOD_PRESSURE_MEASURE FcBloodPressureMeasureData
Temperature measure / FcSyncDataType.TEMPERATURE_MEASURE FcTemperatureData
Pressure measure / FcSyncDataType.PRESSURE_MEASURE FcPressureData
  • Only the data measured on the device will be synchronized. Data measured using FcDataFeature.openHealthRealTimeData from the app will not be synchronized.
  • Not all devices support measure data. You don't need to determine whether the device supports it, just process the data obtained in the syncData results.

Today total data

Due to some historical reasons and device functionality limitations, The FcStepData is not always real-time, it may be delayed by 5 minutes. So if you use the accumulated FcStepData of the day to obtain steps, it will be inconsistent with the steps on the device, At this point, FcTodayTotalDatacan be used.

Name Flag Type Class
Today total data All supported FcSyncDataType.TODAY_TOTAL_DATA FcTodayTotalData

Usage

  • FcDataFeature.syncData : Execute sync
  • FcDataFeature.observerSyncState : Observer sync state. For [0-100] represents the actual progress of synchronization. Others value emit are define in FcSyncState.
  • FcDataFeature.isSyncing : Is currently in data syncing?

Data

Step

The device will monitor the user's motion status throughout the day and generate step data.

When FcDataFeature.syncData emit a FcSyncDataType.STEP type data, you can use FcSyncData.toStep to convert to FcStepData.

FcStepData indicates the number of steps of the user's movement at a certain point in time, such as 2019-05-29 12:00:00 and 50 steps. Actually, it can be understood that the user has accumulated 50 steps in the 5 minute period from 2019-05-29 11:55:00 to 2019-05-29 12:00:00.

If FcDeviceInfo.Feature.STEP_EXTRA is supported, FcStepData also contains the distance and calories exercised during this time. Practically all new devices will support this. For information on how to handle unsupported situations, please refer to the sample project SyncDataRepository.saveStep.

The device generates a step data about every 5 minutes, but this is not absolute. If the user is in continuous motion, each step data will be separated by 5 minutes. If the user is intermittently moving, the interval may be greater than 5 minutes or less than 5 minutes.

Device re-bound solution.

The current design of the device is to clear the data each time it is bound. Therefore, when the device is re-bound, the number of steps will become 0, which may be inconsistent with the data stored locally by the APP.

The solution is to delete the FcStepData of the day cached in APP when the device is re-bound. For more detail, please refer to the sample project SyncDataRepository.saveTodayStep

FcStepData delay solution

The device saves a FcStepData every 5 minutes, but the total number of steps displayed on the device is real-time. If you use FcStepData to accumulate the total number of steps, it is always delayed by 5 minutes relative to the device.

The solution is use total number of steps in FcTodayTotalData. For more detail, please refer to the sample project SyncDataRepository.saveTodayStep

Sleep

The device monitors the user's sleep state between 21:30 and 12:00 the next day and generates sleep data.

When FcDataFeature.syncData emit a FcSyncDataType.SLEEP type data, you can use FcSyncData.toSleep to convert to FcSleepData.

FcSleepData.timestamp gets the start timestamp of a certain day, for example 2019-05-29 00:00:00:000, which can be understood as representing the sleep condition of last night. That is, the sleep condition between 2019-05-28 21:30 and 2019-05-29 12:00.

Sleep data on the same day may be returned multiple times, this should be noted.

Health data

Heart Rate, Oxygen, Blood Pressure, Temperature and Pressure are collectively referred to as Health data. These types of data are affected by FcHealthMonitorConfig, We call it monitor data.

For example, heart rate monitoring data, When FcDataFeature.syncData emit a FcSyncDataType.HEART_RATE type data, you can use FcSyncData.toheartRate to convert to FcHeartRateData.

APP can use FcDataFeature.openHealthRealTimeData to measure real-time data. Similarly, real-time data measurement can also be performed on the device. The data generated by some devices can also be synchronized, We call it measure data.

For example, heart rate measure data, When FcDataFeature.syncData emit a FcSyncDataType.HEART_RATE_MEASURE type data, you can use FcSyncData.toheartRateMeasure to convert to FcHeartRateData.

Before using these types of data, please first determine whether the device supports them, such as FcDeviceInfo.Feature.HEART_RATE.

ECG

When FcDeviceInfo.Feature.ECG is supported, the device support ECG function.

The ECG measurement on the device can be converted to FcEcgData.

The ECG data is relatively large, and currently the device only stores the latest measurement records

The ECG algorithms of different chips may vary, If FcDeviceInfo.Feature.TI_ECG is supported, you can adjust the speed and amplitude of ECG data. Refer to the sample project EcgFragment.updateEcgDetail

Sport and GPS

When FcDeviceInfo.Feature.SPORT is supported, the device support sport function. When the user starts sports on the device, FcSportData will be generated.

When FcDeviceInfo.Feature.GPS is supported, will additionally generate FcGpsData. FcGpsData belongs to FcSportData, and they are related by sportId. If FcGpsData.sportId is the same as FcSportData.sportId, it means it is the GPS data generated by this sport.

If the syncData is all successful, then FcSportData and FcGpsData should have all returned successfully. You can refer to sample project SyncDataRepository.clearSportGpsId to see how to associate these two data.

The device may support multiple sport types, refer to: Sport-UI-Type

Game

When FcDeviceInfo.Feature.GAME is supported, the device support game function.

The FcGameData will be generated when the user plays games on the device.

The device may support multiple game types, refer to: GameType

In addition to sync game data from the device, the following method are also related to game functions:

  • FcSettingsFeature.requestSupportGameTypes: Request all game types supported by the device.

  • FcSettingsFeature.requestHighestGameRecords: Request the highest game record for a certain game type

  • FcSettingsFeature.setGameRankingTrends: Set ranking changes for a certain game type

  • FcSettingsFeature.setLockGame: Set game lock or unlock

Clone this wiki locally