Skip to content

Commit

Permalink
Merge pull request #24 from Floyddotnet/pull-commandqueue-hangs
Browse files Browse the repository at this point in the history
Fix a bug that results in that the command queue is no longer processed
  • Loading branch information
softypit authored Mar 29, 2019
2 parents 0d6aec6 + b0e65b7 commit 87e8679
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions main/eq3_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,12 @@ static void gattc_profile_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
/* Disconnected */
get_server = false;
ESP_LOGI(GATTC_TAG, "ESP_GATTC_DISCONNECT_EVT, status = %d", p_data->disconnect.reason);
//esp_ble_gattc_app_unregister(gl_profile_tab[PROFILE_A_APP_ID].gattc_if);
//esp_ble_gattc_app_unregister(gl_profile_tab[PROFILE_A_APP_ID].gattc_if);
ble_operation_in_progress = false;

if(p_data->disconnect.reason != ESP_GATT_CONN_TERMINATE_LOCAL_HOST)
gattc_command_error(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, "TRV error");

break;
default:
ESP_LOGI(GATTC_TAG, "Unhandled_EVT %d", event);
Expand Down Expand Up @@ -941,10 +946,15 @@ static int setup_command(void){
static int command_complete(bool success){
bool deletehead = false;
int rc = EQ3_CMD_RETRY;

if(success == true){
deletehead = true;
rc = EQ3_CMD_DONE;
}else{
}
else if(cmdqueue == NULL) {
rc = EQ3_CMD_DONE;
}
else{
/* Command failed - retry if there are any retries left */

/* Normal operation - retry the same command until all attempts are exhausted
Expand Down Expand Up @@ -973,7 +983,7 @@ static int command_complete(bool success){
#endif
}
}
if(deletehead){
if(deletehead && cmdqueue != NULL){
/* Delete this command from the queue */
struct eq3cmd *delcmd = cmdqueue;
cmdqueue = cmdqueue->next;
Expand Down Expand Up @@ -1149,7 +1159,7 @@ void app_main(){

/* Timer message handling */
if(xQueueReceive(timer_queue, &evt, 0)){
ESP_LOGI(GATTC_TAG, "Timer0 event");
ESP_LOGI(GATTC_TAG, "Timer0 event (nextcmd.running=%d, ble_operation_in_progress=%d)", nextcmd.running, ble_operation_in_progress);
outstanding_timer = false;

if(nextcmd.running == true){
Expand All @@ -1162,7 +1172,6 @@ void app_main(){
esp_ble_gattc_close (gl_profile_tab[PROFILE_A_APP_ID].gattc_if, gl_profile_tab[PROFILE_A_APP_ID].conn_id);
}
runtimer();
ble_operation_in_progress = false;
break;
case START_WIFI:
ESP_LOGI(GATTC_TAG, "Init wifi");
Expand Down

0 comments on commit 87e8679

Please sign in to comment.