MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / at_client_obj_wait_connect

Function at_client_obj_wait_connect

components/net/at/src/at_client.c:460–499  ·  view source on GitHub ↗

* Waiting for connection to external devices. * * @param client current AT client object * @param timeout millisecond for timeout * * @return 0 : success * -2 : timeout * -5 : no memory */

Source from the content-addressed store, hash-verified

458 * -5 : no memory
459 */
460int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
461{
462 rt_err_t result = RT_EOK;
463 at_response_t resp = RT_NULL;
464 rt_tick_t start_time = 0;
465
466 if (client == RT_NULL)
467 {
468 LOG_E("input AT client object is NULL, please create or get AT Client object!");
469 return -RT_ERROR;
470 }
471
472 resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
473 if (resp == RT_NULL)
474 {
475 LOG_E("no memory for AT client(%s) response object.", client->device->parent.name);
476 return -RT_ENOMEM;
477 }
478
479 start_time = rt_tick_get();
480
481 while (1)
482 {
483 /* Check whether it is timeout */
484 if (rt_tick_get() - start_time > rt_tick_from_millisecond(timeout))
485 {
486 LOG_E("wait AT client(%s) connect timeout(%d tick).", client->device->parent.name, timeout);
487 result = -RT_ETIMEOUT;
488 break;
489 }
490
491 if (at_obj_exec_cmd(client, resp, "AT") == RT_EOK)
492 {
493 break;
494 }
495 }
496
497 at_delete_resp(resp);
498 return result;
499}
500
501/**
502 * Send data to AT server, send data don't have end sign(eg: \r\n).

Callers

nothing calls this directly

Calls 5

at_create_respFunction · 0.85
rt_tick_from_millisecondFunction · 0.85
rt_tick_getFunction · 0.85
at_obj_exec_cmdFunction · 0.85
at_delete_respFunction · 0.85

Tested by

no test coverage detected