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

Function at_client_obj_recv

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

* AT client receive fixed-length data. * * @param client current AT client object * @param buf receive data buffer * @param size receive fixed data size * @param timeout receive data timeout (ms) * * @note this function can only be used in execution function of URC data * * @return >0: receive data size * =0: receive failed */

Source from the content-addressed store, hash-verified

547 * =0: receive failed
548 */
549rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_int32_t timeout)
550{
551 rt_size_t read_idx = 0;
552
553 RT_ASSERT(buf);
554
555 if (client == RT_NULL)
556 {
557 LOG_E("input AT Client object is NULL, please create or get AT Client object!");
558 return 0;
559 }
560
561#ifndef RT_USING_SERIAL_V2
562 while (size)
563 {
564 rt_size_t read_len;
565
566 rt_event_recv(&client->event, at_client_rx_notice_event, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, 0, NULL);
567
568 read_len = rt_device_read(client->device, 0, buf + read_idx, size);
569 if (read_len > 0)
570 {
571 read_idx += read_len;
572 size -= read_len;
573 }
574 else
575 {
576 if (rt_event_recv(&client->event, at_client_rx_notice_event, RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, rt_tick_from_millisecond(timeout), NULL) != RT_EOK)
577 break;
578 }
579 }
580#else
581 rt_int32_t rx_timeout = rt_tick_from_millisecond(timeout);
582 rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
583 read_idx = rt_device_read(client->device, 0, buf, size);
584 rx_timeout = RT_WAITING_NO;
585 rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
586#endif
587
588#ifdef AT_PRINT_RAW_CMD
589 at_print_raw_cmd("urc_recv", buf, read_idx);
590#endif
591
592 return read_idx;
593}
594
595/**
596 * AT client set end sign.

Callers

nothing calls this directly

Calls 5

rt_event_recvFunction · 0.85
rt_device_readFunction · 0.85
rt_tick_from_millisecondFunction · 0.85
rt_device_controlFunction · 0.85
at_print_raw_cmdFunction · 0.85

Tested by

no test coverage detected