Browse Source

上传文件至 'src/hlw2025141/app/projects/earphone/com'

修改广播数据的参数
TangRuiyang 2 months ago
parent
commit
ac7d1f98fe

+ 11 - 11
src/hlw2025141/app/projects/earphone/com/checksum.py

@@ -1,11 +1,11 @@
-def calc(datas):
-    cs = 0;
-    for data in datas:
-        cs += data
-    cs &= 0xff
-    datas.append(cs)
-    print([hex(data) for data in datas])
-
-if __name__ == '__main__':
-    datas = [0xaa, 0x01, 0x01, 0x64]
-    calc(datas)
+def calc(datas):
+    cs = 0;
+    for data in datas:
+        cs += data
+    cs &= 0xff
+    datas.append(cs)
+    print([hex(data) for data in datas])
+
+if __name__ == '__main__':
+    datas = [0xaa, 0x01, 0x01, 0x64]
+    calc(datas)

+ 148 - 134
src/hlw2025141/app/projects/earphone/com/com_adv.c

@@ -1,134 +1,148 @@
-#include "com_adv.h"
-
-
-static uint32_t _fill_adv_type(uint8_t offset, uint8_t* buf)
-{
-
-    uint8_t* p = (uint8_t*)(buf + offset);
-    uint8_t i = 0;
-
-    p[i++] = 2;
-    p[i++] = 0x01;
-    p[i++] = 0x06;
-
-    printf("adv type: %d\r\n", i);
-    return i;
-
-}
-
-
-static uint32_t _fill_adv_local_name(uint8_t offset, uint8_t* buf)
-{
-
-    uint8_t* p = (uint8_t*)(buf + offset);
-    uint8_t i = 0;
-    int len;
-
-    len = strlen(xcfg_cb.le_name);
-    p[i++] = len + 1;
-    p[i++] = 0x09;
-    memcpy(&p[i], xcfg_cb.le_name, len);
-    i += len;
-
-    printf("adv local name: %d\r\n", i);
-    return i;
-
-}
-
-
-static uint32_t _fill_adv_uuid_datas(uint8_t offset, uint8_t* buf)
-{
-
-    uint8_t* p = (uint8_t*)(buf + offset);
-    uint8_t i = 0;
-
-    p[i++] = 6;
-    p[i++] = 0x16;
-    p[i++] = 0xaa;
-    p[i++] = 0xfa;
-    p[i++] = 100;     /* 左耳电量 */
-    p[i++] = 96;      /* 右耳电量 */
-    p[i++] = 0;
-
-    printf("adv uuid datas: %d\r\n", i);
-    return i;
-
-}
-
-
-static uint32_t _fill_adv_fact_datas(uint8_t offset, uint8_t* buf)
-{
-
-    uint8_t* p = (uint8_t*)(buf + offset);
-    uint8_t i = 0;
-    uint8_t addr[6];
-    uint8_t j;
-
-    p[i++] = 29;
-    p[i++] = 0xff;
-    p[i++] = 0xff;
-    p[i++] = 0xff;
-    p[i++] = 0x00;    /* 软件版本号低8位 */
-    p[i++] = 0x64;    /* 软件版本号高8位 */
-    p[i++] = 0x00;    /* 固件版本号低8位 */
-    p[i++] = 0x64;    /* 固件版本号高8位 */
-    p[i++] = 0x00;    /* 硬件版本号低8位 */
-    p[i++] = 0x64;    /* 硬件版本号高8位 */
-    p[i++] = 0x00;    /* 设备型号低8位 */
-    p[i++] = 0x00;    /* 设备型号中8位 */
-    p[i++] = 0x00;    /* 设备型号高8位 */
-
-    /* BLE地址 */
-    bt_get_local_bd_addr(addr);
-    j = 0;
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-
-    /* 经典蓝牙地址 */
-    bt_get_local_bd_addr(addr);
-    j = 0;
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-    p[i++] = addr[j++];
-
-    /* 设备序列号 */
-    p[i++] = 0x00;
-    p[i++] = 0x00;
-    p[i++] = 0x00;
-    p[i++] = 0x00;
-    p[i++] = 0x00;
-
-    printf("adv fact datas: %d\r\n", i);
-    return i;
-
-}
-
-
-uint32_t com_adv_fill_adv_data(uint8_t* buf)
-{
-
-    uint8_t i = 0;
-
-    i += _fill_adv_type(i, buf);
-    i += _fill_adv_local_name(i, buf);
-    i += _fill_adv_uuid_datas(i, buf);
-
-    return i;
-
-}
-
-
-uint32_t com_adv_fill_scan_data(uint8_t* buf)
-{
-
-    return _fill_adv_fact_datas(0, buf);
-
-}
-
+#include "com_adv.h"
+
+
+static uint32_t _fill_adv_type(uint8_t offset, uint8_t* buf)
+{
+
+    uint8_t* p = (uint8_t*)(buf + offset);
+    uint8_t i = 0;
+
+    p[i++] = 2;
+    p[i++] = 0x01;
+    p[i++] = 0x06;
+
+    printf("adv type: %d\r\n", i);
+    return i;
+
+}
+
+
+static uint32_t _fill_adv_local_name(uint8_t offset, uint8_t* buf)
+{
+
+    uint8_t* p = (uint8_t*)(buf + offset);
+    uint8_t i = 0;
+    int len;
+
+    len = strlen(xcfg_cb.le_name);
+    p[i++] = len + 1;
+    p[i++] = 0x09;
+    memcpy(&p[i], xcfg_cb.le_name, len);
+    i += len;
+
+    printf("adv local name: %d\r\n", i);
+    return i;
+
+}
+
+
+static uint32_t _fill_adv_uuid_datas(uint8_t offset, uint8_t* buf)
+{
+
+    uint8_t* p = (uint8_t*)(buf + offset);
+    uint8_t i = 0;
+
+    p[i++] = 6;
+    p[i++] = 0x16;
+    p[i++] = 0xaa;
+    p[i++] = 0xfa;
+    if(sys_cb.tws_force_channel == 2 && !bt_tws_is_slave())
+    {
+        p[i++] = hfp_get_bat_level_ex();     /* 左耳电量 */
+    }
+    else
+    {
+        p[i++] = sys_cb.rem_100_level_vbat;      /* 左耳电量 */
+    }
+    if(sys_cb.tws_force_channel == 1 && !bt_tws_is_slave())
+    {
+        p[i++] = hfp_get_bat_level_ex();      /* 右耳电量 */
+    }
+    else
+    {
+        p[i++] = sys_cb.rem_100_level_vbat;      /* 右耳电量 */
+    }
+    p[i++] = 0;
+
+    printf("adv uuid datas: %d\r\n", i);
+    return i;
+
+}
+
+
+static uint32_t _fill_adv_fact_datas(uint8_t offset, uint8_t* buf)
+{
+
+    uint8_t* p = (uint8_t*)(buf + offset);
+    uint8_t i = 0;
+    uint8_t addr[6];
+    uint8_t j;
+
+    p[i++] = 29;
+    p[i++] = 0xff;
+    p[i++] = 0xff;
+    p[i++] = 0xff;
+    p[i++] = TRY_APP_ADV_SW_VERSION_LOW_8BIT;    /* 软件版本号低8位 */
+    p[i++] = TRY_APP_ADV_SW_VERSION_HIGH_8BIT;    /* 软件版本号高8位 */
+    p[i++] = TRY_APP_ADV_FW_VERSION_LOW_8BIT;    /* 固件版本号低8位 */
+    p[i++] = TRY_APP_ADV_FW_VERSION_HIGH_8BIT;    /* 固件版本号高8位 */
+    p[i++] = TRY_APP_ADV_HW_VERSION_LOW_8BIT;    /* 硬件版本号低8位 */
+    p[i++] = TRY_APP_ADV_HW_VERSION_HIGH_8BIT;    /* 硬件版本号高8位 */
+    p[i++] = 0x00;    /* 设备型号低8位 */
+    p[i++] = 0x11;    /* 设备型号中8位 */
+    p[i++] = 0x58;    /* 设备型号高8位 */
+
+    /* BLE地址 */
+    bt_get_local_bd_addr(addr);
+    j = 0;
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+
+    /* 经典蓝牙地址 */
+    bt_get_local_bd_addr(addr);
+    j = 0;
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+    p[i++] = addr[j++];
+
+    /* 设备序列号 */
+    p[i++] = 0x00;
+    p[i++] = 0x00;
+    p[i++] = 0x00;
+    p[i++] = 0x00;
+    p[i++] = 0x00;
+
+    printf("adv fact datas: %d\r\n", i);
+    return i;
+
+}
+
+
+uint32_t com_adv_fill_adv_data(uint8_t* buf)
+{
+
+    uint8_t i = 0;
+
+    i += _fill_adv_type(i, buf);
+    i += _fill_adv_local_name(i, buf);
+    i += _fill_adv_uuid_datas(i, buf);
+
+    return i;
+
+}
+
+
+uint32_t com_adv_fill_scan_data(uint8_t* buf)
+{
+
+    return _fill_adv_fact_datas(0, buf);
+
+}
+

