From a9410bd9b1e37d83711e4f3b5dbd354cbec1c76f Mon Sep 17 00:00:00 2001 From: wgzAIIT <820906721@qq.com> Date: Tue, 24 May 2022 16:29:46 +0800 Subject: [PATCH] add timeout for adapter_lora.c PrivSemaphoreObtainWait function --- .../Framework/connection/lora/adapter_lora.c | 11 ++++++++-- .../transform_layer/nuttx/transform.h | 20 +++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/APP_Framework/Framework/connection/lora/adapter_lora.c b/APP_Framework/Framework/connection/lora/adapter_lora.c index 5a5f268e4..0051bb487 100644 --- a/APP_Framework/Framework/connection/lora/adapter_lora.c +++ b/APP_Framework/Framework/connection/lora/adapter_lora.c @@ -50,6 +50,8 @@ extern AdapterProductInfoType E220Attach(struct Adapter *adapter); #define ADAPTER_LORA_RECEIVE_ERROR_CNT 1 +#define DEFAULT_SEM_TIMEOUT 10 + //need to change status if the lora client wants to quit the net when timeout or a certain event //eg.can also use sem to trigger quit function static int g_adapter_lora_quit_flag = 0; @@ -453,7 +455,10 @@ static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int le int ret = 0; uint8_t client_id = adapter->net_role_id; - ret = PrivSemaphoreObtainWait(&adapter->sem, NULL); + struct timespec abstime; + abstime.tv_sec = DEFAULT_SEM_TIMEOUT; + + ret = PrivSemaphoreObtainWait(&adapter->sem, &abstime); if (0 == ret) { //only handle this client_id information from gateway if ((client_recv_data_format[client_id - 1].client_id == adapter->net_role_id) && @@ -681,6 +686,8 @@ static void *LoraReceiveTask(void *parameter) void LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *gateway) { int i, ret = 0; + struct timespec abstime; + abstime.tv_sec = DEFAULT_SEM_TIMEOUT; #ifdef GATEWAY_CMD_MODE for (i = 0; i < gateway->client_num; i ++) { @@ -692,7 +699,7 @@ void LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *g continue; } - ret = PrivSemaphoreObtainWait(&gateway_recv_data_sem, NULL); + ret = PrivSemaphoreObtainWait(&gateway_recv_data_sem, &abstime); if (0 == ret) { printf("LoraGatewayProcess receive client %d data done\n", gateway->client_id[i]); } diff --git a/APP_Framework/Framework/transform_layer/nuttx/transform.h b/APP_Framework/Framework/transform_layer/nuttx/transform.h index 39e868a8b..71b4f48e7 100644 --- a/APP_Framework/Framework/transform_layer/nuttx/transform.h +++ b/APP_Framework/Framework/transform_layer/nuttx/transform.h @@ -29,6 +29,7 @@ #include #include #include +#include typedef uint8_t uint8; typedef uint16_t uint16; @@ -44,23 +45,23 @@ typedef int64_t int64; extern "C" { #endif -#define OPE_INT 0x0000 -#define OPE_CFG 0x0001 +#define OPE_INT 0x0000 +#define OPE_CFG 0x0001 -#define NAME_NUM_MAX 32 +#define NAME_NUM_MAX 32 /*********************GPIO define*********************/ #define GPIO_LOW 0x00 #define GPIO_HIGH 0x01 -#define GPIO_CFG_OUTPUT 0x00 -#define GPIO_CFG_INPUT 0x01 -#define GPIO_CFG_INPUT_PULLUP 0x02 +#define GPIO_CFG_OUTPUT 0x00 +#define GPIO_CFG_INPUT 0x01 +#define GPIO_CFG_INPUT_PULLUP 0x02 #define GPIO_CFG_INPUT_PULLDOWN 0x03 -#define GPIO_CFG_OUTPUT_OD 0x04 +#define GPIO_CFG_OUTPUT_OD 0x04 -#define GPIO_CONFIG_MODE 0xffffffff +#define GPIO_CONFIG_MODE 0xffffffff /********************SERIAL define*******************/ #define BAUD_RATE_2400 2400 @@ -174,9 +175,6 @@ int PrivMutexDelete(pthread_mutex_t *p_mutex); int PrivMutexObtain(pthread_mutex_t *p_mutex); int PrivMutexAbandon(pthread_mutex_t *p_mutex); - - - /*********************semaphore**********************/ int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value);