From 50995f3c1f9f9ef6a84cf55942e04256e0e4336e Mon Sep 17 00:00:00 2001 From: yl1185 <1182784652@qq.com> Date: Sun, 24 Apr 2022 14:57:06 +0800 Subject: [PATCH] Framework/connection/wifi verify 1.modify type definition in Mutex and Semaphore 2.modify the macro. --- APP_Framework/Framework/connection/adapter.c | 6 ++-- .../Framework/connection/adapter_agent.c | 16 +++++----- APP_Framework/Framework/connection/at_agent.h | 31 +++++++++++++++++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/APP_Framework/Framework/connection/adapter.c b/APP_Framework/Framework/connection/adapter.c index 6d3d8f227..96d93c828 100644 --- a/APP_Framework/Framework/connection/adapter.c +++ b/APP_Framework/Framework/connection/adapter.c @@ -22,7 +22,7 @@ static DoublelistType adapter_list; -static int adapter_list_lock; +static pthread_mutex_t adapter_list_lock; /** * @description: Init adapter framework @@ -481,6 +481,7 @@ int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_gro */ int AdapterDeviceSetUp(struct Adapter *adapter) { + if (!adapter) return -1; @@ -488,10 +489,10 @@ int AdapterDeviceSetUp(struct Adapter *adapter) struct IpProtocolDone *ip_done = NULL; struct PrivProtocolDone *priv_done = NULL; - switch (adapter->net_protocol) { case PRIVATE_PROTOCOL: + priv_done = (struct PrivProtocolDone *)adapter->done; if (NULL == priv_done->setup) return 0; @@ -515,6 +516,7 @@ int AdapterDeviceSetUp(struct Adapter *adapter) return 0; result = ip_done->setup(adapter); + if (0 == result) { printf("Device %s setup success.\n", adapter->name); adapter->adapter_status = INSTALL; diff --git a/APP_Framework/Framework/connection/adapter_agent.c b/APP_Framework/Framework/connection/adapter_agent.c index 29b4cae8f..5c0222847 100755 --- a/APP_Framework/Framework/connection/adapter_agent.c +++ b/APP_Framework/Framework/connection/adapter_agent.c @@ -29,6 +29,8 @@ #ifdef ADD_XIZI_FETURES # include #endif +#ifdef ADD_RTTHREAD_FETURES +#include #define AT_CMD_MAX_LEN 128 #define AT_AGENT_MAX 2 @@ -139,7 +141,7 @@ int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const PrivMutexObtain(&agent->lock); agent->receive_mode = AT_MODE; - + memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; @@ -300,7 +302,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s) //PrivTaskDelay(1000); if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) { printf("wait sem[%d] timeout\n",agent->entm_rx_notice); - return -ERROR; + return -1; } PrivMutexObtain(&agent->lock); @@ -390,7 +392,7 @@ static int GetCompleteATReply(ATAgentType agent) memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; PrivMutexAbandon(&agent->lock); - return -ERROR; + return -1; } printf("GetCompleteATReply done\n"); @@ -449,10 +451,10 @@ int DeleteATAgent(ATAgentType agent) PrivSemaphoreDelete(&agent->entm_rx_notice); } - if (agent->rsp_sem) { - printf("delete agent rsp_sem = %d\n",agent->rsp_sem); - PrivSemaphoreDelete(&agent->rsp_sem); - } + // if (agent->rsp_sem) { + // printf("delete agent rsp_sem = %d\n",agent->rsp_sem); + // PrivSemaphoreDelete(&agent->rsp_sem); + // } if (agent->maintain_buffer) { PrivFree(agent->maintain_buffer); diff --git a/APP_Framework/Framework/connection/at_agent.h b/APP_Framework/Framework/connection/at_agent.h index c98428573..7f82f511a 100755 --- a/APP_Framework/Framework/connection/at_agent.h +++ b/APP_Framework/Framework/connection/at_agent.h @@ -42,7 +42,6 @@ struct ATReply uint32 reply_len; }; typedef struct ATReply *ATReplyType; - struct ATAgent { char agent_name[64]; @@ -56,7 +55,7 @@ struct ATAgent #ifdef ADD_NUTTX_FETURES pthread_mutex_t lock; #else - int lock; + pthread_mutex_t lock; #endif ATReplyType reply; @@ -64,7 +63,33 @@ struct ATAgent char reply_end_last_char; char reply_end_char; uint32 reply_char_num; - int rsp_sem; + sem_t rsp_sem; + + pthread_t at_handler; + + #define ENTM_RECV_MAX 256 + char entm_recv_buf[ENTM_RECV_MAX]; + uint32 entm_recv_len; + enum ReceiveMode receive_mode; + int entm_rx_notice; +}; +typedef struct ATAgent *ATAgentType; + +int EntmSend(ATAgentType agent, const char *data, int len); +int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s); +char *GetReplyText(ATReplyType reply); +int AtSetReplyEndChar(ATAgentType agent, char last_ch, char end_ch); +int AtSetReplyCharNum(ATAgentType agent, unsigned int num); +int AtSetReplyLrEnd(ATAgentType agent, char enable); +ATReplyType CreateATReply(uint32 reply_max_len); +unsigned int IpTint(char *ipstr); +void SwapStr(char *str, int begin, int end); +char* IpTstr(unsigned int ipint); +ATAgentType GetATAgent(const char *agent_name); +int InitATAgent(const char *agent_name, int fd, uint32 maintain_max); +int DeleteATAgent(ATAgentType agent); +int ParseATReply(char* str, const char *format, ...); +void DeleteATReply(ATReplyType reply); pthread_t at_handler;