Skip to content

Commit 5976da3

Browse files
committed
Fixed PID scan issue
1 parent 8b36cd2 commit 5976da3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

main/autopid.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,24 +303,30 @@ esp_err_t autopid_find_standard_pid(uint8_t protocol, char *available_pids, uint
303303
char pid_str[64];
304304

305305
// If the PID has multiple parameters
306-
if (pid_info->num_params > 1) {
306+
if (pid_info->num_params > 1 && pid_info->params) {
307307
ESP_LOGI(TAG, "Processing multi-parameter PID: %02X", pid);
308308
// Add each parameter as a separate entry
309309
for (int p = 0; p < pid_info->num_params; p++) {
310-
snprintf(pid_str, sizeof(pid_str), "%02X-%s",
311-
pid, pid_info->params[p].name);
312-
ESP_LOGI(TAG, "PID %02X parameter %d supported: %s",
313-
pid, p + 1, pid_str);
314-
cJSON_AddItemToArray(pid_array, cJSON_CreateString(pid_str));
310+
if (pid_info->params[p].name) {
311+
snprintf(pid_str, sizeof(pid_str), "%02X-%s",
312+
pid, pid_info->params[p].name);
313+
ESP_LOGI(TAG, "PID %02X parameter %d supported: %s",
314+
pid, p + 1, pid_str);
315+
cJSON_AddItemToArray(pid_array, cJSON_CreateString(pid_str));
316+
} else {
317+
ESP_LOGW(TAG, "PID %02X parameter %d has NULL name", pid, p + 1);
318+
}
315319
}
316-
} else {
320+
} else if (pid_info->params && pid_info->params[0].name) {
317321
// Single parameter PID
318322
snprintf(pid_str, sizeof(pid_str), "%02X-%s",
319323
pid, pid_info->params[0].name);
320324
ESP_LOGI(TAG, "PID %02X supported: %s", pid, pid_str);
321325
cJSON_AddItemToArray(pid_array, cJSON_CreateString(pid_str));
326+
} else {
327+
ESP_LOGW(TAG, "PID %02X has invalid or NULL parameters", pid);
322328
}
323-
}
329+
}
324330
}
325331
}
326332
} else {

0 commit comments

Comments
 (0)