* 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 */
| 458 | * -5 : no memory |
| 459 | */ |
| 460 | int 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). |
nothing calls this directly
no test coverage detected