Skip to content
Snippets Groups Projects
Commit 7340e773 authored by Vincent Dupont's avatar Vincent Dupont Committed by Kaspar Schleiser
Browse files

drivers/at: add at_send_cmd_wait_prompt and at_send_bytes

parent ee29b76c
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,11 @@ int at_expect_bytes(at_dev_t *dev, const char *bytes, size_t len, uint32_t timeo ...@@ -54,6 +54,11 @@ int at_expect_bytes(at_dev_t *dev, const char *bytes, size_t len, uint32_t timeo
return 0; return 0;
} }
void at_send_bytes(at_dev_t *dev, const char *bytes, size_t len)
{
uart_write(dev->uart, (const uint8_t *)bytes, len);
}
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)
{ {
unsigned cmdlen = strlen(command); unsigned cmdlen = strlen(command);
...@@ -155,6 +160,30 @@ out: ...@@ -155,6 +160,30 @@ out:
return res; return res;
} }
int at_send_cmd_wait_prompt(at_dev_t *dev, const char *command, uint32_t timeout)
{
unsigned cmdlen = strlen(command);
at_drain(dev);
uart_write(dev->uart, (const uint8_t *)command, cmdlen);
uart_write(dev->uart, (const uint8_t *)AT_END_OF_LINE, sizeof(AT_END_OF_LINE) - 1);
if (at_expect_bytes(dev, command, cmdlen, timeout)) {
return -1;
}
if (at_expect_bytes(dev, AT_END_OF_LINE "\n", sizeof(AT_END_OF_LINE), timeout)) {
return -2;
}
if (at_expect_bytes(dev, ">", 1, timeout)) {
return -3;
}
return 0;
}
int at_send_cmd_wait_ok(at_dev_t *dev, const char *command, uint32_t timeout) int at_send_cmd_wait_ok(at_dev_t *dev, const char *command, uint32_t timeout)
{ {
int res; int res;
......
...@@ -84,6 +84,21 @@ int at_dev_init(at_dev_t *dev, uart_t uart, uint32_t baudrate, char *buf, size_t ...@@ -84,6 +84,21 @@ int at_dev_init(at_dev_t *dev, uart_t uart, uint32_t baudrate, char *buf, size_t
*/ */
int at_send_cmd_wait_ok(at_dev_t *dev, const char *command, uint32_t timeout); int at_send_cmd_wait_ok(at_dev_t *dev, const char *command, uint32_t timeout);
/**
* @brief send AT command, wait for a prompt
*
* This function will send the supplied @p command, then wait for the prompt (>)
* character and return
*
* @param[in] dev device to operate on
* @param[in] command command string to send
* @param[in] timeout timeout (in usec)
*
* @return 0 when prompt is received
* @return <0 otherwise
*/
int at_send_cmd_wait_prompt(at_dev_t *dev, const char *command, uint32_t timeout);
/** /**
* @brief send AT command, wait for response * @brief send AT command, wait for response
* *
...@@ -136,6 +151,15 @@ ssize_t at_send_cmd_get_lines(at_dev_t *dev, const char *command, char *resp_buf ...@@ -136,6 +151,15 @@ 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, size_t len, uint32_t timeout); int at_expect_bytes(at_dev_t *dev, const char *bytes, size_t len, uint32_t timeout);
/**
* @brief Send raw bytes to a device
*
* @param[in] dev device to operate on
* @param[in] bytes buffer containing bytes to send
* @param[in] len number of bytes to send
*/
void at_send_bytes(at_dev_t *dev, const char *bytes, size_t len);
/** /**
* @brief send command to device * @brief send command to device
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment