主题中讨论的其他器件: CC2340R5
工具与软件:
您好!
我有两个 LP-EM-CC2340R5器件、一个用作外设、另一个用作中央器件。 外设每4秒广播一次以节省电力。 应如何配置中央设备以更有效地扫描外设?
外设设置图

中央设置图

中央 代码1-1
/*=============================================
AT command start scan.
=============================================*/
void start_scan(char *pdata)
{
bStatus_t status;
const BLEAppUtil_ScanStart_t centralScanStartParams =
{
/*! Zero for continuously scanning */
.scanPeriod = DEFAULT_SCAN_PERIOD, /* Units of 1.28sec */
/*! Scan Duration shall be greater than to scan interval,*/
/*! Zero continuously scanning. */
.scanDuration = DEFAULT_SCAN_DURATION, /* Units of 10ms */
/*! If non-zero, the list of advertising reports will be */
/*! generated and come with @ref GAP_EVT_SCAN_DISABLED. */
.maxNumReport = APP_MAX_NUM_OF_ADV_REPORTS
};
status = BLEAppUtil_scanStart(¢ralScanStartParams);
if(status == FAILURE)
{
while(1){}
}
}
中央 代码1-2 (BLEAPPUTIL_ADV_REPORT)
void Central_ScanEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
{
uint8 pint_rssi_buf[5] = {0};
BLEAppUtil_ScanEventData_t *scanMsg = (BLEAppUtil_ScanEventData_t *)pMsgData;
// bleStk_GapScan_Evt_AdvRpt_t *pScanRpt = NULL;
switch (event)
{
case BLEAPPUTIL_SCAN_ENABLED:
{
centralScanIndex = 0;
MenuModule_printf(APP_MENU_SCAN_EVENT, 0, "Scan status: Scan started...");
break;
}
case BLEAPPUTIL_SCAN_DISABLED:
{
uint8 i;
for(i = 0; i < APP_MAX_NUM_OF_ADV_REPORTS; i++)
{
memset(¢ralScanRes[i], 0, sizeof(App_scanResults));
}
// Go over the advertise reports that was saved in the host level and save it
for (i = 0; i < scanMsg->pBuf->pScanDis.numReport; i++)
{
GapScan_Evt_AdvRpt_t advReport;
// Get the address from the report
GapScan_getAdvReport(i, &advReport);
// Add the report to the scan list
Central_addScanRes(&advReport);
}
UART2_write(uart, (const char *)"OK\r\n", strlen((const char *)"OK\r\n"), NULL);
MenuModule_printf(APP_MENU_SCAN_EVENT, 0, "Scan status: Scan disabled - "
"Reason: " MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET
"Num results: " MENU_MODULE_COLOR_YELLOW "%d " MENU_MODULE_COLOR_RESET,
scanMsg->pBuf->pScanDis.reason,
scanMsg->pBuf->pScanDis.numReport);
break;
}
case BLEAPPUTIL_ADV_REPORT:
pScanRpt = &scanMsg->pBuf->pAdvReport;
//Display device name,support 20 byte(max)
if (pScanRpt->pData != NULL)
{
uint8_t indx = 0;
if(pScanRpt->dataLen > 0)
{
SimpleCentral_findDeviceName(pScanRpt->pData, pScanRpt->dataLen, deviceName, MAX_SIZE);
}
//Determine the first byte
if( (deviceName[0] != '\0') && (deviceName[0] <= '~') ) //if( (deviceName[0] != '\0') && (deviceName[0] >= ' ') && (deviceName[0] <= '~') )
{
deviceName[MAX_SIZE-1] = '\0';
//RSSI
sprintf((char *)pint_rssi_buf, "%d",pScanRpt->rssi);
//print Mac address.
UART2_write(uart, (const char*)BLEAppUtil_convertBdAddr2Str(pScanRpt->addr),strlen((const char*)BLEAppUtil_convertBdAddr2Str(pScanRpt->addr)) , NULL);
UART2_write(uart, (const char *)"; ", strlen((const char *)"; "), NULL);
//print Device name
UART2_write(uart, (const char *)deviceName, strlen((const char *)deviceName), NULL);
UART2_write(uart, (const char *)"; ", strlen((const char *)"; "), NULL);
//print RSSI
UART2_write(uart, (const char *)pint_rssi_buf, strlen((const char *)pint_rssi_buf), NULL);
UART2_write(uart, (const char *)"\r\n", strlen((const char *)"\r\n"), NULL);
}
}
break;
default:
{
break;
}
}
}


