From e0c279c4960aaf5116fd9902373ff478b550bf1b Mon Sep 17 00:00:00 2001 From: SnickerSun Date: Thu, 9 May 2024 17:36:17 +0800 Subject: [PATCH] =?utf8?q?1=E3=80=81runtime=E5=A2=9E=E5=8A=A0=E8=93=9D?= =?utf8?q?=E7=89=99=E5=90=84=E7=A7=8D=E7=8A=B6=E6=80=81=EF=BC=8C=E7=9B=AE?= =?utf8?q?=E5=89=8D=E5=B7=B2=E7=BB=8F=E5=AE=9E=E7=8E=B0=E6=89=8B=E6=9C=BA?= =?utf8?q?=E8=BF=9E=E6=8E=A5=EF=BC=8C=E8=80=B3=E6=9C=BA=E5=92=8C=E7=BB=8F?= =?utf8?q?=E5=85=B8=E8=93=9D=E7=89=99=E7=8A=B6=E6=80=81=E5=90=8C=E6=AD=A5?= =?utf8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=E3=80=82=E5=8F=A6pullupdownview?= =?utf8?q?=E8=BF=98=E6=9C=AA=E6=AD=A3=E5=B8=B8=E6=9B=B4=E6=96=B0=202?= =?utf8?q?=E3=80=81=E4=BF=AE=E6=94=B9USE=5FCAT1=5FSLEEP=5FTIMER=E5=AE=8F?= =?utf8?q?=E7=9A=84=E6=9C=89=E7=94=A8=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/main/src/PullUpDownView.cpp | 23 ++++++-- .../ble_service/bleservice/bleService.c | 4 ++ .../slip/cat1Service/cat1_server.cpp | 7 ++- .../peripheral/utils/custom_cmd_service.c | 4 +- .../drivers/peripheral/utils/custom_runtime.c | 36 ++++++++++++ .../drivers/peripheral/utils/custom_runtime.h | 57 ++++++++++++++++++- .../drivers/peripheral/utils/custom_utils.c | 12 +++- 7 files changed, 129 insertions(+), 14 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp index ff564c821..dc1b19129 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp @@ -325,21 +325,34 @@ namespace OHOS // 获取手机连接状态 bool PullUpDownView::GetPhoneConnectedStatus(void) { - return true; + uint8_t ret = uapi_dev_runtime_get_ble_connect_stat(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ble phone connect stat = %d", ret); + if (ret == 1) + return true; + else + return false; } // 获取蓝牙耳机连接状态 bool PullUpDownView::GetEarPhoneConnectedStatus(void) { - runtime_status_t *g_runtime = get_device_runtime_status(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_runtime->bt_connected = %d", g_runtime->bt_connected); - return true; + uint8_t ret = uapi_dev_runtime_get_earphone_connect_stat(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "earphone connect stat = %d", ret); + if (ret == 1) + return true; + else + return false; } // 获取蓝牙连接状态 bool PullUpDownView::GetBluetoothConnectedStatus(void) { - return true; + uint8_t ret = uapi_dev_runtime_get_br_connect_stat(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "br connect stat = %d [0 no connect, 1 a2dp, 2 hfp, 3 both]", ret); + if (ret != 0) + return true; + else + return false; } /// @brief 连接状态 diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 3374ee70c..e73549899 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -35,6 +35,7 @@ extern "C" { #include "hidService.h" #include "factorytestService.h" #include "ppgBleService.h" +#include "custom_runtime.h" // extern void bts_data_to_uuid_len2(uint16_t uuid_data, bt_uuid_t *out_uuid); // extern void bts_init_128bit_uuid(const bt_uuid_t *uuid); @@ -106,6 +107,7 @@ uint16_t data2ae3Cmd = 0;//2ae3短指令特征值 uint16_t data2ae4Cmd = 0; uint16_t data2ae5Cmd = 0; uint16_t data2ae1Cmd = 0;//安卓消息来电 + #if 1//def SUPPORT_BLE_SERVICE static void set_phone_info(bd_addr_t *addr)//保存手机信息 包含手机mac地址 { @@ -329,6 +331,8 @@ static void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_CONNECTED!!! 0x%x\r\n",pair_state); } + + uapi_dev_runtime_set_ble_connect_stat(Bleconnect); } static void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t status) diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp index 1bc182c88..3e0170bd4 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp @@ -103,7 +103,7 @@ struct tcp_msg_t { static int g_listen_sock = 0; struct sockaddr_in sourceAddr = {0}; static osTimerId_t g_timer_time_sync = NULL; -#if USE_CAT1_SLEEP_TIMER +#ifdef USE_CAT1_SLEEP_TIMER static osTimerId_t g_timer_cat1_sleep = NULL; #endif static uint8_t g_time_synced = 0; @@ -578,7 +578,7 @@ int cat1_handle_timesync(struct tcp_msg_t *msg) return 1; } -#if USE_CAT1_SLEEP_TIMER +#ifdef USE_CAT1_SLEEP_TIMER void mcu_remove_sleepvote_and_stoptimer(void) { // uapi_cat1_wakeup_cat1(0);// 反馈给cat1,它也可以自己睡 @@ -625,6 +625,7 @@ static void time_sync_func(void) runtime_status_t * runtime = get_device_runtime_status(); if (uapi_cat1_get_power_stat() == false ) { + // PRINT("cat1 power off reset cat1_runtime \n"); //开关是关的 则cat1所有状态清空 runtime->cat1_runtime.cat1_powerOn = 0; runtime->cat1_runtime.network_on = 0; @@ -883,7 +884,7 @@ errcode_t cat1_server_init(void) restart_time_sync(); -#if USE_CAT1_SLEEP_TIMER +#ifdef USE_CAT1_SLEEP_TIMER g_timer_cat1_sleep = osTimerNew((osTimerFunc_t)timeout_handler_sleep_cat1, osTimerPeriodic, NULL, NULL); if (g_timer_cat1_sleep == NULL) PRINT("g_timer_cat1_sleep create failed\n"); diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index c805abbd8..b708dc612 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -96,12 +96,12 @@ static void custom_cmd_service_check_task(void const *arg) uapi_cat1_add_cat1_vote(); //中断会在此添加休眠投票,在收到cat1的消息后,会移除投票进入休眠。 //之前的5秒后移除投票延迟太久,与5秒更新一次信号强度 - #if USE_CAT1_SLEEP_TIMER + #ifdef USE_CAT1_SLEEP_TIMER restart_sleep_cat1_timer(); #endif break; case CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE: - #if USE_CAT1_SLEEP_TIMER + #ifdef USE_CAT1_SLEEP_TIMER mcu_remove_sleepvote_and_stoptimer(); #endif break; diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.c b/code/sdk/drivers/peripheral/utils/custom_runtime.c index 1bb0e6db6..23963c08d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.c +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.c @@ -6,3 +6,39 @@ runtime_status_t * get_device_runtime_status(void) return &g_runtime; } + +void uapi_dev_runtime_set_bt_powerstat(uint8_t stat) +{ + g_runtime.bt_powerOn = stat; +} +void uapi_dev_runtime_set_ble_connect_stat(uint8_t connect) +{ + g_runtime.bt_ble_connectstat = connect; +} +void uapi_dev_runtime_set_br_connect_stat(uint8_t connect) +{ + g_runtime.bt_br_connectstat = connect; +} +void uapi_dev_runtime_set_earphone_connect_stat(uint8_t connect) +{ + g_runtime.bt_earphone_connectstat = connect; +} + + + +uint8_t uapi_dev_runtime_get_bt_powerstat(void) +{ + return g_runtime.bt_powerOn ; +} +uint8_t uapi_dev_runtime_get_ble_connect_stat(void) +{ + return g_runtime.bt_ble_connectstat; +} +uint8_t uapi_dev_runtime_get_br_connect_stat(void) +{ + return g_runtime.bt_br_connectstat ; +} +uint8_t uapi_dev_runtime_get_earphone_connect_stat(void) +{ + return g_runtime.bt_earphone_connectstat ; +} \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index 9fb53e1dd..7dd44ef6a 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -54,21 +54,72 @@ typedef struct char modemVer[64] ; }cat1_runtime_status_t; - +/** + * 设备实时状态记录 + * in_silent_mode 勿扰模式 1 勿扰模式, 0 正常模式 + * in_lowpower_mode 低电模式 1 低电模式, 0 正常模式 + * stepcount 步数 + * bt_powerOn 蓝牙开关 1 开 , 0 关 + * bt_ble_connectstat 设备已连接手机 1连接, 0 未连接 + * bt_br_connectstat 经典蓝牙连接状态 0 未连接, 1 连接a2dp 2 连接hfp 3 连接 a2dp+hfp + * bt_earphone_connectstat 连接耳机状态 1连接, 0 未连接 + * cat1_runtime cat1实时状态,详见 cat1_runtime_status_t 定义 + * */ typedef struct { uint8_t in_silent_mode; uint8_t in_lowpower_mode; uint8_t stepcount; uint8_t bt_powerOn; - uint8_t bt_connected; - + uint8_t bt_ble_connectstat; + uint8_t bt_br_connectstat; + uint8_t bt_earphone_connectstat; cat1_runtime_status_t cat1_runtime; } runtime_status_t; +/** + * 获取 设备实时状态变量 + * 详细内容见 runtime_status_t 定义 +*/ runtime_status_t * get_device_runtime_status(void); + +/** + * 设置蓝牙开关状态 +*/ +void uapi_dev_runtime_set_bt_powerstat(uint8_t stat); +/** + * 设置ble(手机协议)连接状态 1连接, 0 未连接 +*/ +void uapi_dev_runtime_set_ble_connect_stat(uint8_t connect); +/** + * 设置经典蓝牙协议连接状态, 0 未连接, 1 连接a2dp 2 连接hfp 3 连接 a2dp+hfp +*/ +void uapi_dev_runtime_set_br_connect_stat(uint8_t connect); +/** + * 设置耳机连接状态 1连接, 0 未连接 +*/ +void uapi_dev_runtime_set_earphone_connect_stat(uint8_t connect); + +/** + * 获取蓝牙电源状态 1开启0 关闭 +*/ +uint8_t uapi_dev_runtime_get_bt_powerstat(void); +/** + * 获取ble(手机协议)连接状态 1 连接,0 未连接 +*/ +uint8_t uapi_dev_runtime_get_ble_connect_stat(void); + +/** + * 获取经典蓝牙协议连接状态, 0 未连接, 1 连接a2dp 2 连接hfp 3 连接 a2dp+hfp +*/ +uint8_t uapi_dev_runtime_get_br_connect_stat(void); +/** + * 获取耳机连接状态 1连接, 0 未连接 +*/ +uint8_t uapi_dev_runtime_get_earphone_connect_stat(void); + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 9114c2e89..4162387e7 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -27,7 +27,7 @@ #include "networkandcall/include/NetworkAndCallC.h" #include #include - +#include "custom_runtime.h" #define SUPPORT_NV @@ -200,6 +200,7 @@ bool start_custom_ble_service(void) PRINT("start custom protocol classic bt ble service !\r\n"); // bool ret = enable_bt_stack(); #endif + uapi_dev_runtime_set_bt_powerstat(1); return true; } bool stop_custom_ble_service(void) @@ -210,6 +211,7 @@ bool stop_custom_ble_service(void) closeBle(); // bool ret = disable_bt_stack(); #endif + uapi_dev_runtime_set_bt_powerstat(0); return true; } @@ -1517,6 +1519,14 @@ void custom_i2c_reset(void) errcode_t custom_iic_init(void) { errcode_t result; + +// #ifdef CONFIG_I2C_SUPPORT_DMA +// #if CONFIG_I2C_SUPPORT_DMA +// #warning CONFIG_I2C_SUPPORT_DMA = 1 +// #else +// #warning CONFIG_I2C_SUPPORT_DMA = 0 +// #endif +// #endif if(i2c_installed == 0) { result = uapi_i2c_master_init(I2C_BUS_2, 400000, I2C_SPEED_MODE_FS); /* 400000: 400KHz */ -- 2.17.1