Skip to content

Commit f1c4c19

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 f1c4c19

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

app/src/sm_at_host.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,15 @@ 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+
LOG_ERR("invalid context");
1494+
return;
1495+
}
1496+
1497+
if (is_idle(ctx)) {
1498+
flush_pipe_urcs(ctx);
1499+
}
1500+
14921501
va_start(arg_ptr, fmt);
14931502
rsp_send_internal(ctx, false, fmt, arg_ptr);
14941503
va_end(arg_ptr);
@@ -1499,6 +1508,15 @@ void rsp_send_to(struct modem_pipe *pipe, const char *fmt, ...)
14991508
struct sm_at_host_ctx *ctx = sm_at_host_get_ctx_from(pipe);
15001509
va_list arg_ptr;
15011510

1511+
if (!sm_at_ctx_check(ctx)) {
1512+
LOG_ERR("invalid context");
1513+
return;
1514+
}
1515+
1516+
if (is_idle(ctx)) {
1517+
flush_pipe_urcs(ctx);
1518+
}
1519+
15021520
va_start(arg_ptr, fmt);
15031521
rsp_send_internal(ctx, false, fmt, arg_ptr);
15041522
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)