Merge pull request #10191 from fedepell/at_recv_bytes_1
drivers/at: add function to read raw data bytes from modem
This commit is contained in:
commit
e13bc4285b
@ -63,6 +63,24 @@ void at_send_bytes(at_dev_t *dev, const char *bytes, size_t len)
|
|||||||
uart_write(dev->uart, (const uint8_t *)bytes, len);
|
uart_write(dev->uart, (const uint8_t *)bytes, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t at_recv_bytes(at_dev_t *dev, char *bytes, size_t len, uint32_t timeout)
|
||||||
|
{
|
||||||
|
char *resp_pos = bytes;
|
||||||
|
|
||||||
|
while (len) {
|
||||||
|
int read_res;
|
||||||
|
if ((read_res = isrpipe_read_timeout(&dev->isrpipe, resp_pos, 1, timeout)) == 1) {
|
||||||
|
resp_pos += read_res;
|
||||||
|
len -= read_res;
|
||||||
|
}
|
||||||
|
else if (read_res == -ETIMEDOUT) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (resp_pos - bytes);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@ -220,6 +220,18 @@ int at_expect_bytes(at_dev_t *dev, const char *bytes, uint32_t timeout);
|
|||||||
*/
|
*/
|
||||||
void at_send_bytes(at_dev_t *dev, const char *bytes, size_t len);
|
void at_send_bytes(at_dev_t *dev, const char *bytes, size_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Receive raw bytes from a device
|
||||||
|
*
|
||||||
|
* @param[in] dev device to operate on
|
||||||
|
* @param[in] bytes buffer where store received bytes
|
||||||
|
* @param[in] len maximum number of bytes to receive
|
||||||
|
* @param[in] timeout timeout (in usec) of inactivity to finish read
|
||||||
|
*
|
||||||
|
* @returns Number of bytes read, eventually zero if no bytes available
|
||||||
|
*/
|
||||||
|
ssize_t at_recv_bytes(at_dev_t *dev, char *bytes, size_t len, uint32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send command to device
|
* @brief Send command to device
|
||||||
*
|
*
|
||||||
|
|||||||
@ -105,6 +105,25 @@ static int send_lines(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int send_recv_bytes(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char buffer[64];
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
printf("Usage: %s <command> <number of bytes>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(buffer, "%s%s", argv[1], AT_SEND_EOL);
|
||||||
|
at_send_bytes(&at_dev, buffer, strlen(buffer));
|
||||||
|
|
||||||
|
ssize_t len = at_recv_bytes(&at_dev, buffer, atoi(argv[2]), 10 * US_PER_SEC);
|
||||||
|
|
||||||
|
printf("Response (len=%d): %s\n", (int)len, buffer);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int drain(int argc, char **argv)
|
static int drain(int argc, char **argv)
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
@ -228,6 +247,7 @@ static const shell_command_t shell_commands[] = {
|
|||||||
{ "send", "Send a command and wait response", send },
|
{ "send", "Send a command and wait response", send },
|
||||||
{ "send_ok", "Send a command and wait OK", send_ok },
|
{ "send_ok", "Send a command and wait OK", send_ok },
|
||||||
{ "send_lines", "Send a command and wait lines", send_lines },
|
{ "send_lines", "Send a command and wait lines", send_lines },
|
||||||
|
{ "send_recv_bytes", "Send a command and wait response as raw bytes", send_recv_bytes },
|
||||||
{ "drain", "Drain AT device", drain },
|
{ "drain", "Drain AT device", drain },
|
||||||
{ "power_on", "Power on AT device", power_on },
|
{ "power_on", "Power on AT device", power_on },
|
||||||
{ "power_off", "Power off AT device", power_off },
|
{ "power_off", "Power off AT device", power_off },
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user