BLE_Quiet() now resets the timer.
This commit is contained in:
parent
8b655d8be7
commit
e81336cec8
5 changed files with 147 additions and 9 deletions
|
@ -5976,7 +5976,7 @@
|
|||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Create Listing File" v="True" />
|
||||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Default Char Unsigned" v="False" />
|
||||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Generate Debugging Information" v="True" />
|
||||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Preprocessor Definitions" v="PSOC_PLATFORM; DEBUG; CY_CORE_ID=0; TWENTY20TPC" />
|
||||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Preprocessor Definitions" v="PSOC_PLATFORM; DEBUG; CY_CORE_ID=0; TWENTY20TPC; TRACE_BLE" />
|
||||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Pedantic Compilation" v="False" />
|
||||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Warning Level" v="High" />
|
||||
<name_val_pair name="c9323d49-d323-40b8-9b59-cc008d68a989@Debug@CortexM4@C/C++@General@Warnings as Errors" v="False" />
|
||||
|
|
|
@ -411,6 +411,10 @@ SystemKResult_T BLE_GetMyAddress(uint8_t * BD_ADDR)
|
|||
|
||||
SystemKResult_T BLE_ScanAndAdvertise(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_ScanAndAdvertise()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
if (Is_Quiet == false)
|
||||
{
|
||||
COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 };
|
||||
|
@ -428,6 +432,10 @@ SystemKResult_T BLE_ScanAndAdvertise(void)
|
|||
|
||||
SystemKResult_T BLE_StopAdvertising(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_StopAdvertising()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_ADVERTISING, .Data = (void *)0x00 };
|
||||
xQueueSend(COMM_BLE_CommandQueue, &command, 0);
|
||||
|
||||
|
@ -436,6 +444,10 @@ SystemKResult_T BLE_StopAdvertising(void)
|
|||
|
||||
SystemKResult_T BLE_StopScanning(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_StopScanning()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_SCANNING, .Data = (void *)0x00 };
|
||||
xQueueSend(COMM_BLE_CommandQueue, &command, 0);
|
||||
|
||||
|
@ -450,12 +462,59 @@ static void Unquiet_Timer_Callback(TimerHandle_t xTimer)
|
|||
|
||||
SystemKResult_T BLE_Quiet(uint32_t duration_ms)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_Quiet(%lu)", duration_ms);
|
||||
#endif // TRACE_BLE
|
||||
|
||||
SystemKResult_T result = SYSTEMK_RESULT_NOT_READY;
|
||||
|
||||
if (Is_Quiet == true)
|
||||
{
|
||||
// Already quiet; no action needed.
|
||||
return SYSTEMK_RESULT_SUCCESS;
|
||||
// Already quiet; reset timer with new duration if duration_ms > 0.
|
||||
if (duration_ms > 0)
|
||||
{
|
||||
// Stop and delete existing timer if it exists.
|
||||
if (BLEUnquietTimer != NULL)
|
||||
{
|
||||
xTimerStop(BLEUnquietTimer, 0);
|
||||
xTimerDelete(BLEUnquietTimer, 0);
|
||||
BLEUnquietTimer = NULL;
|
||||
}
|
||||
|
||||
// Create and start new timer with the new duration.
|
||||
BLEUnquietTimer = xTimerCreateStatic(
|
||||
"BLEUnquietTimer",
|
||||
pdMS_TO_TICKS(duration_ms),
|
||||
pdFALSE,
|
||||
(void *)0,
|
||||
Unquiet_Timer_Callback,
|
||||
&xBLEUnquietTimerBuffer);
|
||||
|
||||
if (BLEUnquietTimer == NULL)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xTimerStart(BLEUnquietTimer, 0) != pdPASS)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If duration_ms is 0, stop and delete the timer to stay quiet indefinitely.
|
||||
if (BLEUnquietTimer != NULL)
|
||||
{
|
||||
xTimerStop(BLEUnquietTimer, 0);
|
||||
xTimerDelete(BLEUnquietTimer, 0);
|
||||
BLEUnquietTimer = NULL;
|
||||
}
|
||||
}
|
||||
result = SYSTEMK_RESULT_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -482,12 +541,14 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms)
|
|||
if (BLEUnquietTimer == NULL)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xTimerStart(BLEUnquietTimer, 0) != pdPASS)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -499,6 +560,10 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms)
|
|||
|
||||
SystemKResult_T BLE_Unquiet(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_Unquiet()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
SystemKResult_T result = SYSTEMK_RESULT_NOT_READY;
|
||||
|
||||
if (Is_Quiet == false)
|
||||
|
@ -544,6 +609,10 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data)
|
|||
Advertising_Data.advDataLen = BLE_KTAG_PACKET_TOTAL_SIZE;
|
||||
memcpy(Advertising_Data.advData, data, BLE_KTAG_PACKET_TOTAL_SIZE);
|
||||
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "Setting advertising data for packet type %u", data->data[8]);
|
||||
#endif // TRACE_BLE
|
||||
|
||||
cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info);
|
||||
|
||||
if (result != CY_BLE_SUCCESS)
|
||||
|
@ -795,7 +864,7 @@ static void BLE_EventHandler(uint32_t event, void * eventParam)
|
|||
break;
|
||||
|
||||
default:
|
||||
COMM_Console_Print_String(" Unknown KTag packet found!");
|
||||
KLOG_ERROR(TAG, " Unknown KTag packet found: 0x%02X", packet->Generic.type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit bb915121e8e9c8b2679397f4554fa9bc2d836b67
|
||||
Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9
|
|
@ -411,6 +411,10 @@ SystemKResult_T BLE_GetMyAddress(uint8_t * BD_ADDR)
|
|||
|
||||
SystemKResult_T BLE_ScanAndAdvertise(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_ScanAndAdvertise()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
if (Is_Quiet == false)
|
||||
{
|
||||
COMM_BLE_Command_T command = { .ID = COMM_BLE_SCAN_AND_ADVERTISE, .Data = (void *)0x00 };
|
||||
|
@ -428,6 +432,10 @@ SystemKResult_T BLE_ScanAndAdvertise(void)
|
|||
|
||||
SystemKResult_T BLE_StopAdvertising(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_StopAdvertising()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_ADVERTISING, .Data = (void *)0x00 };
|
||||
xQueueSend(COMM_BLE_CommandQueue, &command, 0);
|
||||
|
||||
|
@ -436,6 +444,10 @@ SystemKResult_T BLE_StopAdvertising(void)
|
|||
|
||||
SystemKResult_T BLE_StopScanning(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_StopScanning()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
COMM_BLE_Command_T command = { .ID = COMM_BLE_STOP_SCANNING, .Data = (void *)0x00 };
|
||||
xQueueSend(COMM_BLE_CommandQueue, &command, 0);
|
||||
|
||||
|
@ -450,12 +462,59 @@ static void Unquiet_Timer_Callback(TimerHandle_t xTimer)
|
|||
|
||||
SystemKResult_T BLE_Quiet(uint32_t duration_ms)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_Quiet(%lu)", duration_ms);
|
||||
#endif // TRACE_BLE
|
||||
|
||||
SystemKResult_T result = SYSTEMK_RESULT_NOT_READY;
|
||||
|
||||
if (Is_Quiet == true)
|
||||
{
|
||||
// Already quiet; no action needed.
|
||||
return SYSTEMK_RESULT_SUCCESS;
|
||||
// Already quiet; reset timer with new duration if duration_ms > 0.
|
||||
if (duration_ms > 0)
|
||||
{
|
||||
// Stop and delete existing timer if it exists.
|
||||
if (BLEUnquietTimer != NULL)
|
||||
{
|
||||
xTimerStop(BLEUnquietTimer, 0);
|
||||
xTimerDelete(BLEUnquietTimer, 0);
|
||||
BLEUnquietTimer = NULL;
|
||||
}
|
||||
|
||||
// Create and start new timer with the new duration.
|
||||
BLEUnquietTimer = xTimerCreateStatic(
|
||||
"BLEUnquietTimer",
|
||||
pdMS_TO_TICKS(duration_ms),
|
||||
pdFALSE,
|
||||
(void *)0,
|
||||
Unquiet_Timer_Callback,
|
||||
&xBLEUnquietTimerBuffer);
|
||||
|
||||
if (BLEUnquietTimer == NULL)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xTimerStart(BLEUnquietTimer, 0) != pdPASS)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If duration_ms is 0, stop and delete the timer to stay quiet indefinitely.
|
||||
if (BLEUnquietTimer != NULL)
|
||||
{
|
||||
xTimerStop(BLEUnquietTimer, 0);
|
||||
xTimerDelete(BLEUnquietTimer, 0);
|
||||
BLEUnquietTimer = NULL;
|
||||
}
|
||||
}
|
||||
result = SYSTEMK_RESULT_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -482,12 +541,14 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms)
|
|||
if (BLEUnquietTimer == NULL)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xTimerStart(BLEUnquietTimer, 0) != pdPASS)
|
||||
{
|
||||
KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!");
|
||||
result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -499,6 +560,10 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms)
|
|||
|
||||
SystemKResult_T BLE_Unquiet(void)
|
||||
{
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "BLE_Unquiet()");
|
||||
#endif // TRACE_BLE
|
||||
|
||||
SystemKResult_T result = SYSTEMK_RESULT_NOT_READY;
|
||||
|
||||
if (Is_Quiet == false)
|
||||
|
@ -544,6 +609,10 @@ SystemKResult_T BLE_SetAdvertisingData(BLE_AdvertisingData_T * data)
|
|||
Advertising_Data.advDataLen = BLE_KTAG_PACKET_TOTAL_SIZE;
|
||||
memcpy(Advertising_Data.advData, data, BLE_KTAG_PACKET_TOTAL_SIZE);
|
||||
|
||||
#ifdef TRACE_BLE
|
||||
KLOG_TRACE(TAG, "Setting advertising data for packet type %u", data->data[8]);
|
||||
#endif // TRACE_BLE
|
||||
|
||||
cy_en_ble_api_result_t result = Cy_BLE_GAPP_UpdateAdvScanData(&Advertising_Info);
|
||||
|
||||
if (result != CY_BLE_SUCCESS)
|
||||
|
@ -795,7 +864,7 @@ static void BLE_EventHandler(uint32_t event, void * eventParam)
|
|||
break;
|
||||
|
||||
default:
|
||||
COMM_Console_Print_String(" Unknown KTag packet found!");
|
||||
KLOG_ERROR(TAG, " Unknown KTag packet found: 0x%02X", packet->Generic.type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit bb915121e8e9c8b2679397f4554fa9bc2d836b67
|
||||
Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9
|
Loading…
Add table
Add a link
Reference in a new issue