diff --git a/APP_Framework/Framework/connection/adapter_agent.c b/APP_Framework/Framework/connection/adapter_agent.c index 8d75767ee..b423e1dcf 100755 --- a/APP_Framework/Framework/connection/adapter_agent.c +++ b/APP_Framework/Framework/connection/adapter_agent.c @@ -33,7 +33,7 @@ #define AT_CMD_MAX_LEN 128 #define AT_AGENT_MAX 2 static char send_buf[AT_CMD_MAX_LEN]; -static uint32 last_cmd_len = 0; +static uint32_t last_cmd_len = 0; static struct ATAgent at_agent_table[AT_AGENT_MAX] = {0}; @@ -126,7 +126,7 @@ void ATSprintf(int fd, const char *format, va_list params) PrivWrite(fd, send_buf, last_cmd_len); } -int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...) +int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const char *cmd_expr, ...) { if (agent == NULL) { printf("ATAgent is null"); @@ -147,8 +147,8 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch agent->entm_recv_len = 0; va_list params; - uint32 cmd_size = 0; - uint32 result = 0; + uint32_t cmd_size = 0; + uint32_t result = 0; const char *cmd = NULL; agent->reply = reply; @@ -317,7 +317,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s) static int GetCompleteATReply(ATAgentType agent) { - uint32 read_len = 0; + uint32_t read_len = 0; char ch = 0, last_ch = 0; bool is_full = false; @@ -335,7 +335,9 @@ static int GetCompleteATReply(ATAgentType agent) { PrivRead(agent->fd, &ch, 1); #ifdef CONNECTION_FRAMEWORK_DEBUG - printf(" %c (0x%x)\n", ch, ch); + if(ch != 0){ + printf(" %c (0x%x)\n", ch, ch); + } #endif PrivMutexObtain(&agent->lock); @@ -365,9 +367,13 @@ static int GetCompleteATReply(ATAgentType agent) { if (read_len < agent->maintain_max) { - agent->maintain_buffer[read_len] = ch; - read_len++; - agent->maintain_len = read_len; + if(ch != 0) ///< if the char is null then do not save it to the buff + { + agent->maintain_buffer[read_len] = ch; + read_len++; + agent->maintain_len = read_len; + } + } else { printf("maintain_len is_full ...\n"); is_full = true; diff --git a/APP_Framework/Framework/connection/at_agent.h b/APP_Framework/Framework/connection/at_agent.h index 3267698cf..6a8a4f5a6 100755 --- a/APP_Framework/Framework/connection/at_agent.h +++ b/APP_Framework/Framework/connection/at_agent.h @@ -87,7 +87,7 @@ 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); -int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...); +int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const char *cmd_expr, ...); int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check); #endif \ No newline at end of file diff --git a/APP_Framework/Framework/connection/zigbee/e18/e18.c b/APP_Framework/Framework/connection/zigbee/e18/e18.c index 6d04f6e94..bd8d5ef92 100644 --- a/APP_Framework/Framework/connection/zigbee/e18/e18.c +++ b/APP_Framework/Framework/connection/zigbee/e18/e18.c @@ -123,15 +123,22 @@ static int E18UartOpen(struct Adapter *adapter) static int E18NetworkModeConfig(struct Adapter *adapter) { int ret = 0; + int mode = -1; + if (NULL == adapter) { return -1; } - ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); - if(ret < 0) { - printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); - ret = -1; - goto out; + mode = E18HardwareModeGet(); + if(E18_AS_HEX_MODE == mode) + { + ret = AtCmdConfigAndCheck(adapter->agent, cmd_hex2at, "+OK"); + if(ret < 0) { + printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,cmd_hex2at); + ret = -1; + goto out; + } } + switch (adapter->info->work_mode) { @@ -168,7 +175,10 @@ static int E18NetworkModeConfig(struct Adapter *adapter) } out: - AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); + if(E18_AS_HEX_MODE == mode){ + AtCmdConfigAndCheck(adapter->agent, cmd_exit, "+OK"); + } + return ret; } @@ -241,6 +251,7 @@ static int E18Open(struct Adapter *adapter) { int ret = 0; int try_times = 5; + int count = 0; if (NULL == adapter) { return -1; @@ -267,9 +278,12 @@ static int E18Open(struct Adapter *adapter) try_again: while(try_times--){ ret = E18NetRoleConfig(adapter); + count++; if(ret < 0){ - printf("E18NetRoleConfig failed [%d] times.\n",try_times); - goto try_again; + printf("E18NetRoleConfig failed [%d] times.\n",count); + continue; + } else { + break; } }