mirror of
https://gitee.com/moluo-tech/AT-Command.git
synced 2025-01-15 17:02:53 +08:00
Resolve the issue of not clearing the receive cache before sending multi line commands.
This commit is contained in:
parent
18f9236e30
commit
90c59e1d7a
@ -202,7 +202,7 @@ static void send_cmdline(at_info_t *at, const char *cmd)
|
||||
len = strlen(cmd);
|
||||
__get_adapter(at)->write(cmd, len);
|
||||
__get_adapter(at)->write("\r\n", 2);
|
||||
AT_DEBUG(at,"->\r\n%s\r\n", cmd);
|
||||
AT_DEBUG(at,"->\r\n%s", cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,6 +228,7 @@ static char *get_recvbuf(at_env_t *env)
|
||||
|
||||
static void recvbuf_clear(at_env_t *env)
|
||||
{
|
||||
obj_map(env->obj)->recvbuf[0] = '\0';
|
||||
obj_map(env->obj)->recv_cnt = 0;
|
||||
}
|
||||
|
||||
@ -300,12 +301,12 @@ static void at_finish(struct at_env *env, at_resp_code code)
|
||||
static void do_at_callback(at_info_t *ai, work_item_t *wi, at_resp_code code)
|
||||
{
|
||||
at_response_t r;
|
||||
AT_DEBUG(ai, "<-\r\n%s\r\n", ai->recvbuf);
|
||||
AT_DEBUG(ai, "<-\r\n%s", ai->recvbuf);
|
||||
//Exception notification
|
||||
if ((code == AT_RESP_ERROR || code == AT_RESP_TIMEOUT) && __get_adapter(ai)->error != NULL) {
|
||||
__get_adapter(ai)->error(&r);
|
||||
ai->err_occur = 1;
|
||||
AT_DEBUG(ai, "AT Respose :%s\r\n", code == AT_RESP_TIMEOUT ? "timeout" : "error");
|
||||
AT_DEBUG(ai, "AT Respose :%s", code == AT_RESP_TIMEOUT ? "timeout" : "error");
|
||||
} else {
|
||||
ai->err_occur = 0;
|
||||
}
|
||||
@ -581,11 +582,11 @@ static int send_multiline_handler(at_info_t *ai)
|
||||
env->i++;
|
||||
env->j = 0;
|
||||
env->params = (void *)true; /*Mark execution status*/
|
||||
AT_DEBUG(ai, "<-\r\n%s\r\n", ai->recvbuf);
|
||||
AT_DEBUG(ai, "<-\r\n%s", ai->recvbuf);
|
||||
} else if (find_substr(env, AT_DEF_RESP_ERR)) {
|
||||
AT_DEBUG(ai, "<-\r\n%s\r\n", ai->recvbuf);
|
||||
AT_DEBUG(ai, "<-\r\n%s", ai->recvbuf);
|
||||
env->j++;
|
||||
AT_DEBUG(ai, "CMD:'%s' failed to executed, retry:%d\r\n", cmds[env->i], env->j);
|
||||
AT_DEBUG(ai, "CMD:'%s' failed to executed, retry:%d", cmds[env->i], env->j);
|
||||
if (env->j >= attr->retry) {
|
||||
env->state = 0;
|
||||
env->j = 0;
|
||||
@ -643,6 +644,31 @@ void at_obj_set_urc(at_obj_t *at, const urc_item_t *tbl, int count)
|
||||
ai->urc_tbl = tbl;
|
||||
ai->urc_tbl_size = count;
|
||||
}
|
||||
/**
|
||||
* @brief Get the urc recv buffer count.
|
||||
*/
|
||||
int at_obj_get_urcbuf_count(at_obj_t *at)
|
||||
{
|
||||
return obj_map(at)->urc_cnt;
|
||||
}
|
||||
/**
|
||||
* @brief Temporarily disables the URC matching program
|
||||
* @param enable Enable/disable the URC matching handler
|
||||
* @param timeout Disabled timeout(ms).
|
||||
*/
|
||||
void at_obj_urc_set_enable(at_obj_t *at, int enable, unsigned short timeout)
|
||||
{
|
||||
at_info_t *ai = obj_map(at);
|
||||
ai->urc_enable = enable ? 1 : 0;
|
||||
if (!enable) {
|
||||
ai->urc_timer = at_get_ms();
|
||||
ai->urc_disable_time = timeout;
|
||||
//AT_DEBUG(ai, "Disable the URC, time:%d ms\r\n", timeout);
|
||||
} else {
|
||||
//AT_DEBUG(ai, "Enable the URC\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find a URC handler based on URC receive buffer information.
|
||||
*/
|
||||
@ -663,6 +689,7 @@ static void urc_reset(at_info_t *ai)
|
||||
ai->urc_cnt = 0;
|
||||
ai->urc_item = NULL;
|
||||
ai->urc_match = 0;
|
||||
ai->urc_timer = at_get_ms();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -682,6 +709,7 @@ static void urc_handler_entry(at_info_t *ai, urc_recv_status status, char *urc,
|
||||
/* Send URC event notification. */
|
||||
remain = ai->urc_item ? ai->urc_item->handler(&ctx) : 0;
|
||||
if (remain == 0 && (ai->urc_item || ai->cursor == NULL)) {
|
||||
|
||||
urc_reset(ai);
|
||||
} else {
|
||||
AT_DEBUG(ai,"URC receives %d bytes remaining.\r\n", remain);
|
||||
@ -698,7 +726,7 @@ static void urc_timeout_process(at_info_t *ai)
|
||||
ai->urcbuf[ai->urc_cnt] = '\0';
|
||||
AT_DEBUG(ai,"urc recv timeout=>%s\r\n", ai->urcbuf);
|
||||
urc_handler_entry(ai, URC_RECV_TIMEOUT, ai->urcbuf, ai->urc_cnt);
|
||||
}
|
||||
}
|
||||
urc_reset(ai);
|
||||
}
|
||||
}
|
||||
@ -724,6 +752,7 @@ static void urc_recv_process(at_info_t *ai, char *buf, unsigned int size)
|
||||
ai->urc_enable = 1;
|
||||
AT_DEBUG(ai, "Enable the URC match handler\r\n");
|
||||
}
|
||||
ai->urc_timer = at_get_ms();
|
||||
urc_buf = ai->urcbuf;
|
||||
while (size--) {
|
||||
ch = *buf++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user