1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

drivers/at: add at_send_cmd_wait_prompt and at_send_bytes

This commit is contained in:
Vincent Dupont 2017-07-13 18:44:28 +02:00 committed by Kaspar Schleiser
parent ee29b76c89
commit 7340e77328
2 changed files with 53 additions and 0 deletions

View File

@ -54,6 +54,11 @@ int at_expect_bytes(at_dev_t *dev, const char *bytes, size_t len, uint32_t timeo
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)
{
unsigned cmdlen = strlen(command);
@ -155,6 +160,30 @@ out:
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 res;

View File

@ -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);
/**
* @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
*
@ -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);
/**
* @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
*