Fixed one bug

This commit is contained in:
2024-06-10 18:42:47 +03:00
parent 73ee874c78
commit 5a48774c13

View File

@ -242,7 +242,7 @@ void zh_espnow_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
available_device.device_type = data->device_type; available_device.device_type = data->device_type;
memcpy(available_device.mac_addr, recv_data->mac_addr, 6); memcpy(available_device.mac_addr, recv_data->mac_addr, 6);
available_device.frequency = data->payload_data.keep_alive_message.message_frequency; available_device.frequency = data->payload_data.keep_alive_message.message_frequency;
available_device.time = esp_timer_get_time() / 1000; available_device.time = esp_timer_get_time() / 1000000;
zh_vector_push_back(&gateway_config->available_device_vector, &available_device); zh_vector_push_back(&gateway_config->available_device_vector, &available_device);
xSemaphoreGive(gateway_config->device_check_in_progress_mutex); xSemaphoreGive(gateway_config->device_check_in_progress_mutex);
} }
@ -904,7 +904,7 @@ void zh_device_availability_check_task(void *pvParameter)
{ {
break; break;
} }
if (available_device->time + (available_device->frequency * 3) > esp_timer_get_time() / 1000) if (esp_timer_get_time() / 1000000 > available_device->time + (available_device->frequency * 3))
{ {
char *topic = (char *)heap_caps_malloc(strlen(CONFIG_MQTT_TOPIC_PREFIX) + strlen(zh_get_device_type_value_name(available_device->device_type)) + 27, MALLOC_CAP_8BIT); char *topic = (char *)heap_caps_malloc(strlen(CONFIG_MQTT_TOPIC_PREFIX) + strlen(zh_get_device_type_value_name(available_device->device_type)) + 27, MALLOC_CAP_8BIT);
memset(topic, 0, strlen(CONFIG_MQTT_TOPIC_PREFIX) + strlen(zh_get_device_type_value_name(available_device->device_type)) + 27); memset(topic, 0, strlen(CONFIG_MQTT_TOPIC_PREFIX) + strlen(zh_get_device_type_value_name(available_device->device_type)) + 27);
@ -912,7 +912,7 @@ void zh_device_availability_check_task(void *pvParameter)
esp_mqtt_client_publish(gateway_config->mqtt_client, topic, "offline", 0, 2, true); esp_mqtt_client_publish(gateway_config->mqtt_client, topic, "offline", 0, 2, true);
heap_caps_free(topic); heap_caps_free(topic);
zh_vector_delete_item(&gateway_config->available_device_vector, i); zh_vector_delete_item(&gateway_config->available_device_vector, i);
goto CHECK; // Since the vector is shifted to the left after deletion, the index needs to be re-checked. goto CHECK; // Since the vector is shifted after item deletion, the item needs to be re-checked.
} }
} }
xSemaphoreGive(gateway_config->device_check_in_progress_mutex); xSemaphoreGive(gateway_config->device_check_in_progress_mutex);