174 lines
5.5 KiB
C
174 lines
5.5 KiB
C
/*----------------------------------------------------------------------------
|
|
* Copyright (c) Fenda Technologies Co., Ltd. 2021. All rights reserved.
|
|
*
|
|
* Description: ble_blood_oxygen_server.c
|
|
*
|
|
* Author: shey.tanxiaoyu
|
|
*
|
|
* Create: 2021-09-13
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "ble_blood_oxygen_server.h"
|
|
#include "ble_data_transmission.h"
|
|
#include "health_api.h"
|
|
//#include "task_ui.h"
|
|
|
|
/* 4.8.1 APP查询血氧测量状态 */
|
|
void ble_get_spo2_measure_status(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
|
{
|
|
uint16_t write_idx = 0;
|
|
protocol_data_info_t data_info = {0};
|
|
|
|
data_info.error = FENDA_SUCCESS;
|
|
do {
|
|
user_get_data_info(&data_info, &in_data, &in_len);
|
|
switch (data_info.type & 0x7F) {
|
|
case GET_SPO2_MEASURE_STATUS_TYPE:
|
|
// out_data[write_idx++] = 3;
|
|
// out_data[write_idx++] = RETURN_SPO2_MEASURE_STATUS_TYPE;
|
|
// out_data[write_idx++] = health_api_spo2_measure_state_get();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
in_data = data_info.p_data;
|
|
in_data += (data_info.len);
|
|
in_len -= (2 + data_info.len);
|
|
if (in_len > FRAM_MAX_SIZ) {
|
|
in_len = 0;
|
|
}
|
|
} while (in_len);
|
|
|
|
*out_len = write_idx;
|
|
}
|
|
|
|
/* 4.8.2 设备主动上报血氧测量状态 */
|
|
void ble_spo2_measure_report(void *ptr)
|
|
{
|
|
// uint16_t write_idx = 0;
|
|
// uint8_t buf_temp[TEMP_NUM_MAX] = {0};
|
|
//
|
|
// buf_temp[write_idx++] = 0x03;
|
|
// buf_temp[write_idx++] = REPORT_SPO2_MEASURE_STATUS_TYPE;
|
|
// buf_temp[write_idx++] = health_api_spo2_measure_state_get();
|
|
//
|
|
// buf_temp[write_idx++] = 0x03;
|
|
// buf_temp[write_idx++] = REPORT_SPO2_MEASURE_RESULT_TYPE;
|
|
// buf_temp[write_idx++] = health_api_get_real_spo2();
|
|
//
|
|
// BLE_SendFrameById(BLOOD_OXYGEN_SERVER, SPO2_MEASURE_REPORT_ID, buf_temp, write_idx);
|
|
}
|
|
|
|
/* 4.8.3 APP开启血氧测量 */
|
|
void ble_set_spo2_once_measure_switch(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
|
{
|
|
uint16_t write_idx = 0;
|
|
protocol_data_info_t data_info = {0};
|
|
uint8_t spo2_once_measure_switch = 0;
|
|
|
|
data_info.error = FENDA_SUCCESS;
|
|
do {
|
|
user_get_data_info(&data_info, &in_data, &in_len);
|
|
switch (data_info.type & 0x7F) {
|
|
case SET_SPO2_ONCE_MEASURE_SWITCH_TYPE:
|
|
spo2_once_measure_switch = *in_data;
|
|
health_api_set_spo2_once_measure_sw(spo2_once_measure_switch);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
in_data = data_info.p_data;
|
|
in_data += (data_info.len);
|
|
in_len -= (2 + data_info.len);
|
|
if(in_len > FRAM_MAX_SIZ) {
|
|
in_len = 0;
|
|
}
|
|
} while (in_len);
|
|
|
|
write_idx = user_set_protocol_error(out_data, BLOOD_OXYGEN_SERVER, data_info.error);
|
|
*out_len = write_idx;
|
|
}
|
|
|
|
/* 4.8.4 血氧连续测量开关 */
|
|
void ble_set_spo2_continue_measure_switch(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
|
{
|
|
uint16_t write_idx = 0;
|
|
protocol_data_info_t data_info = {0};
|
|
uint8_t spo2_continue_measure_switch = 0;
|
|
|
|
data_info.error = FENDA_SUCCESS;
|
|
do {
|
|
user_get_data_info(&data_info, &in_data, &in_len);
|
|
switch (data_info.type & 0x7F) {
|
|
case SET_SPO2_CONTINUE_MEASURE_SWITCH_TYPE:
|
|
spo2_continue_measure_switch = *in_data;
|
|
health_api_set_spo2_cont_measure_sw(spo2_continue_measure_switch);
|
|
// ui_task_notify(EVENT_SPO2_MEASURE_SWITCH, spo2_continue_measure_switch);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
in_data = data_info.p_data;
|
|
in_data += (data_info.len);
|
|
in_len -= (2 + data_info.len);
|
|
if (in_len > FRAM_MAX_SIZ) {
|
|
in_len = 0;
|
|
}
|
|
} while (in_len);
|
|
|
|
write_idx = user_set_protocol_error(out_data, BLOOD_OXYGEN_SERVER, data_info.error);
|
|
*out_len = write_idx;
|
|
}
|
|
|
|
/* 4.8.5 APP设置血氧过低提醒值 */
|
|
void ble_set_spo2_too_low_reminder_value(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
|
{
|
|
uint16_t write_idx = 0;
|
|
protocol_data_info_t data_info = {0};
|
|
|
|
data_info.error = FENDA_SUCCESS;
|
|
do {
|
|
user_get_data_info(&data_info, &in_data, &in_len);
|
|
|
|
switch (data_info.type & 0x7F) {
|
|
case SET_SPO2_TOO_LOW_REMINDER_VALUE_TYPE:
|
|
if (*data_info.p_data == 0) {
|
|
health_api_set_spo2_lower_remind(0, *data_info.p_data);
|
|
} else {
|
|
health_api_set_spo2_lower_remind(1, *data_info.p_data);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
in_data = data_info.p_data;
|
|
in_data += (data_info.len);
|
|
in_len -= (2 + data_info.len);
|
|
if (in_len > FRAM_MAX_SIZ) {
|
|
in_len = 0;
|
|
}
|
|
} while (in_len);
|
|
|
|
write_idx = user_set_protocol_error(out_data, BLOOD_OXYGEN_SERVER, data_info.error);
|
|
*out_len = write_idx;
|
|
}
|
|
|
|
|
|
const p_func_t blood_oxygen_server_func[BLOOD_OXYGEN_SERVER_MAX_ID] = {
|
|
user_null_func,
|
|
ble_get_spo2_measure_status, //4.8.1
|
|
user_null_func, //4.8.2
|
|
ble_set_spo2_once_measure_switch, //4.8.3
|
|
ble_set_spo2_continue_measure_switch, //4.8.4
|
|
ble_set_spo2_too_low_reminder_value, //4.8.5
|
|
};
|
|
|