I am working with simplecentral project and SDK 2.2.
My design is using simplecentral as a pure listener, it would start scan periodically, to lower power consumption, i wanna stop scanning after gets specific data and start a timer at the same time. After the timer triggered, in the callback function, it would start scan (call GapScan_enable). If the device fails getting data wanted, it would stop scan after the duration (set by users) and start again in next scan period (i set the device with infinite mode).
When it comes to my code, i find that the device runs to error when calling GapScan_enable in function registered to util timer. My codes:
#define SC_EVT_OPEN_SCAN 0x0B
#define SC_SCAN_PERIOD 8000
// Clock instance for scan events.
static Clock_Struct clkScanOpen;
//construct clock at GAP_DEVICE_INIT_DONE_EVENT
Util_constructClock(&clkScanOpen, SimpleCentral_clockHandler,
SC_SCAN_PERIOD, 0, false, SC_EVT_OPEN_SCAN);
.....
if(GapScan_disable() != SUCCESS)//;
{
SC_Log_info0("Gap Scan disable failed");
}
//start clock at SC_EVT_ADV_REPORT
Util_startClock(&clkScanOpen);
...
void SimpleCentral_clockHandler(UArg arg)
{
uint8_t evtId = (uint8_t) (arg & 0xFF);
switch (evtId)
{
case SC_EVT_READ_RSSI:
SimpleCentral_enqueueMsg(SC_EVT_READ_RSSI, (uint8_t) (arg >> 8) , NULL);
break;
case SC_EVT_READ_RPA:
// Restart timer
Util_startClock(&clkRpaRead);
// Let the application handle the event
SimpleCentral_enqueueMsg(SC_EVT_READ_RPA, 0, NULL);
break;
case SC_EVT_OPEN_SCAN:
//re-enable scan here
GapScan_enable(scanPeriod, scanDuration, 0);
SC_Log_info0("clock Handler SC_EVT_OPEN_SCAN");
break;
default:
break;
}
}
Is there anything wrong with my codes?
Looking forward to anything helpful.
