1. 程式人生 > 其它 >TLSR8258方案開發之BLE協議介面程式碼解析

TLSR8258方案開發之BLE協議介面程式碼解析

一 前言

  這裡的程式碼是在原廠基礎上修改了不少。雖然程式碼複雜了不少,但是邏輯也清晰了不少。

 

二  廣播協議

  想要熟悉並修改ble的廣播協議和內容,請查閱結構體:

static const attribute_t my_Attributes[]   比如,假如要上報電壓值,可以在裡面新增
        {0,ATT_PERMISSIONS_READ,2,sizeof(my_batCharVal),(u8*)(&my_characterUUID), (u8*)(my_batCharVal), 0},                //prop

   該廣播資訊的填寫如下所示:

 
//// Battery attribute values
static const u8 my_batCharVal[5] = {
    CHAR_PROP_READ | CHAR_PROP_NOTIFY,
    U16_LO(BATT_LEVEL_INPUT_DP_H), U16_HI(BATT_LEVEL_INPUT_DP_H),
    U16_LO(CHARACTERISTIC_UUID_BATTERY_LEVEL), U16_HI(CHARACTERISTIC_UUID_BATTERY_LEVEL)
};

 

三 連線和斷開   連線成功的介面如下所示:
    case
APP_BLE_EVENT_CONNECTED: b_ble_connected = ON; LOG_INFO("Connected!!! ble_state:%d ",b_ble_connected); LOG_INFO("e: %d p:%d n: %d", param->e, param->p, param->n);

  斷開的介面如下所示:

    case APP_BLE_EVENT_DISCONNECTED:
        b_ble_connected = OFF;
        b_rx_notify_enable 
= OFF; LOG_INFO("DisConnected Reason: 0x%02x ble_state:%d ", param->p,b_ble_connected); att_mtu_size = DEFAULT_ATT_MTU_SIZE;

 

四 資料收發      資料接收的介面函式:
static int parse_xp_message(XpMessage* message, uint8_t* data, uint16_t len)
{
    uint8_t* p = NULL;
    p = data;
    
    set_xp_header(message, data, &p);
    LOG_DEBUG("%s Info: ble received data:", __func__);
  資料傳送的介面函式:
    app_ble_send_data_by_notification(buff, length);

 

五 軟硬體連結:

泰凌微TLSR8258 BLE5.0物聯網IOT評估開發板產品級原始碼開放-淘寶網 (taobao.com)