Skip to content

Commit 74560b0

Browse files
committed
app: Send URC to all open AT pipes
Send URC messages to all pipes that are open and are in AT mode. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 7bf7e84 commit 74560b0

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

app/src/sm_at_host.c

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,16 @@ bool in_idle_pipe(struct modem_pipe *pipe)
15241524
return in_idle_ctx(ctx);
15251525
}
15261526

1527+
bool is_open_pipe(struct modem_pipe *pipe)
1528+
{
1529+
return pipe ? sm_pipe_is_open(pipe) : false;
1530+
}
1531+
1532+
bool is_open_ctx(struct sm_at_host_ctx *ctx)
1533+
{
1534+
return sm_at_host_get_pipe(ctx);
1535+
}
1536+
15271537
void exit_datamode_handler(int result)
15281538
{
15291539
struct sm_at_host_ctx *ctx = sm_at_host_get_current();
@@ -1807,6 +1817,27 @@ static struct sm_at_host_ctx *sm_at_host_create(struct modem_pipe *pipe)
18071817
return ctx;
18081818
}
18091819

1820+
static void send_urcs(void)
1821+
{
1822+
while (!ring_buf_is_empty(&urc_buf)) {
1823+
struct sm_at_host_ctx *ctx;
1824+
uint8_t *p;
1825+
size_t len = ring_buf_get_claim(&urc_buf, &p, UINT16_MAX);
1826+
1827+
SYS_SLIST_FOR_EACH_CONTAINER(&instance_list, ctx, node) {
1828+
if (!is_open(ctx) || !in_at_mode(ctx)) {
1829+
continue;
1830+
}
1831+
int send = sm_at_host_pipe_tx_blocking(ctx, p, len);
1832+
1833+
if (send < len) {
1834+
LOG_ERR("Failed to send URC: %d (ctx %p)", send, ctx);
1835+
}
1836+
}
1837+
ring_buf_get_finish(&urc_buf, len);
1838+
}
1839+
}
1840+
18101841
static void sm_at_host_work_fn(struct k_work *work)
18111842
{
18121843
struct sm_at_host_msg msg;
@@ -1889,16 +1920,7 @@ static void sm_at_host_work_fn(struct k_work *work)
18891920
case SM_EVENT_URC:
18901921
/* Don't interrupt AT command execution */
18911922
if (in_idle(msg.ctx)) {
1892-
while (!ring_buf_is_empty(&urc_buf)) {
1893-
uint8_t *p;
1894-
size_t len = ring_buf_get_claim(&urc_buf, &p, UINT16_MAX);
1895-
int send = sm_at_host_pipe_tx_blocking(msg.ctx, p, len);
1896-
1897-
if (send < len) {
1898-
LOG_ERR("Failed to send URC: %d", send);
1899-
}
1900-
ring_buf_get_finish(&urc_buf, len);
1901-
}
1923+
send_urcs();
19021924
event_work_fn(msg.ctx);
19031925
} else {
19041926
/* Postpone URC sending */

app/src/sm_at_host.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ bool in_idle_pipe(struct modem_pipe *pipe);
170170
struct modem_pipe * : in_idle_pipe \
171171
)(X)
172172

173+
#define is_open(X) \
174+
_Generic((X), \
175+
struct sm_at_host_ctx * : is_open_ctx, \
176+
struct modem_pipe * : is_open_pipe \
177+
)(X)
178+
173179
/**
174180
* @brief Exit the data mode handler
175181
*

0 commit comments

Comments
 (0)