1、runtime增加蓝牙各种状态,目前已经实现手机连接,耳机和经典蓝牙状态同步未完成。另pullupdownview还未正常更新 154/1 154/head 155/target/1 156/target/1
authorSnickerSun <snickersun@163.com>
Thu, 9 May 2024 09:36:17 +0000 (17:36 +0800)
committerSnickerSun <snickersun@163.com>
Thu, 9 May 2024 09:36:17 +0000 (17:36 +0800)
2、修改USE_CAT1_SLEEP_TIMER宏的有用法

code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp
code/sdk/application/wearable/service/ble_service/bleservice/bleService.c
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp
code/sdk/drivers/peripheral/utils/custom_cmd_service.c
code/sdk/drivers/peripheral/utils/custom_runtime.c
code/sdk/drivers/peripheral/utils/custom_runtime.h
code/sdk/drivers/peripheral/utils/custom_utils.c

index ff564c8..dc1b191 100644 (file)
@@ -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 连接状态
index 3374ee7..e735498 100644 (file)
@@ -35,6 +35,7 @@ extern "C" {
 #include "hidService.h"\r
 #include "factorytestService.h"\r
 #include "ppgBleService.h"\r
+#include "custom_runtime.h"\r
 \r
 // extern void bts_data_to_uuid_len2(uint16_t uuid_data, bt_uuid_t *out_uuid);\r
 // extern void bts_init_128bit_uuid(const bt_uuid_t *uuid);\r
@@ -106,6 +107,7 @@ uint16_t data2ae3Cmd = 0;//2ae3短指令特征值
 uint16_t data2ae4Cmd = 0;\r
 uint16_t data2ae5Cmd = 0;\r
 uint16_t data2ae1Cmd = 0;//安卓消息来电\r
+\r
 #if 1//def SUPPORT_BLE_SERVICE\r
 static void set_phone_info(bd_addr_t *addr)//保存手机信息 包含手机mac地址\r
 {\r
@@ -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);\r
         \r
     }\r
+\r
+    uapi_dev_runtime_set_ble_connect_stat(Bleconnect);\r
 }\r
 \r
 static void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t status)\r
index 1bc182c..3e0170b 100644 (file)
@@ -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");
index c805abb..b708dc6 100644 (file)
@@ -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;
index 1bb0e6d..23963c0 100644 (file)
@@ -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
index 9fb53e1..7dd44ef 100644 (file)
@@ -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
 }
index 9114c2e..4162387 100644 (file)
@@ -27,7 +27,7 @@
 #include "networkandcall/include/NetworkAndCallC.h"
 #include <dirent.h>
 #include <unistd.h>
-
+#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 */