static int32_t g_scanIntervalTimePrev = WAIT_TIME_SCAN_INTERVAL_DEFAULT;
static int32_t g_intervalCount = 0;
static bool g_isWorkingScanThread = false;
-static CALEScanState_t g_scanningStep = BLE_SCAN_DISABLE;
+static CALEScanState_t g_curScanningStep = BLE_SCAN_DISABLE;
+static CALEScanState_t g_nextScanningStep = BLE_SCAN_ENABLE;
static CABLEDataReceivedCallback g_CABLEClientDataReceivedCallback = NULL;
}
}
-void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount)
+void CALEClientSetScanInterval(int32_t intervalTime, int32_t workingCount,
+ CALEScanState_t nextScanningStep)
{
- OIC_LOG_V(DEBUG, TAG, "CALEClientSetScanInterval : %d -> %d",
- g_scanIntervalTime, intervalTime);
+ OIC_LOG_V(DEBUG, TAG, "CALEClientSetScanInterval : %d -> %d, next scan state will be %d",
+ g_scanIntervalTime, intervalTime, nextScanningStep);
// previous time should be stored.
if (0 < workingCount)
}
g_scanIntervalTime = intervalTime;
g_intervalCount = workingCount;
+ g_nextScanningStep = nextScanningStep;
}
-void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount)
+void CALERestartScanWithInterval(int32_t intervalTime, int32_t workingCount,
+ CALEScanState_t nextScanningStep)
{
- // restart scan with interval
- CALEClientSetScanInterval(intervalTime, workingCount);
+ if (intervalTime == g_scanIntervalTime
+ && workingCount == g_intervalCount
+ && nextScanningStep == g_nextScanningStep)
+ {
+ OIC_LOG(DEBUG, TAG, "setting duplicate interval time");
+ return;
+ }
+
+ CALEClientSetScanInterval(intervalTime, workingCount, nextScanningStep);
ca_cond_signal(g_threadScanIntervalCond);
}
while(g_isWorkingScanThread)
{
OIC_LOG(DEBUG, TAG, "scan waiting time out");
- if (BLE_SCAN_ENABLE == g_scanningStep)
+ if (BLE_SCAN_ENABLE == g_curScanningStep)
{
//stop scan
CAResult_t ret = CALEClientStopScan();
{
// called signal scan thread will be terminated
OIC_LOG(DEBUG, TAG, "signal scanInterval waiting");
- g_scanningStep = BLE_SCAN_DISABLE;
+ if (BLE_SCAN_DISABLE == g_nextScanningStep)
+ {
+ g_curScanningStep = BLE_SCAN_ENABLE;
+ }
+ else
+ {
+ g_curScanningStep = BLE_SCAN_DISABLE;
+ }
}
else
{
- if (BLE_SCAN_ENABLE == g_scanningStep)
+ if (BLE_SCAN_ENABLE == g_curScanningStep)
{
if (g_intervalCount > 0)
{
if (g_intervalCount == 1)
{
OIC_LOG(DEBUG, TAG, "reset default time");
- CALEClientSetScanInterval(g_scanIntervalTimePrev, 0);
+ CALEClientSetScanInterval(g_scanIntervalTimePrev, 0, BLE_SCAN_ENABLE);
}
g_intervalCount--;
OIC_LOG_V(DEBUG, TAG, "interval count : %d", g_intervalCount);
}
- g_scanningStep = BLE_SCAN_DISABLE;
+ g_curScanningStep = BLE_SCAN_DISABLE;
}
else
{
- g_scanningStep = BLE_SCAN_ENABLE;
+ g_curScanningStep = BLE_SCAN_ENABLE;
}
}
}
}
// initialize scan flags
- g_scanningStep = BLE_SCAN_DISABLE;
+ g_curScanningStep = BLE_SCAN_DISABLE;
g_isWorkingScanThread = true;
g_intervalCount = 0;
g_scanIntervalTime = g_scanIntervalTimePrev;
+ g_nextScanningStep = BLE_SCAN_ENABLE;
if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle,
CALEScanThread, NULL))
2 * MICROSECS_PER_SEC; // Microseconds
// set scan interval and start scan
- CALERestartScanWithInterval(WAIT_TIME_SCANNED_CHECKING, 1);
+ CALERestartScanWithInterval(WAIT_TIME_SCANNED_CHECKING, 1, BLE_SCAN_ENABLE);
bool devicesDiscovered = false;
for (size_t i = 0; i < RETRIES; ++i)
}
// reset scan interval time after checking scanned devices
- CALERestartScanWithInterval(g_scanIntervalTimePrev, 0);
+ CALERestartScanWithInterval(0, 0, BLE_SCAN_DISABLE);
// time out for scanning devices
if (!devicesDiscovered)
VERIFY_NON_NULL_RET(env, TAG, "env is null", NULL);
VERIFY_NON_NULL_RET(bluetoothDevice, TAG, "bluetoothDevice is null", NULL);
+ // reset scan interval time after checking scanned devices
+ CALERestartScanWithInterval(0, 0, BLE_SCAN_DISABLE);
+
// get gatt object from Bluetooth Device object for closeProfileProxy(..)
jstring jni_address = CALEClientGetLEAddressFromBTDevice(env, bluetoothDevice);
if (jni_address)
CALEClientSetSendFinishFlag(true);
OIC_LOG(DEBUG, TAG, "set signal for send data");
}
+
+ // reset interval scan logic
+ CALERestartScanWithInterval(g_scanIntervalTimePrev, 0, BLE_SCAN_ENABLE);
+
// mutex unlock
ca_mutex_unlock(g_threadMutex);
}
}
}
+ // reset interval scan logic
+ CALERestartScanWithInterval(g_scanIntervalTimePrev, 0, BLE_SCAN_ENABLE);
+
OIC_LOG(INFO, TAG, "ServicesDiscovery is successful");
(*env)->ReleaseStringUTFChars(env, jni_address, address);
return;