Skip to content

Commit e80e80b

Browse files
committed
update autopid
ecu status becomes offline if all pid requests fail
1 parent 560dfb3 commit e80e80b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

main/autopid.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static void autopid_task(void *pvParameters)
485485

486486
case READ_PID:
487487
{
488-
uint8_t pid_no_response = 0;
488+
uint8_t pid_response = 0;
489489
if(num_of_pids > 0)
490490
{
491491
for(uint32_t i = 0; i < num_of_pids; i++)
@@ -524,6 +524,7 @@ static void autopid_task(void *pvParameters)
524524

525525
// Convert the cJSON object to a string
526526
response_str = cJSON_PrintUnformatted(rsp_json);
527+
pid_response = 1;
527528
}
528529

529530
if (response_str != NULL)
@@ -568,7 +569,6 @@ static void autopid_task(void *pvParameters)
568569
vTaskDelay(pdMS_TO_TICKS(10));
569570
free(error_rsp);
570571
}
571-
pid_no_response = 1;
572572
}
573573
}
574574
vTaskDelay(pdMS_TO_TICKS(2));
@@ -620,6 +620,7 @@ static void autopid_task(void *pvParameters)
620620
// Add the name and result to the JSON object
621621
cJSON_AddNumberToObject(rsp_json, car.pids[i].parameters[j].name, result);
622622
ESP_LOGI(TAG, "Expression result, Name: %s: %lf", car.pids[i].parameters[j].name, result);
623+
pid_response = 1;
623624
}
624625
}
625626
else
@@ -628,7 +629,7 @@ static void autopid_task(void *pvParameters)
628629
if(asprintf(&error_rsp, "{\"error\": \"Failed Expression: %s\"}", car.pids[i].parameters[j].expression) != -1)
629630
{
630631
mqtt_publish(error_topic, error_rsp, 0, 0, 0);
631-
autopid_data_write(error_rsp);
632+
// autopid_data_write(error_rsp);
632633
vTaskDelay(pdMS_TO_TICKS(10));
633634
free(error_rsp);
634635
}
@@ -640,7 +641,7 @@ static void autopid_task(void *pvParameters)
640641
if(asprintf(&error_rsp, "{\"error\": \"Failed Expression: %s\"}", car.pids[i].parameters[j].expression) != -1)
641642
{
642643
mqtt_publish(error_topic, error_rsp, 0, 0, 0);
643-
autopid_data_write(error_rsp);
644+
// autopid_data_write(error_rsp);
644645
vTaskDelay(pdMS_TO_TICKS(10));
645646
free(error_rsp);
646647
}
@@ -653,11 +654,10 @@ static void autopid_task(void *pvParameters)
653654
if(asprintf(&error_rsp, "{\"error\": \"Timeout, pid: %s\"}", car.pids[i].pid) != -1)
654655
{
655656
mqtt_publish(error_topic, error_rsp, 0, 0, 0);
656-
autopid_data_write(error_rsp);
657+
// autopid_data_write(error_rsp);
657658
vTaskDelay(pdMS_TO_TICKS(10));
658659
free(error_rsp);
659660
}
660-
pid_no_response = 1;
661661
}
662662
}
663663
else
@@ -666,11 +666,10 @@ static void autopid_task(void *pvParameters)
666666
if(asprintf(&error_rsp, "{\"error\": \"PID Error\"}") != -1)
667667
{
668668
mqtt_publish(error_topic, error_rsp, 0, 0, 0);
669-
autopid_data_write(error_rsp);
669+
// autopid_data_write(error_rsp);
670670
vTaskDelay(pdMS_TO_TICKS(10));
671671
free(error_rsp);
672672
}
673-
pid_no_response = 1;
674673
}
675674
}
676675

@@ -687,7 +686,7 @@ static void autopid_task(void *pvParameters)
687686
}
688687
}
689688
vTaskDelay(pdMS_TO_TICKS(10));
690-
if(pid_no_response)
689+
if(pid_response == 0)
691690
{
692691
autopid_state = DISCONNECT_NOTIFY;
693692
ESP_LOGI(TAG, "State change --> DISCONNECT_NOTIFY");

0 commit comments

Comments
 (0)