* Send commands through custom formatting to AT server and wait response. * * @param client current AT client object * @param resp AT response object, using RT_NULL when you don't care response * @param format formatting macro, it can be one of these values: AT_END_CR_LF, AT_END_RAW, AT_END_CR, AT_END_LF. * Behavior of AT_END_CR_LF is same as at_obj_exec_cmd, and it will add \r\
| 373 | * -7 : enter AT CLI mode |
| 374 | */ |
| 375 | int at_obj_exec_cmd_format(at_client_t client, at_response_t resp, const char *format, const char *cmd_expr, ...) |
| 376 | { |
| 377 | va_list args; |
| 378 | rt_err_t result = RT_EOK; |
| 379 | |
| 380 | RT_ASSERT(cmd_expr); |
| 381 | |
| 382 | if (client == RT_NULL) |
| 383 | { |
| 384 | LOG_E("input AT Client object is NULL, please create or get AT Client object!"); |
| 385 | return -RT_ERROR; |
| 386 | } |
| 387 | |
| 388 | /* check AT CLI mode */ |
| 389 | if (client->status == AT_STATUS_CLI && resp) |
| 390 | { |
| 391 | return -RT_EBUSY; |
| 392 | } |
| 393 | |
| 394 | rt_mutex_take(&client->lock, RT_WAITING_FOREVER); |
| 395 | |
| 396 | client->resp_status = AT_RESP_OK; |
| 397 | |
| 398 | if (resp != RT_NULL) |
| 399 | { |
| 400 | resp->buf_len = 0; |
| 401 | resp->line_counts = 0; |
| 402 | } |
| 403 | |
| 404 | client->resp = resp; |
| 405 | rt_event_recv(&client->event, at_client_resp_notice_event, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, 0, NULL); |
| 406 | |
| 407 | va_start(args, cmd_expr); |
| 408 | |
| 409 | if (strcmp(format, AT_END_CR_LF) == 0) |
| 410 | { |
| 411 | client->last_cmd_len = at_vprintfln(client->device, client->send_buf, client->send_bufsz, cmd_expr, args); |
| 412 | } |
| 413 | else if (strcmp(format, AT_END_RAW) == 0) |
| 414 | { |
| 415 | client->last_cmd_len = at_vprintf(client->device, client->send_buf, client->send_bufsz, cmd_expr, args); |
| 416 | } |
| 417 | else if (strcmp(format, AT_END_CR) == 0) |
| 418 | { |
| 419 | client->last_cmd_len = at_vprintfcr(client->device, client->send_buf, client->send_bufsz, cmd_expr, args); |
| 420 | } |
| 421 | else if (strcmp(format, AT_END_LF) == 0) |
| 422 | { |
| 423 | client->last_cmd_len = at_vprintflf(client->device, client->send_buf, client->send_bufsz, cmd_expr, args); |
| 424 | } |
| 425 | |
| 426 | va_end(args); |
| 427 | |
| 428 | if (resp != RT_NULL) |
| 429 | { |
| 430 | if (rt_event_recv(&client->event, at_client_resp_notice_event, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, resp->timeout, NULL) != RT_EOK) |
| 431 | { |
| 432 | LOG_W("execute command (%.*s) timeout (%d ticks)!", client->last_cmd_len, client->send_buf, resp->timeout); |
nothing calls this directly
no test coverage detected