Code Desc
Overview
sample api is a web api app,implement 6 api,path
/pb/upload general data (most of the watch data) upload
/alarm/upload alarm data upload
/call_log/upload sos call log/normal call log upload
/deviceinfo/upload hardware info upload
/status/notify device online/offline status change notify
/health/sleep provide sleep result for device to display
The first three interfaces must be implemented, and the remaining interfaces are optional. You can choose whether to implement them according to your needs.
the first two interfaces receive general binary data, other interface receives JSON data uploaded by the watch. However, from the perspective of the HTTP protocol, the three interfaces all receive data submitted in form format, and the sample APIs we provide all parse data in general binary format. Some framework cannot ignore content-type, such as spring which will cause error, and the content-type of the client request needs to be modified to application/octet-stream through other methods.
the code mainly includes four parts: controller/parser/calculation/protobuf
controller http handler, request handle
parser data parse
calculation data calculation
protobuf generated protobuf code
The data format of the watch upload /pb/upload and /alarm/upload api: the first 15 bytes are deviceid, and the subsequent data may be 1 or more data packets. Multiple data packets are arranged one after another. The format of each data packet: the 1st-2nd bytes are fixed data 0x44 0x54, the 3rd-4th bytes are the data packet length,the 5th-6th bytes are the data packet CRC check code, the 7th-8th bytes are the protocol code, and the bytes following the previously defined data packet length are the data content, and the format is protobuf.The parser part of the code is to parse this data packet. What the /call_log/upload,/deviceinfo/upload api receives is actually JSON, which can be parsed using JSON-related libraries.
The calculation part displays the preprocessed data. You can call the calculation service to calculate the sleep/ECG analysis/atrial fibrillation analysis data.
Java
use spring boot
controller com.iwown.sample4GApi.controller
DeviceController /pb/upload
AlarmController /alarm/upload
CallLogController /call_log/upload
DeviceInfoController /deviceinfo/upload
DeviceStatusController /status/notify
SleepController /health/sleep
parser com.iwown.sample4GApi.service
HistoryDataParser 0x80 protocol parse
OldManDataParser 0x0A protocol parse
NewAlarmDataParser 0x12 protocol parse
calculation com.iwown.sample4GApi.calculation
SleepPreprocessor sleep data process
EcgPreprocessor ecg data process
RriPreprocessor af data process
Golang
use echo
controller
data_handler.go /pb/upload
alarm_handler.go /alarm/upload
call_log_handler.go /call_log/upload
device_info_handler.go /deviceinfo/upload
device_info_handler.go /status/notify
data_handler.go /health/sleep
parser
history_parser.go 0x80 protocol parse
oldman_parser.go 0x0A protocol parse
alarm_parser.go 0x12 protocol parse
calculation
sleep_preprocessor.go sleep data process
ecg_preprocessor.go ecg data process
af_preprocessor.go af data process
Python
use flask
controller app.py
app.py uploadPBData
app.py uploadAlarmData
app.py uploadCallLog
app.py uploadDeviceInfo
app.py deviceStatusChange
app.py getSleepResult
parser module pbparser
history_parser.py 0x80 protocol parse
oldman_parser.py 0x0A protocol parse
alarm_parser.py 0x12 protocol parse
calculation module calculation
sleep_preprocessor.py sleep data process
ecg_preprocessor.py ecg data process
af_preprocessor.py af data process
C#
use asp.net web core
controller controllers
DataController.cs /pb/upload
AlarmController.cs /alarm/upload
CallLogController.cs /call_log/upload
DeviceInfoController.cs /deviceinfo/upload
DeviceStatusController.cs /status/notify
SleepController.cs /health/sleep
parser parser
HistoryDataParser.cs 0x80 protocol parse
OldmanParser.cs 0x0A protocol parse
AlarmParser.cs 0x12 protocol parse
calculation calculation
Sleep_Preprocessor.cs sleep data process
Ecg_Preprocessor.cs ecg data process
Af_Preprocessor.cs af data process
php
use lumen
controller controller
data_controller.php /pb/upload
alarm_controller.php /alarm/upload
calllog_controller.php /call_log/upload
device_controller.php /deviceinfo/upload
device_controller.php /status/notify
data_controller.php /health/sleep
parser parser
history_parser.php 0x80 protocol parse
oldman_parser.php 0x0A protocol parse
alarm_parser.php 0x12 protocol parse
calculation calculation
sleep_preprocessor.php sleep data process
ecg_preprocessor.php ecg data process
af_preprocessor.php af data process
The PHP version of the sample API parses protobuf differently from other versions. We use protobuf2 for protobuf, but because protoc does not support generating PHP code for protobuf2 definition proto files, we use Python code to parse protobuf. PHP calls the Python script to pass data and get the result. Python will convert the parsed result into a JSON string.