Skip to content

Commit

Permalink
drivers/at: make at_parse_response() public
Browse files Browse the repository at this point in the history
  • Loading branch information
derMihai committed Feb 12, 2024
1 parent 5064f3b commit 499649a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
23 changes: 8 additions & 15 deletions drivers/at/at.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,8 @@ int at_dev_init(at_dev_t *dev, at_dev_init_t const *init)

return uart_init(init->uart, init->baudrate, _isrpipe_write_one_wrapper, dev);
}
/**
* @retval 0, if the response is "OK"
* @retval -AT_ERR_EXTENDED, if the response in "+CMx ERROR: <err>", and <err>
* has been successfully copied to @p dev->err_buf
* @retval -1, if the response is "ERROR", or "+CMx ERROR: <err>" but <err>
* could not be copied
* @retval 1 otherwise
*/
static int parse_resp(at_dev_t *dev, char const *resp)

int at_parse_resp(at_dev_t *dev, char const *resp)
{
if (*resp == '\0') {
return 1;
Expand Down Expand Up @@ -343,7 +336,7 @@ ssize_t at_send_cmd_get_resp_wait_ok(at_dev_t *dev, const char *command, const c
res -= prefix_len;
break;
}
res = parse_resp(dev, resp_buf);
res = at_parse_resp(dev, resp_buf);
if (res == 0) {
// empty response
return 0;
Expand All @@ -365,7 +358,7 @@ ssize_t at_send_cmd_get_resp_wait_ok(at_dev_t *dev, const char *command, const c
if (res_ok < 0) {
return -1;
}
res_ok = parse_resp(dev, err_buff);
res_ok = at_parse_resp(dev, err_buff);
if (res_ok == 0) {
return res;
}
Expand Down Expand Up @@ -411,7 +404,7 @@ ssize_t at_send_cmd_get_lines(at_dev_t *dev, const char *command, char *resp_buf
else if (res > 0) {
size_t const res_len = res;
bytes_left -= res_len;
res = parse_resp(dev, pos);
res = at_parse_resp(dev, pos);

switch (res) {
case 0:
Expand Down Expand Up @@ -458,7 +451,7 @@ int at_send_cmd_wait_prompt(at_dev_t *dev, const char *command, uint32_t timeout
if (strstr(resp_buf, ">")) {
return 0;
}
res = parse_resp(dev, resp_buf);
res = at_parse_resp(dev, resp_buf);
#ifdef MODULE_AT_URC
if (res == 1) {
clist_foreach(&dev->urc_list, _check_urc, resp_buf);
Expand All @@ -478,7 +471,7 @@ int at_send_cmd_wait_ok(at_dev_t *dev, const char *command, uint32_t timeout)
res = at_send_cmd_get_resp(dev, command, resp_buf, resp_buf_size, timeout);

while (res >= 0) {
res = parse_resp(dev, resp_buf);
res = at_parse_resp(dev, resp_buf);
if (res < 1) {
return res;
}
Expand Down Expand Up @@ -587,7 +580,7 @@ int at_wait_ok(at_dev_t *dev, uint32_t timeout)
if (res < 0) {
return res;
}
res = parse_resp(dev, dev->err_buf);
res = at_parse_resp(dev, dev->err_buf);
if (res < 1) {
return res;
}
Expand Down
16 changes: 16 additions & 0 deletions drivers/include/at.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,22 @@ ssize_t at_recv_bytes(at_dev_t *dev, char *bytes, size_t len, uint32_t timeout);
*/
int at_send_cmd(at_dev_t *dev, const char *command, uint32_t timeout);

/**
* @brief Parse a response from the device.
*
* This is always called automatically in functions that may return -AT_ERR_EXTENDED.
* However, if you read the response by other methods (e.g. with @ref at_recv_bytes()),
* you might want to call this on the response so that you don't have to parse it yourself.
*
* @retval 0, if the response is "OK"
* @retval -AT_ERR_EXTENDED, if the response is "+CMx ERROR: <err>", and <err>

Check failure on line 419 in drivers/include/at.h

View workflow job for this annotation

GitHub Actions / static-tests

Unsupported xml/html tag <err> found
* has been successfully copied to @p dev->err_buf
* @retval -1, if the response is "ERROR", or "+CMx ERROR: <err>" but <err>

Check failure on line 421 in drivers/include/at.h

View workflow job for this annotation

GitHub Actions / static-tests

Unsupported xml/html tag <err> found
* could not be copied
* @retval 1 otherwise
*/
int at_parse_resp(at_dev_t *dev, char const *resp);

Check failure on line 425 in drivers/include/at.h

View workflow job for this annotation

GitHub Actions / static-tests

return value 'if' of at_parse_resp has multiple documentation sections

/**
* @brief Read a line from device
*
Expand Down

0 comments on commit 499649a

Please # to comment.