開啟廣播需要處理哪些消息?

嘗試自己建議一個(gè)簡(jiǎn)單的藍(lán)牙代碼模板.

但是現(xiàn)在連廣播都沒(méi)法開啟.查了好多遍,也不知道問(wèn)題出在哪里.我認(rèn)為前面的代碼應(yīng)該都不會(huì)出問(wèn)題.可能出在消息處理上.麻煩幫看看到底什么原因沒(méi)有出現(xiàn)廣播.代碼基于ch582

main.c的主要代碼

int?main(void)
{
#if(defined(DCDC_ENABLE))?&&?(DCDC_ENABLE?==?TRUE)
???PWR_DCDCCfg(ENABLE);
#endif
???SetSysClock(CLK_SOURCE_PLL_60MHz);
#if(defined(HAL_SLEEP))?&&?(HAL_SLEEP?==?TRUE)
????GPIOA_ModeCfg(GPIO_Pin_All,?GPIO_ModeIN_PU);
????GPIOB_ModeCfg(GPIO_Pin_All,?GPIO_ModeIN_PU);
#endif
#ifdef?DEBUG
????GPIOA_SetBits(bTXD1);
????GPIOA_ModeCfg(bTXD1,?GPIO_ModeOut_PP_5mA);
????UART1_DefInit();
#endif
????PRINT("%s\n",?VER_LIB);
????CH58X_BLEInit();
????HAL_Init();
????GAPRole_PeripheralInit();
????Device_Init();
????Main_Circulation();
}


初始化的代碼

void Device_Init()
{
?? Device_TaskID = TMOS_ProcessEventRegister(Device_ProcessEvent);
?? uint16_t desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;
?? uint16_t desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;
?? // Setup the GAP Peripheral Role Profile
?? {
?????? uint8_t initial_advertising_enable = TRUE;

????? // Set the GAP Role Parameters
????? GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable);
????? GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanRspData), scanRspData);
????? GAPRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advertData);
????? GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t), &desired_min_interval);
????? GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t), &desired_max_interval);
??? }

?? // Set the GAP Characteristics
??? GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName);

?? {
?????? uint16_t advInt = DEFAULT_ADVERTISING_INTERVAL;

????? // Set advertising interval
?????? GAP_SetParamValue(TGAP_DISC_ADV_INT_MIN, advInt);
?????? GAP_SetParamValue(TGAP_DISC_ADV_INT_MAX, advInt);

????? // Enable scan req notify
?????? GAP_SetParamValue(TGAP_ADV_SCAN_REQ_NOTIFY, ENABLE);
?? }

??? // Setup the GAP Bond Manager
??? {
??????? uint32_t passkey = 0; // passkey "000000"
??????? uint8_t? pairMode = DEFAULT_PAIRING_PARAMETER;
??????? uint8_t? mitm = FALSE;
??????? uint8_t? ioCap = GAPBOND_IO_CAP_NO_INPUT_NO_OUTPUT;
??????? uint8_t ?bonding = REQ_BONDING;
??????? uint8_t ?autoSync = USING_WHITE_LIST;

?????? GAPBondMgr_SetParameter(GAPBOND_PERI_DEFAULT_PASSCODE, sizeof(uint32_t), &passkey);
?????? GAPBondMgr_SetParameter(GAPBOND_PERI_PAIRING_MODE, sizeof(uint8_t), &pairMode);
?????? GAPBondMgr_SetParameter(GAPBOND_PERI_MITM_PROTECTION, sizeof(uint8_t), &mitm);
?????? GAPBondMgr_SetParameter(GAPBOND_PERI_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
?????? GAPBondMgr_SetParameter(GAPBOND_PERI_BONDING_ENABLED, sizeof(uint8_t), &bonding);
?????? GAPBondMgr_SetParameter(GAPBOND_AUTO_SYNC_WL, sizeof(uint8_t), &autoSync);
??? }

??? // Initialize GATT attributes
??? GGS_AddService(GATT_ALL_SERVICES); ? ?? // GAP
??? GATTServApp_AddService(GATT_ALL_SERVICES); // GATT attributes
??? DevInfo_AddService();
??? // Setup a delayed profile startup
??? tmos_set_event(Device_TaskID, START_DEVICE_EVT);
}

uint16_t Device_ProcessEvent(uint8_t task_id, uint16_t events)
{
??? if(events & SYS_EVENT_MSG)
??? {
???????? uint8_t *pMsg;

???????? if((pMsg = tmos_msg_receive(Device_TaskID)) != NULL)
???????? {
???????????? //這里是消息處理代碼,往下傳遞的回調(diào)的函數(shù)代碼在這里

??????????? // Release the TMOS message
?????????????? tmos_msg_deallocate(pMsg);
???????? }
???????? return (events ^ SYS_EVENT_MSG);
??? }
??? if(events & START_DEVICE_EVT)
???? {
???????? // Start the Device
???????? GAPRole_PeripheralStartDevice(Device_TaskID, &DeviceBondCB, &DevicePeripheralCB);
???????? return (events ^ START_DEVICE_EVT);
??? }

?? //下面是其他消息的處理

}


實(shí)際調(diào)試,回調(diào)函數(shù)DevicePeripheralCB里面的代碼是被執(zhí)行的,不過(guò)全部復(fù)制8個(gè)0也沒(méi)啥意義.

static??void?DeviceGapStateCB(gapRole_States_t?newState,?gapRoleEvent_t?*pEvent)
{
????if(newState?==?GAPROLE_STARTED)
?????{
????????//?Set?the?system?ID?from?the?bd?addr
????????uint8_t?systemId[DEVINFO_SYSTEM_ID_LEN];
????????GAPRole_GetParameter(GAPROLE_BD_ADDR,?systemId);

???????//?shift?three?bytes?up
????????systemId[7]?=?systemId[5];
????????systemId[6]?=?systemId[4];
????????systemId[5]?=?systemId[3];

???????//?set?middle?bytes?to?zero
????????systemId[4]?=?0;
????????systemId[3]?=?0;

????????DevInfo_SetParameter(DEVINFO_SYSTEM_ID,?DEVINFO_SYSTEM_ID_LEN,?systemId);
???????}

???????gapProfileState?=?newState;
}

為啥空格全部變成?了?


帖子編輯過(guò)后空格就全部變成?????了


方便的話將完整工程發(fā)送到rzz@wch.cn,便于查找問(wèn)題。可以先簡(jiǎn)化一下程序參考Broadcaster(廣播者)例程,先使設(shè)備可以正常廣播。


根據(jù)發(fā)過(guò)來(lái)的工程進(jìn)行測(cè)試能夠搜索到廣播且可以連接。測(cè)試條件CH582M的DEMO板。確認(rèn)硬件燒錄我們的例程是否可以正常廣播同時(shí)也可以使用我們的DEMO板燒錄你的程序進(jìn)行測(cè)試。

image.png

1683274521594.jpg


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频