Skip to content

Commit 3ceeac6

Browse files
committed
app: Flush URCs before rsp_send()
The data_send() API was already flushing URC messages before sending the data to the pipe. Now if application uses rsp_send() or rsp_send_to() outside of AT command context and combined with data_send() it causes URC messages to be appended in between two calls. Example: rsp_send_to(pipe, "#XRECV: ..."); data_send(pipe, data); /**< this causes URCs to be flushed */ The response in the AT channel would be: #XRECV: ... #XAPOLL: <example urc> data The easiest fix would be to apply same mechanism to urc_send() as the data_send() already does. For clarify, use rsp_send_to() on all callbacks that might execute from poll work handler. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent cc88c7d commit 3ceeac6

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

app/src/sm_at_host.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,14 @@ void rsp_send(const char *fmt, ...)
14891489
struct sm_at_host_ctx *ctx = sm_at_host_get_current();
14901490
va_list arg_ptr;
14911491

1492+
if (!sm_at_ctx_check(ctx)) {
1493+
return;
1494+
}
1495+
1496+
if (is_idle(ctx)) {
1497+
flush_pipe_urcs(ctx);
1498+
}
1499+
14921500
va_start(arg_ptr, fmt);
14931501
rsp_send_internal(ctx, false, fmt, arg_ptr);
14941502
va_end(arg_ptr);
@@ -1499,6 +1507,14 @@ void rsp_send_to(struct modem_pipe *pipe, const char *fmt, ...)
14991507
struct sm_at_host_ctx *ctx = sm_at_host_get_ctx_from(pipe);
15001508
va_list arg_ptr;
15011509

1510+
if (!sm_at_ctx_check(ctx)) {
1511+
return;
1512+
}
1513+
1514+
if (is_idle(ctx)) {
1515+
flush_pipe_urcs(ctx);
1516+
}
1517+
15021518
va_start(arg_ptr, fmt);
15031519
rsp_send_internal(ctx, false, fmt, arg_ptr);
15041520
va_end(arg_ptr);

app/src/sm_at_socket.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static void auto_reception(struct sm_socket *sock)
259259
}
260260
if (!in_datamode(sock->pipe)) {
261261
/* <CR><LF> after the data. */
262-
rsp_send("\r\n");
262+
rsp_send_to(sock->pipe, "\r\n");
263263
}
264264
}
265265

@@ -1127,7 +1127,7 @@ static int do_recv(struct sm_socket *sock, int timeout, int flags,
11271127
LOG_WRN("zsock_recv() return 0");
11281128
} else {
11291129
if (!in_datamode(sock->pipe)) {
1130-
rsp_send("\r\n#XRECV: %d,%d,%d\r\n", sock->fd, mode, ret);
1130+
rsp_send_to(sock->pipe, "\r\n#XRECV: %d,%d,%d\r\n", sock->fd, mode, ret);
11311131
}
11321132

11331133
if (mode == AT_SOCKET_MODE_HEX) {
@@ -1242,7 +1242,7 @@ static int do_recvfrom(struct sm_socket *sock, int timeout, int flags,
12421242
uint16_t peer_port = 0;
12431243

12441244
util_get_peer_addr((struct net_sockaddr *)&remote, peer_addr, &peer_port);
1245-
rsp_send("\r\n#XRECVFROM: %d,%d,%d,\"%s\",%d\r\n", sock->fd,
1245+
rsp_send_to(sock->pipe, "\r\n#XRECVFROM: %d,%d,%d,\"%s\",%d\r\n", sock->fd,
12461246
mode, ret, peer_addr, peer_port);
12471247
}
12481248

0 commit comments

Comments
 (0)