drivers/at: Add function to receive until string
This commit is contained in:
parent
30d89b3f62
commit
5b04fb1713
@ -80,6 +80,34 @@ ssize_t at_recv_bytes(at_dev_t *dev, char *bytes, size_t len, uint32_t timeout)
|
|||||||
return (resp_pos - bytes);
|
return (resp_pos - bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int at_recv_bytes_until_string(at_dev_t *dev, const char *string,
|
||||||
|
char *bytes, size_t *bytes_len, uint32_t timeout)
|
||||||
|
{
|
||||||
|
size_t len = 0;
|
||||||
|
char *_string = (char *)string;
|
||||||
|
|
||||||
|
while (*_string && len < *bytes_len) {
|
||||||
|
int res;
|
||||||
|
char c;
|
||||||
|
if ((res = isrpipe_read_timeout(&dev->isrpipe, &c, 1, timeout)) == 1) {
|
||||||
|
if (AT_PRINT_INCOMING) {
|
||||||
|
print(&c, 1);
|
||||||
|
}
|
||||||
|
if (c == *_string) {
|
||||||
|
_string++;
|
||||||
|
}
|
||||||
|
bytes[len] = c;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*bytes_len = len;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*bytes_len = len;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int at_send_cmd(at_dev_t *dev, const char *command, uint32_t timeout)
|
int at_send_cmd(at_dev_t *dev, const char *command, uint32_t timeout)
|
||||||
{
|
{
|
||||||
size_t cmdlen = strlen(command);
|
size_t cmdlen = strlen(command);
|
||||||
|
|||||||
@ -211,6 +211,25 @@ ssize_t at_send_cmd_get_lines(at_dev_t *dev, const char *command, char *resp_buf
|
|||||||
*/
|
*/
|
||||||
int at_expect_bytes(at_dev_t *dev, const char *bytes, uint32_t timeout);
|
int at_expect_bytes(at_dev_t *dev, const char *bytes, uint32_t timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Receives bytes into @p bytes buffer until the string pattern
|
||||||
|
* @p string is received or the buffer is full.
|
||||||
|
*
|
||||||
|
* @param[in] dev device to operate on
|
||||||
|
* @param[in] string string pattern to expect
|
||||||
|
* @param[out] bytes buffer to store received bytes
|
||||||
|
* @param[in, out] bytes_len pointer to the maximum number of bytes to
|
||||||
|
* receive. On return stores the amount of received
|
||||||
|
* bytes.
|
||||||
|
* @param[in] timeout timeout (in usec) of inactivity to finish read
|
||||||
|
*
|
||||||
|
* @returns 0 on success
|
||||||
|
* @returns <0 on error
|
||||||
|
*/
|
||||||
|
int at_recv_bytes_until_string(at_dev_t *dev, const char *string,
|
||||||
|
char *bytes, size_t *bytes_len,
|
||||||
|
uint32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send raw bytes to a device
|
* @brief Send raw bytes to a device
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user