Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #77 from 0x1abin/development-2
Browse files Browse the repository at this point in the history
Development 2
  • Loading branch information
0x1abin authored Aug 27, 2021
2 parents 46f6111 + 9904a19 commit 7ec6b86
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
7 changes: 7 additions & 0 deletions include/tuya_config_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
#define HTTP_TIMEOUT_MS_DEFAULT (5000U)
#endif

/**
* @brief HTTP TLS timeout config.
*/
#ifndef MATOP_TIMEOUT_MS_DEFAULT
#define MATOP_TIMEOUT_MS_DEFAULT (8000U)
#endif

#endif /* ifndef TUYA_CONFIG_DEFAULTS_H_ */
2 changes: 1 addition & 1 deletion middleware/core_mqtt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* If a ping response is not received before this timeout, then
* #MQTT_ProcessLoop will return #MQTTKeepAliveTimeout.
*/
#define MQTT_PINGRESP_TIMEOUT_MS ( 500U )
#define MQTT_PINGRESP_TIMEOUT_MS ( 2000U )

/**
* @brief CORE_MQTT_BUFFER_SIZE
Expand Down
1 change: 0 additions & 1 deletion middleware/mqtt_client_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ mqtt_client_status_t mqtt_client_yield(void* client)
if( mqtt_status != MQTTSuccess ) {
log_error("MQTT_ProcessLoop returned with status = %s.", MQTT_Status_strerror( mqtt_status ));
mqtt_client_disconnect(context);
system_sleep(context->config.timeout_ms);
return MQTT_STATUS_NETWORK_TIMEOUT;
}
return MQTT_STATUS_SUCCESS;
Expand Down
3 changes: 2 additions & 1 deletion src/matop_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>

#include "tuya_log.h"
#include "tuya_config_defaults.h"
#include "tuya_error_code.h"
#include "tuya_cloud_types.h"
#include "system_interface.h"
Expand Down Expand Up @@ -245,7 +246,7 @@ int matop_service_request_async(matop_context_t* context,
}
message_handle->next = NULL;
message_handle->id = ++matop->id_cnt;
message_handle->timeout = system_ticks() + (request->timeout == 0 ? 5000:request->timeout);
message_handle->timeout = system_ticks() + (request->timeout == 0 ? MATOP_TIMEOUT_MS_DEFAULT:request->timeout);
message_handle->notify_cb = notify_cb;
message_handle->user_data = user_data;

Expand Down
33 changes: 23 additions & 10 deletions utils/MultiTimer.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#include "MultiTimer.h"
#include <stdio.h>

// Timer handle list head.
#define MULTIMER_MAX_TIMEOUT 0x7fffffff

/* Check if timer's expiry time is greater than time and care about uint32_t wraparounds */
#define CHECK_TIME_LESS_THAN(t, compare_to) ( (((uint32_t)((t)-(compare_to))) > MULTIMER_MAX_TIMEOUT) ? 1 : 0 )

/* Timer handle list head. */
static MultiTimer* timerList = NULL;

// Timer tick
/* Timer tick */
static PlatformTicksFunction_t platformTicksFunction = NULL;

/**
Expand Down Expand Up @@ -101,17 +106,25 @@ int MultiTimerStop(MultiTimer* timer)
*/
void MultiTimerYield(void)
{
MultiTimer* target = timerList;
for (; target; target = target->next) {
if (target->deadline > platformTicksFunction()) {
MultiTimer** nextTimer = &timerList;

for (; *nextTimer; nextTimer = &(*nextTimer)->next) {
MultiTimer* entry = *nextTimer;
/* Sorted list, just process with the front part. */
if (CHECK_TIME_LESS_THAN(platformTicksFunction(), entry->deadline)) {
return;
}
MultiTimerStop(target);
if (target->period) {
MultiTimerStart(target, target->period);
/* remove expired timer from list */
*nextTimer = entry->next;

if (entry->period) {
MultiTimerStart(entry, entry->period);
}
if (entry->callback) {
entry->callback(entry, entry->userData);
}
if (target->callback) {
target->callback(target, target->userData);
if (entry->next == NULL) {
return;
}
}
}

0 comments on commit 7ec6b86

Please sign in to comment.