+ 11 - 11
src/hlw2025141/app/projects/earphone/com/com_adv.h

@@ -1,11 +1,11 @@
-#ifndef __COM_ADV_H__
-#define __COM_ADV_H__
-
-#include "include.h"
-
-
-uint32_t com_adv_fill_scan_data(uint8_t* buf);
-uint32_t com_adv_fill_adv_data(uint8_t* buf);
-
-
-#endif
+#ifndef __COM_ADV_H__
+#define __COM_ADV_H__
+
+#include "include.h"
+
+
+uint32_t com_adv_fill_scan_data(uint8_t* buf);
+uint32_t com_adv_fill_adv_data(uint8_t* buf);
+
+
+#endif

+ 80 - 80
src/hlw2025141/app/projects/earphone/com/com_ble.c

@@ -1,80 +1,80 @@
-#include "com_ble.h"
-#include "com_dec.h"
-
-
-static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len);
-
-const uint8_t _service_uuid16[2]={0xa0, 0xfa};
-static const gatts_uuid_base_st _service_uuid_base = {
-    .type = BLE_GATTS_UUID_TYPE_16BIT,
-    .uuid = _service_uuid16,
-};
-static gatts_service_base_st _service_gatts_base;
-
-const uint8_t _tx_uuid16[2]={0xa1, 0xfa};
-static const gatts_uuid_base_st _tx_uuid_base = {
-    .props = ATT_WRITE_WITHOUT_RESPONSE | ATT_READ,
-    .type = BLE_GATTS_UUID_TYPE_16BIT,
-    .uuid = _tx_uuid16,
-};
-
-const uint8_t _rx_uuid16[2]={0xa2, 0xfa};
-static const gatts_uuid_base_st _rx_uuid_base = {
-    .props = ATT_NOTIFY | ATT_READ,
-    .type = BLE_GATTS_UUID_TYPE_16BIT,
-    .uuid = _rx_uuid16,
-};
-static gatts_service_base_st _rx_gatts_base;
-
-static ble_gatt_characteristic_cb_info_t _tx_write_base_cb_info = {
-    .att_callback_func = _on_write,
-};
-
-static ble_gatt_characteristic_cb_info_t _rx_notify_base_cb_info = {
-    .client_config = GATT_CLIENT_CONFIG_NOTIFY,
-};
-
-
-int com_ble_init(void)
-{
-
-    int ret = 0;
-
-    ret = ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
-                                _service_uuid_base.uuid,
-                                _service_uuid_base.type,
-                                &_service_gatts_base.handle);
-
-    ret = ble_gatts_characteristic_add(_tx_uuid_base.uuid,
-                                       _tx_uuid_base.type,
-                                       _tx_uuid_base.props,
-                                       NULL,
-                                       &_tx_write_base_cb_info);
-
-    ret = ble_gatts_characteristic_add(_rx_uuid_base.uuid,
-                                       _rx_uuid_base.type,
-                                       _rx_uuid_base.props,
-                                       &_rx_gatts_base.handle,
-                                       &_rx_notify_base_cb_info);
-
-    return ret;
-
-}
-
-
-static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len)
-{
-
-    com_dec_on_recv(datas, len);
-
-    return 0;
-
-}
-
-
-void com_ble_notify(uint8_t* buf, uint8_t len)
-{
-
-    ble_tx_notify(_rx_gatts_base.handle, buf, len);
-
-}
+#include "com_ble.h"
+#include "com_dec.h"
+
+
+static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len);
+
+const uint8_t _service_uuid16[2]={0xa0, 0xfa};
+static const gatts_uuid_base_st _service_uuid_base = {
+    .type = BLE_GATTS_UUID_TYPE_16BIT,
+    .uuid = _service_uuid16,
+};
+static gatts_service_base_st _service_gatts_base;
+
+const uint8_t _tx_uuid16[2]={0xa1, 0xfa};
+static const gatts_uuid_base_st _tx_uuid_base = {
+    .props = ATT_WRITE_WITHOUT_RESPONSE | ATT_READ,
+    .type = BLE_GATTS_UUID_TYPE_16BIT,
+    .uuid = _tx_uuid16,
+};
+
+const uint8_t _rx_uuid16[2]={0xa2, 0xfa};
+static const gatts_uuid_base_st _rx_uuid_base = {
+    .props = ATT_NOTIFY | ATT_READ,
+    .type = BLE_GATTS_UUID_TYPE_16BIT,
+    .uuid = _rx_uuid16,
+};
+static gatts_service_base_st _rx_gatts_base;
+
+static ble_gatt_characteristic_cb_info_t _tx_write_base_cb_info = {
+    .att_callback_func = _on_write,
+};
+
+static ble_gatt_characteristic_cb_info_t _rx_notify_base_cb_info = {
+    .client_config = GATT_CLIENT_CONFIG_NOTIFY,
+};
+
+
+int com_ble_init(void)
+{
+
+    int ret = 0;
+
+    ret = ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
+                                _service_uuid_base.uuid,
+                                _service_uuid_base.type,
+                                &_service_gatts_base.handle);
+
+    ret = ble_gatts_characteristic_add(_tx_uuid_base.uuid,
+                                       _tx_uuid_base.type,
+                                       _tx_uuid_base.props,
+                                       NULL,
+                                       &_tx_write_base_cb_info);
+
+    ret = ble_gatts_characteristic_add(_rx_uuid_base.uuid,
+                                       _rx_uuid_base.type,
+                                       _rx_uuid_base.props,
+                                       &_rx_gatts_base.handle,
+                                       &_rx_notify_base_cb_info);
+
+    return ret;
+
+}
+
+
+static int _on_write(uint16_t con_handle, uint16_t handle, uint32_t flag, uint8_t* datas, uint16_t len)
+{
+
+    com_dec_on_recv(datas, len);
+
+    return 0;
+
+}
+
+
+void com_ble_notify(uint8_t* buf, uint8_t len)
+{
+
+    ble_tx_notify(_rx_gatts_base.handle, buf, len);
+
+}

+ 13 - 13
src/hlw2025141/app/projects/earphone/com/com_ble.h

@@ -1,13 +1,13 @@
-#ifndef __COM_BLE_H__
-#define __COM_BLE_H__
-
-#include "include.h"
-
-
-int com_ble_init(void);
-
-
-void com_ble_notify(uint8_t* buf, uint8_t len);
-
-
-#endif
+#ifndef __COM_BLE_H__
+#define __COM_BLE_H__
+
+#include "include.h"
+
+
+int com_ble_init(void);
+
+
+void com_ble_notify(uint8_t* buf, uint8_t len);
+
+
+#endif