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

Function at_recv_readline

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

Source from the content-addressed store, hash-verified

774}
775
776static int at_recv_readline(at_client_t client)
777{
778 char ch = 0, last_ch = 0;
779 rt_bool_t is_full = RT_FALSE;
780 rt_uint32_t event;
781
782 rt_memset(client->recv_line_buf, 0x00, client->recv_bufsz);
783 client->recv_line_len = 0;
784
785 while (1)
786 {
787 event = 0;
788 rt_event_recv(&client->event, at_client_rx_notice_event | at_client_deInit_event,
789 RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &event);
790
791 if (event & at_client_deInit_event)
792 {
793 rt_event_send(&client->event, at_client_deInit_over_event);
794 rt_thread_delete(rt_thread_self());
795 }
796
797 if (event & at_client_rx_notice_event)
798 {
799 while (RT_EOK == at_client_getchar(client, &ch))
800 {
801 if (client->recv_line_len < client->recv_bufsz)
802 {
803 client->recv_line_buf[client->recv_line_len++] = ch;
804 }
805 else
806 {
807 is_full = RT_TRUE;
808 }
809
810 /* is newline or URC data */
811 client->urc = get_urc_obj(client);
812 if (client->urc != RT_NULL || (ch == '\n' && last_ch == '\r')
813 || (client->end_sign != 0 && ch == client->end_sign))
814 {
815 if (is_full)
816 {
817 LOG_E("read line failed. The line data length is out of buffer size(%d)!", client->recv_bufsz);
818 rt_memset(client->recv_line_buf, 0x00, client->recv_bufsz);
819 client->recv_line_len = 0;
820 return -RT_EFULL;
821 }
822
823 /* Since the buffer state is uncertain, we proactively clear it; the overhead is negligible. */
824 rt_event_send(&client->event, at_client_rx_notice_event);
825 goto __next;
826 }
827 last_ch = ch;
828 }
829 }
830 }
831
832__next:
833#ifdef AT_PRINT_RAW_CMD

Callers 1

client_parserFunction · 0.85

Calls 8

rt_memsetFunction · 0.85
rt_event_recvFunction · 0.85
rt_event_sendFunction · 0.85
rt_thread_deleteFunction · 0.85
rt_thread_selfFunction · 0.85
at_client_getcharFunction · 0.85
get_urc_objFunction · 0.85
at_print_raw_cmdFunction · 0.85

Tested by

no test coverage detected